@spectrum-web-components/overlay 0.19.6-overlay.12 → 0.19.6-overlay.13
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.dev.js.map +1 -1
- package/src/Overlay.js.map +1 -1
- package/src/OverlayBase.d.ts +1 -1
- package/src/OverlayBase.dev.js +5 -5
- package/src/OverlayBase.dev.js.map +2 -2
- package/src/OverlayBase.js +1 -1
- package/src/OverlayBase.js.map +2 -2
- package/src/OverlayDialog.dev.js +3 -3
- 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 +3 -3
- package/src/OverlayNoPopover.dev.js.map +2 -2
- package/src/OverlayNoPopover.js +1 -1
- package/src/OverlayNoPopover.js.map +2 -2
- package/src/OverlayPopover.dev.js +7 -4
- package/src/OverlayPopover.dev.js.map +2 -2
- package/src/OverlayPopover.js +1 -1
- package/src/OverlayPopover.js.map +2 -2
- package/src/overlay-base.css.dev.js +1 -1
- package/src/overlay-base.css.dev.js.map +1 -1
- package/src/overlay-base.css.js +1 -1
- package/src/overlay-base.css.js.map +1 -1
- package/test/overlay.test.js +4 -21
- 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(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 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 (!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 // This has a bug where the current overlay and the focused content could share the same `activeElement` shadow root...\n const relationEvent = new Event('overlay-relation-query', {\n bubbles: true,\n composed: true,\n });\n this.addEventListener(\n relationEvent.type,\n (event: Event) => {\n /* eslint-disable @spectrum-web-components/document-active-element */\n if (\n document.activeElement &&\n event\n .composedPath()\n .includes(document.activeElement)\n ) {\n (this.triggerElement as HTMLElement).focus();\n }\n /* eslint-enable @spectrum-web-components/document-active-element */\n }\n );\n this.dispatchEvent(relationEvent);\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,OAAO;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 { 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 // This has a bug where the current overlay and the focused content could share the same `activeElement` shadow root...\n const relationEvent = new Event('overlay-relation-query', {\n bubbles: true,\n composed: true,\n });\n this.addEventListener(\n relationEvent.type,\n (event: Event) => {\n /* eslint-disable @spectrum-web-components/document-active-element */\n if (\n document.activeElement &&\n event\n .composedPath()\n .includes(document.activeElement)\n ) {\n (this.triggerElement as HTMLElement).focus();\n }\n /* eslint-enable @spectrum-web-components/document-active-element */\n }\n );\n this.dispatchEvent(relationEvent);\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,qBACZ,iBAC2B;AAC3B,UAAI,UAAU;AACd,YAAM,QACF,CAAC,IAAqB,UACtB,YAA2B;AACvB,YAAI,OAAO,GAAG,SAAS,aAAa;AAChC,aAAG,OAAO;AAAA,QACd;AACA,YAAI,CAAC,iBAAiB;AAClB,gBAAM,QAAQ,MAAY;AACtB,eAAG,oBAAoB,SAAS,KAAK;AACrC,mBAAO,IAAI,KAAK;AAAA,UACpB;AACA,aAAG,iBAAiB,SAAS,KAAK;AAAA,QACtC;AACA,YAAI,QAAQ,KAAK,CAAC,iBAAiB;AAC/B;AAAA,QACJ;AACA,cAAM,QAAQ,kBACR,wBACA;AACN,aAAK,cAAc,IAAI,MAAM,CAAC;AAC9B,kBAAU,WAAW,iBAAiB,EAAE;AACxC,YAAI,CAAC,SAAS;AACV,gBAAM,aAAa,GAAG,iB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,eAAK,SAAS,MAAM;AAAA,QACxB,OAAO;AACH,uBAAa;AAAA,QACjB;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,MAAgB,iBACZ,iBACA,SACa;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;AAEE,gBAAM,gBAAgB,IAAI,MAAM,0BAA0B;AAAA,YACtD,SAAS;AAAA,YACT,UAAU;AAAA,UACd,CAAC;AACD,eAAK;AAAA,YACD,cAAc;AAAA,YACd,CAAC,UAAiB;AAEd,kBACI,SAAS,iBACT,MACK,aAAa,EACb,SAAS,SAAS,aAAa,GACtC;AACE,gBAAC,KAAK,eAA+B,MAAM;AAAA,cAC/C;AAAA,YAEJ;AAAA,UACJ;AACA,eAAK,cAAc,aAAa;AAAA,QACpC;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 h,firstFocusableSlottedIn as
|
|
1
|
+
"use strict";import{firstFocusableIn as h,firstFocusableSlottedIn as p}from"@spectrum-web-components/shared/src/first-focusable-in.js";import{BeforetoggleClosedEvent as E,BeforetoggleOpenEvent as v,guaranteedTransitionend as f}from"./OverlayBase.js";import{VirtualTrigger as m}from"./VirtualTrigger.js";function r(){return new Promise(d=>requestAnimationFrame(()=>d()))}export function OverlayDialog(d){class u extends d{async manageDialogOpen(){const t=this.open;await this.managePosition(),await this.dialogEnsureOnDOM();const n=await this.dialogMakeTransition(t);await this.dialogApplyFocus(t,n)}async dialogEnsureOnDOM(){await r(),await r(),await r(),await r()}async dialogMakeTransition(t){let n=null;const l=(e,i)=>async()=>{if(typeof e.open!="undefined"&&(e.open=t),!t){const s=()=>{e.removeEventListener("close",s),c(e,i)};e.addEventListener("close",s)}if(i>0||!t)return;const o=t?v:E;this.dispatchEvent(new o),n=n||h(e),n||e.querySelectorAll("slot").forEach(a=>{n||(n=p(a))}),!(!this.isConnected||this.dialogEl.open)&&this.dialogEl.showModal()},c=(e,i)=>()=>{if(this.open!==t)return;const o=t?"sp-opened":"sp-closed";if(i>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 m;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,i)=>{f(e,l(e,i),c(e,i))}),n}async dialogApplyFocus(t,n){if(this.receivesFocus!=="false"){if(await r(),await r(),t===this.open&&!this.open){if(this.type!=="hint"&&this.triggerElement&&!(this.triggerElement instanceof m)){const l=new Event("overlay-relation-query",{bubbles:!0,composed:!0});this.addEventListener(l.type,c=>{document.activeElement&&c.composedPath().includes(document.activeElement)&&this.triggerElement.focus()}),this.dispatchEvent(l)}return}n==null||n.focus()}}}return u}
|
|
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(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 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 (!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 // This has a bug where the current overlay and the focused content could share the same `activeElement` shadow root...\n const relationEvent = new Event('overlay-relation-query', {\n bubbles: true,\n composed: true,\n });\n this.addEventListener(\n relationEvent.type,\n (event: Event) => {\n /* eslint-disable @spectrum-web-components/document-active-element */\n if (\n document.activeElement &&\n event\n .composedPath()\n .includes(document.activeElement)\n ) {\n (this.triggerElement as HTMLElement).focus();\n }\n /* eslint-enable @spectrum-web-components/document-active-element */\n }\n );\n this.dispatchEvent(relationEvent);\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,MAAM,KAAK,kBAAkB,EAC7B,MAAMC,EAAU,MAAM,KAAK,qBAAqBD,CAAe,EAC/D,MAAM,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';\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 // This has a bug where the current overlay and the focused content could share the same `activeElement` shadow root...\n const relationEvent = new Event('overlay-relation-query', {\n bubbles: true,\n composed: true,\n });\n this.addEventListener(\n relationEvent.type,\n (event: Event) => {\n /* eslint-disable @spectrum-web-components/document-active-element */\n if (\n document.activeElement &&\n event\n .composedPath()\n .includes(document.activeElement)\n ) {\n (this.triggerElement as HTMLElement).focus();\n }\n /* eslint-enable @spectrum-web-components/document-active-element */\n }\n );\n this.dispatchEvent(relationEvent);\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,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,EAAiB,CAClB,MAAMK,EAAQ,IAAY,CACtBF,EAAG,oBAAoB,QAASE,CAAK,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C,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,CAC7C,GAEI,KAAK,OAAS,QAEd,KAAK,gBACL,EAAE,KAAK,0BAA0BL,GACnC,CAEE,MAAMiB,EAAgB,IAAI,MAAM,yBAA0B,CACtD,QAAS,GACT,SAAU,EACd,CAAC,EACD,KAAK,iBACDA,EAAc,KACbL,GAAiB,CAGV,SAAS,eACTA,EACK,aAAa,EACb,SAAS,SAAS,aAAa,GAEnC,KAAK,eAA+B,MAAM,CAGnD,CACJ,EACA,KAAK,cAAcK,CAAa,CACpC,CACA,MACJ,CAEAX,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", "relationEvent"]
|
|
7
7
|
}
|
|
@@ -19,7 +19,7 @@ export function OverlayNoPopover(constructor) {
|
|
|
19
19
|
await this.managePosition();
|
|
20
20
|
await this.ensureOnDOM();
|
|
21
21
|
const focusEl = await this.makeTransition(targetOpenState);
|
|
22
|
-
await this.applyFocus(focusEl);
|
|
22
|
+
await this.applyFocus(targetOpenState, focusEl);
|
|
23
23
|
}
|
|
24
24
|
async ensureOnDOM() {
|
|
25
25
|
await nextFrame();
|
|
@@ -92,13 +92,13 @@ export function OverlayNoPopover(constructor) {
|
|
|
92
92
|
});
|
|
93
93
|
return focusEl;
|
|
94
94
|
}
|
|
95
|
-
async applyFocus(focusEl) {
|
|
95
|
+
async applyFocus(targetOpenState, focusEl) {
|
|
96
96
|
if (this.receivesFocus === "false") {
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
99
|
await nextFrame();
|
|
100
100
|
await nextFrame();
|
|
101
|
-
if (!this.open) {
|
|
101
|
+
if (targetOpenState === this.open && !this.open) {
|
|
102
102
|
if (
|
|
103
103
|
// Do not return focus to trigger when overlay is a "hint" (tooltip)
|
|
104
104
|
this.type !== "hint" && // Only return focus when the trigger is not "virtual"
|
|
@@ -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(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(focusEl: HTMLElement | null): Promise<void> {\n if (this.receivesFocus === 'false') {\n return;\n }\n\n await nextFrame();\n await nextFrame();\n if (!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 // This has a bug where the current overlay and the focused content could share the same `activeElement` shadow root...\n const relationEvent = new Event('overlay-relation-query', {\n bubbles: true,\n composed: true,\n });\n this.addEventListener(\n relationEvent.type,\n (event: Event) => {\n /* eslint-disable @spectrum-web-components/document-active-element */\n if (\n document.activeElement &&\n event\n .composedPath()\n .includes(document.activeElement)\n ) {\n (this.triggerElement as HTMLElement).focus();\n }\n /* eslint-enable @spectrum-web-components/document-active-element */\n }\n );\n this.dispatchEvent(relationEvent);\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,OAAO;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} 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, focusEl: HTMLElement | null): 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 // This has a bug where the current overlay and the focused content could share the same `activeElement` shadow root...\n const relationEvent = new Event('overlay-relation-query', {\n bubbles: true,\n composed: true,\n });\n this.addEventListener(\n relationEvent.type,\n (event: Event) => {\n /* eslint-disable @spectrum-web-components/document-active-element */\n if (\n document.activeElement &&\n event\n .composedPath()\n .includes(document.activeElement)\n ) {\n (this.triggerElement as HTMLElement).focus();\n }\n /* eslint-enable @spectrum-web-components/document-active-element */\n }\n );\n this.dispatchEvent(relationEvent);\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,aACg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as p,firstFocusableSlottedIn as v}from"@spectrum-web-components/shared/src/first-focusable-in.js";import{BeforetoggleClosedEvent as
|
|
1
|
+
"use strict";import{firstFocusableIn as p,firstFocusableSlottedIn as v}from"@spectrum-web-components/shared/src/first-focusable-in.js";import{BeforetoggleClosedEvent as h,BeforetoggleOpenEvent as d,guaranteedTransitionend as f}from"./OverlayBase.js";import{VirtualTrigger as m}from"./VirtualTrigger.js";function a(){return new Promise(l=>requestAnimationFrame(()=>l()))}export function OverlayNoPopover(l){class u extends l{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 a(),await a()}async makeTransition(t){let e=null;const r=(n,o)=>()=>{if(t!==this.open)return;if(typeof n.open!="undefined"&&(n.open=t),o===0){const i=t?d:h;this.dispatchEvent(new i)}if(t!==!0||(e=e||p(n),e))return;n.querySelectorAll("slot").forEach(i=>{e||(e=v(i))})},c=(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 m;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)=>{f(n,r(n,o),c(n,o))}),e}async applyFocus(t,e){if(this.receivesFocus!=="false"){if(await a(),await a(),t===this.open&&!this.open){if(this.type!=="hint"&&this.triggerElement&&!(this.triggerElement instanceof m)){const r=new Event("overlay-relation-query",{bubbles:!0,composed:!0});this.addEventListener(r.type,c=>{document.activeElement&&c.composedPath().includes(document.activeElement)&&this.triggerElement.focus()}),this.dispatchEvent(r)}return}e==null||e.focus()}}}return u}
|
|
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(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(focusEl: HTMLElement | null): Promise<void> {\n if (this.receivesFocus === 'false') {\n return;\n }\n\n await nextFrame();\n await nextFrame();\n if (!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 // This has a bug where the current overlay and the focused content could share the same `activeElement` shadow root...\n const relationEvent = new Event('overlay-relation-query', {\n bubbles: true,\n composed: true,\n });\n this.addEventListener(\n relationEvent.type,\n (event: Event) => {\n /* eslint-disable @spectrum-web-components/document-active-element */\n if (\n document.activeElement &&\n event\n .composedPath()\n .includes(document.activeElement)\n ) {\n (this.triggerElement as HTMLElement).focus();\n }\n /* eslint-enable @spectrum-web-components/document-active-element */\n }\n );\n this.dispatchEvent(relationEvent);\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,
|
|
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, focusEl: HTMLElement | null): 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 // This has a bug where the current overlay and the focused content could share the same `activeElement` shadow root...\n const relationEvent = new Event('overlay-relation-query', {\n bubbles: true,\n composed: true,\n });\n this.addEventListener(\n relationEvent.type,\n (event: Event) => {\n /* eslint-disable @spectrum-web-components/document-active-element */\n if (\n document.activeElement &&\n event\n .composedPath()\n .includes(document.activeElement)\n ) {\n (this.triggerElement as HTMLElement).focus();\n }\n /* eslint-enable @spectrum-web-components/document-active-element */\n }\n );\n this.dispatchEvent(relationEvent);\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,IA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,EACD,KAAK,iBACDA,EAAc,KACbL,GAAiB,CAGV,SAAS,eACTA,EACK,aAAa,EACb,SAAS,SAAS,aAAa,GAEnC,KAAK,eAA+B,MAAM,CAGnD,CACJ,EACA,KAAK,cAAcK,CAAa,CACpC,CACA,MACJ,CAEAT,GAAA,MAAAA,EAAS,QACb,CACJ,CACA,OAAOF,CACX",
|
|
6
6
|
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedTransitionend", "VirtualTrigger", "nextFrame", "res", "constructor", "OverlayWithNoPopover", "targetOpenState", "focusEl", "start", "el", "index", "event", "slot", "finish", "eventName", "hasVirtualTrigger", "relationEvent"]
|
|
7
7
|
}
|
|
@@ -19,7 +19,7 @@ export function OverlayPopover(constructor) {
|
|
|
19
19
|
await this.managePosition();
|
|
20
20
|
await this.ensureOnDOM(targetOpenState);
|
|
21
21
|
const focusEl = await this.makeTransition(targetOpenState);
|
|
22
|
-
await this.applyFocus(focusEl);
|
|
22
|
+
await this.applyFocus(targetOpenState, focusEl);
|
|
23
23
|
}
|
|
24
24
|
async ensureOnDOM(targetOpenState) {
|
|
25
25
|
await nextFrame();
|
|
@@ -94,7 +94,10 @@ export function OverlayPopover(constructor) {
|
|
|
94
94
|
);
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
|
-
if (
|
|
97
|
+
if (this.open !== targetOpenState) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (targetOpenState !== true && this.dialogEl.matches(":open") && this.isConnected) {
|
|
98
101
|
this.dialogEl.addEventListener(
|
|
99
102
|
"beforetoggle",
|
|
100
103
|
() => {
|
|
@@ -116,13 +119,13 @@ export function OverlayPopover(constructor) {
|
|
|
116
119
|
});
|
|
117
120
|
return focusEl;
|
|
118
121
|
}
|
|
119
|
-
async applyFocus(focusEl) {
|
|
122
|
+
async applyFocus(targetOpenState, focusEl) {
|
|
120
123
|
if (this.receivesFocus === "false") {
|
|
121
124
|
return;
|
|
122
125
|
}
|
|
123
126
|
await nextFrame();
|
|
124
127
|
await nextFrame();
|
|
125
|
-
if (!this.open) {
|
|
128
|
+
if (targetOpenState === this.open && !this.open) {
|
|
126
129
|
if (
|
|
127
130
|
// Do not return focus to trigger when overlay is a "hint" (tooltip)
|
|
128
131
|
this.type !== "hint" && // Only return focus when the trigger is not "virtual"
|
|
@@ -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(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 (\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;AACxD,YAAM,kBAAkB,KAAK;AAC7B,YAAM,KAAK,eAAe;AAC1B,YAAM,KAAK,YAAY,eAAe;AACtC,YAAM,UAAU,MAAM,KAAK,eAAe,eAAe;AACzD,YAAM,KAAK,WAAW,OAAO;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} 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, focusEl: HTMLElement | null): 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 // This has a bug where the current overlay and the focused content could share the same `activeElement` shadow root...\n const relationEvent = new Event('overlay-relation-query', {\n bubbles: true,\n composed: true,\n });\n this.addEventListener(\n relationEvent.type,\n (event: Event) => {\n /* eslint-disable @spectrum-web-components/document-active-element */\n if (\n document.activeElement &&\n event\n .composedPath()\n .includes(document.activeElement)\n ) {\n (this.triggerElement as HTMLElement).focus();\n }\n /* eslint-enable @spectrum-web-components/document-active-element */\n }\n );\n this.dispatchEvent(relationEvent);\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;AACxD,YAAM,kBAAkB,KAAK;AAC7B,YAAM,KAAK,eAAe;AAC1B,YAAM,KAAK,YA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A,YACtD,SAAS;AAAA,YACT,UAAU;AAAA,UACd,CAAC;AACD,eAAK;AAAA,YACD,cAAc;AAAA,YACd,CAAC,UAAiB;AAEd,kBACI,SAAS,iBACT,MACK,aAAa,EACb,SAAS,SAAS,aAAa,GACtC;AACE,gBAAC,KAAK,eAA+B,MAAM;AAAA,cAC/C;AAAA,YAEJ;AAAA,UACJ;AACA,eAAK,cAAc,aAAa;AAAA,QACpC;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 p,firstFocusableSlottedIn as d}from"@spectrum-web-components/shared/src/first-focusable-in.js";import{BeforetoggleClosedEvent as v,BeforetoggleOpenEvent as E,guaranteedTransitionend as f}from"./OverlayBase.js";import{VirtualTrigger as h}from"./VirtualTrigger.js";function r(){return new Promise(l=>requestAnimationFrame(()=>l()))}export function OverlayPopover(l){class u extends l{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 a=(n,i)=>()=>{if(typeof n.open!="undefined"&&(n.open=e),i===0){const o=e?E:v;this.dispatchEvent(new o)}if(!e||(t=t||p(n),t))return;n.querySelectorAll("slot").forEach(o=>{t||(t=d(o))})},c=(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 m=this.triggerElement instanceof h;this.dispatchEvent(new Event(s,{bubbles:m,composed:m})),n.dispatchEvent(new Event(s,{bubbles:!1,composed:!1})),this.triggerElement&&!m&&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)=>{f(n,a(n,i),c(n,i))}),t}async applyFocus(e,t){if(this.receivesFocus!=="false"){if(await r(),await r(),e===this.open&&!this.open){if(this.type!=="hint"&&this.triggerElement&&!(this.triggerElement instanceof h)){const a=new Event("overlay-relation-query",{bubbles:!0,composed:!0});this.addEventListener(a.type,c=>{document.activeElement&&c.composedPath().includes(document.activeElement)&&this.triggerElement.focus()}),this.dispatchEvent(a)}return}t==null||t.focus()}}}return u}
|
|
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(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 (\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,
|
|
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, focusEl: HTMLElement | null): 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 // This has a bug where the current overlay and the focused content could share the same `activeElement` shadow root...\n const relationEvent = new Event('overlay-relation-query', {\n bubbles: true,\n composed: true,\n });\n this.addEventListener(\n relationEvent.type,\n (event: Event) => {\n /* eslint-disable @spectrum-web-components/document-active-element */\n if (\n document.activeElement &&\n event\n .composedPath()\n .includes(document.activeElement)\n ) {\n (this.triggerElement as HTMLElement).focus();\n }\n /* eslint-enable @spectrum-web-components/document-active-element */\n }\n );\n this.dispatchEvent(relationEvent);\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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FocusableSlottedIn", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedTransitionend", "VirtualTrigger", "nextFrame", "res", "constructor", "OverlayWithPopover", "targetOpenState", "focusEl", "start", "el", "index", "event", "slot", "finish", "eventName", "reportChange", "hasVirtualTrigger", "relationEvent"]
|
|
7
7
|
}
|
|
@@ -3,7 +3,7 @@ import { css } from "@spectrum-web-components/base";
|
|
|
3
3
|
const styles = css`
|
|
4
4
|
:host{--swc-overlay-animation-distance:var(
|
|
5
5
|
--spectrum-picker-m-texticon-popover-offset-y,var(--spectrum-global-dimension-size-75)
|
|
6
|
-
)}dialog{background:none;border:0;box-sizing:border-box;display:flex;margin:0;max-height:calc(100vh - 16px);max-height:calc(100dvh - 16px);max-width:calc(100vw - 16px);opacity:1!important;overflow:visible;padding:0;position:fixed}:host(:not([open])) dialog{left:0;pointer-events:none;top:0;transform:translate(-999em,-999em)}dialog::backdrop{display:none}dialog>div{width:100%}::slotted(sp-popover){position:static}dialog[actual-placement*=top]{margin-top:var(--swc-overlay-animation-distance);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=right]{margin-left:calc(var(--swc-overlay-animation-distance)*-1);padding-inline:var(--swc-overlay-animation-distance)}dialog[actual-placement*=bottom]{margin-top:calc(var(--swc-overlay-animation-distance)*-1);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=left]{margin-left:var(--swc-overlay-animation-distance);padding-inline:var(--swc-overlay-animation-distance)}@supports selector(:open){dialog{opacity:0}dialog:open{opacity:1}}@supports not selector(:open){:host:not([open]) dialog{pointer-events:none}dialog[actual-placement]{z-index:var(--swc-overlay-z-index)}}
|
|
6
|
+
);position:fixed}dialog{background:none;border:0;box-sizing:border-box;display:flex;margin:0;max-height:calc(100vh - 16px);max-height:calc(100dvh - 16px);max-width:calc(100vw - 16px);opacity:1!important;overflow:visible;padding:0;position:fixed}:host(:not([open])) dialog{left:0;pointer-events:none;top:0;transform:translate(-999em,-999em)}dialog::backdrop{display:none}dialog>div{width:100%}::slotted(sp-popover){position:static}dialog[actual-placement*=top]{margin-top:var(--swc-overlay-animation-distance);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=right]{margin-left:calc(var(--swc-overlay-animation-distance)*-1);padding-inline:var(--swc-overlay-animation-distance)}dialog[actual-placement*=bottom]{margin-top:calc(var(--swc-overlay-animation-distance)*-1);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=left]{margin-left:var(--swc-overlay-animation-distance);padding-inline:var(--swc-overlay-animation-distance)}@supports selector(:open){dialog{opacity:0}dialog:open{opacity:1}}@supports not selector(:open){:host:not([open]) dialog{pointer-events:none}dialog[actual-placement]{z-index:var(--swc-overlay-z-index)}}
|
|
7
7
|
`;
|
|
8
8
|
export default styles;
|
|
9
9
|
//# sourceMappingURL=overlay-base.css.dev.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["overlay-base.css.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2023 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 { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host{--swc-overlay-animation-distance:var(\n--spectrum-picker-m-texticon-popover-offset-y,var(--spectrum-global-dimension-size-75)\n)}dialog{background:none;border:0;box-sizing:border-box;display:flex;margin:0;max-height:calc(100vh - 16px);max-height:calc(100dvh - 16px);max-width:calc(100vw - 16px);opacity:1!important;overflow:visible;padding:0;position:fixed}:host(:not([open])) dialog{left:0;pointer-events:none;top:0;transform:translate(-999em,-999em)}dialog::backdrop{display:none}dialog>div{width:100%}::slotted(sp-popover){position:static}dialog[actual-placement*=top]{margin-top:var(--swc-overlay-animation-distance);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=right]{margin-left:calc(var(--swc-overlay-animation-distance)*-1);padding-inline:var(--swc-overlay-animation-distance)}dialog[actual-placement*=bottom]{margin-top:calc(var(--swc-overlay-animation-distance)*-1);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=left]{margin-left:var(--swc-overlay-animation-distance);padding-inline:var(--swc-overlay-animation-distance)}@supports selector(:open){dialog{opacity:0}dialog:open{opacity:1}}@supports not selector(:open){:host:not([open]) dialog{pointer-events:none}dialog[actual-placement]{z-index:var(--swc-overlay-z-index)}}\n`;\nexport default styles;"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2023 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 { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host{--swc-overlay-animation-distance:var(\n--spectrum-picker-m-texticon-popover-offset-y,var(--spectrum-global-dimension-size-75)\n);position:fixed}dialog{background:none;border:0;box-sizing:border-box;display:flex;margin:0;max-height:calc(100vh - 16px);max-height:calc(100dvh - 16px);max-width:calc(100vw - 16px);opacity:1!important;overflow:visible;padding:0;position:fixed}:host(:not([open])) dialog{left:0;pointer-events:none;top:0;transform:translate(-999em,-999em)}dialog::backdrop{display:none}dialog>div{width:100%}::slotted(sp-popover){position:static}dialog[actual-placement*=top]{margin-top:var(--swc-overlay-animation-distance);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=right]{margin-left:calc(var(--swc-overlay-animation-distance)*-1);padding-inline:var(--swc-overlay-animation-distance)}dialog[actual-placement*=bottom]{margin-top:calc(var(--swc-overlay-animation-distance)*-1);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=left]{margin-left:var(--swc-overlay-animation-distance);padding-inline:var(--swc-overlay-animation-distance)}@supports selector(:open){dialog{opacity:0}dialog:open{opacity:1}}@supports not selector(:open){:host:not([open]) dialog{pointer-events:none}dialog[actual-placement]{z-index:var(--swc-overlay-z-index)}}\n`;\nexport default styles;"],
|
|
5
5
|
"mappings": ";AAWA,SAAS,WAAW;AACpB,MAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAKf,eAAe;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/overlay-base.css.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";import{css as a}from"@spectrum-web-components/base";const o=a`
|
|
2
2
|
:host{--swc-overlay-animation-distance:var(
|
|
3
3
|
--spectrum-picker-m-texticon-popover-offset-y,var(--spectrum-global-dimension-size-75)
|
|
4
|
-
)}dialog{background:none;border:0;box-sizing:border-box;display:flex;margin:0;max-height:calc(100vh - 16px);max-height:calc(100dvh - 16px);max-width:calc(100vw - 16px);opacity:1!important;overflow:visible;padding:0;position:fixed}:host(:not([open])) dialog{left:0;pointer-events:none;top:0;transform:translate(-999em,-999em)}dialog::backdrop{display:none}dialog>div{width:100%}::slotted(sp-popover){position:static}dialog[actual-placement*=top]{margin-top:var(--swc-overlay-animation-distance);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=right]{margin-left:calc(var(--swc-overlay-animation-distance)*-1);padding-inline:var(--swc-overlay-animation-distance)}dialog[actual-placement*=bottom]{margin-top:calc(var(--swc-overlay-animation-distance)*-1);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=left]{margin-left:var(--swc-overlay-animation-distance);padding-inline:var(--swc-overlay-animation-distance)}@supports selector(:open){dialog{opacity:0}dialog:open{opacity:1}}@supports not selector(:open){:host:not([open]) dialog{pointer-events:none}dialog[actual-placement]{z-index:var(--swc-overlay-z-index)}}
|
|
4
|
+
);position:fixed}dialog{background:none;border:0;box-sizing:border-box;display:flex;margin:0;max-height:calc(100vh - 16px);max-height:calc(100dvh - 16px);max-width:calc(100vw - 16px);opacity:1!important;overflow:visible;padding:0;position:fixed}:host(:not([open])) dialog{left:0;pointer-events:none;top:0;transform:translate(-999em,-999em)}dialog::backdrop{display:none}dialog>div{width:100%}::slotted(sp-popover){position:static}dialog[actual-placement*=top]{margin-top:var(--swc-overlay-animation-distance);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=right]{margin-left:calc(var(--swc-overlay-animation-distance)*-1);padding-inline:var(--swc-overlay-animation-distance)}dialog[actual-placement*=bottom]{margin-top:calc(var(--swc-overlay-animation-distance)*-1);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=left]{margin-left:var(--swc-overlay-animation-distance);padding-inline:var(--swc-overlay-animation-distance)}@supports selector(:open){dialog{opacity:0}dialog:open{opacity:1}}@supports not selector(:open){:host:not([open]) dialog{pointer-events:none}dialog[actual-placement]{z-index:var(--swc-overlay-z-index)}}
|
|
5
5
|
`;export default o;
|
|
6
6
|
//# sourceMappingURL=overlay-base.css.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["overlay-base.css.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2023 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 { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host{--swc-overlay-animation-distance:var(\n--spectrum-picker-m-texticon-popover-offset-y,var(--spectrum-global-dimension-size-75)\n)}dialog{background:none;border:0;box-sizing:border-box;display:flex;margin:0;max-height:calc(100vh - 16px);max-height:calc(100dvh - 16px);max-width:calc(100vw - 16px);opacity:1!important;overflow:visible;padding:0;position:fixed}:host(:not([open])) dialog{left:0;pointer-events:none;top:0;transform:translate(-999em,-999em)}dialog::backdrop{display:none}dialog>div{width:100%}::slotted(sp-popover){position:static}dialog[actual-placement*=top]{margin-top:var(--swc-overlay-animation-distance);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=right]{margin-left:calc(var(--swc-overlay-animation-distance)*-1);padding-inline:var(--swc-overlay-animation-distance)}dialog[actual-placement*=bottom]{margin-top:calc(var(--swc-overlay-animation-distance)*-1);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=left]{margin-left:var(--swc-overlay-animation-distance);padding-inline:var(--swc-overlay-animation-distance)}@supports selector(:open){dialog{opacity:0}dialog:open{opacity:1}}@supports not selector(:open){:host:not([open]) dialog{pointer-events:none}dialog[actual-placement]{z-index:var(--swc-overlay-z-index)}}\n`;\nexport default styles;"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2023 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 { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host{--swc-overlay-animation-distance:var(\n--spectrum-picker-m-texticon-popover-offset-y,var(--spectrum-global-dimension-size-75)\n);position:fixed}dialog{background:none;border:0;box-sizing:border-box;display:flex;margin:0;max-height:calc(100vh - 16px);max-height:calc(100dvh - 16px);max-width:calc(100vw - 16px);opacity:1!important;overflow:visible;padding:0;position:fixed}:host(:not([open])) dialog{left:0;pointer-events:none;top:0;transform:translate(-999em,-999em)}dialog::backdrop{display:none}dialog>div{width:100%}::slotted(sp-popover){position:static}dialog[actual-placement*=top]{margin-top:var(--swc-overlay-animation-distance);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=right]{margin-left:calc(var(--swc-overlay-animation-distance)*-1);padding-inline:var(--swc-overlay-animation-distance)}dialog[actual-placement*=bottom]{margin-top:calc(var(--swc-overlay-animation-distance)*-1);padding-block:var(--swc-overlay-animation-distance)}dialog[actual-placement*=left]{margin-left:var(--swc-overlay-animation-distance);padding-inline:var(--swc-overlay-animation-distance)}@supports selector(:open){dialog{opacity:0}dialog:open{opacity:1}}@supports not selector(:open){:host:not([open]) dialog{pointer-events:none}dialog[actual-placement]{z-index:var(--swc-overlay-z-index)}}\n`;\nexport default styles;"],
|
|
5
5
|
"mappings": "aAWA,OAAS,OAAAA,MAAW,gCACpB,MAAMC,EAASD;AAAA;AAAA;AAAA;AAAA,EAKf,eAAeC",
|
|
6
6
|
"names": ["css", "styles"]
|
|
7
7
|
}
|
package/test/overlay.test.js
CHANGED
|
@@ -444,23 +444,10 @@ describe('Overlay - type="modal"', () => {
|
|
|
444
444
|
it('closes the first "contextmenu" when opening a second', async () => {
|
|
445
445
|
const closed = oneEvent(document, "sp-closed");
|
|
446
446
|
const opened = oneEvent(document, "sp-opened");
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
{
|
|
450
|
-
type: "move",
|
|
451
|
-
position: [width / 4, height / 4]
|
|
452
|
-
},
|
|
453
|
-
{
|
|
454
|
-
type: "click",
|
|
455
|
-
options: {
|
|
456
|
-
button: "right"
|
|
457
|
-
},
|
|
458
|
-
position: [width / 4, height / 4]
|
|
459
|
-
}
|
|
460
|
-
]
|
|
461
|
-
});
|
|
462
|
-
await opened;
|
|
447
|
+
const trigger = document.querySelector("start-end-contextmenu");
|
|
448
|
+
trigger.dispatchEvent(new Event("contextmenu"));
|
|
463
449
|
await closed;
|
|
450
|
+
await opened;
|
|
464
451
|
secondMenu = document.querySelector("sp-popover");
|
|
465
452
|
secondRect = secondMenu.getBoundingClientRect();
|
|
466
453
|
expect(secondMenu).to.not.be.null;
|
|
@@ -469,13 +456,9 @@ describe('Overlay - type="modal"', () => {
|
|
|
469
456
|
const closed = oneEvent(document, "sp-closed");
|
|
470
457
|
sendMouse({
|
|
471
458
|
steps: [
|
|
472
|
-
{
|
|
473
|
-
type: "move",
|
|
474
|
-
position: [width / 8, height / 8]
|
|
475
|
-
},
|
|
476
459
|
{
|
|
477
460
|
type: "click",
|
|
478
|
-
position: [width / 8, height / 8]
|
|
461
|
+
position: [width - width / 8, height - height / 8]
|
|
479
462
|
}
|
|
480
463
|
]
|
|
481
464
|
});
|