@spectrum-web-components/overlay 0.16.4 → 0.16.6-devmode.7

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 (93) 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 +68 -14
  10. package/src/ActiveOverlay.dev.js +445 -0
  11. package/src/ActiveOverlay.dev.js.map +7 -0
  12. package/src/ActiveOverlay.js +404 -424
  13. package/src/ActiveOverlay.js.map +7 -1
  14. package/src/OverlayTrigger.dev.js +293 -0
  15. package/src/OverlayTrigger.dev.js.map +7 -0
  16. package/src/OverlayTrigger.js +245 -264
  17. package/src/OverlayTrigger.js.map +7 -1
  18. package/src/VirtualTrigger.dev.js +30 -0
  19. package/src/VirtualTrigger.dev.js.map +7 -0
  20. package/src/VirtualTrigger.js +28 -38
  21. package/src/VirtualTrigger.js.map +7 -1
  22. package/src/active-overlay.css.dev.js +12 -0
  23. package/src/active-overlay.css.dev.js.map +7 -0
  24. package/src/active-overlay.css.js +3 -14
  25. package/src/active-overlay.css.js.map +7 -1
  26. package/src/index.dev.js +7 -0
  27. package/src/index.dev.js.map +7 -0
  28. package/src/index.js +7 -18
  29. package/src/index.js.map +7 -1
  30. package/src/loader.dev.js +5 -0
  31. package/src/loader.dev.js.map +7 -0
  32. package/src/loader.js +3 -14
  33. package/src/loader.js.map +7 -1
  34. package/src/overlay-events.dev.js +7 -0
  35. package/src/overlay-events.dev.js.map +7 -0
  36. package/src/overlay-events.js +5 -16
  37. package/src/overlay-events.js.map +7 -1
  38. package/src/overlay-stack.dev.js +436 -0
  39. package/src/overlay-stack.dev.js.map +7 -0
  40. package/src/overlay-stack.js +374 -420
  41. package/src/overlay-stack.js.map +7 -1
  42. package/src/overlay-timer.dev.js +71 -0
  43. package/src/overlay-timer.dev.js.map +7 -0
  44. package/src/overlay-timer.js +64 -82
  45. package/src/overlay-timer.js.map +7 -1
  46. package/src/overlay-trigger.css.dev.js +6 -0
  47. package/src/overlay-trigger.css.dev.js.map +7 -0
  48. package/src/overlay-trigger.css.js +3 -14
  49. package/src/overlay-trigger.css.js.map +7 -1
  50. package/src/overlay-types.dev.js +1 -0
  51. package/src/overlay-types.dev.js.map +7 -0
  52. package/src/overlay-types.js +1 -13
  53. package/src/overlay-types.js.map +7 -1
  54. package/src/overlay-utils.dev.js +28 -0
  55. package/src/overlay-utils.dev.js.map +7 -0
  56. package/src/overlay-utils.js +22 -33
  57. package/src/overlay-utils.js.map +7 -1
  58. package/src/overlay.dev.js +85 -0
  59. package/src/overlay.dev.js.map +7 -0
  60. package/src/overlay.js +83 -119
  61. package/src/overlay.js.map +7 -1
  62. package/stories/overlay-story-components.js +188 -184
  63. package/stories/overlay-story-components.js.map +7 -1
  64. package/stories/overlay.stories.js +238 -228
  65. package/stories/overlay.stories.js.map +7 -1
  66. package/sync/overlay-trigger.dev.js +7 -0
  67. package/sync/overlay-trigger.dev.js.map +7 -0
  68. package/sync/overlay-trigger.js +5 -16
  69. package/sync/overlay-trigger.js.map +7 -1
  70. package/test/benchmark/basic-test.js +7 -18
  71. package/test/benchmark/basic-test.js.map +7 -1
  72. package/test/overlay-lifecycle.test.js +107 -115
  73. package/test/overlay-lifecycle.test.js.map +7 -1
  74. package/test/overlay-timer.test.js +110 -122
  75. package/test/overlay-timer.test.js.map +7 -1
  76. package/test/overlay-trigger-click.test.js +43 -48
  77. package/test/overlay-trigger-click.test.js.map +7 -1
  78. package/test/overlay-trigger-extended.test.js +167 -182
  79. package/test/overlay-trigger-extended.test.js.map +7 -1
  80. package/test/overlay-trigger-hover-click.test.js +59 -73
  81. package/test/overlay-trigger-hover-click.test.js.map +7 -1
  82. package/test/overlay-trigger-hover.test.js +74 -77
  83. package/test/overlay-trigger-hover.test.js.map +7 -1
  84. package/test/overlay-trigger-longpress.test.js +166 -178
  85. package/test/overlay-trigger-longpress.test.js.map +7 -1
  86. package/test/overlay-trigger-sync.test.js +400 -422
  87. package/test/overlay-trigger-sync.test.js.map +7 -1
  88. package/test/overlay-trigger.test.js +400 -422
  89. package/test/overlay-trigger.test.js.map +7 -1
  90. package/test/overlay.test-vrt.js +4 -15
  91. package/test/overlay.test-vrt.js.map +7 -1
  92. package/test/overlay.test.js +458 -479
  93. package/test/overlay.test.js.map +7 -1
