@spectrum-web-components/overlay 0.40.2 → 0.40.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -1
- package/custom-elements.json +36 -5
- package/package.json +7 -7
- package/src/AbstractOverlay.d.ts +19 -1
- package/src/AbstractOverlay.dev.js +17 -0
- package/src/AbstractOverlay.dev.js.map +2 -2
- package/src/AbstractOverlay.js +1 -1
- package/src/AbstractOverlay.js.map +3 -3
- package/src/Overlay.dev.js +1 -2
- package/src/Overlay.dev.js.map +2 -2
- package/src/Overlay.js +1 -1
- package/src/Overlay.js.map +2 -2
- package/src/OverlayDialog.dev.js +14 -15
- package/src/OverlayDialog.dev.js.map +2 -2
- package/src/OverlayDialog.js +1 -1
- package/src/OverlayDialog.js.map +3 -3
- package/src/OverlayNoPopover.dev.js +9 -11
- package/src/OverlayNoPopover.dev.js.map +2 -2
- package/src/OverlayNoPopover.js +1 -1
- package/src/OverlayNoPopover.js.map +3 -3
- package/src/OverlayPopover.dev.js +14 -19
- package/src/OverlayPopover.dev.js.map +2 -2
- package/src/OverlayPopover.js +1 -1
- package/src/OverlayPopover.js.map +3 -3
- package/src/OverlayStack.d.ts +1 -0
- package/src/OverlayStack.dev.js +12 -4
- package/src/OverlayStack.dev.js.map +2 -2
- package/src/OverlayStack.js +1 -1
- package/src/OverlayStack.js.map +3 -3
- package/src/OverlayTrigger.dev.js +1 -1
- package/src/OverlayTrigger.dev.js.map +2 -2
- package/src/OverlayTrigger.js +1 -1
- package/src/OverlayTrigger.js.map +2 -2
- package/src/PlacementController.d.ts +1 -0
- package/src/PlacementController.dev.js +24 -12
- package/src/PlacementController.dev.js.map +2 -2
- package/src/PlacementController.js +1 -1
- package/src/PlacementController.js.map +3 -3
- package/src/overlay-trigger.css.dev.js.map +1 -1
- package/src/overlay-trigger.css.js.map +1 -1
- package/src/overlay-types.d.ts +0 -6
- package/src/overlay-types.dev.js.map +1 -1
- package/src/overlay-types.js.map +1 -1
- package/src/overlay.css.dev.js +1 -1
- package/src/overlay.css.dev.js.map +1 -1
- package/src/overlay.css.js +1 -1
- package/src/overlay.css.js.map +1 -1
- package/src/topLayerOverTransforms.dev.js +8 -1
- package/src/topLayerOverTransforms.dev.js.map +2 -2
- package/src/topLayerOverTransforms.js +1 -1
- package/src/topLayerOverTransforms.js.map +2 -2
- package/stories/overlay-element.stories.js +75 -22
- package/stories/overlay-element.stories.js.map +2 -2
- package/stories/overlay.stories.js +79 -3
- package/stories/overlay.stories.js.map +3 -3
- package/test/index.js +20 -12
- package/test/index.js.map +2 -2
- package/test/overlay-element.test.js +4 -2
- package/test/overlay-element.test.js.map +2 -2
- package/test/overlay-trigger-longpress.test.js +27 -9
- package/test/overlay-trigger-longpress.test.js.map +2 -2
- package/test/overlay-update.test.js +5 -5
- package/test/overlay-update.test.js.map +2 -2
package/src/OverlayDialog.dev.js
CHANGED
|
@@ -7,7 +7,8 @@ import { VirtualTrigger } from "./VirtualTrigger.dev.js";
|
|
|
7
7
|
import {
|
|
8
8
|
BeforetoggleClosedEvent,
|
|
9
9
|
BeforetoggleOpenEvent,
|
|
10
|
-
guaranteedAllTransitionend
|
|
10
|
+
guaranteedAllTransitionend,
|
|
11
|
+
OverlayStateEvent
|
|
11
12
|
} from "./AbstractOverlay.dev.js";
|
|
12
13
|
import { userFocusableSelector } from "@spectrum-web-components/shared";
|
|
13
14
|
export function OverlayDialog(constructor) {
|
|
@@ -70,10 +71,9 @@ export function OverlayDialog(constructor) {
|
|
|
70
71
|
const eventName = targetOpenState ? "sp-opened" : "sp-closed";
|
|
71
72
|
if (index > 0) {
|
|
72
73
|
el.dispatchEvent(
|
|
73
|
-
new
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
detail: { interaction: this.type }
|
|
74
|
+
new OverlayStateEvent(eventName, this, {
|
|
75
|
+
interaction: this.type,
|
|
76
|
+
publish: false
|
|
77
77
|
})
|
|
78
78
|
);
|
|
79
79
|
return;
|
|
@@ -84,23 +84,22 @@ export function OverlayDialog(constructor) {
|
|
|
84
84
|
const reportChange = () => {
|
|
85
85
|
const hasVirtualTrigger = this.triggerElement instanceof VirtualTrigger;
|
|
86
86
|
this.dispatchEvent(
|
|
87
|
-
new
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
new OverlayStateEvent(eventName, this, {
|
|
88
|
+
interaction: this.type,
|
|
89
|
+
publish: hasVirtualTrigger
|
|
90
90
|
})
|
|
91
91
|
);
|
|
92
92
|
el.dispatchEvent(
|
|
93
|
-
new
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
new OverlayStateEvent(eventName, this, {
|
|
94
|
+
interaction: this.type,
|
|
95
|
+
publish: false
|
|
96
96
|
})
|
|
97
97
|
);
|
|
98
98
|
if (this.triggerElement && !hasVirtualTrigger) {
|
|
99
99
|
this.triggerElement.dispatchEvent(
|
|
100
|
-
new
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
detail: { interaction: this.type }
|
|
100
|
+
new OverlayStateEvent(eventName, this, {
|
|
101
|
+
interaction: this.type,
|
|
102
|
+
publish: true
|
|
104
103
|
})
|
|
105
104
|
);
|
|
106
105
|
}
|
|
@@ -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 type { SpectrumElement } from '@spectrum-web-components/base';\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport {
|
|
5
|
-
"mappings": ";AAYA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,SAAS,sBAAsB;
|
|
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 type { SpectrumElement } from '@spectrum-web-components/base';\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport { Constructor, OpenableElement } from './overlay-types.dev.js'\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedAllTransitionend,\n OverlayStateEvent,\n} from './AbstractOverlay.dev.js'\nimport type { AbstractOverlay } from './AbstractOverlay.dev.js'\nimport { userFocusableSelector } from '@spectrum-web-components/shared';\n\nexport function OverlayDialog<T extends Constructor<AbstractOverlay>>(\n constructor: T\n): T & Constructor<SpectrumElement> {\n class OverlayWithDialog extends constructor {\n protected override async manageDialogOpen(): Promise<void> {\n const targetOpenState = this.open;\n await this.managePosition();\n if (this.open !== targetOpenState) {\n return;\n }\n if (this.open !== targetOpenState) {\n return;\n }\n const focusEl = await this.dialogMakeTransition(targetOpenState);\n if (this.open !== targetOpenState) {\n return;\n }\n await this.dialogApplyFocus(targetOpenState, focusEl);\n }\n\n protected async 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 el.open = targetOpenState;\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) {\n // Announce workflow on the first element _only_.\n return;\n }\n const event = targetOpenState\n ? BeforetoggleOpenEvent\n : BeforetoggleClosedEvent;\n this.dispatchEvent(new event());\n if (!targetOpenState) {\n // Show/focus workflow when opening _only_.\n return;\n }\n if (el.matches(userFocusableSelector)) {\n focusEl = el;\n }\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 // In both of these cases the browser will error.\n // You can neither \"reopen\" a <dialog> or open one that is not on the DOM.\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 OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: false,\n })\n );\n return;\n }\n if (!this.isConnected || targetOpenState !== this.open) {\n // Don't lead into the `.close()` workflow if not connected to the DOM.\n // The browser will error in this case.\n return;\n }\n const reportChange = (): void => {\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: hasVirtualTrigger,\n })\n );\n el.dispatchEvent(\n new OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: false,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: true,\n })\n );\n }\n this.state = targetOpenState ? 'opened' : 'closed';\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 guaranteedAllTransitionend(\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 be 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 this.applyFocus(targetOpenState, focusEl);\n }\n }\n return OverlayWithDialog;\n}\n"],
|
|
5
|
+
"mappings": ";AAYA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,SAAS,sBAAsB;AAE/B;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,SAAS,6BAA6B;AAE/B,gBAAS,cACZ,aACgC;AAAA,EAChC,MAAM,0BAA0B,YAAY;AAAA,IACxC,MAAyB,mBAAkC;AACvD,YAAM,kBAAkB,KAAK;AAC7B,YAAM,KAAK,eAAe;AAC1B,UAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,MACJ;AACA,UAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,MACJ;AACA,YAAM,UAAU,MAAM,KAAK,qBAAqB,eAAe;AAC/D,UAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,MACJ;AACA,YAAM,KAAK,iBAAiB,iBAAiB,OAAO;AAAA,IACxD;AAAA,IAEA,MAAgB,qBACZ,iBAC2B;AAC3B,UAAI,UAAU;AACd,YAAM,QACF,CAAC,IAAqB,UACtB,YAA2B;AACvB,WAAG,OAAO;AACV,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,GAAG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+B;AAAA,cACjC,IAAI,kBAAkB,WAAW,MAAM;AAAA,gBACnC,aAAa,KAAK;AAAA,gBAClB,SAAS;AAAA,cACb,CAAC;AAAA,YACL;AAAA,UACJ;AACA,eAAK,QAAQ,kBAAkB,WAAW;AAAA,QAC9C;AACA,YAAI,CAAC,mBAAmB,KAAK,SAAS,MAAM;AACxC,eAAK,SAAS;AAAA,YACV;AAAA,YACA,MAAM;AACF,2BAAa;AAAA,YACjB;AAAA,YACA,EAAE,MAAM,KAAK;AAAA,UACjB;AACA,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,WAAK,WAAW,iBAAiB,OAAO;AAAA,IAC5C;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
|
|
1
|
+
"use strict";import{firstFocusableIn as u,firstFocusableSlottedIn as m}from"@spectrum-web-components/shared/src/first-focusable-in.js";import{VirtualTrigger as d}from"./VirtualTrigger.js";import{BeforetoggleClosedEvent as f,BeforetoggleOpenEvent as E,guaranteedAllTransitionend as v,OverlayStateEvent as l}from"./AbstractOverlay.js";import{userFocusableSelector as g}from"@spectrum-web-components/shared";export function OverlayDialog(c){class h extends c{async manageDialogOpen(){const e=this.open;if(await this.managePosition(),this.open!==e||this.open!==e)return;const i=await this.dialogMakeTransition(e);this.open===e&&await this.dialogApplyFocus(e,i)}async dialogMakeTransition(e){let i=null;const p=(t,o)=>async()=>{if(t.open=e,!e){const n=()=>{t.removeEventListener("close",n),a(t,o)};t.addEventListener("close",n)}if(o>0)return;const s=e?E:f;this.dispatchEvent(new s),e&&(t.matches(g)&&(i=t),i=i||u(t),i||t.querySelectorAll("slot").forEach(r=>{i||(i=m(r))}),!(!this.isConnected||this.dialogEl.open)&&this.dialogEl.showModal())},a=(t,o)=>()=>{if(this.open!==e)return;const s=e?"sp-opened":"sp-closed";if(o>0){t.dispatchEvent(new l(s,this,{interaction:this.type,publish:!1}));return}if(!this.isConnected||e!==this.open)return;const n=()=>{const r=this.triggerElement instanceof d;this.dispatchEvent(new l(s,this,{interaction:this.type,publish:r})),t.dispatchEvent(new l(s,this,{interaction:this.type,publish:!1})),this.triggerElement&&!r&&this.triggerElement.dispatchEvent(new l(s,this,{interaction:this.type,publish:!0})),this.state=e?"opened":"closed"};!e&&this.dialogEl.open?(this.dialogEl.addEventListener("close",()=>{n()},{once:!0}),this.dialogEl.close()):n()};return this.elements.forEach((t,o)=>{v(t,p(t,o),a(t,o))}),i}async dialogApplyFocus(e,i){this.applyFocus(e,i)}}return h}
|
|
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 type { SpectrumElement } from '@spectrum-web-components/base';\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport { VirtualTrigger } from './VirtualTrigger.js';\nimport {
|
|
5
|
-
"mappings": "aAYA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DACP,OAAS,kBAAAC,MAAsB,
|
|
6
|
-
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "VirtualTrigger", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedAllTransitionend", "userFocusableSelector", "constructor", "OverlayWithDialog", "targetOpenState", "focusEl", "start", "el", "index", "close", "finish", "event", "slot", "eventName", "reportChange", "hasVirtualTrigger"]
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport type { SpectrumElement } from '@spectrum-web-components/base';\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport { VirtualTrigger } from './VirtualTrigger.js';\nimport { Constructor, OpenableElement } from './overlay-types.js';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedAllTransitionend,\n OverlayStateEvent,\n} from './AbstractOverlay.js';\nimport type { AbstractOverlay } from './AbstractOverlay.js';\nimport { userFocusableSelector } from '@spectrum-web-components/shared';\n\nexport function OverlayDialog<T extends Constructor<AbstractOverlay>>(\n constructor: T\n): T & Constructor<SpectrumElement> {\n class OverlayWithDialog extends constructor {\n protected override async manageDialogOpen(): Promise<void> {\n const targetOpenState = this.open;\n await this.managePosition();\n if (this.open !== targetOpenState) {\n return;\n }\n if (this.open !== targetOpenState) {\n return;\n }\n const focusEl = await this.dialogMakeTransition(targetOpenState);\n if (this.open !== targetOpenState) {\n return;\n }\n await this.dialogApplyFocus(targetOpenState, focusEl);\n }\n\n protected async 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 el.open = targetOpenState;\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) {\n // Announce workflow on the first element _only_.\n return;\n }\n const event = targetOpenState\n ? BeforetoggleOpenEvent\n : BeforetoggleClosedEvent;\n this.dispatchEvent(new event());\n if (!targetOpenState) {\n // Show/focus workflow when opening _only_.\n return;\n }\n if (el.matches(userFocusableSelector)) {\n focusEl = el;\n }\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 // In both of these cases the browser will error.\n // You can neither \"reopen\" a <dialog> or open one that is not on the DOM.\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 OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: false,\n })\n );\n return;\n }\n if (!this.isConnected || targetOpenState !== this.open) {\n // Don't lead into the `.close()` workflow if not connected to the DOM.\n // The browser will error in this case.\n return;\n }\n const reportChange = (): void => {\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: hasVirtualTrigger,\n })\n );\n el.dispatchEvent(\n new OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: false,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: true,\n })\n );\n }\n this.state = targetOpenState ? 'opened' : 'closed';\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 guaranteedAllTransitionend(\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 be 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 this.applyFocus(targetOpenState, focusEl);\n }\n }\n return OverlayWithDialog;\n}\n"],
|
|
5
|
+
"mappings": "aAYA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DACP,OAAS,kBAAAC,MAAsB,sBAE/B,OACI,2BAAAC,EACA,yBAAAC,EACA,8BAAAC,EACA,qBAAAC,MACG,uBAEP,OAAS,yBAAAC,MAA6B,kCAE/B,gBAAS,cACZC,EACgC,CAChC,MAAMC,UAA0BD,CAAY,CACxC,MAAyB,kBAAkC,CACvD,MAAME,EAAkB,KAAK,KAK7B,GAJA,MAAM,KAAK,eAAe,EACtB,KAAK,OAASA,GAGd,KAAK,OAASA,EACd,OAEJ,MAAMC,EAAU,MAAM,KAAK,qBAAqBD,CAAe,EAC3D,KAAK,OAASA,GAGlB,MAAM,KAAK,iBAAiBA,EAAiBC,CAAO,CACxD,CAEA,MAAgB,qBACZD,EAC2B,CAC3B,IAAIC,EAAU,KACd,MAAMC,EACF,CAACC,EAAqBC,IACtB,SAA2B,CAEvB,GADAD,EAAG,KAAOH,EACN,CAACA,EAAiB,CAClB,MAAMK,EAAQ,IAAY,CACtBF,E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K,CACjB,EACA,KAAK,SAAS,MAAM,GAEpBA,EAAa,CAErB,EACA,YAAK,SAAS,QAAQ,CAACP,EAAIC,IAAU,CACjCT,EACIQ,EACAD,EAAMC,EAAIC,CAAK,EACfE,EAAOH,EAAIC,CAAK,CACpB,CACJ,CAAC,EACMH,CACX,CAEA,MAAgB,iBACZD,EACAC,EACa,CAMb,KAAK,WAAWD,EAAiBC,CAAO,CAC5C,CACJ,CACA,OAAOF,CACX",
|
|
6
|
+
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "VirtualTrigger", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedAllTransitionend", "OverlayStateEvent", "userFocusableSelector", "constructor", "OverlayWithDialog", "targetOpenState", "focusEl", "start", "el", "index", "close", "finish", "event", "slot", "eventName", "reportChange", "hasVirtualTrigger"]
|
|
7
7
|
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
BeforetoggleOpenEvent,
|
|
10
10
|
forcePaint,
|
|
11
11
|
guaranteedAllTransitionend,
|
|
12
|
+
OverlayStateEvent,
|
|
12
13
|
overlayTimer
|
|
13
14
|
} from "./AbstractOverlay.dev.js";
|
|
14
15
|
import { userFocusableSelector } from "@spectrum-web-components/shared";
|
|
@@ -69,10 +70,8 @@ export function OverlayNoPopover(constructor) {
|
|
|
69
70
|
}
|
|
70
71
|
const eventName = targetOpenState ? "sp-opened" : "sp-closed";
|
|
71
72
|
el.dispatchEvent(
|
|
72
|
-
new
|
|
73
|
-
|
|
74
|
-
composed: false,
|
|
75
|
-
detail: { interaction: this.type }
|
|
73
|
+
new OverlayStateEvent(eventName, this, {
|
|
74
|
+
interaction: this.type
|
|
76
75
|
})
|
|
77
76
|
);
|
|
78
77
|
if (index > 0) {
|
|
@@ -80,17 +79,16 @@ export function OverlayNoPopover(constructor) {
|
|
|
80
79
|
}
|
|
81
80
|
const hasVirtualTrigger = this.triggerElement instanceof VirtualTrigger;
|
|
82
81
|
this.dispatchEvent(
|
|
83
|
-
new
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
new OverlayStateEvent(eventName, this, {
|
|
83
|
+
interaction: this.type,
|
|
84
|
+
publish: hasVirtualTrigger
|
|
86
85
|
})
|
|
87
86
|
);
|
|
88
87
|
if (this.triggerElement && !hasVirtualTrigger) {
|
|
89
88
|
this.triggerElement.dispatchEvent(
|
|
90
|
-
new
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
detail: { interaction: this.type }
|
|
89
|
+
new OverlayStateEvent(eventName, this, {
|
|
90
|
+
interaction: this.type,
|
|
91
|
+
publish: true
|
|
94
92
|
})
|
|
95
93
|
);
|
|
96
94
|
}
|
|
@@ -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 type { SpectrumElement } from '@spectrum-web-components/base';\nimport { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport {
|
|
5
|
-
"mappings": ";AAWA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP,SAAS,sBAAsB;
|
|
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 type { SpectrumElement } from '@spectrum-web-components/base';\nimport { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport { Constructor, OpenableElement } from './overlay-types.dev.js'\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n forcePaint,\n guaranteedAllTransitionend,\n OverlayStateEvent,\n overlayTimer,\n} from './AbstractOverlay.dev.js'\nimport type { AbstractOverlay } from './AbstractOverlay.dev.js'\nimport { userFocusableSelector } from '@spectrum-web-components/shared';\n\nexport function OverlayNoPopover<T extends Constructor<AbstractOverlay>>(\n constructor: T\n): T & Constructor<SpectrumElement> {\n class OverlayWithNoPopover extends constructor {\n protected override async managePopoverOpen(): Promise<void> {\n await this.managePosition();\n }\n\n protected override async manageDelay(\n targetOpenState: boolean\n ): Promise<void> {\n if (targetOpenState === false || targetOpenState !== this.open) {\n overlayTimer.close(this);\n return;\n }\n if (this.delayed) {\n const cancelled = await overlayTimer.openTimer(this);\n if (cancelled) {\n this.open = !targetOpenState;\n }\n }\n }\n\n protected override async ensureOnDOM(\n _targetOpenState: boolean\n ): Promise<void> {\n forcePaint();\n }\n\n protected override async makeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n if (this.open !== targetOpenState) {\n return null;\n }\n let focusEl = null as HTMLElement | null;\n const start = (el: OpenableElement, index: number) => (): void => {\n if (targetOpenState !== this.open) {\n return;\n }\n el.open = targetOpenState;\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 if (el.matches(userFocusableSelector)) {\n focusEl = el;\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 OverlayStateEvent(eventName, this, {\n interaction: this.type,\n })\n );\n if (index > 0) {\n return;\n }\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: hasVirtualTrigger,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: true,\n })\n );\n }\n this.state = targetOpenState ? 'opened' : 'closed';\n };\n this.elements.forEach((el, index) => {\n guaranteedAllTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n }\n return OverlayWithNoPopover;\n}\n"],
|
|
5
|
+
"mappings": ";AAWA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP,SAAS,sBAAsB;AAE/B;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,SAAS,6BAA6B;AAE/B,gBAAS,iBACZ,aACgC;AAAA,EAChC,MAAM,6BAA6B,YAAY;AAAA,IAC3C,MAAyB,oBAAmC;AACxD,YAAM,KAAK,eAAe;AAAA,IAC9B;AAAA,IAEA,MAAyB,YACrB,iBACa;AACb,UAAI,oBAAoB,SAAS,oBAAoB,KAAK,MAAM;AAC5D,qBAAa,MAAM,IAAI;AACvB;AAAA,MACJ;AACA,UAAI,KAAK,SAAS;AACd,cAAM,YAAY,MAAM,aAAa,UAAU,IAAI;AACnD,YAAI,WAAW;AACX,eAAK,OAAO,CAAC;AAAA,QACjB;AAAA,MACJ;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,kBAAkB,WAAW,MAAM;AAAA,cACnC,aAAa,KAAK;AAAA,cAClB,SAAS;AAAA,YACb,CAAC;AAAA,UACL;AAAA,QACJ;AACA,aAAK,QAAQ,kBAAkB,WAAW;AAAA,MAC9C;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,EACJ;AACA,SAAO;AACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/OverlayNoPopover.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";import{firstFocusableIn as
|
|
1
|
+
"use strict";import{firstFocusableIn as h,firstFocusableSlottedIn as u}from"@spectrum-web-components/shared/src/first-focusable-in.js";import{VirtualTrigger as d}from"./VirtualTrigger.js";import{BeforetoggleClosedEvent as f,BeforetoggleOpenEvent as v,forcePaint as E,guaranteedAllTransitionend as y,OverlayStateEvent as s,overlayTimer as l}from"./AbstractOverlay.js";import{userFocusableSelector as b}from"@spectrum-web-components/shared";export function OverlayNoPopover(c){class a extends c{async managePopoverOpen(){await this.managePosition()}async manageDelay(e){if(e===!1||e!==this.open){l.close(this);return}this.delayed&&await l.openTimer(this)&&(this.open=!e)}async ensureOnDOM(e){E()}async makeTransition(e){if(this.open!==e)return null;let o=null;const m=(t,r)=>()=>{if(e!==this.open)return;if(t.open=e,r===0){const n=e?v:f;this.dispatchEvent(new n)}if(e!==!0||(t.matches(b)&&(o=t),o=o||h(t),o))return;t.querySelectorAll("slot").forEach(n=>{o||(o=u(n))})},p=(t,r)=>()=>{if(this.open!==e)return;const i=e?"sp-opened":"sp-closed";if(t.dispatchEvent(new s(i,this,{interaction:this.type})),r>0)return;const n=this.triggerElement instanceof d;this.dispatchEvent(new s(i,this,{interaction:this.type,publish:n})),this.triggerElement&&!n&&this.triggerElement.dispatchEvent(new s(i,this,{interaction:this.type,publish:!0})),this.state=e?"opened":"closed"};return this.elements.forEach((t,r)=>{y(t,m(t,r),p(t,r))}),o}}return a}
|
|
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 type { SpectrumElement } from '@spectrum-web-components/base';\nimport { VirtualTrigger } from './VirtualTrigger.js';\nimport {
|
|
5
|
-
"mappings": "aAWA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DAEP,OAAS,kBAAAC,MAAsB,
|
|
6
|
-
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "VirtualTrigger", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "forcePaint", "guaranteedAllTransitionend", "overlayTimer", "userFocusableSelector", "constructor", "OverlayWithNoPopover", "targetOpenState", "_targetOpenState", "focusEl", "start", "el", "index", "event", "slot", "finish", "eventName", "hasVirtualTrigger"]
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport type { SpectrumElement } from '@spectrum-web-components/base';\nimport { VirtualTrigger } from './VirtualTrigger.js';\nimport { Constructor, OpenableElement } from './overlay-types.js';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n forcePaint,\n guaranteedAllTransitionend,\n OverlayStateEvent,\n overlayTimer,\n} from './AbstractOverlay.js';\nimport type { AbstractOverlay } from './AbstractOverlay.js';\nimport { userFocusableSelector } from '@spectrum-web-components/shared';\n\nexport function OverlayNoPopover<T extends Constructor<AbstractOverlay>>(\n constructor: T\n): T & Constructor<SpectrumElement> {\n class OverlayWithNoPopover extends constructor {\n protected override async managePopoverOpen(): Promise<void> {\n await this.managePosition();\n }\n\n protected override async manageDelay(\n targetOpenState: boolean\n ): Promise<void> {\n if (targetOpenState === false || targetOpenState !== this.open) {\n overlayTimer.close(this);\n return;\n }\n if (this.delayed) {\n const cancelled = await overlayTimer.openTimer(this);\n if (cancelled) {\n this.open = !targetOpenState;\n }\n }\n }\n\n protected override async ensureOnDOM(\n _targetOpenState: boolean\n ): Promise<void> {\n forcePaint();\n }\n\n protected override async makeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n if (this.open !== targetOpenState) {\n return null;\n }\n let focusEl = null as HTMLElement | null;\n const start = (el: OpenableElement, index: number) => (): void => {\n if (targetOpenState !== this.open) {\n return;\n }\n el.open = targetOpenState;\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 if (el.matches(userFocusableSelector)) {\n focusEl = el;\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 OverlayStateEvent(eventName, this, {\n interaction: this.type,\n })\n );\n if (index > 0) {\n return;\n }\n const hasVirtualTrigger =\n this.triggerElement instanceof VirtualTrigger;\n this.dispatchEvent(\n new OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: hasVirtualTrigger,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: true,\n })\n );\n }\n this.state = targetOpenState ? 'opened' : 'closed';\n };\n this.elements.forEach((el, index) => {\n guaranteedAllTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n }\n return OverlayWithNoPopover;\n}\n"],
|
|
5
|
+
"mappings": "aAWA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DAEP,OAAS,kBAAAC,MAAsB,sBAE/B,OACI,2BAAAC,EACA,yBAAAC,EACA,cAAAC,EACA,8BAAAC,EACA,qBAAAC,EACA,gBAAAC,MACG,uBAEP,OAAS,yBAAAC,MAA6B,kCAE/B,gBAAS,iBACZC,EACgC,CAChC,MAAMC,UAA6BD,CAAY,CAC3C,MAAyB,mBAAmC,CACxD,MAAM,KAAK,eAAe,CAC9B,CAEA,MAAyB,YACrBE,EACa,CACb,GAAIA,IAAoB,IAASA,IAAoB,KAAK,KAAM,CAC5DJ,EAAa,MAAM,IAAI,EACvB,MACJ,CACI,KAAK,SACa,MAAMA,EAAa,UAAU,IAAI,IAE/C,KAAK,KAAO,CAACI,EAGzB,CAEA,MAAyB,YACrBC,EACa,CACbR,EAAW,CACf,CAEA,MAAyB,eACrBO,EAC2B,CAC3B,GAAI,KAAK,OAASA,EACd,OAAO,KAEX,IAAIE,EAAU,KACd,MAAMC,EAAQ,CAACC,EAAqBC,IAAkB,IAAY,CAC9D,GAAIL,IAAoB,KAAK,KACzB,OAGJ,GADAI,EAAG,KAAOJ,EACNK,IAAU,EAAG,CACb,MAAMC,EAAQN,EACRR,EACAD,EACN,KAAK,cAAc,IAAIe,CAAO,CAClC,CAQA,GAPIN,IAAoB,KAGpBI,EAAG,QAAQP,CAAqB,IAChCK,EAAUE,GAEdF,EAAUA,GAAWd,EAAiBgB,CAAE,EACpCF,GACA,OAEeE,EAAG,iBAAiB,MAAM,EAClC,QAASG,GAAS,CACpBL,IACDA,EAAUb,EAAwBkB,CAAI,EAE9C,CAAC,CACL,EACMC,EAAS,CAACJ,EAAqBC,IAAkB,IAAY,CAC/D,GAAI,KAAK,OAASL,EACd,OAEJ,MAAMS,EAAYT,EAAkB,YAAc,YAMlD,GALAI,EAAG,cACC,IAAIT,EAAkBc,EAAW,KAAM,CACnC,YAAa,KAAK,IACtB,CAAC,CACL,EACIJ,EAAQ,EACR,OAEJ,MAAMK,EACF,KAAK,0BAA0BpB,EACnC,KAAK,cACD,IAAIK,EAAkBc,EAAW,KAAM,CACnC,YAAa,KAAK,KAClB,QAASC,CACb,CAAC,CACL,EACI,KAAK,gBAAkB,CAACA,GACvB,KAAK,eAA+B,cACjC,IAAIf,EAAkBc,EAAW,KAAM,CACnC,YAAa,KAAK,KAClB,QAAS,EACb,CAAC,CACL,EAEJ,KAAK,MAAQT,EAAkB,SAAW,QAC9C,EACA,YAAK,SAAS,QAAQ,CAACI,EAAIC,IAAU,CACjCX,EACIU,EACAD,EAAMC,EAAIC,CAAK,EACfG,EAAOJ,EAAIC,CAAK,CACpB,CACJ,CAAC,EACMH,CACX,CACJ,CACA,OAAOH,CACX",
|
|
6
|
+
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "VirtualTrigger", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "forcePaint", "guaranteedAllTransitionend", "OverlayStateEvent", "overlayTimer", "userFocusableSelector", "constructor", "OverlayWithNoPopover", "targetOpenState", "_targetOpenState", "focusEl", "start", "el", "index", "event", "slot", "finish", "eventName", "hasVirtualTrigger"]
|
|
7
7
|
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
BeforetoggleOpenEvent,
|
|
10
10
|
guaranteedAllTransitionend,
|
|
11
11
|
nextFrame,
|
|
12
|
+
OverlayStateEvent,
|
|
12
13
|
overlayTimer
|
|
13
14
|
} from "./AbstractOverlay.dev.js";
|
|
14
15
|
import { userFocusableSelector } from "@spectrum-web-components/shared";
|
|
@@ -120,10 +121,9 @@ export function OverlayPopover(constructor) {
|
|
|
120
121
|
const eventName = targetOpenState ? "sp-opened" : "sp-closed";
|
|
121
122
|
if (index > 0) {
|
|
122
123
|
el.dispatchEvent(
|
|
123
|
-
new
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
detail: { interaction: this.type }
|
|
124
|
+
new OverlayStateEvent(eventName, this, {
|
|
125
|
+
interaction: this.type,
|
|
126
|
+
publish: false
|
|
127
127
|
})
|
|
128
128
|
);
|
|
129
129
|
return;
|
|
@@ -135,28 +135,23 @@ export function OverlayPopover(constructor) {
|
|
|
135
135
|
await nextFrame();
|
|
136
136
|
const hasVirtualTrigger = this.triggerElement instanceof VirtualTrigger;
|
|
137
137
|
this.dispatchEvent(
|
|
138
|
-
new
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
new OverlayStateEvent(eventName, this, {
|
|
139
|
+
interaction: this.type,
|
|
140
|
+
publish: hasVirtualTrigger
|
|
141
141
|
})
|
|
142
142
|
);
|
|
143
143
|
el.dispatchEvent(
|
|
144
|
-
new
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
detail: { interaction: this.type }
|
|
144
|
+
new OverlayStateEvent(eventName, this, {
|
|
145
|
+
interaction: this.type,
|
|
146
|
+
publish: false
|
|
148
147
|
})
|
|
149
148
|
);
|
|
150
149
|
if (this.triggerElement && !hasVirtualTrigger) {
|
|
151
150
|
this.triggerElement.dispatchEvent(
|
|
152
|
-
new
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
composed: true,
|
|
157
|
-
detail: { interaction: this.type }
|
|
158
|
-
}
|
|
159
|
-
)
|
|
151
|
+
new OverlayStateEvent(eventName, this, {
|
|
152
|
+
interaction: this.type,
|
|
153
|
+
publish: true
|
|
154
|
+
})
|
|
160
155
|
);
|
|
161
156
|
}
|
|
162
157
|
this.state = targetOpenState ? "opened" : "closed";
|
|
@@ -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 type { SpectrumElement } from '@spectrum-web-components/base';\nimport { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport {
|
|
5
|
-
"mappings": ";AAWA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP,SAAS,sBAAsB;
|
|
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 type { SpectrumElement } from '@spectrum-web-components/base';\nimport { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport { Constructor, OpenableElement } from './overlay-types.dev.js'\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedAllTransitionend,\n nextFrame,\n OverlayStateEvent,\n overlayTimer,\n} from './AbstractOverlay.dev.js'\nimport type { AbstractOverlay } from './AbstractOverlay.dev.js'\nimport { userFocusableSelector } from '@spectrum-web-components/shared';\n\nfunction isOpen(el: HTMLElement): boolean {\n let popoverOpen = false;\n try {\n popoverOpen = el.matches(':popover-open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n let open = false;\n try {\n open = el.matches(':open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n return popoverOpen || open;\n}\n\nexport function OverlayPopover<T extends Constructor<AbstractOverlay>>(\n constructor: T\n): T & Constructor<SpectrumElement> {\n class OverlayWithPopover extends constructor {\n protected override async manageDelay(\n targetOpenState: boolean\n ): Promise<void> {\n if (targetOpenState === false || targetOpenState !== this.open) {\n overlayTimer.close(this);\n return;\n }\n if (this.delayed) {\n const cancelled = await overlayTimer.openTimer(this);\n if (cancelled) {\n this.open = !targetOpenState;\n }\n }\n }\n\n /**\n * A popover should be hidden _after_ it is no longer on top-layer because\n * the position metrics will have changed from when it was originally positioned.\n */\n private async shouldHidePopover(\n targetOpenState: boolean\n ): Promise<void> {\n if (targetOpenState && this.open !== targetOpenState) {\n return;\n }\n const update = async ({\n newState,\n }: { newState?: string } = {}): Promise<void> => {\n if (newState === 'open') {\n return;\n }\n // When in a parent Overlay, this Overlay may need to position itself\n // while closing in due to the parent _also_ closing which means the\n // location can no longer rely on \"top layer over transform\" math.\n await this.placementController.resetOverlayPosition();\n };\n if (!isOpen(this.dialogEl)) {\n // The means the Overlay was closed from the outside, it is already off of top-layer\n // so we need to position it in regards to this new state.\n update();\n return;\n }\n // `toggle` is an async event, so it's possible for this handler to run a frame late\n this.dialogEl.addEventListener('toggle', update as EventListener, {\n once: true,\n });\n }\n\n private async shouldShowPopover(\n targetOpenState: boolean\n ): Promise<void> {\n let popoverOpen = false;\n try {\n popoverOpen = this.dialogEl.matches(':popover-open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n let open = false;\n try {\n open = this.dialogEl.matches(':open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n if (\n targetOpenState &&\n this.open === targetOpenState &&\n !popoverOpen &&\n !open &&\n this.isConnected\n ) {\n this.dialogEl.showPopover();\n await this.managePosition();\n }\n }\n\n protected override async ensureOnDOM(\n targetOpenState: boolean\n ): Promise<void> {\n await nextFrame();\n await this.shouldHidePopover(targetOpenState);\n await this.shouldShowPopover(targetOpenState);\n await nextFrame();\n }\n\n protected override async makeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n if (this.open !== targetOpenState) {\n return null;\n }\n let focusEl = null as HTMLElement | null;\n const start = (el: OpenableElement, index: number) => (): void => {\n el.open = targetOpenState;\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 if (el.matches(userFocusableSelector)) {\n focusEl = el;\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 OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: 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 OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: hasVirtualTrigger,\n })\n );\n el.dispatchEvent(\n new OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: false,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: true,\n })\n );\n }\n this.state = targetOpenState ? 'opened' : 'closed';\n };\n if (this.open !== targetOpenState) {\n return;\n }\n const open = isOpen(this.dialogEl);\n if (targetOpenState !== true && open && this.isConnected) {\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 guaranteedAllTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n }\n return OverlayWithPopover;\n}\n"],
|
|
5
|
+
"mappings": ";AAWA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP,SAAS,sBAAsB;AAE/B;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,SAAS,6BAA6B;AAEtC,SAAS,OAAO,IAA0B;AACtC,MAAI,cAAc;AAClB,MAAI;AACA,kBAAc,GAAG,QAAQ,eAAe;AAAA,EAE5C,SAAS,OAAO;AAAA,EAAC;AACjB,MAAI,OAAO;AACX,MAAI;AACA,WAAO,GAAG,QAAQ,OAAO;AAAA,EAE7B,SAAS,OAAO;AAAA,EAAC;AACjB,SAAO,eAAe;AAC1B;AAEO,gBAAS,eACZ,aACgC;AAAA,EAChC,MAAM,2BAA2B,YAAY;AAAA,IACzC,MAAyB,YACrB,iBACa;AACb,UAAI,oBAAoB,SAAS,oBAAoB,KAAK,MAAM;AAC5D,qBAAa,MAAM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B,WAAW,MAAM;AAAA,gBACnC,aAAa,KAAK;AAAA,gBAClB,SAAS;AAAA,cACb,CAAC;AAAA,YACL;AAAA,UACJ;AACA,eAAK,QAAQ,kBAAkB,WAAW;AAAA,QAC9C;AACA,YAAI,KAAK,SAAS,iBAAiB;AAC/B;AAAA,QACJ;AACA,cAAM,OAAO,OAAO,KAAK,QAAQ;AACjC,YAAI,oBAAoB,QAAQ,QAAQ,KAAK,aAAa;AACtD,eAAK,SAAS;AAAA,YACV;AAAA,YACA,MAAM;AACF,2BAAa;AAAA,YACjB;AAAA,YACA,EAAE,MAAM,KAAK;AAAA,UACjB;AACA,eAAK,SAAS,YAAY;AAAA,QAC9B,OAAO;AACH,uBAAa;AAAA,QACjB;AAAA,MACJ;AACJ,WAAK,SAAS,QAAQ,CAAC,IAAI,UAAU;AACjC;AAAA,UACI;AAAA,UACA,MAAM,IAAI,KAAK;AAAA,UACf,OAAO,IAAI,KAAK;AAAA,QACpB;AAAA,MACJ,CAAC;AACD,aAAO;AAAA,IACX;AAAA,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 E,firstFocusableSlottedIn as y}from"@spectrum-web-components/shared/src/first-focusable-in.js";import{VirtualTrigger as b}from"./VirtualTrigger.js";import{BeforetoggleClosedEvent as w,BeforetoggleOpenEvent as P,guaranteedAllTransitionend as g,nextFrame as d,OverlayStateEvent as c,overlayTimer as u}from"./AbstractOverlay.js";import{userFocusableSelector as T}from"@spectrum-web-components/shared";function v(l){let a=!1;try{a=l.matches(":popover-open")}catch(e){}let h=!1;try{h=l.matches(":open")}catch(e){}return a||h}export function OverlayPopover(l){class a extends l{async manageDelay(e){if(e===!1||e!==this.open){u.close(this);return}this.delayed&&await u.openTimer(this)&&(this.open=!e)}async shouldHidePopover(e){if(e&&this.open!==e)return;const o=async({newState:i}={})=>{i!=="open"&&await this.placementController.resetOverlayPosition()};if(!v(this.dialogEl)){o();return}this.dialogEl.addEventListener("toggle",o,{once:!0})}async shouldShowPopover(e){let o=!1;try{o=this.dialogEl.matches(":popover-open")}catch(p){}let i=!1;try{i=this.dialogEl.matches(":open")}catch(p){}e&&this.open===e&&!o&&!i&&this.isConnected&&(this.dialogEl.showPopover(),await this.managePosition())}async ensureOnDOM(e){await d(),await this.shouldHidePopover(e),await this.shouldShowPopover(e),await d()}async makeTransition(e){if(this.open!==e)return null;let o=null;const i=(t,r)=>()=>{if(t.open=e,r===0){const s=e?P:w;this.dispatchEvent(new s)}if(!e||(t.matches(T)&&(o=t),o=o||E(t),o))return;t.querySelectorAll("slot").forEach(s=>{o||(o=y(s))})},p=(t,r)=>async()=>{if(this.open!==e)return;const n=e?"sp-opened":"sp-closed";if(r>0){t.dispatchEvent(new c(n,this,{interaction:this.type,publish:!1}));return}const s=async()=>{if(this.open!==e)return;await d();const m=this.triggerElement instanceof b;this.dispatchEvent(new c(n,this,{interaction:this.type,publish:m})),t.dispatchEvent(new c(n,this,{interaction:this.type,publish:!1})),this.triggerElement&&!m&&this.triggerElement.dispatchEvent(new c(n,this,{interaction:this.type,publish:!0})),this.state=e?"opened":"closed"};if(this.open!==e)return;const f=v(this.dialogEl);e!==!0&&f&&this.isConnected?(this.dialogEl.addEventListener("beforetoggle",()=>{s()},{once:!0}),this.dialogEl.hidePopover()):s()};return this.elements.forEach((t,r)=>{g(t,i(t,r),p(t,r))}),o}}return a}
|
|
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 type { SpectrumElement } from '@spectrum-web-components/base';\nimport { VirtualTrigger } from './VirtualTrigger.js';\nimport {
|
|
5
|
-
"mappings": "aAWA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DAEP,OAAS,kBAAAC,MAAsB,
|
|
6
|
-
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "VirtualTrigger", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedAllTransitionend", "nextFrame", "overlayTimer", "userFocusableSelector", "isOpen", "el", "popoverOpen", "error", "open", "constructor", "OverlayWithPopover", "targetOpenState", "update", "newState", "focusEl", "start", "index", "event", "slot", "finish", "eventName", "reportChange", "hasVirtualTrigger"]
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport {\n firstFocusableIn,\n firstFocusableSlottedIn,\n} from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport type { SpectrumElement } from '@spectrum-web-components/base';\nimport { VirtualTrigger } from './VirtualTrigger.js';\nimport { Constructor, OpenableElement } from './overlay-types.js';\nimport {\n BeforetoggleClosedEvent,\n BeforetoggleOpenEvent,\n guaranteedAllTransitionend,\n nextFrame,\n OverlayStateEvent,\n overlayTimer,\n} from './AbstractOverlay.js';\nimport type { AbstractOverlay } from './AbstractOverlay.js';\nimport { userFocusableSelector } from '@spectrum-web-components/shared';\n\nfunction isOpen(el: HTMLElement): boolean {\n let popoverOpen = false;\n try {\n popoverOpen = el.matches(':popover-open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n let open = false;\n try {\n open = el.matches(':open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n return popoverOpen || open;\n}\n\nexport function OverlayPopover<T extends Constructor<AbstractOverlay>>(\n constructor: T\n): T & Constructor<SpectrumElement> {\n class OverlayWithPopover extends constructor {\n protected override async manageDelay(\n targetOpenState: boolean\n ): Promise<void> {\n if (targetOpenState === false || targetOpenState !== this.open) {\n overlayTimer.close(this);\n return;\n }\n if (this.delayed) {\n const cancelled = await overlayTimer.openTimer(this);\n if (cancelled) {\n this.open = !targetOpenState;\n }\n }\n }\n\n /**\n * A popover should be hidden _after_ it is no longer on top-layer because\n * the position metrics will have changed from when it was originally positioned.\n */\n private async shouldHidePopover(\n targetOpenState: boolean\n ): Promise<void> {\n if (targetOpenState && this.open !== targetOpenState) {\n return;\n }\n const update = async ({\n newState,\n }: { newState?: string } = {}): Promise<void> => {\n if (newState === 'open') {\n return;\n }\n // When in a parent Overlay, this Overlay may need to position itself\n // while closing in due to the parent _also_ closing which means the\n // location can no longer rely on \"top layer over transform\" math.\n await this.placementController.resetOverlayPosition();\n };\n if (!isOpen(this.dialogEl)) {\n // The means the Overlay was closed from the outside, it is already off of top-layer\n // so we need to position it in regards to this new state.\n update();\n return;\n }\n // `toggle` is an async event, so it's possible for this handler to run a frame late\n this.dialogEl.addEventListener('toggle', update as EventListener, {\n once: true,\n });\n }\n\n private async shouldShowPopover(\n targetOpenState: boolean\n ): Promise<void> {\n let popoverOpen = false;\n try {\n popoverOpen = this.dialogEl.matches(':popover-open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n let open = false;\n try {\n open = this.dialogEl.matches(':open');\n // eslint-disable-next-line no-empty\n } catch (error) {}\n if (\n targetOpenState &&\n this.open === targetOpenState &&\n !popoverOpen &&\n !open &&\n this.isConnected\n ) {\n this.dialogEl.showPopover();\n await this.managePosition();\n }\n }\n\n protected override async ensureOnDOM(\n targetOpenState: boolean\n ): Promise<void> {\n await nextFrame();\n await this.shouldHidePopover(targetOpenState);\n await this.shouldShowPopover(targetOpenState);\n await nextFrame();\n }\n\n protected override async makeTransition(\n targetOpenState: boolean\n ): Promise<HTMLElement | null> {\n if (this.open !== targetOpenState) {\n return null;\n }\n let focusEl = null as HTMLElement | null;\n const start = (el: OpenableElement, index: number) => (): void => {\n el.open = targetOpenState;\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 if (el.matches(userFocusableSelector)) {\n focusEl = el;\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 OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: 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 OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: hasVirtualTrigger,\n })\n );\n el.dispatchEvent(\n new OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: false,\n })\n );\n if (this.triggerElement && !hasVirtualTrigger) {\n (this.triggerElement as HTMLElement).dispatchEvent(\n new OverlayStateEvent(eventName, this, {\n interaction: this.type,\n publish: true,\n })\n );\n }\n this.state = targetOpenState ? 'opened' : 'closed';\n };\n if (this.open !== targetOpenState) {\n return;\n }\n const open = isOpen(this.dialogEl);\n if (targetOpenState !== true && open && this.isConnected) {\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 guaranteedAllTransitionend(\n el,\n start(el, index),\n finish(el, index)\n );\n });\n return focusEl;\n }\n }\n return OverlayWithPopover;\n}\n"],
|
|
5
|
+
"mappings": "aAWA,OACI,oBAAAA,EACA,2BAAAC,MACG,4DAEP,OAAS,kBAAAC,MAAsB,sBAE/B,OACI,2BAAAC,EACA,yBAAAC,EACA,8BAAAC,EACA,aAAAC,EACA,qBAAAC,EACA,gBAAAC,MACG,uBAEP,OAAS,yBAAAC,MAA6B,kCAEtC,SAASC,EAAOC,EAA0B,CACtC,IAAIC,EAAc,GAClB,GAAI,CACAA,EAAcD,EAAG,QAAQ,eAAe,CAE5C,OAASE,EAAO,CAAC,CACjB,IAAIC,EAAO,GACX,GAAI,CACAA,EAAOH,EAAG,QAAQ,OAAO,CAE7B,OAASE,EAAO,CAAC,CACjB,OAAOD,GAAeE,CAC1B,CAEO,gBAAS,eACZC,EACgC,CAChC,MAAMC,UAA2BD,CAAY,CACzC,MAAyB,YACrBE,EACa,CACb,GAAIA,IAAoB,IAASA,IAAoB,KAAK,KAAM,CAC5DT,EAAa,MAAM,IAAI,EACvB,MACJ,CACI,KAAK,SACa,MAAMA,EAAa,UAAU,IAAI,IAE/C,KAAK,KAAO,CAACS,EAGzB,CAMA,MAAc,kBACVA,EACa,CACb,GAAIA,GAAmB,KAAK,OAASA,EACjC,OAEJ,MAAMC,EAAS,MAAO,CAClB,SAAAC,CACJ,EAA2B,CAAC,IAAqB,CACzCA,IAAa,QAMjB,MAAM,KAAK,oBAAoB,qBAAqB,CACxD,EACA,GAAI,CAACT,EA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S,EACb,CAAC,CACL,EACA,MACJ,CACA,MAAMC,EAAe,SAA2B,CAC5C,GAAI,KAAK,OAASV,EACd,OAEJ,MAAMX,EAAU,EAChB,MAAMsB,EACF,KAAK,0BAA0B1B,EACnC,KAAK,cACD,IAAIK,EAAkBmB,EAAW,KAAM,CACnC,YAAa,KAAK,KAClB,QAASE,CACb,CAAC,CACL,EACAjB,EAAG,cACC,IAAIJ,EAAkBmB,EAAW,KAAM,CACnC,YAAa,KAAK,KAClB,QAAS,EACb,CAAC,CACL,EACI,KAAK,gBAAkB,CAACE,GACvB,KAAK,eAA+B,cACjC,IAAIrB,EAAkBmB,EAAW,KAAM,CACnC,YAAa,KAAK,KAClB,QAAS,EACb,CAAC,CACL,EAEJ,KAAK,MAAQT,EAAkB,SAAW,QAC9C,EACA,GAAI,KAAK,OAASA,EACd,OAEJ,MAAMH,EAAOJ,EAAO,KAAK,QAAQ,EAC7BO,IAAoB,IAAQH,GAAQ,KAAK,aACzC,KAAK,SAAS,iBACV,eACA,IAAM,CACFa,EAAa,CACjB,EACA,CAAE,KAAM,EAAK,CACjB,EACA,KAAK,SAAS,YAAY,GAE1BA,EAAa,CAErB,EACJ,YAAK,SAAS,QAAQ,CAAChB,EAAIW,IAAU,CACjCjB,EACIM,EACAU,EAAMV,EAAIW,CAAK,EACfG,EAAOd,EAAIW,CAAK,CACpB,CACJ,CAAC,EACMF,CACX,CACJ,CACA,OAAOJ,CACX",
|
|
6
|
+
"names": ["firstFocusableIn", "firstFocusableSlottedIn", "VirtualTrigger", "BeforetoggleClosedEvent", "BeforetoggleOpenEvent", "guaranteedAllTransitionend", "nextFrame", "OverlayStateEvent", "overlayTimer", "userFocusableSelector", "isOpen", "el", "popoverOpen", "error", "open", "constructor", "OverlayWithPopover", "targetOpenState", "update", "newState", "focusEl", "start", "index", "event", "slot", "finish", "eventName", "reportChange", "hasVirtualTrigger"]
|
|
7
7
|
}
|