@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
|
@@ -35,18 +35,53 @@ const getFallbackPlacements = (placement) => {
|
|
|
35
35
|
};
|
|
36
36
|
export const placementUpdatedSymbol = Symbol("placement updated");
|
|
37
37
|
export class PlacementController {
|
|
38
|
+
/**
|
|
39
|
+
* Creates an instance of the PlacementController.
|
|
40
|
+
*
|
|
41
|
+
* @param {ReactiveElement & { elements: OpenableElement[] }} host - The host element that uses this controller.
|
|
42
|
+
*/
|
|
38
43
|
constructor(host) {
|
|
44
|
+
/**
|
|
45
|
+
* A WeakMap to store the original placements of overlay elements.
|
|
46
|
+
*
|
|
47
|
+
* @private
|
|
48
|
+
* @type {WeakMap<HTMLElement, Placement>}
|
|
49
|
+
*/
|
|
39
50
|
this.originalPlacements = /* @__PURE__ */ new WeakMap();
|
|
51
|
+
/**
|
|
52
|
+
* Flag to allow or disallow placement updates.
|
|
53
|
+
*
|
|
54
|
+
* @type {boolean}
|
|
55
|
+
*/
|
|
40
56
|
this.allowPlacementUpdate = false;
|
|
57
|
+
/**
|
|
58
|
+
* Closes the overlay if an ancestor element is updated.
|
|
59
|
+
*
|
|
60
|
+
* This method checks if placement updates are allowed and if the overlay type is not 'modal'.
|
|
61
|
+
* If these conditions are met and a cleanup function is defined, it dispatches a 'close' event
|
|
62
|
+
* on the target element to close the overlay.
|
|
63
|
+
*/
|
|
41
64
|
this.closeForAncestorUpdate = () => {
|
|
42
65
|
if (!this.allowPlacementUpdate && this.options.type !== "modal" && this.cleanup) {
|
|
43
66
|
this.target.dispatchEvent(new Event("close", { bubbles: true }));
|
|
44
67
|
}
|
|
45
68
|
this.allowPlacementUpdate = false;
|
|
46
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Updates the placement of the overlay.
|
|
72
|
+
*
|
|
73
|
+
* This method calls the computePlacement method to recalculate the overlay's position.
|
|
74
|
+
*
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
47
77
|
this.updatePlacement = () => {
|
|
48
78
|
this.computePlacement();
|
|
49
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* Resets the overlay's position.
|
|
82
|
+
*
|
|
83
|
+
* This method clears the overlay's position, forces a reflow, and recomputes the placement.
|
|
84
|
+
*/
|
|
50
85
|
this.resetOverlayPosition = () => {
|
|
51
86
|
if (!this.target || !this.options) return;
|
|
52
87
|
this.clearOverlayPosition();
|
|
@@ -56,6 +91,16 @@ export class PlacementController {
|
|
|
56
91
|
this.host = host;
|
|
57
92
|
this.host.addController(this);
|
|
58
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Places the overlay relative to the target element.
|
|
96
|
+
*
|
|
97
|
+
* This method sets up the necessary configurations and event listeners to manage the
|
|
98
|
+
* positioning and constraints of the overlay element.
|
|
99
|
+
*
|
|
100
|
+
* @param {HTMLElement} [target=this.target] - The target element for the overlay.
|
|
101
|
+
* @param {OverlayOptionsV1} [options=this.options] - The options for configuring the overlay placement.
|
|
102
|
+
* @returns {Promise<void>} A promise that resolves when the overlay has been placed.
|
|
103
|
+
*/
|
|
59
104
|
async placeOverlay(target = this.target, options = this.options) {
|
|
60
105
|
this.target = target;
|
|
61
106
|
this.options = options;
|
|
@@ -97,6 +142,15 @@ export class PlacementController {
|
|
|
97
142
|
cleanupElementResize();
|
|
98
143
|
};
|
|
99
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Computes the placement of the overlay relative to the target element.
|
|
147
|
+
*
|
|
148
|
+
* This method calculates the necessary positioning and constraints for the overlay element
|
|
149
|
+
* using various middleware functions. It updates the overlay's style and attributes based
|
|
150
|
+
* on the computed position.
|
|
151
|
+
*
|
|
152
|
+
* @returns {Promise<void>} A promise that resolves when the placement has been computed.
|
|
153
|
+
*/
|
|
100
154
|
async computePlacement() {
|
|
101
155
|
var _a, _b;
|
|
102
156
|
const { options, target } = this;
|
|
@@ -177,6 +231,12 @@ export class PlacementController {
|
|
|
177
231
|
});
|
|
178
232
|
}
|
|
179
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Clears the overlay's position styles.
|
|
236
|
+
*
|
|
237
|
+
* This method removes the max-height and max-width styles from the target element,
|
|
238
|
+
* and resets the initial height and constrained state of the overlay.
|
|
239
|
+
*/
|
|
180
240
|
clearOverlayPosition() {
|
|
181
241
|
if (!this.target) {
|
|
182
242
|
return;
|
|
@@ -186,12 +246,22 @@ export class PlacementController {
|
|
|
186
246
|
this.initialHeight = void 0;
|
|
187
247
|
this.isConstrained = false;
|
|
188
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Lifecycle method called when the host element is connected to the DOM.
|
|
251
|
+
*
|
|
252
|
+
* This method sets up an event listener to reset the overlay's position when the 'sp-update-overlays' event is dispatched.
|
|
253
|
+
*/
|
|
189
254
|
hostConnected() {
|
|
190
255
|
document.addEventListener(
|
|
191
256
|
"sp-update-overlays",
|
|
192
257
|
this.resetOverlayPosition
|
|
193
258
|
);
|
|
194
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* Lifecycle method called when the host element is updated.
|
|
262
|
+
*
|
|
263
|
+
* This method cleans up resources if the overlay is not open.
|
|
264
|
+
*/
|
|
195
265
|
hostUpdated() {
|
|
196
266
|
var _a;
|
|
197
267
|
if (!this.host.open) {
|
|
@@ -199,6 +269,11 @@ export class PlacementController {
|
|
|
199
269
|
this.cleanup = void 0;
|
|
200
270
|
}
|
|
201
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Lifecycle method called when the host element is disconnected from the DOM.
|
|
274
|
+
*
|
|
275
|
+
* This method removes the event listener and cleans up resources.
|
|
276
|
+
*/
|
|
202
277
|
hostDisconnected() {
|
|
203
278
|
var _a;
|
|
204
279
|
(_a = this.cleanup) == null ? void 0 : _a.call(this);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["PlacementController.ts"],
|
|
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 {\n ReactiveController,\n ReactiveElement,\n} from '@spectrum-web-components/base';\nimport {\n arrow,\n autoUpdate,\n computePosition,\n flip,\n offset,\n Placement,\n shift,\n size,\n} from '@floating-ui/dom';\nimport type { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport type { OpenableElement } from './overlay-types.dev.js'\nimport type { Overlay } from './Overlay.dev.js'\n\ntype OverlayOptionsV1 = {\n abortPromise?: Promise<boolean>;\n delayed?: boolean;\n offset?: number | [number, number]; // supporting multi-axis\n placement: Placement;\n notImmediatelyClosable?: boolean; // rename or place behind other API options\n receivesFocus?: 'auto';\n root?: HTMLElement;\n tipPadding?: number;\n trigger: HTMLElement | VirtualTrigger;\n type?: 'modal' | 'page' | 'hint' | 'auto' | 'manual';\n};\n\nfunction roundByDPR(num?: number): number {\n if (typeof num === 'undefined') return 0;\n const dpr = window.devicePixelRatio || 1;\n return Math.round(num * dpr) / dpr ?? -10000;\n}\n\n// See: https://spectrum.adobe.com/page/popover/#Container-padding\nconst REQUIRED_DISTANCE_TO_EDGE = 8;\n// See: https://github.com/adobe/spectrum-web-components/issues/910\nconst MIN_OVERLAY_HEIGHT = 100;\n\nconst getFallbackPlacements = (placement: Placement): Placement[] => {\n const fallbacks: Record<Placement, Placement[]> = {\n left: ['right', 'bottom', 'top'],\n 'left-start': ['right-start', 'bottom', 'top'],\n 'left-end': ['right-end', 'bottom', 'top'],\n right: ['left', 'bottom', 'top'],\n 'right-start': ['left-start', 'bottom', 'top'],\n 'right-end': ['left-end', 'bottom', 'top'],\n top: ['bottom', 'left', 'right'],\n 'top-start': ['bottom-start', 'left', 'right'],\n 'top-end': ['bottom-end', 'left', 'right'],\n bottom: ['top', 'left', 'right'],\n 'bottom-start': ['top-start', 'left', 'right'],\n 'bottom-end': ['top-end', 'left', 'right'],\n };\n return fallbacks[placement] ?? [placement];\n};\n\nexport const placementUpdatedSymbol = Symbol('placement updated');\n\nexport class PlacementController implements ReactiveController {\n private cleanup?: () => void;\n\n initialHeight?: number;\n\n isConstrained?: boolean;\n\n private host!: ReactiveElement & { elements: OpenableElement[] };\n\n private options!: OverlayOptionsV1;\n\n private originalPlacements = new WeakMap<HTMLElement, Placement>();\n\n private target!: HTMLElement;\n\n constructor(host: ReactiveElement & { elements: OpenableElement[] }) {\n this.host = host;\n // Add the controller after the MutationObserver has been created in preparation\n // for the `hostConnected`/`hostDisconnected` callbacks to be run.\n this.host.addController(this);\n }\n\n public async placeOverlay(\n target: HTMLElement = this.target,\n options: OverlayOptionsV1 = this.options\n ): Promise<void> {\n this.target = target;\n this.options = options;\n if (!target || !options) return;\n\n const cleanupAncestorResize = autoUpdate(\n options.trigger,\n target,\n this.closeForAncestorUpdate,\n {\n ancestorResize: false,\n elementResize: false,\n layoutShift: false,\n }\n );\n const cleanupElementResize = autoUpdate(\n options.trigger,\n target,\n this.updatePlacement,\n {\n ancestorScroll: false,\n }\n );\n this.cleanup = () => {\n this.host.elements?.forEach((element) => {\n element.addEventListener(\n 'sp-closed',\n () => {\n const placement = this.originalPlacements.get(element);\n if (placement) {\n element.setAttribute('placement', placement);\n }\n this.originalPlacements.delete(element);\n },\n { once: true }\n );\n });\n cleanupAncestorResize();\n cleanupElementResize();\n };\n }\n\n allowPlacementUpdate = false;\n\n closeForAncestorUpdate = (): void => {\n if (\n !this.allowPlacementUpdate &&\n this.options.type !== 'modal' &&\n this.cleanup\n ) {\n this.target.dispatchEvent(new Event('close', { bubbles: true }));\n }\n this.allowPlacementUpdate = false;\n };\n\n updatePlacement = (): void => {\n this.computePlacement();\n };\n\n async computePlacement(): Promise<void> {\n const { options, target } = this;\n\n await (document.fonts ? document.fonts.ready : Promise.resolve());\n\n const flipMiddleware = !(options.trigger instanceof HTMLElement)\n ? flip({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n fallbackPlacements: getFallbackPlacements(options.placement),\n })\n : flip();\n\n const [mainAxis = 0, crossAxis = 0] = Array.isArray(options?.offset)\n ? options.offset\n : [options.offset, 0];\n\n const tipElement = this.host.elements.find(\n (el) => el.tipElement\n )?.tipElement;\n\n const middleware = [\n offset({\n mainAxis,\n crossAxis,\n }),\n shift({ padding: REQUIRED_DISTANCE_TO_EDGE }),\n flipMiddleware,\n size({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n apply: ({\n availableWidth,\n availableHeight,\n rects: { floating },\n }) => {\n const maxHeight = Math.max(\n MIN_OVERLAY_HEIGHT,\n Math.floor(availableHeight)\n );\n const actualHeight = floating.height;\n this.initialHeight = !this.isConstrained // && !this.virtualTrigger\n ? actualHeight\n : this.initialHeight || actualHeight;\n this.isConstrained =\n actualHeight < this.initialHeight ||\n maxHeight <= actualHeight;\n const appliedHeight = this.isConstrained\n ? `${maxHeight}px`\n : '';\n Object.assign(target.style, {\n maxWidth: `${Math.floor(availableWidth)}px`,\n maxHeight: appliedHeight,\n });\n },\n }),\n ...(tipElement\n ? [\n arrow({\n element: tipElement,\n padding:\n options.tipPadding || REQUIRED_DISTANCE_TO_EDGE,\n }),\n ]\n : []),\n ];\n const { x, y, placement, middlewareData } = await computePosition(\n options.trigger,\n target,\n {\n placement: options.placement,\n middleware,\n strategy: 'fixed',\n }\n );\n Object.assign(target.style, {\n top: '0px',\n left: '0px',\n translate: `${roundByDPR(x)}px ${roundByDPR(y)}px`,\n });\n\n target.setAttribute('actual-placement', placement);\n this.host.elements?.forEach((element) => {\n if (!this.originalPlacements.has(element)) {\n this.originalPlacements.set(\n element,\n element.getAttribute('placement') as Placement\n );\n }\n element.setAttribute('placement', placement);\n });\n\n if (tipElement && middlewareData.arrow) {\n const { x: arrowX, y: arrowY } = middlewareData.arrow;\n\n Object.assign(tipElement.style, {\n top:\n placement.startsWith('right') ||\n placement.startsWith('left')\n ? '0px'\n : '',\n left:\n placement.startsWith('bottom') ||\n placement.startsWith('top')\n ? '0px'\n : '',\n translate: `${roundByDPR(arrowX)}px ${roundByDPR(arrowY)}px`,\n });\n }\n }\n\n public clearOverlayPosition(): void {\n if (!this.target) {\n return;\n }\n this.target.style.removeProperty('max-height');\n this.target.style.removeProperty('max-width');\n this.initialHeight = undefined;\n this.isConstrained = false;\n }\n\n public resetOverlayPosition = (): void => {\n if (!this.target || !this.options) return;\n this.clearOverlayPosition();\n\n // force paint\n this.host.offsetHeight;\n this.computePlacement();\n };\n\n hostConnected(): void {\n document.addEventListener(\n 'sp-update-overlays',\n this.resetOverlayPosition\n );\n }\n\n hostUpdated(): void {\n if (!(this.host as Overlay).open) {\n this.cleanup?.();\n this.cleanup = undefined;\n }\n }\n\n hostDisconnected(): void {\n this.cleanup?.();\n this.cleanup = undefined;\n document.removeEventListener(\n 'sp-update-overlays',\n this.resetOverlayPosition\n );\n }\n}\n"],
|
|
5
|
-
"mappings": ";AAgBA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACG;
|
|
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 {\n ReactiveController,\n ReactiveElement,\n} from '@spectrum-web-components/base';\nimport {\n arrow,\n autoUpdate,\n computePosition,\n flip,\n offset,\n Placement,\n shift,\n size,\n} from '@floating-ui/dom';\nimport type { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport type { OpenableElement } from './overlay-types.dev.js'\nimport type { Overlay } from './Overlay.dev.js'\n\ntype OverlayOptionsV1 = {\n abortPromise?: Promise<boolean>;\n delayed?: boolean;\n offset?: number | [number, number]; // supporting multi-axis\n placement: Placement;\n notImmediatelyClosable?: boolean; // rename or place behind other API options\n receivesFocus?: 'auto';\n root?: HTMLElement;\n tipPadding?: number;\n trigger: HTMLElement | VirtualTrigger;\n type?: 'modal' | 'page' | 'hint' | 'auto' | 'manual';\n};\n\n/**\n * Rounds a number by the device pixel ratio (DPR).\n *\n * @param {number} [num] - The number to round.\n * @returns {number} The rounded number.\n */\nfunction roundByDPR(num?: number): number {\n if (typeof num === 'undefined') return 0;\n const dpr = window.devicePixelRatio || 1;\n return Math.round(num * dpr) / dpr;\n}\n\n// Minimum distance required between the overlay and the edge of the container.\n// See: https://spectrum.adobe.com/page/popover/#Container-padding\nconst REQUIRED_DISTANCE_TO_EDGE = 8;\n// Minimum height for the overlay.\n// See: https://github.com/adobe/spectrum-web-components/issues/910\nconst MIN_OVERLAY_HEIGHT = 100;\n\n/**\n * Gets fallback placements for the overlay based on the initial placement.\n *\n * @param {Placement} placement - The initial placement of the overlay.\n * @returns {Placement[]} An array of fallback placements.\n */\nconst getFallbackPlacements = (placement: Placement): Placement[] => {\n const fallbacks: Record<Placement, Placement[]> = {\n left: ['right', 'bottom', 'top'],\n 'left-start': ['right-start', 'bottom', 'top'],\n 'left-end': ['right-end', 'bottom', 'top'],\n right: ['left', 'bottom', 'top'],\n 'right-start': ['left-start', 'bottom', 'top'],\n 'right-end': ['left-end', 'bottom', 'top'],\n top: ['bottom', 'left', 'right'],\n 'top-start': ['bottom-start', 'left', 'right'],\n 'top-end': ['bottom-end', 'left', 'right'],\n bottom: ['top', 'left', 'right'],\n 'bottom-start': ['top-start', 'left', 'right'],\n 'bottom-end': ['top-end', 'left', 'right'],\n };\n return fallbacks[placement] ?? [placement];\n};\n\n/**\n * Symbol used to indicate that the placement has been updated.\n */\nexport const placementUpdatedSymbol = Symbol('placement updated');\n\n/**\n * Controller for managing the placement of an overlay.\n *\n * This class implements the ReactiveController interface and provides methods\n * for managing the positioning and constraints of an overlay element.\n */\nexport class PlacementController implements ReactiveController {\n /**\n * Function to clean up resources when the controller is no longer needed.\n *\n * @private\n */\n private cleanup?: () => void;\n\n /**\n * Initial height of the overlay.\n *\n * @type {number}\n */\n initialHeight?: number;\n\n /**\n * Indicates whether the overlay is constrained by available space.\n *\n * @type {boolean}\n */\n isConstrained?: boolean;\n\n /**\n * The host element that uses this controller.\n *\n * @private\n * @type {ReactiveElement & { elements: OpenableElement[] }}\n */\n private host!: ReactiveElement & { elements: OpenableElement[] };\n\n /**\n * Options for configuring the overlay placement.\n *\n * @private\n * @type {OverlayOptionsV1}\n */\n private options!: OverlayOptionsV1;\n\n /**\n * A WeakMap to store the original placements of overlay elements.\n *\n * @private\n * @type {WeakMap<HTMLElement, Placement>}\n */\n private originalPlacements = new WeakMap<HTMLElement, Placement>();\n\n /**\n * The target element for the overlay.\n *\n * @private\n * @type {HTMLElement}\n */\n private target!: HTMLElement;\n\n /**\n * Creates an instance of the PlacementController.\n *\n * @param {ReactiveElement & { elements: OpenableElement[] }} host - The host element that uses this controller.\n */\n constructor(host: ReactiveElement & { elements: OpenableElement[] }) {\n this.host = host;\n // Add the controller after the MutationObserver has been created in preparation\n // for the `hostConnected`/`hostDisconnected` callbacks to be run.\n this.host.addController(this);\n }\n\n /**\n * Places the overlay relative to the target element.\n *\n * This method sets up the necessary configurations and event listeners to manage the\n * positioning and constraints of the overlay element.\n *\n * @param {HTMLElement} [target=this.target] - The target element for the overlay.\n * @param {OverlayOptionsV1} [options=this.options] - The options for configuring the overlay placement.\n * @returns {Promise<void>} A promise that resolves when the overlay has been placed.\n */\n public async placeOverlay(\n target: HTMLElement = this.target,\n options: OverlayOptionsV1 = this.options\n ): Promise<void> {\n // Set the target and options for the overlay.\n this.target = target;\n this.options = options;\n if (!target || !options) return;\n\n // Set up auto-update for ancestor resize events.\n const cleanupAncestorResize = autoUpdate(\n options.trigger,\n target,\n this.closeForAncestorUpdate,\n {\n ancestorResize: false,\n elementResize: false,\n layoutShift: false,\n }\n );\n\n // Set up auto-update for element resize events.\n const cleanupElementResize = autoUpdate(\n options.trigger,\n target,\n this.updatePlacement,\n {\n ancestorScroll: false,\n }\n );\n\n // Define the cleanup function to remove event listeners and reset placements.\n this.cleanup = () => {\n this.host.elements?.forEach((element) => {\n element.addEventListener(\n 'sp-closed',\n () => {\n const placement = this.originalPlacements.get(element);\n\n if (placement) {\n element.setAttribute('placement', placement);\n }\n\n this.originalPlacements.delete(element);\n },\n { once: true }\n );\n });\n cleanupAncestorResize();\n cleanupElementResize();\n };\n }\n\n /**\n * Flag to allow or disallow placement updates.\n *\n * @type {boolean}\n */\n public allowPlacementUpdate = false;\n\n /**\n * Closes the overlay if an ancestor element is updated.\n *\n * This method checks if placement updates are allowed and if the overlay type is not 'modal'.\n * If these conditions are met and a cleanup function is defined, it dispatches a 'close' event\n * on the target element to close the overlay.\n */\n closeForAncestorUpdate = (): void => {\n if (\n !this.allowPlacementUpdate &&\n this.options.type !== 'modal' &&\n this.cleanup\n ) {\n // Dispatch a 'close' event to close the overlay.\n this.target.dispatchEvent(new Event('close', { bubbles: true }));\n }\n\n // Reset the flag to disallow placement updates.\n this.allowPlacementUpdate = false;\n };\n\n /**\n * Updates the placement of the overlay.\n *\n * This method calls the computePlacement method to recalculate the overlay's position.\n *\n * @private\n */\n private updatePlacement = (): void => {\n this.computePlacement();\n };\n\n /**\n * Computes the placement of the overlay relative to the target element.\n *\n * This method calculates the necessary positioning and constraints for the overlay element\n * using various middleware functions. It updates the overlay's style and attributes based\n * on the computed position.\n *\n * @returns {Promise<void>} A promise that resolves when the placement has been computed.\n */\n async computePlacement(): Promise<void> {\n const { options, target } = this;\n\n // Wait for document fonts to be ready before computing placement.\n await (document.fonts ? document.fonts.ready : Promise.resolve());\n\n // Determine the flip middleware based on the type of trigger element.\n const flipMiddleware = !(options.trigger instanceof HTMLElement)\n ? flip({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n fallbackPlacements: getFallbackPlacements(options.placement),\n })\n : flip();\n\n // Extract main axis and cross axis offsets from options.\n const [mainAxis = 0, crossAxis = 0] = Array.isArray(options?.offset)\n ? options.offset\n : [options.offset, 0];\n\n // Find the tip element within the host elements.\n const tipElement = this.host.elements.find(\n (el) => el.tipElement\n )?.tipElement;\n\n // Define middleware functions for positioning and constraints.\n const middleware = [\n offset({\n mainAxis,\n crossAxis,\n }),\n shift({ padding: REQUIRED_DISTANCE_TO_EDGE }),\n flipMiddleware,\n size({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n apply: ({\n availableWidth,\n availableHeight,\n rects: { floating },\n }) => {\n const maxHeight = Math.max(\n MIN_OVERLAY_HEIGHT,\n Math.floor(availableHeight)\n );\n const actualHeight = floating.height;\n this.initialHeight = !this.isConstrained // && !this.virtualTrigger\n ? actualHeight\n : this.initialHeight || actualHeight;\n this.isConstrained =\n actualHeight < this.initialHeight ||\n maxHeight <= actualHeight;\n const appliedHeight = this.isConstrained\n ? `${maxHeight}px`\n : '';\n Object.assign(target.style, {\n maxWidth: `${Math.floor(availableWidth)}px`,\n maxHeight: appliedHeight,\n });\n },\n }),\n ...(tipElement\n ? [\n arrow({\n element: tipElement,\n padding:\n options.tipPadding || REQUIRED_DISTANCE_TO_EDGE,\n }),\n ]\n : []),\n ];\n\n // Compute the position of the overlay using the defined middleware.\n const { x, y, placement, middlewareData } = await computePosition(\n options.trigger,\n target,\n {\n placement: options.placement,\n middleware,\n strategy: 'fixed',\n }\n );\n\n // Update the overlay's style with the computed position.\n Object.assign(target.style, {\n top: '0px',\n left: '0px',\n translate: `${roundByDPR(x)}px ${roundByDPR(y)}px`,\n });\n\n // Set the 'actual-placement' attribute on the target element.\n target.setAttribute('actual-placement', placement);\n\n // Update the placement attribute for each host element.\n this.host.elements?.forEach((element) => {\n if (!this.originalPlacements.has(element)) {\n this.originalPlacements.set(\n element,\n element.getAttribute('placement') as Placement\n );\n }\n element.setAttribute('placement', placement);\n });\n\n // Update the tip element's style with the computed arrow position.\n if (tipElement && middlewareData.arrow) {\n const { x: arrowX, y: arrowY } = middlewareData.arrow;\n\n Object.assign(tipElement.style, {\n top:\n placement.startsWith('right') ||\n placement.startsWith('left')\n ? '0px'\n : '',\n left:\n placement.startsWith('bottom') ||\n placement.startsWith('top')\n ? '0px'\n : '',\n translate: `${roundByDPR(arrowX)}px ${roundByDPR(arrowY)}px`,\n });\n }\n }\n\n /**\n * Clears the overlay's position styles.\n *\n * This method removes the max-height and max-width styles from the target element,\n * and resets the initial height and constrained state of the overlay.\n */\n public clearOverlayPosition(): void {\n if (!this.target) {\n return;\n }\n // Remove max-height and max-width styles from the target element.\n this.target.style.removeProperty('max-height');\n this.target.style.removeProperty('max-width');\n // Reset the initial height and constrained state.\n this.initialHeight = undefined;\n this.isConstrained = false;\n }\n\n /**\n * Resets the overlay's position.\n *\n * This method clears the overlay's position, forces a reflow, and recomputes the placement.\n */\n public resetOverlayPosition = (): void => {\n if (!this.target || !this.options) return;\n // Clear the overlay's position.\n this.clearOverlayPosition();\n\n // Force a reflow.\n this.host.offsetHeight;\n // Recompute the placement.\n this.computePlacement();\n };\n\n /**\n * Lifecycle method called when the host element is connected to the DOM.\n *\n * This method sets up an event listener to reset the overlay's position when the 'sp-update-overlays' event is dispatched.\n */\n hostConnected(): void {\n document.addEventListener(\n 'sp-update-overlays',\n this.resetOverlayPosition\n );\n }\n\n /**\n * Lifecycle method called when the host element is updated.\n *\n * This method cleans up resources if the overlay is not open.\n */\n hostUpdated(): void {\n if (!(this.host as Overlay).open) {\n // Clean up resources if the overlay is not open.\n this.cleanup?.();\n this.cleanup = undefined;\n }\n }\n\n /**\n * Lifecycle method called when the host element is disconnected from the DOM.\n *\n * This method removes the event listener and cleans up resources.\n */\n hostDisconnected(): void {\n // Clean up resources.\n this.cleanup?.();\n this.cleanup = undefined;\n // Remove the event listener.\n document.removeEventListener(\n 'sp-update-overlays',\n this.resetOverlayPosition\n );\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAgBA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACG;AAwBP,SAAS,WAAW,KAAsB;AACtC,MAAI,OAAO,QAAQ,YAAa,QAAO;AACvC,QAAM,MAAM,OAAO,oBAAoB;AACvC,SAAO,KAAK,MAAM,MAAM,GAAG,IAAI;AACnC;AAIA,MAAM,4BAA4B;AAGlC,MAAM,qBAAqB;AAQ3B,MAAM,wBAAwB,CAAC,cAAsC;AApErE;AAqEI,QAAM,YAA4C;AAAA,IAC9C,MAAM,CAAC,SAAS,UAAU,KAAK;AAAA,IAC/B,cAAc,CAAC,eAAe,UAAU,KAAK;AAAA,IAC7C,YAAY,CAAC,aAAa,UAAU,KAAK;AAAA,IACzC,OAAO,CAAC,QAAQ,UAAU,KAAK;AAAA,IAC/B,eAAe,CAAC,cAAc,UAAU,KAAK;AAAA,IAC7C,aAAa,CAAC,YAAY,UAAU,KAAK;AAAA,IACzC,KAAK,CAAC,UAAU,QAAQ,OAAO;AAAA,IAC/B,aAAa,CAAC,gBAAgB,QAAQ,OAAO;AAAA,IAC7C,WAAW,CAAC,cAAc,QAAQ,OAAO;AAAA,IACzC,QAAQ,CAAC,OAAO,QAAQ,OAAO;AAAA,IAC/B,gBAAgB,CAAC,aAAa,QAAQ,OAAO;AAAA,IAC7C,cAAc,CAAC,WAAW,QAAQ,OAAO;AAAA,EAC7C;AACA,UAAO,eAAU,SAAS,MAAnB,YAAwB,CAAC,SAAS;AAC7C;AAKO,aAAM,yBAAyB,OAAO,mBAAmB;AAQzD,aAAM,oBAAkD;AAAA;AAAA;AAAA;AAAA;AAA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B,UAAU,WAAW,MAAM,IACrB,QACA;AAAA,QACV,MACI,UAAU,WAAW,QAAQ,KAC7B,UAAU,WAAW,KAAK,IACpB,QACA;AAAA,QACV,WAAW,GAAG,WAAW,MAAM,CAAC,MAAM,WAAW,MAAM,CAAC;AAAA,MAC5D,CAAC;AAAA,IACL;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,uBAA6B;AAChC,QAAI,CAAC,KAAK,QAAQ;AACd;AAAA,IACJ;AAEA,SAAK,OAAO,MAAM,eAAe,YAAY;AAC7C,SAAK,OAAO,MAAM,eAAe,WAAW;AAE5C,SAAK,gBAAgB;AACrB,SAAK,gBAAgB;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBA,gBAAsB;AAClB,aAAS;AAAA,MACL;AAAA,MACA,KAAK;AAAA,IACT;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,cAAoB;AA/bxB;AAgcQ,QAAI,CAAE,KAAK,KAAiB,MAAM;AAE9B,iBAAK,YAAL;AACA,WAAK,UAAU;AAAA,IACnB;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,mBAAyB;AA5c7B;AA8cQ,eAAK,YAAL;AACA,SAAK,UAAU;AAEf,aAAS;AAAA,MACL;AAAA,MACA,KAAK;AAAA,IACT;AAAA,EACJ;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["PlacementController.ts"],
|
|
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 {\n ReactiveController,\n ReactiveElement,\n} from '@spectrum-web-components/base';\nimport {\n arrow,\n autoUpdate,\n computePosition,\n flip,\n offset,\n Placement,\n shift,\n size,\n} from '@floating-ui/dom';\nimport type { VirtualTrigger } from './VirtualTrigger.js';\nimport type { OpenableElement } from './overlay-types.js';\nimport type { Overlay } from './Overlay.js';\n\ntype OverlayOptionsV1 = {\n abortPromise?: Promise<boolean>;\n delayed?: boolean;\n offset?: number | [number, number]; // supporting multi-axis\n placement: Placement;\n notImmediatelyClosable?: boolean; // rename or place behind other API options\n receivesFocus?: 'auto';\n root?: HTMLElement;\n tipPadding?: number;\n trigger: HTMLElement | VirtualTrigger;\n type?: 'modal' | 'page' | 'hint' | 'auto' | 'manual';\n};\n\nfunction roundByDPR(num?: number): number {\n if (typeof num === 'undefined') return 0;\n const dpr = window.devicePixelRatio || 1;\n return Math.round(num * dpr) / dpr ?? -10000;\n}\n\n// See: https://spectrum.adobe.com/page/popover/#Container-padding\nconst REQUIRED_DISTANCE_TO_EDGE = 8;\n// See: https://github.com/adobe/spectrum-web-components/issues/910\nconst MIN_OVERLAY_HEIGHT = 100;\n\nconst getFallbackPlacements = (placement: Placement): Placement[] => {\n const fallbacks: Record<Placement, Placement[]> = {\n left: ['right', 'bottom', 'top'],\n 'left-start': ['right-start', 'bottom', 'top'],\n 'left-end': ['right-end', 'bottom', 'top'],\n right: ['left', 'bottom', 'top'],\n 'right-start': ['left-start', 'bottom', 'top'],\n 'right-end': ['left-end', 'bottom', 'top'],\n top: ['bottom', 'left', 'right'],\n 'top-start': ['bottom-start', 'left', 'right'],\n 'top-end': ['bottom-end', 'left', 'right'],\n bottom: ['top', 'left', 'right'],\n 'bottom-start': ['top-start', 'left', 'right'],\n 'bottom-end': ['top-end', 'left', 'right'],\n };\n return fallbacks[placement] ?? [placement];\n};\n\nexport const placementUpdatedSymbol = Symbol('placement updated');\n\nexport class PlacementController implements ReactiveController {\n private cleanup?: () => void;\n\n initialHeight?: number;\n\n isConstrained?: boolean;\n\n private host!: ReactiveElement & { elements: OpenableElement[] };\n\n private options!: OverlayOptionsV1;\n\n private originalPlacements = new WeakMap<HTMLElement, Placement>();\n\n private target!: HTMLElement;\n\n constructor(host: ReactiveElement & { elements: OpenableElement[] }) {\n this.host = host;\n // Add the controller after the MutationObserver has been created in preparation\n // for the `hostConnected`/`hostDisconnected` callbacks to be run.\n this.host.addController(this);\n }\n\n public async placeOverlay(\n target: HTMLElement = this.target,\n options: OverlayOptionsV1 = this.options\n ): Promise<void> {\n this.target = target;\n this.options = options;\n if (!target || !options) return;\n\n const cleanupAncestorResize = autoUpdate(\n options.trigger,\n target,\n this.closeForAncestorUpdate,\n {\n ancestorResize: false,\n elementResize: false,\n layoutShift: false,\n }\n );\n const cleanupElementResize = autoUpdate(\n options.trigger,\n target,\n this.updatePlacement,\n {\n ancestorScroll: false,\n }\n );\n this.cleanup = () => {\n this.host.elements?.forEach((element) => {\n element.addEventListener(\n 'sp-closed',\n () => {\n const placement = this.originalPlacements.get(element);\n if (placement) {\n element.setAttribute('placement', placement);\n }\n this.originalPlacements.delete(element);\n },\n { once: true }\n );\n });\n cleanupAncestorResize();\n cleanupElementResize();\n };\n }\n\n allowPlacementUpdate = false;\n\n closeForAncestorUpdate = (): void => {\n if (\n !this.allowPlacementUpdate &&\n this.options.type !== 'modal' &&\n this.cleanup\n ) {\n this.target.dispatchEvent(new Event('close', { bubbles: true }));\n }\n this.allowPlacementUpdate = false;\n };\n\n updatePlacement = (): void => {\n this.computePlacement();\n };\n\n async computePlacement(): Promise<void> {\n const { options, target } = this;\n\n await (document.fonts ? document.fonts.ready : Promise.resolve());\n\n const flipMiddleware = !(options.trigger instanceof HTMLElement)\n ? flip({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n fallbackPlacements: getFallbackPlacements(options.placement),\n })\n : flip();\n\n const [mainAxis = 0, crossAxis = 0] = Array.isArray(options?.offset)\n ? options.offset\n : [options.offset, 0];\n\n const tipElement = this.host.elements.find(\n (el) => el.tipElement\n )?.tipElement;\n\n const middleware = [\n offset({\n mainAxis,\n crossAxis,\n }),\n shift({ padding: REQUIRED_DISTANCE_TO_EDGE }),\n flipMiddleware,\n size({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n apply: ({\n availableWidth,\n availableHeight,\n rects: { floating },\n }) => {\n const maxHeight = Math.max(\n MIN_OVERLAY_HEIGHT,\n Math.floor(availableHeight)\n );\n const actualHeight = floating.height;\n this.initialHeight = !this.isConstrained // && !this.virtualTrigger\n ? actualHeight\n : this.initialHeight || actualHeight;\n this.isConstrained =\n actualHeight < this.initialHeight ||\n maxHeight <= actualHeight;\n const appliedHeight = this.isConstrained\n ? `${maxHeight}px`\n : '';\n Object.assign(target.style, {\n maxWidth: `${Math.floor(availableWidth)}px`,\n maxHeight: appliedHeight,\n });\n },\n }),\n ...(tipElement\n ? [\n arrow({\n element: tipElement,\n padding:\n options.tipPadding || REQUIRED_DISTANCE_TO_EDGE,\n }),\n ]\n : []),\n ];\n const { x, y, placement, middlewareData } = await computePosition(\n options.trigger,\n target,\n {\n placement: options.placement,\n middleware,\n strategy: 'fixed',\n }\n );\n Object.assign(target.style, {\n top: '0px',\n left: '0px',\n translate: `${roundByDPR(x)}px ${roundByDPR(y)}px`,\n });\n\n target.setAttribute('actual-placement', placement);\n this.host.elements?.forEach((element) => {\n if (!this.originalPlacements.has(element)) {\n this.originalPlacements.set(\n element,\n element.getAttribute('placement') as Placement\n );\n }\n element.setAttribute('placement', placement);\n });\n\n if (tipElement && middlewareData.arrow) {\n const { x: arrowX, y: arrowY } = middlewareData.arrow;\n\n Object.assign(tipElement.style, {\n top:\n placement.startsWith('right') ||\n placement.startsWith('left')\n ? '0px'\n : '',\n left:\n placement.startsWith('bottom') ||\n placement.startsWith('top')\n ? '0px'\n : '',\n translate: `${roundByDPR(arrowX)}px ${roundByDPR(arrowY)}px`,\n });\n }\n }\n\n public clearOverlayPosition(): void {\n if (!this.target) {\n return;\n }\n this.target.style.removeProperty('max-height');\n this.target.style.removeProperty('max-width');\n this.initialHeight = undefined;\n this.isConstrained = false;\n }\n\n public resetOverlayPosition = (): void => {\n if (!this.target || !this.options) return;\n this.clearOverlayPosition();\n\n // force paint\n this.host.offsetHeight;\n this.computePlacement();\n };\n\n hostConnected(): void {\n document.addEventListener(\n 'sp-update-overlays',\n this.resetOverlayPosition\n );\n }\n\n hostUpdated(): void {\n if (!(this.host as Overlay).open) {\n this.cleanup?.();\n this.cleanup = undefined;\n }\n }\n\n hostDisconnected(): void {\n this.cleanup?.();\n this.cleanup = undefined;\n document.removeEventListener(\n 'sp-update-overlays',\n this.resetOverlayPosition\n );\n }\n}\n"],
|
|
5
|
-
"mappings": "aAgBA,OACI,SAAAA,EACA,cAAAC,EACA,mBAAAC,EACA,QAAAC,EACA,UAAAC,EAEA,SAAAC,EACA,QAAAC,MACG,
|
|
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 {\n ReactiveController,\n ReactiveElement,\n} from '@spectrum-web-components/base';\nimport {\n arrow,\n autoUpdate,\n computePosition,\n flip,\n offset,\n Placement,\n shift,\n size,\n} from '@floating-ui/dom';\nimport type { VirtualTrigger } from './VirtualTrigger.js';\nimport type { OpenableElement } from './overlay-types.js';\nimport type { Overlay } from './Overlay.js';\n\ntype OverlayOptionsV1 = {\n abortPromise?: Promise<boolean>;\n delayed?: boolean;\n offset?: number | [number, number]; // supporting multi-axis\n placement: Placement;\n notImmediatelyClosable?: boolean; // rename or place behind other API options\n receivesFocus?: 'auto';\n root?: HTMLElement;\n tipPadding?: number;\n trigger: HTMLElement | VirtualTrigger;\n type?: 'modal' | 'page' | 'hint' | 'auto' | 'manual';\n};\n\n/**\n * Rounds a number by the device pixel ratio (DPR).\n *\n * @param {number} [num] - The number to round.\n * @returns {number} The rounded number.\n */\nfunction roundByDPR(num?: number): number {\n if (typeof num === 'undefined') return 0;\n const dpr = window.devicePixelRatio || 1;\n return Math.round(num * dpr) / dpr;\n}\n\n// Minimum distance required between the overlay and the edge of the container.\n// See: https://spectrum.adobe.com/page/popover/#Container-padding\nconst REQUIRED_DISTANCE_TO_EDGE = 8;\n// Minimum height for the overlay.\n// See: https://github.com/adobe/spectrum-web-components/issues/910\nconst MIN_OVERLAY_HEIGHT = 100;\n\n/**\n * Gets fallback placements for the overlay based on the initial placement.\n *\n * @param {Placement} placement - The initial placement of the overlay.\n * @returns {Placement[]} An array of fallback placements.\n */\nconst getFallbackPlacements = (placement: Placement): Placement[] => {\n const fallbacks: Record<Placement, Placement[]> = {\n left: ['right', 'bottom', 'top'],\n 'left-start': ['right-start', 'bottom', 'top'],\n 'left-end': ['right-end', 'bottom', 'top'],\n right: ['left', 'bottom', 'top'],\n 'right-start': ['left-start', 'bottom', 'top'],\n 'right-end': ['left-end', 'bottom', 'top'],\n top: ['bottom', 'left', 'right'],\n 'top-start': ['bottom-start', 'left', 'right'],\n 'top-end': ['bottom-end', 'left', 'right'],\n bottom: ['top', 'left', 'right'],\n 'bottom-start': ['top-start', 'left', 'right'],\n 'bottom-end': ['top-end', 'left', 'right'],\n };\n return fallbacks[placement] ?? [placement];\n};\n\n/**\n * Symbol used to indicate that the placement has been updated.\n */\nexport const placementUpdatedSymbol = Symbol('placement updated');\n\n/**\n * Controller for managing the placement of an overlay.\n *\n * This class implements the ReactiveController interface and provides methods\n * for managing the positioning and constraints of an overlay element.\n */\nexport class PlacementController implements ReactiveController {\n /**\n * Function to clean up resources when the controller is no longer needed.\n *\n * @private\n */\n private cleanup?: () => void;\n\n /**\n * Initial height of the overlay.\n *\n * @type {number}\n */\n initialHeight?: number;\n\n /**\n * Indicates whether the overlay is constrained by available space.\n *\n * @type {boolean}\n */\n isConstrained?: boolean;\n\n /**\n * The host element that uses this controller.\n *\n * @private\n * @type {ReactiveElement & { elements: OpenableElement[] }}\n */\n private host!: ReactiveElement & { elements: OpenableElement[] };\n\n /**\n * Options for configuring the overlay placement.\n *\n * @private\n * @type {OverlayOptionsV1}\n */\n private options!: OverlayOptionsV1;\n\n /**\n * A WeakMap to store the original placements of overlay elements.\n *\n * @private\n * @type {WeakMap<HTMLElement, Placement>}\n */\n private originalPlacements = new WeakMap<HTMLElement, Placement>();\n\n /**\n * The target element for the overlay.\n *\n * @private\n * @type {HTMLElement}\n */\n private target!: HTMLElement;\n\n /**\n * Creates an instance of the PlacementController.\n *\n * @param {ReactiveElement & { elements: OpenableElement[] }} host - The host element that uses this controller.\n */\n constructor(host: ReactiveElement & { elements: OpenableElement[] }) {\n this.host = host;\n // Add the controller after the MutationObserver has been created in preparation\n // for the `hostConnected`/`hostDisconnected` callbacks to be run.\n this.host.addController(this);\n }\n\n /**\n * Places the overlay relative to the target element.\n *\n * This method sets up the necessary configurations and event listeners to manage the\n * positioning and constraints of the overlay element.\n *\n * @param {HTMLElement} [target=this.target] - The target element for the overlay.\n * @param {OverlayOptionsV1} [options=this.options] - The options for configuring the overlay placement.\n * @returns {Promise<void>} A promise that resolves when the overlay has been placed.\n */\n public async placeOverlay(\n target: HTMLElement = this.target,\n options: OverlayOptionsV1 = this.options\n ): Promise<void> {\n // Set the target and options for the overlay.\n this.target = target;\n this.options = options;\n if (!target || !options) return;\n\n // Set up auto-update for ancestor resize events.\n const cleanupAncestorResize = autoUpdate(\n options.trigger,\n target,\n this.closeForAncestorUpdate,\n {\n ancestorResize: false,\n elementResize: false,\n layoutShift: false,\n }\n );\n\n // Set up auto-update for element resize events.\n const cleanupElementResize = autoUpdate(\n options.trigger,\n target,\n this.updatePlacement,\n {\n ancestorScroll: false,\n }\n );\n\n // Define the cleanup function to remove event listeners and reset placements.\n this.cleanup = () => {\n this.host.elements?.forEach((element) => {\n element.addEventListener(\n 'sp-closed',\n () => {\n const placement = this.originalPlacements.get(element);\n\n if (placement) {\n element.setAttribute('placement', placement);\n }\n\n this.originalPlacements.delete(element);\n },\n { once: true }\n );\n });\n cleanupAncestorResize();\n cleanupElementResize();\n };\n }\n\n /**\n * Flag to allow or disallow placement updates.\n *\n * @type {boolean}\n */\n public allowPlacementUpdate = false;\n\n /**\n * Closes the overlay if an ancestor element is updated.\n *\n * This method checks if placement updates are allowed and if the overlay type is not 'modal'.\n * If these conditions are met and a cleanup function is defined, it dispatches a 'close' event\n * on the target element to close the overlay.\n */\n closeForAncestorUpdate = (): void => {\n if (\n !this.allowPlacementUpdate &&\n this.options.type !== 'modal' &&\n this.cleanup\n ) {\n // Dispatch a 'close' event to close the overlay.\n this.target.dispatchEvent(new Event('close', { bubbles: true }));\n }\n\n // Reset the flag to disallow placement updates.\n this.allowPlacementUpdate = false;\n };\n\n /**\n * Updates the placement of the overlay.\n *\n * This method calls the computePlacement method to recalculate the overlay's position.\n *\n * @private\n */\n private updatePlacement = (): void => {\n this.computePlacement();\n };\n\n /**\n * Computes the placement of the overlay relative to the target element.\n *\n * This method calculates the necessary positioning and constraints for the overlay element\n * using various middleware functions. It updates the overlay's style and attributes based\n * on the computed position.\n *\n * @returns {Promise<void>} A promise that resolves when the placement has been computed.\n */\n async computePlacement(): Promise<void> {\n const { options, target } = this;\n\n // Wait for document fonts to be ready before computing placement.\n await (document.fonts ? document.fonts.ready : Promise.resolve());\n\n // Determine the flip middleware based on the type of trigger element.\n const flipMiddleware = !(options.trigger instanceof HTMLElement)\n ? flip({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n fallbackPlacements: getFallbackPlacements(options.placement),\n })\n : flip();\n\n // Extract main axis and cross axis offsets from options.\n const [mainAxis = 0, crossAxis = 0] = Array.isArray(options?.offset)\n ? options.offset\n : [options.offset, 0];\n\n // Find the tip element within the host elements.\n const tipElement = this.host.elements.find(\n (el) => el.tipElement\n )?.tipElement;\n\n // Define middleware functions for positioning and constraints.\n const middleware = [\n offset({\n mainAxis,\n crossAxis,\n }),\n shift({ padding: REQUIRED_DISTANCE_TO_EDGE }),\n flipMiddleware,\n size({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n apply: ({\n availableWidth,\n availableHeight,\n rects: { floating },\n }) => {\n const maxHeight = Math.max(\n MIN_OVERLAY_HEIGHT,\n Math.floor(availableHeight)\n );\n const actualHeight = floating.height;\n this.initialHeight = !this.isConstrained // && !this.virtualTrigger\n ? actualHeight\n : this.initialHeight || actualHeight;\n this.isConstrained =\n actualHeight < this.initialHeight ||\n maxHeight <= actualHeight;\n const appliedHeight = this.isConstrained\n ? `${maxHeight}px`\n : '';\n Object.assign(target.style, {\n maxWidth: `${Math.floor(availableWidth)}px`,\n maxHeight: appliedHeight,\n });\n },\n }),\n ...(tipElement\n ? [\n arrow({\n element: tipElement,\n padding:\n options.tipPadding || REQUIRED_DISTANCE_TO_EDGE,\n }),\n ]\n : []),\n ];\n\n // Compute the position of the overlay using the defined middleware.\n const { x, y, placement, middlewareData } = await computePosition(\n options.trigger,\n target,\n {\n placement: options.placement,\n middleware,\n strategy: 'fixed',\n }\n );\n\n // Update the overlay's style with the computed position.\n Object.assign(target.style, {\n top: '0px',\n left: '0px',\n translate: `${roundByDPR(x)}px ${roundByDPR(y)}px`,\n });\n\n // Set the 'actual-placement' attribute on the target element.\n target.setAttribute('actual-placement', placement);\n\n // Update the placement attribute for each host element.\n this.host.elements?.forEach((element) => {\n if (!this.originalPlacements.has(element)) {\n this.originalPlacements.set(\n element,\n element.getAttribute('placement') as Placement\n );\n }\n element.setAttribute('placement', placement);\n });\n\n // Update the tip element's style with the computed arrow position.\n if (tipElement && middlewareData.arrow) {\n const { x: arrowX, y: arrowY } = middlewareData.arrow;\n\n Object.assign(tipElement.style, {\n top:\n placement.startsWith('right') ||\n placement.startsWith('left')\n ? '0px'\n : '',\n left:\n placement.startsWith('bottom') ||\n placement.startsWith('top')\n ? '0px'\n : '',\n translate: `${roundByDPR(arrowX)}px ${roundByDPR(arrowY)}px`,\n });\n }\n }\n\n /**\n * Clears the overlay's position styles.\n *\n * This method removes the max-height and max-width styles from the target element,\n * and resets the initial height and constrained state of the overlay.\n */\n public clearOverlayPosition(): void {\n if (!this.target) {\n return;\n }\n // Remove max-height and max-width styles from the target element.\n this.target.style.removeProperty('max-height');\n this.target.style.removeProperty('max-width');\n // Reset the initial height and constrained state.\n this.initialHeight = undefined;\n this.isConstrained = false;\n }\n\n /**\n * Resets the overlay's position.\n *\n * This method clears the overlay's position, forces a reflow, and recomputes the placement.\n */\n public resetOverlayPosition = (): void => {\n if (!this.target || !this.options) return;\n // Clear the overlay's position.\n this.clearOverlayPosition();\n\n // Force a reflow.\n this.host.offsetHeight;\n // Recompute the placement.\n this.computePlacement();\n };\n\n /**\n * Lifecycle method called when the host element is connected to the DOM.\n *\n * This method sets up an event listener to reset the overlay's position when the 'sp-update-overlays' event is dispatched.\n */\n hostConnected(): void {\n document.addEventListener(\n 'sp-update-overlays',\n this.resetOverlayPosition\n );\n }\n\n /**\n * Lifecycle method called when the host element is updated.\n *\n * This method cleans up resources if the overlay is not open.\n */\n hostUpdated(): void {\n if (!(this.host as Overlay).open) {\n // Clean up resources if the overlay is not open.\n this.cleanup?.();\n this.cleanup = undefined;\n }\n }\n\n /**\n * Lifecycle method called when the host element is disconnected from the DOM.\n *\n * This method removes the event listener and cleans up resources.\n */\n hostDisconnected(): void {\n // Clean up resources.\n this.cleanup?.();\n this.cleanup = undefined;\n // Remove the event listener.\n document.removeEventListener(\n 'sp-update-overlays',\n this.resetOverlayPosition\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "aAgBA,OACI,SAAAA,EACA,cAAAC,EACA,mBAAAC,EACA,QAAAC,EACA,UAAAC,EAEA,SAAAC,EACA,QAAAC,MACG,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MAAO,CACpC,KAAM,CAAE,EAAGC,EAAQ,EAAGC,CAAO,EAAIF,EAAe,MAEhD,OAAO,OAAOX,EAAW,MAAO,CAC5B,IACIZ,EAAU,WAAW,OAAO,GAC5BA,EAAU,WAAW,MAAM,EACrB,MACA,GACV,KACIA,EAAU,WAAW,QAAQ,GAC7BA,EAAU,WAAW,KAAK,EACpB,MACA,GACV,UAAW,GAAGN,EAAW8B,CAAM,CAAC,MAAM9B,EAAW+B,CAAM,CAAC,IAC5D,CAAC,CACL,CACJ,CAQO,sBAA6B,CAC3B,KAAK,SAIV,KAAK,OAAO,MAAM,eAAe,YAAY,EAC7C,KAAK,OAAO,MAAM,eAAe,WAAW,EAE5C,KAAK,cAAgB,OACrB,KAAK,cAAgB,GACzB,CAuBA,eAAsB,CAClB,SAAS,iBACL,qBACA,KAAK,oBACT,CACJ,CAOA,aAAoB,CA/bxB,IAAAxB,EAgcc,KAAK,KAAiB,QAExBA,EAAA,KAAK,UAAL,MAAAA,EAAA,WACA,KAAK,QAAU,OAEvB,CAOA,kBAAyB,CA5c7B,IAAAA,GA8cQA,EAAA,KAAK,UAAL,MAAAA,EAAA,WACA,KAAK,QAAU,OAEf,SAAS,oBACL,qBACA,KAAK,oBACT,CACJ,CACJ",
|
|
6
6
|
"names": ["arrow", "autoUpdate", "computePosition", "flip", "offset", "shift", "size", "roundByDPR", "num", "dpr", "REQUIRED_DISTANCE_TO_EDGE", "MIN_OVERLAY_HEIGHT", "getFallbackPlacements", "placement", "_a", "host", "target", "options", "cleanupAncestorResize", "cleanupElementResize", "element", "_b", "flipMiddleware", "mainAxis", "crossAxis", "tipElement", "el", "middleware", "availableWidth", "availableHeight", "floating", "maxHeight", "actualHeight", "appliedHeight", "x", "y", "middlewareData", "arrowX", "arrowY"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["overlay-trigger.css.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2025 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}slot[name=longpress-describedby-descriptor]{display:none}\n`;\nexport default styles;"],
|
|
5
5
|
"mappings": ";AAWA,SAAS,WAAW;AACpB,MAAM,SAAS;AAAA;AAAA;AAGf,eAAe;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["overlay-trigger.css.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2025 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}slot[name=longpress-describedby-descriptor]{display:none}\n`;\nexport default styles;"],
|
|
5
5
|
"mappings": "aAWA,OAAS,OAAAA,MAAW,gCACpB,MAAMC,EAASD;AAAA;AAAA,EAGf,eAAeC",
|
|
6
6
|
"names": ["css", "styles"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["overlay.css.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2025 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{pointer-events:none;--swc-overlay-animation-distance:var(--spectrum-spacing-100);display:contents}:host(:has(>sp-tooltip)){--swc-overlay-animation-distance:var(--spectrum-tooltip-animation-distance)}.dialog{box-sizing:border-box;max-height:calc(100vh - 16px);max-height:calc(100dvh - 16px);max-width:calc(100vw - 16px);height:auto;--sp-overlay-open:true;background:0 0;border:0;margin:0;padding:0;display:flex;position:fixed;inset:0 auto auto 0;overflow:visible;opacity:1!important}.dialog:not([is-visible]){display:none}.dialog:focus{outline:none}dialog:modal{--mod-popover-filter:var(--spectrum-popover-filter)}:host(:not([open])) .dialog{--sp-overlay-open:false}.dialog::backdrop{display:none}.dialog:before{content:\"\";position:absolute;inset:-999em;pointer-events:auto!important}.dialog:not(.not-immediately-closable):before{display:none}.dialog>div{width:100%}::slotted(*){pointer-events:auto;visibility:visible!important}::slotted(sp-popover){position:static}.dialog:not([actual-placement])[placement*=top]{padding-block:var(--swc-overlay-animation-distance);margin-top:var(--swc-overlay-animation-distance)}.dialog:not([actual-placement])[placement*=right]{padding-inline:var(--swc-overlay-animation-distance);margin-left:calc(-1*var(--swc-overlay-animation-distance))}.dialog:not([actual-placement])[placement*=bottom]{padding-block:var(--swc-overlay-animation-distance);margin-top:calc(-1*var(--swc-overlay-animation-distance))}.dialog:not([actual-placement])[placement*=left]{padding-inline:var(--swc-overlay-animation-distance);margin-left:var(--swc-overlay-animation-distance)}.dialog[actual-placement*=top]{padding-block:var(--swc-overlay-animation-distance);margin-top:var(--swc-overlay-animation-distance)}.dialog[actual-placement*=right]{padding-inline:var(--swc-overlay-animation-distance);margin-left:calc(-1*var(--swc-overlay-animation-distance))}.dialog[actual-placement*=bottom]{padding-block:var(--swc-overlay-animation-distance);margin-top:calc(-1*var(--swc-overlay-animation-distance))}.dialog[actual-placement*=left]{padding-inline:var(--swc-overlay-animation-distance);margin-left:var(--swc-overlay-animation-distance)}slot[name=longpress-describedby-descriptor]{display:none}@supports selector(:open){.dialog{opacity:0}.dialog:open{opacity:1;--mod-popover-filter:var(--spectrum-popover-filter)}}@supports selector(:popover-open){.dialog{opacity:0}.dialog:popover-open{opacity:1;--mod-popover-filter:var(--spectrum-popover-filter)}}@supports (overlay:auto){.dialog{transition:all var(--mod-overlay-animation-duration,var(--spectrum-animation-duration-100,.13s)),translate 0s,display var(--mod-overlay-animation-duration,var(--spectrum-animation-duration-100,.13s));transition-behavior:allow-discrete;display:none}.dialog:popover-open,.dialog:modal{display:flex}}@supports (not selector(:open)) and (not selector(:popover-open)){:host:not([open]) .dialog{pointer-events:none}.dialog[actual-placement]{z-index:calc(var(--swc-overlay-z-index-base,1000) + var(--swc-overlay-open-count))}}\n`;\nexport default styles;"],
|
|
5
5
|
"mappings": ";AAWA,SAAS,WAAW;AACpB,MAAM,SAAS;AAAA;AAAA;AAGf,eAAe;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/overlay.css.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["overlay.css.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2025 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{pointer-events:none;--swc-overlay-animation-distance:var(--spectrum-spacing-100);display:contents}:host(:has(>sp-tooltip)){--swc-overlay-animation-distance:var(--spectrum-tooltip-animation-distance)}.dialog{box-sizing:border-box;max-height:calc(100vh - 16px);max-height:calc(100dvh - 16px);max-width:calc(100vw - 16px);height:auto;--sp-overlay-open:true;background:0 0;border:0;margin:0;padding:0;display:flex;position:fixed;inset:0 auto auto 0;overflow:visible;opacity:1!important}.dialog:not([is-visible]){display:none}.dialog:focus{outline:none}dialog:modal{--mod-popover-filter:var(--spectrum-popover-filter)}:host(:not([open])) .dialog{--sp-overlay-open:false}.dialog::backdrop{display:none}.dialog:before{content:\"\";position:absolute;inset:-999em;pointer-events:auto!important}.dialog:not(.not-immediately-closable):before{display:none}.dialog>div{width:100%}::slotted(*){pointer-events:auto;visibility:visible!important}::slotted(sp-popover){position:static}.dialog:not([actual-placement])[placement*=top]{padding-block:var(--swc-overlay-animation-distance);margin-top:var(--swc-overlay-animation-distance)}.dialog:not([actual-placement])[placement*=right]{padding-inline:var(--swc-overlay-animation-distance);margin-left:calc(-1*var(--swc-overlay-animation-distance))}.dialog:not([actual-placement])[placement*=bottom]{padding-block:var(--swc-overlay-animation-distance);margin-top:calc(-1*var(--swc-overlay-animation-distance))}.dialog:not([actual-placement])[placement*=left]{padding-inline:var(--swc-overlay-animation-distance);margin-left:var(--swc-overlay-animation-distance)}.dialog[actual-placement*=top]{padding-block:var(--swc-overlay-animation-distance);margin-top:var(--swc-overlay-animation-distance)}.dialog[actual-placement*=right]{padding-inline:var(--swc-overlay-animation-distance);margin-left:calc(-1*var(--swc-overlay-animation-distance))}.dialog[actual-placement*=bottom]{padding-block:var(--swc-overlay-animation-distance);margin-top:calc(-1*var(--swc-overlay-animation-distance))}.dialog[actual-placement*=left]{padding-inline:var(--swc-overlay-animation-distance);margin-left:var(--swc-overlay-animation-distance)}slot[name=longpress-describedby-descriptor]{display:none}@supports selector(:open){.dialog{opacity:0}.dialog:open{opacity:1;--mod-popover-filter:var(--spectrum-popover-filter)}}@supports selector(:popover-open){.dialog{opacity:0}.dialog:popover-open{opacity:1;--mod-popover-filter:var(--spectrum-popover-filter)}}@supports (overlay:auto){.dialog{transition:all var(--mod-overlay-animation-duration,var(--spectrum-animation-duration-100,.13s)),translate 0s,display var(--mod-overlay-animation-duration,var(--spectrum-animation-duration-100,.13s));transition-behavior:allow-discrete;display:none}.dialog:popover-open,.dialog:modal{display:flex}}@supports (not selector(:open)) and (not selector(:popover-open)){:host:not([open]) .dialog{pointer-events:none}.dialog[actual-placement]{z-index:calc(var(--swc-overlay-z-index-base,1000) + var(--swc-overlay-open-count))}}\n`;\nexport default styles;"],
|
|
5
5
|
"mappings": "aAWA,OAAS,OAAAA,MAAW,gCACpB,MAAMC,EAASD;AAAA;AAAA,EAGf,eAAeC",
|
|
6
6
|
"names": ["css", "styles"]
|
|
7
7
|
}
|
package/stories/index.js
CHANGED
|
@@ -6,9 +6,17 @@ function nextFrame() {
|
|
|
6
6
|
class IsOverlayOpen extends HTMLElement {
|
|
7
7
|
constructor() {
|
|
8
8
|
super();
|
|
9
|
+
this.sendFocus = async () => {
|
|
10
|
+
var _a;
|
|
11
|
+
const selectedItem = (_a = document.querySelector("[focusable]")) == null ? void 0 : _a.querySelector("[selected]");
|
|
12
|
+
if (selectedItem) {
|
|
13
|
+
selectedItem.focus();
|
|
14
|
+
selectedItem.focused = true;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
9
17
|
this.handleOpened = async (event) => {
|
|
10
18
|
const overlay = event.target;
|
|
11
|
-
const actions = [nextFrame(), overlay.updateComplete];
|
|
19
|
+
const actions = [nextFrame(), overlay.updateComplete, this.sendFocus()];
|
|
12
20
|
await Promise.all(actions);
|
|
13
21
|
await nextFrame();
|
|
14
22
|
await nextFrame();
|
package/stories/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["index.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2023 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { html, TemplateResult } from '@spectrum-web-components/base';\nimport type { Overlay } from '@spectrum-web-components/overlay';\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\nclass IsOverlayOpen extends HTMLElement {\n ready!: (value: boolean | PromiseLike<boolean>) => void;\n\n constructor() {\n super();\n this.readyPromise = new Promise((res) => {\n this.ready = res;\n this.setup();\n });\n }\n\n async setup(): Promise<void> {\n await nextFrame();\n
|
|
5
|
-
"mappings": ";AAYA,SAAS,YAA4B;AAGrC,SAAS,YAA2B;AAChC,SAAO,IAAI,QAAQ,CAAC,QAAQ,sBAAsB,MAAM,IAAI,CAAC,CAAC;AAClE;AAEA,MAAM,sBAAsB,YAAY;AAAA,EAGpC,cAAc;AACV,UAAM;
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2023 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { html, TemplateResult } from '@spectrum-web-components/base';\nimport type { Overlay } from '@spectrum-web-components/overlay';\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\nclass IsOverlayOpen extends HTMLElement {\n ready!: (value: boolean | PromiseLike<boolean>) => void;\n\n constructor() {\n super();\n this.readyPromise = new Promise((res) => {\n this.ready = res;\n this.setup();\n });\n }\n\n async setup(): Promise<void> {\n await nextFrame();\n document.addEventListener('sp-opened', this.handleOpened);\n }\n\n private sendFocus = async (): Promise<void> => {\n const selectedItem = document\n .querySelector('[focusable]')\n ?.querySelector('[selected]') as HTMLElement & {\n focused?: boolean;\n };\n\n if (selectedItem) {\n selectedItem.focus();\n selectedItem.focused = true;\n }\n };\n\n handleOpened = async (event: Event): Promise<void> => {\n const overlay = event.target as Overlay;\n const actions = [nextFrame(), overlay.updateComplete, this.sendFocus()];\n\n await Promise.all(actions);\n // Focus happens _after_ `sp-opened` by at least two frames.\n await nextFrame();\n await nextFrame();\n await nextFrame();\n await nextFrame();\n\n this.ready(true);\n };\n\n private readyPromise: Promise<boolean> = Promise.resolve(false);\n\n get updateComplete(): Promise<boolean> {\n return this.readyPromise;\n }\n}\n\ncustomElements.define('is-overlay-open', IsOverlayOpen);\n\nexport const isOverlayOpen = (story: () => TemplateResult): TemplateResult => {\n return html`\n ${story()}\n <is-overlay-open></is-overlay-open>\n `;\n};\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,YAA4B;AAGrC,SAAS,YAA2B;AAChC,SAAO,IAAI,QAAQ,CAAC,QAAQ,sBAAsB,MAAM,IAAI,CAAC,CAAC;AAClE;AAEA,MAAM,sBAAsB,YAAY;AAAA,EAGpC,cAAc;AACV,UAAM;AAYV,SAAQ,YAAY,YAA2B;AAnCnD;AAoCQ,YAAM,gBAAe,cAChB,cAAc,aAAa,MADX,mBAEf,cAAc;AAIpB,UAAI,cAAc;AACd,qBAAa,MAAM;AACnB,qBAAa,UAAU;AAAA,MAC3B;AAAA,IACJ;AAEA,wBAAe,OAAO,UAAgC;AAClD,YAAM,UAAU,MAAM;AACtB,YAAM,UAAU,CAAC,UAAU,GAAG,QAAQ,gBAAgB,KAAK,UAAU,CAAC;AAEtE,YAAM,QAAQ,IAAI,OAAO;AAEzB,YAAM,UAAU;AAChB,YAAM,UAAU;AAChB,YAAM,UAAU;AAChB,YAAM,UAAU;AAEhB,WAAK,MAAM,IAAI;AAAA,IACnB;AAEA,SAAQ,eAAiC,QAAQ,QAAQ,KAAK;AAtC1D,SAAK,eAAe,IAAI,QAAQ,CAAC,QAAQ;AACrC,WAAK,QAAQ;AACb,WAAK,MAAM;AAAA,IACf,CAAC;AAAA,EACL;AAAA,EAEA,MAAM,QAAuB;AACzB,UAAM,UAAU;AAChB,aAAS,iBAAiB,aAAa,KAAK,YAAY;AAAA,EAC5D;AAAA,EA+BA,IAAI,iBAAmC;AACnC,WAAO,KAAK;AAAA,EAChB;AACJ;AAEA,eAAe,OAAO,mBAAmB,aAAa;AAE/C,aAAM,gBAAgB,CAAC,UAAgD;AAC1E,SAAO;AAAA,UACD,MAAM,CAAC;AAAA;AAAA;AAGjB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -226,10 +226,18 @@ export const Default = ({ open } = {}) => {
|
|
|
226
226
|
Default.swc_vrt = {
|
|
227
227
|
skip: true
|
|
228
228
|
};
|
|
229
|
+
Default.parameters = {
|
|
230
|
+
// Disables Chromatic's snapshotting on a global level
|
|
231
|
+
chromatic: { disableSnapshot: true }
|
|
232
|
+
};
|
|
229
233
|
export const configured = (args) => template(args);
|
|
230
234
|
configured.swc_vrt = {
|
|
231
235
|
skip: true
|
|
232
236
|
};
|
|
237
|
+
configured.parameters = {
|
|
238
|
+
// Disables Chromatic's snapshotting on a global level
|
|
239
|
+
chromatic: { disableSnapshot: true }
|
|
240
|
+
};
|
|
233
241
|
export const insertionOptions = (args = {}) => html`
|
|
234
242
|
${template(args)}
|
|
235
243
|
<div id="other-element"></div>
|
|
@@ -243,6 +251,10 @@ insertionOptions.args = {
|
|
|
243
251
|
insertionOptions.swc_vrt = {
|
|
244
252
|
skip: true
|
|
245
253
|
};
|
|
254
|
+
insertionOptions.parameters = {
|
|
255
|
+
// Disables Chromatic's snapshotting on a global level
|
|
256
|
+
chromatic: { disableSnapshot: true }
|
|
257
|
+
};
|
|
246
258
|
class ManagedOverlayTrigger extends LitElement {
|
|
247
259
|
constructor() {
|
|
248
260
|
super(...arguments);
|
|
@@ -321,4 +333,8 @@ export const managedOverlayTrigger = () => html`
|
|
|
321
333
|
managedOverlayTrigger.swc_vrt = {
|
|
322
334
|
skip: true
|
|
323
335
|
};
|
|
336
|
+
managedOverlayTrigger.parameters = {
|
|
337
|
+
// Disables Chromatic's snapshotting on a global level
|
|
338
|
+
chromatic: { disableSnapshot: true }
|
|
339
|
+
};
|
|
324
340
|
//# sourceMappingURL=overlay-directive.stories.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["overlay-directive.stories.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\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 html,\n LitElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n OverlayContentTypes,\n OverlayOpenCloseDetail,\n Placement,\n TriggerInteractions,\n} from '@spectrum-web-components/overlay';\nimport '@spectrum-web-components/action-button/sp-action-button.js';\nimport '@spectrum-web-components/action-group/sp-action-group.js';\nimport '@spectrum-web-components/button/sp-button.js';\nimport '@spectrum-web-components/dialog/sp-dialog-wrapper.js';\nimport '@spectrum-web-components/field-label/sp-field-label.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-magnify.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-open-in.js';\nimport '@spectrum-web-components/overlay/overlay-trigger.js';\nimport {\n InsertionOptions,\n trigger,\n} from '@spectrum-web-components/overlay/src/overlay-trigger-directive.js';\n\nimport '@spectrum-web-components/dialog/sp-dialog.js';\nimport '@spectrum-web-components/picker/sp-picker.js';\nimport '@spectrum-web-components/menu/sp-menu.js';\nimport '@spectrum-web-components/menu/sp-menu-item.js';\nimport '@spectrum-web-components/menu/sp-menu-divider.js';\nimport '@spectrum-web-components/popover/sp-popover.js';\nimport '@spectrum-web-components/slider/sp-slider.js';\nimport '@spectrum-web-components/radio/sp-radio.js';\nimport '@spectrum-web-components/radio/sp-radio-group.js';\nimport '@spectrum-web-components/tooltip/sp-tooltip.js';\nimport '@spectrum-web-components/theme/sp-theme.js';\nimport '@spectrum-web-components/theme/src/themes.js';\nimport '@spectrum-web-components/accordion/sp-accordion.js';\nimport '@spectrum-web-components/accordion/sp-accordion-item.js';\nimport '../../../projects/story-decorator/src/types.js';\n\nimport './overlay-story-components.js';\nimport { tooltip } from '@spectrum-web-components/tooltip/src/tooltip-directive.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\nimport { state } from '@spectrum-web-components/base/src/decorators.js';\n\nconst storyStyles = html`\n <style>\n html,\n body,\n #root,\n #root-inner,\n sp-story-decorator {\n height: 100%;\n margin: 0;\n }\n\n sp-story-decorator::part(container) {\n display: flex;\n flex-direction: column;\n width: 100%;\n height: 100%;\n align-items: center;\n justify-content: center;\n }\n\n overlay-trigger {\n flex: none;\n }\n\n #styled-div {\n background-color: var(--styled-div-background-color, blue);\n color: white;\n padding: 4px 10px;\n margin-bottom: 10px;\n }\n\n #inner-trigger {\n display: inline-block;\n }\n </style>\n`;\n\nexport default {\n title: 'Overlay Directive',\n argTypes: {\n offset: { control: 'number' },\n placement: {\n control: {\n type: 'inline-radio',\n options: [\n 'top',\n 'top-start',\n 'top-end',\n 'bottom',\n 'bottom-start',\n 'bottom-end',\n 'left',\n 'left-start',\n 'left-end',\n 'right',\n 'right-start',\n 'right-end',\n 'auto',\n 'auto-start',\n 'auto-end',\n 'none',\n ],\n },\n },\n type: {\n control: {\n type: 'inline-radio',\n options: ['modal', 'replace', 'inline'],\n },\n },\n colorStop: {\n control: {\n type: 'inline-radio',\n options: ['light', 'dark'],\n },\n },\n open: {\n name: 'open',\n type: { name: 'boolean', required: false },\n description: 'Whether the second accordion item is open.',\n table: {\n type: { summary: 'boolean' },\n defaultValue: { summary: false },\n },\n control: {\n type: 'boolean',\n },\n },\n },\n args: {\n placement: 'bottom',\n offset: 0,\n colorStop: 'light',\n triggerOn: 'click',\n open: false,\n },\n};\n\ninterface Properties {\n placement?: Placement;\n offset?: number;\n triggerOn?: OverlayContentTypes;\n type?: Extract<TriggerInteractions, 'inline' | 'modal' | 'replace'>;\n insertionOptions?: InsertionOptions;\n open?: boolean;\n}\n\nconst template = ({\n placement,\n offset,\n open,\n triggerOn,\n insertionOptions,\n}: Properties): TemplateResult => {\n const renderTooltip = (): TemplateResult => html`\n Click to open a popover.\n `;\n const renderPopover = (): TemplateResult => html`\n <sp-popover placement=\"${ifDefined(placement)}\" tip>\n <sp-dialog no-divider>\n <div class=\"options-popover-content\">\n <sp-slider\n value=\"5\"\n step=\"0.5\"\n min=\"0\"\n max=\"20\"\n label=\"Awesomeness\"\n ></sp-slider>\n <div id=\"styled-div\">\n The background of this div should be blue\n </div>\n <sp-button\n ${tooltip(\n () => html`\n Click to open another popover.\n `\n )}\n ${trigger(\n () => html`\n <sp-popover placement=\"bottom\" tip open>\n <sp-dialog size=\"s\" no-divider>\n <div class=\"options-popover-content\">\n Another Popover\n </div>\n </sp-dialog>\n </sp-popover>\n `,\n {\n triggerInteraction: 'click',\n overlayOptions: {\n placement: 'bottom',\n },\n }\n )}\n >\n Press Me\n </sp-button>\n </div>\n </sp-dialog>\n </sp-popover>\n `;\n return html`\n ${storyStyles}\n <sp-button\n variant=\"primary\"\n ${tooltip(renderTooltip)}\n ${trigger(renderPopover, {\n open,\n triggerInteraction: triggerOn,\n overlayOptions: {\n placement,\n offset,\n },\n insertionOptions: insertionOptions,\n })}\n >\n Show Popover\n </sp-button>\n `;\n};\n\nexport const Default = ({ open }: Properties = {}): TemplateResult => {\n const renderPopover = (): TemplateResult => html`\n <sp-popover>\n <sp-dialog no-divider>Popover content goes here</sp-dialog>\n </sp-popover>\n `;\n const options = typeof open !== 'undefined' ? { open } : undefined;\n return html`\n <sp-button ${trigger(renderPopover, options)}>Open Popover</sp-button>\n `;\n};\n\nDefault.swc_vrt = {\n skip: true,\n};\n\nexport const configured = (args: Properties): TemplateResult => template(args);\n\nconfigured.swc_vrt = {\n skip: true,\n};\n\nexport const insertionOptions = (args: Properties = {}): TemplateResult => html`\n ${template(args)}\n <div id=\"other-element\"></div>\n`;\n\ninsertionOptions.args = {\n insertionOptions: {\n el: () => document.querySelector('#other-element'),\n where: 'afterbegin',\n },\n} as Properties;\n\ninsertionOptions.swc_vrt = {\n skip: true,\n};\n\nclass ManagedOverlayTrigger extends LitElement {\n @state()\n private isRenderOverlay = false;\n\n @state()\n private isOpenState = false;\n\n protected override render(): TemplateResult {\n return html`\n <sp-button\n @click=${() => {\n this.isRenderOverlay = !this.isRenderOverlay;\n }}\n >\n Toggle Overlay Render Button\n </sp-button>\n\n <sp-button\n @click=${() => {\n this.isRenderOverlay = true;\n this.isOpenState = true;\n }}\n >\n Create Overlay Render Button And Open Overlay\n </sp-button>\n\n ${this.isRenderOverlay ? this.renderOverlayButton() : html``}\n `;\n }\n\n private renderOverlayButton(): TemplateResult {\n return html`\n <sp-button\n ?selected=${this.isOpenState}\n ${trigger(\n () => html`\n <sp-popover\n @sp-opened=${(\n event: CustomEvent<OverlayOpenCloseDetail>\n ) => {\n if (event.target !== event.currentTarget) {\n return;\n }\n console.log('sp-opened');\n this.isOpenState = true;\n }}\n @sp-closed=${(\n event: CustomEvent<OverlayOpenCloseDetail>\n ) => {\n if (event.target !== event.currentTarget) {\n return;\n }\n console.log('sp-closed');\n this.isOpenState = false;\n }}\n >\n <h1>My Test Popover</h1>\n </sp-popover>\n `,\n {\n triggerInteraction: 'click',\n overlayOptions: { placement: 'bottom-end' },\n open: this.isOpenState,\n }\n )}\n >\n Toggle Popover\n </sp-button>\n `;\n }\n}\n\ncustomElements.define('managed-overlay-trigger', ManagedOverlayTrigger);\n\nexport const managedOverlayTrigger = (): TemplateResult => html`\n <managed-overlay-trigger></managed-overlay-trigger>\n`;\n\nmanagedOverlayTrigger.swc_vrt = {\n skip: true,\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;AAUA;AAAA,EACI;AAAA,EACA;AAAA,OAEG;AAOP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP;AAAA,EAEI;AAAA,OACG;AAEP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AACP,OAAO;AAEP,OAAO;AACP,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AAEtB,MAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqCpB,eAAe;AAAA,EACX,OAAO;AA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c;AAAA;AAAA,EAEH,SAAyB;AACxC,WAAO;AAAA;AAAA,yBAEU,MAAM;AACX,WAAK,kBAAkB,CAAC,KAAK;AAAA,IACjC,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAMQ,MAAM;AACX,WAAK,kBAAkB;AACvB,WAAK,cAAc;AAAA,IACvB,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,cAKH,KAAK,kBAAkB,KAAK,oBAAoB,IAAI,MAAM;AAAA;AAAA,EAEpE;AAAA,EAEQ,sBAAsC;AAC1C,WAAO;AAAA;AAAA,4BAEa,KAAK,WAAW;AAAA,kBAC1B;AAAA,MACE,MAAM;AAAA;AAAA,yCAEe,CACT,UACC;AACD,YAAI,MAAM,WAAW,MAAM,eAAe;AACtC;AAAA,QACJ;AACA,gBAAQ,IAAI,WAAW;AACvB,aAAK,cAAc;AAAA,MACvB,CAAC;AAAA,yCACY,CACT,UACC;AACD,YAAI,MAAM,WAAW,MAAM,eAAe;AACtC;AAAA,QACJ;AACA,gBAAQ,IAAI,WAAW;AACvB,aAAK,cAAc;AAAA,MACvB,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,MAKT;AAAA,QACI,oBAAoB;AAAA,QACpB,gBAAgB,EAAE,WAAW,aAAa;AAAA,QAC1C,MAAM,KAAK;AAAA,MACf;AAAA,IACJ,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAKb;AACJ;AApEY;AAAA,EADP,MAAM;AAAA,GADL,sBAEM;AAGA;AAAA,EADP,MAAM;AAAA,GAJL,sBAKM;AAmEZ,eAAe,OAAO,2BAA2B,qBAAqB;AAE/D,aAAM,wBAAwB,MAAsB;AAAA;AAAA;AAI3D,sBAAsB,UAAU;AAAA,EAC5B,MAAM;AACV;",
|
|
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\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 html,\n LitElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n OverlayContentTypes,\n OverlayOpenCloseDetail,\n Placement,\n TriggerInteractions,\n} from '@spectrum-web-components/overlay';\nimport '@spectrum-web-components/action-button/sp-action-button.js';\nimport '@spectrum-web-components/action-group/sp-action-group.js';\nimport '@spectrum-web-components/button/sp-button.js';\nimport '@spectrum-web-components/dialog/sp-dialog-wrapper.js';\nimport '@spectrum-web-components/field-label/sp-field-label.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-magnify.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-open-in.js';\nimport '@spectrum-web-components/overlay/overlay-trigger.js';\nimport {\n InsertionOptions,\n trigger,\n} from '@spectrum-web-components/overlay/src/overlay-trigger-directive.js';\n\nimport '@spectrum-web-components/dialog/sp-dialog.js';\nimport '@spectrum-web-components/picker/sp-picker.js';\nimport '@spectrum-web-components/menu/sp-menu.js';\nimport '@spectrum-web-components/menu/sp-menu-item.js';\nimport '@spectrum-web-components/menu/sp-menu-divider.js';\nimport '@spectrum-web-components/popover/sp-popover.js';\nimport '@spectrum-web-components/slider/sp-slider.js';\nimport '@spectrum-web-components/radio/sp-radio.js';\nimport '@spectrum-web-components/radio/sp-radio-group.js';\nimport '@spectrum-web-components/tooltip/sp-tooltip.js';\nimport '@spectrum-web-components/theme/sp-theme.js';\nimport '@spectrum-web-components/theme/src/themes.js';\nimport '@spectrum-web-components/accordion/sp-accordion.js';\nimport '@spectrum-web-components/accordion/sp-accordion-item.js';\nimport '../../../projects/story-decorator/src/types.js';\n\nimport './overlay-story-components.js';\nimport { tooltip } from '@spectrum-web-components/tooltip/src/tooltip-directive.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\nimport { state } from '@spectrum-web-components/base/src/decorators.js';\n\nconst storyStyles = html`\n <style>\n html,\n body,\n #root,\n #root-inner,\n sp-story-decorator {\n height: 100%;\n margin: 0;\n }\n\n sp-story-decorator::part(container) {\n display: flex;\n flex-direction: column;\n width: 100%;\n height: 100%;\n align-items: center;\n justify-content: center;\n }\n\n overlay-trigger {\n flex: none;\n }\n\n #styled-div {\n background-color: var(--styled-div-background-color, blue);\n color: white;\n padding: 4px 10px;\n margin-bottom: 10px;\n }\n\n #inner-trigger {\n display: inline-block;\n }\n </style>\n`;\n\nexport default {\n title: 'Overlay Directive',\n argTypes: {\n offset: { control: 'number' },\n placement: {\n control: {\n type: 'inline-radio',\n options: [\n 'top',\n 'top-start',\n 'top-end',\n 'bottom',\n 'bottom-start',\n 'bottom-end',\n 'left',\n 'left-start',\n 'left-end',\n 'right',\n 'right-start',\n 'right-end',\n 'auto',\n 'auto-start',\n 'auto-end',\n 'none',\n ],\n },\n },\n type: {\n control: {\n type: 'inline-radio',\n options: ['modal', 'replace', 'inline'],\n },\n },\n colorStop: {\n control: {\n type: 'inline-radio',\n options: ['light', 'dark'],\n },\n },\n open: {\n name: 'open',\n type: { name: 'boolean', required: false },\n description: 'Whether the second accordion item is open.',\n table: {\n type: { summary: 'boolean' },\n defaultValue: { summary: false },\n },\n control: {\n type: 'boolean',\n },\n },\n },\n args: {\n placement: 'bottom',\n offset: 0,\n colorStop: 'light',\n triggerOn: 'click',\n open: false,\n },\n};\n\ninterface Properties {\n placement?: Placement;\n offset?: number;\n triggerOn?: OverlayContentTypes;\n type?: Extract<TriggerInteractions, 'inline' | 'modal' | 'replace'>;\n insertionOptions?: InsertionOptions;\n open?: boolean;\n}\n\nconst template = ({\n placement,\n offset,\n open,\n triggerOn,\n insertionOptions,\n}: Properties): TemplateResult => {\n const renderTooltip = (): TemplateResult => html`\n Click to open a popover.\n `;\n const renderPopover = (): TemplateResult => html`\n <sp-popover placement=\"${ifDefined(placement)}\" tip>\n <sp-dialog no-divider>\n <div class=\"options-popover-content\">\n <sp-slider\n value=\"5\"\n step=\"0.5\"\n min=\"0\"\n max=\"20\"\n label=\"Awesomeness\"\n ></sp-slider>\n <div id=\"styled-div\">\n The background of this div should be blue\n </div>\n <sp-button\n ${tooltip(\n () => html`\n Click to open another popover.\n `\n )}\n ${trigger(\n () => html`\n <sp-popover placement=\"bottom\" tip open>\n <sp-dialog size=\"s\" no-divider>\n <div class=\"options-popover-content\">\n Another Popover\n </div>\n </sp-dialog>\n </sp-popover>\n `,\n {\n triggerInteraction: 'click',\n overlayOptions: {\n placement: 'bottom',\n },\n }\n )}\n >\n Press Me\n </sp-button>\n </div>\n </sp-dialog>\n </sp-popover>\n `;\n return html`\n ${storyStyles}\n <sp-button\n variant=\"primary\"\n ${tooltip(renderTooltip)}\n ${trigger(renderPopover, {\n open,\n triggerInteraction: triggerOn,\n overlayOptions: {\n placement,\n offset,\n },\n insertionOptions: insertionOptions,\n })}\n >\n Show Popover\n </sp-button>\n `;\n};\n\nexport const Default = ({ open }: Properties = {}): TemplateResult => {\n const renderPopover = (): TemplateResult => html`\n <sp-popover>\n <sp-dialog no-divider>Popover content goes here</sp-dialog>\n </sp-popover>\n `;\n const options = typeof open !== 'undefined' ? { open } : undefined;\n return html`\n <sp-button ${trigger(renderPopover, options)}>Open Popover</sp-button>\n `;\n};\n\nDefault.swc_vrt = {\n skip: true,\n};\n\nDefault.parameters = {\n // Disables Chromatic's snapshotting on a global level\n chromatic: { disableSnapshot: true },\n};\n\nexport const configured = (args: Properties): TemplateResult => template(args);\n\nconfigured.swc_vrt = {\n skip: true,\n};\n\nconfigured.parameters = {\n // Disables Chromatic's snapshotting on a global level\n chromatic: { disableSnapshot: true },\n};\n\nexport const insertionOptions = (args: Properties = {}): TemplateResult => html`\n ${template(args)}\n <div id=\"other-element\"></div>\n`;\n\ninsertionOptions.args = {\n insertionOptions: {\n el: () => document.querySelector('#other-element'),\n where: 'afterbegin',\n },\n} as Properties;\n\ninsertionOptions.swc_vrt = {\n skip: true,\n};\n\ninsertionOptions.parameters = {\n // Disables Chromatic's snapshotting on a global level\n chromatic: { disableSnapshot: true },\n};\n\nclass ManagedOverlayTrigger extends LitElement {\n @state()\n private isRenderOverlay = false;\n\n @state()\n private isOpenState = false;\n\n protected override render(): TemplateResult {\n return html`\n <sp-button\n @click=${() => {\n this.isRenderOverlay = !this.isRenderOverlay;\n }}\n >\n Toggle Overlay Render Button\n </sp-button>\n\n <sp-button\n @click=${() => {\n this.isRenderOverlay = true;\n this.isOpenState = true;\n }}\n >\n Create Overlay Render Button And Open Overlay\n </sp-button>\n\n ${this.isRenderOverlay ? this.renderOverlayButton() : html``}\n `;\n }\n\n private renderOverlayButton(): TemplateResult {\n return html`\n <sp-button\n ?selected=${this.isOpenState}\n ${trigger(\n () => html`\n <sp-popover\n @sp-opened=${(\n event: CustomEvent<OverlayOpenCloseDetail>\n ) => {\n if (event.target !== event.currentTarget) {\n return;\n }\n console.log('sp-opened');\n this.isOpenState = true;\n }}\n @sp-closed=${(\n event: CustomEvent<OverlayOpenCloseDetail>\n ) => {\n if (event.target !== event.currentTarget) {\n return;\n }\n console.log('sp-closed');\n this.isOpenState = false;\n }}\n >\n <h1>My Test Popover</h1>\n </sp-popover>\n `,\n {\n triggerInteraction: 'click',\n overlayOptions: { placement: 'bottom-end' },\n open: this.isOpenState,\n }\n )}\n >\n Toggle Popover\n </sp-button>\n `;\n }\n}\n\ncustomElements.define('managed-overlay-trigger', ManagedOverlayTrigger);\n\nexport const managedOverlayTrigger = (): TemplateResult => html`\n <managed-overlay-trigger></managed-overlay-trigger>\n`;\n\nmanagedOverlayTrigger.swc_vrt = {\n skip: true,\n};\n\nmanagedOverlayTrigger.parameters = {\n // Disables Chromatic's snapshotting on a global level\n chromatic: { disableSnapshot: true },\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAUA;AAAA,EACI;AAAA,EACA;AAAA,OAEG;AAOP,OAAO;AACP,OAAO;AACP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ACT,UACC;AACD,YAAI,MAAM,WAAW,MAAM,eAAe;AACtC;AAAA,QACJ;AACA,gBAAQ,IAAI,WAAW;AACvB,aAAK,cAAc;AAAA,MACvB,CAAC;AAAA,yCACY,CACT,UACC;AACD,YAAI,MAAM,WAAW,MAAM,eAAe;AACtC;AAAA,QACJ;AACA,gBAAQ,IAAI,WAAW;AACvB,aAAK,cAAc;AAAA,MACvB,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,MAKT;AAAA,QACI,oBAAoB;AAAA,QACpB,gBAAgB,EAAE,WAAW,aAAa;AAAA,QAC1C,MAAM,KAAK;AAAA,MACf;AAAA,IACJ,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAKb;AACJ;AApEY;AAAA,EADP,MAAM;AAAA,GADL,sBAEM;AAGA;AAAA,EADP,MAAM;AAAA,GAJL,sBAKM;AAmEZ,eAAe,OAAO,2BAA2B,qBAAqB;AAE/D,aAAM,wBAAwB,MAAsB;AAAA;AAAA;AAI3D,sBAAsB,UAAU;AAAA,EAC5B,MAAM;AACV;AAEA,sBAAsB,aAAa;AAAA;AAAA,EAE/B,WAAW,EAAE,iBAAiB,KAAK;AACvC;",
|
|
6
6
|
"names": ["insertionOptions"]
|
|
7
7
|
}
|
|
@@ -161,6 +161,10 @@ export const withSlider = () => html`
|
|
|
161
161
|
withSlider.swc_vrt = {
|
|
162
162
|
skip: true
|
|
163
163
|
};
|
|
164
|
+
withSlider.parameters = {
|
|
165
|
+
// Disables Chromatic's snapshotting on a global level
|
|
166
|
+
chromatic: { disableSnapshot: true }
|
|
167
|
+
};
|
|
164
168
|
export const hover = (args) => Template(args);
|
|
165
169
|
hover.args = {
|
|
166
170
|
interaction: "hover",
|
|
@@ -633,6 +637,10 @@ export const transientHover = () => html`
|
|
|
633
637
|
transientHover.swc_vrt = {
|
|
634
638
|
skip: true
|
|
635
639
|
};
|
|
640
|
+
transientHover.parameters = {
|
|
641
|
+
// Disables Chromatic's snapshotting on a global level
|
|
642
|
+
chromatic: { disableSnapshot: true }
|
|
643
|
+
};
|
|
636
644
|
export const lazyElements = () => {
|
|
637
645
|
const handleSlottableRequest = (event) => {
|
|
638
646
|
const template = event.data === removeSlottableRequest ? void 0 : html`
|
|
@@ -672,4 +680,8 @@ export const lazyElements = () => {
|
|
|
672
680
|
lazyElements.swc_vrt = {
|
|
673
681
|
skip: true
|
|
674
682
|
};
|
|
683
|
+
lazyElements.parameters = {
|
|
684
|
+
// Disables Chromatic's snapshotting on a global level
|
|
685
|
+
chromatic: { disableSnapshot: true }
|
|
686
|
+
};
|
|
675
687
|
//# sourceMappingURL=overlay-element.stories.js.map
|