@spectrum-web-components/overlay 0.30.1-overlay.42 → 0.31.1-overlay.29
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/package.json +6 -6
- package/src/OverlayBase.d.ts +3 -0
- package/src/OverlayBase.dev.js +15 -3
- package/src/OverlayBase.dev.js.map +2 -2
- package/src/OverlayBase.js +3 -3
- package/src/OverlayBase.js.map +3 -3
- package/src/OverlayDialog.dev.js +9 -0
- package/src/OverlayDialog.dev.js.map +2 -2
- package/src/OverlayDialog.js +1 -1
- package/src/OverlayDialog.js.map +2 -2
- package/src/OverlayNoPopover.dev.js +32 -4
- package/src/OverlayNoPopover.dev.js.map +2 -2
- package/src/OverlayNoPopover.js +1 -1
- package/src/OverlayNoPopover.js.map +3 -3
- package/src/OverlayPopover.dev.js +32 -4
- package/src/OverlayPopover.dev.js.map +2 -2
- package/src/OverlayPopover.js +1 -1
- package/src/OverlayPopover.js.map +3 -3
- package/stories/overlay-element.stories.js +24 -7
- package/stories/overlay-element.stories.js.map +2 -2
- package/test/overlay.test.js +9 -9
- package/test/overlay.test.js.map +2 -2
package/src/OverlayDialog.dev.js
CHANGED
|
@@ -17,8 +17,17 @@ export function OverlayDialog(constructor) {
|
|
|
17
17
|
async manageDialogOpen() {
|
|
18
18
|
const targetOpenState = this.open;
|
|
19
19
|
await this.managePosition();
|
|
20
|
+
if (this.open !== targetOpenState) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
20
23
|
await this.dialogEnsureOnDOM();
|
|
24
|
+
if (this.open !== targetOpenState) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
21
27
|
const focusEl = await this.dialogMakeTransition(targetOpenState);
|
|
28
|
+
if (this.open !== targetOpenState) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
22
31
|
await this.dialogApplyFocus(targetOpenState, focusEl);
|
|
23
32
|
}
|
|
24
33
|
async dialogEnsureOnDOM() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["OverlayDialog.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { ReactiveElement } from 'lit';\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedTransitionend,\n OpenableElement,\n OverlayBase,\n} from './OverlayBase.dev.js'\nimport { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport { OverlayOpenCloseDetail } from './overlay-types.dev.js'\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\nexport function OverlayDialog<T extends Constructor<OverlayBase>>(\n constructor: T\n): T & Constructor<ReactiveElement> {\n class OverlayWithDialog extends constructor {\n protected override async manageDialogOpen(): Promise<void> {\n const targetOpenState = this.open;\n await this.managePosition();\n await this.dialogEnsureOnDOM();\n const focusEl = await this.dialogMakeTransition(targetOpenState);\n await this.dialogApplyFocus(targetOpenState, focusEl);\n }\n\n protected async dialogEnsureOnDOM(): Promise<void> {\n await nextFrame();\n await nextFrame();\n await nextFrame();\n await nextFrame();\n }\n\n protected async dialogMakeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n let focusEl = null as HTMLElement | null;\n const start =\n (el: OpenableElement, index: number) =>\n async (): Promise<void> => {\n if (typeof el.open !== 'undefined') {\n el.open = targetOpenState;\n }\n if (!targetOpenState) {\n const close = (): void => {\n el.removeEventListener('close', close);\n finish(el, index);\n };\n el.addEventListener('close', close);\n }\n if (index > 0 || !targetOpenState) {\n return;\n }\n const event = targetOpenState\n ? BeforetoggleOpenEvent\n : BeforetoggleClosedEvent;\n this.dispatchEvent(new event());\n focusEl = focusEl || firstFocusableIn(el);\n if (!focusEl) {\n const childSlots = el.querySelectorAll('slot');\n childSlots.forEach((slot) => {\n if (!focusEl) {\n focusEl = firstFocusableSlottedIn(slot);\n }\n });\n }\n if (!this.isConnected || this.dialogEl.open) {\n return;\n }\n this.dialogEl.showModal();\n };\n const finish = (el: OpenableElement, index: number) => (): void => {\n if (this.open !== targetOpenState) {\n return;\n }\n const eventName = targetOpenState ? 'sp-opened' : 'sp-closed';\n if (index > 0) {\n el.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: false,\n composed: false,\n detail: { interaction: this.type },\n })\n );\n return;\n }\n if (!this.isConnected || targetOpenState !== this.open) {\n return;\n }\n const reportChange = (): void => {\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new Event(eventName, {\n bubbles: hasVirtualTrigger,\n composed: hasVirtualTrigger,\n })\n );\n el.dispatchEvent(\n new Event(eventName, {\n bubbles: false,\n composed: false,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n })\n );\n }\n };\n if (!targetOpenState && this.dialogEl.open) {\n this.dialogEl.addEventListener(\n 'close',\n () => {\n reportChange();\n },\n { once: true }\n );\n this.dialogEl.close();\n } else {\n reportChange();\n }\n };\n this.elements.forEach((el, index) => {\n guaranteedTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n\n protected async dialogApplyFocus(\n targetOpenState: boolean,\n focusEl: HTMLElement | null\n ): Promise<void> {\n /**\n * Focus should handled natively in `<dialog>` elements when leveraging `.showModal()`, but it's NOT.\n * - webkit bug: https://bugs.webkit.org/show_bug.cgi?id=255507\n * - firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1828398\n **/\n if (this.receivesFocus === 'false') {\n return;\n }\n\n await nextFrame();\n await nextFrame();\n if (targetOpenState === this.open && !this.open) {\n if (\n // Do not return focus to trigger when overlay is a \"hint\" (tooltip)\n this.type !== 'hint' &&\n // Only return focus when the trigger is not \"virtual\"\n this.triggerElement &&\n !(this.triggerElement instanceof VirtualTrigger)\n ) {\n if (\n this.contains(\n (this.getRootNode() as Document).activeElement\n )\n ) {\n this.triggerElement.focus();\n }\n }\n return;\n }\n\n focusEl?.focus();\n }\n }\n return OverlayWithDialog;\n}\n"],
|
|
5
|
-
"mappings": ";AAYA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OAGG;AACP,SAAS,sBAAsB;AAS/B,SAAS,YAA2B;AAChC,SAAO,IAAI,QAAQ,CAAC,QAAQ,sBAAsB,MAAM,IAAI,CAAC,CAAC;AAClE;AAEO,gBAAS,cACZ,aACgC;AAChC,QAAM,0BAA0B,YAAY;AAAA,IACxC,MAAyB,mBAAkC;AACvD,YAAM,kBAAkB,KAAK;AAC7B,YAAM,KAAK,eAAe;AAC1B,YAAM,KAAK,kBAAkB;AAC7B,YAAM,UAAU,MAAM,KAAK,qBAAqB,eAAe;AAC/D,YAAM,KAAK,iBAAiB,iBAAiB,OAAO;AAAA,IACxD;AAAA,IAEA,MAAgB,oBAAmC;AAC/C,YAAM,UAAU;AAChB,YAAM,UAAU;AAChB,YAAM,UAAU;AAChB,YAAM,UAAU;AAAA,IACpB;AAAA,IAEA,MAAgB,qBACZ,iBAC2B;AAC3B,UAAI,UAAU;AACd,YAAM,QACF,CAAC,IAAqB,UACtB,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rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { ReactiveElement } from 'lit';\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedTransitionend,\n OpenableElement,\n OverlayBase,\n} from './OverlayBase.dev.js'\nimport { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport { OverlayOpenCloseDetail } from './overlay-types.dev.js'\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\nexport function OverlayDialog<T extends Constructor<OverlayBase>>(\n constructor: T\n): T & Constructor<ReactiveElement> {\n class OverlayWithDialog extends constructor {\n protected override async manageDialogOpen(): Promise<void> {\n const targetOpenState = this.open;\n await this.managePosition();\n if (this.open !== targetOpenState) {\n return;\n }\n await this.dialogEnsureOnDOM();\n if (this.open !== targetOpenState) {\n return;\n }\n const focusEl = await this.dialogMakeTransition(targetOpenState);\n if (this.open !== targetOpenState) {\n return;\n }\n await this.dialogApplyFocus(targetOpenState, focusEl);\n }\n\n protected async dialogEnsureOnDOM(): Promise<void> {\n await nextFrame();\n await nextFrame();\n await nextFrame();\n await nextFrame();\n }\n\n protected async dialogMakeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n let focusEl = null as HTMLElement | null;\n const start =\n (el: OpenableElement, index: number) =>\n async (): Promise<void> => {\n if (typeof el.open !== 'undefined') {\n el.open = targetOpenState;\n }\n if (!targetOpenState) {\n const close = (): void => {\n el.removeEventListener('close', close);\n finish(el, index);\n };\n el.addEventListener('close', close);\n }\n if (index > 0 || !targetOpenState) {\n return;\n }\n const event = targetOpenState\n ? BeforetoggleOpenEvent\n : BeforetoggleClosedEvent;\n this.dispatchEvent(new event());\n focusEl = focusEl || firstFocusableIn(el);\n if (!focusEl) {\n const childSlots = el.querySelectorAll('slot');\n childSlots.forEach((slot) => {\n if (!focusEl) {\n focusEl = firstFocusableSlottedIn(slot);\n }\n });\n }\n if (!this.isConnected || this.dialogEl.open) {\n return;\n }\n this.dialogEl.showModal();\n };\n const finish = (el: OpenableElement, index: number) => (): void => {\n if (this.open !== targetOpenState) {\n return;\n }\n const eventName = targetOpenState ? 'sp-opened' : 'sp-closed';\n if (index > 0) {\n el.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: false,\n composed: false,\n detail: { interaction: this.type },\n })\n );\n return;\n }\n if (!this.isConnected || targetOpenState !== this.open) {\n return;\n }\n const reportChange = (): void => {\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new Event(eventName, {\n bubbles: hasVirtualTrigger,\n composed: hasVirtualTrigger,\n })\n );\n el.dispatchEvent(\n new Event(eventName, {\n bubbles: false,\n composed: false,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n })\n );\n }\n };\n if (!targetOpenState && this.dialogEl.open) {\n this.dialogEl.addEventListener(\n 'close',\n () => {\n reportChange();\n },\n { once: true }\n );\n this.dialogEl.close();\n } else {\n reportChange();\n }\n };\n this.elements.forEach((el, index) => {\n guaranteedTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n\n protected async dialogApplyFocus(\n targetOpenState: boolean,\n focusEl: HTMLElement | null\n ): Promise<void> {\n /**\n * Focus should handled natively in `<dialog>` elements when leveraging `.showModal()`, but it's NOT.\n * - webkit bug: https://bugs.webkit.org/show_bug.cgi?id=255507\n * - firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1828398\n **/\n if (this.receivesFocus === 'false') {\n return;\n }\n\n await nextFrame();\n await nextFrame();\n if (targetOpenState === this.open && !this.open) {\n if (\n // Do not return focus to trigger when overlay is a \"hint\" (tooltip)\n this.type !== 'hint' &&\n // Only return focus when the trigger is not \"virtual\"\n this.triggerElement &&\n !(this.triggerElement instanceof VirtualTrigger)\n ) {\n if (\n this.contains(\n (this.getRootNode() as Document).activeElement\n )\n ) {\n this.triggerElement.focus();\n }\n }\n return;\n }\n\n focusEl?.focus();\n }\n }\n return OverlayWithDialog;\n}\n"],
|
|
5
|
+
"mappings": ";AAYA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OAGG;AACP,SAAS,sBAAsB;AAS/B,SAAS,YAA2B;AAChC,SAAO,IAAI,QAAQ,CAAC,QAAQ,sBAAsB,MAAM,IAAI,CAAC,CAAC;AAClE;AAEO,gBAAS,cACZ,aACgC;AAChC,QAAM,0BAA0B,YAAY;AAAA,IACxC,MAAyB,mBAAkC;AACvD,YAAM,kBAAkB,KAAK;AAC7B,YAAM,KAAK,eAAe;AAC1B,UAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,MACJ;AACA,YAAM,KAAK,kBAAkB;AAC7B,UAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,MACJ;AACA,YAAM,UAAU,MAAM,KAAK,qBAAqB,eAAe;AAC/D,UAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,MACJ;AACA,YAAM,KAAK,iBAAiB,iBAAiB,OAAO;AAAA,IACxD;AAAA,IAEA,MAAgB,oBAAmC;AAC/C,YAAM,UAAU;AAChB,YAAM,UAAU;AAChB,YAAM,UAAU;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;AACA;AAAA,MACJ;AAEA,yCAAS;AAAA,IACb;AAAA,EACJ;AACA,SAAO;AACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/OverlayDialog.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";import{firstFocusableIn as p,firstFocusableSlottedIn as u}from"@spectrum-web-components/shared/src/first-focusable-in.js";import{BeforetoggleClosedEvent as f,BeforetoggleOpenEvent as v,guaranteedTransitionend as E}from"./OverlayBase.js";import{VirtualTrigger as d}from"./VirtualTrigger.js";function r(){return new Promise(l=>requestAnimationFrame(()=>l()))}export function OverlayDialog(l){class m extends l{async manageDialogOpen(){const
|
|
1
|
+
"use strict";import{firstFocusableIn as p,firstFocusableSlottedIn as u}from"@spectrum-web-components/shared/src/first-focusable-in.js";import{BeforetoggleClosedEvent as f,BeforetoggleOpenEvent as v,guaranteedTransitionend as E}from"./OverlayBase.js";import{VirtualTrigger as d}from"./VirtualTrigger.js";function r(){return new Promise(l=>requestAnimationFrame(()=>l()))}export function OverlayDialog(l){class m extends l{async manageDialogOpen(){const e=this.open;if(await this.managePosition(),this.open!==e||(await this.dialogEnsureOnDOM(),this.open!==e))return;const i=await this.dialogMakeTransition(e);this.open===e&&await this.dialogApplyFocus(e,i)}async dialogEnsureOnDOM(){await r(),await r(),await r(),await r()}async dialogMakeTransition(e){let i=null;const h=(t,n)=>async()=>{if(typeof t.open!="undefined"&&(t.open=e),!e){const s=()=>{t.removeEventListener("close",s),c(t,n)};t.addEventListener("close",s)}if(n>0||!e)return;const o=e?v:f;this.dispatchEvent(new o),i=i||p(t),i||t.querySelectorAll("slot").forEach(a=>{i||(i=u(a))}),!(!this.isConnected||this.dialogEl.open)&&this.dialogEl.showModal()},c=(t,n)=>()=>{if(this.open!==e)return;const o=e?"sp-opened":"sp-closed";if(n>0){t.dispatchEvent(new CustomEvent(o,{bubbles:!1,composed:!1,detail:{interaction:this.type}}));return}if(!this.isConnected||e!==this.open)return;const s=()=>{const a=this.triggerElement instanceof d;this.dispatchEvent(new Event(o,{bubbles:a,composed:a})),t.dispatchEvent(new Event(o,{bubbles:!1,composed:!1})),this.triggerElement&&!a&&this.triggerElement.dispatchEvent(new CustomEvent(o,{bubbles:!0,composed:!0,detail:{interaction:this.type}}))};!e&&this.dialogEl.open?(this.dialogEl.addEventListener("close",()=>{s()},{once:!0}),this.dialogEl.close()):s()};return this.elements.forEach((t,n)=>{E(t,h(t,n),c(t,n))}),i}async dialogApplyFocus(e,i){if(this.receivesFocus!=="false"){if(await r(),await r(),e===this.open&&!this.open){this.type!=="hint"&&this.triggerElement&&!(this.triggerElement instanceof d)&&this.contains(this.getRootNode().activeElement)&&this.triggerElement.focus();return}i==null||i.focus()}}}return m}
|
|
2
2
|
//# sourceMappingURL=OverlayDialog.js.map
|
package/src/OverlayDialog.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["OverlayDialog.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { ReactiveElement } from 'lit';\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedTransitionend,\n OpenableElement,\n OverlayBase,\n} from './OverlayBase.js';\nimport { VirtualTrigger } from './VirtualTrigger.js';\nimport { OverlayOpenCloseDetail } from './overlay-types.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\nexport function OverlayDialog<T extends Constructor<OverlayBase>>(\n constructor: T\n): T & Constructor<ReactiveElement> {\n class OverlayWithDialog extends constructor {\n protected override async manageDialogOpen(): Promise<void> {\n const targetOpenState = this.open;\n await this.managePosition();\n await this.dialogEnsureOnDOM();\n const focusEl = await this.dialogMakeTransition(targetOpenState);\n await this.dialogApplyFocus(targetOpenState, focusEl);\n }\n\n protected async dialogEnsureOnDOM(): Promise<void> {\n await nextFrame();\n await nextFrame();\n await nextFrame();\n await nextFrame();\n }\n\n protected async dialogMakeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n let focusEl = null as HTMLElement | null;\n const start =\n (el: OpenableElement, index: number) =>\n async (): Promise<void> => {\n if (typeof el.open !== 'undefined') {\n el.open = targetOpenState;\n }\n if (!targetOpenState) {\n const close = (): void => {\n el.removeEventListener('close', close);\n finish(el, index);\n };\n el.addEventListener('close', close);\n }\n if (index > 0 || !targetOpenState) {\n return;\n }\n const event = targetOpenState\n ? BeforetoggleOpenEvent\n : BeforetoggleClosedEvent;\n this.dispatchEvent(new event());\n focusEl = focusEl || firstFocusableIn(el);\n if (!focusEl) {\n const childSlots = el.querySelectorAll('slot');\n childSlots.forEach((slot) => {\n if (!focusEl) {\n focusEl = firstFocusableSlottedIn(slot);\n }\n });\n }\n if (!this.isConnected || this.dialogEl.open) {\n return;\n }\n this.dialogEl.showModal();\n };\n const finish = (el: OpenableElement, index: number) => (): void => {\n if (this.open !== targetOpenState) {\n return;\n }\n const eventName = targetOpenState ? 'sp-opened' : 'sp-closed';\n if (index > 0) {\n el.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: false,\n composed: false,\n detail: { interaction: this.type },\n })\n );\n return;\n }\n if (!this.isConnected || targetOpenState !== this.open) {\n return;\n }\n const reportChange = (): void => {\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new Event(eventName, {\n bubbles: hasVirtualTrigger,\n composed: hasVirtualTrigger,\n })\n );\n el.dispatchEvent(\n new Event(eventName, {\n bubbles: false,\n composed: false,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n })\n );\n }\n };\n if (!targetOpenState && this.dialogEl.open) {\n this.dialogEl.addEventListener(\n 'close',\n () => {\n reportChange();\n },\n { once: true }\n );\n this.dialogEl.close();\n } else {\n reportChange();\n }\n };\n this.elements.forEach((el, index) => {\n guaranteedTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n\n protected async dialogApplyFocus(\n targetOpenState: boolean,\n focusEl: HTMLElement | null\n ): Promise<void> {\n /**\n * Focus should handled natively in `<dialog>` elements when leveraging `.showModal()`, but it's NOT.\n * - webkit bug: https://bugs.webkit.org/show_bug.cgi?id=255507\n * - firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1828398\n **/\n if (this.receivesFocus === 'false') {\n return;\n }\n\n await nextFrame();\n await nextFrame();\n if (targetOpenState === this.open && !this.open) {\n if (\n // Do not return focus to trigger when overlay is a \"hint\" (tooltip)\n this.type !== 'hint' &&\n // Only return focus when the trigger is not \"virtual\"\n this.triggerElement &&\n !(this.triggerElement instanceof VirtualTrigger)\n ) {\n if (\n this.contains(\n (this.getRootNode() as Document).activeElement\n )\n ) {\n this.triggerElement.focus();\n }\n }\n return;\n }\n\n focusEl?.focus();\n }\n }\n return OverlayWithDialog;\n}\n"],
|
|
5
|
-
"mappings": "aAYA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DACP,OACI,2BAAAC,EACA,yBAAAC,EACA,2BAAAC,MAGG,mBACP,OAAS,kBAAAC,MAAsB,sBAS/B,SAASC,GAA2B,CAChC,OAAO,IAAI,QAASC,GAAQ,sBAAsB,IAAMA,EAAI,CAAC,CAAC,CAClE,CAEO,gBAAS,cACZC,EACgC,CAChC,MAAMC,UAA0BD,CAAY,CACxC,MAAyB,kBAAkC,CACvD,MAAME,EAAkB,KAAK,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { ReactiveElement } from 'lit';\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedTransitionend,\n OpenableElement,\n OverlayBase,\n} from './OverlayBase.js';\nimport { VirtualTrigger } from './VirtualTrigger.js';\nimport { OverlayOpenCloseDetail } from './overlay-types.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\nexport function OverlayDialog<T extends Constructor<OverlayBase>>(\n constructor: T\n): T & Constructor<ReactiveElement> {\n class OverlayWithDialog extends constructor {\n protected override async manageDialogOpen(): Promise<void> {\n const targetOpenState = this.open;\n await this.managePosition();\n if (this.open !== targetOpenState) {\n return;\n }\n await this.dialogEnsureOnDOM();\n if (this.open !== targetOpenState) {\n return;\n }\n const focusEl = await this.dialogMakeTransition(targetOpenState);\n if (this.open !== targetOpenState) {\n return;\n }\n await this.dialogApplyFocus(targetOpenState, focusEl);\n }\n\n protected async dialogEnsureOnDOM(): Promise<void> {\n await nextFrame();\n await nextFrame();\n await nextFrame();\n await nextFrame();\n }\n\n protected async dialogMakeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n let focusEl = null as HTMLElement | null;\n const start =\n (el: OpenableElement, index: number) =>\n async (): Promise<void> => {\n if (typeof el.open !== 'undefined') {\n el.open = targetOpenState;\n }\n if (!targetOpenState) {\n const close = (): void => {\n el.removeEventListener('close', close);\n finish(el, index);\n };\n el.addEventListener('close', close);\n }\n if (index > 0 || !targetOpenState) {\n return;\n }\n const event = targetOpenState\n ? BeforetoggleOpenEvent\n : BeforetoggleClosedEvent;\n this.dispatchEvent(new event());\n focusEl = focusEl || firstFocusableIn(el);\n if (!focusEl) {\n const childSlots = el.querySelectorAll('slot');\n childSlots.forEach((slot) => {\n if (!focusEl) {\n focusEl = firstFocusableSlottedIn(slot);\n }\n });\n }\n if (!this.isConnected || this.dialogEl.open) {\n return;\n }\n this.dialogEl.showModal();\n };\n const finish = (el: OpenableElement, index: number) => (): void => {\n if (this.open !== targetOpenState) {\n return;\n }\n const eventName = targetOpenState ? 'sp-opened' : 'sp-closed';\n if (index > 0) {\n el.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: false,\n composed: false,\n detail: { interaction: this.type },\n })\n );\n return;\n }\n if (!this.isConnected || targetOpenState !== this.open) {\n return;\n }\n const reportChange = (): void => {\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new Event(eventName, {\n bubbles: hasVirtualTrigger,\n composed: hasVirtualTrigger,\n })\n );\n el.dispatchEvent(\n new Event(eventName, {\n bubbles: false,\n composed: false,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n })\n );\n }\n };\n if (!targetOpenState && this.dialogEl.open) {\n this.dialogEl.addEventListener(\n 'close',\n () => {\n reportChange();\n },\n { once: true }\n );\n this.dialogEl.close();\n } else {\n reportChange();\n }\n };\n this.elements.forEach((el, index) => {\n guaranteedTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n\n protected async dialogApplyFocus(\n targetOpenState: boolean,\n focusEl: HTMLElement | null\n ): Promise<void> {\n /**\n * Focus should handled natively in `<dialog>` elements when leveraging `.showModal()`, but it's NOT.\n * - webkit bug: https://bugs.webkit.org/show_bug.cgi?id=255507\n * - firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1828398\n **/\n if (this.receivesFocus === 'false') {\n return;\n }\n\n await nextFrame();\n await nextFrame();\n if (targetOpenState === this.open && !this.open) {\n if (\n // Do not return focus to trigger when overlay is a \"hint\" (tooltip)\n this.type !== 'hint' &&\n // Only return focus when the trigger is not \"virtual\"\n this.triggerElement &&\n !(this.triggerElement instanceof VirtualTrigger)\n ) {\n if (\n this.contains(\n (this.getRootNode() as Document).activeElement\n )\n ) {\n this.triggerElement.focus();\n }\n }\n return;\n }\n\n focusEl?.focus();\n }\n }\n return OverlayWithDialog;\n}\n"],
|
|
5
|
+
"mappings": "aAYA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DACP,OACI,2BAAAC,EACA,yBAAAC,EACA,2BAAAC,MAGG,mBACP,OAAS,kBAAAC,MAAsB,sBAS/B,SAASC,GAA2B,CAChC,OAAO,IAAI,QAASC,GAAQ,sBAAsB,IAAMA,EAAI,CAAC,CAAC,CAClE,CAEO,gBAAS,cACZC,EACgC,CAChC,MAAMC,UAA0BD,CAAY,CACxC,MAAyB,kBAAkC,CACvD,MAAME,EAAkB,KAAK,KAM7B,GALA,MAAM,KAAK,eAAe,EACtB,KAAK,OAASA,IAGlB,MAAM,KAAK,kBAAkB,EACzB,KAAK,OAASA,GACd,OAEJ,MAAMC,EAAU,MAAM,KAAK,qBAAqBD,CAAe,EAC3D,KAAK,OAASA,GAGlB,M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AS,GACT,SAAU,EACd,CAAC,CACL,EACI,KAAK,gBAAkB,CAACE,GACvB,KAAK,eAA+B,cACjC,IAAI,YAAoCF,EAAW,CAC/C,QAAS,GACT,SAAU,GACV,OAAQ,CAAE,YAAa,KAAK,IAAK,CACrC,CAAC,CACL,CAER,EACI,CAACT,GAAmB,KAAK,SAAS,MAClC,KAAK,SAAS,iBACV,QACA,IAAM,CACFU,EAAa,CACjB,EACA,CAAE,KAAM,EAAK,CACjB,EACA,KAAK,SAAS,MAAM,GAEpBA,EAAa,CAErB,EACA,YAAK,SAAS,QAAQ,CAACP,EAAIC,IAAU,CACjCV,EACIS,EACAD,EAAMC,EAAIC,CAAK,EACfE,EAAOH,EAAIC,CAAK,CACpB,CACJ,CAAC,EACMH,CACX,CAEA,MAAgB,iBACZD,EACAC,EACa,CAMb,GAAI,KAAK,gBAAkB,QAM3B,IAFA,MAAML,EAAU,EAChB,MAAMA,EAAU,EACZI,IAAoB,KAAK,MAAQ,CAAC,KAAK,KAAM,CAGzC,KAAK,OAAS,QAEd,KAAK,gBACL,EAAE,KAAK,0BAA0BL,IAG7B,KAAK,SACA,KAAK,YAAY,EAAe,aACrC,GAEA,KAAK,eAAe,MAAM,EAGlC,OAGJM,GAAA,MAAAA,EAAS,QACb,CACJ,CACA,OAAOF,CACX",
|
|
6
6
|
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedTransitionend", "VirtualTrigger", "nextFrame", "res", "constructor", "OverlayWithDialog", "targetOpenState", "focusEl", "start", "el", "index", "close", "finish", "event", "slot", "eventName", "reportChange", "hasVirtualTrigger"]
|
|
7
7
|
}
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
BeforetoggleClosedEvent,
|
|
8
8
|
BeforetoggleOpenEvent,
|
|
9
|
-
guaranteedTransitionend
|
|
9
|
+
guaranteedTransitionend,
|
|
10
|
+
overlayTimer
|
|
10
11
|
} from "./OverlayBase.dev.js";
|
|
11
12
|
import { VirtualTrigger } from "./VirtualTrigger.dev.js";
|
|
12
13
|
function nextFrame() {
|
|
@@ -17,15 +18,43 @@ export function OverlayNoPopover(constructor) {
|
|
|
17
18
|
async managePopoverOpen() {
|
|
18
19
|
const targetOpenState = this.open;
|
|
19
20
|
await this.managePosition();
|
|
21
|
+
if (this.open !== targetOpenState) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
await this.manageDelay(targetOpenState);
|
|
25
|
+
if (this.open !== targetOpenState) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
20
28
|
await this.ensureOnDOM();
|
|
29
|
+
if (this.open !== targetOpenState) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
21
32
|
const focusEl = await this.makeTransition(targetOpenState);
|
|
33
|
+
if (this.open !== targetOpenState) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
22
36
|
await this.applyFocus(targetOpenState, focusEl);
|
|
23
37
|
}
|
|
38
|
+
async manageDelay(targetOpenState) {
|
|
39
|
+
if (targetOpenState === false || targetOpenState !== this.open) {
|
|
40
|
+
overlayTimer.close(this);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (this.delayed) {
|
|
44
|
+
const cancelled = await overlayTimer.openTimer(this);
|
|
45
|
+
if (cancelled) {
|
|
46
|
+
this.open = !targetOpenState;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
24
50
|
async ensureOnDOM() {
|
|
25
51
|
await nextFrame();
|
|
26
52
|
await nextFrame();
|
|
27
53
|
}
|
|
28
54
|
async makeTransition(targetOpenState) {
|
|
55
|
+
if (this.open !== targetOpenState) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
29
58
|
let focusEl = null;
|
|
30
59
|
const start = (el, index) => () => {
|
|
31
60
|
if (targetOpenState !== this.open) {
|
|
@@ -94,15 +123,14 @@ export function OverlayNoPopover(constructor) {
|
|
|
94
123
|
return focusEl;
|
|
95
124
|
}
|
|
96
125
|
async applyFocus(targetOpenState, focusEl) {
|
|
97
|
-
if (this.receivesFocus === "false") {
|
|
126
|
+
if (this.receivesFocus === "false" || this.type === "hint") {
|
|
98
127
|
return;
|
|
99
128
|
}
|
|
100
129
|
await nextFrame();
|
|
101
130
|
await nextFrame();
|
|
102
131
|
if (targetOpenState === this.open && !this.open) {
|
|
103
132
|
if (
|
|
104
|
-
//
|
|
105
|
-
this.type !== "hint" && // Only return focus when the trigger is not "virtual"
|
|
133
|
+
// Only return focus when the trigger is not "virtual"
|
|
106
134
|
this.triggerElement && !(this.triggerElement instanceof VirtualTrigger)
|
|
107
135
|
) {
|
|
108
136
|
if (this.contains(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["OverlayNoPopover.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport { ReactiveElement } from 'lit';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedTransitionend,\n OpenableElement,\n OverlayBase,\n} from './OverlayBase.dev.js'\nimport { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport { OverlayOpenCloseDetail } from './overlay-types.dev.js'\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\nexport function OverlayNoPopover<T extends Constructor<OverlayBase>>(\n constructor: T\n): T & Constructor<ReactiveElement> {\n class OverlayWithNoPopover extends constructor {\n protected override async managePopoverOpen(): Promise<void> {\n const targetOpenState = this.open;\n await this.managePosition();\n await this.ensureOnDOM();\n const focusEl = await this.makeTransition(targetOpenState);\n await this.applyFocus(targetOpenState, focusEl);\n }\n\n private async ensureOnDOM(): Promise<void> {\n await nextFrame();\n await nextFrame();\n }\n\n private async makeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n let focusEl = null as HTMLElement | null;\n const start = (el: OpenableElement, index: number) => (): void => {\n if (targetOpenState !== this.open) {\n return;\n }\n if (typeof el.open !== 'undefined') {\n el.open = targetOpenState;\n }\n if (index === 0) {\n const event = targetOpenState\n ? BeforetoggleOpenEvent\n : BeforetoggleClosedEvent;\n this.dispatchEvent(new event());\n }\n if (targetOpenState !== true) {\n return;\n }\n focusEl = focusEl || firstFocusableIn(el);\n if (focusEl) {\n return;\n }\n const childSlots = el.querySelectorAll('slot');\n childSlots.forEach((slot) => {\n if (!focusEl) {\n focusEl = firstFocusableSlottedIn(slot);\n }\n });\n };\n const finish = (el: OpenableElement, index: number) => (): void => {\n if (this.open !== targetOpenState) {\n return;\n }\n const eventName = targetOpenState ? 'sp-opened' : 'sp-closed';\n el.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: false,\n composed: false,\n detail: { interaction: this.type },\n })\n );\n if (index > 0) {\n return;\n }\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new Event(eventName, {\n bubbles: hasVirtualTrigger,\n composed: hasVirtualTrigger,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n })\n );\n }\n };\n this.elements.forEach((el, index) => {\n guaranteedTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n\n private async applyFocus(\n targetOpenState: boolean,\n focusEl: HTMLElement | null\n ): Promise<void> {\n if (this.receivesFocus === 'false') {\n return;\n }\n\n await nextFrame();\n await nextFrame();\n if (targetOpenState === this.open && !this.open) {\n if (\n //
|
|
5
|
-
"mappings": ";AAWA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport { ReactiveElement } from 'lit';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedTransitionend,\n OpenableElement,\n OverlayBase,\n overlayTimer,\n} from './OverlayBase.dev.js'\nimport { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport { OverlayOpenCloseDetail } from './overlay-types.dev.js'\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\nexport function OverlayNoPopover<T extends Constructor<OverlayBase>>(\n constructor: T\n): T & Constructor<ReactiveElement> {\n class OverlayWithNoPopover extends constructor {\n protected override async managePopoverOpen(): Promise<void> {\n const targetOpenState = this.open;\n await this.managePosition();\n if (this.open !== targetOpenState) {\n return;\n }\n await this.manageDelay(targetOpenState);\n if (this.open !== targetOpenState) {\n return;\n }\n await this.ensureOnDOM();\n if (this.open !== targetOpenState) {\n return;\n }\n const focusEl = await this.makeTransition(targetOpenState);\n if (this.open !== targetOpenState) {\n return;\n }\n await this.applyFocus(targetOpenState, focusEl);\n }\n\n private async manageDelay(targetOpenState: boolean): Promise<void> {\n if (targetOpenState === false || targetOpenState !== this.open) {\n overlayTimer.close(this);\n return;\n }\n if (this.delayed) {\n const cancelled = await overlayTimer.openTimer(this);\n if (cancelled) {\n this.open = !targetOpenState;\n }\n }\n }\n\n private async ensureOnDOM(): Promise<void> {\n await nextFrame();\n await nextFrame();\n }\n\n private async makeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n if (this.open !== targetOpenState) {\n return null;\n }\n let focusEl = null as HTMLElement | null;\n const start = (el: OpenableElement, index: number) => (): void => {\n if (targetOpenState !== this.open) {\n return;\n }\n if (typeof el.open !== 'undefined') {\n el.open = targetOpenState;\n }\n if (index === 0) {\n const event = targetOpenState\n ? BeforetoggleOpenEvent\n : BeforetoggleClosedEvent;\n this.dispatchEvent(new event());\n }\n if (targetOpenState !== true) {\n return;\n }\n focusEl = focusEl || firstFocusableIn(el);\n if (focusEl) {\n return;\n }\n const childSlots = el.querySelectorAll('slot');\n childSlots.forEach((slot) => {\n if (!focusEl) {\n focusEl = firstFocusableSlottedIn(slot);\n }\n });\n };\n const finish = (el: OpenableElement, index: number) => (): void => {\n if (this.open !== targetOpenState) {\n return;\n }\n const eventName = targetOpenState ? 'sp-opened' : 'sp-closed';\n el.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: false,\n composed: false,\n detail: { interaction: this.type },\n })\n );\n if (index > 0) {\n return;\n }\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new Event(eventName, {\n bubbles: hasVirtualTrigger,\n composed: hasVirtualTrigger,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n })\n );\n }\n };\n this.elements.forEach((el, index) => {\n guaranteedTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n\n private async applyFocus(\n targetOpenState: boolean,\n focusEl: HTMLElement | null\n ): Promise<void> {\n // Do not move focus when explicitly told not to\n // and when the Overlay is a \"hint\"\n if (this.receivesFocus === 'false' || this.type === 'hint') {\n return;\n }\n\n await nextFrame();\n await nextFrame();\n if (targetOpenState === this.open && !this.open) {\n if (\n // Only return focus when the trigger is not \"virtual\"\n this.triggerElement &&\n !(this.triggerElement instanceof VirtualTrigger)\n ) {\n if (\n this.contains(\n (this.getRootNode() as Document).activeElement\n )\n ) {\n this.triggerElement.focus();\n }\n }\n return;\n }\n\n focusEl?.focus();\n }\n }\n return OverlayWithNoPopover;\n}\n"],
|
|
5
|
+
"mappings": ";AAWA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,OACG;AACP,SAAS,sBAAsB;AAS/B,SAAS,YAA2B;AAChC,SAAO,IAAI,QAAQ,CAAC,QAAQ,sBAAsB,MAAM,IAAI,CAAC,CAAC;AAClE;AAEO,gBAAS,iBACZ,aACgC;AAChC,QAAM,6BAA6B,YAAY;AAAA,IAC3C,MAAyB,oBAAmC;AACxD,YAAM,kBAAkB,KAAK;AAC7B,YAAM,KAAK,eAAe;AAC1B,UAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,MACJ;AACA,YAAM,KAAK,YAAY,eAAe;AACtC,UAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,MACJ;AACA,YAAM,KAAK,YAAY;AACvB,UAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,MACJ;AACA,YAAM,UAAU,MAAM,KAAK,eAA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@@
|
|
|
1
|
-
"use strict";import{firstFocusableIn as
|
|
1
|
+
"use strict";import{firstFocusableIn as h,firstFocusableSlottedIn as f}from"@spectrum-web-components/shared/src/first-focusable-in.js";import{BeforetoggleClosedEvent as v,BeforetoggleOpenEvent as d,guaranteedTransitionend as y,overlayTimer as l}from"./OverlayBase.js";import{VirtualTrigger as c}from"./VirtualTrigger.js";function r(){return new Promise(a=>requestAnimationFrame(()=>a()))}export function OverlayNoPopover(a){class m extends a{async managePopoverOpen(){const e=this.open;if(await this.managePosition(),this.open!==e||(await this.manageDelay(e),this.open!==e)||(await this.ensureOnDOM(),this.open!==e))return;const t=await this.makeTransition(e);this.open===e&&await this.applyFocus(e,t)}async manageDelay(e){if(e===!1||e!==this.open){l.close(this);return}this.delayed&&await l.openTimer(this)&&(this.open=!e)}async ensureOnDOM(){await r(),await r()}async makeTransition(e){if(this.open!==e)return null;let t=null;const p=(i,o)=>()=>{if(e!==this.open)return;if(typeof i.open!="undefined"&&(i.open=e),o===0){const n=e?d:v;this.dispatchEvent(new n)}if(e!==!0||(t=t||h(i),t))return;i.querySelectorAll("slot").forEach(n=>{t||(t=f(n))})},u=(i,o)=>()=>{if(this.open!==e)return;const s=e?"sp-opened":"sp-closed";if(i.dispatchEvent(new CustomEvent(s,{bubbles:!1,composed:!1,detail:{interaction:this.type}})),o>0)return;const n=this.triggerElement instanceof c;this.dispatchEvent(new Event(s,{bubbles:n,composed:n})),this.triggerElement&&!n&&this.triggerElement.dispatchEvent(new CustomEvent(s,{bubbles:!0,composed:!0,detail:{interaction:this.type}}))};return this.elements.forEach((i,o)=>{y(i,p(i,o),u(i,o))}),t}async applyFocus(e,t){if(!(this.receivesFocus==="false"||this.type==="hint")){if(await r(),await r(),e===this.open&&!this.open){this.triggerElement&&!(this.triggerElement instanceof c)&&this.contains(this.getRootNode().activeElement)&&this.triggerElement.focus();return}t==null||t.focus()}}}return m}
|
|
2
2
|
//# sourceMappingURL=OverlayNoPopover.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["OverlayNoPopover.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport { ReactiveElement } from 'lit';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedTransitionend,\n OpenableElement,\n OverlayBase,\n} from './OverlayBase.js';\nimport { VirtualTrigger } from './VirtualTrigger.js';\nimport { OverlayOpenCloseDetail } from './overlay-types.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\nexport function OverlayNoPopover<T extends Constructor<OverlayBase>>(\n constructor: T\n): T & Constructor<ReactiveElement> {\n class OverlayWithNoPopover extends constructor {\n protected override async managePopoverOpen(): Promise<void> {\n const targetOpenState = this.open;\n await this.managePosition();\n await this.ensureOnDOM();\n const focusEl = await this.makeTransition(targetOpenState);\n await this.applyFocus(targetOpenState, focusEl);\n }\n\n private async ensureOnDOM(): Promise<void> {\n await nextFrame();\n await nextFrame();\n }\n\n private async makeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n let focusEl = null as HTMLElement | null;\n const start = (el: OpenableElement, index: number) => (): void => {\n if (targetOpenState !== this.open) {\n return;\n }\n if (typeof el.open !== 'undefined') {\n el.open = targetOpenState;\n }\n if (index === 0) {\n const event = targetOpenState\n ? BeforetoggleOpenEvent\n : BeforetoggleClosedEvent;\n this.dispatchEvent(new event());\n }\n if (targetOpenState !== true) {\n return;\n }\n focusEl = focusEl || firstFocusableIn(el);\n if (focusEl) {\n return;\n }\n const childSlots = el.querySelectorAll('slot');\n childSlots.forEach((slot) => {\n if (!focusEl) {\n focusEl = firstFocusableSlottedIn(slot);\n }\n });\n };\n const finish = (el: OpenableElement, index: number) => (): void => {\n if (this.open !== targetOpenState) {\n return;\n }\n const eventName = targetOpenState ? 'sp-opened' : 'sp-closed';\n el.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: false,\n composed: false,\n detail: { interaction: this.type },\n })\n );\n if (index > 0) {\n return;\n }\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new Event(eventName, {\n bubbles: hasVirtualTrigger,\n composed: hasVirtualTrigger,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n })\n );\n }\n };\n this.elements.forEach((el, index) => {\n guaranteedTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n\n private async applyFocus(\n targetOpenState: boolean,\n focusEl: HTMLElement | null\n ): Promise<void> {\n if (this.receivesFocus === 'false') {\n return;\n }\n\n await nextFrame();\n await nextFrame();\n if (targetOpenState === this.open && !this.open) {\n if (\n //
|
|
5
|
-
"mappings": "aAWA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DAEP,OACI,2BAAAC,EACA,yBAAAC,EACA,2BAAAC,
|
|
6
|
-
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedTransitionend", "VirtualTrigger", "nextFrame", "res", "constructor", "OverlayWithNoPopover", "targetOpenState", "focusEl", "start", "el", "index", "event", "slot", "finish", "eventName", "hasVirtualTrigger"]
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport { ReactiveElement } from 'lit';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedTransitionend,\n OpenableElement,\n OverlayBase,\n overlayTimer,\n} from './OverlayBase.js';\nimport { VirtualTrigger } from './VirtualTrigger.js';\nimport { OverlayOpenCloseDetail } from './overlay-types.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\nexport function OverlayNoPopover<T extends Constructor<OverlayBase>>(\n constructor: T\n): T & Constructor<ReactiveElement> {\n class OverlayWithNoPopover extends constructor {\n protected override async managePopoverOpen(): Promise<void> {\n const targetOpenState = this.open;\n await this.managePosition();\n if (this.open !== targetOpenState) {\n return;\n }\n await this.manageDelay(targetOpenState);\n if (this.open !== targetOpenState) {\n return;\n }\n await this.ensureOnDOM();\n if (this.open !== targetOpenState) {\n return;\n }\n const focusEl = await this.makeTransition(targetOpenState);\n if (this.open !== targetOpenState) {\n return;\n }\n await this.applyFocus(targetOpenState, focusEl);\n }\n\n private async manageDelay(targetOpenState: boolean): Promise<void> {\n if (targetOpenState === false || targetOpenState !== this.open) {\n overlayTimer.close(this);\n return;\n }\n if (this.delayed) {\n const cancelled = await overlayTimer.openTimer(this);\n if (cancelled) {\n this.open = !targetOpenState;\n }\n }\n }\n\n private async ensureOnDOM(): Promise<void> {\n await nextFrame();\n await nextFrame();\n }\n\n private async makeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n if (this.open !== targetOpenState) {\n return null;\n }\n let focusEl = null as HTMLElement | null;\n const start = (el: OpenableElement, index: number) => (): void => {\n if (targetOpenState !== this.open) {\n return;\n }\n if (typeof el.open !== 'undefined') {\n el.open = targetOpenState;\n }\n if (index === 0) {\n const event = targetOpenState\n ? BeforetoggleOpenEvent\n : BeforetoggleClosedEvent;\n this.dispatchEvent(new event());\n }\n if (targetOpenState !== true) {\n return;\n }\n focusEl = focusEl || firstFocusableIn(el);\n if (focusEl) {\n return;\n }\n const childSlots = el.querySelectorAll('slot');\n childSlots.forEach((slot) => {\n if (!focusEl) {\n focusEl = firstFocusableSlottedIn(slot);\n }\n });\n };\n const finish = (el: OpenableElement, index: number) => (): void => {\n if (this.open !== targetOpenState) {\n return;\n }\n const eventName = targetOpenState ? 'sp-opened' : 'sp-closed';\n el.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: false,\n composed: false,\n detail: { interaction: this.type },\n })\n );\n if (index > 0) {\n return;\n }\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new Event(eventName, {\n bubbles: hasVirtualTrigger,\n composed: hasVirtualTrigger,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n })\n );\n }\n };\n this.elements.forEach((el, index) => {\n guaranteedTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n\n private async applyFocus(\n targetOpenState: boolean,\n focusEl: HTMLElement | null\n ): Promise<void> {\n // Do not move focus when explicitly told not to\n // and when the Overlay is a \"hint\"\n if (this.receivesFocus === 'false' || this.type === 'hint') {\n return;\n }\n\n await nextFrame();\n await nextFrame();\n if (targetOpenState === this.open && !this.open) {\n if (\n // Only return focus when the trigger is not \"virtual\"\n this.triggerElement &&\n !(this.triggerElement instanceof VirtualTrigger)\n ) {\n if (\n this.contains(\n (this.getRootNode() as Document).activeElement\n )\n ) {\n this.triggerElement.focus();\n }\n }\n return;\n }\n\n focusEl?.focus();\n }\n }\n return OverlayWithNoPopover;\n}\n"],
|
|
5
|
+
"mappings": "aAWA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DAEP,OACI,2BAAAC,EACA,yBAAAC,EACA,2BAAAC,EAGA,gBAAAC,MACG,mBACP,OAAS,kBAAAC,MAAsB,sBAS/B,SAASC,GAA2B,CAChC,OAAO,IAAI,QAASC,GAAQ,sBAAsB,IAAMA,EAAI,CAAC,CAAC,CAClE,CAEO,gBAAS,iBACZC,EACgC,CAChC,MAAMC,UAA6BD,CAAY,CAC3C,MAAyB,mBAAmC,CACxD,MAAME,EAAkB,KAAK,KAU7B,GATA,MAAM,KAAK,eAAe,EACtB,KAAK,OAASA,IAGlB,MAAM,KAAK,YAAYA,CAAe,EAClC,KAAK,OAASA,KAGlB,MAAM,KAAK,YAAY,EACnB,KAAK,OAASA,GACd,OAEJ,MAAMC,EAAU,MAAM,KAAK,eAAeD,CAAe,EACrD,KAAK,OAASA,GAGlB,MAAM,KAAK,WAAWA,EAAiBC,CAAO,CAClD,CAEA,MAAc,YAAYD,EAAyC,CAC/D,GAAIA,IAAoB,IAASA,IAAoB,KAAK,KAAM,CAC5DN,EAAa,MAAM,IAAI,EACvB,OAEA,KAAK,SACa,MAAMA,EAAa,UAAU,IAAI,IAE/C,KAAK,KAAO,CAACM,EAGzB,CAEA,MAAc,aAA6B,CACvC,MAAMJ,EAAU,EAChB,MAAMA,EAAU,CACpB,CAEA,MAAc,eACVI,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oB,KAAK,MAAQ,CAAC,KAAK,KAAM,CAGzC,KAAK,gBACL,EAAE,KAAK,0BAA0BL,IAG7B,KAAK,SACA,KAAK,YAAY,EAAe,aACrC,GAEA,KAAK,eAAe,MAAM,EAGlC,OAGJM,GAAA,MAAAA,EAAS,QACb,CACJ,CACA,OAAOF,CACX",
|
|
6
|
+
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedTransitionend", "overlayTimer", "VirtualTrigger", "nextFrame", "res", "constructor", "OverlayWithNoPopover", "targetOpenState", "focusEl", "start", "el", "index", "event", "slot", "finish", "eventName", "hasVirtualTrigger"]
|
|
7
7
|
}
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
BeforetoggleClosedEvent,
|
|
8
8
|
BeforetoggleOpenEvent,
|
|
9
|
-
guaranteedTransitionend
|
|
9
|
+
guaranteedTransitionend,
|
|
10
|
+
overlayTimer
|
|
10
11
|
} from "./OverlayBase.dev.js";
|
|
11
12
|
import { VirtualTrigger } from "./VirtualTrigger.dev.js";
|
|
12
13
|
function nextFrame() {
|
|
@@ -17,10 +18,35 @@ export function OverlayPopover(constructor) {
|
|
|
17
18
|
async managePopoverOpen() {
|
|
18
19
|
const targetOpenState = this.open;
|
|
19
20
|
await this.managePosition();
|
|
21
|
+
if (this.open !== targetOpenState) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
await this.manageDelay(targetOpenState);
|
|
25
|
+
if (this.open !== targetOpenState) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
20
28
|
await this.ensureOnDOM(targetOpenState);
|
|
29
|
+
if (this.open !== targetOpenState) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
21
32
|
const focusEl = await this.makeTransition(targetOpenState);
|
|
33
|
+
if (this.open !== targetOpenState) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
22
36
|
await this.applyFocus(targetOpenState, focusEl);
|
|
23
37
|
}
|
|
38
|
+
async manageDelay(targetOpenState) {
|
|
39
|
+
if (targetOpenState === false || targetOpenState !== this.open) {
|
|
40
|
+
overlayTimer.close(this);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (this.delayed) {
|
|
44
|
+
const cancelled = await overlayTimer.openTimer(this);
|
|
45
|
+
if (cancelled) {
|
|
46
|
+
this.open = !targetOpenState;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
24
50
|
async ensureOnDOM(targetOpenState) {
|
|
25
51
|
await nextFrame();
|
|
26
52
|
let popoverOpen = false;
|
|
@@ -39,6 +65,9 @@ export function OverlayPopover(constructor) {
|
|
|
39
65
|
await nextFrame();
|
|
40
66
|
}
|
|
41
67
|
async makeTransition(targetOpenState) {
|
|
68
|
+
if (this.open !== targetOpenState) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
42
71
|
let focusEl = null;
|
|
43
72
|
const start = (el, index) => () => {
|
|
44
73
|
if (typeof el.open !== "undefined") {
|
|
@@ -144,15 +173,14 @@ export function OverlayPopover(constructor) {
|
|
|
144
173
|
return focusEl;
|
|
145
174
|
}
|
|
146
175
|
async applyFocus(targetOpenState, focusEl) {
|
|
147
|
-
if (this.receivesFocus === "false") {
|
|
176
|
+
if (this.receivesFocus === "false" || this.type === "hint") {
|
|
148
177
|
return;
|
|
149
178
|
}
|
|
150
179
|
await nextFrame();
|
|
151
180
|
await nextFrame();
|
|
152
181
|
if (targetOpenState === this.open && !this.open) {
|
|
153
182
|
if (
|
|
154
|
-
//
|
|
155
|
-
this.type !== "hint" && // Only return focus when the trigger is not "virtual"
|
|
183
|
+
// Only return focus when the trigger is not "virtual"
|
|
156
184
|
this.triggerElement && !(this.triggerElement instanceof VirtualTrigger)
|
|
157
185
|
) {
|
|
158
186
|
if (this.contains(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["OverlayPopover.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport { ReactiveElement } from 'lit';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedTransitionend,\n OpenableElement,\n OverlayBase,\n} from './OverlayBase.dev.js'\nimport { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport { OverlayOpenCloseDetail } from './overlay-types.dev.js'\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\nexport function OverlayPopover<T extends Constructor<OverlayBase>>(\n constructor: T\n): T & Constructor<ReactiveElement> {\n class OverlayWithPopover extends constructor {\n protected override async managePopoverOpen(): Promise<void> {\n const targetOpenState = this.open;\n await this.managePosition();\n await this.ensureOnDOM(targetOpenState);\n const focusEl = await this.makeTransition(targetOpenState);\n await this.applyFocus(targetOpenState, focusEl);\n }\n\n private async ensureOnDOM(targetOpenState: boolean): Promise<void> {\n await nextFrame();\n let popoverOpen = false;\n try {\n popoverOpen = this.dialogEl.matches(':popover-open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n let open = false;\n try {\n open = this.dialogEl.matches(':open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n if (\n targetOpenState &&\n this.open === targetOpenState &&\n !popoverOpen &&\n !open &&\n this.isConnected\n ) {\n this.dialogEl.showPopover();\n }\n await nextFrame();\n }\n\n private async makeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n let focusEl = null as HTMLElement | null;\n const start = (el: OpenableElement, index: number) => (): void => {\n if (typeof el.open !== 'undefined') {\n el.open = targetOpenState;\n }\n if (index === 0) {\n const event = targetOpenState\n ? BeforetoggleOpenEvent\n : BeforetoggleClosedEvent;\n this.dispatchEvent(new event());\n }\n if (!targetOpenState) {\n return;\n }\n focusEl = focusEl || firstFocusableIn(el);\n if (focusEl) {\n return;\n }\n const childSlots = el.querySelectorAll('slot');\n childSlots.forEach((slot) => {\n if (!focusEl) {\n focusEl = firstFocusableSlottedIn(slot);\n }\n });\n };\n const finish =\n (el: OpenableElement, index: number) =>\n async (): Promise<void> => {\n if (this.open !== targetOpenState) {\n return;\n }\n const eventName = targetOpenState\n ? 'sp-opened'\n : 'sp-closed';\n if (index > 0) {\n el.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: false,\n composed: false,\n detail: { interaction: this.type },\n })\n );\n return;\n }\n const reportChange = async (): Promise<void> => {\n if (this.open !== targetOpenState) {\n return;\n }\n await nextFrame();\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new Event(eventName, {\n bubbles: hasVirtualTrigger,\n composed: hasVirtualTrigger,\n })\n );\n el.dispatchEvent(\n new Event(eventName, {\n bubbles: false,\n composed: false,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(\n eventName,\n {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n }\n )\n );\n }\n };\n if (this.open !== targetOpenState) {\n return;\n }\n let popoverOpen = false;\n try {\n popoverOpen = this.dialogEl.matches(':popover-open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n let open = false;\n try {\n open = this.dialogEl.matches(':open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n if (\n targetOpenState !== true &&\n (popoverOpen || open) &&\n this.isConnected\n ) {\n this.dialogEl.addEventListener(\n 'beforetoggle',\n () => {\n reportChange();\n },\n { once: true }\n );\n this.dialogEl.hidePopover();\n } else {\n reportChange();\n }\n };\n this.elements.forEach((el, index) => {\n guaranteedTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n\n private async applyFocus(\n targetOpenState: boolean,\n focusEl: HTMLElement | null\n ): Promise<void> {\n if (this.receivesFocus === 'false') {\n return;\n }\n\n await nextFrame();\n await nextFrame();\n if (targetOpenState === this.open && !this.open) {\n if (\n //
|
|
5
|
-
"mappings": ";AAWA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport { ReactiveElement } from 'lit';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedTransitionend,\n OpenableElement,\n OverlayBase,\n overlayTimer,\n} from './OverlayBase.dev.js'\nimport { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport { OverlayOpenCloseDetail } from './overlay-types.dev.js'\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\nexport function OverlayPopover<T extends Constructor<OverlayBase>>(\n constructor: T\n): T & Constructor<ReactiveElement> {\n class OverlayWithPopover extends constructor {\n protected override async managePopoverOpen(): Promise<void> {\n const targetOpenState = this.open;\n await this.managePosition();\n if (this.open !== targetOpenState) {\n return;\n }\n await this.manageDelay(targetOpenState);\n if (this.open !== targetOpenState) {\n return;\n }\n await this.ensureOnDOM(targetOpenState);\n if (this.open !== targetOpenState) {\n return;\n }\n const focusEl = await this.makeTransition(targetOpenState);\n if (this.open !== targetOpenState) {\n return;\n }\n await this.applyFocus(targetOpenState, focusEl);\n }\n\n private async manageDelay(targetOpenState: boolean): Promise<void> {\n if (targetOpenState === false || targetOpenState !== this.open) {\n overlayTimer.close(this);\n return;\n }\n if (this.delayed) {\n const cancelled = await overlayTimer.openTimer(this);\n if (cancelled) {\n this.open = !targetOpenState;\n }\n }\n }\n\n private async ensureOnDOM(targetOpenState: boolean): Promise<void> {\n await nextFrame();\n let popoverOpen = false;\n try {\n popoverOpen = this.dialogEl.matches(':popover-open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n let open = false;\n try {\n open = this.dialogEl.matches(':open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n if (\n targetOpenState &&\n this.open === targetOpenState &&\n !popoverOpen &&\n !open &&\n this.isConnected\n ) {\n this.dialogEl.showPopover();\n }\n await nextFrame();\n }\n\n private async makeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n if (this.open !== targetOpenState) {\n return null;\n }\n let focusEl = null as HTMLElement | null;\n const start = (el: OpenableElement, index: number) => (): void => {\n if (typeof el.open !== 'undefined') {\n el.open = targetOpenState;\n }\n if (index === 0) {\n const event = targetOpenState\n ? BeforetoggleOpenEvent\n : BeforetoggleClosedEvent;\n this.dispatchEvent(new event());\n }\n if (!targetOpenState) {\n return;\n }\n focusEl = focusEl || firstFocusableIn(el);\n if (focusEl) {\n return;\n }\n const childSlots = el.querySelectorAll('slot');\n childSlots.forEach((slot) => {\n if (!focusEl) {\n focusEl = firstFocusableSlottedIn(slot);\n }\n });\n };\n const finish =\n (el: OpenableElement, index: number) =>\n async (): Promise<void> => {\n if (this.open !== targetOpenState) {\n return;\n }\n const eventName = targetOpenState\n ? 'sp-opened'\n : 'sp-closed';\n if (index > 0) {\n el.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: false,\n composed: false,\n detail: { interaction: this.type },\n })\n );\n return;\n }\n const reportChange = async (): Promise<void> => {\n if (this.open !== targetOpenState) {\n return;\n }\n await nextFrame();\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new Event(eventName, {\n bubbles: hasVirtualTrigger,\n composed: hasVirtualTrigger,\n })\n );\n el.dispatchEvent(\n new Event(eventName, {\n bubbles: false,\n composed: false,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(\n eventName,\n {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n }\n )\n );\n }\n };\n if (this.open !== targetOpenState) {\n return;\n }\n let popoverOpen = false;\n try {\n popoverOpen = this.dialogEl.matches(':popover-open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n let open = false;\n try {\n open = this.dialogEl.matches(':open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n if (\n targetOpenState !== true &&\n (popoverOpen || open) &&\n this.isConnected\n ) {\n this.dialogEl.addEventListener(\n 'beforetoggle',\n () => {\n reportChange();\n },\n { once: true }\n );\n this.dialogEl.hidePopover();\n } else {\n reportChange();\n }\n };\n this.elements.forEach((el, index) => {\n guaranteedTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n\n private async applyFocus(\n targetOpenState: boolean,\n focusEl: HTMLElement | null\n ): Promise<void> {\n // Do not move focus when explicitly told not to\n // and when the Overlay is a \"hint\"\n if (this.receivesFocus === 'false' || this.type === 'hint') {\n return;\n }\n\n await nextFrame();\n await nextFrame();\n if (targetOpenState === this.open && !this.open) {\n if (\n // Only return focus when the trigger is not \"virtual\"\n this.triggerElement &&\n !(this.triggerElement instanceof VirtualTrigger)\n ) {\n if (\n this.contains(\n (this.getRootNode() as Document).activeElement\n )\n ) {\n this.triggerElement.focus();\n }\n }\n return;\n }\n\n focusEl?.focus();\n }\n }\n return OverlayWithPopover;\n}\n"],
|
|
5
|
+
"mappings": ";AAWA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,OACG;AACP,SAAS,sBAAsB;AAS/B,SAAS,YAA2B;AAChC,SAAO,IAAI,QAAQ,CAAC,QAAQ,sBAAsB,MAAM,IAAI,CAAC,CAAC;AAClE;AAEO,gBAAS,eACZ,aACgC;AAChC,QAAM,2BAA2B,YAAY;AAAA,IACzC,MAAyB,oBAAmC;AACxD,YAAM,kBAAkB,KAAK;AAC7B,YAAM,KAAK,eAAe;AAC1B,UAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,MACJ;AACA,YAAM,KAAK,YAAY,eAAe;AACtC,UAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,MACJ;AACA,YAAM,KAAK,YAAY,eAAe;AACtC,UAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,MACJ;AACA,YAAM,UAAU,MAAM,KAAK,eAAe,eAAe;AACzD,UAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,MACJ;AACA,YAAM,KAAK,WAAW,iBAAiB,OAAO;AAAA,IAClD;AAAA,IAEA,MAAc,YAAY,iBAAyC;AAC/D,UAAI,oBAAoB,SAAS,oBAAoB,KAAK,MAAM;AAC5D,qBAAa,MAAM,IAAI;AACvB;AAAA,MACJ;AACA,UAAI,KAAK,SAAS;AACd,cAAM,YAAY,MAAM,aAAa,UAAU,IAAI;AACnD,YAAI,WAAW;AACX,eAAK,OAAO,CAAC;AAAA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A,UACA,MAAM,IAAI,KAAK;AAAA,UACf,OAAO,IAAI,KAAK;AAAA,QACpB;AAAA,MACJ,CAAC;AACD,aAAO;AAAA,IACX;AAAA,IAEA,MAAc,WACV,iBACA,SACa;AAGb,UAAI,KAAK,kBAAkB,WAAW,KAAK,SAAS,QAAQ;AACxD;AAAA,MACJ;AAEA,YAAM,UAAU;AAChB,YAAM,UAAU;AAChB,UAAI,oBAAoB,KAAK,QAAQ,CAAC,KAAK,MAAM;AAC7C;AAAA;AAAA,UAEI,KAAK,kBACL,EAAE,KAAK,0BAA0B;AAAA,UACnC;AACE,cACI,KAAK;AAAA,YACA,KAAK,YAAY,EAAe;AAAA,UACrC,GACF;AACE,iBAAK,eAAe,MAAM;AAAA,UAC9B;AAAA,QACJ;AACA;AAAA,MACJ;AAEA,yCAAS;AAAA,IACb;AAAA,EACJ;AACA,SAAO;AACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/OverlayPopover.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";import{firstFocusableIn as v,firstFocusableSlottedIn as
|
|
1
|
+
"use strict";import{firstFocusableIn as v,firstFocusableSlottedIn as E}from"@spectrum-web-components/shared/src/first-focusable-in.js";import{BeforetoggleClosedEvent as y,BeforetoggleOpenEvent as g,guaranteedTransitionend as b,overlayTimer as u}from"./OverlayBase.js";import{VirtualTrigger as f}from"./VirtualTrigger.js";function a(){return new Promise(c=>requestAnimationFrame(()=>c()))}export function OverlayPopover(c){class d extends c{async managePopoverOpen(){const e=this.open;if(await this.managePosition(),this.open!==e||(await this.manageDelay(e),this.open!==e)||(await this.ensureOnDOM(e),this.open!==e))return;const t=await this.makeTransition(e);this.open===e&&await this.applyFocus(e,t)}async manageDelay(e){if(e===!1||e!==this.open){u.close(this);return}this.delayed&&await u.openTimer(this)&&(this.open=!e)}async ensureOnDOM(e){await a();let t=!1;try{t=this.dialogEl.matches(":popover-open")}catch(p){}let l=!1;try{l=this.dialogEl.matches(":open")}catch(p){}e&&this.open===e&&!t&&!l&&this.isConnected&&this.dialogEl.showPopover(),await a()}async makeTransition(e){if(this.open!==e)return null;let t=null;const l=(i,o)=>()=>{if(typeof i.open!="undefined"&&(i.open=e),o===0){const n=e?g:y;this.dispatchEvent(new n)}if(!e||(t=t||v(i),t))return;i.querySelectorAll("slot").forEach(n=>{t||(t=E(n))})},p=(i,o)=>async()=>{if(this.open!==e)return;const s=e?"sp-opened":"sp-closed";if(o>0){i.dispatchEvent(new CustomEvent(s,{bubbles:!1,composed:!1,detail:{interaction:this.type}}));return}const n=async()=>{if(this.open!==e)return;await a();const r=this.triggerElement instanceof f;this.dispatchEvent(new Event(s,{bubbles:r,composed:r})),i.dispatchEvent(new Event(s,{bubbles:!1,composed:!1})),this.triggerElement&&!r&&this.triggerElement.dispatchEvent(new CustomEvent(s,{bubbles:!0,composed:!0,detail:{interaction:this.type}}))};if(this.open!==e)return;let h=!1;try{h=this.dialogEl.matches(":popover-open")}catch(r){}let m=!1;try{m=this.dialogEl.matches(":open")}catch(r){}e!==!0&&(h||m)&&this.isConnected?(this.dialogEl.addEventListener("beforetoggle",()=>{n()},{once:!0}),this.dialogEl.hidePopover()):n()};return this.elements.forEach((i,o)=>{b(i,l(i,o),p(i,o))}),t}async applyFocus(e,t){if(!(this.receivesFocus==="false"||this.type==="hint")){if(await a(),await a(),e===this.open&&!this.open){this.triggerElement&&!(this.triggerElement instanceof f)&&this.contains(this.getRootNode().activeElement)&&this.triggerElement.focus();return}t==null||t.focus()}}}return d}
|
|
2
2
|
//# sourceMappingURL=OverlayPopover.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["OverlayPopover.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport { ReactiveElement } from 'lit';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedTransitionend,\n OpenableElement,\n OverlayBase,\n} from './OverlayBase.js';\nimport { VirtualTrigger } from './VirtualTrigger.js';\nimport { OverlayOpenCloseDetail } from './overlay-types.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\nexport function OverlayPopover<T extends Constructor<OverlayBase>>(\n constructor: T\n): T & Constructor<ReactiveElement> {\n class OverlayWithPopover extends constructor {\n protected override async managePopoverOpen(): Promise<void> {\n const targetOpenState = this.open;\n await this.managePosition();\n await this.ensureOnDOM(targetOpenState);\n const focusEl = await this.makeTransition(targetOpenState);\n await this.applyFocus(targetOpenState, focusEl);\n }\n\n private async ensureOnDOM(targetOpenState: boolean): Promise<void> {\n await nextFrame();\n let popoverOpen = false;\n try {\n popoverOpen = this.dialogEl.matches(':popover-open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n let open = false;\n try {\n open = this.dialogEl.matches(':open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n if (\n targetOpenState &&\n this.open === targetOpenState &&\n !popoverOpen &&\n !open &&\n this.isConnected\n ) {\n this.dialogEl.showPopover();\n }\n await nextFrame();\n }\n\n private async makeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n let focusEl = null as HTMLElement | null;\n const start = (el: OpenableElement, index: number) => (): void => {\n if (typeof el.open !== 'undefined') {\n el.open = targetOpenState;\n }\n if (index === 0) {\n const event = targetOpenState\n ? BeforetoggleOpenEvent\n : BeforetoggleClosedEvent;\n this.dispatchEvent(new event());\n }\n if (!targetOpenState) {\n return;\n }\n focusEl = focusEl || firstFocusableIn(el);\n if (focusEl) {\n return;\n }\n const childSlots = el.querySelectorAll('slot');\n childSlots.forEach((slot) => {\n if (!focusEl) {\n focusEl = firstFocusableSlottedIn(slot);\n }\n });\n };\n const finish =\n (el: OpenableElement, index: number) =>\n async (): Promise<void> => {\n if (this.open !== targetOpenState) {\n return;\n }\n const eventName = targetOpenState\n ? 'sp-opened'\n : 'sp-closed';\n if (index > 0) {\n el.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: false,\n composed: false,\n detail: { interaction: this.type },\n })\n );\n return;\n }\n const reportChange = async (): Promise<void> => {\n if (this.open !== targetOpenState) {\n return;\n }\n await nextFrame();\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new Event(eventName, {\n bubbles: hasVirtualTrigger,\n composed: hasVirtualTrigger,\n })\n );\n el.dispatchEvent(\n new Event(eventName, {\n bubbles: false,\n composed: false,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(\n eventName,\n {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n }\n )\n );\n }\n };\n if (this.open !== targetOpenState) {\n return;\n }\n let popoverOpen = false;\n try {\n popoverOpen = this.dialogEl.matches(':popover-open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n let open = false;\n try {\n open = this.dialogEl.matches(':open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n if (\n targetOpenState !== true &&\n (popoverOpen || open) &&\n this.isConnected\n ) {\n this.dialogEl.addEventListener(\n 'beforetoggle',\n () => {\n reportChange();\n },\n { once: true }\n );\n this.dialogEl.hidePopover();\n } else {\n reportChange();\n }\n };\n this.elements.forEach((el, index) => {\n guaranteedTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n\n private async applyFocus(\n targetOpenState: boolean,\n focusEl: HTMLElement | null\n ): Promise<void> {\n if (this.receivesFocus === 'false') {\n return;\n }\n\n await nextFrame();\n await nextFrame();\n if (targetOpenState === this.open && !this.open) {\n if (\n //
|
|
5
|
-
"mappings": "aAWA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DAEP,OACI,2BAAAC,EACA,yBAAAC,EACA,2BAAAC,
|
|
6
|
-
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedTransitionend", "VirtualTrigger", "nextFrame", "res", "constructor", "OverlayWithPopover", "targetOpenState", "focusEl", "popoverOpen", "error", "open", "start", "el", "index", "event", "slot", "finish", "eventName", "reportChange", "hasVirtualTrigger"]
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport { ReactiveElement } from 'lit';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedTransitionend,\n OpenableElement,\n OverlayBase,\n overlayTimer,\n} from './OverlayBase.js';\nimport { VirtualTrigger } from './VirtualTrigger.js';\nimport { OverlayOpenCloseDetail } from './overlay-types.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\nexport function OverlayPopover<T extends Constructor<OverlayBase>>(\n constructor: T\n): T & Constructor<ReactiveElement> {\n class OverlayWithPopover extends constructor {\n protected override async managePopoverOpen(): Promise<void> {\n const targetOpenState = this.open;\n await this.managePosition();\n if (this.open !== targetOpenState) {\n return;\n }\n await this.manageDelay(targetOpenState);\n if (this.open !== targetOpenState) {\n return;\n }\n await this.ensureOnDOM(targetOpenState);\n if (this.open !== targetOpenState) {\n return;\n }\n const focusEl = await this.makeTransition(targetOpenState);\n if (this.open !== targetOpenState) {\n return;\n }\n await this.applyFocus(targetOpenState, focusEl);\n }\n\n private async manageDelay(targetOpenState: boolean): Promise<void> {\n if (targetOpenState === false || targetOpenState !== this.open) {\n overlayTimer.close(this);\n return;\n }\n if (this.delayed) {\n const cancelled = await overlayTimer.openTimer(this);\n if (cancelled) {\n this.open = !targetOpenState;\n }\n }\n }\n\n private async ensureOnDOM(targetOpenState: boolean): Promise<void> {\n await nextFrame();\n let popoverOpen = false;\n try {\n popoverOpen = this.dialogEl.matches(':popover-open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n let open = false;\n try {\n open = this.dialogEl.matches(':open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n if (\n targetOpenState &&\n this.open === targetOpenState &&\n !popoverOpen &&\n !open &&\n this.isConnected\n ) {\n this.dialogEl.showPopover();\n }\n await nextFrame();\n }\n\n private async makeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n if (this.open !== targetOpenState) {\n return null;\n }\n let focusEl = null as HTMLElement | null;\n const start = (el: OpenableElement, index: number) => (): void => {\n if (typeof el.open !== 'undefined') {\n el.open = targetOpenState;\n }\n if (index === 0) {\n const event = targetOpenState\n ? BeforetoggleOpenEvent\n : BeforetoggleClosedEvent;\n this.dispatchEvent(new event());\n }\n if (!targetOpenState) {\n return;\n }\n focusEl = focusEl || firstFocusableIn(el);\n if (focusEl) {\n return;\n }\n const childSlots = el.querySelectorAll('slot');\n childSlots.forEach((slot) => {\n if (!focusEl) {\n focusEl = firstFocusableSlottedIn(slot);\n }\n });\n };\n const finish =\n (el: OpenableElement, index: number) =>\n async (): Promise<void> => {\n if (this.open !== targetOpenState) {\n return;\n }\n const eventName = targetOpenState\n ? 'sp-opened'\n : 'sp-closed';\n if (index > 0) {\n el.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(eventName, {\n bubbles: false,\n composed: false,\n detail: { interaction: this.type },\n })\n );\n return;\n }\n const reportChange = async (): Promise<void> => {\n if (this.open !== targetOpenState) {\n return;\n }\n await nextFrame();\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new Event(eventName, {\n bubbles: hasVirtualTrigger,\n composed: hasVirtualTrigger,\n })\n );\n el.dispatchEvent(\n new Event(eventName, {\n bubbles: false,\n composed: false,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>(\n eventName,\n {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n }\n )\n );\n }\n };\n if (this.open !== targetOpenState) {\n return;\n }\n let popoverOpen = false;\n try {\n popoverOpen = this.dialogEl.matches(':popover-open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n let open = false;\n try {\n open = this.dialogEl.matches(':open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n if (\n targetOpenState !== true &&\n (popoverOpen || open) &&\n this.isConnected\n ) {\n this.dialogEl.addEventListener(\n 'beforetoggle',\n () => {\n reportChange();\n },\n { once: true }\n );\n this.dialogEl.hidePopover();\n } else {\n reportChange();\n }\n };\n this.elements.forEach((el, index) => {\n guaranteedTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n\n private async applyFocus(\n targetOpenState: boolean,\n focusEl: HTMLElement | null\n ): Promise<void> {\n // Do not move focus when explicitly told not to\n // and when the Overlay is a \"hint\"\n if (this.receivesFocus === 'false' || this.type === 'hint') {\n return;\n }\n\n await nextFrame();\n await nextFrame();\n if (targetOpenState === this.open && !this.open) {\n if (\n // Only return focus when the trigger is not \"virtual\"\n this.triggerElement &&\n !(this.triggerElement instanceof VirtualTrigger)\n ) {\n if (\n this.contains(\n (this.getRootNode() as Document).activeElement\n )\n ) {\n this.triggerElement.focus();\n }\n }\n return;\n }\n\n focusEl?.focus();\n }\n }\n return OverlayWithPopover;\n}\n"],
|
|
5
|
+
"mappings": "aAWA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DAEP,OACI,2BAAAC,EACA,yBAAAC,EACA,2BAAAC,EAGA,gBAAAC,MACG,mBACP,OAAS,kBAAAC,MAAsB,sBAS/B,SAASC,GAA2B,CAChC,OAAO,IAAI,QAASC,GAAQ,sBAAsB,IAAMA,EAAI,CAAC,CAAC,CAClE,CAEO,gBAAS,eACZC,EACgC,CAChC,MAAMC,UAA2BD,CAAY,CACzC,MAAyB,mBAAmC,CACxD,MAAME,EAAkB,KAAK,KAU7B,GATA,MAAM,KAAK,eAAe,EACtB,KAAK,OAASA,IAGlB,MAAM,KAAK,YAAYA,CAAe,EAClC,KAAK,OAASA,KAGlB,MAAM,KAAK,YAAYA,CAAe,EAClC,KAAK,OAASA,GACd,OAEJ,MAAMC,EAAU,MAAM,KAAK,eAAeD,CAAe,EACrD,KAAK,OAASA,GAGlB,MAAM,KAAK,WAAWA,EAAiBC,CAAO,CAClD,CAEA,MAAc,YAAYD,EAAyC,CAC/D,GAAIA,IAAoB,IAASA,IAAoB,KAAK,KAAM,CAC5DN,EAAa,MAAM,IAAI,EACvB,OAEA,KAAK,SACa,MAAMA,EAAa,UAAU,IAAI,IAE/C,KAAK,KAAO,CAACM,EAGzB,CAEA,MAAc,YAAYA,EAAyC,CAC/D,MAAMJ,EAAU,EAChB,IAAIM,EAAc,GAClB,GAAI,CACAA,EAAc,KAAK,SAAS,QAAQ,eAAe,C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A,CACI,QAAS,GACT,SAAU,GACV,OAAQ,CAAE,YAAa,KAAK,IAAK,CACrC,CACJ,CACJ,CAER,EACA,GAAI,KAAK,OAASX,EACd,OAEJ,IAAIE,EAAc,GAClB,GAAI,CACAA,EAAc,KAAK,SAAS,QAAQ,eAAe,CAEvD,OAASC,EAAP,CAAe,CACjB,IAAIC,EAAO,GACX,GAAI,CACAA,EAAO,KAAK,SAAS,QAAQ,OAAO,CAExC,OAASD,EAAP,CAAe,CAEbH,IAAoB,KACnBE,GAAeE,IAChB,KAAK,aAEL,KAAK,SAAS,iBACV,eACA,IAAM,CACFQ,EAAa,CACjB,EACA,CAAE,KAAM,EAAK,CACjB,EACA,KAAK,SAAS,YAAY,GAE1BA,EAAa,CAErB,EACJ,YAAK,SAAS,QAAQ,CAACN,EAAIC,IAAU,CACjCd,EACIa,EACAD,EAAMC,EAAIC,CAAK,EACfG,EAAOJ,EAAIC,CAAK,CACpB,CACJ,CAAC,EACMN,CACX,CAEA,MAAc,WACVD,EACAC,EACa,CAGb,GAAI,OAAK,gBAAkB,SAAW,KAAK,OAAS,QAMpD,IAFA,MAAML,EAAU,EAChB,MAAMA,EAAU,EACZI,IAAoB,KAAK,MAAQ,CAAC,KAAK,KAAM,CAGzC,KAAK,gBACL,EAAE,KAAK,0BAA0BL,IAG7B,KAAK,SACA,KAAK,YAAY,EAAe,aACrC,GAEA,KAAK,eAAe,MAAM,EAGlC,OAGJM,GAAA,MAAAA,EAAS,QACb,CACJ,CACA,OAAOF,CACX",
|
|
6
|
+
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedTransitionend", "overlayTimer", "VirtualTrigger", "nextFrame", "res", "constructor", "OverlayWithPopover", "targetOpenState", "focusEl", "popoverOpen", "error", "open", "start", "el", "index", "event", "slot", "finish", "eventName", "reportChange", "hasVirtualTrigger"]
|
|
7
7
|
}
|