@spectrum-web-components/overlay 0.17.1-devmode.0 → 0.18.0
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/README.md +3 -0
- package/active-overlay.js +1 -2
- package/active-overlay.js.map +1 -1
- package/overlay-trigger.js +1 -2
- package/overlay-trigger.js.map +1 -1
- package/package.json +7 -7
- package/src/ActiveOverlay.js +8 -437
- package/src/ActiveOverlay.js.map +1 -1
- package/src/OverlayTrigger.js +2 -265
- package/src/OverlayTrigger.js.map +1 -1
- package/src/VirtualTrigger.js +1 -29
- package/src/VirtualTrigger.js.map +1 -1
- package/src/active-overlay.css.js +2 -4
- package/src/active-overlay.css.js.map +1 -1
- package/src/index.js +1 -6
- package/src/index.js.map +1 -1
- package/src/loader.js +1 -4
- package/src/loader.js.map +1 -1
- package/src/overlay-events.js +1 -6
- package/src/overlay-events.js.map +1 -1
- package/src/overlay-stack.js +2 -405
- package/src/overlay-stack.js.map +1 -1
- package/src/overlay-timer.js +1 -70
- package/src/overlay-timer.js.map +1 -1
- package/src/overlay-trigger.css.js +2 -4
- package/src/overlay-trigger.css.js.map +1 -1
- package/src/overlay-utils.js +1 -27
- package/src/overlay-utils.js.map +1 -1
- package/src/overlay.js +1 -84
- package/src/overlay.js.map +1 -1
- package/stories/overlay-story-components.js +11 -207
- package/stories/overlay-story-components.js.map +1 -1
- package/stories/overlay.stories.js +55 -338
- package/stories/overlay.stories.js.map +1 -1
- package/sync/overlay-trigger.js +1 -6
- package/sync/overlay-trigger.js.map +1 -1
- package/test/benchmark/basic-test.js +1 -6
- package/test/benchmark/basic-test.js.map +1 -1
- package/test/overlay-lifecycle.test.js +6 -112
- package/test/overlay-lifecycle.test.js.map +1 -1
- package/test/overlay-timer.test.js +1 -116
- package/test/overlay-timer.test.js.map +1 -1
- package/test/overlay-trigger-click.test.js +7 -51
- package/test/overlay-trigger-click.test.js.map +1 -1
- package/test/overlay-trigger-extended.test.js +4 -174
- package/test/overlay-trigger-extended.test.js.map +1 -1
- package/test/overlay-trigger-hover-click.test.js +3 -63
- package/test/overlay-trigger-hover-click.test.js.map +1 -1
- package/test/overlay-trigger-hover.test.js +7 -81
- package/test/overlay-trigger-hover.test.js.map +1 -1
- package/test/overlay-trigger-longpress.test.js +9 -177
- package/test/overlay-trigger-longpress.test.js.map +1 -1
- package/test/overlay-trigger-sync.test.js +4 -407
- package/test/overlay-trigger-sync.test.js.map +1 -1
- package/test/overlay-trigger.test.js +4 -407
- package/test/overlay-trigger.test.js.map +1 -1
- package/test/overlay.test-vrt.js +1 -3
- package/test/overlay.test-vrt.js.map +1 -1
- package/test/overlay.test.js +11 -477
- package/test/overlay.test.js.map +1 -1
package/README.md
CHANGED
|
@@ -84,6 +84,7 @@ type OverlayOptions = {
|
|
|
84
84
|
placement?: Placement;
|
|
85
85
|
offset?: number;
|
|
86
86
|
receivesFocus?: 'auto';
|
|
87
|
+
notImmediatelyClosable?: boolean;
|
|
87
88
|
}
|
|
88
89
|
```
|
|
89
90
|
|
|
@@ -95,6 +96,8 @@ type OverlayOptions = {
|
|
|
95
96
|
|
|
96
97
|
`receivesFocus` tells the overlay stack to throw focus into the overlay after it has opened.
|
|
97
98
|
|
|
99
|
+
`notImmediatelyClosable` prevents immediate clicks from closing the overlay. If you find that a trigger event is immediately overridden with a subsequent click (for instance, a `focus` trigger that should be closed on `click`), set `notImmediatelyClosable: true` to disregard clicks that coincide with the opening trigger.
|
|
100
|
+
|
|
98
101
|
### Events
|
|
99
102
|
|
|
100
103
|
The work to both open and close an overlay is asynchronous. This asynchrony is surfaced into the application via DOM events dispatched from the `trigger` element of your overlay. An `sp-opened` event will be dispatched once the overlay has finished opening, and an `sp-closed` event will be dispatched once the overlay has finished closing. In both cases, the dispatched event will include a `detail` property with an `interaction: TriggerInteractions` key to support associating the event/overlay with its originating `interaction`.
|
package/active-overlay.js
CHANGED
package/active-overlay.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["active-overlay.ts"],
|
|
4
4
|
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { ActiveOverlay } from './src/ActiveOverlay.js';\n\ncustomElements.define('active-overlay', ActiveOverlay);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'active-overlay': ActiveOverlay;\n }\n}\n"],
|
|
5
|
-
"mappings": "AAWA
|
|
5
|
+
"mappings": "AAWA,uDAEA,eAAe,OAAO,iBAAkB,CAAa",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/overlay-trigger.js
CHANGED
package/overlay-trigger.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["overlay-trigger.ts"],
|
|
4
4
|
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { OverlayTrigger } from './src/OverlayTrigger.js';\n\ncustomElements.define('overlay-trigger', OverlayTrigger);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'overlay-trigger': OverlayTrigger;\n }\n}\n"],
|
|
5
|
-
"mappings": "AAWA
|
|
5
|
+
"mappings": "AAWA,yDAEA,eAAe,OAAO,kBAAmB,CAAc",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/overlay",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -103,10 +103,10 @@
|
|
|
103
103
|
],
|
|
104
104
|
"dependencies": {
|
|
105
105
|
"@floating-ui/dom": "^0.5.2",
|
|
106
|
-
"@spectrum-web-components/action-button": "^0.
|
|
107
|
-
"@spectrum-web-components/base": "^0.
|
|
108
|
-
"@spectrum-web-components/shared": "^0.
|
|
109
|
-
"@spectrum-web-components/theme": "^0.
|
|
106
|
+
"@spectrum-web-components/action-button": "^0.10.0",
|
|
107
|
+
"@spectrum-web-components/base": "^0.7.0",
|
|
108
|
+
"@spectrum-web-components/shared": "^0.15.0",
|
|
109
|
+
"@spectrum-web-components/theme": "^0.14.0",
|
|
110
110
|
"tslib": "^2.0.0"
|
|
111
111
|
},
|
|
112
112
|
"types": "./src/index.d.ts",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"./overlay-trigger.js",
|
|
117
117
|
"./sync/overlay-trigger.js",
|
|
118
118
|
"./stories/overlay-story-components.js",
|
|
119
|
-
"./**/*.dev.
|
|
119
|
+
"./**/*.dev.js"
|
|
120
120
|
],
|
|
121
|
-
"gitHead": "
|
|
121
|
+
"gitHead": "05c81318844160db3f8156144106e643507fef97"
|
|
122
122
|
}
|
package/src/ActiveOverlay.js
CHANGED
|
@@ -1,445 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
-
if (decorator = decorators[i])
|
|
7
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
-
if (kind && result)
|
|
9
|
-
__defProp(target, key, result);
|
|
10
|
-
return result;
|
|
11
|
-
};
|
|
12
|
-
import {
|
|
13
|
-
html,
|
|
14
|
-
SpectrumElement
|
|
15
|
-
} from "@spectrum-web-components/base";
|
|
16
|
-
import { ifDefined } from "@spectrum-web-components/base/src/directives.js";
|
|
17
|
-
import { property } from "@spectrum-web-components/base/src/decorators.js";
|
|
18
|
-
import { reparentChildren } from "@spectrum-web-components/shared/src/reparent-children.js";
|
|
19
|
-
import { firstFocusableIn } from "@spectrum-web-components/shared/src/first-focusable-in.js";
|
|
20
|
-
import styles from "./active-overlay.css.js";
|
|
21
|
-
import { parentOverlayOf } from "./overlay-utils.js";
|
|
22
|
-
import {
|
|
23
|
-
arrow,
|
|
24
|
-
computePosition,
|
|
25
|
-
flip,
|
|
26
|
-
offset,
|
|
27
|
-
shift,
|
|
28
|
-
size
|
|
29
|
-
} from "@floating-ui/dom";
|
|
30
|
-
const stateMachine = {
|
|
31
|
-
initial: "idle",
|
|
32
|
-
states: {
|
|
33
|
-
idle: {
|
|
34
|
-
on: {
|
|
35
|
-
active: "active"
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
active: {
|
|
39
|
-
on: {
|
|
40
|
-
hiding: "hiding",
|
|
41
|
-
idle: "idle"
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
hiding: {
|
|
45
|
-
on: {
|
|
46
|
-
dispose: "dispose"
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
dispose: {
|
|
50
|
-
on: {
|
|
51
|
-
disposed: "disposed"
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
disposed: {
|
|
55
|
-
on: {}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
const stateTransition = (state, event) => {
|
|
60
|
-
if (!state)
|
|
61
|
-
return stateMachine.initial;
|
|
62
|
-
if (!event)
|
|
63
|
-
return state;
|
|
64
|
-
return stateMachine.states[state].on[event] || state;
|
|
65
|
-
};
|
|
66
|
-
const getFallbackPlacements = (placement) => {
|
|
67
|
-
var _a;
|
|
68
|
-
const fallbacks = {
|
|
69
|
-
left: ["right", "bottom", "top"],
|
|
70
|
-
"left-start": ["right-start", "bottom", "top"],
|
|
71
|
-
"left-end": ["right-end", "bottom", "top"],
|
|
72
|
-
right: ["left", "bottom", "top"],
|
|
73
|
-
"right-start": ["left-start", "bottom", "top"],
|
|
74
|
-
"right-end": ["left-end", "bottom", "top"],
|
|
75
|
-
top: ["bottom", "left", "right"],
|
|
76
|
-
"top-start": ["bottom-start", "left", "right"],
|
|
77
|
-
"top-end": ["bottom-end", "left", "right"],
|
|
78
|
-
bottom: ["top", "left", "right"],
|
|
79
|
-
"bottom-start": ["top-start", "left", "right"],
|
|
80
|
-
"bottom-end": ["top-end", "left", "right"]
|
|
81
|
-
};
|
|
82
|
-
return (_a = fallbacks[placement]) != null ? _a : [placement];
|
|
83
|
-
};
|
|
84
|
-
const _ActiveOverlay = class extends SpectrumElement {
|
|
85
|
-
constructor() {
|
|
86
|
-
super();
|
|
87
|
-
this._state = stateTransition();
|
|
88
|
-
this.animating = false;
|
|
89
|
-
this.theme = {};
|
|
90
|
-
this.tabbingAway = false;
|
|
91
|
-
this.offset = 6;
|
|
92
|
-
this.skidding = 0;
|
|
93
|
-
this.interaction = "hover";
|
|
94
|
-
this.positionAnimationFrame = 0;
|
|
95
|
-
this.willNotifyClosed = false;
|
|
96
|
-
this.isConstrained = false;
|
|
97
|
-
this.updateOverlayPosition = async () => {
|
|
98
|
-
if (!this.placement || this.placement === "none") {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
await (document.fonts ? document.fonts.ready : Promise.resolve());
|
|
102
|
-
function roundByDPR(num) {
|
|
103
|
-
const dpr = window.devicePixelRatio || 1;
|
|
104
|
-
return Math.round(num * dpr) / dpr || -1e4;
|
|
105
|
-
}
|
|
106
|
-
const REQUIRED_DISTANCE_TO_EDGE = 8;
|
|
107
|
-
const MIN_OVERLAY_HEIGHT = 100;
|
|
108
|
-
const flipMiddleware = this.virtualTrigger ? flip({
|
|
109
|
-
padding: REQUIRED_DISTANCE_TO_EDGE,
|
|
110
|
-
fallbackPlacements: getFallbackPlacements(this.placement)
|
|
111
|
-
}) : flip({
|
|
112
|
-
padding: REQUIRED_DISTANCE_TO_EDGE
|
|
113
|
-
});
|
|
114
|
-
const middleware = [
|
|
115
|
-
offset({
|
|
116
|
-
mainAxis: this.offset,
|
|
117
|
-
crossAxis: this.skidding
|
|
118
|
-
}),
|
|
119
|
-
shift({ padding: REQUIRED_DISTANCE_TO_EDGE }),
|
|
120
|
-
flipMiddleware,
|
|
121
|
-
size({
|
|
122
|
-
padding: REQUIRED_DISTANCE_TO_EDGE,
|
|
123
|
-
apply: ({
|
|
124
|
-
availableWidth,
|
|
125
|
-
availableHeight,
|
|
126
|
-
rects: { floating }
|
|
127
|
-
}) => {
|
|
128
|
-
const maxHeight = Math.max(MIN_OVERLAY_HEIGHT, Math.floor(availableHeight));
|
|
129
|
-
const actualHeight = floating.height;
|
|
130
|
-
this.initialHeight = !this.isConstrained && !this.virtualTrigger ? actualHeight : this.initialHeight || actualHeight;
|
|
131
|
-
this.isConstrained = actualHeight < this.initialHeight || maxHeight <= actualHeight;
|
|
132
|
-
const appliedHeight = this.isConstrained ? `${maxHeight}px` : "";
|
|
133
|
-
Object.assign(this.style, {
|
|
134
|
-
maxWidth: `${Math.floor(availableWidth)}px`,
|
|
135
|
-
maxHeight: appliedHeight,
|
|
136
|
-
height: appliedHeight
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
];
|
|
141
|
-
if (this.overlayContentTip) {
|
|
142
|
-
middleware.push(arrow({ element: this.overlayContentTip }));
|
|
143
|
-
}
|
|
144
|
-
const { x, y, placement, middlewareData } = await computePosition(this.virtualTrigger || this.trigger, this, {
|
|
145
|
-
placement: this.placement,
|
|
146
|
-
middleware
|
|
147
|
-
});
|
|
148
|
-
Object.assign(this.style, {
|
|
149
|
-
top: "0px",
|
|
150
|
-
left: "0px",
|
|
151
|
-
transform: `translate(${roundByDPR(x)}px, ${roundByDPR(y)}px)`
|
|
152
|
-
});
|
|
153
|
-
if (placement !== this.getAttribute("actual-placement")) {
|
|
154
|
-
this.setAttribute("actual-placement", placement);
|
|
155
|
-
this.overlayContent.setAttribute("placement", placement);
|
|
156
|
-
}
|
|
157
|
-
if (this.overlayContentTip && middlewareData.arrow) {
|
|
158
|
-
const { x: arrowX, y: arrowY } = middlewareData.arrow;
|
|
159
|
-
Object.assign(this.overlayContentTip.style, {
|
|
160
|
-
left: arrowX != null ? `${roundByDPR(arrowX)}px` : "",
|
|
161
|
-
top: arrowY != null ? `${roundByDPR(arrowY)}px` : "",
|
|
162
|
-
right: "",
|
|
163
|
-
bottom: ""
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
this.handleInlineTriggerKeydown = (event) => {
|
|
168
|
-
const { code, shiftKey } = event;
|
|
169
|
-
if (code !== "Tab")
|
|
170
|
-
return;
|
|
171
|
-
if (shiftKey) {
|
|
172
|
-
this.tabbingAway = true;
|
|
173
|
-
this.dispatchEvent(new Event("close"));
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
event.stopPropagation();
|
|
177
|
-
event.preventDefault();
|
|
178
|
-
this.focus();
|
|
179
|
-
};
|
|
180
|
-
this.stealOverlayContentPromise = Promise.resolve();
|
|
181
|
-
this.stealOverlayContentPromise = new Promise((res) => this.stealOverlayContentResolver = res);
|
|
182
|
-
}
|
|
183
|
-
get state() {
|
|
184
|
-
return this._state;
|
|
185
|
-
}
|
|
186
|
-
set state(state) {
|
|
187
|
-
const nextState = stateTransition(this.state, state);
|
|
188
|
-
if (nextState === this.state) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
this._state = nextState;
|
|
192
|
-
if (this.state === "active" || this.state === "hiding") {
|
|
193
|
-
this.setAttribute("state", this.state);
|
|
194
|
-
} else {
|
|
195
|
-
this.removeAttribute("state");
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
async focus() {
|
|
199
|
-
const firstFocusable = firstFocusableIn(this);
|
|
200
|
-
if (firstFocusable) {
|
|
201
|
-
if (firstFocusable.updateComplete) {
|
|
202
|
-
await firstFocusable.updateComplete;
|
|
203
|
-
}
|
|
204
|
-
const activeElement = this.getRootNode().activeElement;
|
|
205
|
-
if (activeElement === this || !this.contains(activeElement)) {
|
|
206
|
-
firstFocusable.focus();
|
|
207
|
-
}
|
|
208
|
-
} else {
|
|
209
|
-
super.focus();
|
|
210
|
-
}
|
|
211
|
-
this.removeAttribute("tabindex");
|
|
212
|
-
}
|
|
213
|
-
get hasTheme() {
|
|
214
|
-
return !!this.theme.color || !!this.theme.scale || !!this.theme.lang;
|
|
215
|
-
}
|
|
216
|
-
static get styles() {
|
|
217
|
-
return [styles];
|
|
218
|
-
}
|
|
219
|
-
get hasModalRoot() {
|
|
220
|
-
return !!this._modalRoot;
|
|
221
|
-
}
|
|
222
|
-
feature() {
|
|
223
|
-
this.tabIndex = -1;
|
|
224
|
-
const parentOverlay = parentOverlayOf(this.trigger);
|
|
225
|
-
const parentIsModal = parentOverlay && parentOverlay.slot === "open";
|
|
226
|
-
if (parentIsModal) {
|
|
227
|
-
this._modalRoot = parentOverlay._modalRoot || parentOverlay;
|
|
228
|
-
}
|
|
229
|
-
if (this.interaction === "modal" || this._modalRoot) {
|
|
230
|
-
this.slot = "open";
|
|
231
|
-
if (this.interaction === "modal") {
|
|
232
|
-
this.setAttribute("aria-modal", "true");
|
|
233
|
-
}
|
|
234
|
-
if (this._modalRoot) {
|
|
235
|
-
parentOverlay == null ? void 0 : parentOverlay.feature();
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
obscure(nextOverlayInteraction) {
|
|
240
|
-
if (this.slot && nextOverlayInteraction === "modal") {
|
|
241
|
-
this.removeAttribute("slot");
|
|
242
|
-
this.removeAttribute("aria-modal");
|
|
243
|
-
if (this.interaction !== "modal") {
|
|
244
|
-
const parentOverlay = parentOverlayOf(this.trigger);
|
|
245
|
-
this._modalRoot = parentOverlay == null ? void 0 : parentOverlay.obscure(nextOverlayInteraction);
|
|
246
|
-
return this._modalRoot;
|
|
247
|
-
}
|
|
248
|
-
return this;
|
|
249
|
-
}
|
|
250
|
-
return void 0;
|
|
251
|
-
}
|
|
252
|
-
async willUpdate() {
|
|
253
|
-
if (this.hasUpdated)
|
|
254
|
-
return;
|
|
255
|
-
if (!this.overlayContent || !this.trigger)
|
|
256
|
-
return;
|
|
257
|
-
this.stealOverlayContent(this.overlayContent);
|
|
258
|
-
this.state = "active";
|
|
259
|
-
this.feature();
|
|
260
|
-
if (this.placement === "none") {
|
|
261
|
-
this.style.setProperty("--swc-visual-viewport-height", `${window.innerHeight}px`);
|
|
262
|
-
} else if (this.placement) {
|
|
263
|
-
await this.updateOverlayPosition();
|
|
264
|
-
document.addEventListener("sp-update-overlays", this.updateOverlayPosition);
|
|
265
|
-
window.addEventListener("scroll", this.updateOverlayPosition);
|
|
266
|
-
}
|
|
267
|
-
const actions = [];
|
|
268
|
-
if (this.placement && this.placement !== "none") {
|
|
269
|
-
actions.push(this.applyContentAnimation("sp-overlay-fade-in"));
|
|
270
|
-
}
|
|
271
|
-
if (typeof this.overlayContent.updateComplete !== "undefined") {
|
|
272
|
-
actions.push(this.overlayContent.updateComplete);
|
|
273
|
-
}
|
|
274
|
-
this.childrenReady = Promise.all(actions);
|
|
275
|
-
}
|
|
276
|
-
async openCallback(lifecycleCallback) {
|
|
277
|
-
await this.updateComplete;
|
|
278
|
-
if (this.receivesFocus) {
|
|
279
|
-
await this.focus();
|
|
280
|
-
}
|
|
281
|
-
await lifecycleCallback();
|
|
282
|
-
this.trigger.dispatchEvent(new CustomEvent("sp-opened", {
|
|
283
|
-
bubbles: true,
|
|
284
|
-
composed: true,
|
|
285
|
-
cancelable: true,
|
|
286
|
-
detail: {
|
|
287
|
-
interaction: this.interaction
|
|
288
|
-
}
|
|
289
|
-
}));
|
|
290
|
-
}
|
|
291
|
-
open(openDetail) {
|
|
292
|
-
this.extractDetail(openDetail);
|
|
293
|
-
}
|
|
294
|
-
extractDetail(detail) {
|
|
295
|
-
this.overlayContent = detail.content;
|
|
296
|
-
this.overlayContentTip = detail.contentTip;
|
|
297
|
-
this.trigger = detail.trigger;
|
|
298
|
-
this.virtualTrigger = detail.virtualTrigger;
|
|
299
|
-
this.placement = detail.placement;
|
|
300
|
-
this.offset = detail.offset;
|
|
301
|
-
this.skidding = detail.skidding || 0;
|
|
302
|
-
this.interaction = detail.interaction;
|
|
303
|
-
this.theme = detail.theme;
|
|
304
|
-
this.receivesFocus = detail.receivesFocus;
|
|
305
|
-
this.root = detail.root;
|
|
306
|
-
}
|
|
307
|
-
dispose() {
|
|
308
|
-
if (this.state !== "dispose")
|
|
309
|
-
return;
|
|
310
|
-
if (this.timeout) {
|
|
311
|
-
clearTimeout(this.timeout);
|
|
312
|
-
delete this.timeout;
|
|
313
|
-
}
|
|
314
|
-
this.trigger.removeEventListener("keydown", this.handleInlineTriggerKeydown);
|
|
315
|
-
this.returnOverlayContent();
|
|
316
|
-
this.state = "disposed";
|
|
317
|
-
if (this.willNotifyClosed) {
|
|
318
|
-
this.overlayContent.dispatchEvent(new Event("sp-overlay-closed"));
|
|
319
|
-
this.willNotifyClosed = false;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
stealOverlayContent(element) {
|
|
323
|
-
this.originalPlacement = element.getAttribute("placement");
|
|
324
|
-
this.restoreContent = reparentChildren([element], this, {
|
|
325
|
-
position: "beforeend",
|
|
326
|
-
prepareCallback: (el) => {
|
|
327
|
-
const slotName = el.slot;
|
|
328
|
-
const placement = el.placement;
|
|
329
|
-
el.removeAttribute("slot");
|
|
330
|
-
return (el2) => {
|
|
331
|
-
el2.slot = slotName;
|
|
332
|
-
el2.placement = placement;
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
this.stealOverlayContentResolver();
|
|
337
|
-
}
|
|
338
|
-
returnOverlayContent() {
|
|
339
|
-
if (!this.restoreContent)
|
|
340
|
-
return;
|
|
341
|
-
const [element] = this.restoreContent();
|
|
342
|
-
this.restoreContent = void 0;
|
|
343
|
-
this.willNotifyClosed = true;
|
|
344
|
-
if (this.originalPlacement) {
|
|
345
|
-
element.setAttribute("placement", this.originalPlacement);
|
|
346
|
-
delete this.originalPlacement;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
async hide(animated = true) {
|
|
350
|
-
this.state = "hiding";
|
|
351
|
-
if (animated) {
|
|
352
|
-
await this.applyContentAnimation("sp-overlay-fade-out");
|
|
353
|
-
}
|
|
354
|
-
this.state = "dispose";
|
|
355
|
-
}
|
|
356
|
-
schedulePositionUpdate() {
|
|
357
|
-
cancelAnimationFrame(this.positionAnimationFrame);
|
|
358
|
-
this.positionAnimationFrame = requestAnimationFrame(() => this.updateOverlayPosition());
|
|
359
|
-
}
|
|
360
|
-
onSlotChange() {
|
|
361
|
-
this.schedulePositionUpdate();
|
|
362
|
-
}
|
|
363
|
-
applyContentAnimation(animation) {
|
|
364
|
-
if (this.placement === "none") {
|
|
365
|
-
return Promise.resolve(true);
|
|
366
|
-
}
|
|
367
|
-
return new Promise((resolve) => {
|
|
368
|
-
const contents = this.shadowRoot.querySelector("#contents");
|
|
369
|
-
const doneHandler = (event) => {
|
|
370
|
-
if (animation !== event.animationName)
|
|
371
|
-
return;
|
|
372
|
-
contents.removeEventListener("animationend", doneHandler);
|
|
373
|
-
contents.removeEventListener("animationcancel", doneHandler);
|
|
374
|
-
this.animating = false;
|
|
375
|
-
resolve(event.type === "animationcancel");
|
|
376
|
-
};
|
|
377
|
-
contents.addEventListener("animationend", doneHandler);
|
|
378
|
-
contents.addEventListener("animationcancel", doneHandler);
|
|
379
|
-
contents.style.animationName = animation;
|
|
380
|
-
this.animating = true;
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
renderTheme(content) {
|
|
384
|
-
const { color, scale, lang, theme } = this.theme;
|
|
385
|
-
return html`
|
|
1
|
+
var E=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var l=(s,t,e,i)=>{for(var o=i>1?void 0:i?R(t,e):t,n=s.length-1,p;n>=0;n--)(p=s[n])&&(o=(i?p(t,e,o):p(o))||o);return i&&o&&E(t,e,o),o};import{html as y,SpectrumElement as A}from"@spectrum-web-components/base";import{ifDefined as h}from"@spectrum-web-components/base/src/directives.js";import{property as c}from"@spectrum-web-components/base/src/decorators.js";import{reparentChildren as x}from"@spectrum-web-components/shared/src/reparent-children.js";import{firstFocusableIn as S}from"@spectrum-web-components/shared/src/first-focusable-in.js";import H from"./active-overlay.css.js";import{parentOverlayOf as b}from"./overlay-utils.js";import{arrow as L,computePosition as F,flip as C,offset as I,shift as M,size as k}from"@floating-ui/dom";const P={initial:"idle",states:{idle:{on:{active:"active"}},active:{on:{hiding:"hiding",idle:"idle"}},hiding:{on:{dispose:"dispose"}},dispose:{on:{disposed:"disposed"}},disposed:{on:{}}}},T=(s,t)=>s?t&&P.states[s].on[t]||s:P.initial,D=s=>{var e;return(e={left:["right","bottom","top"],"left-start":["right-start","bottom","top"],"left-end":["right-end","bottom","top"],right:["left","bottom","top"],"right-start":["left-start","bottom","top"],"right-end":["left-end","bottom","top"],top:["bottom","left","right"],"top-start":["bottom-start","left","right"],"top-end":["bottom-end","left","right"],bottom:["top","left","right"],"bottom-start":["top-start","left","right"],"bottom-end":["top-end","left","right"]}[s])!=null?e:[s]},u=class extends A{constructor(){super();this._state=T();this.animating=!1;this.theme={};this.tabbingAway=!1;this.offset=6;this.skidding=0;this.interaction="hover";this.positionAnimationFrame=0;this.willNotifyClosed=!1;this.isConstrained=!1;this.updateOverlayPosition=async()=>{if(!this.placement||this.placement==="none")return;await(document.fonts?document.fonts.ready:Promise.resolve());function t(r){const a=window.devicePixelRatio||1;return Math.round(r*a)/a||-1e4}const e=8,i=100,o=this.virtualTrigger?C({padding:e,fallbackPlacements:D(this.placement)}):C({padding:e}),n=[I({mainAxis:this.offset,crossAxis:this.skidding}),M({padding:e}),o,k({padding:e,apply:({availableWidth:r,availableHeight:a,rects:{floating:O}})=>{const f=Math.max(i,Math.floor(a)),m=O.height;this.initialHeight=!this.isConstrained&&!this.virtualTrigger?m:this.initialHeight||m,this.isConstrained=m<this.initialHeight||f<=m;const g=this.isConstrained?`${f}px`:"";Object.assign(this.style,{maxWidth:`${Math.floor(r)}px`,maxHeight:g,height:g})}})];this.overlayContentTip&&n.push(L({element:this.overlayContentTip}));const{x:p,y:w,placement:d,middlewareData:v}=await F(this.virtualTrigger||this.trigger,this,{placement:this.placement,middleware:n});if(Object.assign(this.style,{top:"0px",left:"0px",transform:`translate(${t(p)}px, ${t(w)}px)`}),d!==this.getAttribute("actual-placement")&&(this.setAttribute("actual-placement",d),this.overlayContent.setAttribute("placement",d)),this.overlayContentTip&&v.arrow){const{x:r,y:a}=v.arrow;Object.assign(this.overlayContentTip.style,{left:r!=null?`${t(r)}px`:"",top:a!=null?`${t(a)}px`:"",right:"",bottom:""})}};this.handleInlineTriggerKeydown=t=>{const{code:e,shiftKey:i}=t;if(e==="Tab"){if(i){this.tabbingAway=!0,this.dispatchEvent(new Event("close"));return}t.stopPropagation(),t.preventDefault(),this.focus()}};this.stealOverlayContentPromise=Promise.resolve();this.stealOverlayContentPromise=new Promise(t=>this.stealOverlayContentResolver=t)}get state(){return this._state}set state(t){const e=T(this.state,t);e!==this.state&&(this._state=e,this.state==="active"||this.state==="hiding"?this.setAttribute("state",this.state):this.removeAttribute("state"))}async focus(){const t=S(this);if(t){t.updateComplete&&await t.updateComplete;const e=this.getRootNode().activeElement;(e===this||!this.contains(e))&&t.focus()}else super.focus();this.removeAttribute("tabindex")}get hasTheme(){return!!this.theme.color||!!this.theme.scale||!!this.theme.lang}static get styles(){return[H]}get hasModalRoot(){return!!this._modalRoot}feature(){this.tabIndex=-1;const t=b(this.trigger);t&&t.slot==="open"&&(this._modalRoot=t._modalRoot||t),(this.interaction==="modal"||this._modalRoot)&&(this.slot="open",this.interaction==="modal"&&this.setAttribute("aria-modal","true"),this._modalRoot&&(t==null||t.feature()))}obscure(t){if(this.slot&&t==="modal"){if(this.removeAttribute("slot"),this.removeAttribute("aria-modal"),this.interaction!=="modal"){const e=b(this.trigger);return this._modalRoot=e==null?void 0:e.obscure(t),this._modalRoot}return this}}async willUpdate(){if(this.hasUpdated||!this.overlayContent||!this.trigger)return;this.stealOverlayContent(this.overlayContent),this.state="active",this.feature(),this.placement==="none"?this.style.setProperty("--swc-visual-viewport-height",`${window.innerHeight}px`):this.placement&&(await this.updateOverlayPosition(),document.addEventListener("sp-update-overlays",this.updateOverlayPosition),window.addEventListener("scroll",this.updateOverlayPosition));const t=[];this.placement&&this.placement!=="none"&&t.push(this.applyContentAnimation("sp-overlay-fade-in")),typeof this.overlayContent.updateComplete!="undefined"&&t.push(this.overlayContent.updateComplete),this.childrenReady=Promise.all(t)}async openCallback(t){await this.updateComplete,this.receivesFocus&&await this.focus(),await t(),this.trigger.dispatchEvent(new CustomEvent("sp-opened",{bubbles:!0,composed:!0,cancelable:!0,detail:{interaction:this.interaction}}))}open(t){this.extractDetail(t)}extractDetail(t){this.overlayContent=t.content,this.overlayContentTip=t.contentTip,this.trigger=t.trigger,this.virtualTrigger=t.virtualTrigger,this.placement=t.placement,this.offset=t.offset,this.skidding=t.skidding||0,this.interaction=t.interaction,this.theme=t.theme,this.receivesFocus=t.receivesFocus,this.root=t.root}dispose(){this.state==="dispose"&&(this.timeout&&(clearTimeout(this.timeout),delete this.timeout),this.trigger.removeEventListener("keydown",this.handleInlineTriggerKeydown),this.returnOverlayContent(),this.state="disposed",this.willNotifyClosed&&(this.overlayContent.dispatchEvent(new Event("sp-overlay-closed")),this.willNotifyClosed=!1))}stealOverlayContent(t){this.originalPlacement=t.getAttribute("placement"),this.restoreContent=x([t],this,{position:"beforeend",prepareCallback:e=>{const i=e.slot,o=e.placement;return e.removeAttribute("slot"),n=>{n.slot=i,n.placement=o}}}),this.stealOverlayContentResolver()}returnOverlayContent(){if(!this.restoreContent)return;const[t]=this.restoreContent();this.restoreContent=void 0,this.willNotifyClosed=!0,this.originalPlacement&&(t.setAttribute("placement",this.originalPlacement),delete this.originalPlacement)}async hide(t=!0){this.state="hiding",t&&await this.applyContentAnimation("sp-overlay-fade-out"),this.state="dispose"}schedulePositionUpdate(){cancelAnimationFrame(this.positionAnimationFrame),this.positionAnimationFrame=requestAnimationFrame(()=>this.updateOverlayPosition())}onSlotChange(){this.schedulePositionUpdate()}applyContentAnimation(t){return this.placement==="none"?Promise.resolve(!0):new Promise(e=>{const i=this.shadowRoot.querySelector("#contents"),o=n=>{t===n.animationName&&(i.removeEventListener("animationend",o),i.removeEventListener("animationcancel",o),this.animating=!1,e(n.type==="animationcancel"))};i.addEventListener("animationend",o),i.addEventListener("animationcancel",o),i.style.animationName=t,this.animating=!0})}renderTheme(t){const{color:e,scale:i,lang:o,theme:n}=this.theme;return y`
|
|
386
2
|
<sp-theme
|
|
387
|
-
theme=${
|
|
388
|
-
color=${
|
|
389
|
-
scale=${
|
|
390
|
-
lang=${
|
|
3
|
+
theme=${h(n)}
|
|
4
|
+
color=${h(e)}
|
|
5
|
+
scale=${h(i)}
|
|
6
|
+
lang=${h(o)}
|
|
391
7
|
part="theme"
|
|
392
8
|
>
|
|
393
|
-
${
|
|
9
|
+
${t}
|
|
394
10
|
</sp-theme>
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
render() {
|
|
398
|
-
const content = html`
|
|
11
|
+
`}render(){const t=y`
|
|
399
12
|
<div id="contents">
|
|
400
13
|
<slot @slotchange=${this.onSlotChange}></slot>
|
|
401
14
|
</div>
|
|
402
|
-
`;
|
|
403
|
-
return this.hasTheme ? this.renderTheme(content) : content;
|
|
404
|
-
}
|
|
405
|
-
static create(details) {
|
|
406
|
-
const overlay = new _ActiveOverlay();
|
|
407
|
-
if (details.content) {
|
|
408
|
-
overlay.open(details);
|
|
409
|
-
}
|
|
410
|
-
return overlay;
|
|
411
|
-
}
|
|
412
|
-
async getUpdateComplete() {
|
|
413
|
-
const actions = [
|
|
414
|
-
super.getUpdateComplete(),
|
|
415
|
-
this.stealOverlayContentPromise
|
|
416
|
-
];
|
|
417
|
-
if (this.childrenReady) {
|
|
418
|
-
actions.push(this.childrenReady);
|
|
419
|
-
}
|
|
420
|
-
const [complete] = await Promise.all(actions);
|
|
421
|
-
return complete;
|
|
422
|
-
}
|
|
423
|
-
disconnectedCallback() {
|
|
424
|
-
document.removeEventListener("sp-update-overlays", this.updateOverlayPosition);
|
|
425
|
-
window.removeEventListener("scroll", this.updateOverlayPosition);
|
|
426
|
-
super.disconnectedCallback();
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
export let ActiveOverlay = _ActiveOverlay;
|
|
430
|
-
__decorateClass([
|
|
431
|
-
property()
|
|
432
|
-
], ActiveOverlay.prototype, "_state", 2);
|
|
433
|
-
__decorateClass([
|
|
434
|
-
property({ reflect: true, type: Boolean })
|
|
435
|
-
], ActiveOverlay.prototype, "animating", 2);
|
|
436
|
-
__decorateClass([
|
|
437
|
-
property({ reflect: true })
|
|
438
|
-
], ActiveOverlay.prototype, "placement", 2);
|
|
439
|
-
__decorateClass([
|
|
440
|
-
property({ attribute: false })
|
|
441
|
-
], ActiveOverlay.prototype, "theme", 2);
|
|
442
|
-
__decorateClass([
|
|
443
|
-
property({ attribute: false })
|
|
444
|
-
], ActiveOverlay.prototype, "receivesFocus", 2);
|
|
15
|
+
`;return this.hasTheme?this.renderTheme(t):t}static create(t){const e=new u;return t.content&&e.open(t),e}async getUpdateComplete(){const t=[super.getUpdateComplete(),this.stealOverlayContentPromise];this.childrenReady&&t.push(this.childrenReady);const[e]=await Promise.all(t);return e}disconnectedCallback(){document.removeEventListener("sp-update-overlays",this.updateOverlayPosition),window.removeEventListener("scroll",this.updateOverlayPosition),super.disconnectedCallback()}};export let ActiveOverlay=u;l([c()],ActiveOverlay.prototype,"_state",2),l([c({reflect:!0,type:Boolean})],ActiveOverlay.prototype,"animating",2),l([c({reflect:!0})],ActiveOverlay.prototype,"placement",2),l([c({attribute:!1})],ActiveOverlay.prototype,"theme",2),l([c({attribute:!1})],ActiveOverlay.prototype,"receivesFocus",2);
|
|
445
16
|
//# sourceMappingURL=ActiveOverlay.js.map
|