@spectrum-web-components/overlay 0.15.0 → 0.15.2
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/active-overlay.d.ts +6 -0
- package/active-overlay.js +14 -0
- package/active-overlay.js.map +1 -0
- package/custom-elements.json +6 -6
- package/overlay-trigger.d.ts +6 -0
- package/overlay-trigger.js +14 -0
- package/overlay-trigger.js.map +1 -0
- package/package.json +6 -6
- package/src/ActiveOverlay.d.ts +77 -0
- package/src/ActiveOverlay.js +436 -0
- package/src/ActiveOverlay.js.map +1 -0
- package/src/OverlayTrigger.d.ts +66 -0
- package/src/OverlayTrigger.js +310 -0
- package/src/OverlayTrigger.js.map +1 -0
- package/src/VirtualTrigger.d.ts +7 -0
- package/src/VirtualTrigger.js +40 -0
- package/src/VirtualTrigger.js.map +1 -0
- package/src/active-overlay.css.d.ts +2 -0
- package/src/active-overlay.css.js +21 -0
- package/src/active-overlay.css.js.map +1 -0
- package/src/index.d.ts +6 -0
- package/src/index.js +18 -0
- package/src/index.js.map +1 -0
- package/src/loader.d.ts +2 -0
- package/src/loader.js +16 -0
- package/src/loader.js.map +1 -0
- package/src/overlay-stack.d.ts +46 -0
- package/src/overlay-stack.js +449 -0
- package/src/overlay-stack.js.map +1 -0
- package/src/overlay-timer.d.ts +22 -0
- package/src/overlay-timer.js +89 -0
- package/src/overlay-timer.js.map +1 -0
- package/src/overlay-trigger.css.d.ts +2 -0
- package/src/overlay-trigger.css.js +17 -0
- package/src/overlay-trigger.css.js.map +1 -0
- package/src/overlay-types.d.ts +52 -0
- package/src/overlay-types.js +13 -0
- package/src/overlay-types.js.map +1 -0
- package/src/overlay.d.ts +59 -0
- package/src/overlay.js +119 -0
- package/src/overlay.js.map +1 -0
- package/stories/overlay-story-components.js +292 -0
- package/stories/overlay-story-components.js.map +1 -0
- package/stories/overlay.stories.js +805 -0
- package/stories/overlay.stories.js.map +1 -0
- package/sync/overlay-trigger.d.ts +1 -0
- package/sync/overlay-trigger.js +18 -0
- package/sync/overlay-trigger.js.map +1 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_WARMUP = 1000;
|
|
13
|
+
const DEFAULT_COOLDOWN = 1000;
|
|
14
|
+
/**
|
|
15
|
+
* A timer to help with implementation of warnup/cooldown behavior as described here:
|
|
16
|
+
* https://spectrum.adobe.com/page/tooltip/#Immediate-or-delayed-appearance
|
|
17
|
+
*/
|
|
18
|
+
export class OverlayTimer {
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
this.warmUpDelay = DEFAULT_WARMUP;
|
|
21
|
+
this.coolDownDelay = DEFAULT_COOLDOWN;
|
|
22
|
+
this.isWarm = false;
|
|
23
|
+
this.timeout = 0;
|
|
24
|
+
Object.assign(this, options);
|
|
25
|
+
}
|
|
26
|
+
async openTimer(component) {
|
|
27
|
+
this.cancelCooldownTimer();
|
|
28
|
+
if (!this.component || component !== this.component) {
|
|
29
|
+
if (this.component) {
|
|
30
|
+
this.close(this.component);
|
|
31
|
+
this.cancelCooldownTimer();
|
|
32
|
+
}
|
|
33
|
+
this.component = component;
|
|
34
|
+
if (this.isWarm) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
this.promise = new Promise((resolve) => {
|
|
38
|
+
this.resolve = resolve;
|
|
39
|
+
this.timeout = window.setTimeout(() => {
|
|
40
|
+
if (this.resolve) {
|
|
41
|
+
this.resolve(false);
|
|
42
|
+
this.isWarm = true;
|
|
43
|
+
}
|
|
44
|
+
}, this.warmUpDelay);
|
|
45
|
+
});
|
|
46
|
+
return this.promise;
|
|
47
|
+
}
|
|
48
|
+
else if (this.promise) {
|
|
49
|
+
return this.promise;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// This should never happen
|
|
53
|
+
throw new Error('Inconsistent state');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
close(component) {
|
|
57
|
+
if (this.component && this.component === component) {
|
|
58
|
+
this.resetCooldownTimer();
|
|
59
|
+
if (this.timeout > 0) {
|
|
60
|
+
clearTimeout(this.timeout);
|
|
61
|
+
this.timeout = 0;
|
|
62
|
+
}
|
|
63
|
+
if (this.resolve) {
|
|
64
|
+
this.resolve(true);
|
|
65
|
+
delete this.resolve;
|
|
66
|
+
}
|
|
67
|
+
delete this.promise;
|
|
68
|
+
delete this.component;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
resetCooldownTimer() {
|
|
72
|
+
if (this.isWarm) {
|
|
73
|
+
if (this.cooldownTimeout) {
|
|
74
|
+
window.clearTimeout(this.cooldownTimeout);
|
|
75
|
+
}
|
|
76
|
+
this.cooldownTimeout = window.setTimeout(() => {
|
|
77
|
+
this.isWarm = false;
|
|
78
|
+
delete this.cooldownTimeout;
|
|
79
|
+
}, this.coolDownDelay);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
cancelCooldownTimer() {
|
|
83
|
+
if (this.cooldownTimeout) {
|
|
84
|
+
window.clearTimeout(this.cooldownTimeout);
|
|
85
|
+
}
|
|
86
|
+
delete this.cooldownTimeout;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=overlay-timer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay-timer.js","sourceRoot":"","sources":["overlay-timer.ts"],"names":[],"mappings":"AAA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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"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { css } from '@spectrum-web-components/base';
|
|
13
|
+
const styles = css `
|
|
14
|
+
:host([disabled]) ::slotted([slot=trigger]){pointer-events:none}#overlay-content{display:none}
|
|
15
|
+
`;
|
|
16
|
+
export default styles;
|
|
17
|
+
//# sourceMappingURL=overlay-trigger.css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay-trigger.css.js","sourceRoot":"","sources":["overlay-trigger.css.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AACpD,MAAM,MAAM,GAAG,GAAG,CAAA;;CAEjB,CAAC;AACF,eAAe,MAAM,CAAC","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 { css } from '@spectrum-web-components/base';\nconst styles = css`\n:host([disabled]) ::slotted([slot=trigger]){pointer-events:none}#overlay-content{display:none}\n`;\nexport default styles;"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ThemeData } from '@spectrum-web-components/theme/src/Theme.js';
|
|
2
|
+
import type { Placement as FloatingUIPlacement } from '@floating-ui/dom';
|
|
3
|
+
import type { VirtualTrigger } from './VirtualTrigger.js';
|
|
4
|
+
export declare type TriggerInteractions = 'click' | 'longpress' | 'hover' | 'custom' | 'replace' | 'inline' | 'modal';
|
|
5
|
+
export interface OverlayOpenDetail {
|
|
6
|
+
content: HTMLElement;
|
|
7
|
+
contentTip?: HTMLElement;
|
|
8
|
+
delayed: boolean;
|
|
9
|
+
offset: number;
|
|
10
|
+
skidding?: number;
|
|
11
|
+
placement?: Placement;
|
|
12
|
+
receivesFocus?: 'auto';
|
|
13
|
+
virtualTrigger?: VirtualTrigger;
|
|
14
|
+
trigger: HTMLElement;
|
|
15
|
+
interaction: TriggerInteractions;
|
|
16
|
+
theme: ThemeData;
|
|
17
|
+
notImmediatelyClosable?: boolean;
|
|
18
|
+
abortPromise?: Promise<boolean>;
|
|
19
|
+
}
|
|
20
|
+
export interface OverlayOpenCloseDetail {
|
|
21
|
+
interaction: TriggerInteractions;
|
|
22
|
+
reason?: 'external-click';
|
|
23
|
+
}
|
|
24
|
+
export interface OverlayCloseReasonDetail {
|
|
25
|
+
reason?: 'external-click';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Used, via an event, to query details about how an element should be shown in
|
|
29
|
+
* an overlay
|
|
30
|
+
*/
|
|
31
|
+
export interface OverlayDisplayQueryDetail {
|
|
32
|
+
overlayRootName?: string;
|
|
33
|
+
overlayRootElement?: HTMLElement;
|
|
34
|
+
overlayContentTipElement?: HTMLElement;
|
|
35
|
+
}
|
|
36
|
+
export declare type Placement = FloatingUIPlacement | 'none';
|
|
37
|
+
export declare type OverlayOptions = {
|
|
38
|
+
delayed?: boolean;
|
|
39
|
+
placement?: Placement;
|
|
40
|
+
offset?: number;
|
|
41
|
+
receivesFocus?: 'auto';
|
|
42
|
+
notImmediatelyClosable?: boolean;
|
|
43
|
+
abortPromise?: Promise<boolean>;
|
|
44
|
+
virtualTrigger?: VirtualTrigger;
|
|
45
|
+
};
|
|
46
|
+
declare global {
|
|
47
|
+
interface GlobalEventHandlersEventMap {
|
|
48
|
+
'sp-overlay-query': CustomEvent<OverlayDisplayQueryDetail>;
|
|
49
|
+
'sp-open': CustomEvent<OverlayOpenCloseDetail>;
|
|
50
|
+
'sp-close': CustomEvent<OverlayOpenCloseDetail>;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=overlay-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay-types.js","sourceRoot":"","sources":["overlay-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE","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 { Placement as FloatingUIPlacement } from '@floating-ui/dom';\nimport type { VirtualTrigger } from './VirtualTrigger.js';\n\nexport type TriggerInteractions =\n | 'click'\n | 'longpress'\n | 'hover'\n | 'custom'\n | 'replace'\n | 'inline'\n | 'modal';\n\nexport interface OverlayOpenDetail {\n content: HTMLElement;\n contentTip?: HTMLElement;\n delayed: boolean;\n offset: number;\n skidding?: number;\n placement?: Placement;\n receivesFocus?: 'auto';\n virtualTrigger?: VirtualTrigger;\n trigger: HTMLElement;\n interaction: TriggerInteractions;\n theme: ThemeData;\n notImmediatelyClosable?: boolean;\n abortPromise?: Promise<boolean>;\n}\n\nexport interface OverlayOpenCloseDetail {\n interaction: TriggerInteractions;\n reason?: 'external-click';\n}\n\nexport interface OverlayCloseReasonDetail {\n reason?: 'external-click';\n}\n\n/**\n * Used, via an event, to query details about how an element should be shown in\n * an overlay\n */\nexport interface OverlayDisplayQueryDetail {\n overlayRootName?: string;\n overlayRootElement?: HTMLElement;\n overlayContentTipElement?: HTMLElement;\n}\n\nexport type Placement = FloatingUIPlacement | 'none';\n\nexport type OverlayOptions = {\n delayed?: boolean;\n placement?: Placement;\n offset?: number;\n receivesFocus?: 'auto';\n notImmediatelyClosable?: boolean;\n abortPromise?: Promise<boolean>;\n virtualTrigger?: VirtualTrigger;\n};\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'sp-overlay-query': CustomEvent<OverlayDisplayQueryDetail>;\n 'sp-open': CustomEvent<OverlayOpenCloseDetail>;\n 'sp-close': CustomEvent<OverlayOpenCloseDetail>;\n }\n}\n"]}
|
package/src/overlay.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { OverlayOptions, TriggerInteractions } from './overlay-types';
|
|
2
|
+
/**
|
|
3
|
+
* This class allows access to the overlay system which allows a client to
|
|
4
|
+
* position an element in the overlay positioned relative to another node.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Overlay {
|
|
7
|
+
private static overlayStack;
|
|
8
|
+
private isOpen;
|
|
9
|
+
private overlayElement;
|
|
10
|
+
private owner;
|
|
11
|
+
private interaction;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param owner the parent element we will use to position the overlay element
|
|
15
|
+
* @param interaction the type of interaction that caused this overlay to be shown
|
|
16
|
+
* @param overlayElement the item to display as an overlay
|
|
17
|
+
*/
|
|
18
|
+
constructor(owner: HTMLElement, interaction: TriggerInteractions, overlayElement: HTMLElement);
|
|
19
|
+
/**
|
|
20
|
+
* Open an overlay
|
|
21
|
+
*
|
|
22
|
+
* @param owner the parent element we will use to position the overlay element
|
|
23
|
+
* @param interaction the type of interaction that caused this overlay to be shown
|
|
24
|
+
* @param overlayElement the item to display as an overlay
|
|
25
|
+
* @param options display parameters
|
|
26
|
+
* @param options.delayed if true delay opening of the overlay based on the global warmup/cooldown timer
|
|
27
|
+
* @param options.offset distance to offset the overlay
|
|
28
|
+
* @param options.placement side on which to position the overlay
|
|
29
|
+
* @returns an Overlay object which can be used to close the overlay
|
|
30
|
+
*/
|
|
31
|
+
static open(owner: HTMLElement, interaction: TriggerInteractions, overlayElement: HTMLElement, options: OverlayOptions): Promise<() => void>;
|
|
32
|
+
static update(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Open an overlay
|
|
35
|
+
*
|
|
36
|
+
* @param options display parameters
|
|
37
|
+
* @param options.delayed delay before opening the overlay
|
|
38
|
+
* @param options.offset distance to offset the overlay
|
|
39
|
+
* @param options.placement side on which to position the overlay
|
|
40
|
+
* @returns a Promise that resolves to true if this operation was cancelled
|
|
41
|
+
*/
|
|
42
|
+
open({ abortPromise, delayed, offset, placement, receivesFocus, notImmediatelyClosable, virtualTrigger, }: OverlayOptions): Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* Close the overlay if it is open
|
|
45
|
+
*/
|
|
46
|
+
close(): void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Announces that an overlay-based UI element has opened
|
|
50
|
+
* @event sp-open
|
|
51
|
+
* @type {object}
|
|
52
|
+
* @property {TriggerInteractions} interaction type of interaction that triggered the opening
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* Announces that an overlay-based UI element has opened
|
|
56
|
+
* @event sp-close
|
|
57
|
+
* @type {object}
|
|
58
|
+
* @property {TriggerInteractions} interaction type of interaction that triggered the closing
|
|
59
|
+
*/
|
package/src/overlay.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { OverlayStack } from './overlay-stack.js';
|
|
13
|
+
/**
|
|
14
|
+
* This class allows access to the overlay system which allows a client to
|
|
15
|
+
* position an element in the overlay positioned relative to another node.
|
|
16
|
+
*/
|
|
17
|
+
export class Overlay {
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param owner the parent element we will use to position the overlay element
|
|
21
|
+
* @param interaction the type of interaction that caused this overlay to be shown
|
|
22
|
+
* @param overlayElement the item to display as an overlay
|
|
23
|
+
*/
|
|
24
|
+
constructor(owner, interaction, overlayElement) {
|
|
25
|
+
this.isOpen = false;
|
|
26
|
+
this.owner = owner;
|
|
27
|
+
this.overlayElement = overlayElement;
|
|
28
|
+
this.interaction = interaction;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Open an overlay
|
|
32
|
+
*
|
|
33
|
+
* @param owner the parent element we will use to position the overlay element
|
|
34
|
+
* @param interaction the type of interaction that caused this overlay to be shown
|
|
35
|
+
* @param overlayElement the item to display as an overlay
|
|
36
|
+
* @param options display parameters
|
|
37
|
+
* @param options.delayed if true delay opening of the overlay based on the global warmup/cooldown timer
|
|
38
|
+
* @param options.offset distance to offset the overlay
|
|
39
|
+
* @param options.placement side on which to position the overlay
|
|
40
|
+
* @returns an Overlay object which can be used to close the overlay
|
|
41
|
+
*/
|
|
42
|
+
static async open(owner, interaction, overlayElement, options) {
|
|
43
|
+
const overlay = new Overlay(owner, interaction, overlayElement);
|
|
44
|
+
await overlay.open(options);
|
|
45
|
+
return () => {
|
|
46
|
+
overlay.close();
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
static update() {
|
|
50
|
+
const overlayUpdateEvent = new CustomEvent('sp-update-overlays', {
|
|
51
|
+
bubbles: true,
|
|
52
|
+
composed: true,
|
|
53
|
+
cancelable: true,
|
|
54
|
+
});
|
|
55
|
+
document.dispatchEvent(overlayUpdateEvent);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Open an overlay
|
|
59
|
+
*
|
|
60
|
+
* @param options display parameters
|
|
61
|
+
* @param options.delayed delay before opening the overlay
|
|
62
|
+
* @param options.offset distance to offset the overlay
|
|
63
|
+
* @param options.placement side on which to position the overlay
|
|
64
|
+
* @returns a Promise that resolves to true if this operation was cancelled
|
|
65
|
+
*/
|
|
66
|
+
async open({ abortPromise, delayed, offset = 0, placement = 'top', receivesFocus, notImmediatelyClosable, virtualTrigger, }) {
|
|
67
|
+
/* c8 ignore next */
|
|
68
|
+
if (this.isOpen)
|
|
69
|
+
return true;
|
|
70
|
+
if (delayed === undefined) {
|
|
71
|
+
delayed = this.overlayElement.hasAttribute('delayed');
|
|
72
|
+
}
|
|
73
|
+
const queryThemeDetail = {
|
|
74
|
+
color: undefined,
|
|
75
|
+
scale: undefined,
|
|
76
|
+
lang: undefined,
|
|
77
|
+
};
|
|
78
|
+
const queryThemeEvent = new CustomEvent('sp-query-theme', {
|
|
79
|
+
bubbles: true,
|
|
80
|
+
composed: true,
|
|
81
|
+
detail: queryThemeDetail,
|
|
82
|
+
cancelable: true,
|
|
83
|
+
});
|
|
84
|
+
this.owner.dispatchEvent(queryThemeEvent);
|
|
85
|
+
const overlayDetailQuery = {};
|
|
86
|
+
const queryOverlayDetailEvent = new CustomEvent('sp-overlay-query', {
|
|
87
|
+
bubbles: true,
|
|
88
|
+
composed: true,
|
|
89
|
+
detail: overlayDetailQuery,
|
|
90
|
+
cancelable: true,
|
|
91
|
+
});
|
|
92
|
+
this.overlayElement.dispatchEvent(queryOverlayDetailEvent);
|
|
93
|
+
await Overlay.overlayStack.openOverlay(Object.assign({ abortPromise, content: this.overlayElement, contentTip: overlayDetailQuery.overlayContentTipElement, delayed, offset: offset, placement: placement, trigger: this.owner, interaction: this.interaction, theme: queryThemeDetail, receivesFocus,
|
|
94
|
+
notImmediatelyClosable,
|
|
95
|
+
virtualTrigger }, overlayDetailQuery));
|
|
96
|
+
this.isOpen = true;
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Close the overlay if it is open
|
|
101
|
+
*/
|
|
102
|
+
close() {
|
|
103
|
+
Overlay.overlayStack.closeOverlay(this.overlayElement);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
Overlay.overlayStack = new OverlayStack();
|
|
107
|
+
/**
|
|
108
|
+
* Announces that an overlay-based UI element has opened
|
|
109
|
+
* @event sp-open
|
|
110
|
+
* @type {object}
|
|
111
|
+
* @property {TriggerInteractions} interaction type of interaction that triggered the opening
|
|
112
|
+
*/
|
|
113
|
+
/**
|
|
114
|
+
* Announces that an overlay-based UI element has opened
|
|
115
|
+
* @event sp-close
|
|
116
|
+
* @type {object}
|
|
117
|
+
* @property {TriggerInteractions} interaction type of interaction that triggered the closing
|
|
118
|
+
*/
|
|
119
|
+
//# sourceMappingURL=overlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay.js","sourceRoot":"","sources":["overlay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAQF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;GAGG;AACH,MAAM,OAAO,OAAO;IAQhB;;;;;OAKG;IACH,YACI,KAAkB,EAClB,WAAgC,EAChC,cAA2B;QAdvB,WAAM,GAAG,KAAK,CAAC;QAgBnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;IAED;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,KAAK,CAAC,IAAI,CACpB,KAAkB,EAClB,WAAgC,EAChC,cAA2B,EAC3B,OAAuB;QAEvB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;QAChE,MAAM,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5B,OAAO,GAAS,EAAE;YACd,OAAO,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC,CAAC;IACN,CAAC;IAEM,MAAM,CAAC,MAAM;QAChB,MAAM,kBAAkB,GAAG,IAAI,WAAW,CAAC,oBAAoB,EAAE;YAC7D,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,QAAQ,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;;;OAQG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gB,EACvB,aAAa;YACb,sBAAsB;YACtB,cAAc,IACX,kBAAkB,EACvB,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,KAAK;QACR,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC3D,CAAC;;AAjIc,oBAAY,GAAG,IAAI,YAAY,EAAE,CAAC;AAoIrD;;;;;GAKG;AAEH;;;;;GAKG","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 }: 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 };\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 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"]}
|