@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.
Files changed (96) hide show
  1. package/active-overlay.dev.js +3 -0
  2. package/active-overlay.dev.js.map +7 -0
  3. package/active-overlay.js +3 -14
  4. package/active-overlay.js.map +7 -1
  5. package/overlay-trigger.dev.js +3 -0
  6. package/overlay-trigger.dev.js.map +7 -0
  7. package/overlay-trigger.js +3 -14
  8. package/overlay-trigger.js.map +7 -1
  9. package/package.json +69 -15
  10. package/src/ActiveOverlay.d.ts +2 -2
  11. package/src/ActiveOverlay.dev.js +445 -0
  12. package/src/ActiveOverlay.dev.js.map +7 -0
  13. package/src/ActiveOverlay.js +404 -423
  14. package/src/ActiveOverlay.js.map +7 -1
  15. package/src/OverlayTrigger.dev.js +293 -0
  16. package/src/OverlayTrigger.dev.js.map +7 -0
  17. package/src/OverlayTrigger.js +245 -264
  18. package/src/OverlayTrigger.js.map +7 -1
  19. package/src/VirtualTrigger.dev.js +30 -0
  20. package/src/VirtualTrigger.dev.js.map +7 -0
  21. package/src/VirtualTrigger.js +28 -38
  22. package/src/VirtualTrigger.js.map +7 -1
  23. package/src/active-overlay.css.dev.js +12 -0
  24. package/src/active-overlay.css.dev.js.map +7 -0
  25. package/src/active-overlay.css.js +3 -14
  26. package/src/active-overlay.css.js.map +7 -1
  27. package/src/index.dev.js +7 -0
  28. package/src/index.dev.js.map +7 -0
  29. package/src/index.js +7 -18
  30. package/src/index.js.map +7 -1
  31. package/src/loader.dev.js +5 -0
  32. package/src/loader.dev.js.map +7 -0
  33. package/src/loader.js +3 -14
  34. package/src/loader.js.map +7 -1
  35. package/src/overlay-events.d.ts +11 -0
  36. package/src/overlay-events.dev.js +7 -0
  37. package/src/overlay-events.dev.js.map +7 -0
  38. package/src/overlay-events.js +7 -0
  39. package/src/overlay-events.js.map +7 -0
  40. package/src/overlay-stack.d.ts +2 -0
  41. package/src/overlay-stack.dev.js +436 -0
  42. package/src/overlay-stack.dev.js.map +7 -0
  43. package/src/overlay-stack.js +374 -419
  44. package/src/overlay-stack.js.map +7 -1
  45. package/src/overlay-timer.dev.js +71 -0
  46. package/src/overlay-timer.dev.js.map +7 -0
  47. package/src/overlay-timer.js +64 -82
  48. package/src/overlay-timer.js.map +7 -1
  49. package/src/overlay-trigger.css.dev.js +6 -0
  50. package/src/overlay-trigger.css.dev.js.map +7 -0
  51. package/src/overlay-trigger.css.js +3 -14
  52. package/src/overlay-trigger.css.js.map +7 -1
  53. package/src/overlay-types.dev.js +1 -0
  54. package/src/overlay-types.dev.js.map +7 -0
  55. package/src/overlay-types.js +1 -13
  56. package/src/overlay-types.js.map +7 -1
  57. package/src/overlay-utils.dev.js +28 -0
  58. package/src/overlay-utils.dev.js.map +7 -0
  59. package/src/overlay-utils.js +22 -33
  60. package/src/overlay-utils.js.map +7 -1
  61. package/src/overlay.dev.js +85 -0
  62. package/src/overlay.dev.js.map +7 -0
  63. package/src/overlay.js +83 -119
  64. package/src/overlay.js.map +7 -1
  65. package/stories/overlay-story-components.js +188 -184
  66. package/stories/overlay-story-components.js.map +7 -1
  67. package/stories/overlay.stories.js +238 -228
  68. package/stories/overlay.stories.js.map +7 -1
  69. package/sync/overlay-trigger.dev.js +7 -0
  70. package/sync/overlay-trigger.dev.js.map +7 -0
  71. package/sync/overlay-trigger.js +5 -16
  72. package/sync/overlay-trigger.js.map +7 -1
  73. package/test/benchmark/basic-test.js +7 -18
  74. package/test/benchmark/basic-test.js.map +7 -1
  75. package/test/overlay-lifecycle.test.js +107 -115
  76. package/test/overlay-lifecycle.test.js.map +7 -1
  77. package/test/overlay-timer.test.js +110 -122
  78. package/test/overlay-timer.test.js.map +7 -1
  79. package/test/overlay-trigger-click.test.js +43 -48
  80. package/test/overlay-trigger-click.test.js.map +7 -1
  81. package/test/overlay-trigger-extended.test.js +167 -182
  82. package/test/overlay-trigger-extended.test.js.map +7 -1
  83. package/test/overlay-trigger-hover-click.test.js +59 -73
  84. package/test/overlay-trigger-hover-click.test.js.map +7 -1
  85. package/test/overlay-trigger-hover.test.js +74 -77
  86. package/test/overlay-trigger-hover.test.js.map +7 -1
  87. package/test/overlay-trigger-longpress.test.js +166 -178
  88. package/test/overlay-trigger-longpress.test.js.map +7 -1
  89. package/test/overlay-trigger-sync.test.js +400 -422
  90. package/test/overlay-trigger-sync.test.js.map +7 -1
  91. package/test/overlay-trigger.test.js +400 -422
  92. package/test/overlay-trigger.test.js.map +7 -1
  93. package/test/overlay.test-vrt.js +4 -15
  94. package/test/overlay.test-vrt.js.map +7 -1
  95. package/test/overlay.test.js +458 -479
  96. package/test/overlay.test.js.map +7 -1
