@spectrum-web-components/overlay 1.1.0-beta.9 → 1.1.1
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 +7 -7
- package/src/HoverController.d.ts +2 -0
- package/src/HoverController.dev.js +26 -2
- package/src/HoverController.dev.js.map +2 -2
- package/src/HoverController.js +1 -1
- package/src/HoverController.js.map +3 -3
- package/src/InteractionController.d.ts +11 -5
- package/src/InteractionController.dev.js +7 -3
- package/src/InteractionController.dev.js.map +2 -2
- package/src/InteractionController.js +1 -1
- package/src/InteractionController.js.map +2 -2
- package/src/Overlay.d.ts +349 -19
- package/src/Overlay.dev.js +276 -16
- package/src/Overlay.dev.js.map +2 -2
- package/src/Overlay.js +4 -4
- package/src/Overlay.js.map +3 -3
- package/src/OverlayDialog.dev.js +1 -0
- package/src/OverlayDialog.dev.js.map +2 -2
- package/src/OverlayDialog.js +1 -1
- package/src/OverlayDialog.js.map +2 -2
- package/src/OverlayPopover.dev.js +3 -3
- package/src/OverlayPopover.dev.js.map +2 -2
- package/src/OverlayPopover.js +1 -1
- package/src/OverlayPopover.js.map +2 -2
- package/src/OverlayStack.d.ts +2 -2
- package/src/OverlayStack.dev.js +8 -5
- package/src/OverlayStack.dev.js.map +2 -2
- package/src/OverlayStack.js +1 -1
- package/src/OverlayStack.js.map +3 -3
- package/src/PlacementController.d.ts +118 -1
- package/src/PlacementController.dev.js +75 -0
- package/src/PlacementController.dev.js.map +2 -2
- package/src/PlacementController.js.map +2 -2
- package/src/overlay-trigger.css.dev.js.map +1 -1
- package/src/overlay-trigger.css.js.map +1 -1
- package/src/overlay.css.dev.js.map +1 -1
- package/src/overlay.css.js.map +1 -1
- package/stories/index.js +9 -1
- package/stories/index.js.map +2 -2
- package/stories/overlay-directive.stories.js +16 -0
- package/stories/overlay-directive.stories.js.map +2 -2
- package/stories/overlay-element.stories.js +12 -0
- package/stories/overlay-element.stories.js.map +2 -2
- package/stories/overlay.stories.js +64 -49
- package/stories/overlay.stories.js.map +2 -2
- package/test/overlay-element.test.js +2 -4
- package/test/overlay-element.test.js.map +2 -2
- package/test/overlay-trigger-longpress.test.js +112 -130
- package/test/overlay-trigger-longpress.test.js.map +2 -2
- package/test/overlay.test.js +89 -0
- package/test/overlay.test.js.map +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/overlay",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -160,11 +160,11 @@
|
|
|
160
160
|
"dependencies": {
|
|
161
161
|
"@floating-ui/dom": "^1.6.1",
|
|
162
162
|
"@floating-ui/utils": "^0.2.1",
|
|
163
|
-
"@spectrum-web-components/action-button": "^1.1.
|
|
164
|
-
"@spectrum-web-components/base": "^1.1.
|
|
165
|
-
"@spectrum-web-components/reactive-controllers": "^1.1.
|
|
166
|
-
"@spectrum-web-components/shared": "^1.1.
|
|
167
|
-
"@spectrum-web-components/theme": "^1.1.
|
|
163
|
+
"@spectrum-web-components/action-button": "^1.1.1",
|
|
164
|
+
"@spectrum-web-components/base": "^1.1.1",
|
|
165
|
+
"@spectrum-web-components/reactive-controllers": "^1.1.1",
|
|
166
|
+
"@spectrum-web-components/shared": "^1.1.1",
|
|
167
|
+
"@spectrum-web-components/theme": "^1.1.1"
|
|
168
168
|
},
|
|
169
169
|
"types": "./src/index.d.ts",
|
|
170
170
|
"customElements": "custom-elements.json",
|
|
@@ -176,5 +176,5 @@
|
|
|
176
176
|
"./stories/overlay-story-components.js",
|
|
177
177
|
"./**/*.dev.js"
|
|
178
178
|
],
|
|
179
|
-
"gitHead": "
|
|
179
|
+
"gitHead": "44870aa95001c1b995456d994ae31bbe7277fac9"
|
|
180
180
|
}
|
package/src/HoverController.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare class HoverController extends InteractionController {
|
|
|
5
5
|
focusedin: boolean;
|
|
6
6
|
private hoverTimeout?;
|
|
7
7
|
pointerentered: boolean;
|
|
8
|
+
handleKeyup(event: KeyboardEvent): void;
|
|
8
9
|
handleTargetFocusin(): void;
|
|
9
10
|
handleTargetFocusout(): void;
|
|
10
11
|
handleTargetPointerenter(): void;
|
|
@@ -17,4 +18,5 @@ export declare class HoverController extends InteractionController {
|
|
|
17
18
|
protected doPointerleave(): void;
|
|
18
19
|
init(): void;
|
|
19
20
|
initOverlay(): void;
|
|
21
|
+
private removeSafariFocusRingClass;
|
|
20
22
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { conditionAttributeWithId } from "@spectrum-web-components/base/src/condition-attribute-with-id.js";
|
|
3
|
+
import { isWebKit } from "@spectrum-web-components/shared";
|
|
3
4
|
import { randomID } from "@spectrum-web-components/shared/src/random-id.js";
|
|
5
|
+
import { noop } from "./AbstractOverlay.dev.js";
|
|
4
6
|
import {
|
|
5
7
|
InteractionController,
|
|
6
|
-
InteractionTypes
|
|
8
|
+
InteractionTypes,
|
|
9
|
+
lastInteractionType,
|
|
10
|
+
SAFARI_FOCUS_RING_CLASS
|
|
7
11
|
} from "./InteractionController.dev.js";
|
|
8
|
-
import { noop } from "./AbstractOverlay.dev.js";
|
|
9
12
|
const HOVER_DELAY = 300;
|
|
10
13
|
export class HoverController extends InteractionController {
|
|
11
14
|
constructor() {
|
|
@@ -15,14 +18,26 @@ export class HoverController extends InteractionController {
|
|
|
15
18
|
this.focusedin = false;
|
|
16
19
|
this.pointerentered = false;
|
|
17
20
|
}
|
|
21
|
+
handleKeyup(event) {
|
|
22
|
+
if (event.code === "Tab" || event.code === "Escape") {
|
|
23
|
+
this.open = true;
|
|
24
|
+
this.removeSafariFocusRingClass();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
18
27
|
handleTargetFocusin() {
|
|
19
28
|
if (!this.target.matches(":focus-visible")) {
|
|
20
29
|
return;
|
|
21
30
|
}
|
|
31
|
+
if (isWebKit() && this.target[lastInteractionType] === InteractionTypes.click) {
|
|
32
|
+
this.target.classList.add(SAFARI_FOCUS_RING_CLASS);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
22
35
|
this.open = true;
|
|
23
36
|
this.focusedin = true;
|
|
37
|
+
this.removeSafariFocusRingClass();
|
|
24
38
|
}
|
|
25
39
|
handleTargetFocusout() {
|
|
40
|
+
this.removeSafariFocusRingClass();
|
|
26
41
|
this.focusedin = false;
|
|
27
42
|
if (this.pointerentered) return;
|
|
28
43
|
this.open = false;
|
|
@@ -109,6 +124,11 @@ export class HoverController extends InteractionController {
|
|
|
109
124
|
(_a = this.abortController) == null ? void 0 : _a.abort();
|
|
110
125
|
this.abortController = new AbortController();
|
|
111
126
|
const { signal } = this.abortController;
|
|
127
|
+
this.target.addEventListener(
|
|
128
|
+
"keyup",
|
|
129
|
+
(event) => this.handleKeyup(event),
|
|
130
|
+
{ signal }
|
|
131
|
+
);
|
|
112
132
|
this.target.addEventListener(
|
|
113
133
|
"focusin",
|
|
114
134
|
() => this.handleTargetFocusin(),
|
|
@@ -149,5 +169,9 @@ export class HoverController extends InteractionController {
|
|
|
149
169
|
{ signal }
|
|
150
170
|
);
|
|
151
171
|
}
|
|
172
|
+
removeSafariFocusRingClass() {
|
|
173
|
+
if (isWebKit() && this.target.classList.contains(SAFARI_FOCUS_RING_CLASS))
|
|
174
|
+
this.target.classList.remove(SAFARI_FOCUS_RING_CLASS);
|
|
175
|
+
}
|
|
152
176
|
}
|
|
153
177
|
//# sourceMappingURL=HoverController.dev.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["HoverController.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2024 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { conditionAttributeWithId } from '@spectrum-web-components/base/src/condition-attribute-with-id.js';\nimport { randomID } from '@spectrum-web-components/shared/src/random-id.js';\
|
|
5
|
-
"mappings": ";AAYA,SAAS,gCAAgC;AACzC,SAAS,gBAAgB;
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2024 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { conditionAttributeWithId } from '@spectrum-web-components/base/src/condition-attribute-with-id.js';\nimport { isWebKit } from '@spectrum-web-components/shared';\nimport { randomID } from '@spectrum-web-components/shared/src/random-id.js';\nimport { noop } from './AbstractOverlay.dev.js'\nimport {\n InteractionController,\n InteractionTypes,\n lastInteractionType,\n SAFARI_FOCUS_RING_CLASS,\n} from './InteractionController.dev.js'\n\nconst HOVER_DELAY = 300;\n\nexport class HoverController extends InteractionController {\n override type = InteractionTypes.hover;\n\n private elementIds: string[] = [];\n\n focusedin = false;\n\n private hoverTimeout?: ReturnType<typeof setTimeout>;\n\n pointerentered = false;\n\n handleKeyup(event: KeyboardEvent): void {\n if (event.code === 'Tab' || event.code === 'Escape') {\n this.open = true;\n this.removeSafariFocusRingClass();\n }\n }\n\n handleTargetFocusin(): void {\n if (!this.target.matches(':focus-visible')) {\n return;\n }\n\n if (\n isWebKit() &&\n this.target[lastInteractionType] === InteractionTypes.click\n ) {\n this.target.classList.add(SAFARI_FOCUS_RING_CLASS);\n return;\n }\n\n this.open = true;\n this.focusedin = true;\n this.removeSafariFocusRingClass();\n }\n\n handleTargetFocusout(): void {\n this.removeSafariFocusRingClass();\n this.focusedin = false;\n if (this.pointerentered) return;\n this.open = false;\n }\n\n handleTargetPointerenter(): void {\n if (this.hoverTimeout) {\n clearTimeout(this.hoverTimeout);\n this.hoverTimeout = undefined;\n }\n if (this.overlay?.disabled) return;\n this.open = true;\n this.pointerentered = true;\n }\n\n handleTargetPointerleave(): void {\n this.doPointerleave();\n }\n\n // set a timeout once the pointer enters and the overlay is shown\n // give the user time to enter the overlay\n handleHostPointerenter(): void {\n if (this.hoverTimeout) {\n clearTimeout(this.hoverTimeout);\n this.hoverTimeout = undefined;\n }\n }\n\n handleHostPointerleave(): void {\n this.doPointerleave();\n }\n\n override prepareDescription(): void {\n // require \"content\" to apply relationship\n if (!this.overlay.elements.length) return;\n\n const triggerRoot = this.target.getRootNode();\n const contentRoot = this.overlay.elements[0].getRootNode();\n const overlayRoot = this.overlay.getRootNode();\n if (triggerRoot === overlayRoot) {\n this.prepareOverlayRelativeDescription();\n } else if (triggerRoot === contentRoot) {\n this.prepareContentRelativeDescription();\n }\n }\n\n private prepareOverlayRelativeDescription(): void {\n const releaseDescription = conditionAttributeWithId(\n this.target,\n 'aria-describedby',\n [this.overlay.id]\n );\n this.releaseDescription = () => {\n releaseDescription();\n this.releaseDescription = noop;\n };\n }\n\n private prepareContentRelativeDescription(): void {\n const elementIds: string[] = [];\n const appliedIds = this.overlay.elements.map((el) => {\n elementIds.push(el.id);\n if (!el.id) {\n el.id = `${this.overlay.tagName.toLowerCase()}-helper-${randomID()}`;\n }\n return el.id;\n });\n this.elementIds = elementIds;\n const releaseDescription = conditionAttributeWithId(\n this.target,\n 'aria-describedby',\n appliedIds\n );\n this.releaseDescription = () => {\n releaseDescription();\n this.overlay.elements.map((el, index) => {\n el.id = this.elementIds[index];\n });\n this.releaseDescription = noop;\n };\n }\n\n protected doPointerleave(): void {\n this.pointerentered = false;\n const triggerElement = this.target as HTMLElement;\n if (this.focusedin && triggerElement.matches(':focus-visible')) return;\n\n this.hoverTimeout = setTimeout(() => {\n this.open = false;\n }, HOVER_DELAY);\n }\n\n override init(): void {\n // Clean up listeners if they've already been bound\n this.abortController?.abort();\n this.abortController = new AbortController();\n const { signal } = this.abortController;\n this.target.addEventListener(\n 'keyup',\n (event) => this.handleKeyup(event),\n { signal }\n );\n this.target.addEventListener(\n 'focusin',\n () => this.handleTargetFocusin(),\n { signal }\n );\n this.target.addEventListener(\n 'focusout',\n () => this.handleTargetFocusout(),\n { signal }\n );\n this.target.addEventListener(\n 'pointerenter',\n () => this.handleTargetPointerenter(),\n { signal }\n );\n this.target.addEventListener(\n 'pointerleave',\n () => this.handleTargetPointerleave(),\n { signal }\n );\n if (this.overlay) {\n this.initOverlay();\n }\n }\n\n override initOverlay(): void {\n if (!this.abortController) {\n return;\n }\n const { signal } = this.abortController;\n this.overlay.addEventListener(\n 'pointerenter',\n () => this.handleHostPointerenter(),\n { signal }\n );\n this.overlay.addEventListener(\n 'pointerleave',\n () => this.handleHostPointerleave(),\n { signal }\n );\n }\n\n private removeSafariFocusRingClass(): void {\n if (\n isWebKit() &&\n this.target.classList.contains(SAFARI_FOCUS_RING_CLASS)\n )\n this.target.classList.remove(SAFARI_FOCUS_RING_CLASS);\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,gCAAgC;AACzC,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,YAAY;AACrB;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,MAAM,cAAc;AAEb,aAAM,wBAAwB,sBAAsB;AAAA,EAApD;AAAA;AACH,SAAS,OAAO,iBAAiB;AAEjC,SAAQ,aAAuB,CAAC;AAEhC,qBAAY;AAIZ,0BAAiB;AAAA;AAAA,EAEjB,YAAY,OAA4B;AACpC,QAAI,MAAM,SAAS,SAAS,MAAM,SAAS,UAAU;A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,oBAAoB;AAAA,MAC/B,EAAE,OAAO;AAAA,IACb;AACA,SAAK,OAAO;AAAA,MACR;AAAA,MACA,MAAM,KAAK,qBAAqB;AAAA,MAChC,EAAE,OAAO;AAAA,IACb;AACA,SAAK,OAAO;AAAA,MACR;AAAA,MACA,MAAM,KAAK,yBAAyB;AAAA,MACpC,EAAE,OAAO;AAAA,IACb;AACA,SAAK,OAAO;AAAA,MACR;AAAA,MACA,MAAM,KAAK,yBAAyB;AAAA,MACpC,EAAE,OAAO;AAAA,IACb;AACA,QAAI,KAAK,SAAS;AACd,WAAK,YAAY;AAAA,IACrB;AAAA,EACJ;AAAA,EAES,cAAoB;AACzB,QAAI,CAAC,KAAK,iBAAiB;AACvB;AAAA,IACJ;AACA,UAAM,EAAE,OAAO,IAAI,KAAK;AACxB,SAAK,QAAQ;AAAA,MACT;AAAA,MACA,MAAM,KAAK,uBAAuB;AAAA,MAClC,EAAE,OAAO;AAAA,IACb;AACA,SAAK,QAAQ;AAAA,MACT;AAAA,MACA,MAAM,KAAK,uBAAuB;AAAA,MAClC,EAAE,OAAO;AAAA,IACb;AAAA,EACJ;AAAA,EAEQ,6BAAmC;AACvC,QACI,SAAS,KACT,KAAK,OAAO,UAAU,SAAS,uBAAuB;AAEtD,WAAK,OAAO,UAAU,OAAO,uBAAuB;AAAA,EAC5D;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/HoverController.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";import{conditionAttributeWithId as
|
|
1
|
+
"use strict";import{conditionAttributeWithId as s}from"@spectrum-web-components/base/src/condition-attribute-with-id.js";import{isWebKit as n}from"@spectrum-web-components/shared";import{randomID as d}from"@spectrum-web-components/shared/src/random-id.js";import{noop as a}from"./AbstractOverlay.js";import{InteractionController as v,InteractionTypes as l,lastInteractionType as p,SAFARI_FOCUS_RING_CLASS as o}from"./InteractionController.js";const c=300;export class HoverController extends v{constructor(){super(...arguments);this.type=l.hover;this.elementIds=[];this.focusedin=!1;this.pointerentered=!1}handleKeyup(e){(e.code==="Tab"||e.code==="Escape")&&(this.open=!0,this.removeSafariFocusRingClass())}handleTargetFocusin(){if(this.target.matches(":focus-visible")){if(n()&&this.target[p]===l.click){this.target.classList.add(o);return}this.open=!0,this.focusedin=!0,this.removeSafariFocusRingClass()}}handleTargetFocusout(){this.removeSafariFocusRingClass(),this.focusedin=!1,!this.pointerentered&&(this.open=!1)}handleTargetPointerenter(){var e;this.hoverTimeout&&(clearTimeout(this.hoverTimeout),this.hoverTimeout=void 0),!((e=this.overlay)!=null&&e.disabled)&&(this.open=!0,this.pointerentered=!0)}handleTargetPointerleave(){this.doPointerleave()}handleHostPointerenter(){this.hoverTimeout&&(clearTimeout(this.hoverTimeout),this.hoverTimeout=void 0)}handleHostPointerleave(){this.doPointerleave()}prepareDescription(){if(!this.overlay.elements.length)return;const e=this.target.getRootNode(),t=this.overlay.elements[0].getRootNode(),r=this.overlay.getRootNode();e===r?this.prepareOverlayRelativeDescription():e===t&&this.prepareContentRelativeDescription()}prepareOverlayRelativeDescription(){const e=s(this.target,"aria-describedby",[this.overlay.id]);this.releaseDescription=()=>{e(),this.releaseDescription=a}}prepareContentRelativeDescription(){const e=[],t=this.overlay.elements.map(i=>(e.push(i.id),i.id||(i.id=`${this.overlay.tagName.toLowerCase()}-helper-${d()}`),i.id));this.elementIds=e;const r=s(this.target,"aria-describedby",t);this.releaseDescription=()=>{r(),this.overlay.elements.map((i,h)=>{i.id=this.elementIds[h]}),this.releaseDescription=a}}doPointerleave(){this.pointerentered=!1;const e=this.target;this.focusedin&&e.matches(":focus-visible")||(this.hoverTimeout=setTimeout(()=>{this.open=!1},c))}init(){var t;(t=this.abortController)==null||t.abort(),this.abortController=new AbortController;const{signal:e}=this.abortController;this.target.addEventListener("keyup",r=>this.handleKeyup(r),{signal:e}),this.target.addEventListener("focusin",()=>this.handleTargetFocusin(),{signal:e}),this.target.addEventListener("focusout",()=>this.handleTargetFocusout(),{signal:e}),this.target.addEventListener("pointerenter",()=>this.handleTargetPointerenter(),{signal:e}),this.target.addEventListener("pointerleave",()=>this.handleTargetPointerleave(),{signal:e}),this.overlay&&this.initOverlay()}initOverlay(){if(!this.abortController)return;const{signal:e}=this.abortController;this.overlay.addEventListener("pointerenter",()=>this.handleHostPointerenter(),{signal:e}),this.overlay.addEventListener("pointerleave",()=>this.handleHostPointerleave(),{signal:e})}removeSafariFocusRingClass(){n()&&this.target.classList.contains(o)&&this.target.classList.remove(o)}}
|
|
2
2
|
//# sourceMappingURL=HoverController.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["HoverController.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2024 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { conditionAttributeWithId } from '@spectrum-web-components/base/src/condition-attribute-with-id.js';\nimport { randomID } from '@spectrum-web-components/shared/src/random-id.js';\
|
|
5
|
-
"mappings": "aAYA,OAAS,4BAAAA,MAAgC,mEACzC,OAAS,YAAAC,MAAgB,
|
|
6
|
-
"names": ["conditionAttributeWithId", "randomID", "InteractionController", "InteractionTypes", "
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2024 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { conditionAttributeWithId } from '@spectrum-web-components/base/src/condition-attribute-with-id.js';\nimport { isWebKit } from '@spectrum-web-components/shared';\nimport { randomID } from '@spectrum-web-components/shared/src/random-id.js';\nimport { noop } from './AbstractOverlay.js';\nimport {\n InteractionController,\n InteractionTypes,\n lastInteractionType,\n SAFARI_FOCUS_RING_CLASS,\n} from './InteractionController.js';\n\nconst HOVER_DELAY = 300;\n\nexport class HoverController extends InteractionController {\n override type = InteractionTypes.hover;\n\n private elementIds: string[] = [];\n\n focusedin = false;\n\n private hoverTimeout?: ReturnType<typeof setTimeout>;\n\n pointerentered = false;\n\n handleKeyup(event: KeyboardEvent): void {\n if (event.code === 'Tab' || event.code === 'Escape') {\n this.open = true;\n this.removeSafariFocusRingClass();\n }\n }\n\n handleTargetFocusin(): void {\n if (!this.target.matches(':focus-visible')) {\n return;\n }\n\n if (\n isWebKit() &&\n this.target[lastInteractionType] === InteractionTypes.click\n ) {\n this.target.classList.add(SAFARI_FOCUS_RING_CLASS);\n return;\n }\n\n this.open = true;\n this.focusedin = true;\n this.removeSafariFocusRingClass();\n }\n\n handleTargetFocusout(): void {\n this.removeSafariFocusRingClass();\n this.focusedin = false;\n if (this.pointerentered) return;\n this.open = false;\n }\n\n handleTargetPointerenter(): void {\n if (this.hoverTimeout) {\n clearTimeout(this.hoverTimeout);\n this.hoverTimeout = undefined;\n }\n if (this.overlay?.disabled) return;\n this.open = true;\n this.pointerentered = true;\n }\n\n handleTargetPointerleave(): void {\n this.doPointerleave();\n }\n\n // set a timeout once the pointer enters and the overlay is shown\n // give the user time to enter the overlay\n handleHostPointerenter(): void {\n if (this.hoverTimeout) {\n clearTimeout(this.hoverTimeout);\n this.hoverTimeout = undefined;\n }\n }\n\n handleHostPointerleave(): void {\n this.doPointerleave();\n }\n\n override prepareDescription(): void {\n // require \"content\" to apply relationship\n if (!this.overlay.elements.length) return;\n\n const triggerRoot = this.target.getRootNode();\n const contentRoot = this.overlay.elements[0].getRootNode();\n const overlayRoot = this.overlay.getRootNode();\n if (triggerRoot === overlayRoot) {\n this.prepareOverlayRelativeDescription();\n } else if (triggerRoot === contentRoot) {\n this.prepareContentRelativeDescription();\n }\n }\n\n private prepareOverlayRelativeDescription(): void {\n const releaseDescription = conditionAttributeWithId(\n this.target,\n 'aria-describedby',\n [this.overlay.id]\n );\n this.releaseDescription = () => {\n releaseDescription();\n this.releaseDescription = noop;\n };\n }\n\n private prepareContentRelativeDescription(): void {\n const elementIds: string[] = [];\n const appliedIds = this.overlay.elements.map((el) => {\n elementIds.push(el.id);\n if (!el.id) {\n el.id = `${this.overlay.tagName.toLowerCase()}-helper-${randomID()}`;\n }\n return el.id;\n });\n this.elementIds = elementIds;\n const releaseDescription = conditionAttributeWithId(\n this.target,\n 'aria-describedby',\n appliedIds\n );\n this.releaseDescription = () => {\n releaseDescription();\n this.overlay.elements.map((el, index) => {\n el.id = this.elementIds[index];\n });\n this.releaseDescription = noop;\n };\n }\n\n protected doPointerleave(): void {\n this.pointerentered = false;\n const triggerElement = this.target as HTMLElement;\n if (this.focusedin && triggerElement.matches(':focus-visible')) return;\n\n this.hoverTimeout = setTimeout(() => {\n this.open = false;\n }, HOVER_DELAY);\n }\n\n override init(): void {\n // Clean up listeners if they've already been bound\n this.abortController?.abort();\n this.abortController = new AbortController();\n const { signal } = this.abortController;\n this.target.addEventListener(\n 'keyup',\n (event) => this.handleKeyup(event),\n { signal }\n );\n this.target.addEventListener(\n 'focusin',\n () => this.handleTargetFocusin(),\n { signal }\n );\n this.target.addEventListener(\n 'focusout',\n () => this.handleTargetFocusout(),\n { signal }\n );\n this.target.addEventListener(\n 'pointerenter',\n () => this.handleTargetPointerenter(),\n { signal }\n );\n this.target.addEventListener(\n 'pointerleave',\n () => this.handleTargetPointerleave(),\n { signal }\n );\n if (this.overlay) {\n this.initOverlay();\n }\n }\n\n override initOverlay(): void {\n if (!this.abortController) {\n return;\n }\n const { signal } = this.abortController;\n this.overlay.addEventListener(\n 'pointerenter',\n () => this.handleHostPointerenter(),\n { signal }\n );\n this.overlay.addEventListener(\n 'pointerleave',\n () => this.handleHostPointerleave(),\n { signal }\n );\n }\n\n private removeSafariFocusRingClass(): void {\n if (\n isWebKit() &&\n this.target.classList.contains(SAFARI_FOCUS_RING_CLASS)\n )\n this.target.classList.remove(SAFARI_FOCUS_RING_CLASS);\n }\n}\n"],
|
|
5
|
+
"mappings": "aAYA,OAAS,4BAAAA,MAAgC,mEACzC,OAAS,YAAAC,MAAgB,kCACzB,OAAS,YAAAC,MAAgB,mDACzB,OAAS,QAAAC,MAAY,uBACrB,OACI,yBAAAC,EACA,oBAAAC,EACA,uBAAAC,EACA,2BAAAC,MACG,6BAEP,MAAMC,EAAc,IAEb,aAAM,wBAAwBJ,CAAsB,CAApD,kCACH,KAAS,KAAOC,EAAiB,MAEjC,KAAQ,WAAuB,CAAC,EAEhC,eAAY,GAIZ,oBAAiB,GAEjB,YAAYI,EAA4B,EAChCA,EAAM,OAAS,OAASA,EAAM,OAAS,YACvC,KAAK,KAAO,GACZ,KAAK,2BAA2B,EAExC,CAEA,qBAA4B,CACxB,GAAK,KAAK,OAAO,QAAQ,gBAAgB,EAIzC,IACIR,EAAS,GACT,KAAK,OAAOK,CAAmB,IAAMD,EAAiB,MACxD,CACE,KAAK,OAAO,UAAU,IAAIE,CAAuB,EACjD,MACJ,CAEA,KAAK,KAAO,GACZ,KAAK,UAAY,GACjB,KAAK,2BAA2B,EACpC,CAEA,sBAA6B,CACzB,KAAK,2BAA2B,EAChC,KAAK,UAAY,GACb,MAAK,iBACT,KAAK,KAAO,GAChB,CAEA,0BAAiC,CApErC,IAAAG,EAqEY,KAAK,eACL,aAAa,KAAK,YAAY,EAC9B,KAAK,aAAe,QAEpB,GAAAA,EAAA,KAAK,UAAL,MAAAA,EAAc,YAClB,KAAK,KAAO,GACZ,KAAK,eAAiB,GAC1B,CAEA,0BAAiC,CAC7B,KAAK,eA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JQA,EAAA,KAAK,kBAAL,MAAAA,EAAsB,QACtB,KAAK,gBAAkB,IAAI,gBAC3B,KAAM,CAAE,OAAAU,CAAO,EAAI,KAAK,gBACxB,KAAK,OAAO,iBACR,QACCX,GAAU,KAAK,YAAYA,CAAK,EACjC,CAAE,OAAAW,CAAO,CACb,EACA,KAAK,OAAO,iBACR,UACA,IAAM,KAAK,oBAAoB,EAC/B,CAAE,OAAAA,CAAO,CACb,EACA,KAAK,OAAO,iBACR,WACA,IAAM,KAAK,qBAAqB,EAChC,CAAE,OAAAA,CAAO,CACb,EACA,KAAK,OAAO,iBACR,eACA,IAAM,KAAK,yBAAyB,EACpC,CAAE,OAAAA,CAAO,CACb,EACA,KAAK,OAAO,iBACR,eACA,IAAM,KAAK,yBAAyB,EACpC,CAAE,OAAAA,CAAO,CACb,EACI,KAAK,SACL,KAAK,YAAY,CAEzB,CAES,aAAoB,CACzB,GAAI,CAAC,KAAK,gBACN,OAEJ,KAAM,CAAE,OAAAA,CAAO,EAAI,KAAK,gBACxB,KAAK,QAAQ,iBACT,eACA,IAAM,KAAK,uBAAuB,EAClC,CAAE,OAAAA,CAAO,CACb,EACA,KAAK,QAAQ,iBACT,eACA,IAAM,KAAK,uBAAuB,EAClC,CAAE,OAAAA,CAAO,CACb,CACJ,CAEQ,4BAAmC,CAEnCnB,EAAS,GACT,KAAK,OAAO,UAAU,SAASM,CAAuB,GAEtD,KAAK,OAAO,UAAU,OAAOA,CAAuB,CAC5D,CACJ",
|
|
6
|
+
"names": ["conditionAttributeWithId", "isWebKit", "randomID", "noop", "InteractionController", "InteractionTypes", "lastInteractionType", "SAFARI_FOCUS_RING_CLASS", "HOVER_DELAY", "event", "_a", "triggerRoot", "contentRoot", "overlayRoot", "releaseDescription", "elementIds", "appliedIds", "el", "index", "triggerElement", "signal"]
|
|
7
7
|
}
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import type { ReactiveController } from '@spectrum-web-components/base';
|
|
2
2
|
import { AbstractOverlay } from './AbstractOverlay.js';
|
|
3
3
|
export declare enum InteractionTypes {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
click = "click",
|
|
5
|
+
hover = "hover",
|
|
6
|
+
longpress = "longpress"
|
|
7
7
|
}
|
|
8
|
+
export declare const lastInteractionType: unique symbol;
|
|
9
|
+
export declare const SAFARI_FOCUS_RING_CLASS = "remove-focus-ring-safari-hack";
|
|
8
10
|
export type ControllerOptions = {
|
|
9
11
|
overlay?: AbstractOverlay;
|
|
10
12
|
handleOverlayReady?: (overlay: AbstractOverlay) => void;
|
|
11
13
|
isPersistent?: boolean;
|
|
12
14
|
};
|
|
15
|
+
type InteractionTarget = HTMLElement & {
|
|
16
|
+
[lastInteractionType]?: InteractionTypes;
|
|
17
|
+
};
|
|
13
18
|
export declare class InteractionController implements ReactiveController {
|
|
14
|
-
target:
|
|
19
|
+
target: InteractionTarget;
|
|
15
20
|
abortController: AbortController;
|
|
16
21
|
get activelyOpening(): boolean;
|
|
17
22
|
private handleOverlayReady?;
|
|
@@ -26,7 +31,7 @@ export declare class InteractionController implements ReactiveController {
|
|
|
26
31
|
private _overlay;
|
|
27
32
|
protected isPersistent: boolean;
|
|
28
33
|
type: InteractionTypes;
|
|
29
|
-
constructor(target:
|
|
34
|
+
constructor(target: InteractionTarget, { overlay, isPersistent, handleOverlayReady }: ControllerOptions);
|
|
30
35
|
prepareDescription(_: HTMLElement): void;
|
|
31
36
|
releaseDescription(): void;
|
|
32
37
|
shouldCompleteOpen(): void;
|
|
@@ -36,3 +41,4 @@ export declare class InteractionController implements ReactiveController {
|
|
|
36
41
|
hostConnected(): void;
|
|
37
42
|
hostDisconnected(): void;
|
|
38
43
|
}
|
|
44
|
+
export {};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
export var InteractionTypes = /* @__PURE__ */ ((InteractionTypes2) => {
|
|
3
|
-
InteractionTypes2[
|
|
4
|
-
InteractionTypes2[
|
|
5
|
-
InteractionTypes2[
|
|
3
|
+
InteractionTypes2["click"] = "click";
|
|
4
|
+
InteractionTypes2["hover"] = "hover";
|
|
5
|
+
InteractionTypes2["longpress"] = "longpress";
|
|
6
6
|
return InteractionTypes2;
|
|
7
7
|
})(InteractionTypes || {});
|
|
8
|
+
export const lastInteractionType = Symbol("lastInteractionType");
|
|
9
|
+
export const SAFARI_FOCUS_RING_CLASS = "remove-focus-ring-safari-hack";
|
|
8
10
|
export class InteractionController {
|
|
9
11
|
constructor(target, { overlay, isPersistent, handleOverlayReady }) {
|
|
10
12
|
this.target = target;
|
|
@@ -33,6 +35,7 @@ export class InteractionController {
|
|
|
33
35
|
this.isLazilyOpen = open;
|
|
34
36
|
if (this.overlay) {
|
|
35
37
|
this.overlay.open = open;
|
|
38
|
+
this.target[lastInteractionType] = this.type;
|
|
36
39
|
return;
|
|
37
40
|
}
|
|
38
41
|
if (!open) {
|
|
@@ -42,6 +45,7 @@ export class InteractionController {
|
|
|
42
45
|
const { Overlay } = await import("./Overlay.dev.js");
|
|
43
46
|
this.overlay = new Overlay();
|
|
44
47
|
this.overlay.open = true;
|
|
48
|
+
this.target[lastInteractionType] = this.type;
|
|
45
49
|
});
|
|
46
50
|
import("@spectrum-web-components/overlay/sp-overlay.js");
|
|
47
51
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["InteractionController.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2024 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { ReactiveController } from '@spectrum-web-components/base';\nimport { AbstractOverlay } from './AbstractOverlay.dev.js'\n\nexport enum InteractionTypes {\n 'click',\n 'hover',\n 'longpress',\n}\n\nexport type ControllerOptions = {\n overlay?: AbstractOverlay;\n handleOverlayReady?: (overlay: AbstractOverlay) => void;\n isPersistent?: boolean;\n};\n\nexport class InteractionController implements ReactiveController {\n abortController!: AbortController;\n\n get activelyOpening(): boolean {\n return false;\n }\n\n private handleOverlayReady?: (overlay: AbstractOverlay) => void;\n\n // Holds optimistic open state when an Overlay is not yet present\n private isLazilyOpen = false;\n\n public get open(): boolean {\n return this.overlay?.open ?? this.isLazilyOpen;\n }\n\n /**\n * Set `open` against the associated Overlay lazily.\n */\n public set open(open: boolean) {\n if (open === this.open) return;\n this.isLazilyOpen = open;\n if (this.overlay) {\n // If there already is an Overlay, apply the value of `open` directly.\n this.overlay.open = open;\n return;\n }\n if (!open) {\n // When `open` moves to `false` and there is not yet an Overlay,\n // assume that no Overlay and a closed Overlay are the same and return early.\n return;\n }\n // When there is no Overlay and `open` is moving to `true`, lazily import/create\n // an Overlay and apply that state to it.\n customElements\n .whenDefined('sp-overlay')\n .then(async (): Promise<void> => {\n const { Overlay } = await import('./Overlay.dev.js');\n this.overlay = new Overlay();\n this.overlay.open = true;\n });\n import('@spectrum-web-components/overlay/sp-overlay.js');\n }\n\n public get overlay(): AbstractOverlay {\n return this._overlay;\n }\n\n public set overlay(overlay: AbstractOverlay | undefined) {\n if (!overlay) return;\n if (this.overlay === overlay) return;\n if (this.overlay) {\n this.overlay.removeController(this);\n }\n this._overlay = overlay;\n this.overlay.addController(this);\n this.initOverlay();\n this.prepareDescription(this.target);\n this.handleOverlayReady?.(this.overlay);\n }\n\n private _overlay!: AbstractOverlay;\n\n protected isPersistent = false;\n\n type!: InteractionTypes;\n\n constructor(\n public target:
|
|
5
|
-
"mappings": ";AAeO,WAAK,mBAAL,kBAAKA,sBAAL;AACH,EAAAA,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2024 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { ReactiveController } from '@spectrum-web-components/base';\nimport { AbstractOverlay } from './AbstractOverlay.dev.js'\n\nexport enum InteractionTypes {\n click = 'click',\n hover = 'hover',\n longpress = 'longpress',\n}\n\nexport const lastInteractionType = Symbol('lastInteractionType');\nexport const SAFARI_FOCUS_RING_CLASS = 'remove-focus-ring-safari-hack';\n\nexport type ControllerOptions = {\n overlay?: AbstractOverlay;\n handleOverlayReady?: (overlay: AbstractOverlay) => void;\n isPersistent?: boolean;\n};\n\ntype InteractionTarget = HTMLElement & {\n [lastInteractionType]?: InteractionTypes;\n};\n\nexport class InteractionController implements ReactiveController {\n abortController!: AbortController;\n\n get activelyOpening(): boolean {\n return false;\n }\n\n private handleOverlayReady?: (overlay: AbstractOverlay) => void;\n\n // Holds optimistic open state when an Overlay is not yet present\n private isLazilyOpen = false;\n\n public get open(): boolean {\n return this.overlay?.open ?? this.isLazilyOpen;\n }\n\n /**\n * Set `open` against the associated Overlay lazily.\n */\n public set open(open: boolean) {\n if (open === this.open) return;\n this.isLazilyOpen = open;\n if (this.overlay) {\n // If there already is an Overlay, apply the value of `open` directly.\n this.overlay.open = open;\n this.target[lastInteractionType] = this.type;\n return;\n }\n if (!open) {\n // When `open` moves to `false` and there is not yet an Overlay,\n // assume that no Overlay and a closed Overlay are the same and return early.\n return;\n }\n // When there is no Overlay and `open` is moving to `true`, lazily import/create\n // an Overlay and apply that state to it.\n customElements\n .whenDefined('sp-overlay')\n .then(async (): Promise<void> => {\n const { Overlay } = await import('./Overlay.dev.js');\n this.overlay = new Overlay();\n this.overlay.open = true;\n this.target[lastInteractionType] = this.type;\n });\n import('@spectrum-web-components/overlay/sp-overlay.js');\n }\n\n public get overlay(): AbstractOverlay {\n return this._overlay;\n }\n\n public set overlay(overlay: AbstractOverlay | undefined) {\n if (!overlay) return;\n if (this.overlay === overlay) return;\n if (this.overlay) {\n this.overlay.removeController(this);\n }\n this._overlay = overlay;\n this.overlay.addController(this);\n this.initOverlay();\n this.prepareDescription(this.target);\n this.handleOverlayReady?.(this.overlay);\n }\n\n private _overlay!: AbstractOverlay;\n\n protected isPersistent = false;\n\n type!: InteractionTypes;\n\n constructor(\n public target: InteractionTarget,\n { overlay, isPersistent, handleOverlayReady }: ControllerOptions\n ) {\n this.isPersistent = !!isPersistent;\n this.handleOverlayReady = handleOverlayReady;\n if (this.isPersistent) {\n this.init();\n }\n this.overlay = overlay;\n }\n\n prepareDescription(_: HTMLElement): void {}\n\n releaseDescription(): void {}\n\n shouldCompleteOpen(): void {}\n\n /* c8 ignore next 3 */\n init(): void {\n // Abstract init() method.\n }\n\n /* c8 ignore next 3 */\n initOverlay(): void {\n // Abstract initOverlay() method.\n }\n\n abort(): void {\n this.releaseDescription();\n this.abortController?.abort();\n }\n\n hostConnected(): void {\n this.init();\n }\n\n hostDisconnected(): void {\n if (!this.isPersistent) {\n this.abort();\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAeO,WAAK,mBAAL,kBAAKA,sBAAL;AACH,EAAAA,kBAAA,WAAQ;AACR,EAAAA,kBAAA,WAAQ;AACR,EAAAA,kBAAA,eAAY;AAHJ,SAAAA;AAAA,GAAA;AAML,aAAM,sBAAsB,OAAO,qBAAqB;AACxD,aAAM,0BAA0B;AAYhC,aAAM,sBAAoD;AAAA,EAqE7D,YACW,QACP,EAAE,SAAS,cAAc,mBAAmB,GAC9C;AAFS;AA5DX;AAAA,SAAQ,eAAe;AAuDvB,SAAU,eAAe;AAQrB,SAAK,eAAe,CAAC,CAAC;AACtB,SAAK,qBAAqB;AAC1B,QAAI,KAAK,cAAc;AACnB,WAAK,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pB;AAAA,EAEA,QAAc;AAnIlB;AAoIQ,SAAK,mBAAmB;AACxB,eAAK,oBAAL,mBAAsB;AAAA,EAC1B;AAAA,EAEA,gBAAsB;AAClB,SAAK,KAAK;AAAA,EACd;AAAA,EAEA,mBAAyB;AACrB,QAAI,CAAC,KAAK,cAAc;AACpB,WAAK,MAAM;AAAA,IACf;AAAA,EACJ;AACJ;",
|
|
6
6
|
"names": ["InteractionTypes"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";export var InteractionTypes=(r=>(r
|
|
1
|
+
"use strict";export var InteractionTypes=(r=>(r.click="click",r.hover="hover",r.longpress="longpress",r))(InteractionTypes||{});export const lastInteractionType=Symbol("lastInteractionType"),SAFARI_FOCUS_RING_CLASS="remove-focus-ring-safari-hack";export class InteractionController{constructor(e,{overlay:t,isPersistent:r,handleOverlayReady:i}){this.target=e;this.isLazilyOpen=!1;this.isPersistent=!1;this.isPersistent=!!r,this.handleOverlayReady=i,this.isPersistent&&this.init(),this.overlay=t}get activelyOpening(){return!1}get open(){var e,t;return(t=(e=this.overlay)==null?void 0:e.open)!=null?t:this.isLazilyOpen}set open(e){if(e!==this.open){if(this.isLazilyOpen=e,this.overlay){this.overlay.open=e,this.target[lastInteractionType]=this.type;return}e&&(customElements.whenDefined("sp-overlay").then(async()=>{const{Overlay:t}=await import("./Overlay.js");this.overlay=new t,this.overlay.open=!0,this.target[lastInteractionType]=this.type}),import("@spectrum-web-components/overlay/sp-overlay.js"))}}get overlay(){return this._overlay}set overlay(e){var t;e&&this.overlay!==e&&(this.overlay&&this.overlay.removeController(this),this._overlay=e,this.overlay.addController(this),this.initOverlay(),this.prepareDescription(this.target),(t=this.handleOverlayReady)==null||t.call(this,this.overlay))}prepareDescription(e){}releaseDescription(){}shouldCompleteOpen(){}init(){}initOverlay(){}abort(){var e;this.releaseDescription(),(e=this.abortController)==null||e.abort()}hostConnected(){this.init()}hostDisconnected(){this.isPersistent||this.abort()}}
|
|
2
2
|
//# sourceMappingURL=InteractionController.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["InteractionController.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2024 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { ReactiveController } from '@spectrum-web-components/base';\nimport { AbstractOverlay } from './AbstractOverlay.js';\n\nexport enum InteractionTypes {\n 'click',\n 'hover',\n 'longpress',\n}\n\nexport type ControllerOptions = {\n overlay?: AbstractOverlay;\n handleOverlayReady?: (overlay: AbstractOverlay) => void;\n isPersistent?: boolean;\n};\n\nexport class InteractionController implements ReactiveController {\n abortController!: AbortController;\n\n get activelyOpening(): boolean {\n return false;\n }\n\n private handleOverlayReady?: (overlay: AbstractOverlay) => void;\n\n // Holds optimistic open state when an Overlay is not yet present\n private isLazilyOpen = false;\n\n public get open(): boolean {\n return this.overlay?.open ?? this.isLazilyOpen;\n }\n\n /**\n * Set `open` against the associated Overlay lazily.\n */\n public set open(open: boolean) {\n if (open === this.open) return;\n this.isLazilyOpen = open;\n if (this.overlay) {\n // If there already is an Overlay, apply the value of `open` directly.\n this.overlay.open = open;\n return;\n }\n if (!open) {\n // When `open` moves to `false` and there is not yet an Overlay,\n // assume that no Overlay and a closed Overlay are the same and return early.\n return;\n }\n // When there is no Overlay and `open` is moving to `true`, lazily import/create\n // an Overlay and apply that state to it.\n customElements\n .whenDefined('sp-overlay')\n .then(async (): Promise<void> => {\n const { Overlay } = await import('./Overlay.js');\n this.overlay = new Overlay();\n this.overlay.open = true;\n });\n import('@spectrum-web-components/overlay/sp-overlay.js');\n }\n\n public get overlay(): AbstractOverlay {\n return this._overlay;\n }\n\n public set overlay(overlay: AbstractOverlay | undefined) {\n if (!overlay) return;\n if (this.overlay === overlay) return;\n if (this.overlay) {\n this.overlay.removeController(this);\n }\n this._overlay = overlay;\n this.overlay.addController(this);\n this.initOverlay();\n this.prepareDescription(this.target);\n this.handleOverlayReady?.(this.overlay);\n }\n\n private _overlay!: AbstractOverlay;\n\n protected isPersistent = false;\n\n type!: InteractionTypes;\n\n constructor(\n public target:
|
|
5
|
-
"mappings": "aAeO,WAAK,kBAAAA,IACRA,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2024 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { ReactiveController } from '@spectrum-web-components/base';\nimport { AbstractOverlay } from './AbstractOverlay.js';\n\nexport enum InteractionTypes {\n click = 'click',\n hover = 'hover',\n longpress = 'longpress',\n}\n\nexport const lastInteractionType = Symbol('lastInteractionType');\nexport const SAFARI_FOCUS_RING_CLASS = 'remove-focus-ring-safari-hack';\n\nexport type ControllerOptions = {\n overlay?: AbstractOverlay;\n handleOverlayReady?: (overlay: AbstractOverlay) => void;\n isPersistent?: boolean;\n};\n\ntype InteractionTarget = HTMLElement & {\n [lastInteractionType]?: InteractionTypes;\n};\n\nexport class InteractionController implements ReactiveController {\n abortController!: AbortController;\n\n get activelyOpening(): boolean {\n return false;\n }\n\n private handleOverlayReady?: (overlay: AbstractOverlay) => void;\n\n // Holds optimistic open state when an Overlay is not yet present\n private isLazilyOpen = false;\n\n public get open(): boolean {\n return this.overlay?.open ?? this.isLazilyOpen;\n }\n\n /**\n * Set `open` against the associated Overlay lazily.\n */\n public set open(open: boolean) {\n if (open === this.open) return;\n this.isLazilyOpen = open;\n if (this.overlay) {\n // If there already is an Overlay, apply the value of `open` directly.\n this.overlay.open = open;\n this.target[lastInteractionType] = this.type;\n return;\n }\n if (!open) {\n // When `open` moves to `false` and there is not yet an Overlay,\n // assume that no Overlay and a closed Overlay are the same and return early.\n return;\n }\n // When there is no Overlay and `open` is moving to `true`, lazily import/create\n // an Overlay and apply that state to it.\n customElements\n .whenDefined('sp-overlay')\n .then(async (): Promise<void> => {\n const { Overlay } = await import('./Overlay.js');\n this.overlay = new Overlay();\n this.overlay.open = true;\n this.target[lastInteractionType] = this.type;\n });\n import('@spectrum-web-components/overlay/sp-overlay.js');\n }\n\n public get overlay(): AbstractOverlay {\n return this._overlay;\n }\n\n public set overlay(overlay: AbstractOverlay | undefined) {\n if (!overlay) return;\n if (this.overlay === overlay) return;\n if (this.overlay) {\n this.overlay.removeController(this);\n }\n this._overlay = overlay;\n this.overlay.addController(this);\n this.initOverlay();\n this.prepareDescription(this.target);\n this.handleOverlayReady?.(this.overlay);\n }\n\n private _overlay!: AbstractOverlay;\n\n protected isPersistent = false;\n\n type!: InteractionTypes;\n\n constructor(\n public target: InteractionTarget,\n { overlay, isPersistent, handleOverlayReady }: ControllerOptions\n ) {\n this.isPersistent = !!isPersistent;\n this.handleOverlayReady = handleOverlayReady;\n if (this.isPersistent) {\n this.init();\n }\n this.overlay = overlay;\n }\n\n prepareDescription(_: HTMLElement): void {}\n\n releaseDescription(): void {}\n\n shouldCompleteOpen(): void {}\n\n /* c8 ignore next 3 */\n init(): void {\n // Abstract init() method.\n }\n\n /* c8 ignore next 3 */\n initOverlay(): void {\n // Abstract initOverlay() method.\n }\n\n abort(): void {\n this.releaseDescription();\n this.abortController?.abort();\n }\n\n hostConnected(): void {\n this.init();\n }\n\n hostDisconnected(): void {\n if (!this.isPersistent) {\n this.abort();\n }\n }\n}\n"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