@spectrum-web-components/overlay 0.19.6-overlay.14 → 0.19.6-overlay.17
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/Overlay.d.ts +3 -0
- package/src/Overlay.dev.js.map +2 -2
- package/src/Overlay.js.map +2 -2
- package/src/OverlayBase.d.ts +1 -4
- package/src/OverlayBase.dev.js.map +2 -2
- package/src/OverlayBase.js.map +2 -2
- package/src/OverlayDialog.dev.js +5 -13
- package/src/OverlayDialog.dev.js.map +2 -2
- package/src/OverlayDialog.js +1 -1
- package/src/OverlayDialog.js.map +3 -3
- package/src/OverlayNoPopover.dev.js +5 -13
- 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 +5 -13
- package/src/OverlayPopover.dev.js.map +2 -2
- package/src/OverlayPopover.js +1 -1
- package/src/OverlayPopover.js.map +3 -3
- package/stories/overlay.stories.js.map +2 -2
- package/test/overlay.test.js +3 -1
- package/test/overlay.test.js.map +2 -2
|
@@ -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'\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 Event(eventName, {\n bubbles: false,\n composed: false,\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(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
|
|
5
|
-
"mappings": ";AAYA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OAGG;AACP,SAAS,sBAAsB;AAQ/B,SAAS,YAA2B;AAChC,SAAO,IAAI,QAAQ,CA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a;AAMb,UAAI,KAAK,kBAAkB,SAAS;AAChC;AAAA,MACJ;AAEA,YAAM,UAAU;AAChB,YAAM,UAAU;AAChB,UAAI,oBAAoB,KAAK,QAAQ,CAAC,KAAK,MAAM;AAC7C;AAAA;AAAA,UAEI,KAAK,SAAS;AAAA,UAEd,KAAK,kBACL,EAAE,KAAK,0BAA0B;AAAA,UACnC;
|
|
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'\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 Event(eventName, {\n bubbles: false,\n composed: false,\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(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;AAQ/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,qB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
|
}
|
package/src/OverlayDialog.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";import{firstFocusableIn as
|
|
1
|
+
"use strict";import{firstFocusableIn as u,firstFocusableSlottedIn as p}from"@spectrum-web-components/shared/src/first-focusable-in.js";import{BeforetoggleClosedEvent as f,BeforetoggleOpenEvent as E,guaranteedTransitionend as g}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 t=this.open;await this.managePosition(),await this.dialogEnsureOnDOM();const i=await this.dialogMakeTransition(t);await this.dialogApplyFocus(t,i)}async dialogEnsureOnDOM(){await r(),await r(),await r(),await r()}async dialogMakeTransition(t){let i=null;const h=(e,n)=>async()=>{if(typeof e.open!="undefined"&&(e.open=t),!t){const s=()=>{e.removeEventListener("close",s),c(e,n)};e.addEventListener("close",s)}if(n>0||!t)return;const o=t?E:f;this.dispatchEvent(new o),i=i||u(e),i||e.querySelectorAll("slot").forEach(a=>{i||(i=p(a))}),!(!this.isConnected||this.dialogEl.open)&&this.dialogEl.showModal()},c=(e,n)=>()=>{if(this.open!==t)return;const o=t?"sp-opened":"sp-closed";if(n>0){e.dispatchEvent(new Event(o,{bubbles:!1,composed:!1}));return}if(!this.isConnected||t!==this.open)return;const s=()=>{const a=this.triggerElement instanceof d;this.dispatchEvent(new Event(o,{bubbles:a,composed:a})),e.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}}))};!t&&this.dialogEl.open?(this.dialogEl.addEventListener("close",()=>{s()},{once:!0}),this.dialogEl.close()):s()};return this.elements.forEach((e,n)=>{g(e,h(e,n),c(e,n))}),i}async dialogApplyFocus(t,i){if(this.receivesFocus!=="false"){if(await r(),await r(),t===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';\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 Event(eventName, {\n bubbles: false,\n composed: false,\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(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
|
|
5
|
-
"mappings": "aAYA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DACP,OACI,2BAAAC,EACA,yBAAAC,EACA,2BAAAC,MAGG,mBACP,OAAS,kBAAAC,MAAsB,sBAQ/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,KAC7B,MAAM,KAAK,eAAe,EAC1B,MAAM,KAAK,kBAAkB,EAC7B,MAAMC,EAAU,MAAM,KAAK,qBAAqBD,CAAe,EAC/D,MAAM,KAAK,iBAAiBA,EAAiBC,CAAO,CACxD,CAEA,MAAgB,mBAAmC,CAC/C,MAAML,EAAU,EAChB,MAAMA,EAAU,EAChB,MAAMA,EAAU,EAChB,MAAMA,EAAU,CACpB,CAEA,MAAgB,qBACZI,EAC2B,CAC3B,IAAIC,EAAU,KACd,MAAMC,EACF,CAACC,EAAqBC,IACtB,SAA2B,CAIvB,GAHI,OAAOD,EAAG,MAAS,cACnBA,EAAG,KAAOH,GAEV,CAACA,EA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A,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,
|
|
6
|
-
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedTransitionend", "VirtualTrigger", "nextFrame", "res", "constructor", "OverlayWithDialog", "targetOpenState", "focusEl", "start", "el", "index", "close", "finish", "event", "slot", "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 { 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';\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 Event(eventName, {\n bubbles: false,\n composed: false,\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(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,sBAQ/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,KAC7B,MAAM,KAAK,eAAe,EAC1B,MAA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R,EAAG,cACC,IAAI,MAAMM,EAAW,CACjB,QAAS,GACT,SAAU,EACd,CAAC,CACL,EACI,KAAK,gBAAkB,CAACE,GACvB,KAAK,eAA+B,cACjC,IAAI,YAAYF,EAAW,CACvB,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,MACJ,CAEAM,GAAA,MAAAA,EAAS,QACb,CACJ,CACA,OAAOF,CACX",
|
|
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
|
}
|
|
@@ -104,19 +104,11 @@ export function OverlayNoPopover(constructor) {
|
|
|
104
104
|
this.type !== "hint" && // Only return focus when the trigger is not "virtual"
|
|
105
105
|
this.triggerElement && !(this.triggerElement instanceof VirtualTrigger)
|
|
106
106
|
) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
relationEvent.type,
|
|
113
|
-
(event) => {
|
|
114
|
-
if (document.activeElement && event.composedPath().includes(document.activeElement)) {
|
|
115
|
-
this.triggerElement.focus();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
);
|
|
119
|
-
this.dispatchEvent(relationEvent);
|
|
107
|
+
if (this.contains(
|
|
108
|
+
this.getRootNode().activeElement
|
|
109
|
+
)) {
|
|
110
|
+
this.triggerElement.focus();
|
|
111
|
+
}
|
|
120
112
|
}
|
|
121
113
|
return;
|
|
122
114
|
}
|
|
@@ -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'\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 Event(eventName, {\n bubbles: false,\n composed: false,\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(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(targetOpenState: boolean
|
|
5
|
-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AAM,YAAY,kBAAkB,cAAc;AAClD,WAAG;AAAA,UACC,IAAI,MAAM,WAAW;AAAA,YACjB,SAAS;AAAA,YACT,UAAU;AAAA,UACd,CAAC;AAAA,QACL;AACA,YAAI,QAAQ,GAAG;AACX;AAAA,QACJ;AACA,cAAM,oBACF,KAAK,0BAA0B;AACnC,aAAK;AAAA,UACD,IAAI,MAAM,WAAW;AAAA,YACjB,SAAS;AAAA,YACT,UAAU;AAAA,UACd,CAAC;AAAA,QACL;AACA,YAAI,KAAK,kBAAkB,CAAC,mBAAmB;AAC3C,UAAC,KAAK,eAA+B;AAAA,YACjC,IAAI,YAAY,WAAW;AAAA,cACvB,SAAS;AAAA,cACT,UAAU;AAAA,cACV,QAAQ,EAAE,aAAa,KAAK,KAAK;AAAA,YACrC,CAAC;AAAA,UACL;AAAA,QACJ;AAAA,MACJ;AACA,WAAK,SAAS,QAAQ,CAAC,IAAI,UAAU;AACjC;AAAA,UACI;AAAA,UACA,MAAM,IAAI,KAAK;AAAA,UACf,OAAO,IAAI,KAAK;AAAA,QACpB;AAAA,MACJ,CAAC;AACD,aAAO;AAAA,IACX;AAAA,IAEA,MAAc,
|
|
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'\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 Event(eventName, {\n bubbles: false,\n composed: false,\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(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 // 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 OverlayWithNoPopover;\n}\n"],
|
|
5
|
+
"mappings": ";AAWA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OAGG;AACP,SAAS,sBAAsB;AAQ/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,YAAM,KAAK,YAAY;AACvB,YAAM,UAAU,MAAM,KAAK,eAAe,eAAe;AACzD,YAAM,KAAK,WAAW,iBAAiB,OAAO;AAAA,IAClD;AAAA,IAEA,MAAc,cAA6B;AACvC,YAAM,UAAU;AAChB,YAAM,UAAU;AAAA,IACpB;AAAA,IAEA,MAAc,eACV,iBAC2B;AAC3B,UAAI,UAAU;AACd,YAAM,QAAQ,CAAC,IAAqB,UAAkB,MAAY;AAC9D,YAAI,oBA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QACpB;AAAA,MACJ,CAAC;AACD,aAAO;AAAA,IACX;AAAA,IAEA,MAAc,WACV,iBACA,SACa;AACb,UAAI,KAAK,kBAAkB,SAAS;AAChC;AAAA,MACJ;AAEA,YAAM,UAAU;AAChB,YAAM,UAAU;AAChB,UAAI,oBAAoB,KAAK,QAAQ,CAAC,KAAK,MAAM;AAC7C;AAAA;AAAA,UAEI,KAAK,SAAS;AAAA,UAEd,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/OverlayNoPopover.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";import{firstFocusableIn as p,firstFocusableSlottedIn as
|
|
1
|
+
"use strict";import{firstFocusableIn as p,firstFocusableSlottedIn as h}from"@spectrum-web-components/shared/src/first-focusable-in.js";import{BeforetoggleClosedEvent as f,BeforetoggleOpenEvent as v,guaranteedTransitionend as d}from"./OverlayBase.js";import{VirtualTrigger as l}from"./VirtualTrigger.js";function r(){return new Promise(a=>requestAnimationFrame(()=>a()))}export function OverlayNoPopover(a){class c extends a{async managePopoverOpen(){const t=this.open;await this.managePosition(),await this.ensureOnDOM();const e=await this.makeTransition(t);await this.applyFocus(t,e)}async ensureOnDOM(){await r(),await r()}async makeTransition(t){let e=null;const m=(n,o)=>()=>{if(t!==this.open)return;if(typeof n.open!="undefined"&&(n.open=t),o===0){const i=t?v:f;this.dispatchEvent(new i)}if(t!==!0||(e=e||p(n),e))return;n.querySelectorAll("slot").forEach(i=>{e||(e=h(i))})},u=(n,o)=>()=>{if(this.open!==t)return;const s=t?"sp-opened":"sp-closed";if(n.dispatchEvent(new Event(s,{bubbles:!1,composed:!1})),o>0)return;const i=this.triggerElement instanceof l;this.dispatchEvent(new Event(s,{bubbles:i,composed:i})),this.triggerElement&&!i&&this.triggerElement.dispatchEvent(new CustomEvent(s,{bubbles:!0,composed:!0,detail:{interaction:this.type}}))};return this.elements.forEach((n,o)=>{d(n,m(n,o),u(n,o))}),e}async applyFocus(t,e){if(this.receivesFocus!=="false"){if(await r(),await r(),t===this.open&&!this.open){this.type!=="hint"&&this.triggerElement&&!(this.triggerElement instanceof l)&&this.contains(this.getRootNode().activeElement)&&this.triggerElement.focus();return}e==null||e.focus()}}}return c}
|
|
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';\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 Event(eventName, {\n bubbles: false,\n composed: false,\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(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(targetOpenState: boolean
|
|
5
|
-
"mappings": "aAWA,OAC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QAASC,EACT,SAAUA,CACd,CAAC,CACL,EACI,KAAK,gBAAkB,CAACA,GACvB,KAAK,eAA+B,cACjC,IAAI,YAAYD,EAAW,CACvB,QAAS,GACT,SAAU,GACV,OAAQ,CAAE,YAAa,KAAK,IAAK,CACrC,CAAC,CACL,CAER,EACA,YAAK,SAAS,QAAQ,CAACL,EAAIC,IAAU,CACjCV,EACIS,EACAD,EAAMC,EAAIC,CAAK,EACfG,EAAOJ,EAAIC,CAAK,CACpB,CACJ,CAAC,EACMH,CACX,CAEA,MAAc,
|
|
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} from './OverlayBase.js';\nimport { VirtualTrigger } from './VirtualTrigger.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 Event(eventName, {\n bubbles: false,\n composed: false,\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(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 // 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 OverlayWithNoPopover;\n}\n"],
|
|
5
|
+
"mappings": "aAWA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DAEP,OACI,2BAAAC,EACA,yBAAAC,EACA,2BAAAC,MAGG,mBACP,OAAS,kBAAAC,MAAsB,sBAQ/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,KAC7B,MAAM,KAAK,eAAe,EAC1B,MAAM,KAAK,YAAY,EACvB,MAAMC,EAAU,MAAM,KAAK,eAAeD,CAAe,EACzD,MAAM,KAAK,WAAWA,EAAiBC,CAAO,CAClD,CAEA,MAAc,aAA6B,CACvC,MAAML,EAAU,EAChB,MAAMA,EAAU,CACpB,CAEA,MAAc,eACVI,EAC2B,CAC3B,IAAIC,EAAU,KACd,MAAMC,EAAQ,CAACC,EAAqBC,IAAkB,IAAY,CAC9D,GAAIJ,IAAoB,KAAK,KACzB,OAKJ,GAHI,OAAOG,EAAG,MAAS,cACnBA,EAAG,KAAOH,GAEVI,IAAU,EAAG,CACb,MAAMC,EAAQL,EACRP,EACAD,EACN,KAAK,cAAc,IAAIa,CAAO,CAClC,CAKA,GAJIL,IAAoB,KAGxBC,EAAUA,GAAWX,EAAiBa,CAAE,EACpCF,GACA,OAEeE,EAAG,iBAAiB,MAAM,EAClC,QAASG,GAAS,CACpBL,IACDA,EAAUV,EAAwBe,CAAI,EAE9C,CAAC,CACL,EACMC,EAAS,CAACJ,EAAqBC,IAAkB,IAAY,CAC/D,GAAI,KAAK,OAASJ,EACd,OAEJ,MAAMQ,EAAYR,EAAkB,YAAc,YAOlD,GANAG,EAAG,cACC,IAAI,MAAMK,EAAW,CACjB,QAAS,GACT,SAAU,EACd,CAAC,CACL,EACIJ,EAAQ,EACR,OAEJ,MAAMK,EACF,KAAK,0BAA0Bd,EACnC,KAAK,cACD,IAAI,MAAMa,EAAW,CACjB,QAASC,EACT,SAAUA,CACd,CAAC,CACL,EACI,KAAK,gBAAkB,CAACA,GACvB,KAAK,eAA+B,cACjC,IAAI,YAAYD,EAAW,CACvB,QAAS,GACT,SAAU,GACV,OAAQ,CAAE,YAAa,KAAK,IAAK,CACrC,CAAC,CACL,CAER,EACA,YAAK,SAAS,QAAQ,CAACL,EAAIC,IAAU,CACjCV,EACIS,EACAD,EAAMC,EAAIC,CAAK,EACfG,EAAOJ,EAAIC,CAAK,CACpB,CACJ,CAAC,EACMH,CACX,CAEA,MAAc,WACVD,EACAC,EACa,CACb,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,MACJ,CAEAM,GAAA,MAAAA,EAAS,QACb,CACJ,CACA,OAAOF,CACX",
|
|
6
|
+
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedTransitionend", "VirtualTrigger", "nextFrame", "res", "constructor", "OverlayWithNoPopover", "targetOpenState", "focusEl", "start", "el", "index", "event", "slot", "finish", "eventName", "hasVirtualTrigger"]
|
|
7
7
|
}
|
|
@@ -131,19 +131,11 @@ export function OverlayPopover(constructor) {
|
|
|
131
131
|
this.type !== "hint" && // Only return focus when the trigger is not "virtual"
|
|
132
132
|
this.triggerElement && !(this.triggerElement instanceof VirtualTrigger)
|
|
133
133
|
) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
relationEvent.type,
|
|
140
|
-
(event) => {
|
|
141
|
-
if (document.activeElement && event.composedPath().includes(document.activeElement)) {
|
|
142
|
-
this.triggerElement.focus();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
);
|
|
146
|
-
this.dispatchEvent(relationEvent);
|
|
134
|
+
if (this.contains(
|
|
135
|
+
this.getRootNode().activeElement
|
|
136
|
+
)) {
|
|
137
|
+
this.triggerElement.focus();
|
|
138
|
+
}
|
|
147
139
|
}
|
|
148
140
|
return;
|
|
149
141
|
}
|
|
@@ -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'\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 if (\n targetOpenState &&\n this.open === targetOpenState &&\n !this.dialogEl.matches(':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 Event(eventName, {\n bubbles: false,\n composed: false,\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(eventName, {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n })\n );\n }\n };\n if (this.open !== targetOpenState) {\n return;\n }\n if (\n targetOpenState !== true &&\n this.dialogEl.matches(':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(targetOpenState: boolean
|
|
5
|
-
"mappings": ";AAWA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OAGG;AACP,SAAS,sBAAsB;AAQ/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,YAAM,KAAK,YAAY,eAAe;AACtC,YAAM,UAAU,MAAM,KAAK,eAAe,eAAe;AACzD,YAAM,KAAK,WAAW,iBAAiB,OAAO;AAAA,IAClD;AAAA,IAEA,MAAc,YAAY,iBAAyC;AAC/D,YAAM,UAAU;AAChB,UACI,mBACA,KAAK,SAAS,mBACd,CAAC,KAAK,SAAS,QAAQ,OAAO,KAC9B,KAAK,aACP;AACE,aAAK,SAAS,Y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AAC,KAAK,eAA+B;AAAA,cACjC,IAAI,YAAY,WAAW;AAAA,gBACvB,SAAS;AAAA,gBACT,UAAU;AAAA,gBACV,QAAQ,EAAE,aAAa,KAAK,KAAK;AAAA,cACrC,CAAC;AAAA,YACL;AAAA,UACJ;AAAA,QACJ;AACA,YAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,QACJ;AACA,YACI,oBAAoB,QACpB,KAAK,SAAS,QAAQ,OAAO,KAC7B,KAAK,aACP;AACE,eAAK,SAAS;AAAA,YACV;AAAA,YACA,MAAM;AACF,2BAAa;AAAA,YACjB;AAAA,YACA,EAAE,MAAM,KAAK;AAAA,UACjB;AACA,eAAK,SAAS,YAAY;AAAA,QAC9B,OAAO;AACH,uBAAa;AAAA,QACjB;AAAA,MACJ;AACJ,WAAK,SAAS,QAAQ,CAAC,IAAI,UAAU;AACjC;AAAA,UACI;AAAA,UACA,MAAM,IAAI,KAAK;AAAA,UACf,OAAO,IAAI,KAAK;AAAA,QACpB;AAAA,MACJ,CAAC;AACD,aAAO;AAAA,IACX;AAAA,IAEA,MAAc,
|
|
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'\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 if (\n targetOpenState &&\n this.open === targetOpenState &&\n !this.dialogEl.matches(':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 Event(eventName, {\n bubbles: false,\n composed: false,\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(eventName, {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n })\n );\n }\n };\n if (this.open !== targetOpenState) {\n return;\n }\n if (\n targetOpenState !== true &&\n this.dialogEl.matches(':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 // 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 OverlayWithPopover;\n}\n"],
|
|
5
|
+
"mappings": ";AAWA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OAGG;AACP,SAAS,sBAAsB;AAQ/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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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
|
|
1
|
+
"use strict";import{firstFocusableIn as u,firstFocusableSlottedIn as d}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 c}from"./VirtualTrigger.js";function r(){return new Promise(a=>requestAnimationFrame(()=>a()))}export function OverlayPopover(a){class m extends a{async managePopoverOpen(){const e=this.open;await this.managePosition(),await this.ensureOnDOM(e);const t=await this.makeTransition(e);await this.applyFocus(e,t)}async ensureOnDOM(e){await r(),e&&this.open===e&&!this.dialogEl.matches(":open")&&this.isConnected&&this.dialogEl.showPopover(),await r()}async makeTransition(e){let t=null;const h=(n,i)=>()=>{if(typeof n.open!="undefined"&&(n.open=e),i===0){const o=e?v:f;this.dispatchEvent(new o)}if(!e||(t=t||u(n),t))return;n.querySelectorAll("slot").forEach(o=>{t||(t=d(o))})},p=(n,i)=>async()=>{if(this.open!==e)return;const s=e?"sp-opened":"sp-closed";if(i>0){n.dispatchEvent(new Event(s,{bubbles:!1,composed:!1}));return}const o=async()=>{if(this.open!==e)return;await r();const l=this.triggerElement instanceof c;this.dispatchEvent(new Event(s,{bubbles:l,composed:l})),n.dispatchEvent(new Event(s,{bubbles:!1,composed:!1})),this.triggerElement&&!l&&this.triggerElement.dispatchEvent(new CustomEvent(s,{bubbles:!0,composed:!0,detail:{interaction:this.type}}))};this.open===e&&(e!==!0&&this.dialogEl.matches(":open")&&this.isConnected?(this.dialogEl.addEventListener("beforetoggle",()=>{o()},{once:!0}),this.dialogEl.hidePopover()):o())};return this.elements.forEach((n,i)=>{E(n,h(n,i),p(n,i))}),t}async applyFocus(e,t){if(this.receivesFocus!=="false"){if(await r(),await r(),e===this.open&&!this.open){this.type!=="hint"&&this.triggerElement&&!(this.triggerElement instanceof c)&&this.contains(this.getRootNode().activeElement)&&this.triggerElement.focus();return}t==null||t.focus()}}}return m}
|
|
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';\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 if (\n targetOpenState &&\n this.open === targetOpenState &&\n !this.dialogEl.matches(':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 Event(eventName, {\n bubbles: false,\n composed: false,\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(eventName, {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n })\n );\n }\n };\n if (this.open !== targetOpenState) {\n return;\n }\n if (\n targetOpenState !== true &&\n this.dialogEl.matches(':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(targetOpenState: boolean
|
|
5
|
-
"mappings": "aAWA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DAEP,OACI,2BAAAC,EACA,yBAAAC,EACA,2BAAAC,MAGG,mBACP,OAAS,kBAAAC,MAAsB,sBAQ/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,KAC7B,MAAM,KAAK,eAAe,EAC1B,MAAM,KAAK,YAAYA,CAAe,EACtC,MAAMC,EAAU,MAAM,KAAK,eAAeD,CAAe,EACzD,MAAM,KAAK,WAAWA,EAAiBC,CAAO,CAClD,CAEA,MAAc,YAAYD,EAAyC,CAC/D,MAAMJ,EAAU,EAEZI,GACA,KAAK,OAASA,GACd,CAAC,KAAK,SAAS,QAAQ,OAAO,GAC9B,KAAK,aAEL,KAAK,SAAS,YAAY,EAE9B,MAAMJ,EAAU,CACpB,CAEA,MAAc,eACVI,EAC2B,CAC3B,IAAIC,EAAU,KACd,MAAMC,EAAQ,CAACC,EAAqBC,IAAkB,IAAY,CAI9D,GAHI,OAAOD,EAAG,MAAS,cACnBA,EAAG,KAAOH,GAEVI,IAAU,EAAG,CACb,MAAMC,EAAQL,EACRP,EACAD,EACN,KAAK,cAAc,IAAIa,CAAO,CAClC,CAKA,GAJI,CAACL,IAGLC,EAAUA,GAAWX,EAAiBa,CAAE,EACpCF,GACA,OAEeE,EAAG,iBAAiB,MAAM,EAClC,QAASG,GAAS,CACpBL,IACDA,EAAUV,EAAwBe,CAAI,EAE9C,CAAC,CACL,EACMC,EACF,CAACJ,EAAqBC,IACtB,SAA2B,CACvB,GAAI,KAAK,OAASJ,EACd,OAEJ,MAAMQ,EAAYR,EACZ,YACA,YACN,GAAII,EAAQ,EAAG,CACXD,EAAG,cACC,IAAI,MAAMK,EAAW,CACjB,QAAS,GACT,SAAU,EACd,CAAC,CACL,EACA,MACJ,CACA,MAAMC,EAAe,SAA2B,CAC5C,GAAI,KAAK,OAAST,EACd,OAEJ,MAAMJ,EAAU,EAChB,MAAMc,EACF,KAAK,0BAA0Bf,EACnC,KAAK,cACD,IAAI,MAAMa,EAAW,CACjB,QAASE,EACT,SAAUA,CACd,CAAC,CACL,EACAP,EAAG,cACC,IAAI,MAAMK,EAAW,CACjB,QAAS,GACT,SAAU,EACd,CAAC,CACL,EACI,KAAK,gBAAkB,CAACE,GACvB,KAAK,eAA+B,cACjC,IAAI,YAAYF,EAAW,CACvB,QAAS,GACT,SAAU,GACV,OAAQ,CAAE,YAAa,KAAK,IAAK,CACrC,CAAC,CACL,CAER,EACI,KAAK,OAASR,IAIdA,IAAoB,IACpB,KAAK,SAAS,QAAQ,OAAO,GAC7B,KAAK,aAEL,KAAK,SAAS,iBACV,eACA,IAAM,CACFS,EAAa,CACjB,EACA,CAAE,KAAM,EAAK,CACjB,EACA,KAAK,SAAS,YAAY,GAE1BA,EAAa,EAErB,EACJ,YAAK,SAAS,QAAQ,CAACN,EAAIC,IAAU,CACjCV,EACIS,EACAD,EAAMC,EAAIC,CAAK,EACfG,EAAOJ,EAAIC,CAAK,CACpB,CACJ,CAAC,EACMH,CACX,CAEA,MAAc,
|
|
6
|
-
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedTransitionend", "VirtualTrigger", "nextFrame", "res", "constructor", "OverlayWithPopover", "targetOpenState", "focusEl", "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} from './OverlayBase.js';\nimport { VirtualTrigger } from './VirtualTrigger.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 if (\n targetOpenState &&\n this.open === targetOpenState &&\n !this.dialogEl.matches(':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 Event(eventName, {\n bubbles: false,\n composed: false,\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(eventName, {\n bubbles: true,\n composed: true,\n detail: { interaction: this.type },\n })\n );\n }\n };\n if (this.open !== targetOpenState) {\n return;\n }\n if (\n targetOpenState !== true &&\n this.dialogEl.matches(':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 // 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 OverlayWithPopover;\n}\n"],
|
|
5
|
+
"mappings": "aAWA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DAEP,OACI,2BAAAC,EACA,yBAAAC,EACA,2BAAAC,MAGG,mBACP,OAAS,kBAAAC,MAAsB,sBAQ/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,KAC7B,MAAM,KAAK,eAAe,EAC1B,MAAM,KAAK,YAAYA,CAAe,EACtC,MAAMC,EAAU,MAAM,KAAK,eAAeD,CAAe,EACzD,MAAM,KAAK,WAAWA,EAAiBC,CAAO,CAClD,CAEA,MAAc,YAAYD,EAAyC,CAC/D,MAAMJ,EAAU,EAEZI,GACA,KAAK,OAASA,GACd,CAAC,KAAK,SAAS,QAAQ,OAAO,GAC9B,KAAK,aAEL,KAAK,SAAS,YAAY,EAE9B,MAAMJ,EAAU,CACpB,CAEA,MAAc,eACVI,EAC2B,CAC3B,IAAIC,EAAU,KACd,MAAMC,EAAQ,CAACC,EAAqBC,IAAkB,IAAY,CAI9D,GAHI,OAAOD,EAAG,MAAS,cACnBA,EAAG,KAAOH,GAEVI,IAAU,EAAG,CACb,MAAMC,EAAQL,EACRP,EACAD,EACN,KAAK,cAAc,IAAIa,CAAO,CAClC,CAKA,GAJI,CAACL,IAGLC,EAAUA,GAAWX,EAAiBa,C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,KAAK,OAAS,QAEd,KAAK,gBACL,EAAE,KAAK,0BAA0BL,IAG7B,KAAK,SACA,KAAK,YAAY,EAAe,aACrC,GAEA,KAAK,eAAe,MAAM,EAGlC,MACJ,CAEAM,GAAA,MAAAA,EAAS,QACb,CACJ,CACA,OAAOF,CACX",
|
|
6
|
+
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedTransitionend", "VirtualTrigger", "nextFrame", "res", "constructor", "OverlayWithPopover", "targetOpenState", "focusEl", "start", "el", "index", "event", "slot", "finish", "eventName", "reportChange", "hasVirtualTrigger"]
|
|
7
7
|
}
|