Skip to content

Commit 464f2fd

Browse files
authored
fix(Ui5DomRef - TypeScript): update types (#6471)
1 parent b3a6abb commit 464f2fd

File tree

1 file changed

+81
-23
lines changed

1 file changed

+81
-23
lines changed

packages/main/src/types/Ui5DomRef.ts

Lines changed: 81 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,52 @@
1+
import type { PropertyValue, SlotValue } from '@ui5/webcomponents-base/dist/UI5ElementMetadata.js';
2+
3+
type ChangeInfo = {
4+
type: 'property' | 'slot';
5+
name: string;
6+
reason?: string;
7+
child?: SlotValue;
8+
target?: Ui5DomRef;
9+
newValue?: PropertyValue;
10+
oldValue?: PropertyValue;
11+
};
12+
13+
type InvalidationInfo = ChangeInfo & { target: Ui5DomRef };
14+
115
export interface Ui5DomRef extends Omit<HTMLElement, 'focus'> {
16+
/**
17+
* Called every time before the component renders.
18+
* @public
19+
*/
20+
onBeforeRendering(): void;
21+
/**
22+
* Called every time after the component renders.
23+
* @public
24+
*/
25+
onAfterRendering(): void;
26+
/**
27+
* Called on connectedCallback - added to the DOM.
28+
* @public
29+
*/
30+
onEnterDOM(): void;
31+
/**
32+
* Called on disconnectedCallback - removed from the DOM.
33+
* @public
34+
*/
35+
onExitDOM(): void;
236
/**
337
* Attach a callback that will be executed whenever the component is invalidated
438
*
539
* @param callback
40+
* @public
641
*/
7-
attachInvalidate: (callback) => void;
42+
attachInvalidate(callback: (param: InvalidationInfo) => void): void;
843
/**
944
* Detach the callback that is executed whenever the component is invalidated
1045
*
1146
* @param callback
47+
* @public
1248
*/
13-
detachInvalidate: (callback) => void;
49+
detachInvalidate(callback: (param: InvalidationInfo) => void): void;
1450
/**
1551
* A callback that is executed each time an already rendered component is invalidated (scheduled for re-rendering)
1652
*
@@ -26,68 +62,90 @@ export interface Ui5DomRef extends Omit<HTMLElement, 'focus'> {
2662
* 1) children: immediate children (HTML elements or text nodes) were added, removed or reordered in the slot
2763
* 2) textcontent: text nodes in the slot changed value (or nested text nodes were added or changed value). Can only trigger for slots of "type: Node"
2864
* 3) slotchange: a slot element, slotted inside that slot had its "slotchange" event listener called. This practically means that transitively slotted children changed.
29-
* Can only trigger if the child of a slot is a slot element itself.
65+
* Can only trigger if the child of a slot is a slot element itself.
3066
* 4) childchange: indicates that a UI5Element child in that slot was invalidated and in turn invalidated the component.
31-
* Can only trigger for slots with "invalidateOnChildChange" metadata descriptor
67+
* Can only trigger for slots with "invalidateOnChildChange" metadata descriptor
3268
*
3369
* - newValue: the new value of the property (for type="property" only)
3470
*
3571
* - oldValue: the old value of the property (for type="property" only)
3672
*
3773
* - child the child that was changed (for type="slot" and reason="childchange" only)
3874
*
75+
* @public
3976
*/
40-
onInvalidation: (changeInfo) => void;
77+
onInvalidation(changeInfo: ChangeInfo): void;
4178
/**
4279
* Returns the DOM Element inside the Shadow Root that corresponds to the opening tag in the UI5 Web Component's template
43-
*
44-
* __Note:__ For logical (abstract) elements (items, options, etc...), returns the part of the parent's DOM that represents this option
45-
*
80+
* *Note:* For logical (abstract) elements (items, options, etc...), returns the part of the parent's DOM that represents this option
4681
* Use this method instead of "this.shadowRoot" to read the Shadow DOM, if ever necessary
82+
*
83+
* @public
4784
*/
48-
getDomRef: () => HTMLElement;
85+
getDomRef(): HTMLElement | undefined;
86+
4987
/**
50-
* Returns the DOM Element marked with `data-sap-focus-ref` inside the template.
88+
* Returns the DOM Element marked with "data-sap-focus-ref" inside the template.
5189
* This is the element that will receive the focus by default.
90+
* @public
5291
*/
53-
getFocusDomRef: () => HTMLElement;
92+
getFocusDomRef(): HTMLElement | undefined;
93+
5494
/**
55-
* Returns the DOM Element marked with `data-sap-focus-ref` inside the template.
95+
* Waits for dom ref and then returns the DOM Element marked with "data-sap-focus-ref" inside the template.
5696
* This is the element that will receive the focus by default.
97+
* @public
5798
*/
58-
getFocusDomRefAsync: () => Promise<HTMLElement>;
99+
getFocusDomRefAsync(): Promise<HTMLElement | undefined>;
59100
/**
60101
* Set the focus to the element, returned by "getFocusDomRef()" (marked by "data-sap-focus-ref")
61-
* @param {FocusOptions} focusOptions additional options for the focus
102+
* @param focusOptions additional options for the focus
103+
* @public
62104
*/
63-
focus: (focusOptions?: FocusOptions) => Promise<void>;
105+
focus(focusOptions?: FocusOptions): Promise<void>;
64106
/**
65107
*
108+
* @public
66109
* @param name - name of the event
67110
* @param data - additional data for the event
68111
* @param cancelable - true, if the user can call preventDefault on the event object
69112
* @param bubbles - true, if the event bubbles
70-
* @returns {boolean} false, if the event was cancelled (preventDefault called), true otherwise
113+
* @returns false, if the event was cancelled (preventDefault called), true otherwise
71114
*/
72-
fireEvent: <T>(name: string, data?: T, cancelable?: boolean, bubbles?: boolean) => boolean;
115+
fireEvent<T>(name: string, data?: T, cancelable?: boolean, bubbles?: boolean): boolean;
73116
/**
74117
* Returns the actual children, associated with a slot.
75118
* Useful when there are transitive slots in nested component scenarios and you don't want to get a list of the slots, but rather of their content.
119+
* @public
76120
*/
77-
getSlottedNodes: <T = Node>(slotName: string) => Array<T>;
121+
getSlottedNodes<T = Node>(slotName: string): Array<T>;
122+
/**
123+
* Attach a callback that will be executed whenever the component's state is finalized
124+
*
125+
* @param callback
126+
* @public
127+
*/
128+
attachComponentStateFinalized(callback: () => void): void;
129+
/**
130+
* Detach the callback that is executed whenever the component's state is finalized
131+
*
132+
* @param callback
133+
* @public
134+
*/
135+
detachComponentStateFinalized(callback: () => void): void;
78136
/**
79137
* Determines whether the component should be rendered in RTL mode or not.
80138
* Returns: "rtl", "ltr" or undefined
81139
*
82-
* @returns {string|undefined}
140+
* @public
141+
* @default undefined
83142
*/
84143
readonly effectiveDir: string | undefined;
144+
85145
/**
86146
* Used to duck-type UI5 elements without using instanceof
147+
* @public
148+
* @default true
87149
*/
88150
readonly isUI5Element: boolean;
89-
/**
90-
* Returns the `staticAreaItem` DOM Element.
91-
*/
92-
getStaticAreaItemDomRef: () => Promise<ShadowRoot | null>;
93151
}

0 commit comments

Comments
 (0)