@spectrum-web-components/overlay 0.13.1 → 0.13.3
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/custom-elements.json +97 -135
- package/package.json +6 -6
- package/src/ActiveOverlay.d.ts +7 -14
- package/src/ActiveOverlay.js +93 -94
- package/src/ActiveOverlay.js.map +1 -1
- package/src/OverlayTrigger.d.ts +12 -3
- package/src/OverlayTrigger.js +52 -10
- package/src/OverlayTrigger.js.map +1 -1
- package/src/VirtualTrigger.d.ts +1 -2
- package/src/VirtualTrigger.js.map +1 -1
- package/src/active-overlay.css.js +1 -1
- package/src/active-overlay.css.js.map +1 -1
- package/src/overlay-stack.d.ts +2 -0
- package/src/overlay-stack.js +39 -28
- package/src/overlay-stack.js.map +1 -1
- package/src/overlay-trigger.css.js +1 -1
- package/src/overlay-trigger.css.js.map +1 -1
- package/src/overlay-types.d.ts +3 -3
- package/src/overlay-types.js.map +1 -1
- package/stories/overlay.stories.js +1 -1
- package/stories/overlay.stories.js.map +1 -1
- package/src/apply-max-size.d.ts +0 -2
- package/src/apply-max-size.js +0 -30
- package/src/apply-max-size.js.map +0 -1
- package/src/popper.d.ts +0 -8
- package/src/popper.js +0 -29
- package/src/popper.js.map +0 -1
package/src/ActiveOverlay.js
CHANGED
|
@@ -16,7 +16,7 @@ import { property } from '@spectrum-web-components/base/src/decorators.js';
|
|
|
16
16
|
import { reparentChildren } from '@spectrum-web-components/shared';
|
|
17
17
|
import { firstFocusableIn } from '@spectrum-web-components/shared/src/first-focusable-in.js';
|
|
18
18
|
import styles from './active-overlay.css.js';
|
|
19
|
-
import {
|
|
19
|
+
import { arrow, computePosition, flip, offset, shift, size, } from '@floating-ui/dom';
|
|
20
20
|
const stateMachine = {
|
|
21
21
|
initial: 'idle',
|
|
22
22
|
states: {
|
|
@@ -26,13 +26,6 @@ const stateMachine = {
|
|
|
26
26
|
},
|
|
27
27
|
},
|
|
28
28
|
active: {
|
|
29
|
-
on: {
|
|
30
|
-
visible: 'visible',
|
|
31
|
-
hiding: 'hiding',
|
|
32
|
-
idle: 'idle',
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
visible: {
|
|
36
29
|
on: {
|
|
37
30
|
hiding: 'hiding',
|
|
38
31
|
idle: 'idle',
|
|
@@ -88,6 +81,73 @@ export class ActiveOverlay extends SpectrumElement {
|
|
|
88
81
|
this.interaction = 'hover';
|
|
89
82
|
this.positionAnimationFrame = 0;
|
|
90
83
|
this.willNotifyClosed = false;
|
|
84
|
+
this.isConstrained = false;
|
|
85
|
+
this.updateOverlayPosition = async () => {
|
|
86
|
+
if (!this.placement || this.placement === 'none') {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
await (document.fonts ? document.fonts.ready : Promise.resolve());
|
|
90
|
+
function roundByDPR(num) {
|
|
91
|
+
const dpr = window.devicePixelRatio || 1;
|
|
92
|
+
return Math.round(num * dpr) / dpr || 0;
|
|
93
|
+
}
|
|
94
|
+
// See: https://spectrum.adobe.com/page/popover/#Container-padding
|
|
95
|
+
const REQUIRED_DISTANCE_TO_EDGE = 8;
|
|
96
|
+
// See: https://github.com/adobe/spectrum-web-components/issues/910
|
|
97
|
+
const MIN_OVERLAY_HEIGHT = 100;
|
|
98
|
+
const middleware = [
|
|
99
|
+
offset(this.offset),
|
|
100
|
+
flip({
|
|
101
|
+
fallbackStrategy: 'initialPlacement',
|
|
102
|
+
}),
|
|
103
|
+
shift({ padding: REQUIRED_DISTANCE_TO_EDGE }),
|
|
104
|
+
size({
|
|
105
|
+
padding: REQUIRED_DISTANCE_TO_EDGE,
|
|
106
|
+
apply: ({ width, height, floating }) => {
|
|
107
|
+
const maxHeight = Math.max(MIN_OVERLAY_HEIGHT, Math.floor(height));
|
|
108
|
+
const actualHeight = floating.height;
|
|
109
|
+
this.initialHeight = !this.isConstrained
|
|
110
|
+
? actualHeight
|
|
111
|
+
: this.initialHeight || actualHeight;
|
|
112
|
+
this.isConstrained =
|
|
113
|
+
actualHeight < this.initialHeight ||
|
|
114
|
+
maxHeight <= actualHeight;
|
|
115
|
+
const appliedHeight = this.isConstrained
|
|
116
|
+
? `${maxHeight}px`
|
|
117
|
+
: '';
|
|
118
|
+
Object.assign(this.style, {
|
|
119
|
+
maxWidth: `${Math.floor(width)}px`,
|
|
120
|
+
maxHeight: appliedHeight,
|
|
121
|
+
height: appliedHeight,
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
}),
|
|
125
|
+
];
|
|
126
|
+
if (this.overlayContentTip) {
|
|
127
|
+
middleware.push(arrow({ element: this.overlayContentTip }));
|
|
128
|
+
}
|
|
129
|
+
const { x, y, placement, middlewareData } = await computePosition(this.virtualTrigger || this.trigger, this, {
|
|
130
|
+
placement: this.placement,
|
|
131
|
+
middleware,
|
|
132
|
+
});
|
|
133
|
+
Object.assign(this.style, {
|
|
134
|
+
left: `${roundByDPR(x)}px`,
|
|
135
|
+
top: `${roundByDPR(y)}px`,
|
|
136
|
+
});
|
|
137
|
+
if (placement !== this.getAttribute('actual-placement')) {
|
|
138
|
+
this.setAttribute('actual-placement', placement);
|
|
139
|
+
this.overlayContent.setAttribute('placement', placement);
|
|
140
|
+
}
|
|
141
|
+
if (this.overlayContentTip && middlewareData.arrow) {
|
|
142
|
+
const { x: arrowX, y: arrowY } = middlewareData.arrow;
|
|
143
|
+
Object.assign(this.overlayContentTip.style, {
|
|
144
|
+
left: arrowX != null ? `${roundByDPR(arrowX)}px` : '',
|
|
145
|
+
top: arrowY != null ? `${roundByDPR(arrowY)}px` : '',
|
|
146
|
+
right: '',
|
|
147
|
+
bottom: '',
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
91
151
|
this.handleInlineTriggerKeydown = (event) => {
|
|
92
152
|
const { code, shiftKey } = event;
|
|
93
153
|
/* c8 ignore next */
|
|
@@ -114,9 +174,7 @@ export class ActiveOverlay extends SpectrumElement {
|
|
|
114
174
|
return;
|
|
115
175
|
}
|
|
116
176
|
this._state = nextState;
|
|
117
|
-
if (this.state === 'active' ||
|
|
118
|
-
this.state === 'visible' ||
|
|
119
|
-
this.state === 'hiding') {
|
|
177
|
+
if (this.state === 'active' || this.state === 'hiding') {
|
|
120
178
|
this.setAttribute('state', this.state);
|
|
121
179
|
}
|
|
122
180
|
else {
|
|
@@ -171,80 +229,31 @@ export class ActiveOverlay extends SpectrumElement {
|
|
|
171
229
|
}
|
|
172
230
|
return undefined;
|
|
173
231
|
}
|
|
174
|
-
firstUpdated(changedProperties) {
|
|
232
|
+
async firstUpdated(changedProperties) {
|
|
175
233
|
super.firstUpdated(changedProperties);
|
|
176
234
|
/* c8 ignore next */
|
|
177
|
-
if (!this.overlayContent)
|
|
178
|
-
return;
|
|
179
|
-
this.stealOverlayContent(this.overlayContent);
|
|
180
|
-
/* c8 ignore next */
|
|
181
235
|
if (!this.overlayContent || !this.trigger)
|
|
182
236
|
return;
|
|
183
|
-
|
|
184
|
-
this.popper = createPopper(this.virtualTrigger || this.trigger, this, {
|
|
185
|
-
placement: this.placement,
|
|
186
|
-
modifiers: [
|
|
187
|
-
maxSize,
|
|
188
|
-
applyMaxSize,
|
|
189
|
-
{
|
|
190
|
-
name: 'arrow',
|
|
191
|
-
options: {
|
|
192
|
-
element: this.overlayContentTip,
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
name: 'offset',
|
|
197
|
-
options: {
|
|
198
|
-
offset: [0, this.offset],
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
],
|
|
202
|
-
});
|
|
203
|
-
}
|
|
237
|
+
this.stealOverlayContent(this.overlayContent);
|
|
204
238
|
this.state = 'active';
|
|
205
|
-
document.addEventListener('sp-update-overlays', () => {
|
|
206
|
-
this.updateOverlayPosition();
|
|
207
|
-
this.state = 'visible';
|
|
208
|
-
});
|
|
209
239
|
this.feature();
|
|
210
|
-
this.
|
|
211
|
-
|
|
212
|
-
.
|
|
213
|
-
|
|
214
|
-
this.focus();
|
|
215
|
-
}
|
|
216
|
-
this.trigger.dispatchEvent(new CustomEvent('sp-opened', {
|
|
217
|
-
bubbles: true,
|
|
218
|
-
composed: true,
|
|
219
|
-
cancelable: true,
|
|
220
|
-
detail: {
|
|
221
|
-
interaction: this.interaction,
|
|
222
|
-
},
|
|
223
|
-
}));
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
updateOverlayPopperPlacement() {
|
|
227
|
-
/* c8 ignore next */
|
|
228
|
-
const activeWithContent = this.state === 'active' && this.overlayContent;
|
|
229
|
-
if (!activeWithContent)
|
|
230
|
-
return;
|
|
231
|
-
if (this.dataPopperPlacement) {
|
|
232
|
-
// Copy this attribute to the actual overlay node so that it can use
|
|
233
|
-
// the attribute for styling shadow DOM elements based on the side
|
|
234
|
-
// that popper has chosen for it
|
|
235
|
-
this.overlayContent.setAttribute('placement', this.dataPopperPlacement);
|
|
236
|
-
}
|
|
237
|
-
else if (this.originalPlacement) {
|
|
238
|
-
this.overlayContent.setAttribute('placement', this.originalPlacement);
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
this.overlayContent.removeAttribute('placement');
|
|
240
|
+
if (this.placement && this.placement !== 'none') {
|
|
241
|
+
await this.updateOverlayPosition();
|
|
242
|
+
document.addEventListener('sp-update-overlays', this.updateOverlayPosition);
|
|
243
|
+
window.addEventListener('scroll', this.updateOverlayPosition);
|
|
242
244
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
this.updateOverlayPopperPlacement();
|
|
245
|
+
await this.applyContentAnimation('sp-overlay-fade-in');
|
|
246
|
+
if (this.receivesFocus) {
|
|
247
|
+
this.focus();
|
|
247
248
|
}
|
|
249
|
+
this.trigger.dispatchEvent(new CustomEvent('sp-opened', {
|
|
250
|
+
bubbles: true,
|
|
251
|
+
composed: true,
|
|
252
|
+
cancelable: true,
|
|
253
|
+
detail: {
|
|
254
|
+
interaction: this.interaction,
|
|
255
|
+
},
|
|
256
|
+
}));
|
|
248
257
|
}
|
|
249
258
|
open(openDetail) {
|
|
250
259
|
this.extractDetail(openDetail);
|
|
@@ -269,10 +278,6 @@ export class ActiveOverlay extends SpectrumElement {
|
|
|
269
278
|
clearTimeout(this.timeout);
|
|
270
279
|
delete this.timeout;
|
|
271
280
|
}
|
|
272
|
-
if (this.popper) {
|
|
273
|
-
this.popper.destroy();
|
|
274
|
-
this.popper = undefined;
|
|
275
|
-
}
|
|
276
281
|
this.trigger.removeEventListener('keydown', this.handleInlineTriggerKeydown);
|
|
277
282
|
this.returnOverlayContent();
|
|
278
283
|
this.state = 'disposed';
|
|
@@ -285,9 +290,11 @@ export class ActiveOverlay extends SpectrumElement {
|
|
|
285
290
|
this.originalPlacement = element.getAttribute('placement');
|
|
286
291
|
this.restoreContent = reparentChildren([element], this, (el) => {
|
|
287
292
|
const slotName = el.slot;
|
|
293
|
+
const placement = el.placement;
|
|
288
294
|
el.removeAttribute('slot');
|
|
289
295
|
return (el) => {
|
|
290
296
|
el.slot = slotName;
|
|
297
|
+
el.placement = placement;
|
|
291
298
|
};
|
|
292
299
|
});
|
|
293
300
|
this.stealOverlayContentResolver();
|
|
@@ -304,12 +311,6 @@ export class ActiveOverlay extends SpectrumElement {
|
|
|
304
311
|
delete this.originalPlacement;
|
|
305
312
|
}
|
|
306
313
|
}
|
|
307
|
-
async updateOverlayPosition() {
|
|
308
|
-
await (document.fonts ? document.fonts.ready : Promise.resolve());
|
|
309
|
-
if (this.popper) {
|
|
310
|
-
await this.popper.update();
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
314
|
async hide(animated = true) {
|
|
314
315
|
this.state = 'hiding';
|
|
315
316
|
if (animated) {
|
|
@@ -325,10 +326,6 @@ export class ActiveOverlay extends SpectrumElement {
|
|
|
325
326
|
onSlotChange() {
|
|
326
327
|
this.schedulePositionUpdate();
|
|
327
328
|
}
|
|
328
|
-
connectedCallback() {
|
|
329
|
-
super.connectedCallback();
|
|
330
|
-
this.schedulePositionUpdate();
|
|
331
|
-
}
|
|
332
329
|
applyContentAnimation(animation) {
|
|
333
330
|
return new Promise((resolve) => {
|
|
334
331
|
const contents = this.shadowRoot.querySelector('#contents');
|
|
@@ -379,6 +376,11 @@ export class ActiveOverlay extends SpectrumElement {
|
|
|
379
376
|
await this.stealOverlayContentPromise;
|
|
380
377
|
return complete;
|
|
381
378
|
}
|
|
379
|
+
disconnectedCallback() {
|
|
380
|
+
document.removeEventListener('sp-update-overlays', this.updateOverlayPosition);
|
|
381
|
+
window.removeEventListener('scroll', this.updateOverlayPosition);
|
|
382
|
+
super.disconnectedCallback();
|
|
383
|
+
}
|
|
382
384
|
}
|
|
383
385
|
__decorate([
|
|
384
386
|
property()
|
|
@@ -395,7 +397,4 @@ __decorate([
|
|
|
395
397
|
__decorate([
|
|
396
398
|
property({ attribute: false })
|
|
397
399
|
], ActiveOverlay.prototype, "receivesFocus", void 0);
|
|
398
|
-
__decorate([
|
|
399
|
-
property({ attribute: 'data-popper-placement' })
|
|
400
|
-
], ActiveOverlay.prototype, "dataPopperPlacement", void 0);
|
|
401
400
|
//# sourceMappingURL=ActiveOverlay.js.map
|
package/src/ActiveOverlay.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActiveOverlay.js","sourceRoot":"","sources":["ActiveOverlay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAEH,IAAI,EAEJ,eAAe,GAElB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,iDAAiD,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2DAA2D,CAAC;AAE7F,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAO7C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAY,OAAO,EAAE,MAAM,aAAa,CAAC;AAqB5E,MA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AAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACzB;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;IAKS,KAAK,CAAC,iBAAiB;QAC7B,MAAM,QAAQ,GAAG,CAAC,MAAM,KAAK,CAAC,iBAAiB,EAAE,CAAY,CAAC;QAC9D,MAAM,IAAI,CAAC,0BAA0B,CAAC;QACtC,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AA3YG;IADC,QAAQ,EAAE;6CACuB;AAsBlC;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;gDAClB;AAGzB;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gDACC;AAE7B;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;4CAKxB;AAEP;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oDACD;AAY9B;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,uBAAuB,EAAE,CAAC;0DACV","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { reparentChildren } from '@spectrum-web-components/shared';\nimport { firstFocusableIn } from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport { Color, Scale } from '@spectrum-web-components/theme';\nimport styles from './active-overlay.css.js';\nimport {\n OverlayOpenCloseDetail,\n OverlayOpenDetail,\n Placement,\n TriggerInteractions,\n} from './overlay-types.js';\nimport { applyMaxSize, createPopper, Instance, maxSize } from './popper.js';\nimport { VirtualTrigger } from './VirtualTrigger.js';\n\nexport interface PositionResult {\n arrowOffsetLeft: number;\n arrowOffsetTop: number;\n maxHeight: number;\n placement: string;\n positionLeft: number;\n positionTop: number;\n}\n\ntype OverlayStateType =\n | 'idle'\n | 'active'\n | 'visible'\n | 'hiding'\n | 'dispose'\n | 'disposed';\ntype ContentAnimation = 'sp-overlay-fade-in' | 'sp-overlay-fade-out';\n\nconst stateMachine: {\n initial: OverlayStateType;\n states: {\n [stateName: string]: {\n on: {\n [transitionName: string]: OverlayStateType;\n };\n };\n };\n} = {\n initial: 'idle',\n states: {\n idle: {\n on: {\n active: 'active',\n },\n },\n active: {\n on: {\n visible: 'visible',\n hiding: 'hiding',\n idle: 'idle',\n },\n },\n visible: {\n on: {\n hiding: 'hiding',\n idle: 'idle',\n },\n },\n hiding: {\n on: {\n dispose: 'dispose',\n },\n },\n dispose: {\n on: {\n disposed: 'disposed',\n },\n },\n disposed: {\n on: {},\n },\n },\n};\n\nconst stateTransition = (\n state?: OverlayStateType,\n event?: string\n): OverlayStateType => {\n if (!state) return stateMachine.initial;\n /* c8 ignore next */\n if (!event) return state;\n return stateMachine.states[state].on[event] || state;\n};\n\nconst parentOverlayOf = (el: Element): ActiveOverlay | null => {\n const closestOverlay = el.closest('active-overlay');\n if (closestOverlay) {\n return closestOverlay;\n }\n const rootNode = el.getRootNode() as ShadowRoot;\n if (rootNode.host) {\n return parentOverlayOf(rootNode.host);\n }\n return null;\n};\n\n/**\n * @element active-overlay\n *\n * @slot - content to display in the overlay\n */\nexport class ActiveOverlay extends SpectrumElement {\n public overlayContent!: HTMLElement;\n public overlayContentTip?: HTMLElement;\n public trigger!: HTMLElement;\n public virtualTrigger?: VirtualTrigger;\n\n private popper?: Instance;\n\n @property()\n public _state = stateTransition();\n public get state(): OverlayStateType {\n return this._state;\n }\n public set state(state: OverlayStateType) {\n const nextState = stateTransition(this.state, state);\n if (nextState === this.state) {\n return;\n }\n this._state = nextState;\n if (\n this.state === 'active' ||\n this.state === 'visible' ||\n this.state === 'hiding'\n ) {\n this.setAttribute('state', this.state);\n } else {\n this.removeAttribute('state');\n }\n }\n\n @property({ reflect: true, type: Boolean })\n public animating = false;\n\n @property({ reflect: true })\n public placement?: Placement;\n @property({ attribute: false })\n public theme: {\n color?: Color;\n scale?: Scale;\n lang?: string;\n } = {};\n @property({ attribute: false })\n public receivesFocus?: 'auto';\n\n public tabbingAway = false;\n private originalPlacement?: Placement;\n private restoreContent?: () => Element[];\n\n /**\n * @prop Used by the popper library to indicate where the overlay was\n * actually rendered. Popper may switch which side an overlay\n * is rendered on to fit it on the screen\n */\n @property({ attribute: 'data-popper-placement' })\n public dataPopperPlacement?: Placement;\n\n public focus(): void {\n const firstFocusable = firstFocusableIn(this);\n if (firstFocusable) {\n firstFocusable.focus();\n /* c8 ignore next 3 */\n } else {\n super.focus();\n }\n this.removeAttribute('tabindex');\n }\n\n private get hasTheme(): boolean {\n return !!this.theme.color || !!this.theme.scale || !!this.theme.lang;\n }\n\n public offset = 6;\n public interaction: TriggerInteractions = 'hover';\n private positionAnimationFrame = 0;\n\n private timeout?: number;\n\n public static get styles(): CSSResultArray {\n return [styles];\n }\n\n public constructor() {\n super();\n this.stealOverlayContentPromise = new Promise(\n (res) => (this.stealOverlayContentResolver = res)\n );\n }\n\n private _modalRoot?: ActiveOverlay;\n\n public get hasModalRoot(): boolean {\n return !!this._modalRoot;\n }\n\n public feature(): void {\n this.tabIndex = -1;\n const parentOverlay = parentOverlayOf(this.trigger);\n const parentIsModal = parentOverlay && parentOverlay.slot === 'open';\n // If an overlay it triggered from within a \"modal\" overlay, it needs to continue\n // to act like one to get treated correctly in regards to tab trapping.\n if (this.interaction === 'modal' || parentIsModal || this._modalRoot) {\n this.slot = 'open';\n // If this isn't a modal root, walk up the overlays to the next modal root\n // and \"feature\" each on of the intervening overlays.\n if (this._modalRoot) {\n parentOverlay?.feature();\n }\n }\n }\n\n public obscure(\n nextOverlayInteraction: TriggerInteractions\n ): ActiveOverlay | undefined {\n if (this.slot && nextOverlayInteraction === 'modal') {\n this.removeAttribute('slot');\n // Obscure upto and including the next modal root.\n if (this.interaction !== 'modal') {\n const parentOverlay = parentOverlayOf(this.trigger);\n this._modalRoot = parentOverlay?.obscure(\n nextOverlayInteraction\n );\n return this._modalRoot;\n }\n return this;\n }\n return undefined;\n }\n\n public firstUpdated(changedProperties: PropertyValues): void {\n super.firstUpdated(changedProperties);\n\n /* c8 ignore next */\n if (!this.overlayContent) return;\n\n this.stealOverlayContent(this.overlayContent);\n\n /* c8 ignore next */\n if (!this.overlayContent || !this.trigger) return;\n\n if (this.placement && this.placement !== 'none') {\n this.popper = createPopper(\n this.virtualTrigger || this.trigger,\n this,\n {\n placement: this.placement,\n modifiers: [\n maxSize,\n applyMaxSize,\n {\n name: 'arrow',\n options: {\n element: this.overlayContentTip,\n },\n },\n {\n name: 'offset',\n options: {\n offset: [0, this.offset],\n },\n },\n ],\n }\n );\n }\n\n this.state = 'active';\n\n document.addEventListener('sp-update-overlays', () => {\n this.updateOverlayPosition();\n this.state = 'visible';\n });\n\n this.feature();\n this.updateOverlayPosition()\n .then(() => this.applyContentAnimation('sp-overlay-fade-in'))\n .then(() => {\n if (this.receivesFocus) {\n this.focus();\n }\n this.trigger.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>('sp-opened', {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail: {\n interaction: this.interaction,\n },\n })\n );\n });\n }\n\n private updateOverlayPopperPlacement(): void {\n /* c8 ignore next */\n const activeWithContent =\n this.state === 'active' && this.overlayContent;\n if (!activeWithContent) return;\n\n if (this.dataPopperPlacement) {\n // Copy this attribute to the actual overlay node so that it can use\n // the attribute for styling shadow DOM elements based on the side\n // that popper has chosen for it\n this.overlayContent.setAttribute(\n 'placement',\n this.dataPopperPlacement\n );\n } else if (this.originalPlacement) {\n this.overlayContent.setAttribute(\n 'placement',\n this.originalPlacement\n );\n } else {\n this.overlayContent.removeAttribute('placement');\n }\n }\n\n public updated(changedProperties: PropertyValues): void {\n if (changedProperties.has('dataPopperPlacement')) {\n this.updateOverlayPopperPlacement();\n }\n }\n\n private open(openDetail: OverlayOpenDetail): void {\n this.extractDetail(openDetail);\n }\n\n private extractDetail(detail: OverlayOpenDetail): void {\n this.overlayContent = detail.content;\n this.overlayContentTip = detail.contentTip;\n this.trigger = detail.trigger;\n this.virtualTrigger = detail.virtualTrigger;\n this.placement = detail.placement;\n this.offset = detail.offset;\n this.interaction = detail.interaction;\n this.theme = detail.theme;\n this.receivesFocus = detail.receivesFocus;\n }\n\n public dispose(): void {\n /* c8 ignore next */\n if (this.state !== 'dispose') return;\n\n /* c8 ignore next 4 */\n if (this.timeout) {\n clearTimeout(this.timeout);\n delete this.timeout;\n }\n\n if (this.popper) {\n this.popper.destroy();\n this.popper = undefined;\n }\n this.trigger.removeEventListener(\n 'keydown',\n this.handleInlineTriggerKeydown\n );\n\n this.returnOverlayContent();\n this.state = 'disposed';\n\n if (this.willNotifyClosed) {\n this.overlayContent.dispatchEvent(new Event('sp-overlay-closed'));\n this.willNotifyClosed = false;\n }\n }\n\n private stealOverlayContent(element: HTMLElement): void {\n this.originalPlacement = element.getAttribute('placement') as Placement;\n this.restoreContent = reparentChildren([element], this, (el) => {\n const slotName = el.slot;\n el.removeAttribute('slot');\n return (el) => {\n el.slot = slotName;\n };\n });\n this.stealOverlayContentResolver();\n }\n\n private willNotifyClosed = false;\n\n private returnOverlayContent(): void {\n /* c8 ignore next */\n if (!this.restoreContent) return;\n\n const [element] = this.restoreContent();\n this.restoreContent = undefined;\n this.willNotifyClosed = true;\n\n if (this.originalPlacement) {\n element.setAttribute('placement', this.originalPlacement);\n delete this.originalPlacement;\n }\n }\n\n public async updateOverlayPosition(): Promise<void> {\n await (document.fonts ? document.fonts.ready : Promise.resolve());\n if (this.popper) {\n await this.popper.update();\n }\n }\n\n public async hide(animated = true): Promise<void> {\n this.state = 'hiding';\n if (animated) {\n await this.applyContentAnimation('sp-overlay-fade-out');\n }\n this.state = 'dispose';\n }\n\n private schedulePositionUpdate(): void {\n // Edge needs a little time to update the DOM before computing the layout\n cancelAnimationFrame(this.positionAnimationFrame);\n this.positionAnimationFrame = requestAnimationFrame(() =>\n this.updateOverlayPosition()\n );\n }\n\n private onSlotChange(): void {\n this.schedulePositionUpdate();\n }\n\n public handleInlineTriggerKeydown = (event: KeyboardEvent): void => {\n const { code, shiftKey } = event;\n /* c8 ignore next */\n if (code !== 'Tab') return;\n if (shiftKey) {\n this.tabbingAway = true;\n this.dispatchEvent(new Event('close'));\n return;\n }\n\n event.stopPropagation();\n event.preventDefault();\n this.focus();\n };\n\n public connectedCallback(): void {\n super.connectedCallback();\n this.schedulePositionUpdate();\n }\n\n public applyContentAnimation(\n animation: ContentAnimation\n ): Promise<boolean> {\n return new Promise((resolve): void => {\n const contents = this.shadowRoot.querySelector(\n '#contents'\n ) as HTMLElement;\n const doneHandler = (event: AnimationEvent): void => {\n if (animation !== event.animationName) return;\n contents.removeEventListener('animationend', doneHandler);\n contents.removeEventListener('animationcancel', doneHandler);\n this.animating = false;\n resolve(event.type === 'animationcancel');\n };\n contents.addEventListener('animationend', doneHandler);\n contents.addEventListener('animationcancel', doneHandler);\n\n contents.style.animationName = animation;\n this.animating = true;\n });\n }\n\n public renderTheme(content: TemplateResult): TemplateResult {\n const { color, scale, lang } = this.theme;\n return html`\n <sp-theme\n color=${ifDefined(color)}\n scale=${ifDefined(scale)}\n lang=${ifDefined(lang)}\n part=\"theme\"\n >\n ${content}\n </sp-theme>\n `;\n }\n\n public render(): TemplateResult {\n const content = html`\n <div id=\"contents\">\n <slot @slotchange=${this.onSlotChange}></slot>\n </div>\n `;\n return this.hasTheme ? this.renderTheme(content) : content;\n }\n\n public static create(details: OverlayOpenDetail): ActiveOverlay {\n const overlay = new ActiveOverlay();\n\n if (details.content) {\n overlay.open(details);\n }\n\n return overlay;\n }\n\n private stealOverlayContentPromise = Promise.resolve();\n private stealOverlayContentResolver!: () => void;\n\n protected async getUpdateComplete(): Promise<boolean> {\n const complete = (await super.getUpdateComplete()) as boolean;\n await this.stealOverlayContentPromise;\n return complete;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ActiveOverlay.js","sourceRoot":"","sources":["ActiveOverlay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAEH,IAAI,EAEJ,eAAe,GAElB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,iDAAiD,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2DAA2D,CAAC;AAE7F,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAQ7C,OAAO,EACH,KAAK,EACL,eAAe,EACf,IAAI,EACJ,MAAM,EACN,KAAK,EACL,IAAI,GACP,MAAM,kBAAkB,CAAC;AAc1B,MAAM,YAAY,GASd;IACA,OAAO,EAAE,MAAM;IACf,MAAM,EAAE;QACJ,IAAI,EAAE;YACF,EAAE,EAAE;gBACA,MAAM,EAAE,QAAQ;aACnB;SACJ;QACD,MAAM,EAAE;YACJ,EAAE,EAAE;gBACA,MAAM,EAAE,QAAQ;gBAChB,IAAI,EAAE,MAAM;aACf;SACJ;QACD,MAAM,EAAE;YACJ,EAAE,EAAE;gBACA,OAAO,EAAE,SAAS;aACrB;SACJ;QACD,OAAO,EAAE;YACL,EAAE,EAAE;gBACA,QAAQ,EAAE,UAAU;aACvB;SACJ;QACD,QAAQ,EAAE;YACN,EAAE,EAAE,EAAE;SACT;KACJ;CACJ,CAAC;AAEF,MAAM,eAAe,GAAG,CACpB,KAAwB,EACxB,KAAc,E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EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;gDAClB;AAGzB;IADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gDACC;AAE7B;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;4CAKxB;AAEP;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oDACD","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { reparentChildren } from '@spectrum-web-components/shared';\nimport { firstFocusableIn } from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport { Color, Scale } from '@spectrum-web-components/theme';\nimport styles from './active-overlay.css.js';\nimport {\n OverlayOpenCloseDetail,\n OverlayOpenDetail,\n Placement,\n TriggerInteractions,\n} from './overlay-types.js';\nimport type { VirtualTrigger } from './VirtualTrigger.js';\nimport {\n arrow,\n computePosition,\n flip,\n offset,\n shift,\n size,\n} from '@floating-ui/dom';\n\nexport interface PositionResult {\n arrowOffsetLeft: number;\n arrowOffsetTop: number;\n maxHeight: number;\n placement: string;\n positionLeft: number;\n positionTop: number;\n}\n\ntype OverlayStateType = 'idle' | 'active' | 'hiding' | 'dispose' | 'disposed';\ntype ContentAnimation = 'sp-overlay-fade-in' | 'sp-overlay-fade-out';\n\nconst stateMachine: {\n initial: OverlayStateType;\n states: {\n [stateName: string]: {\n on: {\n [transitionName: string]: OverlayStateType;\n };\n };\n };\n} = {\n initial: 'idle',\n states: {\n idle: {\n on: {\n active: 'active',\n },\n },\n active: {\n on: {\n hiding: 'hiding',\n idle: 'idle',\n },\n },\n hiding: {\n on: {\n dispose: 'dispose',\n },\n },\n dispose: {\n on: {\n disposed: 'disposed',\n },\n },\n disposed: {\n on: {},\n },\n },\n};\n\nconst stateTransition = (\n state?: OverlayStateType,\n event?: string\n): OverlayStateType => {\n if (!state) return stateMachine.initial;\n /* c8 ignore next */\n if (!event) return state;\n return stateMachine.states[state].on[event] || state;\n};\n\nconst parentOverlayOf = (el: Element): ActiveOverlay | null => {\n const closestOverlay = el.closest('active-overlay');\n if (closestOverlay) {\n return closestOverlay;\n }\n const rootNode = el.getRootNode() as ShadowRoot;\n if (rootNode.host) {\n return parentOverlayOf(rootNode.host);\n }\n return null;\n};\n\n/**\n * @element active-overlay\n *\n * @slot - content to display in the overlay\n */\nexport class ActiveOverlay extends SpectrumElement {\n public overlayContent!: HTMLElement;\n public overlayContentTip?: HTMLElement;\n public trigger!: HTMLElement;\n public virtualTrigger?: VirtualTrigger;\n\n @property()\n public _state = stateTransition();\n public get state(): OverlayStateType {\n return this._state;\n }\n public set state(state: OverlayStateType) {\n const nextState = stateTransition(this.state, state);\n if (nextState === this.state) {\n return;\n }\n this._state = nextState;\n if (this.state === 'active' || this.state === 'hiding') {\n this.setAttribute('state', this.state);\n } else {\n this.removeAttribute('state');\n }\n }\n\n @property({ reflect: true, type: Boolean })\n public animating = false;\n\n @property({ reflect: true })\n public placement?: Placement;\n @property({ attribute: false })\n public theme: {\n color?: Color;\n scale?: Scale;\n lang?: string;\n } = {};\n @property({ attribute: false })\n public receivesFocus?: 'auto';\n\n public tabbingAway = false;\n private originalPlacement?: Placement;\n private restoreContent?: () => Element[];\n\n public focus(): void {\n const firstFocusable = firstFocusableIn(this);\n if (firstFocusable) {\n firstFocusable.focus();\n /* c8 ignore next 3 */\n } else {\n super.focus();\n }\n this.removeAttribute('tabindex');\n }\n\n private get hasTheme(): boolean {\n return !!this.theme.color || !!this.theme.scale || !!this.theme.lang;\n }\n\n public offset = 6;\n public interaction: TriggerInteractions = 'hover';\n private positionAnimationFrame = 0;\n\n private timeout?: number;\n\n public static get styles(): CSSResultArray {\n return [styles];\n }\n\n public constructor() {\n super();\n this.stealOverlayContentPromise = new Promise(\n (res) => (this.stealOverlayContentResolver = res)\n );\n }\n\n private _modalRoot?: ActiveOverlay;\n\n public get hasModalRoot(): boolean {\n return !!this._modalRoot;\n }\n\n public feature(): void {\n this.tabIndex = -1;\n const parentOverlay = parentOverlayOf(this.trigger);\n const parentIsModal = parentOverlay && parentOverlay.slot === 'open';\n // If an overlay it triggered from within a \"modal\" overlay, it needs to continue\n // to act like one to get treated correctly in regards to tab trapping.\n if (this.interaction === 'modal' || parentIsModal || this._modalRoot) {\n this.slot = 'open';\n // If this isn't a modal root, walk up the overlays to the next modal root\n // and \"feature\" each on of the intervening overlays.\n if (this._modalRoot) {\n parentOverlay?.feature();\n }\n }\n }\n\n public obscure(\n nextOverlayInteraction: TriggerInteractions\n ): ActiveOverlay | undefined {\n if (this.slot && nextOverlayInteraction === 'modal') {\n this.removeAttribute('slot');\n // Obscure upto and including the next modal root.\n if (this.interaction !== 'modal') {\n const parentOverlay = parentOverlayOf(this.trigger);\n this._modalRoot = parentOverlay?.obscure(\n nextOverlayInteraction\n );\n return this._modalRoot;\n }\n return this;\n }\n return undefined;\n }\n\n public async firstUpdated(\n changedProperties: PropertyValues\n ): Promise<void> {\n super.firstUpdated(changedProperties);\n\n /* c8 ignore next */\n if (!this.overlayContent || !this.trigger) return;\n\n this.stealOverlayContent(\n this.overlayContent as HTMLElement & { placement: Placement }\n );\n\n this.state = 'active';\n this.feature();\n if (this.placement && this.placement !== 'none') {\n await this.updateOverlayPosition();\n document.addEventListener(\n 'sp-update-overlays',\n this.updateOverlayPosition\n );\n window.addEventListener('scroll', this.updateOverlayPosition);\n }\n await this.applyContentAnimation('sp-overlay-fade-in');\n if (this.receivesFocus) {\n this.focus();\n }\n this.trigger.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>('sp-opened', {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail: {\n interaction: this.interaction,\n },\n })\n );\n }\n\n private open(openDetail: OverlayOpenDetail): void {\n this.extractDetail(openDetail);\n }\n\n private extractDetail(detail: OverlayOpenDetail): void {\n this.overlayContent = detail.content;\n this.overlayContentTip = detail.contentTip;\n this.trigger = detail.trigger;\n this.virtualTrigger = detail.virtualTrigger;\n this.placement = detail.placement;\n this.offset = detail.offset;\n this.interaction = detail.interaction;\n this.theme = detail.theme;\n this.receivesFocus = detail.receivesFocus;\n }\n\n public dispose(): void {\n /* c8 ignore next */\n if (this.state !== 'dispose') return;\n\n /* c8 ignore next 4 */\n if (this.timeout) {\n clearTimeout(this.timeout);\n delete this.timeout;\n }\n\n this.trigger.removeEventListener(\n 'keydown',\n this.handleInlineTriggerKeydown\n );\n\n this.returnOverlayContent();\n this.state = 'disposed';\n\n if (this.willNotifyClosed) {\n this.overlayContent.dispatchEvent(new Event('sp-overlay-closed'));\n this.willNotifyClosed = false;\n }\n }\n\n private stealOverlayContent(\n element: HTMLElement & { placement: Placement }\n ): void {\n this.originalPlacement = element.getAttribute('placement') as Placement;\n this.restoreContent = reparentChildren([element], this, (el) => {\n const slotName = el.slot;\n const placement = el.placement;\n el.removeAttribute('slot');\n return (el) => {\n el.slot = slotName;\n el.placement = placement;\n };\n });\n this.stealOverlayContentResolver();\n }\n\n private willNotifyClosed = false;\n\n private returnOverlayContent(): void {\n /* c8 ignore next */\n if (!this.restoreContent) return;\n\n const [element] = this.restoreContent();\n this.restoreContent = undefined;\n this.willNotifyClosed = true;\n\n if (this.originalPlacement) {\n element.setAttribute('placement', this.originalPlacement);\n delete this.originalPlacement;\n }\n }\n\n private initialHeight!: number;\n private isConstrained = false;\n\n public updateOverlayPosition = async (): Promise<void> => {\n if (!this.placement || this.placement === 'none') {\n return;\n }\n await (document.fonts ? document.fonts.ready : Promise.resolve());\n\n function roundByDPR(num: number): number {\n const dpr = window.devicePixelRatio || 1;\n return Math.round(num * dpr) / dpr || 0;\n }\n\n // See: https://spectrum.adobe.com/page/popover/#Container-padding\n const REQUIRED_DISTANCE_TO_EDGE = 8;\n // See: https://github.com/adobe/spectrum-web-components/issues/910\n const MIN_OVERLAY_HEIGHT = 100;\n\n const middleware = [\n offset(this.offset),\n flip({\n fallbackStrategy: 'initialPlacement',\n }),\n shift({ padding: REQUIRED_DISTANCE_TO_EDGE }),\n size({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n apply: ({ width, height, floating }) => {\n const maxHeight = Math.max(\n MIN_OVERLAY_HEIGHT,\n Math.floor(height)\n );\n const actualHeight = floating.height;\n this.initialHeight = !this.isConstrained\n ? actualHeight\n : this.initialHeight || actualHeight;\n this.isConstrained =\n actualHeight < this.initialHeight ||\n maxHeight <= actualHeight;\n const appliedHeight = this.isConstrained\n ? `${maxHeight}px`\n : '';\n Object.assign(this.style, {\n maxWidth: `${Math.floor(width)}px`,\n maxHeight: appliedHeight,\n height: appliedHeight,\n });\n },\n }),\n ];\n if (this.overlayContentTip) {\n middleware.push(arrow({ element: this.overlayContentTip }));\n }\n const { x, y, placement, middlewareData } = await computePosition(\n this.virtualTrigger || this.trigger,\n this,\n {\n placement: this.placement,\n middleware,\n }\n );\n\n Object.assign(this.style, {\n left: `${roundByDPR(x)}px`,\n top: `${roundByDPR(y)}px`,\n });\n\n if (placement !== this.getAttribute('actual-placement')) {\n this.setAttribute('actual-placement', placement);\n this.overlayContent.setAttribute('placement', placement);\n }\n\n if (this.overlayContentTip && middlewareData.arrow) {\n const { x: arrowX, y: arrowY } = middlewareData.arrow;\n\n Object.assign(this.overlayContentTip.style, {\n left: arrowX != null ? `${roundByDPR(arrowX)}px` : '',\n top: arrowY != null ? `${roundByDPR(arrowY)}px` : '',\n right: '',\n bottom: '',\n });\n }\n };\n\n public async hide(animated = true): Promise<void> {\n this.state = 'hiding';\n if (animated) {\n await this.applyContentAnimation('sp-overlay-fade-out');\n }\n this.state = 'dispose';\n }\n\n private schedulePositionUpdate(): void {\n // Edge needs a little time to update the DOM before computing the layout\n cancelAnimationFrame(this.positionAnimationFrame);\n this.positionAnimationFrame = requestAnimationFrame(() =>\n this.updateOverlayPosition()\n );\n }\n\n private onSlotChange(): void {\n this.schedulePositionUpdate();\n }\n\n public handleInlineTriggerKeydown = (event: KeyboardEvent): void => {\n const { code, shiftKey } = event;\n /* c8 ignore next */\n if (code !== 'Tab') return;\n if (shiftKey) {\n this.tabbingAway = true;\n this.dispatchEvent(new Event('close'));\n return;\n }\n\n event.stopPropagation();\n event.preventDefault();\n this.focus();\n };\n\n public applyContentAnimation(\n animation: ContentAnimation\n ): Promise<boolean> {\n return new Promise((resolve): void => {\n const contents = this.shadowRoot.querySelector(\n '#contents'\n ) as HTMLElement;\n const doneHandler = (event: AnimationEvent): void => {\n if (animation !== event.animationName) return;\n contents.removeEventListener('animationend', doneHandler);\n contents.removeEventListener('animationcancel', doneHandler);\n this.animating = false;\n resolve(event.type === 'animationcancel');\n };\n contents.addEventListener('animationend', doneHandler);\n contents.addEventListener('animationcancel', doneHandler);\n\n contents.style.animationName = animation;\n this.animating = true;\n });\n }\n\n public renderTheme(content: TemplateResult): TemplateResult {\n const { color, scale, lang } = this.theme;\n return html`\n <sp-theme\n color=${ifDefined(color)}\n scale=${ifDefined(scale)}\n lang=${ifDefined(lang)}\n part=\"theme\"\n >\n ${content}\n </sp-theme>\n `;\n }\n\n public render(): TemplateResult {\n const content = html`\n <div id=\"contents\">\n <slot @slotchange=${this.onSlotChange}></slot>\n </div>\n `;\n return this.hasTheme ? this.renderTheme(content) : content;\n }\n\n public static create(details: OverlayOpenDetail): ActiveOverlay {\n const overlay = new ActiveOverlay();\n\n if (details.content) {\n overlay.open(details);\n }\n\n return overlay;\n }\n\n private stealOverlayContentPromise = Promise.resolve();\n private stealOverlayContentResolver!: () => void;\n\n protected async getUpdateComplete(): Promise<boolean> {\n const complete = (await super.getUpdateComplete()) as boolean;\n await this.stealOverlayContentPromise;\n return complete;\n }\n\n disconnectedCallback(): void {\n document.removeEventListener(\n 'sp-update-overlays',\n this.updateOverlayPosition\n );\n window.removeEventListener('scroll', this.updateOverlayPosition);\n super.disconnectedCallback();\n }\n}\n"]}
|
package/src/OverlayTrigger.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { CSSResultArray,
|
|
1
|
+
import { CSSResultArray, PropertyValues, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
|
|
2
2
|
import { OverlayOptions, Placement, TriggerInteractions } from './overlay-types';
|
|
3
3
|
export declare type OverlayContentTypes = 'click' | 'hover' | 'longpress';
|
|
4
|
+
export declare const LONGPRESS_INSTRUCTIONS: {
|
|
5
|
+
touch: string;
|
|
6
|
+
keyboard: string;
|
|
7
|
+
mouse: string;
|
|
8
|
+
};
|
|
4
9
|
/**
|
|
5
10
|
* @element overlay-trigger
|
|
6
11
|
*
|
|
@@ -12,7 +17,7 @@ export declare type OverlayContentTypes = 'click' | 'hover' | 'longpress';
|
|
|
12
17
|
* @fires sp-opened - Announces that the overlay has been opened
|
|
13
18
|
* @fires sp-closed - Announces that the overlay has been closed
|
|
14
19
|
*/
|
|
15
|
-
export declare class OverlayTrigger extends
|
|
20
|
+
export declare class OverlayTrigger extends SpectrumElement {
|
|
16
21
|
private closeClickOverlay?;
|
|
17
22
|
private closeLongpressOverlay?;
|
|
18
23
|
private closeHoverOverlay?;
|
|
@@ -26,13 +31,17 @@ export declare class OverlayTrigger extends LitElement {
|
|
|
26
31
|
offset: number;
|
|
27
32
|
open?: OverlayContentTypes;
|
|
28
33
|
disabled: boolean;
|
|
34
|
+
hasLongpressContent: boolean;
|
|
35
|
+
private longpressDescriptor?;
|
|
29
36
|
private clickContent?;
|
|
30
37
|
private longpressContent?;
|
|
31
38
|
private hoverContent?;
|
|
32
39
|
private targetContent?;
|
|
40
|
+
private _longpressId;
|
|
33
41
|
private handleClose;
|
|
34
42
|
protected render(): TemplateResult;
|
|
35
|
-
protected updated(changes: PropertyValues): void;
|
|
43
|
+
protected updated(changes: PropertyValues<this>): void;
|
|
44
|
+
protected manageLongpressDescriptor(): void;
|
|
36
45
|
private closeAllOverlays;
|
|
37
46
|
private manageOpen;
|
|
38
47
|
private openOverlay;
|
package/src/OverlayTrigger.js
CHANGED
|
@@ -11,11 +11,17 @@ governing permissions and limitations under the License.
|
|
|
11
11
|
*/
|
|
12
12
|
var _a;
|
|
13
13
|
import { __decorate } from "tslib";
|
|
14
|
-
import { html,
|
|
15
|
-
import { property } from '@spectrum-web-components/base/src/decorators.js';
|
|
14
|
+
import { html, SpectrumElement, } from '@spectrum-web-components/base';
|
|
15
|
+
import { property, state, } from '@spectrum-web-components/base/src/decorators.js';
|
|
16
16
|
import { firstFocusableIn } from '@spectrum-web-components/shared/src/first-focusable-in.js';
|
|
17
|
+
import { isAndroid, isIOS, } from '@spectrum-web-components/shared/src/platform.js';
|
|
17
18
|
import { openOverlay } from './loader.js';
|
|
18
19
|
import overlayTriggerStyles from './overlay-trigger.css.js';
|
|
20
|
+
export const LONGPRESS_INSTRUCTIONS = {
|
|
21
|
+
touch: 'Double tap and long press for additional options',
|
|
22
|
+
keyboard: 'Press Space or Alt+Down Arrow for additional options',
|
|
23
|
+
mouse: 'Click and hold for additional options',
|
|
24
|
+
};
|
|
19
25
|
/**
|
|
20
26
|
* @element overlay-trigger
|
|
21
27
|
*
|
|
@@ -27,7 +33,7 @@ import overlayTriggerStyles from './overlay-trigger.css.js';
|
|
|
27
33
|
* @fires sp-opened - Announces that the overlay has been opened
|
|
28
34
|
* @fires sp-closed - Announces that the overlay has been closed
|
|
29
35
|
*/
|
|
30
|
-
export class OverlayTrigger extends
|
|
36
|
+
export class OverlayTrigger extends SpectrumElement {
|
|
31
37
|
constructor() {
|
|
32
38
|
super(...arguments);
|
|
33
39
|
/**
|
|
@@ -37,6 +43,8 @@ export class OverlayTrigger extends LitElement {
|
|
|
37
43
|
this.placement = 'bottom';
|
|
38
44
|
this.offset = 6;
|
|
39
45
|
this.disabled = false;
|
|
46
|
+
this.hasLongpressContent = false;
|
|
47
|
+
this._longpressId = `longpress-describedby-descriptor`;
|
|
40
48
|
this.abortOverlay = () => {
|
|
41
49
|
return;
|
|
42
50
|
};
|
|
@@ -57,7 +65,7 @@ export class OverlayTrigger extends LitElement {
|
|
|
57
65
|
// Keyboard event availability documented in README.md
|
|
58
66
|
/* eslint-disable lit-a11y/click-events-have-key-events */
|
|
59
67
|
return html `
|
|
60
|
-
<
|
|
68
|
+
<slot
|
|
61
69
|
id="trigger"
|
|
62
70
|
@click=${this.onTrigger}
|
|
63
71
|
@longpress=${this.onTrigger}
|
|
@@ -66,12 +74,9 @@ export class OverlayTrigger extends LitElement {
|
|
|
66
74
|
@focusin=${this.onTrigger}
|
|
67
75
|
@focusout=${this.onTrigger}
|
|
68
76
|
@sp-closed=${this.handleClose}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
name="trigger"
|
|
73
|
-
></slot>
|
|
74
|
-
</div>
|
|
77
|
+
@slotchange=${this.onTargetSlotChange}
|
|
78
|
+
name="trigger"
|
|
79
|
+
></slot>
|
|
75
80
|
<div id="overlay-content">
|
|
76
81
|
<slot
|
|
77
82
|
@slotchange=${this.onClickSlotChange}
|
|
@@ -85,6 +90,7 @@ export class OverlayTrigger extends LitElement {
|
|
|
85
90
|
@slotchange=${this.onHoverSlotChange}
|
|
86
91
|
name="hover-content"
|
|
87
92
|
></slot>
|
|
93
|
+
<slot name=${this._longpressId}></slot>
|
|
88
94
|
</div>
|
|
89
95
|
`;
|
|
90
96
|
/* eslint-enable lit-a11y/click-events-have-key-events */
|
|
@@ -98,6 +104,37 @@ export class OverlayTrigger extends LitElement {
|
|
|
98
104
|
if (changes.has('open')) {
|
|
99
105
|
this.manageOpen();
|
|
100
106
|
}
|
|
107
|
+
if (changes.has('hasLongpressContent')) {
|
|
108
|
+
this.manageLongpressDescriptor();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
manageLongpressDescriptor() {
|
|
112
|
+
const trigger = this.querySelector('[slot="trigger"]');
|
|
113
|
+
const ariaDescribedby = trigger.getAttribute('aria-describedby');
|
|
114
|
+
let descriptors = ariaDescribedby ? ariaDescribedby.split(/\s+/) : [];
|
|
115
|
+
if (this.hasLongpressContent) {
|
|
116
|
+
if (!this.longpressDescriptor) {
|
|
117
|
+
this.longpressDescriptor = document.createElement('div');
|
|
118
|
+
this.longpressDescriptor.id = this._longpressId;
|
|
119
|
+
this.longpressDescriptor.slot = this._longpressId;
|
|
120
|
+
}
|
|
121
|
+
const messageType = isIOS() || isAndroid() ? 'touch' : 'keyboard';
|
|
122
|
+
this.longpressDescriptor.textContent =
|
|
123
|
+
LONGPRESS_INSTRUCTIONS[messageType];
|
|
124
|
+
this.appendChild(this.longpressDescriptor);
|
|
125
|
+
descriptors.push(this._longpressId);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
if (this.longpressDescriptor)
|
|
129
|
+
this.longpressDescriptor.remove();
|
|
130
|
+
descriptors = descriptors.filter((descriptor) => descriptor !== this._longpressId);
|
|
131
|
+
}
|
|
132
|
+
if (descriptors.length) {
|
|
133
|
+
trigger.setAttribute('aria-describedby', descriptors.join(' '));
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
trigger.removeAttribute('aria-describedby');
|
|
137
|
+
}
|
|
101
138
|
}
|
|
102
139
|
closeAllOverlays() {
|
|
103
140
|
if (this.abortOverlay)
|
|
@@ -222,6 +259,8 @@ export class OverlayTrigger extends LitElement {
|
|
|
222
259
|
}
|
|
223
260
|
onLongpressSlotChange(event) {
|
|
224
261
|
this.longpressContent = this.extractSlotContentFromEvent(event);
|
|
262
|
+
this.hasLongpressContent =
|
|
263
|
+
!!this.longpressContent || !!this.closeLongpressOverlay;
|
|
225
264
|
this.manageOpen();
|
|
226
265
|
}
|
|
227
266
|
onHoverSlotChange(event) {
|
|
@@ -265,4 +304,7 @@ __decorate([
|
|
|
265
304
|
__decorate([
|
|
266
305
|
property({ type: Boolean, reflect: true })
|
|
267
306
|
], OverlayTrigger.prototype, "disabled", void 0);
|
|
307
|
+
__decorate([
|
|
308
|
+
state()
|
|
309
|
+
], OverlayTrigger.prototype, "hasLongpressContent", void 0);
|
|
268
310
|
//# sourceMappingURL=OverlayTrigger.js.map
|