@momentum-design/components 0.129.45 → 0.129.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +300 -300
- package/dist/browser/index.js.map +4 -4
- package/dist/components/button/button.component.d.ts +9 -1
- package/dist/components/button/button.component.js +13 -2
- package/dist/components/combobox/combobox.component.d.ts +1 -1
- package/dist/components/combobox/combobox.component.js +2 -5
- package/dist/components/dialog/dialog.component.d.ts +19 -7
- package/dist/components/dialog/dialog.component.js +40 -14
- package/dist/components/menubar/menubar.component.d.ts +6 -0
- package/dist/components/menubar/menubar.component.js +30 -26
- package/dist/components/menupopover/menupopover.component.d.ts +1 -1
- package/dist/components/menupopover/menupopover.component.js +19 -24
- package/dist/components/popover/popover.component.d.ts +15 -26
- package/dist/components/popover/popover.component.js +46 -54
- package/dist/components/searchpopover/searchpopover.component.d.ts +1 -1
- package/dist/components/searchpopover/searchpopover.component.js +2 -2
- package/dist/components/select/select.component.d.ts +1 -1
- package/dist/components/select/select.component.js +5 -3
- package/dist/components/text/text.component.d.ts +11 -2
- package/dist/components/text/text.component.js +17 -2
- package/dist/components/tooltip/tooltip.component.d.ts +13 -1
- package/dist/components/tooltip/tooltip.component.js +40 -0
- package/dist/components/tooltip/tooltip.constants.d.ts +1 -0
- package/dist/components/tooltip/tooltip.constants.js +1 -0
- package/dist/custom-elements.json +187 -68
- package/dist/utils/controllers/DepthManager.d.ts +202 -0
- package/dist/utils/controllers/DepthManager.js +259 -0
- package/dist/utils/dom.d.ts +8 -0
- package/dist/utils/dom.js +7 -0
- package/dist/utils/mixins/BackdropMixin.js +19 -2
- package/dist/utils/mixins/FocusTrapMixin.d.ts +0 -0
- package/dist/utils/mixins/FocusTrapMixin.js +1 -0
- package/dist/utils/mixins/OverflowMixin.d.ts +7 -0
- package/dist/utils/mixins/OverflowMixin.js +23 -0
- package/package.json +1 -1
- package/dist/components/popover/popover.stack.d.ts +0 -53
- package/dist/components/popover/popover.stack.js +0 -66
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { ReactiveController } from 'lit';
|
|
2
|
+
import type { Component } from '../../models';
|
|
3
|
+
/**
|
|
4
|
+
* Types of changes that can occur in the stack
|
|
5
|
+
*
|
|
6
|
+
* - 'added': An element was added to the stack, e.g.: pushed
|
|
7
|
+
* - 'removed': An element was removed from the stack, e.g.: popped or removed
|
|
8
|
+
* - 'moved': An element's position in the stack changed e.g.: another element above it was removed
|
|
9
|
+
*/
|
|
10
|
+
export type StackChange = 'added' | 'removed' | 'moved';
|
|
11
|
+
/**
|
|
12
|
+
* A component that can be managed by the DepthManager stack.
|
|
13
|
+
*
|
|
14
|
+
* These elements can receive notifications when their position in the stack changes
|
|
15
|
+
* if they implement the `onComponentStackChanged` callback.
|
|
16
|
+
*/
|
|
17
|
+
export interface StackedOverlayComponent extends Component {
|
|
18
|
+
/**
|
|
19
|
+
* Callback invoked when the component's position in the stack changes.
|
|
20
|
+
*
|
|
21
|
+
* @param change - The type of change that occurred in the stack.
|
|
22
|
+
*/
|
|
23
|
+
onComponentStackChanged?: (change: StackChange) => void;
|
|
24
|
+
/**
|
|
25
|
+
* ID of the trigger element associated with this overlay component
|
|
26
|
+
*/
|
|
27
|
+
triggerID?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Predicate function used to determine whether to pop an item from the stack.
|
|
31
|
+
* - Returns true to pop the item.
|
|
32
|
+
* - Returns false to stop popping items.
|
|
33
|
+
* - Returns 'skip' to skip the item without popping it.
|
|
34
|
+
*/
|
|
35
|
+
type PopPredicateFn = (item: StackedOverlayComponent, idx: number) => true | false | 'skip';
|
|
36
|
+
export declare const OVERLAY_BACKDROP_Z_INDEX_OFFSET = -2;
|
|
37
|
+
export declare const OVERLAY_TRIGGER_Z_INDEX_OFFSET = -1;
|
|
38
|
+
/**
|
|
39
|
+
* DepthManager is a controller that manages a stack of elements to control their depth (z-index).
|
|
40
|
+
*
|
|
41
|
+
* It uses a global stack to keep track of the order of elements, allowing for proper layering of overlays.
|
|
42
|
+
*
|
|
43
|
+
* ## Use Case
|
|
44
|
+
*
|
|
45
|
+
* ### Pop single overlay
|
|
46
|
+
*
|
|
47
|
+
* The easiest one, usually the host removes itself from the stack when it is closed, with the `popHost` method.
|
|
48
|
+
*
|
|
49
|
+
* ### Pop until specific overlay
|
|
50
|
+
*
|
|
51
|
+
* When the chain of nested popover (e.g.: submenus) opened and the user closes other than the last one,
|
|
52
|
+
* we have to close all overlays stacked above the specific one. In this case, the `popItem` or directly the `pupUntil` method is used.
|
|
53
|
+
*
|
|
54
|
+
* ### Closing "sibling" overlays
|
|
55
|
+
*
|
|
56
|
+
* In some cases, multiple overlays can be opened from the same trigger (e.g.: tooltip, context menu, etc.), we can not close
|
|
57
|
+
* all overlays above the specific one, because they independently opened.
|
|
58
|
+
*
|
|
59
|
+
* `popUntil` method can handle this case by skipping the overlays which share the same trigger ID as the specified one.
|
|
60
|
+
*
|
|
61
|
+
* ### Manually removing overlays
|
|
62
|
+
*
|
|
63
|
+
* When the user switch from one sub-menu to another, we need to close all sub-menus from common parent menu.
|
|
64
|
+
* DepthManager does not have built-in solution for this case. The host component need to make sure the submenu
|
|
65
|
+
* hide before the new one is shown.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* // Add and remove item based on the disabled state
|
|
70
|
+
* class Container extends Component {
|
|
71
|
+
* private this.depthManager = new DepthManager<>(this);
|
|
72
|
+
*
|
|
73
|
+
* constructor() {
|
|
74
|
+
* super();
|
|
75
|
+
* this.addEventListener('modified', this.handleModifiedEvent);
|
|
76
|
+
* }
|
|
77
|
+
*
|
|
78
|
+
* openOverlay() {
|
|
79
|
+
* this.depthManager.pushHost()
|
|
80
|
+
* }
|
|
81
|
+
*
|
|
82
|
+
* closeOverlay() {
|
|
83
|
+
* this.depthManager.popHost()
|
|
84
|
+
* }
|
|
85
|
+
*
|
|
86
|
+
* onComponentStackChanged (change: StackChange) {
|
|
87
|
+
* switch (change) {
|
|
88
|
+
* case 'added':
|
|
89
|
+
* return;
|
|
90
|
+
* case 'removed':
|
|
91
|
+
* return this.closeOverlay()
|
|
92
|
+
* case 'moved':
|
|
93
|
+
* return this.requestUpdate('zIndex');
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare class DepthManager implements ReactiveController {
|
|
100
|
+
private readonly host;
|
|
101
|
+
/**
|
|
102
|
+
* Creates an instance of DepthManager.
|
|
103
|
+
*/
|
|
104
|
+
constructor(host: StackedOverlayComponent);
|
|
105
|
+
hostConnected(): void;
|
|
106
|
+
hostDisconnected(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Gets the total number of elements in the stack
|
|
109
|
+
*/
|
|
110
|
+
get length(): number;
|
|
111
|
+
/**
|
|
112
|
+
* Adds host element to the stack
|
|
113
|
+
*
|
|
114
|
+
* @returns push was successful (true) or not (false)
|
|
115
|
+
*/
|
|
116
|
+
pushHost(): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Pops all the items above the host and then pops the host itself
|
|
119
|
+
*
|
|
120
|
+
* @returns The host if it was in the stack, undefined otherwise
|
|
121
|
+
*/
|
|
122
|
+
popHost(): StackedOverlayComponent | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Pops all the items above the specified item and then pops the item itself
|
|
125
|
+
*
|
|
126
|
+
* @param item - The item to pop
|
|
127
|
+
* @returns The item if it was in the stack, undefined otherwise
|
|
128
|
+
*/
|
|
129
|
+
popItem(item: StackedOverlayComponent): StackedOverlayComponent | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* Removes the last element from the stack
|
|
132
|
+
*
|
|
133
|
+
* @returns The last element in the stack
|
|
134
|
+
*/
|
|
135
|
+
pop(): StackedOverlayComponent | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* Removes elements from the stack until the predicate function returns false
|
|
138
|
+
*
|
|
139
|
+
* Note: it will remove the
|
|
140
|
+
*
|
|
141
|
+
* @param predicateFn - The predicate function to test each element
|
|
142
|
+
* @returns The removed elements
|
|
143
|
+
*/
|
|
144
|
+
popUntil(predicateFn: PopPredicateFn): StackedOverlayComponent[];
|
|
145
|
+
/**
|
|
146
|
+
* Returns the last element in the stack
|
|
147
|
+
* without removing it
|
|
148
|
+
*
|
|
149
|
+
* @returns The last element in the stack
|
|
150
|
+
*/
|
|
151
|
+
peek(): StackedOverlayComponent | undefined;
|
|
152
|
+
/**
|
|
153
|
+
* Removes one or more elements from the stack without popping others.
|
|
154
|
+
*
|
|
155
|
+
* It notifies the elements on the stack which were removed and those which changed position.
|
|
156
|
+
* Items removed in bach, notify moved items only once.
|
|
157
|
+
*
|
|
158
|
+
* @param elements - Popover instance
|
|
159
|
+
* @returns undefined when the element was not found, the removed element otherwise
|
|
160
|
+
*/
|
|
161
|
+
remove(elements: StackedOverlayComponent[]): StackedOverlayComponent[];
|
|
162
|
+
/**
|
|
163
|
+
* Checks if the stack has a specific element
|
|
164
|
+
*
|
|
165
|
+
* @param element - Popover instance
|
|
166
|
+
* @returns True if the stack has the element, false otherwise
|
|
167
|
+
*/
|
|
168
|
+
has(element: StackedOverlayComponent): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Gets the depth of the host element in the stack
|
|
171
|
+
*/
|
|
172
|
+
getHostDepth(): number;
|
|
173
|
+
/**
|
|
174
|
+
* Gets the depth of the element in the stack
|
|
175
|
+
* @param element - The element to get the depth of
|
|
176
|
+
*/
|
|
177
|
+
getElementDepth(element: StackedOverlayComponent): number;
|
|
178
|
+
/**
|
|
179
|
+
* Gets the z-index of the host element in the stack
|
|
180
|
+
*/
|
|
181
|
+
getHostZIndex(): number;
|
|
182
|
+
/**
|
|
183
|
+
* Gets the z-index of the element in the stack
|
|
184
|
+
* @param element - The element to get the z-index of
|
|
185
|
+
*
|
|
186
|
+
* @returns The z-index of the element if found, otherwise returns -1
|
|
187
|
+
*/
|
|
188
|
+
getItemZIndex(element: StackedOverlayComponent): number;
|
|
189
|
+
/**
|
|
190
|
+
* Checks if host is at the top of the stack
|
|
191
|
+
*
|
|
192
|
+
* @returns True if host is on top, false otherwise
|
|
193
|
+
*/
|
|
194
|
+
isHostOnTop(): boolean;
|
|
195
|
+
/**
|
|
196
|
+
* Clears the stack
|
|
197
|
+
*
|
|
198
|
+
* Pops all elements from the stack one-by-one.
|
|
199
|
+
*/
|
|
200
|
+
clear(): void;
|
|
201
|
+
}
|
|
202
|
+
export {};
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global stack of elements managed by DepthManager
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
const elementStack = [];
|
|
6
|
+
/**
|
|
7
|
+
* Initial z-index for the first element in the stack
|
|
8
|
+
*/
|
|
9
|
+
const BASE_Z_INDEX = 1000;
|
|
10
|
+
/**
|
|
11
|
+
* Number of z-index levels per element in the stack
|
|
12
|
+
* @internal
|
|
13
|
+
* - level -2: level of backdrop (if any)
|
|
14
|
+
* - level -1: level of trigger component (if any)
|
|
15
|
+
* - level 0: z-index of the overlay element (e.g. popover, dialog, etc.)
|
|
16
|
+
*/
|
|
17
|
+
const NUMBER_OF_Z_INDEX_LEVELS_PER_ELEMENT = 3;
|
|
18
|
+
export const OVERLAY_BACKDROP_Z_INDEX_OFFSET = -2;
|
|
19
|
+
export const OVERLAY_TRIGGER_Z_INDEX_OFFSET = -1;
|
|
20
|
+
/**
|
|
21
|
+
* DepthManager is a controller that manages a stack of elements to control their depth (z-index).
|
|
22
|
+
*
|
|
23
|
+
* It uses a global stack to keep track of the order of elements, allowing for proper layering of overlays.
|
|
24
|
+
*
|
|
25
|
+
* ## Use Case
|
|
26
|
+
*
|
|
27
|
+
* ### Pop single overlay
|
|
28
|
+
*
|
|
29
|
+
* The easiest one, usually the host removes itself from the stack when it is closed, with the `popHost` method.
|
|
30
|
+
*
|
|
31
|
+
* ### Pop until specific overlay
|
|
32
|
+
*
|
|
33
|
+
* When the chain of nested popover (e.g.: submenus) opened and the user closes other than the last one,
|
|
34
|
+
* we have to close all overlays stacked above the specific one. In this case, the `popItem` or directly the `pupUntil` method is used.
|
|
35
|
+
*
|
|
36
|
+
* ### Closing "sibling" overlays
|
|
37
|
+
*
|
|
38
|
+
* In some cases, multiple overlays can be opened from the same trigger (e.g.: tooltip, context menu, etc.), we can not close
|
|
39
|
+
* all overlays above the specific one, because they independently opened.
|
|
40
|
+
*
|
|
41
|
+
* `popUntil` method can handle this case by skipping the overlays which share the same trigger ID as the specified one.
|
|
42
|
+
*
|
|
43
|
+
* ### Manually removing overlays
|
|
44
|
+
*
|
|
45
|
+
* When the user switch from one sub-menu to another, we need to close all sub-menus from common parent menu.
|
|
46
|
+
* DepthManager does not have built-in solution for this case. The host component need to make sure the submenu
|
|
47
|
+
* hide before the new one is shown.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* // Add and remove item based on the disabled state
|
|
52
|
+
* class Container extends Component {
|
|
53
|
+
* private this.depthManager = new DepthManager<>(this);
|
|
54
|
+
*
|
|
55
|
+
* constructor() {
|
|
56
|
+
* super();
|
|
57
|
+
* this.addEventListener('modified', this.handleModifiedEvent);
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* openOverlay() {
|
|
61
|
+
* this.depthManager.pushHost()
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* closeOverlay() {
|
|
65
|
+
* this.depthManager.popHost()
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* onComponentStackChanged (change: StackChange) {
|
|
69
|
+
* switch (change) {
|
|
70
|
+
* case 'added':
|
|
71
|
+
* return;
|
|
72
|
+
* case 'removed':
|
|
73
|
+
* return this.closeOverlay()
|
|
74
|
+
* case 'moved':
|
|
75
|
+
* return this.requestUpdate('zIndex');
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export class DepthManager {
|
|
82
|
+
/**
|
|
83
|
+
* Creates an instance of DepthManager.
|
|
84
|
+
*/
|
|
85
|
+
constructor(host) {
|
|
86
|
+
this.host = host;
|
|
87
|
+
host.addController(this);
|
|
88
|
+
}
|
|
89
|
+
hostConnected() { }
|
|
90
|
+
hostDisconnected() {
|
|
91
|
+
// Remove this instance from the global stack on disconnect
|
|
92
|
+
this.remove([this.host]);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Gets the total number of elements in the stack
|
|
96
|
+
*/
|
|
97
|
+
get length() {
|
|
98
|
+
return elementStack.length;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Adds host element to the stack
|
|
102
|
+
*
|
|
103
|
+
* @returns push was successful (true) or not (false)
|
|
104
|
+
*/
|
|
105
|
+
pushHost() {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
if (!this.has(this.host)) {
|
|
108
|
+
elementStack.push(this.host);
|
|
109
|
+
(_b = (_a = this.host).onComponentStackChanged) === null || _b === void 0 ? void 0 : _b.call(_a, 'added');
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Pops all the items above the host and then pops the host itself
|
|
116
|
+
*
|
|
117
|
+
* @returns The host if it was in the stack, undefined otherwise
|
|
118
|
+
*/
|
|
119
|
+
popHost() {
|
|
120
|
+
return this.popItem(this.host);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Pops all the items above the specified item and then pops the item itself
|
|
124
|
+
*
|
|
125
|
+
* @param item - The item to pop
|
|
126
|
+
* @returns The item if it was in the stack, undefined otherwise
|
|
127
|
+
*/
|
|
128
|
+
popItem(item) {
|
|
129
|
+
if (this.has(item)) {
|
|
130
|
+
const untilItemIdx = elementStack.indexOf(item) - 1;
|
|
131
|
+
this.popUntil((it, idx) => {
|
|
132
|
+
// This can handle the case when multiple overlays share the same trigger (id), e.g.: tooltip, etc.
|
|
133
|
+
if (it !== item && it.triggerID === item.triggerID)
|
|
134
|
+
return 'skip';
|
|
135
|
+
return idx !== untilItemIdx;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Removes the last element from the stack
|
|
142
|
+
*
|
|
143
|
+
* @returns The last element in the stack
|
|
144
|
+
*/
|
|
145
|
+
pop() {
|
|
146
|
+
var _a;
|
|
147
|
+
const popped = elementStack.pop();
|
|
148
|
+
(_a = popped === null || popped === void 0 ? void 0 : popped.onComponentStackChanged) === null || _a === void 0 ? void 0 : _a.call(popped, 'removed');
|
|
149
|
+
return popped;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Removes elements from the stack until the predicate function returns false
|
|
153
|
+
*
|
|
154
|
+
* Note: it will remove the
|
|
155
|
+
*
|
|
156
|
+
* @param predicateFn - The predicate function to test each element
|
|
157
|
+
* @returns The removed elements
|
|
158
|
+
*/
|
|
159
|
+
popUntil(predicateFn) {
|
|
160
|
+
const poppedElements = [];
|
|
161
|
+
for (let i = elementStack.length - 1; i >= 0; i -= 1) {
|
|
162
|
+
const item = elementStack[i];
|
|
163
|
+
const result = predicateFn(item, i);
|
|
164
|
+
if (result === false)
|
|
165
|
+
break;
|
|
166
|
+
if (result !== 'skip')
|
|
167
|
+
poppedElements.push(item);
|
|
168
|
+
}
|
|
169
|
+
return this.remove(poppedElements);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Returns the last element in the stack
|
|
173
|
+
* without removing it
|
|
174
|
+
*
|
|
175
|
+
* @returns The last element in the stack
|
|
176
|
+
*/
|
|
177
|
+
peek() {
|
|
178
|
+
return elementStack.at(-1);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Removes one or more elements from the stack without popping others.
|
|
182
|
+
*
|
|
183
|
+
* It notifies the elements on the stack which were removed and those which changed position.
|
|
184
|
+
* Items removed in bach, notify moved items only once.
|
|
185
|
+
*
|
|
186
|
+
* @param elements - Popover instance
|
|
187
|
+
* @returns undefined when the element was not found, the removed element otherwise
|
|
188
|
+
*/
|
|
189
|
+
remove(elements) {
|
|
190
|
+
var _a, _b;
|
|
191
|
+
const removedElements = elements.filter(el => elementStack.includes(el));
|
|
192
|
+
const updateStackFrom = removedElements.reduce((idx, el) => Math.min(idx, elementStack.indexOf(el)), Infinity);
|
|
193
|
+
// Remove elements from the stack
|
|
194
|
+
removedElements.forEach(el => {
|
|
195
|
+
var _a;
|
|
196
|
+
elementStack.splice(elementStack.indexOf(el), 1);
|
|
197
|
+
(_a = el === null || el === void 0 ? void 0 : el.onComponentStackChanged) === null || _a === void 0 ? void 0 : _a.call(el, 'removed');
|
|
198
|
+
});
|
|
199
|
+
// Notify elements about the move
|
|
200
|
+
for (let i = updateStackFrom; i < elementStack.length; i += 1) {
|
|
201
|
+
(_b = (_a = elementStack[i]).onComponentStackChanged) === null || _b === void 0 ? void 0 : _b.call(_a, 'moved');
|
|
202
|
+
}
|
|
203
|
+
return removedElements;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Checks if the stack has a specific element
|
|
207
|
+
*
|
|
208
|
+
* @param element - Popover instance
|
|
209
|
+
* @returns True if the stack has the element, false otherwise
|
|
210
|
+
*/
|
|
211
|
+
has(element) {
|
|
212
|
+
return elementStack.includes(element);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Gets the depth of the host element in the stack
|
|
216
|
+
*/
|
|
217
|
+
getHostDepth() {
|
|
218
|
+
return this.getElementDepth(this.host);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Gets the depth of the element in the stack
|
|
222
|
+
* @param element - The element to get the depth of
|
|
223
|
+
*/
|
|
224
|
+
getElementDepth(element) {
|
|
225
|
+
return elementStack.indexOf(element);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Gets the z-index of the host element in the stack
|
|
229
|
+
*/
|
|
230
|
+
getHostZIndex() {
|
|
231
|
+
return this.getItemZIndex(this.host);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Gets the z-index of the element in the stack
|
|
235
|
+
* @param element - The element to get the z-index of
|
|
236
|
+
*
|
|
237
|
+
* @returns The z-index of the element if found, otherwise returns -1
|
|
238
|
+
*/
|
|
239
|
+
getItemZIndex(element) {
|
|
240
|
+
const depth = this.getElementDepth(element);
|
|
241
|
+
return depth >= 0 ? BASE_Z_INDEX + depth * NUMBER_OF_Z_INDEX_LEVELS_PER_ELEMENT : -1;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Checks if host is at the top of the stack
|
|
245
|
+
*
|
|
246
|
+
* @returns True if host is on top, false otherwise
|
|
247
|
+
*/
|
|
248
|
+
isHostOnTop() {
|
|
249
|
+
return this.peek() === this.host;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Clears the stack
|
|
253
|
+
*
|
|
254
|
+
* Pops all elements from the stack one-by-one.
|
|
255
|
+
*/
|
|
256
|
+
clear() {
|
|
257
|
+
this.popUntil(() => true);
|
|
258
|
+
}
|
|
259
|
+
}
|
package/dist/utils/dom.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OverflowMixinInterface } from './mixins/OverflowMixin';
|
|
1
2
|
/**
|
|
2
3
|
* nodeB precedes nodeA in either a pre-order depth-first traversal of a tree containing both
|
|
3
4
|
* (e.g., as a descendant or preceding sibling or a descendant of a preceding sibling or
|
|
@@ -107,3 +108,10 @@ export declare const findFocusable: (root: ShadowRoot | HTMLElement | null) => H
|
|
|
107
108
|
* Get the active element from the DOM, including shadow DOMs
|
|
108
109
|
*/
|
|
109
110
|
export declare const getDomActiveElement: (root?: Document) => Element | null;
|
|
111
|
+
/**
|
|
112
|
+
* Type guard to check if an element inherits the OverflowMixin.
|
|
113
|
+
*
|
|
114
|
+
* @param element - The element to check
|
|
115
|
+
* @returns True if the element has the OverflowMixin methods
|
|
116
|
+
*/
|
|
117
|
+
export declare const hasOverflowMixin: <T extends HTMLElement>(element: T) => element is T & OverflowMixinInterface;
|
package/dist/utils/dom.js
CHANGED
|
@@ -189,3 +189,10 @@ export const getDomActiveElement = (root = document) => {
|
|
|
189
189
|
activeElement = activeElement.shadowRoot.activeElement;
|
|
190
190
|
return activeElement;
|
|
191
191
|
};
|
|
192
|
+
/**
|
|
193
|
+
* Type guard to check if an element inherits the OverflowMixin.
|
|
194
|
+
*
|
|
195
|
+
* @param element - The element to check
|
|
196
|
+
* @returns True if the element has the OverflowMixin methods
|
|
197
|
+
*/
|
|
198
|
+
export const hasOverflowMixin = (element) => 'isWidthOverflowing' in element && typeof element.isWidthOverflowing === 'function';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OVERLAY_BACKDROP_Z_INDEX_OFFSET, OVERLAY_TRIGGER_Z_INDEX_OFFSET } from '../controllers/DepthManager';
|
|
1
2
|
export const BackdropMixin = (superClass) => {
|
|
2
3
|
class Backdrop extends superClass {
|
|
3
4
|
constructor() {
|
|
@@ -11,6 +12,20 @@ export const BackdropMixin = (superClass) => {
|
|
|
11
12
|
this.isBackdropInvisible = false;
|
|
12
13
|
/** @internal */
|
|
13
14
|
this.backdropElement = null;
|
|
15
|
+
/** @internal */
|
|
16
|
+
this.triggerElementCache = null;
|
|
17
|
+
}
|
|
18
|
+
update(changedProperties) {
|
|
19
|
+
var _a;
|
|
20
|
+
super.update(changedProperties);
|
|
21
|
+
if (changedProperties.has('zIndex') && this.backdropElement) {
|
|
22
|
+
// Update the backdrop z-index if the zIndex property changes
|
|
23
|
+
this.backdropElement.style.zIndex = `${this.zIndex + OVERLAY_BACKDROP_Z_INDEX_OFFSET}`;
|
|
24
|
+
const triggerEl = (_a = this.triggerElementCache) === null || _a === void 0 ? void 0 : _a.deref();
|
|
25
|
+
if (triggerEl) {
|
|
26
|
+
triggerEl.style.zIndex = `${this.zIndex + OVERLAY_TRIGGER_Z_INDEX_OFFSET}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
14
29
|
}
|
|
15
30
|
/**
|
|
16
31
|
* Creates a backdrop element with the specified class name prefix.
|
|
@@ -30,7 +45,7 @@ export const BackdropMixin = (superClass) => {
|
|
|
30
45
|
width: 100%;
|
|
31
46
|
height: 100%;
|
|
32
47
|
background: ${this.isBackdropInvisible ? `transparent` : `var(--mds-color-theme-common-overlays-secondary-normal)`};
|
|
33
|
-
z-index: ${this.zIndex
|
|
48
|
+
z-index: ${this.zIndex + OVERLAY_BACKDROP_Z_INDEX_OFFSET};
|
|
34
49
|
}
|
|
35
50
|
`;
|
|
36
51
|
backdrop.appendChild(styleElement);
|
|
@@ -63,13 +78,14 @@ export const BackdropMixin = (superClass) => {
|
|
|
63
78
|
if (!element) {
|
|
64
79
|
return;
|
|
65
80
|
}
|
|
81
|
+
this.triggerElementCache = new WeakRef(element);
|
|
66
82
|
// Store the original z-index and position of the element
|
|
67
83
|
this.elementOriginalStyle = {
|
|
68
84
|
zIndex: element.style.zIndex,
|
|
69
85
|
position: element.style.position,
|
|
70
86
|
};
|
|
71
87
|
// Set the z-index and position to ensure the element is above the backdrop
|
|
72
|
-
element.style.zIndex = `${this.zIndex
|
|
88
|
+
element.style.zIndex = `${this.zIndex + OVERLAY_TRIGGER_Z_INDEX_OFFSET}`;
|
|
73
89
|
// Only set the position to relative if it is not already set to fixed or absolute
|
|
74
90
|
if (!['fixed', 'absolute'].includes(window.getComputedStyle(element).position)) {
|
|
75
91
|
element.style.position = 'relative';
|
|
@@ -93,6 +109,7 @@ export const BackdropMixin = (superClass) => {
|
|
|
93
109
|
element.style.position = this.elementOriginalStyle.position;
|
|
94
110
|
// Clear the stored original style
|
|
95
111
|
this.elementOriginalStyle = undefined;
|
|
112
|
+
this.triggerElementCache = null;
|
|
96
113
|
}
|
|
97
114
|
}
|
|
98
115
|
return Backdrop;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import type { Constructor } from './index.types';
|
|
3
|
+
export declare abstract class OverflowMixinInterface {
|
|
4
|
+
protected get overflowElement(): HTMLElement;
|
|
5
|
+
isWidthOverflowing(): boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const OverflowMixin: <T extends Constructor<LitElement>>(superClass: T) => Constructor<OverflowMixinInterface> & T;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const OverflowMixin = (superClass) => {
|
|
2
|
+
class InnerMixinClass extends superClass {
|
|
3
|
+
/**
|
|
4
|
+
* Gets the element whose overflow will be monitored.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
get overflowElement() {
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Determines if the content of the overflow element is overflowing its width.
|
|
13
|
+
*
|
|
14
|
+
* @returns True if the scroll width of the overflow element is greater than its client width.
|
|
15
|
+
*/
|
|
16
|
+
isWidthOverflowing() {
|
|
17
|
+
const el = this.overflowElement;
|
|
18
|
+
return el.scrollWidth > el.clientWidth;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// Cast return type to your mixin's interface intersected with the superClass type
|
|
22
|
+
return InnerMixinClass;
|
|
23
|
+
};
|
package/package.json
CHANGED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type Popover from './popover.component';
|
|
2
|
-
/**
|
|
3
|
-
* Manages a stack of popovers to control their order and lifecycle.
|
|
4
|
-
* This class allows adding, removing, and retrieving popovers
|
|
5
|
-
* while maintaining their stacking behavior.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
declare class PopoverStack {
|
|
9
|
-
/**
|
|
10
|
-
* Stack to maintain the order of popovers
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
private stack;
|
|
14
|
-
/**
|
|
15
|
-
* Adds a popover to the stack
|
|
16
|
-
*
|
|
17
|
-
* @param popover - Popover instance
|
|
18
|
-
* @returns The new depth of the stack
|
|
19
|
-
*/
|
|
20
|
-
push(popover: Popover): number;
|
|
21
|
-
/**
|
|
22
|
-
* Removes the last popover from the stack
|
|
23
|
-
*
|
|
24
|
-
* @returns The last popover in the stack
|
|
25
|
-
*/
|
|
26
|
-
pop(): Popover | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* Returns the last popover in the stack
|
|
29
|
-
* without removing it
|
|
30
|
-
*
|
|
31
|
-
* @returns The last popover in the stack
|
|
32
|
-
*/
|
|
33
|
-
peek(): Popover | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* Removes a popover from the stack
|
|
36
|
-
*
|
|
37
|
-
* @param popover - Popover instance
|
|
38
|
-
*/
|
|
39
|
-
remove(popover: Popover): void;
|
|
40
|
-
/**
|
|
41
|
-
* Checks if the stack has a specific popover
|
|
42
|
-
*
|
|
43
|
-
* @param popover - Popover instance
|
|
44
|
-
* @returns True if the stack has the popover, false otherwise
|
|
45
|
-
*/
|
|
46
|
-
has(popover: Popover): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Clears the stack
|
|
49
|
-
*/
|
|
50
|
-
clear(): void;
|
|
51
|
-
}
|
|
52
|
-
export declare const popoverStack: PopoverStack;
|
|
53
|
-
export {};
|