@@ -1,409 +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: ({ availableWidth, availableHeight, rects: { floating }, }) => {
125
- const maxHeight = Math.max(MIN_OVERLAY_HEIGHT, Math.floor(availableHeight));
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(availableWidth)}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 willUpdate() {
267
- if (this.hasUpdated)
268
- return;
269
- /* c8 ignore next */
270
- if (!this.overlayContent || !this.trigger)
271
- return;
272
- this.stealOverlayContent(this.overlayContent);
273
- this.state = 'active';
274
- this.feature();
275
- if (this.placement === 'none') {
276
- this.style.setProperty('--swc-visual-viewport-height', `${window.innerHeight}px`);
277
- }
278
- else if (this.placement) {
279
- await this.updateOverlayPosition();
280
- document.addEventListener('sp-update-overlays', this.updateOverlayPosition);
281
- window.addEventListener('scroll', this.updateOverlayPosition);
282
- }
283
- const actions = [];
284
- if (this.placement && this.placement !== 'none') {
285
- actions.push(this.applyContentAnimation('sp-overlay-fade-in'));
286
- }
287
- if (typeof this.overlayContent.updateComplete !==
288
- 'undefined') {
289
- actions.push(this.overlayContent.updateComplete);
290
- }
291
- this.childrenReady = Promise.all(actions);
267
+ const actions = [];
268
+ if (this.placement && this.placement !== "none") {
269
+ actions.push(this.applyContentAnimation("sp-overlay-fade-in"));
292
270
  }
293
- async openCallback(lifecycleCallback) {
294
- await this.updateComplete;
295
- if (this.receivesFocus) {
296
- await this.focus();
297
- }
298
- await lifecycleCallback();
299
- this.trigger.dispatchEvent(new CustomEvent('sp-opened', {
300
- bubbles: true,
301
- composed: true,
302
- cancelable: true,
303
- detail: {
304
- interaction: this.interaction,
305
- },
306
- }));
271
+ if (typeof this.overlayContent.updateComplete !== "undefined") {
272
+ actions.push(this.overlayContent.updateComplete);
307
273
  }
308
- open(openDetail) {
309
- 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();
310
280
  }
311
- extractDetail(detail) {
312
- this.overlayContent = detail.content;
313
- this.overlayContentTip = detail.contentTip;
314
- this.trigger = detail.trigger;
315
- this.virtualTrigger = detail.virtualTrigger;
316
- this.placement = detail.placement;
317
- this.offset = detail.offset;
318
- this.skidding = detail.skidding || 0;
319
- this.interaction = detail.interaction;
320
- this.theme = detail.theme;
321
- this.receivesFocus = detail.receivesFocus;
322
- 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;
323
313
  }
324
- dispose() {
325
- /* c8 ignore next */
326
- if (this.state !== 'dispose')
327
- return;
328
- /* c8 ignore next 4 */
329
- if (this.timeout) {
330
- clearTimeout(this.timeout);
331
- delete this.timeout;
332
- }
333
- this.trigger.removeEventListener('keydown', this.handleInlineTriggerKeydown);
334
- this.returnOverlayContent();
335
- this.state = 'disposed';
336
- if (this.willNotifyClosed) {
337
- this.overlayContent.dispatchEvent(new Event('sp-overlay-closed'));
338
- this.willNotifyClosed = false;
339
- }
340
- }
341
- stealOverlayContent(element) {
342
- this.originalPlacement = element.getAttribute('placement');
343
- this.restoreContent = reparentChildren([element], this, {
344
- position: 'beforeend',
345
- prepareCallback: (el) => {
346
- const slotName = el.slot;
347
- const placement = el.placement;
348
- el.removeAttribute('slot');
349
- return (el) => {
350
- el.slot = slotName;
351
- el.placement = placement;
352
- };
353
- },
354
- });
355
- 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;
356
320
  }
357
- returnOverlayContent() {
358
- /* c8 ignore next */
359
- if (!this.restoreContent)
360
- return;
361
- const [element] = this.restoreContent();
362
- this.restoreContent = undefined;
363
- this.willNotifyClosed = true;
364
- if (this.originalPlacement) {
365
- element.setAttribute('placement', this.originalPlacement);
366
- delete this.originalPlacement;
367
- }
368
- }
369
- async hide(animated = true) {
370
- this.state = 'hiding';
371
- if (animated) {
372
- await this.applyContentAnimation('sp-overlay-fade-out');
373
- }
374
- 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;
375
347
  }
376
- schedulePositionUpdate() {
377
- // Edge needs a little time to update the DOM before computing the layout
378
- cancelAnimationFrame(this.positionAnimationFrame);
379
- 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");
380
353
  }
381
- onSlotChange() {
382
- 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);
383
366
  }
384
- applyContentAnimation(animation) {
385
- if (this.placement === 'none') {
386
- return Promise.resolve(true);
387
- }
388
- return new Promise((resolve) => {
389
- const contents = this.shadowRoot.querySelector('#contents');
390
- const doneHandler = (event) => {
391
- if (animation !== event.animationName)
392
- return;
393
- contents.removeEventListener('animationend', doneHandler);
394
- contents.removeEventListener('animationcancel', doneHandler);
395
- this.animating = false;
396
- resolve(event.type === 'animationcancel');
397
- };
398
- contents.addEventListener('animationend', doneHandler);
399
- contents.addEventListener('animationcancel', doneHandler);
400
- contents.style.animationName = animation;
401
- this.animating = true;
402
- });
403
- }
404
- renderTheme(content) {
405
- const { color, scale, lang, theme } = this.theme;
406
- 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`
407
386
  <sp-theme
408
387
  theme=${ifDefined(theme)}
409
388
  color=${ifDefined(color)}
@@ -414,52 +393,53 @@ export class ActiveOverlay extends SpectrumElement {
414
393
  ${content}
415
394
  </sp-theme>
416
395
  `;
417
- }
418
- render() {
419
- const content = html `
396
+ }
397
+ render() {
398
+ const content = html`
420
399
  <div id="contents">
421
400
  <slot @slotchange=${this.onSlotChange}></slot>
422
401
  </div>
423
402
  `;
424
- 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);
425
409
  }
426
- static create(details) {
427
- const overlay = new ActiveOverlay();
428
- if (details.content) {
429
- overlay.open(details);
430
- }
431
- 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);
432
419
  }
433
- async getUpdateComplete() {
434
- const actions = [
435
- super.getUpdateComplete(),
436
- this.stealOverlayContentPromise,
437
- ];
438
- if (this.childrenReady) {
439
- actions.push(this.childrenReady);
440
- }
441
- const [complete] = await Promise.all(actions);
442
- return complete;
443
- }
444
- disconnectedCallback() {
445
- document.removeEventListener('sp-update-overlays', this.updateOverlayPosition);
446
- window.removeEventListener('scroll', this.updateOverlayPosition);
447
- super.disconnectedCallback();
448
- }
449
- }
450
- __decorate([
451
- property()
452
- ], ActiveOverlay.prototype, "_state", void 0);
453
- __decorate([
454
- property({ reflect: true, type: Boolean })
455
- ], ActiveOverlay.prototype, "animating", void 0);
456
- __decorate([
457
- property({ reflect: true })
458
- ], ActiveOverlay.prototype, "placement", void 0);
459
- __decorate([
460
- property({ attribute: false })
461
- ], ActiveOverlay.prototype, "theme", void 0);
462
- __decorate([
463
- property({ attribute: false })
464
- ], ActiveOverlay.prototype, "receivesFocus", void 0);
465
- //# 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