@spectrum-web-components/overlay 0.16.3 → 0.16.6-devmode.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/active-overlay.dev.js +3 -0
- package/active-overlay.dev.js.map +7 -0
- package/active-overlay.js +3 -14
- package/active-overlay.js.map +7 -1
- package/overlay-trigger.dev.js +3 -0
- package/overlay-trigger.dev.js.map +7 -0
- package/overlay-trigger.js +3 -14
- package/overlay-trigger.js.map +7 -1
- package/package.json +69 -15
- package/src/ActiveOverlay.d.ts +2 -2
- package/src/ActiveOverlay.dev.js +445 -0
- package/src/ActiveOverlay.dev.js.map +7 -0
- package/src/ActiveOverlay.js +404 -423
- package/src/ActiveOverlay.js.map +7 -1
- package/src/OverlayTrigger.dev.js +293 -0
- package/src/OverlayTrigger.dev.js.map +7 -0
- package/src/OverlayTrigger.js +245 -264
- package/src/OverlayTrigger.js.map +7 -1
- package/src/VirtualTrigger.dev.js +30 -0
- package/src/VirtualTrigger.dev.js.map +7 -0
- package/src/VirtualTrigger.js +28 -38
- package/src/VirtualTrigger.js.map +7 -1
- package/src/active-overlay.css.dev.js +12 -0
- package/src/active-overlay.css.dev.js.map +7 -0
- package/src/active-overlay.css.js +3 -14
- package/src/active-overlay.css.js.map +7 -1
- package/src/index.dev.js +7 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +7 -18
- package/src/index.js.map +7 -1
- package/src/loader.dev.js +5 -0
- package/src/loader.dev.js.map +7 -0
- package/src/loader.js +3 -14
- package/src/loader.js.map +7 -1
- package/src/overlay-events.d.ts +11 -0
- package/src/overlay-events.dev.js +7 -0
- package/src/overlay-events.dev.js.map +7 -0
- package/src/overlay-events.js +7 -0
- package/src/overlay-events.js.map +7 -0
- package/src/overlay-stack.d.ts +2 -0
- package/src/overlay-stack.dev.js +436 -0
- package/src/overlay-stack.dev.js.map +7 -0
- package/src/overlay-stack.js +374 -419
- package/src/overlay-stack.js.map +7 -1
- package/src/overlay-timer.dev.js +71 -0
- package/src/overlay-timer.dev.js.map +7 -0
- package/src/overlay-timer.js +64 -82
- package/src/overlay-timer.js.map +7 -1
- package/src/overlay-trigger.css.dev.js +6 -0
- package/src/overlay-trigger.css.dev.js.map +7 -0
- package/src/overlay-trigger.css.js +3 -14
- package/src/overlay-trigger.css.js.map +7 -1
- package/src/overlay-types.dev.js +1 -0
- package/src/overlay-types.dev.js.map +7 -0
- package/src/overlay-types.js +1 -13
- package/src/overlay-types.js.map +7 -1
- package/src/overlay-utils.dev.js +28 -0
- package/src/overlay-utils.dev.js.map +7 -0
- package/src/overlay-utils.js +22 -33
- package/src/overlay-utils.js.map +7 -1
- package/src/overlay.dev.js +85 -0
- package/src/overlay.dev.js.map +7 -0
- package/src/overlay.js +83 -119
- package/src/overlay.js.map +7 -1
- package/stories/overlay-story-components.js +188 -184
- package/stories/overlay-story-components.js.map +7 -1
- package/stories/overlay.stories.js +238 -228
- package/stories/overlay.stories.js.map +7 -1
- package/sync/overlay-trigger.dev.js +7 -0
- package/sync/overlay-trigger.dev.js.map +7 -0
- package/sync/overlay-trigger.js +5 -16
- package/sync/overlay-trigger.js.map +7 -1
- package/test/benchmark/basic-test.js +7 -18
- package/test/benchmark/basic-test.js.map +7 -1
- package/test/overlay-lifecycle.test.js +107 -115
- package/test/overlay-lifecycle.test.js.map +7 -1
- package/test/overlay-timer.test.js +110 -122
- package/test/overlay-timer.test.js.map +7 -1
- package/test/overlay-trigger-click.test.js +43 -48
- package/test/overlay-trigger-click.test.js.map +7 -1
- package/test/overlay-trigger-extended.test.js +167 -182
- package/test/overlay-trigger-extended.test.js.map +7 -1
- package/test/overlay-trigger-hover-click.test.js +59 -73
- package/test/overlay-trigger-hover-click.test.js.map +7 -1
- package/test/overlay-trigger-hover.test.js +74 -77
- package/test/overlay-trigger-hover.test.js.map +7 -1
- package/test/overlay-trigger-longpress.test.js +166 -178
- package/test/overlay-trigger-longpress.test.js.map +7 -1
- package/test/overlay-trigger-sync.test.js +400 -422
- package/test/overlay-trigger-sync.test.js.map +7 -1
- package/test/overlay-trigger.test.js +400 -422
- package/test/overlay-trigger.test.js.map +7 -1
- package/test/overlay.test-vrt.js +4 -15
- package/test/overlay.test-vrt.js.map +7 -1
- package/test/overlay.test.js +458 -479
- package/test/overlay.test.js.map +7 -1
package/src/ActiveOverlay.js
CHANGED
|
@@ -1,408 +1,388 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
20
|
-
import
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
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";
|
|
21
30
|
const stateMachine = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
disposed: {
|
|
46
|
-
on: {},
|
|
47
|
-
},
|
|
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
|
+
}
|
|
48
53
|
},
|
|
54
|
+
disposed: {
|
|
55
|
+
on: {}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
49
58
|
};
|
|
50
59
|
const stateTransition = (state, event) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return stateMachine.states[state].on[event] || state;
|
|
60
|
+
if (!state)
|
|
61
|
+
return stateMachine.initial;
|
|
62
|
+
if (!event)
|
|
63
|
+
return state;
|
|
64
|
+
return stateMachine.states[state].on[event] || state;
|
|
57
65
|
};
|
|
58
66
|
const getFallbackPlacements = (placement) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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];
|
|
75
83
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const maxHeight = Math.max(MIN_OVERLAY_HEIGHT, Math.floor(height));
|
|
126
|
-
const actualHeight = floating.height;
|
|
127
|
-
this.initialHeight =
|
|
128
|
-
!this.isConstrained && !this.virtualTrigger
|
|
129
|
-
? actualHeight
|
|
130
|
-
: this.initialHeight || actualHeight;
|
|
131
|
-
this.isConstrained =
|
|
132
|
-
actualHeight < this.initialHeight ||
|
|
133
|
-
maxHeight <= actualHeight;
|
|
134
|
-
const appliedHeight = this.isConstrained
|
|
135
|
-
? `${maxHeight}px`
|
|
136
|
-
: '';
|
|
137
|
-
Object.assign(this.style, {
|
|
138
|
-
maxWidth: `${Math.floor(width)}px`,
|
|
139
|
-
maxHeight: appliedHeight,
|
|
140
|
-
height: appliedHeight,
|
|
141
|
-
});
|
|
142
|
-
},
|
|
143
|
-
}),
|
|
144
|
-
];
|
|
145
|
-
if (this.overlayContentTip) {
|
|
146
|
-
middleware.push(arrow({ element: this.overlayContentTip }));
|
|
147
|
-
}
|
|
148
|
-
const { x, y, placement, middlewareData } = await computePosition(this.virtualTrigger || this.trigger, this, {
|
|
149
|
-
placement: this.placement,
|
|
150
|
-
middleware,
|
|
151
|
-
});
|
|
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` : "";
|
|
152
133
|
Object.assign(this.style, {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
134
|
+
maxWidth: `${Math.floor(availableWidth)}px`,
|
|
135
|
+
maxHeight: appliedHeight,
|
|
136
|
+
height: appliedHeight
|
|
156
137
|
});
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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;
|
|
203
190
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
const activeElement = this.getRootNode()
|
|
211
|
-
.activeElement;
|
|
212
|
-
if (activeElement === this || !this.contains(activeElement)) {
|
|
213
|
-
firstFocusable.focus();
|
|
214
|
-
}
|
|
215
|
-
/* c8 ignore next 3 */
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
super.focus();
|
|
219
|
-
}
|
|
220
|
-
this.removeAttribute('tabindex');
|
|
191
|
+
this._state = nextState;
|
|
192
|
+
if (this.state === "active" || this.state === "hiding") {
|
|
193
|
+
this.setAttribute("state", this.state);
|
|
194
|
+
} else {
|
|
195
|
+
this.removeAttribute("state");
|
|
221
196
|
}
|
|
222
|
-
|
|
223
|
-
|
|
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();
|
|
224
210
|
}
|
|
225
|
-
|
|
226
|
-
|
|
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;
|
|
227
228
|
}
|
|
228
|
-
|
|
229
|
-
|
|
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
|
+
}
|
|
230
237
|
}
|
|
231
|
-
|
|
232
|
-
|
|
238
|
+
}
|
|
239
|
+
obscure(nextOverlayInteraction) {
|
|
240
|
+
if (this.slot && nextOverlayInteraction === "modal") {
|
|
241
|
+
this.removeAttribute("slot");
|
|
242
|
+
this.removeAttribute("aria-modal");
|
|
243
|
+
if (this.interaction !== "modal") {
|
|
233
244
|
const parentOverlay = parentOverlayOf(this.trigger);
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
// If an overlay it triggered from within a "modal" overlay, it needs to continue
|
|
239
|
-
// to act like one to get treated correctly in regards to tab trapping.
|
|
240
|
-
if (this.interaction === 'modal' || this._modalRoot) {
|
|
241
|
-
this.slot = 'open';
|
|
242
|
-
if (this.interaction === 'modal') {
|
|
243
|
-
this.setAttribute('aria-modal', 'true');
|
|
244
|
-
}
|
|
245
|
-
// If this isn't a modal root, walk up the overlays to the next modal root
|
|
246
|
-
// and "feature" each on of the intervening overlays.
|
|
247
|
-
if (this._modalRoot) {
|
|
248
|
-
parentOverlay === null || parentOverlay === void 0 ? void 0 : parentOverlay.feature();
|
|
249
|
-
}
|
|
250
|
-
}
|
|
245
|
+
this._modalRoot = parentOverlay == null ? void 0 : parentOverlay.obscure(nextOverlayInteraction);
|
|
246
|
+
return this._modalRoot;
|
|
247
|
+
}
|
|
248
|
+
return this;
|
|
251
249
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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);
|
|
265
266
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if (!this.overlayContent || !this.trigger)
|
|
270
|
-
return;
|
|
271
|
-
this.stealOverlayContent(this.overlayContent);
|
|
272
|
-
this.state = 'active';
|
|
273
|
-
this.feature();
|
|
274
|
-
if (this.placement === 'none') {
|
|
275
|
-
this.style.setProperty('--swc-visual-viewport-height', `${window.innerHeight}px`);
|
|
276
|
-
}
|
|
277
|
-
else if (this.placement) {
|
|
278
|
-
await this.updateOverlayPosition();
|
|
279
|
-
document.addEventListener('sp-update-overlays', this.updateOverlayPosition);
|
|
280
|
-
window.addEventListener('scroll', this.updateOverlayPosition);
|
|
281
|
-
}
|
|
282
|
-
const actions = [];
|
|
283
|
-
if (this.placement && this.placement !== 'none') {
|
|
284
|
-
actions.push(this.applyContentAnimation('sp-overlay-fade-in'));
|
|
285
|
-
}
|
|
286
|
-
if (typeof this.overlayContent.updateComplete !==
|
|
287
|
-
'undefined') {
|
|
288
|
-
actions.push(this.overlayContent.updateComplete);
|
|
289
|
-
}
|
|
290
|
-
this.childrenReady = Promise.all(actions);
|
|
267
|
+
const actions = [];
|
|
268
|
+
if (this.placement && this.placement !== "none") {
|
|
269
|
+
actions.push(this.applyContentAnimation("sp-overlay-fade-in"));
|
|
291
270
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
if (this.receivesFocus) {
|
|
295
|
-
await this.focus();
|
|
296
|
-
}
|
|
297
|
-
await lifecycleCallback();
|
|
298
|
-
this.trigger.dispatchEvent(new CustomEvent('sp-opened', {
|
|
299
|
-
bubbles: true,
|
|
300
|
-
composed: true,
|
|
301
|
-
cancelable: true,
|
|
302
|
-
detail: {
|
|
303
|
-
interaction: this.interaction,
|
|
304
|
-
},
|
|
305
|
-
}));
|
|
271
|
+
if (typeof this.overlayContent.updateComplete !== "undefined") {
|
|
272
|
+
actions.push(this.overlayContent.updateComplete);
|
|
306
273
|
}
|
|
307
|
-
|
|
308
|
-
|
|
274
|
+
this.childrenReady = Promise.all(actions);
|
|
275
|
+
}
|
|
276
|
+
async openCallback(lifecycleCallback) {
|
|
277
|
+
await this.updateComplete;
|
|
278
|
+
if (this.receivesFocus) {
|
|
279
|
+
await this.focus();
|
|
309
280
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
this.
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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;
|
|
322
313
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
clearTimeout(this.timeout);
|
|
330
|
-
delete this.timeout;
|
|
331
|
-
}
|
|
332
|
-
this.trigger.removeEventListener('keydown', this.handleInlineTriggerKeydown);
|
|
333
|
-
this.returnOverlayContent();
|
|
334
|
-
this.state = 'disposed';
|
|
335
|
-
if (this.willNotifyClosed) {
|
|
336
|
-
this.overlayContent.dispatchEvent(new Event('sp-overlay-closed'));
|
|
337
|
-
this.willNotifyClosed = false;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
stealOverlayContent(element) {
|
|
341
|
-
this.originalPlacement = element.getAttribute('placement');
|
|
342
|
-
this.restoreContent = reparentChildren([element], this, {
|
|
343
|
-
position: 'beforeend',
|
|
344
|
-
prepareCallback: (el) => {
|
|
345
|
-
const slotName = el.slot;
|
|
346
|
-
const placement = el.placement;
|
|
347
|
-
el.removeAttribute('slot');
|
|
348
|
-
return (el) => {
|
|
349
|
-
el.slot = slotName;
|
|
350
|
-
el.placement = placement;
|
|
351
|
-
};
|
|
352
|
-
},
|
|
353
|
-
});
|
|
354
|
-
this.stealOverlayContentResolver();
|
|
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;
|
|
355
320
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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;
|
|
374
347
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
348
|
+
}
|
|
349
|
+
async hide(animated = true) {
|
|
350
|
+
this.state = "hiding";
|
|
351
|
+
if (animated) {
|
|
352
|
+
await this.applyContentAnimation("sp-overlay-fade-out");
|
|
379
353
|
}
|
|
380
|
-
|
|
381
|
-
|
|
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);
|
|
382
366
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
renderTheme(content) {
|
|
404
|
-
const { color, scale, lang, theme } = this.theme;
|
|
405
|
-
return html `
|
|
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`
|
|
406
386
|
<sp-theme
|
|
407
387
|
theme=${ifDefined(theme)}
|
|
408
388
|
color=${ifDefined(color)}
|
|
@@ -413,52 +393,53 @@ export class ActiveOverlay extends SpectrumElement {
|
|
|
413
393
|
${content}
|
|
414
394
|
</sp-theme>
|
|
415
395
|
`;
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
396
|
+
}
|
|
397
|
+
render() {
|
|
398
|
+
const content = html`
|
|
419
399
|
<div id="contents">
|
|
420
400
|
<slot @slotchange=${this.onSlotChange}></slot>
|
|
421
401
|
</div>
|
|
422
402
|
`;
|
|
423
|
-
|
|
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);
|
|
424
409
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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);
|
|
431
419
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
__decorate([
|
|
459
|
-
property({ attribute: false })
|
|
460
|
-
], ActiveOverlay.prototype, "theme", void 0);
|
|
461
|
-
__decorate([
|
|
462
|
-
property({ attribute: false })
|
|
463
|
-
], ActiveOverlay.prototype, "receivesFocus", void 0);
|
|
464
|
-
//# sourceMappingURL=ActiveOverlay.js.map
|
|
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);
|
|
445
|
+
//# sourceMappingURL=ActiveOverlay.js.map
|