@spectrum-web-components/overlay 0.18.0-devmode.0 → 0.18.0
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 +3 -0
- package/active-overlay.js +1 -2
- package/active-overlay.js.map +1 -1
- package/overlay-trigger.js +1 -2
- package/overlay-trigger.js.map +1 -1
- package/package.json +7 -7
- package/src/ActiveOverlay.js +8 -437
- package/src/ActiveOverlay.js.map +1 -1
- package/src/OverlayTrigger.js +2 -265
- package/src/OverlayTrigger.js.map +1 -1
- package/src/VirtualTrigger.js +1 -29
- package/src/VirtualTrigger.js.map +1 -1
- package/src/active-overlay.css.js +2 -4
- package/src/active-overlay.css.js.map +1 -1
- package/src/index.js +1 -6
- package/src/index.js.map +1 -1
- package/src/loader.js +1 -4
- package/src/loader.js.map +1 -1
- package/src/overlay-events.js +1 -6
- package/src/overlay-events.js.map +1 -1
- package/src/overlay-stack.js +2 -405
- package/src/overlay-stack.js.map +1 -1
- package/src/overlay-timer.js +1 -70
- package/src/overlay-timer.js.map +1 -1
- package/src/overlay-trigger.css.js +2 -4
- package/src/overlay-trigger.css.js.map +1 -1
- package/src/overlay-utils.js +1 -27
- package/src/overlay-utils.js.map +1 -1
- package/src/overlay.js +1 -84
- package/src/overlay.js.map +1 -1
- package/stories/overlay-story-components.js +11 -207
- package/stories/overlay-story-components.js.map +1 -1
- package/stories/overlay.stories.js +55 -338
- package/stories/overlay.stories.js.map +1 -1
- package/sync/overlay-trigger.js +1 -6
- package/sync/overlay-trigger.js.map +1 -1
- package/test/benchmark/basic-test.js +1 -6
- package/test/benchmark/basic-test.js.map +1 -1
- package/test/overlay-lifecycle.test.js +6 -112
- package/test/overlay-lifecycle.test.js.map +1 -1
- package/test/overlay-timer.test.js +1 -116
- package/test/overlay-timer.test.js.map +1 -1
- package/test/overlay-trigger-click.test.js +7 -51
- package/test/overlay-trigger-click.test.js.map +1 -1
- package/test/overlay-trigger-extended.test.js +4 -174
- package/test/overlay-trigger-extended.test.js.map +1 -1
- package/test/overlay-trigger-hover-click.test.js +3 -63
- package/test/overlay-trigger-hover-click.test.js.map +1 -1
- package/test/overlay-trigger-hover.test.js +7 -81
- package/test/overlay-trigger-hover.test.js.map +1 -1
- package/test/overlay-trigger-longpress.test.js +9 -177
- package/test/overlay-trigger-longpress.test.js.map +1 -1
- package/test/overlay-trigger-sync.test.js +4 -407
- package/test/overlay-trigger-sync.test.js.map +1 -1
- package/test/overlay-trigger.test.js +4 -407
- package/test/overlay-trigger.test.js.map +1 -1
- package/test/overlay.test-vrt.js +1 -3
- package/test/overlay.test-vrt.js.map +1 -1
- package/test/overlay.test.js +11 -477
- package/test/overlay.test.js.map +1 -1
package/src/overlay-timer.js
CHANGED
|
@@ -1,71 +1,2 @@
|
|
|
1
|
-
const
|
|
2
|
-
const DEFAULT_COOLDOWN = 1e3;
|
|
3
|
-
export class OverlayTimer {
|
|
4
|
-
constructor(options = {}) {
|
|
5
|
-
this.warmUpDelay = DEFAULT_WARMUP;
|
|
6
|
-
this.coolDownDelay = DEFAULT_COOLDOWN;
|
|
7
|
-
this.isWarm = false;
|
|
8
|
-
this.timeout = 0;
|
|
9
|
-
Object.assign(this, options);
|
|
10
|
-
}
|
|
11
|
-
async openTimer(component) {
|
|
12
|
-
this.cancelCooldownTimer();
|
|
13
|
-
if (!this.component || component !== this.component) {
|
|
14
|
-
if (this.component) {
|
|
15
|
-
this.close(this.component);
|
|
16
|
-
this.cancelCooldownTimer();
|
|
17
|
-
}
|
|
18
|
-
this.component = component;
|
|
19
|
-
if (this.isWarm) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
this.promise = new Promise((resolve) => {
|
|
23
|
-
this.resolve = resolve;
|
|
24
|
-
this.timeout = window.setTimeout(() => {
|
|
25
|
-
if (this.resolve) {
|
|
26
|
-
this.resolve(false);
|
|
27
|
-
this.isWarm = true;
|
|
28
|
-
}
|
|
29
|
-
}, this.warmUpDelay);
|
|
30
|
-
});
|
|
31
|
-
return this.promise;
|
|
32
|
-
} else if (this.promise) {
|
|
33
|
-
return this.promise;
|
|
34
|
-
} else {
|
|
35
|
-
throw new Error("Inconsistent state");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
close(component) {
|
|
39
|
-
if (this.component && this.component === component) {
|
|
40
|
-
this.resetCooldownTimer();
|
|
41
|
-
if (this.timeout > 0) {
|
|
42
|
-
clearTimeout(this.timeout);
|
|
43
|
-
this.timeout = 0;
|
|
44
|
-
}
|
|
45
|
-
if (this.resolve) {
|
|
46
|
-
this.resolve(true);
|
|
47
|
-
delete this.resolve;
|
|
48
|
-
}
|
|
49
|
-
delete this.promise;
|
|
50
|
-
delete this.component;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
resetCooldownTimer() {
|
|
54
|
-
if (this.isWarm) {
|
|
55
|
-
if (this.cooldownTimeout) {
|
|
56
|
-
window.clearTimeout(this.cooldownTimeout);
|
|
57
|
-
}
|
|
58
|
-
this.cooldownTimeout = window.setTimeout(() => {
|
|
59
|
-
this.isWarm = false;
|
|
60
|
-
delete this.cooldownTimeout;
|
|
61
|
-
}, this.coolDownDelay);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
cancelCooldownTimer() {
|
|
65
|
-
if (this.cooldownTimeout) {
|
|
66
|
-
window.clearTimeout(this.cooldownTimeout);
|
|
67
|
-
}
|
|
68
|
-
delete this.cooldownTimeout;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
1
|
+
const t=1e3,s=1e3;export class OverlayTimer{constructor(e={}){this.warmUpDelay=1e3;this.coolDownDelay=1e3;this.isWarm=!1;this.timeout=0;Object.assign(this,e)}async openTimer(e){if(this.cancelCooldownTimer(),!this.component||e!==this.component)return this.component&&(this.close(this.component),this.cancelCooldownTimer()),this.component=e,this.isWarm?!1:(this.promise=new Promise(o=>{this.resolve=o,this.timeout=window.setTimeout(()=>{this.resolve&&(this.resolve(!1),this.isWarm=!0)},this.warmUpDelay)}),this.promise);if(this.promise)return this.promise;throw new Error("Inconsistent state")}close(e){this.component&&this.component===e&&(this.resetCooldownTimer(),this.timeout>0&&(clearTimeout(this.timeout),this.timeout=0),this.resolve&&(this.resolve(!0),delete this.resolve),delete this.promise,delete this.component)}resetCooldownTimer(){this.isWarm&&(this.cooldownTimeout&&window.clearTimeout(this.cooldownTimeout),this.cooldownTimeout=window.setTimeout(()=>{this.isWarm=!1,delete this.cooldownTimeout},this.coolDownDelay))}cancelCooldownTimer(){this.cooldownTimeout&&window.clearTimeout(this.cooldownTimeout),delete this.cooldownTimeout}}
|
|
71
2
|
//# sourceMappingURL=overlay-timer.js.map
|
package/src/overlay-timer.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["overlay-timer.ts"],
|
|
4
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*/\n\nconst DEFAULT_WARMUP = 1000;\nconst DEFAULT_COOLDOWN = 1000;\n\n/**\n * A timer to help with implementation of warnup/cooldown behavior as described here:\n * https://spectrum.adobe.com/page/tooltip/#Immediate-or-delayed-appearance\n */\nexport class OverlayTimer {\n private warmUpDelay = DEFAULT_WARMUP;\n private coolDownDelay = DEFAULT_COOLDOWN;\n\n private isWarm = false;\n private cooldownTimeout?: number;\n\n private component?: HTMLElement;\n private timeout = 0;\n private promise?: Promise<boolean>;\n private resolve?: (cancelled: boolean) => void;\n\n constructor(\n options: { warmUpDelay?: number; coolDownDelay?: number } = {}\n ) {\n Object.assign(this, options);\n }\n\n public async openTimer(component: HTMLElement): Promise<boolean> {\n this.cancelCooldownTimer();\n\n if (!this.component || component !== this.component) {\n if (this.component) {\n this.close(this.component);\n this.cancelCooldownTimer();\n }\n this.component = component;\n\n if (this.isWarm) {\n return false;\n }\n\n this.promise = new Promise((resolve) => {\n this.resolve = resolve;\n this.timeout = window.setTimeout(() => {\n if (this.resolve) {\n this.resolve(false);\n this.isWarm = true;\n }\n }, this.warmUpDelay);\n });\n return this.promise;\n } else if (this.promise) {\n return this.promise;\n } else {\n // This should never happen\n throw new Error('Inconsistent state');\n }\n }\n\n public close(component: HTMLElement): void {\n if (this.component && this.component === component) {\n this.resetCooldownTimer();\n if (this.timeout > 0) {\n clearTimeout(this.timeout);\n this.timeout = 0;\n }\n if (this.resolve) {\n this.resolve(true);\n delete this.resolve;\n }\n delete this.promise;\n delete this.component;\n }\n }\n\n private resetCooldownTimer(): void {\n if (this.isWarm) {\n if (this.cooldownTimeout) {\n window.clearTimeout(this.cooldownTimeout);\n }\n this.cooldownTimeout = window.setTimeout(() => {\n this.isWarm = false;\n delete this.cooldownTimeout;\n }, this.coolDownDelay);\n }\n }\n\n private cancelCooldownTimer(): void {\n if (this.cooldownTimeout) {\n window.clearTimeout(this.cooldownTimeout);\n }\n delete this.cooldownTimeout;\n }\n}\n"],
|
|
5
|
-
"mappings": "AAYA,
|
|
5
|
+
"mappings": "AAYA,KAAM,GAAiB,IACjB,EAAmB,IAMlB,aAAM,YAAa,CAYtB,YACI,EAA4D,CAAC,EAC/D,CAbM,iBAAc,IACd,mBAAgB,IAEhB,YAAS,GAIT,aAAU,EAOd,OAAO,OAAO,KAAM,CAAO,CAC/B,MAEa,WAAU,EAA0C,CAG7D,GAFA,KAAK,oBAAoB,EAErB,CAAC,KAAK,WAAa,IAAc,KAAK,UAOtC,MANI,MAAK,WACL,MAAK,MAAM,KAAK,SAAS,EACzB,KAAK,oBAAoB,GAE7B,KAAK,UAAY,EAEb,KAAK,OACE,GAGX,MAAK,QAAU,GAAI,SAAQ,AAAC,GAAY,CACpC,KAAK,QAAU,EACf,KAAK,QAAU,OAAO,WAAW,IAAM,CACnC,AAAI,KAAK,SACL,MAAK,QAAQ,EAAK,EAClB,KAAK,OAAS,GAEtB,EAAG,KAAK,WAAW,CACvB,CAAC,EACM,KAAK,SACT,GAAI,KAAK,QACZ,MAAO,MAAK,QAGZ,KAAM,IAAI,OAAM,oBAAoB,CAE5C,CAEO,MAAM,EAA8B,CACvC,AAAI,KAAK,WAAa,KAAK,YAAc,GACrC,MAAK,mBAAmB,EACpB,KAAK,QAAU,GACf,cAAa,KAAK,OAAO,EACzB,KAAK,QAAU,GAEf,KAAK,SACL,MAAK,QAAQ,EAAI,EACjB,MAAO,MAAK,SAEhB,MAAO,MAAK,QACZ,MAAO,MAAK,UAEpB,CAEQ,oBAA2B,CAC/B,AAAI,KAAK,QACD,MAAK,iBACL,OAAO,aAAa,KAAK,eAAe,EAE5C,KAAK,gBAAkB,OAAO,WAAW,IAAM,CAC3C,KAAK,OAAS,GACd,MAAO,MAAK,eAChB,EAAG,KAAK,aAAa,EAE7B,CAEQ,qBAA4B,CAChC,AAAI,KAAK,iBACL,OAAO,aAAa,KAAK,eAAe,EAE5C,MAAO,MAAK,eAChB,CACJ",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
const styles = css`
|
|
1
|
+
import{css as t}from"@spectrum-web-components/base";const e=t`
|
|
3
2
|
:host([disabled]) ::slotted([slot=trigger]){pointer-events:none}#overlay-content slot{display:none}
|
|
4
|
-
`;
|
|
5
|
-
export default styles;
|
|
3
|
+
`;export default e;
|
|
6
4
|
//# sourceMappingURL=overlay-trigger.css.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["overlay-trigger.css.ts"],
|
|
4
4
|
"sourcesContent": ["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host([disabled]) ::slotted([slot=trigger]){pointer-events:none}#overlay-content slot{display:none}\n`;\nexport default styles;"],
|
|
5
|
-
"mappings": "AAWA
|
|
5
|
+
"mappings": "AAWA,oDACA,KAAM,GAAS;AAAA;AAAA,EAGf,cAAe",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/overlay-utils.js
CHANGED
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
export const parentOverlayOf = (
|
|
2
|
-
if (!el)
|
|
3
|
-
return null;
|
|
4
|
-
const closestOverlay = el.closest("active-overlay");
|
|
5
|
-
if (closestOverlay) {
|
|
6
|
-
return closestOverlay;
|
|
7
|
-
}
|
|
8
|
-
const rootNode = el.getRootNode();
|
|
9
|
-
if (rootNode.host) {
|
|
10
|
-
return parentOverlayOf(rootNode.host);
|
|
11
|
-
}
|
|
12
|
-
return null;
|
|
13
|
-
};
|
|
14
|
-
export const findOverlaysRootedInOverlay = (rootOverlay, activeOverlays) => {
|
|
15
|
-
const overlays = [];
|
|
16
|
-
if (!rootOverlay)
|
|
17
|
-
return [];
|
|
18
|
-
for (const overlay of activeOverlays) {
|
|
19
|
-
if (!overlay.root)
|
|
20
|
-
continue;
|
|
21
|
-
if (parentOverlayOf(overlay.root) === rootOverlay) {
|
|
22
|
-
overlays.push(overlay);
|
|
23
|
-
overlays.push(...findOverlaysRootedInOverlay(overlay, activeOverlays));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return overlays;
|
|
27
|
-
};
|
|
1
|
+
export const parentOverlayOf=e=>{if(!e)return null;const o=e.closest("active-overlay");if(o)return o;const t=e.getRootNode();return t.host?parentOverlayOf(t.host):null},findOverlaysRootedInOverlay=(e,o)=>{const t=[];if(!e)return[];for(const r of o)!r.root||parentOverlayOf(r.root)===e&&(t.push(r),t.push(...findOverlaysRootedInOverlay(r,o)));return t};
|
|
28
2
|
//# sourceMappingURL=overlay-utils.js.map
|
package/src/overlay-utils.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["overlay-utils.ts"],
|
|
4
4
|
"sourcesContent": ["/*\nCopyright 2022 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 { ActiveOverlay } from './ActiveOverlay';\n\nexport const parentOverlayOf = (el?: Element): ActiveOverlay | null => {\n if (!el) return null;\n const closestOverlay = el.closest('active-overlay');\n if (closestOverlay) {\n return closestOverlay;\n }\n const rootNode = el.getRootNode() as ShadowRoot;\n if (rootNode.host) {\n return parentOverlayOf(rootNode.host);\n }\n return null;\n};\n\nexport const findOverlaysRootedInOverlay = (\n rootOverlay: ActiveOverlay | undefined,\n activeOverlays: ActiveOverlay[]\n): ActiveOverlay[] => {\n const overlays: ActiveOverlay[] = [];\n if (!rootOverlay) return [];\n for (const overlay of activeOverlays) {\n if (!overlay.root) continue;\n if (parentOverlayOf(overlay.root) === rootOverlay) {\n overlays.push(overlay);\n overlays.push(\n ...findOverlaysRootedInOverlay(overlay, activeOverlays)\n );\n }\n }\n return overlays;\n};\n"],
|
|
5
|
-
"mappings": "AAcO,
|
|
5
|
+
"mappings": "AAcO,YAAM,iBAAkB,AAAC,GAAuC,CACnE,GAAI,CAAC,EAAI,MAAO,MAChB,KAAM,GAAiB,EAAG,QAAQ,gBAAgB,EAClD,GAAI,EACA,MAAO,GAEX,KAAM,GAAW,EAAG,YAAY,EAChC,MAAI,GAAS,KACF,gBAAgB,EAAS,IAAI,EAEjC,IACX,EAEa,4BAA8B,CACvC,EACA,IACkB,CAClB,KAAM,GAA4B,CAAC,EACnC,GAAI,CAAC,EAAa,MAAO,CAAC,EAC1B,SAAW,KAAW,GAClB,AAAI,CAAC,EAAQ,MACT,gBAAgB,EAAQ,IAAI,IAAM,GAClC,GAAS,KAAK,CAAO,EACrB,EAAS,KACL,GAAG,4BAA4B,EAAS,CAAc,CAC1D,GAGR,MAAO,EACX",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/overlay.js
CHANGED
|
@@ -1,85 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
const _Overlay = class {
|
|
3
|
-
constructor(owner, interaction, overlayElement) {
|
|
4
|
-
this.isOpen = false;
|
|
5
|
-
this.owner = owner;
|
|
6
|
-
this.overlayElement = overlayElement;
|
|
7
|
-
this.interaction = interaction;
|
|
8
|
-
}
|
|
9
|
-
static async open(owner, interaction, overlayElement, options) {
|
|
10
|
-
const overlay = new _Overlay(owner, interaction, overlayElement);
|
|
11
|
-
await overlay.open(options);
|
|
12
|
-
return () => {
|
|
13
|
-
overlay.close();
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
static update() {
|
|
17
|
-
const overlayUpdateEvent = new CustomEvent("sp-update-overlays", {
|
|
18
|
-
bubbles: true,
|
|
19
|
-
composed: true,
|
|
20
|
-
cancelable: true
|
|
21
|
-
});
|
|
22
|
-
document.dispatchEvent(overlayUpdateEvent);
|
|
23
|
-
}
|
|
24
|
-
async open({
|
|
25
|
-
abortPromise,
|
|
26
|
-
delayed,
|
|
27
|
-
offset = 0,
|
|
28
|
-
placement = "top",
|
|
29
|
-
receivesFocus,
|
|
30
|
-
notImmediatelyClosable,
|
|
31
|
-
virtualTrigger,
|
|
32
|
-
root
|
|
33
|
-
}) {
|
|
34
|
-
if (this.isOpen)
|
|
35
|
-
return true;
|
|
36
|
-
if (delayed === void 0) {
|
|
37
|
-
delayed = this.overlayElement.hasAttribute("delayed");
|
|
38
|
-
}
|
|
39
|
-
const queryThemeDetail = {
|
|
40
|
-
color: void 0,
|
|
41
|
-
scale: void 0,
|
|
42
|
-
lang: void 0,
|
|
43
|
-
theme: void 0
|
|
44
|
-
};
|
|
45
|
-
const queryThemeEvent = new CustomEvent("sp-query-theme", {
|
|
46
|
-
bubbles: true,
|
|
47
|
-
composed: true,
|
|
48
|
-
detail: queryThemeDetail,
|
|
49
|
-
cancelable: true
|
|
50
|
-
});
|
|
51
|
-
this.owner.dispatchEvent(queryThemeEvent);
|
|
52
|
-
const overlayDetailQuery = {};
|
|
53
|
-
const queryOverlayDetailEvent = new CustomEvent("sp-overlay-query", {
|
|
54
|
-
bubbles: true,
|
|
55
|
-
composed: true,
|
|
56
|
-
detail: overlayDetailQuery,
|
|
57
|
-
cancelable: true
|
|
58
|
-
});
|
|
59
|
-
this.overlayElement.dispatchEvent(queryOverlayDetailEvent);
|
|
60
|
-
await _Overlay.overlayStack.openOverlay({
|
|
61
|
-
abortPromise,
|
|
62
|
-
content: this.overlayElement,
|
|
63
|
-
contentTip: overlayDetailQuery.overlayContentTipElement,
|
|
64
|
-
delayed,
|
|
65
|
-
offset,
|
|
66
|
-
placement,
|
|
67
|
-
trigger: this.owner,
|
|
68
|
-
interaction: this.interaction,
|
|
69
|
-
theme: queryThemeDetail,
|
|
70
|
-
receivesFocus,
|
|
71
|
-
root,
|
|
72
|
-
notImmediatelyClosable,
|
|
73
|
-
virtualTrigger,
|
|
74
|
-
...overlayDetailQuery
|
|
75
|
-
});
|
|
76
|
-
this.isOpen = true;
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
close() {
|
|
80
|
-
_Overlay.overlayStack.closeOverlay(this.overlayElement);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
export let Overlay = _Overlay;
|
|
84
|
-
Overlay.overlayStack = new OverlayStack();
|
|
1
|
+
import{OverlayStack as m}from"./overlay-stack.js";const r=class{constructor(e,t,n){this.isOpen=!1;this.owner=e,this.overlayElement=n,this.interaction=t}static async open(e,t,n,i){const a=new r(e,t,n);return await a.open(i),()=>{a.close()}}static update(){const e=new CustomEvent("sp-update-overlays",{bubbles:!0,composed:!0,cancelable:!0});document.dispatchEvent(e)}async open({abortPromise:e,delayed:t,offset:n=0,placement:i="top",receivesFocus:a,notImmediatelyClosable:s,virtualTrigger:c,root:p}){if(this.isOpen)return!0;t===void 0&&(t=this.overlayElement.hasAttribute("delayed"));const l={color:void 0,scale:void 0,lang:void 0,theme:void 0},u=new CustomEvent("sp-query-theme",{bubbles:!0,composed:!0,detail:l,cancelable:!0});this.owner.dispatchEvent(u);const o={},v=new CustomEvent("sp-overlay-query",{bubbles:!0,composed:!0,detail:o,cancelable:!0});return this.overlayElement.dispatchEvent(v),await r.overlayStack.openOverlay({abortPromise:e,content:this.overlayElement,contentTip:o.overlayContentTipElement,delayed:t,offset:n,placement:i,trigger:this.owner,interaction:this.interaction,theme:l,receivesFocus:a,root:p,notImmediatelyClosable:s,virtualTrigger:c,...o}),this.isOpen=!0,!0}close(){r.overlayStack.closeOverlay(this.overlayElement)}};export let Overlay=r;Overlay.overlayStack=new m;
|
|
85
2
|
//# sourceMappingURL=overlay.js.map
|
package/src/overlay.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["overlay.ts"],
|
|
4
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*/\n\nimport type { ThemeData } from '@spectrum-web-components/theme/src/Theme.js';\nimport type {\n OverlayDisplayQueryDetail,\n OverlayOptions,\n TriggerInteractions,\n} from './overlay-types';\nimport { OverlayStack } from './overlay-stack.js';\n\n/**\n * This class allows access to the overlay system which allows a client to\n * position an element in the overlay positioned relative to another node.\n */\nexport class Overlay {\n private static overlayStack = new OverlayStack();\n\n private isOpen = false;\n private overlayElement: HTMLElement;\n private owner: HTMLElement;\n private interaction: TriggerInteractions;\n\n /**\n *\n * @param owner the parent element we will use to position the overlay element\n * @param interaction the type of interaction that caused this overlay to be shown\n * @param overlayElement the item to display as an overlay\n */\n constructor(\n owner: HTMLElement,\n interaction: TriggerInteractions,\n overlayElement: HTMLElement\n ) {\n this.owner = owner;\n this.overlayElement = overlayElement;\n this.interaction = interaction;\n }\n\n /**\n * Open an overlay\n *\n * @param owner the parent element we will use to position the overlay element\n * @param interaction the type of interaction that caused this overlay to be shown\n * @param overlayElement the item to display as an overlay\n * @param options display parameters\n * @param options.delayed if true delay opening of the overlay based on the global warmup/cooldown timer\n * @param options.offset distance to offset the overlay\n * @param options.placement side on which to position the overlay\n * @returns an Overlay object which can be used to close the overlay\n */\n public static async open(\n owner: HTMLElement,\n interaction: TriggerInteractions,\n overlayElement: HTMLElement,\n options: OverlayOptions\n ): Promise<() => void> {\n const overlay = new Overlay(owner, interaction, overlayElement);\n await overlay.open(options);\n return (): void => {\n overlay.close();\n };\n }\n\n public static update(): void {\n const overlayUpdateEvent = new CustomEvent('sp-update-overlays', {\n bubbles: true,\n composed: true,\n cancelable: true,\n });\n document.dispatchEvent(overlayUpdateEvent);\n }\n\n /**\n * Open an overlay\n *\n * @param options display parameters\n * @param options.delayed delay before opening the overlay\n * @param options.offset distance to offset the overlay\n * @param options.placement side on which to position the overlay\n * @returns a Promise that resolves to true if this operation was cancelled\n */\n public async open({\n abortPromise,\n delayed,\n offset = 0,\n placement = 'top',\n receivesFocus,\n notImmediatelyClosable,\n virtualTrigger,\n root,\n }: OverlayOptions): Promise<boolean> {\n /* c8 ignore next */\n if (this.isOpen) return true;\n\n if (delayed === undefined) {\n delayed = this.overlayElement.hasAttribute('delayed');\n }\n\n const queryThemeDetail: ThemeData = {\n color: undefined,\n scale: undefined,\n lang: undefined,\n theme: undefined,\n };\n const queryThemeEvent = new CustomEvent<ThemeData>('sp-query-theme', {\n bubbles: true,\n composed: true,\n detail: queryThemeDetail,\n cancelable: true,\n });\n this.owner.dispatchEvent(queryThemeEvent);\n\n const overlayDetailQuery: OverlayDisplayQueryDetail = {};\n const queryOverlayDetailEvent =\n new CustomEvent<OverlayDisplayQueryDetail>('sp-overlay-query', {\n bubbles: true,\n composed: true,\n detail: overlayDetailQuery,\n cancelable: true,\n });\n this.overlayElement.dispatchEvent(queryOverlayDetailEvent);\n\n await Overlay.overlayStack.openOverlay({\n abortPromise,\n content: this.overlayElement,\n contentTip: overlayDetailQuery.overlayContentTipElement,\n delayed,\n offset: offset,\n placement: placement,\n trigger: this.owner,\n interaction: this.interaction,\n theme: queryThemeDetail,\n receivesFocus,\n root,\n notImmediatelyClosable,\n virtualTrigger,\n ...overlayDetailQuery,\n });\n this.isOpen = true;\n return true;\n }\n\n /**\n * Close the overlay if it is open\n */\n public close(): void {\n Overlay.overlayStack.closeOverlay(this.overlayElement);\n }\n}\n\n/**\n * Announces that an overlay-based UI element has opened\n * @event sp-open\n * @type {object}\n * @property {TriggerInteractions} interaction type of interaction that triggered the opening\n */\n\n/**\n * Announces that an overlay-based UI element has opened\n * @event sp-close\n * @type {object}\n * @property {TriggerInteractions} interaction type of interaction that triggered the closing\n */\n"],
|
|
5
|
-
"mappings": "AAkBA
|
|
5
|
+
"mappings": "AAkBA,kDAMO,aAAc,CAcjB,YACI,EACA,EACA,EACF,CAfM,YAAS,GAgBb,KAAK,MAAQ,EACb,KAAK,eAAiB,EACtB,KAAK,YAAc,CACvB,aAcoB,MAChB,EACA,EACA,EACA,EACmB,CACnB,KAAM,GAAU,GAAI,GAAQ,EAAO,EAAa,CAAc,EAC9D,YAAM,GAAQ,KAAK,CAAO,EACnB,IAAY,CACf,EAAQ,MAAM,CAClB,CACJ,OAEc,SAAe,CACzB,KAAM,GAAqB,GAAI,aAAY,qBAAsB,CAC7D,QAAS,GACT,SAAU,GACV,WAAY,EAChB,CAAC,EACD,SAAS,cAAc,CAAkB,CAC7C,MAWa,MAAK,CACd,eACA,UACA,SAAS,EACT,YAAY,MACZ,gBACA,yBACA,iBACA,QACiC,CAEjC,GAAI,KAAK,OAAQ,MAAO,GAExB,AAAI,IAAY,QACZ,GAAU,KAAK,eAAe,aAAa,SAAS,GAGxD,KAAM,GAA8B,CAChC,MAAO,OACP,MAAO,OACP,KAAM,OACN,MAAO,MACX,EACM,EAAkB,GAAI,aAAuB,iBAAkB,CACjE,QAAS,GACT,SAAU,GACV,OAAQ,EACR,WAAY,EAChB,CAAC,EACD,KAAK,MAAM,cAAc,CAAe,EAExC,KAAM,GAAgD,CAAC,EACjD,EACF,GAAI,aAAuC,mBAAoB,CAC3D,QAAS,GACT,SAAU,GACV,OAAQ,EACR,WAAY,EAChB,CAAC,EACL,YAAK,eAAe,cAAc,CAAuB,EAEzD,KAAM,GAAQ,aAAa,YAAY,CACnC,eACA,QAAS,KAAK,eACd,WAAY,EAAmB,yBAC/B,UACA,OAAQ,EACR,UAAW,EACX,QAAS,KAAK,MACd,YAAa,KAAK,YAClB,MAAO,EACP,gBACA,OACA,yBACA,oBACG,CACP,CAAC,EACD,KAAK,OAAS,GACP,EACX,CAKO,OAAc,CACjB,EAAQ,aAAa,aAAa,KAAK,cAAc,CACzD,CACJ,EAtIO,qBACY,AADZ,QACY,aAAe,GAAI",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,35 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
-
if (decorator = decorators[i])
|
|
7
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
-
if (kind && result)
|
|
9
|
-
__defProp(target, key, result);
|
|
10
|
-
return result;
|
|
11
|
-
};
|
|
12
|
-
import {
|
|
13
|
-
css,
|
|
14
|
-
html,
|
|
15
|
-
LitElement
|
|
16
|
-
} from "@spectrum-web-components/base";
|
|
17
|
-
import {
|
|
18
|
-
property,
|
|
19
|
-
query
|
|
20
|
-
} from "@spectrum-web-components/base/src/decorators.js";
|
|
21
|
-
import {
|
|
22
|
-
Overlay
|
|
23
|
-
} from "@spectrum-web-components/overlay";
|
|
24
|
-
import "@spectrum-web-components/button/sp-button.js";
|
|
25
|
-
import "@spectrum-web-components/popover/sp-popover.js";
|
|
26
|
-
import "@spectrum-web-components/radio/sp-radio.js";
|
|
27
|
-
import "@spectrum-web-components/radio/sp-radio-group.js";
|
|
28
|
-
import "@spectrum-web-components/overlay/overlay-trigger.js";
|
|
29
|
-
const MAX_DEPTH = 7;
|
|
30
|
-
class OverlayTargetIcon extends LitElement {
|
|
31
|
-
static get styles() {
|
|
32
|
-
return css`
|
|
1
|
+
var b=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var s=(n,e,t,i)=>{for(var o=i>1?void 0:i?x(e,t):e,r=n.length-1,a;r>=0;r--)(a=n[r])&&(o=(i?a(e,t,o):a(o))||o);return i&&o&&b(e,t,o),o};import{css as u,html as l,LitElement as p}from"@spectrum-web-components/base";import{property as d,query as m}from"@spectrum-web-components/base/src/decorators.js";import{Overlay as T}from"@spectrum-web-components/overlay";import"@spectrum-web-components/button/sp-button.js";import"@spectrum-web-components/popover/sp-popover.js";import"@spectrum-web-components/radio/sp-radio.js";import"@spectrum-web-components/radio/sp-radio-group.js";import"@spectrum-web-components/overlay/overlay-trigger.js";const M=7;class w extends p{static get styles(){return u`
|
|
33
2
|
:host {
|
|
34
3
|
position: absolute;
|
|
35
4
|
display: block;
|
|
@@ -39,10 +8,7 @@ class OverlayTargetIcon extends LitElement {
|
|
|
39
8
|
top: 0;
|
|
40
9
|
left: 0;
|
|
41
10
|
}
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
render() {
|
|
45
|
-
return html`
|
|
11
|
+
`}render(){return l`
|
|
46
12
|
<svg
|
|
47
13
|
aria-hidden="true"
|
|
48
14
|
focusable="false"
|
|
@@ -57,18 +23,7 @@ class OverlayTargetIcon extends LitElement {
|
|
|
57
23
|
d="M248 8C111.03 8 0 119.03 0 256s111.03 248 248 248 248-111.03 248-248S384.97 8 248 8zm0 432c-101.69 0-184-82.29-184-184 0-101.69 82.29-184 184-184 101.69 0 184 82.29 184 184 0 101.69-82.29 184-184 184zm0-312c-70.69 0-128 57.31-128 128s57.31 128 128 128 128-57.31 128-128-57.31-128-128-128zm0 192c-35.29 0-64-28.71-64-64s28.71-64 64-64 64 28.71 64 64-28.71 64-64 64z"
|
|
58
24
|
></path>
|
|
59
25
|
</svg>
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
customElements.define("overlay-target-icon", OverlayTargetIcon);
|
|
64
|
-
class OverlayDrag extends LitElement {
|
|
65
|
-
constructor() {
|
|
66
|
-
super(...arguments);
|
|
67
|
-
this.top = 100;
|
|
68
|
-
this.left = 100;
|
|
69
|
-
}
|
|
70
|
-
static get styles() {
|
|
71
|
-
return css`
|
|
26
|
+
`}}customElements.define("overlay-target-icon",w);class h extends p{constructor(){super(...arguments);this.top=100;this.left=100}static get styles(){return u`
|
|
72
27
|
:host {
|
|
73
28
|
display: block;
|
|
74
29
|
width: 100%;
|
|
@@ -81,104 +36,9 @@ class OverlayDrag extends LitElement {
|
|
|
81
36
|
width: 100%;
|
|
82
37
|
height: 100%;
|
|
83
38
|
}
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
onSlotChange(event) {
|
|
87
|
-
const slot = event.target;
|
|
88
|
-
this.targetElement = void 0;
|
|
89
|
-
const nodes = slot.assignedNodes();
|
|
90
|
-
const slotElement = nodes.find((node) => node instanceof HTMLElement);
|
|
91
|
-
if (!slotElement)
|
|
92
|
-
return;
|
|
93
|
-
this.targetElement = slotElement.querySelector('[slot="trigger"]');
|
|
94
|
-
if (!this.targetElement)
|
|
95
|
-
return;
|
|
96
|
-
this.targetElement.addEventListener("mousedown", (event2) => this.onMouseDown(event2));
|
|
97
|
-
this.resetTargetPosition();
|
|
98
|
-
}
|
|
99
|
-
onMouseDown(event) {
|
|
100
|
-
const target = event.target;
|
|
101
|
-
const parent = target.parentElement;
|
|
102
|
-
if (!parent)
|
|
103
|
-
return;
|
|
104
|
-
const max = {
|
|
105
|
-
x: parent.offsetWidth - target.offsetWidth,
|
|
106
|
-
y: parent.offsetHeight - target.offsetHeight
|
|
107
|
-
};
|
|
108
|
-
const dragStart = {
|
|
109
|
-
x: event.clientX,
|
|
110
|
-
y: event.clientY
|
|
111
|
-
};
|
|
112
|
-
const originalPos = {
|
|
113
|
-
x: this.left,
|
|
114
|
-
y: this.top
|
|
115
|
-
};
|
|
116
|
-
const onMouseMove = (event2) => {
|
|
117
|
-
const dragDelta = {
|
|
118
|
-
x: event2.clientX - dragStart.x,
|
|
119
|
-
y: event2.clientY - dragStart.y
|
|
120
|
-
};
|
|
121
|
-
const newPosition = {
|
|
122
|
-
x: dragDelta.x + originalPos.x,
|
|
123
|
-
y: dragDelta.y + originalPos.y
|
|
124
|
-
};
|
|
125
|
-
this.left = Math.min(Math.max(newPosition.x, 0), max.x);
|
|
126
|
-
this.top = Math.min(Math.max(newPosition.y, 0), max.y);
|
|
127
|
-
Overlay.update();
|
|
128
|
-
};
|
|
129
|
-
const onMouseUp = () => {
|
|
130
|
-
document.removeEventListener("mousemove", onMouseMove);
|
|
131
|
-
document.removeEventListener("mouseup", onMouseUp);
|
|
132
|
-
};
|
|
133
|
-
document.addEventListener("mousemove", onMouseMove);
|
|
134
|
-
document.addEventListener("mouseup", onMouseUp);
|
|
135
|
-
}
|
|
136
|
-
resetTargetPosition() {
|
|
137
|
-
if (!this.targetElement)
|
|
138
|
-
return;
|
|
139
|
-
const target = this.targetElement;
|
|
140
|
-
const parent = target.parentElement;
|
|
141
|
-
if (!parent)
|
|
142
|
-
return;
|
|
143
|
-
this.left = (parent.offsetWidth - target.offsetWidth) / 2;
|
|
144
|
-
this.top = (parent.offsetHeight - target.offsetHeight) / 2;
|
|
145
|
-
}
|
|
146
|
-
updated() {
|
|
147
|
-
if (this.targetElement) {
|
|
148
|
-
this.targetElement.style.transform = `translate(${this.left}px, ${this.top}px)`;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
render() {
|
|
152
|
-
return html`
|
|
39
|
+
`}onSlotChange(e){const t=e.target;this.targetElement=void 0;const o=t.assignedNodes().find(r=>r instanceof HTMLElement);!o||(this.targetElement=o.querySelector('[slot="trigger"]'),this.targetElement&&(this.targetElement.addEventListener("mousedown",r=>this.onMouseDown(r)),this.resetTargetPosition()))}onMouseDown(e){const t=e.target,i=t.parentElement;if(!i)return;const o={x:i.offsetWidth-t.offsetWidth,y:i.offsetHeight-t.offsetHeight},r={x:e.clientX,y:e.clientY},a={x:this.left,y:this.top},g=f=>{const E={x:f.clientX-r.x,y:f.clientY-r.y},y={x:E.x+a.x,y:E.y+a.y};this.left=Math.min(Math.max(y.x,0),o.x),this.top=Math.min(Math.max(y.y,0),o.y),T.update()},v=()=>{document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",v)};document.addEventListener("mousemove",g),document.addEventListener("mouseup",v)}resetTargetPosition(){if(!this.targetElement)return;const e=this.targetElement,t=e.parentElement;!t||(this.left=(t.offsetWidth-e.offsetWidth)/2,this.top=(t.offsetHeight-e.offsetHeight)/2)}updated(){this.targetElement&&(this.targetElement.style.transform=`translate(${this.left}px, ${this.top}px)`)}render(){return l`
|
|
153
40
|
<slot @slotchange=${this.onSlotChange}></slot>
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
__decorateClass([
|
|
158
|
-
property({ type: Number })
|
|
159
|
-
], OverlayDrag.prototype, "top", 2);
|
|
160
|
-
__decorateClass([
|
|
161
|
-
property({ type: Number })
|
|
162
|
-
], OverlayDrag.prototype, "left", 2);
|
|
163
|
-
customElements.define("overlay-drag", OverlayDrag);
|
|
164
|
-
class RecursivePopover extends LitElement {
|
|
165
|
-
constructor() {
|
|
166
|
-
super();
|
|
167
|
-
this.depth = 0;
|
|
168
|
-
this.isShiftTabbing = false;
|
|
169
|
-
this.placement = "right";
|
|
170
|
-
this.depth = 0;
|
|
171
|
-
this.addEventListener("keydown", (event) => {
|
|
172
|
-
const { code } = event;
|
|
173
|
-
if (code === "Enter") {
|
|
174
|
-
this.trigger.click();
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
this.addEventListener("focusin", this.handleFocusin);
|
|
178
|
-
}
|
|
179
|
-
static get styles() {
|
|
180
|
-
return [
|
|
181
|
-
css`
|
|
41
|
+
`}}s([d({type:Number})],h.prototype,"top",2),s([d({type:Number})],h.prototype,"left",2),customElements.define("overlay-drag",h);class c extends p{constructor(){super();this.depth=0;this.isShiftTabbing=!1;this.placement="right",this.depth=0,this.addEventListener("keydown",e=>{const{code:t}=e;t==="Enter"&&this.trigger.click()}),this.addEventListener("focusin",this.handleFocusin)}static get styles(){return[u`
|
|
182
42
|
:host {
|
|
183
43
|
display: block;
|
|
184
44
|
text-align: center;
|
|
@@ -188,39 +48,7 @@ class RecursivePopover extends LitElement {
|
|
|
188
48
|
display: inline-flex;
|
|
189
49
|
margin-top: 11px;
|
|
190
50
|
}
|
|
191
|
-
`
|
|
192
|
-
];
|
|
193
|
-
}
|
|
194
|
-
handleFocusin() {
|
|
195
|
-
this.focus();
|
|
196
|
-
}
|
|
197
|
-
focus() {
|
|
198
|
-
if (this.shadowRoot.activeElement !== null) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const firstFocusable = this.shadowRoot.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
|
|
202
|
-
if (firstFocusable) {
|
|
203
|
-
if (firstFocusable.updateComplete) {
|
|
204
|
-
firstFocusable.updateComplete.then(() => firstFocusable.focus());
|
|
205
|
-
} else {
|
|
206
|
-
firstFocusable.focus();
|
|
207
|
-
}
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
super.focus();
|
|
211
|
-
}
|
|
212
|
-
onRadioChange(event) {
|
|
213
|
-
const target = event.target;
|
|
214
|
-
this.placement = target.selected;
|
|
215
|
-
}
|
|
216
|
-
captureEnter(event) {
|
|
217
|
-
const { code } = event;
|
|
218
|
-
if (code === "Enter") {
|
|
219
|
-
event.stopPropagation();
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
render() {
|
|
223
|
-
return html`
|
|
51
|
+
`]}handleFocusin(){this.focus()}focus(){if(this.shadowRoot.activeElement!==null)return;const e=this.shadowRoot.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(e){e.updateComplete?e.updateComplete.then(()=>e.focus()):e.focus();return}super.focus()}onRadioChange(e){const t=e.target;this.placement=t.selected}captureEnter(e){const{code:t}=e;t==="Enter"&&e.stopPropagation()}render(){return l`
|
|
224
52
|
<sp-radio-group
|
|
225
53
|
horizontal
|
|
226
54
|
@change=${this.onRadioChange}
|
|
@@ -247,33 +75,18 @@ class RecursivePopover extends LitElement {
|
|
|
247
75
|
tip
|
|
248
76
|
open
|
|
249
77
|
>
|
|
250
|
-
${this.depth
|
|
78
|
+
${this.depth<M?l`
|
|
251
79
|
<recursive-popover
|
|
252
80
|
position="${this.placement}"
|
|
253
|
-
depth="${this.depth
|
|
81
|
+
depth="${this.depth+1}"
|
|
254
82
|
tabindex="0"
|
|
255
83
|
></recursive-popover>
|
|
256
|
-
`
|
|
84
|
+
`:l`
|
|
257
85
|
<div>Maximum Depth</div>
|
|
258
86
|
`}
|
|
259
87
|
</sp-popover>
|
|
260
88
|
</overlay-trigger>
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
__decorateClass([
|
|
265
|
-
property({ type: String })
|
|
266
|
-
], RecursivePopover.prototype, "placement", 2);
|
|
267
|
-
__decorateClass([
|
|
268
|
-
property({ type: Number })
|
|
269
|
-
], RecursivePopover.prototype, "depth", 2);
|
|
270
|
-
__decorateClass([
|
|
271
|
-
query('[slot="trigger"]')
|
|
272
|
-
], RecursivePopover.prototype, "trigger", 2);
|
|
273
|
-
customElements.define("recursive-popover", RecursivePopover);
|
|
274
|
-
export class PopoverContent extends LitElement {
|
|
275
|
-
render() {
|
|
276
|
-
return html`
|
|
89
|
+
`}}s([d({type:String})],c.prototype,"placement",2),s([d({type:Number})],c.prototype,"depth",2),s([m('[slot="trigger"]')],c.prototype,"trigger",2),customElements.define("recursive-popover",c);export class PopoverContent extends p{render(){return l`
|
|
277
90
|
<overlay-trigger>
|
|
278
91
|
<sp-button slot="trigger">Open me</sp-button>
|
|
279
92
|
<sp-popover slot="click-content" direction="bottom" dialog>
|
|
@@ -283,14 +96,5 @@ export class PopoverContent extends LitElement {
|
|
|
283
96
|
<p>This is all the content.</p>
|
|
284
97
|
</sp-popover>
|
|
285
98
|
</overlay-trigger>
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
__decorateClass([
|
|
290
|
-
query('[slot="trigger"]')
|
|
291
|
-
], PopoverContent.prototype, "button", 2);
|
|
292
|
-
__decorateClass([
|
|
293
|
-
query("overlay-trigger")
|
|
294
|
-
], PopoverContent.prototype, "trigger", 2);
|
|
295
|
-
customElements.define("popover-content", PopoverContent);
|
|
99
|
+
`}}s([m('[slot="trigger"]')],PopoverContent.prototype,"button",2),s([m("overlay-trigger")],PopoverContent.prototype,"trigger",2),customElements.define("popover-content",PopoverContent);
|
|
296
100
|
//# sourceMappingURL=overlay-story-components.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["overlay-story-components.ts"],
|
|
4
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 css,\n CSSResultGroup,\n html,\n LitElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\n\nimport {\n Overlay,\n OverlayTrigger,\n Placement,\n} from '@spectrum-web-components/overlay';\nimport { RadioGroup } from '@spectrum-web-components/radio';\nimport '@spectrum-web-components/button/sp-button.js';\nimport { Button } from '@spectrum-web-components/button';\nimport '@spectrum-web-components/popover/sp-popover.js';\nimport '@spectrum-web-components/radio/sp-radio.js';\nimport '@spectrum-web-components/radio/sp-radio-group.js';\nimport '@spectrum-web-components/overlay/overlay-trigger.js';\n\n// Prevent infinite recursion in browser\nconst MAX_DEPTH = 7;\n\nclass OverlayTargetIcon extends LitElement {\n static override get styles(): CSSResultGroup {\n return css`\n :host {\n position: absolute;\n display: block;\n color: var(--spectrum-global-color-magenta-700);\n width: 64px;\n height: 64px;\n top: 0;\n left: 0;\n }\n `;\n }\n\n public override render(): TemplateResult {\n return html`\n <svg\n aria-hidden=\"true\"\n focusable=\"false\"\n data-prefix=\"fas\"\n data-icon=\"bullseye\"\n class=\"svg-inline--fa fa-bullseye fa-w-16\"\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 496 512\"\n >\n <path\n fill=\"currentColor\"\n d=\"M248 8C111.03 8 0 119.03 0 256s111.03 248 248 248 248-111.03 248-248S384.97 8 248 8zm0 432c-101.69 0-184-82.29-184-184 0-101.69 82.29-184 184-184 101.69 0 184 82.29 184 184 0 101.69-82.29 184-184 184zm0-312c-70.69 0-128 57.31-128 128s57.31 128 128 128 128-57.31 128-128-57.31-128-128-128zm0 192c-35.29 0-64-28.71-64-64s28.71-64 64-64 64 28.71 64 64-28.71 64-64 64z\"\n ></path>\n </svg>\n `;\n }\n}\ncustomElements.define('overlay-target-icon', OverlayTargetIcon);\n\nclass OverlayDrag extends LitElement {\n @property({ type: Number })\n private top = 100;\n @property({ type: Number })\n private left = 100;\n\n private targetElement: HTMLElement | undefined | null;\n\n static override get styles(): CSSResultGroup {\n return css`\n :host {\n display: block;\n width: 100%;\n height: 100%;\n position: relative;\n }\n\n ::slotted(*) {\n display: block;\n width: 100%;\n height: 100%;\n }\n `;\n }\n\n private onSlotChange(event: Event & { target: HTMLSlotElement }): void {\n const slot = event.target as HTMLSlotElement;\n this.targetElement = undefined;\n\n const nodes = slot.assignedNodes();\n const slotElement = nodes.find(\n (node) => node instanceof HTMLElement\n ) as HTMLElement;\n if (!slotElement) return;\n\n this.targetElement = slotElement.querySelector(\n '[slot=\"trigger\"]'\n ) as HTMLElement;\n if (!this.targetElement) return;\n\n this.targetElement.addEventListener('mousedown', (event) =>\n this.onMouseDown(event)\n );\n\n this.resetTargetPosition();\n }\n\n private onMouseDown(event: MouseEvent): void {\n const target = event.target as HTMLElement;\n const parent = target.parentElement;\n if (!parent) return;\n\n const max = {\n x: parent.offsetWidth - target.offsetWidth,\n y: parent.offsetHeight - target.offsetHeight,\n };\n const dragStart = {\n x: event.clientX,\n y: event.clientY,\n };\n const originalPos = {\n x: this.left,\n y: this.top,\n };\n\n const onMouseMove = (event: MouseEvent): void => {\n const dragDelta = {\n x: event.clientX - dragStart.x,\n y: event.clientY - dragStart.y,\n };\n const newPosition = {\n x: dragDelta.x + originalPos.x,\n y: dragDelta.y + originalPos.y,\n };\n this.left = Math.min(Math.max(newPosition.x, 0), max.x);\n this.top = Math.min(Math.max(newPosition.y, 0), max.y);\n Overlay.update();\n };\n\n const onMouseUp = (): void => {\n document.removeEventListener('mousemove', onMouseMove);\n document.removeEventListener('mouseup', onMouseUp);\n };\n\n document.addEventListener('mousemove', onMouseMove);\n document.addEventListener('mouseup', onMouseUp);\n }\n\n public resetTargetPosition(): void {\n if (!this.targetElement) return;\n const target = this.targetElement as HTMLElement;\n const parent = target.parentElement;\n if (!parent) return;\n\n this.left = (parent.offsetWidth - target.offsetWidth) / 2;\n this.top = (parent.offsetHeight - target.offsetHeight) / 2;\n }\n\n public override updated(): void {\n if (this.targetElement) {\n this.targetElement.style.transform = `translate(${this.left}px, ${this.top}px)`;\n }\n }\n\n public override render(): TemplateResult {\n return html`\n <slot @slotchange=${this.onSlotChange}></slot>\n `;\n }\n}\ncustomElements.define('overlay-drag', OverlayDrag);\n\nclass RecursivePopover extends LitElement {\n @property({ type: String })\n private placement: Placement;\n\n @property({ type: Number })\n private depth = 0;\n\n @query('[slot=\"trigger\"]')\n private trigger!: Button;\n\n protected isShiftTabbing = false;\n\n public override shadowRoot!: ShadowRoot;\n\n public static override get styles(): CSSResultGroup {\n return [\n css`\n :host {\n display: block;\n text-align: center;\n }\n\n overlay-trigger {\n display: inline-flex;\n margin-top: 11px;\n }\n `,\n ];\n }\n\n public constructor() {\n super();\n this.placement = 'right';\n this.depth = 0;\n this.addEventListener('keydown', (event: KeyboardEvent) => {\n const { code } = event;\n if (code === 'Enter') {\n this.trigger.click();\n }\n });\n this.addEventListener('focusin', this.handleFocusin);\n }\n\n private handleFocusin(): void {\n this.focus();\n }\n\n public override focus(): void {\n if (this.shadowRoot.activeElement !== null) {\n return;\n }\n const firstFocusable = this.shadowRoot.querySelector(\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])'\n ) as LitElement;\n if (firstFocusable) {\n if (firstFocusable.updateComplete) {\n firstFocusable.updateComplete.then(() =>\n firstFocusable.focus()\n );\n } else {\n firstFocusable.focus();\n }\n return;\n }\n super.focus();\n }\n\n public onRadioChange(event: Event): void {\n const target = event.target as RadioGroup;\n this.placement = target.selected as Placement;\n }\n\n private captureEnter(event: KeyboardEvent): void {\n const { code } = event;\n if (code === 'Enter') {\n event.stopPropagation();\n }\n }\n\n public override render(): TemplateResult {\n return html`\n <sp-radio-group\n horizontal\n @change=${this.onRadioChange}\n selected=\"${this.placement}\"\n name=\"group-example\"\n >\n <sp-radio value=\"top\">Top</sp-radio>\n <sp-radio value=\"right\">Right</sp-radio>\n <sp-radio value=\"bottom\">Bottom</sp-radio>\n <sp-radio value=\"left\">Left</sp-radio>\n </sp-radio-group>\n <overlay-trigger placement=\"${this.placement}\" type=\"modal\">\n <sp-button\n slot=\"trigger\"\n variant=\"accent\"\n @keydown=${this.captureEnter}\n >\n Open Popover\n </sp-button>\n <sp-popover\n dialog\n slot=\"click-content\"\n direction=\"${this.placement}\"\n tip\n open\n >\n ${this.depth < MAX_DEPTH\n ? html`\n <recursive-popover\n position=\"${this.placement}\"\n depth=\"${this.depth + 1}\"\n tabindex=\"0\"\n ></recursive-popover>\n `\n : html`\n <div>Maximum Depth</div>\n `}\n </sp-popover>\n </overlay-trigger>\n `;\n }\n}\ncustomElements.define('recursive-popover', RecursivePopover);\n\nexport class PopoverContent extends LitElement {\n @query('[slot=\"trigger\"]')\n public button!: Button;\n\n @query('overlay-trigger')\n public trigger!: OverlayTrigger;\n\n override render(): TemplateResult {\n return html`\n <overlay-trigger>\n <sp-button slot=\"trigger\">Open me</sp-button>\n <sp-popover slot=\"click-content\" direction=\"bottom\" dialog>\n <p>This is all the content.</p>\n <p>This is all the content.</p>\n <p>This is all the content.</p>\n <p>This is all the content.</p>\n </sp-popover>\n </overlay-trigger>\n `;\n }\n}\n\ncustomElements.define('popover-content', PopoverContent);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'popover-content': PopoverContent;\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": "wMAWA,8EAOA,sFAKA,2DAMA,qDAEA,uDACA,mDACA,yDACA,4DAGA,K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