@@ -1,408 +1,388 @@
1
- /*
2
- Copyright 2020 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
- */
12
- import { __decorate } from "tslib";
13
- import { html, SpectrumElement, } from '@spectrum-web-components/base';
14
- import { ifDefined } from '@spectrum-web-components/base/src/directives.js';
15
- import { property } from '@spectrum-web-components/base/src/decorators.js';
16
- import { reparentChildren } from '@spectrum-web-components/shared/src/reparent-children.js';
17
- import { firstFocusableIn } from '@spectrum-web-components/shared/src/first-focusable-in.js';
18
- import styles from './active-overlay.css.js';
19
- import { parentOverlayOf } from './overlay-utils.js';
20
- import { arrow, computePosition, flip, offset, shift, size, } from '@floating-ui/dom';
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
- initial: 'idle',
23
- states: {
24
- idle: {
25
- on: {
26
- active: 'active',
27
- },
28
- },
29
- active: {
30
- on: {
31
- hiding: 'hiding',
32
- idle: 'idle',
33
- },
34
- },
35
- hiding: {
36
- on: {
37
- dispose: 'dispose',
38
- },
39
- },
40
- dispose: {
41
- on: {
42
- disposed: 'disposed',
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
- if (!state)
52
- return stateMachine.initial;
53
- /* c8 ignore next */
54
- if (!event)
55
- return state;
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
- var _a;
60
- const fallbacks = {
61
- left: ['right', 'bottom', 'top'],
62
- 'left-start': ['right-start', 'bottom', 'top'],
63
- 'left-end': ['right-end', 'bottom', 'top'],
64
- right: ['left', 'bottom', 'top'],
65
- 'right-start': ['left-start', 'bottom', 'top'],
66
- 'right-end': ['left-end', 'bottom', 'top'],
67
- top: ['bottom', 'left', 'right'],
68
- 'top-start': ['bottom-start', 'left', 'right'],
69
- 'top-end': ['bottom-end', 'left', 'right'],
70
- bottom: ['top', 'left', 'right'],
71
- 'bottom-start': ['top-start', 'left', 'right'],
72
- 'bottom-end': ['top-end', 'left', 'right'],
73
- };
74
- return (_a = fallbacks[placement]) !== null && _a !== void 0 ? _a : [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];
75
83
  };
76
- /**
77
- * @element active-overlay
78
- *
79
- * @slot - content to display in the overlay
80
- */
81
- export class ActiveOverlay extends SpectrumElement {
82
- constructor() {
83
- super();
84
- this._state = stateTransition();
85
- this.animating = false;
86
- this.theme = {};
87
- this.tabbingAway = false;
88
- this.offset = 6;
89
- this.skidding = 0;
90
- this.interaction = 'hover';
91
- this.positionAnimationFrame = 0;
92
- this.willNotifyClosed = false;
93
- this.isConstrained = false;
94
- this.updateOverlayPosition = async () => {
95
- if (!this.placement || this.placement === 'none') {
96
- return;
97
- }
98
- await (document.fonts ? document.fonts.ready : Promise.resolve());
99
- function roundByDPR(num) {
100
- const dpr = window.devicePixelRatio || 1;
101
- return Math.round(num * dpr) / dpr || -10000;
102
- }
103
- // See: https://spectrum.adobe.com/page/popover/#Container-padding
104
- const REQUIRED_DISTANCE_TO_EDGE = 8;
105
- // See: https://github.com/adobe/spectrum-web-components/issues/910
106
- const MIN_OVERLAY_HEIGHT = 100;
107
- const flipMiddleware = this.virtualTrigger
108
- ? flip({
109
- padding: REQUIRED_DISTANCE_TO_EDGE,
110
- fallbackPlacements: getFallbackPlacements(this.placement),
111
- })
112
- : flip({
113
- padding: REQUIRED_DISTANCE_TO_EDGE,
114
- });
115
- const middleware = [
116
- offset({
117
- mainAxis: this.offset,
118
- crossAxis: this.skidding,
119
- }),
120
- shift({ padding: REQUIRED_DISTANCE_TO_EDGE }),
121
- flipMiddleware,
122
- size({
123
- padding: REQUIRED_DISTANCE_TO_EDGE,
124
- apply: ({ width, height, floating }) => {
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
- top: '0px',
154
- left: '0px',
155
- transform: `translate(${roundByDPR(x)}px, ${roundByDPR(y)}px)`,
134
+ maxWidth: `${Math.floor(availableWidth)}px`,
135
+ maxHeight: appliedHeight,
136
+ height: appliedHeight
156
137
  });
157
- if (placement !== this.getAttribute('actual-placement')) {
158
- this.setAttribute('actual-placement', placement);
159
- this.overlayContent.setAttribute('placement', placement);
160
- }
161
- if (this.overlayContentTip && middlewareData.arrow) {
162
- const { x: arrowX, y: arrowY } = middlewareData.arrow;
163
- Object.assign(this.overlayContentTip.style, {
164
- left: arrowX != null ? `${roundByDPR(arrowX)}px` : '',
165
- top: arrowY != null ? `${roundByDPR(arrowY)}px` : '',
166
- right: '',
167
- bottom: '',
168
- });
169
- }
170
- };
171
- this.handleInlineTriggerKeydown = (event) => {
172
- const { code, shiftKey } = event;
173
- /* c8 ignore next */
174
- if (code !== 'Tab')
175
- return;
176
- if (shiftKey) {
177
- this.tabbingAway = true;
178
- this.dispatchEvent(new Event('close'));
179
- return;
180
- }
181
- event.stopPropagation();
182
- event.preventDefault();
183
- this.focus();
184
- };
185
- this.stealOverlayContentPromise = Promise.resolve();
186
- this.stealOverlayContentPromise = new Promise((res) => (this.stealOverlayContentResolver = res));
187
- }
188
- get state() {
189
- return this._state;
190
- }
191
- set state(state) {
192
- const nextState = stateTransition(this.state, state);
193
- if (nextState === this.state) {
194
- return;
195
- }
196
- this._state = nextState;
197
- if (this.state === 'active' || this.state === 'hiding') {
198
- this.setAttribute('state', this.state);
199
- }
200
- else {
201
- this.removeAttribute('state');
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
- async focus() {
205
- const firstFocusable = firstFocusableIn(this);
206
- if (firstFocusable) {
207
- if (firstFocusable.updateComplete) {
208
- await firstFocusable.updateComplete;
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
- get hasTheme() {
223
- return !!this.theme.color || !!this.theme.scale || !!this.theme.lang;
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
- static get styles() {
226
- return [styles];
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
- get hasModalRoot() {
229
- return !!this._modalRoot;
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
- feature() {
232
- this.tabIndex = -1;
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
- const parentIsModal = parentOverlay && parentOverlay.slot === 'open';
235
- if (parentIsModal) {
236
- this._modalRoot = parentOverlay._modalRoot || parentOverlay;
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
- obscure(nextOverlayInteraction) {
253
- if (this.slot && nextOverlayInteraction === 'modal') {
254
- this.removeAttribute('slot');
255
- this.removeAttribute('aria-modal');
256
- // Obscure upto and including the next modal root.
257
- if (this.interaction !== 'modal') {
258
- const parentOverlay = parentOverlayOf(this.trigger);
259
- this._modalRoot = parentOverlay === null || parentOverlay === void 0 ? void 0 : parentOverlay.obscure(nextOverlayInteraction);
260
- return this._modalRoot;
261
- }
262
- return this;
263
- }
264
- return undefined;
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
- async firstUpdated(changedProperties) {
267
- super.firstUpdated(changedProperties);
268
- /* c8 ignore next */
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
- async openCallback(lifecycleCallback) {
293
- await this.updateComplete;
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
- open(openDetail) {
308
- this.extractDetail(openDetail);
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
- extractDetail(detail) {
311
- this.overlayContent = detail.content;
312
- this.overlayContentTip = detail.contentTip;
313
- this.trigger = detail.trigger;
314
- this.virtualTrigger = detail.virtualTrigger;
315
- this.placement = detail.placement;
316
- this.offset = detail.offset;
317
- this.skidding = detail.skidding || 0;
318
- this.interaction = detail.interaction;
319
- this.theme = detail.theme;
320
- this.receivesFocus = detail.receivesFocus;
321
- this.root = detail.root;
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
- dispose() {
324
- /* c8 ignore next */
325
- if (this.state !== 'dispose')
326
- return;
327
- /* c8 ignore next 4 */
328
- if (this.timeout) {
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
- returnOverlayContent() {
357
- /* c8 ignore next */
358
- if (!this.restoreContent)
359
- return;
360
- const [element] = this.restoreContent();
361
- this.restoreContent = undefined;
362
- this.willNotifyClosed = true;
363
- if (this.originalPlacement) {
364
- element.setAttribute('placement', this.originalPlacement);
365
- delete this.originalPlacement;
366
- }
367
- }
368
- async hide(animated = true) {
369
- this.state = 'hiding';
370
- if (animated) {
371
- await this.applyContentAnimation('sp-overlay-fade-out');
372
- }
373
- this.state = 'dispose';
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
- schedulePositionUpdate() {
376
- // Edge needs a little time to update the DOM before computing the layout
377
- cancelAnimationFrame(this.positionAnimationFrame);
378
- this.positionAnimationFrame = requestAnimationFrame(() => this.updateOverlayPosition());
348
+ }
349
+ async hide(animated = true) {
350
+ this.state = "hiding";
351
+ if (animated) {
352
+ await this.applyContentAnimation("sp-overlay-fade-out");
379
353
  }
380
- onSlotChange() {
381
- this.schedulePositionUpdate();
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
- applyContentAnimation(animation) {
384
- if (this.placement === 'none') {
385
- return Promise.resolve(true);
386
- }
387
- return new Promise((resolve) => {
388
- const contents = this.shadowRoot.querySelector('#contents');
389
- const doneHandler = (event) => {
390
- if (animation !== event.animationName)
391
- return;
392
- contents.removeEventListener('animationend', doneHandler);
393
- contents.removeEventListener('animationcancel', doneHandler);
394
- this.animating = false;
395
- resolve(event.type === 'animationcancel');
396
- };
397
- contents.addEventListener('animationend', doneHandler);
398
- contents.addEventListener('animationcancel', doneHandler);
399
- contents.style.animationName = animation;
400
- this.animating = true;
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
- render() {
418
- const content = html `
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
- return this.hasTheme ? this.renderTheme(content) : content;
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
- static create(details) {
426
- const overlay = new ActiveOverlay();
427
- if (details.content) {
428
- overlay.open(details);
429
- }
430
- return overlay;
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
- async getUpdateComplete() {
433
- const actions = [
434
- super.getUpdateComplete(),
435
- this.stealOverlayContentPromise,
436
- ];
437
- if (this.childrenReady) {
438
- actions.push(this.childrenReady);
439
- }
440
- const [complete] = await Promise.all(actions);
441
- return complete;
442
- }
443
- disconnectedCallback() {
444
- document.removeEventListener('sp-update-overlays', this.updateOverlayPosition);
445
- window.removeEventListener('scroll', this.updateOverlayPosition);
446
- super.disconnectedCallback();
447
- }
448
- }
449
- __decorate([
450
- property()
451
- ], ActiveOverlay.prototype, "_state", void 0);
452
- __decorate([
453
- property({ reflect: true, type: Boolean })
454
- ], ActiveOverlay.prototype, "animating", void 0);
455
- __decorate([
456
- property({ reflect: true })
457
- ], ActiveOverlay.prototype, "placement", void 0);
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