@spectrum-web-components/overlay 0.18.4 → 0.18.5
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 +5 -5
- package/src/ActiveOverlay.dev.js +1 -0
- package/src/ActiveOverlay.dev.js.map +2 -2
- package/src/ActiveOverlay.js +1 -1
- package/src/ActiveOverlay.js.map +2 -2
- package/src/overlay-stack.d.ts +1 -0
- package/src/overlay-stack.dev.js +33 -20
- package/src/overlay-stack.dev.js.map +2 -2
- package/src/overlay-stack.js +2 -2
- package/src/overlay-stack.js.map +3 -3
- package/stories/overlay.stories.js +22 -0
- package/stories/overlay.stories.js.map +2 -2
- package/test/overlay-trigger-hover-click.test.js +2 -0
- package/test/overlay-trigger-hover-click.test.js.map +2 -2
- package/test/overlay-trigger-hover.test.js +5 -8
- package/test/overlay-trigger-hover.test.js.map +2 -2
- package/test/overlay.test-vrt.js.map +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/overlay",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -103,10 +103,10 @@
|
|
|
103
103
|
],
|
|
104
104
|
"dependencies": {
|
|
105
105
|
"@floating-ui/dom": "^1.0.2",
|
|
106
|
-
"@spectrum-web-components/action-button": "^0.10.
|
|
106
|
+
"@spectrum-web-components/action-button": "^0.10.4",
|
|
107
107
|
"@spectrum-web-components/base": "^0.7.0",
|
|
108
|
-
"@spectrum-web-components/shared": "^0.15.
|
|
109
|
-
"@spectrum-web-components/theme": "^0.14.
|
|
108
|
+
"@spectrum-web-components/shared": "^0.15.1",
|
|
109
|
+
"@spectrum-web-components/theme": "^0.14.4",
|
|
110
110
|
"tslib": "^2.0.0"
|
|
111
111
|
},
|
|
112
112
|
"types": "./src/index.d.ts",
|
|
@@ -118,5 +118,5 @@
|
|
|
118
118
|
"./stories/overlay-story-components.js",
|
|
119
119
|
"./**/*.dev.js"
|
|
120
120
|
],
|
|
121
|
-
"gitHead": "
|
|
121
|
+
"gitHead": "96da2eef637c5d50dd04a75d40a46353116787b4"
|
|
122
122
|
}
|
package/src/ActiveOverlay.dev.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["ActiveOverlay.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { reparentChildren } from '@spectrum-web-components/shared/src/reparent-children.js';\nimport { firstFocusableIn } from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport type {\n Color,\n Scale,\n ThemeVariant,\n} from '@spectrum-web-components/theme/src/Theme.js';\nimport styles from './active-overlay.css.js';\nimport { parentOverlayOf } from './overlay-utils.dev.js'\nimport {\n OverlayOpenCloseDetail,\n OverlayOpenDetail,\n Placement,\n TriggerInteractions,\n} from './overlay-types.dev.js'\nimport type { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport {\n arrow,\n computePosition,\n flip,\n Placement as FloatingUIPlacement,\n offset,\n shift,\n size,\n} from '@floating-ui/dom';\n\nexport interface PositionResult {\n arrowOffsetLeft: number;\n arrowOffsetTop: number;\n maxHeight: number;\n placement: string;\n positionLeft: number;\n positionTop: number;\n}\n\ntype OverlayStateType = 'idle' | 'active' | 'hiding' | 'dispose' | 'disposed';\ntype ContentAnimation = 'sp-overlay-fade-in' | 'sp-overlay-fade-out';\n\nconst stateMachine: {\n initial: OverlayStateType;\n states: {\n [stateName: string]: {\n on: {\n [transitionName: string]: OverlayStateType;\n };\n };\n };\n} = {\n initial: 'idle',\n states: {\n idle: {\n on: {\n active: 'active',\n },\n },\n active: {\n on: {\n hiding: 'hiding',\n idle: 'idle',\n },\n },\n hiding: {\n on: {\n dispose: 'dispose',\n },\n },\n dispose: {\n on: {\n disposed: 'disposed',\n },\n },\n disposed: {\n on: {},\n },\n },\n};\n\nconst stateTransition = (\n state?: OverlayStateType,\n event?: string\n): OverlayStateType => {\n if (!state) return stateMachine.initial;\n /* c8 ignore next */\n if (!event) return state;\n return stateMachine.states[state].on[event] || state;\n};\n\nconst getFallbackPlacements = (\n placement: FloatingUIPlacement\n): FloatingUIPlacement[] => {\n const fallbacks: Record<FloatingUIPlacement, FloatingUIPlacement[]> = {\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 * @element active-overlay\n *\n * @slot - content to display in the overlay\n */\nexport class ActiveOverlay extends SpectrumElement {\n public overlayContent!: HTMLElement;\n public overlayContentTip?: HTMLElement;\n public trigger!: HTMLElement;\n public root?: HTMLElement;\n public virtualTrigger?: VirtualTrigger;\n\n protected childrenReady!: Promise<unknown[]>;\n\n @property()\n public _state = stateTransition();\n public get state(): OverlayStateType {\n return this._state;\n }\n public set state(state: OverlayStateType) {\n const nextState = stateTransition(this.state, state);\n if (nextState === this.state) {\n return;\n }\n this._state = nextState;\n if (this.state === 'active' || this.state === 'hiding') {\n this.setAttribute('state', this.state);\n } else {\n this.removeAttribute('state');\n }\n }\n\n @property({ reflect: true, type: Boolean })\n public animating = false;\n\n @property({ reflect: true })\n public placement?: Placement;\n @property({ attribute: false })\n public theme: {\n color?: Color;\n scale?: Scale;\n lang?: string;\n theme?: ThemeVariant;\n } = {};\n @property({ attribute: false })\n public receivesFocus?: 'auto';\n\n public tabbingAway = false;\n private originalPlacement?: Placement;\n private restoreContent?: () => Element[];\n\n public override async focus(): Promise<void> {\n const firstFocusable = firstFocusableIn(this);\n if (firstFocusable) {\n if ((firstFocusable as SpectrumElement).updateComplete) {\n await firstFocusable.updateComplete;\n }\n const activeElement = (this.getRootNode() as Document)\n .activeElement;\n if (activeElement === this || !this.contains(activeElement)) {\n firstFocusable.focus();\n }\n /* c8 ignore next 3 */\n } else {\n super.focus();\n }\n this.removeAttribute('tabindex');\n }\n\n private get hasTheme(): boolean {\n return !!this.theme.color || !!this.theme.scale || !!this.theme.lang;\n }\n\n public offset = 6;\n public skidding = 0;\n public interaction: TriggerInteractions = 'hover';\n private positionAnimationFrame = 0;\n\n private timeout?: number;\n\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n public constructor() {\n super();\n this.stealOverlayContentPromise = new Promise(\n (res) => (this.stealOverlayContentResolver = res)\n );\n }\n\n private _modalRoot?: ActiveOverlay;\n\n public get hasModalRoot(): boolean {\n return !!this._modalRoot;\n }\n\n public feature(): void {\n // eslint-disable-next-line spectrum-web-components/document-active-element\n if (!this.contains(document.activeElement)) {\n this.tabIndex = -1;\n }\n const parentOverlay = parentOverlayOf(this.trigger);\n const parentIsModal = parentOverlay && parentOverlay.slot === 'open';\n if (parentIsModal) {\n this._modalRoot = parentOverlay._modalRoot || parentOverlay;\n }\n // If an overlay it triggered from within a \"modal\" overlay, it needs to continue\n // to act like one to get treated correctly in regards to tab trapping.\n if (this.interaction === 'modal' || this._modalRoot) {\n this.slot = 'open';\n if (this.interaction === 'modal') {\n this.setAttribute('aria-modal', 'true');\n }\n // If this isn't a modal root, walk up the overlays to the next modal root\n // and \"feature\" each on of the intervening overlays.\n if (this._modalRoot) {\n parentOverlay?.feature();\n }\n }\n }\n\n public obscure(\n nextOverlayInteraction: TriggerInteractions\n ): ActiveOverlay | undefined {\n if (this.slot && nextOverlayInteraction === 'modal') {\n this.removeAttribute('slot');\n this.removeAttribute('aria-modal');\n // Obscure upto and including the next modal root.\n if (this.interaction !== 'modal') {\n const parentOverlay = parentOverlayOf(this.trigger);\n this._modalRoot = parentOverlay?.obscure(\n nextOverlayInteraction\n );\n return this._modalRoot;\n }\n return this;\n }\n return undefined;\n }\n\n public override async willUpdate(): Promise<void> {\n if (this.hasUpdated) return;\n\n /* c8 ignore next */\n if (!this.overlayContent || !this.trigger) return;\n\n this.stealOverlayContent(\n this.overlayContent as HTMLElement & { placement: Placement }\n );\n\n this.state = 'active';\n this.feature();\n if (this.placement === 'none') {\n this.style.setProperty(\n '--swc-visual-viewport-height',\n `${window.innerHeight}px`\n );\n } else if (this.placement) {\n await this.updateOverlayPosition();\n document.addEventListener(\n 'sp-update-overlays',\n this.updateOverlayPosition\n );\n window.addEventListener('scroll', this.updateOverlayPosition);\n }\n const actions: Promise<unknown>[] = [];\n if (this.placement && this.placement !== 'none') {\n actions.push(this.applyContentAnimation('sp-overlay-fade-in'));\n }\n if (\n typeof (this.overlayContent as SpectrumElement).updateComplete !==\n 'undefined'\n ) {\n actions.push(\n (this.overlayContent as SpectrumElement).updateComplete\n );\n }\n this.childrenReady = Promise.all(actions);\n }\n\n public async openCallback(\n lifecycleCallback: () => Promise<void> | void\n ): Promise<void> {\n await this.updateComplete;\n if (this.receivesFocus) {\n await this.focus();\n }\n\n await lifecycleCallback();\n\n this.trigger.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>('sp-opened', {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail: {\n interaction: this.interaction,\n },\n })\n );\n }\n\n private open(openDetail: OverlayOpenDetail): void {\n this.extractDetail(openDetail);\n }\n\n private extractDetail(detail: OverlayOpenDetail): void {\n this.overlayContent = detail.content;\n this.overlayContentTip = detail.contentTip;\n this.trigger = detail.trigger;\n this.virtualTrigger = detail.virtualTrigger;\n this.placement = detail.placement;\n this.offset = detail.offset;\n this.skidding = detail.skidding || 0;\n this.interaction = detail.interaction;\n this.theme = detail.theme;\n this.receivesFocus = detail.receivesFocus;\n this.root = detail.root;\n }\n\n public dispose(): void {\n /* c8 ignore next */\n if (this.state !== 'dispose') return;\n\n /* c8 ignore next 4 */\n if (this.timeout) {\n clearTimeout(this.timeout);\n delete this.timeout;\n }\n\n this.trigger.removeEventListener(\n 'keydown',\n this.handleInlineTriggerKeydown\n );\n\n this.returnOverlayContent();\n this.state = 'disposed';\n\n if (this.willNotifyClosed) {\n this.overlayContent.dispatchEvent(new Event('sp-overlay-closed'));\n this.willNotifyClosed = false;\n }\n }\n\n private stealOverlayContent(\n element: HTMLElement & { placement: Placement }\n ): void {\n this.originalPlacement = element.getAttribute('placement') as Placement;\n this.restoreContent = reparentChildren([element], this, {\n position: 'beforeend',\n prepareCallback: (el) => {\n const slotName = el.slot;\n const placement = el.placement;\n el.removeAttribute('slot');\n return (el) => {\n el.slot = slotName;\n el.placement = placement;\n };\n },\n });\n this.stealOverlayContentResolver();\n }\n\n private willNotifyClosed = false;\n\n private returnOverlayContent(): void {\n /* c8 ignore next */\n if (!this.restoreContent) return;\n\n const [element] = this.restoreContent();\n this.restoreContent = undefined;\n this.willNotifyClosed = true;\n\n if (this.originalPlacement) {\n element.setAttribute('placement', this.originalPlacement);\n delete this.originalPlacement;\n }\n }\n\n private initialHeight!: number;\n private isConstrained = false;\n\n public updateOverlayPosition = async (): Promise<void> => {\n if (!this.placement || this.placement === 'none') {\n return;\n }\n await (document.fonts ? document.fonts.ready : Promise.resolve());\n\n function roundByDPR(num: number): number {\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\n const REQUIRED_DISTANCE_TO_EDGE = 8;\n // See: https://github.com/adobe/spectrum-web-components/issues/910\n const MIN_OVERLAY_HEIGHT = 100;\n\n const flipMiddleware = this.virtualTrigger\n ? flip({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n fallbackPlacements: getFallbackPlacements(this.placement),\n })\n : flip({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n });\n\n const middleware = [\n offset({\n mainAxis: this.offset,\n crossAxis: this.skidding,\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 =\n !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(this.style, {\n maxWidth: `${Math.floor(availableWidth)}px`,\n maxHeight: appliedHeight,\n height: appliedHeight,\n });\n },\n }),\n ];\n if (this.overlayContentTip) {\n middleware.push(arrow({ element: this.overlayContentTip }));\n }\n const { x, y, placement, middlewareData } = await computePosition(\n this.virtualTrigger || this.trigger,\n this,\n {\n placement: this.placement,\n middleware,\n }\n );\n\n Object.assign(this.style, {\n top: '0px',\n left: '0px',\n transform: `translate(${roundByDPR(x)}px, ${roundByDPR(y)}px)`,\n });\n\n if (placement !== this.getAttribute('actual-placement')) {\n this.setAttribute('actual-placement', placement);\n this.overlayContent.setAttribute('placement', placement);\n }\n\n if (this.overlayContentTip && middlewareData.arrow) {\n const { x: arrowX, y: arrowY } = middlewareData.arrow;\n\n Object.assign(this.overlayContentTip.style, {\n left: arrowX != null ? `${roundByDPR(arrowX)}px` : '',\n top: arrowY != null ? `${roundByDPR(arrowY)}px` : '',\n right: '',\n bottom: '',\n });\n }\n };\n\n public async hide(animated = true): Promise<void> {\n this.state = 'hiding';\n if (animated) {\n await this.applyContentAnimation('sp-overlay-fade-out');\n }\n this.state = 'dispose';\n }\n\n private schedulePositionUpdate(): void {\n // Edge needs a little time to update the DOM before computing the layout\n cancelAnimationFrame(this.positionAnimationFrame);\n this.positionAnimationFrame = requestAnimationFrame(() =>\n this.updateOverlayPosition()\n );\n }\n\n private onSlotChange(): void {\n this.schedulePositionUpdate();\n }\n\n public handleInlineTriggerKeydown = (event: KeyboardEvent): void => {\n const { code, shiftKey } = event;\n /* c8 ignore next */\n if (code !== 'Tab') return;\n if (shiftKey) {\n this.tabbingAway = true;\n this.dispatchEvent(new Event('close'));\n return;\n }\n\n event.stopPropagation();\n event.preventDefault();\n this.focus();\n };\n\n public applyContentAnimation(\n animation: ContentAnimation\n ): Promise<boolean> {\n if (this.placement === 'none') {\n return Promise.resolve(true);\n }\n return new Promise((resolve): void => {\n const contents = this.shadowRoot.querySelector(\n '#contents'\n ) as HTMLElement;\n const doneHandler = (event: AnimationEvent): void => {\n if (animation !== event.animationName) return;\n contents.removeEventListener('animationend', doneHandler);\n contents.removeEventListener('animationcancel', doneHandler);\n this.animating = false;\n resolve(event.type === 'animationcancel');\n };\n contents.addEventListener('animationend', doneHandler);\n contents.addEventListener('animationcancel', doneHandler);\n\n contents.style.animationName = animation;\n this.animating = true;\n });\n }\n\n public renderTheme(content: TemplateResult): TemplateResult {\n const { color, scale, lang, theme } = this.theme;\n return html`\n <sp-theme\n theme=${ifDefined(theme)}\n color=${ifDefined(color)}\n scale=${ifDefined(scale)}\n lang=${ifDefined(lang)}\n part=\"theme\"\n >\n ${content}\n </sp-theme>\n `;\n }\n\n public override render(): TemplateResult {\n const content = html`\n <div id=\"contents\">\n <slot @slotchange=${this.onSlotChange}></slot>\n </div>\n `;\n return this.hasTheme ? this.renderTheme(content) : content;\n }\n\n public static create(details: OverlayOpenDetail): ActiveOverlay {\n const overlay = new ActiveOverlay();\n\n if (details.content) {\n overlay.open(details);\n }\n\n return overlay;\n }\n\n private stealOverlayContentPromise = Promise.resolve();\n private stealOverlayContentResolver!: () => void;\n\n protected override async getUpdateComplete(): Promise<boolean> {\n const actions: Promise<unknown>[] = [\n super.getUpdateComplete(),\n this.stealOverlayContentPromise,\n ];\n if (this.childrenReady) {\n actions.push(this.childrenReady);\n }\n const [complete] = await Promise.all(actions);\n return complete as boolean;\n }\n\n override disconnectedCallback(): void {\n document.removeEventListener(\n 'sp-update-overlays',\n this.updateOverlayPosition\n );\n window.removeEventListener('scroll', this.updateOverlayPosition);\n super.disconnectedCallback();\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,EACA;AAAA,OAEG;AACP,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AAMjC,OAAO,YAAY;AACnB,SAAS,uBAAuB;AAQhC;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAcP,MAAM,eASF;AAAA,EACA,SAAS;AAAA,EACT,QAAQ;AAAA,IACJ,MAAM;AAAA,MACF,IAAI;AAAA,QACA,QAAQ;AAAA,MACZ;AAAA,IACJ;AAAA,IACA,QAAQ;AAAA,MACJ,IAAI;AAAA,QACA,QAAQ;AAAA,QACR,MAAM;AAAA,MACV;AAAA,IACJ;AAAA,IACA,QAAQ;AAAA,MACJ,IAAI;AAAA,QACA,SAAS;AAAA,MACb;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,MACL,IAAI;AAAA,QACA,UAAU;AAAA,MACd;AAAA,IACJ;AAAA,IACA,UAAU;AAAA,MACN,IAAI,CAAC;AAAA,IACT;AAAA,EACJ;AACJ;AAEA,MAAM,kBAAkB,CACpB,OACA,UACmB;AACnB,MAAI,CAAC;AAAO,WAAO,aAAa;AAEhC,MAAI,CAAC;AAAO,WAAO;AACnB,SAAO,aAAa,OAAO,OAAO,GAAG,UAAU;AACnD;AAEA,MAAM,wBAAwB,CAC1B,cACwB;AA7G5B;AA8GI,QAAM,YAAgE;AAAA,IAClE,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,eAAV,YAAwB,CAAC,SAAS;AAC7C;AAOO,MAAM,iBAAN,cAA4B,gBAAgB;AAAA,EA+ExC,cAAc;AACjB,UAAM;AAtEV,SAAO,SAAS,gBAAgB;AAkBhC,SAAO,YAAY;AAKnB,SAAO,QAKH,CAAC;AAIL,SAAO,cAAc;AA0BrB,SAAO,SAAS;AAChB,SAAO,WAAW;AAClB,SAAO,cAAmC;AAC1C,SAAQ,yBAAyB;
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { reparentChildren } from '@spectrum-web-components/shared/src/reparent-children.js';\nimport { firstFocusableIn } from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport type {\n Color,\n Scale,\n ThemeVariant,\n} from '@spectrum-web-components/theme/src/Theme.js';\nimport styles from './active-overlay.css.js';\nimport { parentOverlayOf } from './overlay-utils.dev.js'\nimport {\n OverlayOpenCloseDetail,\n OverlayOpenDetail,\n Placement,\n TriggerInteractions,\n} from './overlay-types.dev.js'\nimport type { VirtualTrigger } from './VirtualTrigger.dev.js'\nimport {\n arrow,\n computePosition,\n flip,\n Placement as FloatingUIPlacement,\n offset,\n shift,\n size,\n} from '@floating-ui/dom';\n\nexport interface PositionResult {\n arrowOffsetLeft: number;\n arrowOffsetTop: number;\n maxHeight: number;\n placement: string;\n positionLeft: number;\n positionTop: number;\n}\n\ntype OverlayStateType = 'idle' | 'active' | 'hiding' | 'dispose' | 'disposed';\ntype ContentAnimation = 'sp-overlay-fade-in' | 'sp-overlay-fade-out';\n\nconst stateMachine: {\n initial: OverlayStateType;\n states: {\n [stateName: string]: {\n on: {\n [transitionName: string]: OverlayStateType;\n };\n };\n };\n} = {\n initial: 'idle',\n states: {\n idle: {\n on: {\n active: 'active',\n },\n },\n active: {\n on: {\n hiding: 'hiding',\n idle: 'idle',\n },\n },\n hiding: {\n on: {\n dispose: 'dispose',\n },\n },\n dispose: {\n on: {\n disposed: 'disposed',\n },\n },\n disposed: {\n on: {},\n },\n },\n};\n\nconst stateTransition = (\n state?: OverlayStateType,\n event?: string\n): OverlayStateType => {\n if (!state) return stateMachine.initial;\n /* c8 ignore next */\n if (!event) return state;\n return stateMachine.states[state].on[event] || state;\n};\n\nconst getFallbackPlacements = (\n placement: FloatingUIPlacement\n): FloatingUIPlacement[] => {\n const fallbacks: Record<FloatingUIPlacement, FloatingUIPlacement[]> = {\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 * @element active-overlay\n *\n * @slot - content to display in the overlay\n */\nexport class ActiveOverlay extends SpectrumElement {\n public overlayContent!: HTMLElement;\n public overlayContentTip?: HTMLElement;\n public trigger!: HTMLElement;\n public root?: HTMLElement;\n public virtualTrigger?: VirtualTrigger;\n\n protected childrenReady!: Promise<unknown[]>;\n\n @property()\n public _state = stateTransition();\n public get state(): OverlayStateType {\n return this._state;\n }\n public set state(state: OverlayStateType) {\n const nextState = stateTransition(this.state, state);\n if (nextState === this.state) {\n return;\n }\n this._state = nextState;\n if (this.state === 'active' || this.state === 'hiding') {\n this.setAttribute('state', this.state);\n } else {\n this.removeAttribute('state');\n }\n }\n\n @property({ reflect: true, type: Boolean })\n public animating = false;\n\n @property({ reflect: true })\n public placement?: Placement;\n @property({ attribute: false })\n public theme: {\n color?: Color;\n scale?: Scale;\n lang?: string;\n theme?: ThemeVariant;\n } = {};\n @property({ attribute: false })\n public receivesFocus?: 'auto';\n\n public tabbingAway = false;\n private originalPlacement?: Placement;\n private restoreContent?: () => Element[];\n\n public override async focus(): Promise<void> {\n const firstFocusable = firstFocusableIn(this);\n if (firstFocusable) {\n if ((firstFocusable as SpectrumElement).updateComplete) {\n await firstFocusable.updateComplete;\n }\n const activeElement = (this.getRootNode() as Document)\n .activeElement;\n if (activeElement === this || !this.contains(activeElement)) {\n firstFocusable.focus();\n }\n /* c8 ignore next 3 */\n } else {\n super.focus();\n }\n this.removeAttribute('tabindex');\n }\n\n private get hasTheme(): boolean {\n return !!this.theme.color || !!this.theme.scale || !!this.theme.lang;\n }\n\n public offset = 6;\n public skidding = 0;\n public interaction: TriggerInteractions = 'hover';\n private positionAnimationFrame = 0;\n\n private timeout?: number;\n\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n public constructor() {\n super();\n this.stealOverlayContentPromise = new Promise(\n (res) => (this.stealOverlayContentResolver = res)\n );\n }\n\n private _modalRoot?: ActiveOverlay;\n\n public get hasModalRoot(): boolean {\n return !!this._modalRoot;\n }\n\n public feature(): void {\n // eslint-disable-next-line spectrum-web-components/document-active-element\n if (!this.contains(document.activeElement)) {\n this.tabIndex = -1;\n }\n const parentOverlay = parentOverlayOf(this.trigger);\n const parentIsModal = parentOverlay && parentOverlay.slot === 'open';\n if (parentIsModal) {\n this._modalRoot = parentOverlay._modalRoot || parentOverlay;\n }\n // If an overlay it triggered from within a \"modal\" overlay, it needs to continue\n // to act like one to get treated correctly in regards to tab trapping.\n if (this.interaction === 'modal' || this._modalRoot) {\n this.slot = 'open';\n if (this.interaction === 'modal') {\n this.setAttribute('aria-modal', 'true');\n }\n // If this isn't a modal root, walk up the overlays to the next modal root\n // and \"feature\" each on of the intervening overlays.\n if (this._modalRoot) {\n parentOverlay?.feature();\n }\n }\n }\n\n public obscure(\n nextOverlayInteraction: TriggerInteractions\n ): ActiveOverlay | undefined {\n if (this.slot && nextOverlayInteraction === 'modal') {\n this.removeAttribute('slot');\n this.removeAttribute('aria-modal');\n // Obscure upto and including the next modal root.\n if (this.interaction !== 'modal') {\n const parentOverlay = parentOverlayOf(this.trigger);\n this._modalRoot = parentOverlay?.obscure(\n nextOverlayInteraction\n );\n return this._modalRoot;\n }\n return this;\n }\n return undefined;\n }\n\n public override async willUpdate(): Promise<void> {\n if (this.hasUpdated) return;\n\n /* c8 ignore next */\n if (!this.overlayContent || !this.trigger) return;\n\n this.stealOverlayContent(\n this.overlayContent as HTMLElement & { placement: Placement }\n );\n\n this.state = 'active';\n\n // force paint\n // this prevents a timing issue that can show up in tests as\n // 'Error: Timeout: Wait for decorator to become ready...'\n this.offsetWidth;\n\n this.feature();\n if (this.placement === 'none') {\n this.style.setProperty(\n '--swc-visual-viewport-height',\n `${window.innerHeight}px`\n );\n } else if (this.placement) {\n await this.updateOverlayPosition();\n document.addEventListener(\n 'sp-update-overlays',\n this.updateOverlayPosition\n );\n window.addEventListener('scroll', this.updateOverlayPosition);\n }\n const actions: Promise<unknown>[] = [];\n if (this.placement && this.placement !== 'none') {\n actions.push(this.applyContentAnimation('sp-overlay-fade-in'));\n }\n if (\n typeof (this.overlayContent as SpectrumElement).updateComplete !==\n 'undefined'\n ) {\n actions.push(\n (this.overlayContent as SpectrumElement).updateComplete\n );\n }\n this.childrenReady = Promise.all(actions);\n }\n\n public async openCallback(\n lifecycleCallback: () => Promise<void> | void\n ): Promise<void> {\n await this.updateComplete;\n if (this.receivesFocus) {\n await this.focus();\n }\n\n await lifecycleCallback();\n\n this.trigger.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>('sp-opened', {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail: {\n interaction: this.interaction,\n },\n })\n );\n }\n\n private open(openDetail: OverlayOpenDetail): void {\n this.extractDetail(openDetail);\n }\n\n private extractDetail(detail: OverlayOpenDetail): void {\n this.overlayContent = detail.content;\n this.overlayContentTip = detail.contentTip;\n this.trigger = detail.trigger;\n this.virtualTrigger = detail.virtualTrigger;\n this.placement = detail.placement;\n this.offset = detail.offset;\n this.skidding = detail.skidding || 0;\n this.interaction = detail.interaction;\n this.theme = detail.theme;\n this.receivesFocus = detail.receivesFocus;\n this.root = detail.root;\n }\n\n public dispose(): void {\n /* c8 ignore next */\n if (this.state !== 'dispose') return;\n\n /* c8 ignore next 4 */\n if (this.timeout) {\n clearTimeout(this.timeout);\n delete this.timeout;\n }\n\n this.trigger.removeEventListener(\n 'keydown',\n this.handleInlineTriggerKeydown\n );\n\n this.returnOverlayContent();\n this.state = 'disposed';\n\n if (this.willNotifyClosed) {\n this.overlayContent.dispatchEvent(new Event('sp-overlay-closed'));\n this.willNotifyClosed = false;\n }\n }\n\n private stealOverlayContent(\n element: HTMLElement & { placement: Placement }\n ): void {\n this.originalPlacement = element.getAttribute('placement') as Placement;\n this.restoreContent = reparentChildren([element], this, {\n position: 'beforeend',\n prepareCallback: (el) => {\n const slotName = el.slot;\n const placement = el.placement;\n el.removeAttribute('slot');\n return (el) => {\n el.slot = slotName;\n el.placement = placement;\n };\n },\n });\n this.stealOverlayContentResolver();\n }\n\n private willNotifyClosed = false;\n\n private returnOverlayContent(): void {\n /* c8 ignore next */\n if (!this.restoreContent) return;\n\n const [element] = this.restoreContent();\n this.restoreContent = undefined;\n this.willNotifyClosed = true;\n\n if (this.originalPlacement) {\n element.setAttribute('placement', this.originalPlacement);\n delete this.originalPlacement;\n }\n }\n\n private initialHeight!: number;\n private isConstrained = false;\n\n public updateOverlayPosition = async (): Promise<void> => {\n if (!this.placement || this.placement === 'none') {\n return;\n }\n await (document.fonts ? document.fonts.ready : Promise.resolve());\n\n function roundByDPR(num: number): number {\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\n const REQUIRED_DISTANCE_TO_EDGE = 8;\n // See: https://github.com/adobe/spectrum-web-components/issues/910\n const MIN_OVERLAY_HEIGHT = 100;\n\n const flipMiddleware = this.virtualTrigger\n ? flip({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n fallbackPlacements: getFallbackPlacements(this.placement),\n })\n : flip({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n });\n\n const middleware = [\n offset({\n mainAxis: this.offset,\n crossAxis: this.skidding,\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 =\n !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(this.style, {\n maxWidth: `${Math.floor(availableWidth)}px`,\n maxHeight: appliedHeight,\n height: appliedHeight,\n });\n },\n }),\n ];\n if (this.overlayContentTip) {\n middleware.push(arrow({ element: this.overlayContentTip }));\n }\n const { x, y, placement, middlewareData } = await computePosition(\n this.virtualTrigger || this.trigger,\n this,\n {\n placement: this.placement,\n middleware,\n }\n );\n\n Object.assign(this.style, {\n top: '0px',\n left: '0px',\n transform: `translate(${roundByDPR(x)}px, ${roundByDPR(y)}px)`,\n });\n\n if (placement !== this.getAttribute('actual-placement')) {\n this.setAttribute('actual-placement', placement);\n this.overlayContent.setAttribute('placement', placement);\n }\n\n if (this.overlayContentTip && middlewareData.arrow) {\n const { x: arrowX, y: arrowY } = middlewareData.arrow;\n\n Object.assign(this.overlayContentTip.style, {\n left: arrowX != null ? `${roundByDPR(arrowX)}px` : '',\n top: arrowY != null ? `${roundByDPR(arrowY)}px` : '',\n right: '',\n bottom: '',\n });\n }\n };\n\n public async hide(animated = true): Promise<void> {\n this.state = 'hiding';\n if (animated) {\n await this.applyContentAnimation('sp-overlay-fade-out');\n }\n this.state = 'dispose';\n }\n\n private schedulePositionUpdate(): void {\n // Edge needs a little time to update the DOM before computing the layout\n cancelAnimationFrame(this.positionAnimationFrame);\n this.positionAnimationFrame = requestAnimationFrame(() =>\n this.updateOverlayPosition()\n );\n }\n\n private onSlotChange(): void {\n this.schedulePositionUpdate();\n }\n\n public handleInlineTriggerKeydown = (event: KeyboardEvent): void => {\n const { code, shiftKey } = event;\n /* c8 ignore next */\n if (code !== 'Tab') return;\n if (shiftKey) {\n this.tabbingAway = true;\n this.dispatchEvent(new Event('close'));\n return;\n }\n\n event.stopPropagation();\n event.preventDefault();\n this.focus();\n };\n\n public applyContentAnimation(\n animation: ContentAnimation\n ): Promise<boolean> {\n if (this.placement === 'none') {\n return Promise.resolve(true);\n }\n return new Promise((resolve): void => {\n const contents = this.shadowRoot.querySelector(\n '#contents'\n ) as HTMLElement;\n const doneHandler = (event: AnimationEvent): void => {\n if (animation !== event.animationName) return;\n contents.removeEventListener('animationend', doneHandler);\n contents.removeEventListener('animationcancel', doneHandler);\n this.animating = false;\n resolve(event.type === 'animationcancel');\n };\n contents.addEventListener('animationend', doneHandler);\n contents.addEventListener('animationcancel', doneHandler);\n\n contents.style.animationName = animation;\n this.animating = true;\n });\n }\n\n public renderTheme(content: TemplateResult): TemplateResult {\n const { color, scale, lang, theme } = this.theme;\n return html`\n <sp-theme\n theme=${ifDefined(theme)}\n color=${ifDefined(color)}\n scale=${ifDefined(scale)}\n lang=${ifDefined(lang)}\n part=\"theme\"\n >\n ${content}\n </sp-theme>\n `;\n }\n\n public override render(): TemplateResult {\n const content = html`\n <div id=\"contents\">\n <slot @slotchange=${this.onSlotChange}></slot>\n </div>\n `;\n return this.hasTheme ? this.renderTheme(content) : content;\n }\n\n public static create(details: OverlayOpenDetail): ActiveOverlay {\n const overlay = new ActiveOverlay();\n\n if (details.content) {\n overlay.open(details);\n }\n\n return overlay;\n }\n\n private stealOverlayContentPromise = Promise.resolve();\n private stealOverlayContentResolver!: () => void;\n\n protected override async getUpdateComplete(): Promise<boolean> {\n const actions: Promise<unknown>[] = [\n super.getUpdateComplete(),\n this.stealOverlayContentPromise,\n ];\n if (this.childrenReady) {\n actions.push(this.childrenReady);\n }\n const [complete] = await Promise.all(actions);\n return complete as boolean;\n }\n\n override disconnectedCallback(): void {\n document.removeEventListener(\n 'sp-update-overlays',\n this.updateOverlayPosition\n );\n window.removeEventListener('scroll', this.updateOverlayPosition);\n super.disconnectedCallback();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,EACA;AAAA,OAEG;AACP,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AAMjC,OAAO,YAAY;AACnB,SAAS,uBAAuB;AAQhC;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAcP,MAAM,eASF;AAAA,EACA,SAAS;AAAA,EACT,QAAQ;AAAA,IACJ,MAAM;AAAA,MACF,IAAI;AAAA,QACA,QAAQ;AAAA,MACZ;AAAA,IACJ;AAAA,IACA,QAAQ;AAAA,MACJ,IAAI;AAAA,QACA,QAAQ;AAAA,QACR,MAAM;AAAA,MACV;AAAA,IACJ;AAAA,IACA,QAAQ;AAAA,MACJ,IAAI;AAAA,QACA,SAAS;AAAA,MACb;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,MACL,IAAI;AAAA,QACA,UAAU;AAAA,MACd;AAAA,IACJ;AAAA,IACA,UAAU;AAAA,MACN,IAAI,CAAC;AAAA,IACT;AAAA,EACJ;AACJ;AAEA,MAAM,kBAAkB,CACpB,OACA,UACmB;AACnB,MAAI,CAAC;AAAO,WAAO,aAAa;AAEhC,MAAI,CAAC;AAAO,WAAO;AACnB,SAAO,aAAa,OAAO,OAAO,GAAG,UAAU;AACnD;AAEA,MAAM,wBAAwB,CAC1B,cACwB;AA7G5B;AA8GI,QAAM,YAAgE;AAAA,IAClE,MAAM,CAAC,SAAS,UAAU,KAAK;AAAA,IAC/B,cAAc,CAAC,eAAe,UAAU,KAAK;AAAA,IAC7C,YAAY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AAAA,EACvD;AAAA,EAEA,OAAc,OAAO,SAA2C;AAC5D,UAAM,UAAU,IAAI,eAAc;AAElC,QAAI,QAAQ,SAAS;AACjB,cAAQ,KAAK,OAAO;AAAA,IACxB;AAEA,WAAO;AAAA,EACX;AAAA,EAKA,MAAyB,oBAAsC;AAC3D,UAAM,UAA8B;AAAA,MAChC,MAAM,kBAAkB;AAAA,MACxB,KAAK;AAAA,IACT;AACA,QAAI,KAAK,eAAe;AACpB,cAAQ,KAAK,KAAK,aAAa;AAAA,IACnC;AACA,UAAM,CAAC,QAAQ,IAAI,MAAM,QAAQ,IAAI,OAAO;AAC5C,WAAO;AAAA,EACX;AAAA,EAES,uBAA6B;AAClC,aAAS;AAAA,MACL;AAAA,MACA,KAAK;AAAA,IACT;AACA,WAAO,oBAAoB,UAAU,KAAK,qBAAqB;AAC/D,UAAM,qBAAqB;AAAA,EAC/B;AACJ;AAlfO,WAAM,gBAAN;AAUI;AAAA,EADN,SAAS;AAAA,GATD,cAUF;AAkBA;AAAA,EADN,SAAS,EAAE,SAAS,MAAM,MAAM,QAAQ,CAAC;AAAA,GA3BjC,cA4BF;AAGA;AAAA,EADN,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,GA9BlB,cA+BF;AAEA;AAAA,EADN,SAAS,EAAE,WAAW,MAAM,CAAC;AAAA,GAhCrB,cAiCF;AAOA;AAAA,EADN,SAAS,EAAE,WAAW,MAAM,CAAC;AAAA,GAvCrB,cAwCF;",
|
|
6
6
|
"names": ["el"]
|
|
7
7
|
}
|
package/src/ActiveOverlay.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var R=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var p=(s,a,t,e)=>{for(var i=e>1?void 0:e?A(a,t):a,o=s.length-1,n;o>=0;o--)(n=s[o])&&(i=(e?n(a,t,i):n(i))||i);return e&&i&&R(a,t,i),i};import{html as b,SpectrumElement as x}from"@spectrum-web-components/base";import{ifDefined as h}from"@spectrum-web-components/base/src/directives.js";import{property as c}from"@spectrum-web-components/base/src/decorators.js";import{reparentChildren as S}from"@spectrum-web-components/shared/src/reparent-children.js";import{firstFocusableIn as H}from"@spectrum-web-components/shared/src/first-focusable-in.js";import L from"./active-overlay.css.js";import{parentOverlayOf as y}from"./overlay-utils.js";import{arrow as F,computePosition as I,flip as C,offset as M,shift as k,size as D}from"@floating-ui/dom";const P={initial:"idle",states:{idle:{on:{active:"active"}},active:{on:{hiding:"hiding",idle:"idle"}},hiding:{on:{dispose:"dispose"}},dispose:{on:{disposed:"disposed"}},disposed:{on:{}}}},T=(s,a)=>s?a&&P.states[s].on[a]||s:P.initial,_=s=>{var t;return(t={left:["right","bottom","top"],"left-start":["right-start","bottom","top"],"left-end":["right-end","bottom","top"],right:["left","bottom","top"],"right-start":["left-start","bottom","top"],"right-end":["left-end","bottom","top"],top:["bottom","left","right"],"top-start":["bottom-start","left","right"],"top-end":["bottom-end","left","right"],bottom:["top","left","right"],"bottom-start":["top-start","left","right"],"bottom-end":["top-end","left","right"]}[s])!=null?t:[s]},u=class extends x{constructor(){super();this._state=T();this.animating=!1;this.theme={};this.tabbingAway=!1;this.offset=6;this.skidding=0;this.interaction="hover";this.positionAnimationFrame=0;this.willNotifyClosed=!1;this.isConstrained=!1;this.updateOverlayPosition=async()=>{if(!this.placement||this.placement==="none")return;await(document.fonts?document.fonts.ready:Promise.resolve());function t(l){const r=window.devicePixelRatio||1;return Math.round(l*r)/r||-1e4}const e=8,i=100,o=this.virtualTrigger?C({padding:e,fallbackPlacements:_(this.placement)}):C({padding:e}),n=[M({mainAxis:this.offset,crossAxis:this.skidding}),k({padding:e}),o,D({padding:e,apply:({availableWidth:l,availableHeight:r,rects:{floating:O}})=>{const f=Math.max(i,Math.floor(r)),m=O.height;this.initialHeight=!this.isConstrained&&!this.virtualTrigger?m:this.initialHeight||m,this.isConstrained=m<this.initialHeight||f<=m;const g=this.isConstrained?`${f}px`:"";Object.assign(this.style,{maxWidth:`${Math.floor(l)}px`,maxHeight:g,height:g})}})];this.overlayContentTip&&n.push(F({element:this.overlayContentTip}));const{x:w,y:E,placement:d,middlewareData:v}=await I(this.virtualTrigger||this.trigger,this,{placement:this.placement,middleware:n});if(Object.assign(this.style,{top:"0px",left:"0px",transform:`translate(${t(w)}px, ${t(E)}px)`}),d!==this.getAttribute("actual-placement")&&(this.setAttribute("actual-placement",d),this.overlayContent.setAttribute("placement",d)),this.overlayContentTip&&v.arrow){const{x:l,y:r}=v.arrow;Object.assign(this.overlayContentTip.style,{left:l!=null?`${t(l)}px`:"",top:r!=null?`${t(r)}px`:"",right:"",bottom:""})}};this.handleInlineTriggerKeydown=t=>{const{code:e,shiftKey:i}=t;if(e==="Tab"){if(i){this.tabbingAway=!0,this.dispatchEvent(new Event("close"));return}t.stopPropagation(),t.preventDefault(),this.focus()}};this.stealOverlayContentPromise=Promise.resolve();this.stealOverlayContentPromise=new Promise(t=>this.stealOverlayContentResolver=t)}get state(){return this._state}set state(t){const e=T(this.state,t);e!==this.state&&(this._state=e,this.state==="active"||this.state==="hiding"?this.setAttribute("state",this.state):this.removeAttribute("state"))}async focus(){const t=H(this);if(t){t.updateComplete&&await t.updateComplete;const e=this.getRootNode().activeElement;(e===this||!this.contains(e))&&t.focus()}else super.focus();this.removeAttribute("tabindex")}get hasTheme(){return!!this.theme.color||!!this.theme.scale||!!this.theme.lang}static get styles(){return[L]}get hasModalRoot(){return!!this._modalRoot}feature(){this.contains(document.activeElement)||(this.tabIndex=-1);const t=y(this.trigger);t&&t.slot==="open"&&(this._modalRoot=t._modalRoot||t),(this.interaction==="modal"||this._modalRoot)&&(this.slot="open",this.interaction==="modal"&&this.setAttribute("aria-modal","true"),this._modalRoot&&(t==null||t.feature()))}obscure(t){if(this.slot&&t==="modal"){if(this.removeAttribute("slot"),this.removeAttribute("aria-modal"),this.interaction!=="modal"){const e=y(this.trigger);return this._modalRoot=e==null?void 0:e.obscure(t),this._modalRoot}return this}}async willUpdate(){if(this.hasUpdated||!this.overlayContent||!this.trigger)return;this.stealOverlayContent(this.overlayContent),this.state="active",this.feature(),this.placement==="none"?this.style.setProperty("--swc-visual-viewport-height",`${window.innerHeight}px`):this.placement&&(await this.updateOverlayPosition(),document.addEventListener("sp-update-overlays",this.updateOverlayPosition),window.addEventListener("scroll",this.updateOverlayPosition));const t=[];this.placement&&this.placement!=="none"&&t.push(this.applyContentAnimation("sp-overlay-fade-in")),typeof this.overlayContent.updateComplete!="undefined"&&t.push(this.overlayContent.updateComplete),this.childrenReady=Promise.all(t)}async openCallback(t){await this.updateComplete,this.receivesFocus&&await this.focus(),await t(),this.trigger.dispatchEvent(new CustomEvent("sp-opened",{bubbles:!0,composed:!0,cancelable:!0,detail:{interaction:this.interaction}}))}open(t){this.extractDetail(t)}extractDetail(t){this.overlayContent=t.content,this.overlayContentTip=t.contentTip,this.trigger=t.trigger,this.virtualTrigger=t.virtualTrigger,this.placement=t.placement,this.offset=t.offset,this.skidding=t.skidding||0,this.interaction=t.interaction,this.theme=t.theme,this.receivesFocus=t.receivesFocus,this.root=t.root}dispose(){this.state==="dispose"&&(this.timeout&&(clearTimeout(this.timeout),delete this.timeout),this.trigger.removeEventListener("keydown",this.handleInlineTriggerKeydown),this.returnOverlayContent(),this.state="disposed",this.willNotifyClosed&&(this.overlayContent.dispatchEvent(new Event("sp-overlay-closed")),this.willNotifyClosed=!1))}stealOverlayContent(t){this.originalPlacement=t.getAttribute("placement"),this.restoreContent=S([t],this,{position:"beforeend",prepareCallback:e=>{const i=e.slot,o=e.placement;return e.removeAttribute("slot"),n=>{n.slot=i,n.placement=o}}}),this.stealOverlayContentResolver()}returnOverlayContent(){if(!this.restoreContent)return;const[t]=this.restoreContent();this.restoreContent=void 0,this.willNotifyClosed=!0,this.originalPlacement&&(t.setAttribute("placement",this.originalPlacement),delete this.originalPlacement)}async hide(t=!0){this.state="hiding",t&&await this.applyContentAnimation("sp-overlay-fade-out"),this.state="dispose"}schedulePositionUpdate(){cancelAnimationFrame(this.positionAnimationFrame),this.positionAnimationFrame=requestAnimationFrame(()=>this.updateOverlayPosition())}onSlotChange(){this.schedulePositionUpdate()}applyContentAnimation(t){return this.placement==="none"?Promise.resolve(!0):new Promise(e=>{const i=this.shadowRoot.querySelector("#contents"),o=n=>{t===n.animationName&&(i.removeEventListener("animationend",o),i.removeEventListener("animationcancel",o),this.animating=!1,e(n.type==="animationcancel"))};i.addEventListener("animationend",o),i.addEventListener("animationcancel",o),i.style.animationName=t,this.animating=!0})}renderTheme(t){const{color:e,scale:i,lang:o,theme:n}=this.theme;return b`
|
|
1
|
+
"use strict";var R=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var p=(s,a,t,e)=>{for(var i=e>1?void 0:e?A(a,t):a,o=s.length-1,n;o>=0;o--)(n=s[o])&&(i=(e?n(a,t,i):n(i))||i);return e&&i&&R(a,t,i),i};import{html as b,SpectrumElement as x}from"@spectrum-web-components/base";import{ifDefined as h}from"@spectrum-web-components/base/src/directives.js";import{property as c}from"@spectrum-web-components/base/src/decorators.js";import{reparentChildren as S}from"@spectrum-web-components/shared/src/reparent-children.js";import{firstFocusableIn as H}from"@spectrum-web-components/shared/src/first-focusable-in.js";import L from"./active-overlay.css.js";import{parentOverlayOf as y}from"./overlay-utils.js";import{arrow as F,computePosition as I,flip as C,offset as M,shift as k,size as D}from"@floating-ui/dom";const P={initial:"idle",states:{idle:{on:{active:"active"}},active:{on:{hiding:"hiding",idle:"idle"}},hiding:{on:{dispose:"dispose"}},dispose:{on:{disposed:"disposed"}},disposed:{on:{}}}},T=(s,a)=>s?a&&P.states[s].on[a]||s:P.initial,_=s=>{var t;return(t={left:["right","bottom","top"],"left-start":["right-start","bottom","top"],"left-end":["right-end","bottom","top"],right:["left","bottom","top"],"right-start":["left-start","bottom","top"],"right-end":["left-end","bottom","top"],top:["bottom","left","right"],"top-start":["bottom-start","left","right"],"top-end":["bottom-end","left","right"],bottom:["top","left","right"],"bottom-start":["top-start","left","right"],"bottom-end":["top-end","left","right"]}[s])!=null?t:[s]},u=class extends x{constructor(){super();this._state=T();this.animating=!1;this.theme={};this.tabbingAway=!1;this.offset=6;this.skidding=0;this.interaction="hover";this.positionAnimationFrame=0;this.willNotifyClosed=!1;this.isConstrained=!1;this.updateOverlayPosition=async()=>{if(!this.placement||this.placement==="none")return;await(document.fonts?document.fonts.ready:Promise.resolve());function t(l){const r=window.devicePixelRatio||1;return Math.round(l*r)/r||-1e4}const e=8,i=100,o=this.virtualTrigger?C({padding:e,fallbackPlacements:_(this.placement)}):C({padding:e}),n=[M({mainAxis:this.offset,crossAxis:this.skidding}),k({padding:e}),o,D({padding:e,apply:({availableWidth:l,availableHeight:r,rects:{floating:O}})=>{const f=Math.max(i,Math.floor(r)),m=O.height;this.initialHeight=!this.isConstrained&&!this.virtualTrigger?m:this.initialHeight||m,this.isConstrained=m<this.initialHeight||f<=m;const g=this.isConstrained?`${f}px`:"";Object.assign(this.style,{maxWidth:`${Math.floor(l)}px`,maxHeight:g,height:g})}})];this.overlayContentTip&&n.push(F({element:this.overlayContentTip}));const{x:w,y:E,placement:d,middlewareData:v}=await I(this.virtualTrigger||this.trigger,this,{placement:this.placement,middleware:n});if(Object.assign(this.style,{top:"0px",left:"0px",transform:`translate(${t(w)}px, ${t(E)}px)`}),d!==this.getAttribute("actual-placement")&&(this.setAttribute("actual-placement",d),this.overlayContent.setAttribute("placement",d)),this.overlayContentTip&&v.arrow){const{x:l,y:r}=v.arrow;Object.assign(this.overlayContentTip.style,{left:l!=null?`${t(l)}px`:"",top:r!=null?`${t(r)}px`:"",right:"",bottom:""})}};this.handleInlineTriggerKeydown=t=>{const{code:e,shiftKey:i}=t;if(e==="Tab"){if(i){this.tabbingAway=!0,this.dispatchEvent(new Event("close"));return}t.stopPropagation(),t.preventDefault(),this.focus()}};this.stealOverlayContentPromise=Promise.resolve();this.stealOverlayContentPromise=new Promise(t=>this.stealOverlayContentResolver=t)}get state(){return this._state}set state(t){const e=T(this.state,t);e!==this.state&&(this._state=e,this.state==="active"||this.state==="hiding"?this.setAttribute("state",this.state):this.removeAttribute("state"))}async focus(){const t=H(this);if(t){t.updateComplete&&await t.updateComplete;const e=this.getRootNode().activeElement;(e===this||!this.contains(e))&&t.focus()}else super.focus();this.removeAttribute("tabindex")}get hasTheme(){return!!this.theme.color||!!this.theme.scale||!!this.theme.lang}static get styles(){return[L]}get hasModalRoot(){return!!this._modalRoot}feature(){this.contains(document.activeElement)||(this.tabIndex=-1);const t=y(this.trigger);t&&t.slot==="open"&&(this._modalRoot=t._modalRoot||t),(this.interaction==="modal"||this._modalRoot)&&(this.slot="open",this.interaction==="modal"&&this.setAttribute("aria-modal","true"),this._modalRoot&&(t==null||t.feature()))}obscure(t){if(this.slot&&t==="modal"){if(this.removeAttribute("slot"),this.removeAttribute("aria-modal"),this.interaction!=="modal"){const e=y(this.trigger);return this._modalRoot=e==null?void 0:e.obscure(t),this._modalRoot}return this}}async willUpdate(){if(this.hasUpdated||!this.overlayContent||!this.trigger)return;this.stealOverlayContent(this.overlayContent),this.state="active",this.offsetWidth,this.feature(),this.placement==="none"?this.style.setProperty("--swc-visual-viewport-height",`${window.innerHeight}px`):this.placement&&(await this.updateOverlayPosition(),document.addEventListener("sp-update-overlays",this.updateOverlayPosition),window.addEventListener("scroll",this.updateOverlayPosition));const t=[];this.placement&&this.placement!=="none"&&t.push(this.applyContentAnimation("sp-overlay-fade-in")),typeof this.overlayContent.updateComplete!="undefined"&&t.push(this.overlayContent.updateComplete),this.childrenReady=Promise.all(t)}async openCallback(t){await this.updateComplete,this.receivesFocus&&await this.focus(),await t(),this.trigger.dispatchEvent(new CustomEvent("sp-opened",{bubbles:!0,composed:!0,cancelable:!0,detail:{interaction:this.interaction}}))}open(t){this.extractDetail(t)}extractDetail(t){this.overlayContent=t.content,this.overlayContentTip=t.contentTip,this.trigger=t.trigger,this.virtualTrigger=t.virtualTrigger,this.placement=t.placement,this.offset=t.offset,this.skidding=t.skidding||0,this.interaction=t.interaction,this.theme=t.theme,this.receivesFocus=t.receivesFocus,this.root=t.root}dispose(){this.state==="dispose"&&(this.timeout&&(clearTimeout(this.timeout),delete this.timeout),this.trigger.removeEventListener("keydown",this.handleInlineTriggerKeydown),this.returnOverlayContent(),this.state="disposed",this.willNotifyClosed&&(this.overlayContent.dispatchEvent(new Event("sp-overlay-closed")),this.willNotifyClosed=!1))}stealOverlayContent(t){this.originalPlacement=t.getAttribute("placement"),this.restoreContent=S([t],this,{position:"beforeend",prepareCallback:e=>{const i=e.slot,o=e.placement;return e.removeAttribute("slot"),n=>{n.slot=i,n.placement=o}}}),this.stealOverlayContentResolver()}returnOverlayContent(){if(!this.restoreContent)return;const[t]=this.restoreContent();this.restoreContent=void 0,this.willNotifyClosed=!0,this.originalPlacement&&(t.setAttribute("placement",this.originalPlacement),delete this.originalPlacement)}async hide(t=!0){this.state="hiding",t&&await this.applyContentAnimation("sp-overlay-fade-out"),this.state="dispose"}schedulePositionUpdate(){cancelAnimationFrame(this.positionAnimationFrame),this.positionAnimationFrame=requestAnimationFrame(()=>this.updateOverlayPosition())}onSlotChange(){this.schedulePositionUpdate()}applyContentAnimation(t){return this.placement==="none"?Promise.resolve(!0):new Promise(e=>{const i=this.shadowRoot.querySelector("#contents"),o=n=>{t===n.animationName&&(i.removeEventListener("animationend",o),i.removeEventListener("animationcancel",o),this.animating=!1,e(n.type==="animationcancel"))};i.addEventListener("animationend",o),i.addEventListener("animationcancel",o),i.style.animationName=t,this.animating=!0})}renderTheme(t){const{color:e,scale:i,lang:o,theme:n}=this.theme;return b`
|
|
2
2
|
<sp-theme
|
|
3
3
|
theme=${h(n)}
|
|
4
4
|
color=${h(e)}
|
package/src/ActiveOverlay.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["ActiveOverlay.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { reparentChildren } from '@spectrum-web-components/shared/src/reparent-children.js';\nimport { firstFocusableIn } from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport type {\n Color,\n Scale,\n ThemeVariant,\n} from '@spectrum-web-components/theme/src/Theme.js';\nimport styles from './active-overlay.css.js';\nimport { parentOverlayOf } from './overlay-utils.js';\nimport {\n OverlayOpenCloseDetail,\n OverlayOpenDetail,\n Placement,\n TriggerInteractions,\n} from './overlay-types.js';\nimport type { VirtualTrigger } from './VirtualTrigger.js';\nimport {\n arrow,\n computePosition,\n flip,\n Placement as FloatingUIPlacement,\n offset,\n shift,\n size,\n} from '@floating-ui/dom';\n\nexport interface PositionResult {\n arrowOffsetLeft: number;\n arrowOffsetTop: number;\n maxHeight: number;\n placement: string;\n positionLeft: number;\n positionTop: number;\n}\n\ntype OverlayStateType = 'idle' | 'active' | 'hiding' | 'dispose' | 'disposed';\ntype ContentAnimation = 'sp-overlay-fade-in' | 'sp-overlay-fade-out';\n\nconst stateMachine: {\n initial: OverlayStateType;\n states: {\n [stateName: string]: {\n on: {\n [transitionName: string]: OverlayStateType;\n };\n };\n };\n} = {\n initial: 'idle',\n states: {\n idle: {\n on: {\n active: 'active',\n },\n },\n active: {\n on: {\n hiding: 'hiding',\n idle: 'idle',\n },\n },\n hiding: {\n on: {\n dispose: 'dispose',\n },\n },\n dispose: {\n on: {\n disposed: 'disposed',\n },\n },\n disposed: {\n on: {},\n },\n },\n};\n\nconst stateTransition = (\n state?: OverlayStateType,\n event?: string\n): OverlayStateType => {\n if (!state) return stateMachine.initial;\n /* c8 ignore next */\n if (!event) return state;\n return stateMachine.states[state].on[event] || state;\n};\n\nconst getFallbackPlacements = (\n placement: FloatingUIPlacement\n): FloatingUIPlacement[] => {\n const fallbacks: Record<FloatingUIPlacement, FloatingUIPlacement[]> = {\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 * @element active-overlay\n *\n * @slot - content to display in the overlay\n */\nexport class ActiveOverlay extends SpectrumElement {\n public overlayContent!: HTMLElement;\n public overlayContentTip?: HTMLElement;\n public trigger!: HTMLElement;\n public root?: HTMLElement;\n public virtualTrigger?: VirtualTrigger;\n\n protected childrenReady!: Promise<unknown[]>;\n\n @property()\n public _state = stateTransition();\n public get state(): OverlayStateType {\n return this._state;\n }\n public set state(state: OverlayStateType) {\n const nextState = stateTransition(this.state, state);\n if (nextState === this.state) {\n return;\n }\n this._state = nextState;\n if (this.state === 'active' || this.state === 'hiding') {\n this.setAttribute('state', this.state);\n } else {\n this.removeAttribute('state');\n }\n }\n\n @property({ reflect: true, type: Boolean })\n public animating = false;\n\n @property({ reflect: true })\n public placement?: Placement;\n @property({ attribute: false })\n public theme: {\n color?: Color;\n scale?: Scale;\n lang?: string;\n theme?: ThemeVariant;\n } = {};\n @property({ attribute: false })\n public receivesFocus?: 'auto';\n\n public tabbingAway = false;\n private originalPlacement?: Placement;\n private restoreContent?: () => Element[];\n\n public override async focus(): Promise<void> {\n const firstFocusable = firstFocusableIn(this);\n if (firstFocusable) {\n if ((firstFocusable as SpectrumElement).updateComplete) {\n await firstFocusable.updateComplete;\n }\n const activeElement = (this.getRootNode() as Document)\n .activeElement;\n if (activeElement === this || !this.contains(activeElement)) {\n firstFocusable.focus();\n }\n /* c8 ignore next 3 */\n } else {\n super.focus();\n }\n this.removeAttribute('tabindex');\n }\n\n private get hasTheme(): boolean {\n return !!this.theme.color || !!this.theme.scale || !!this.theme.lang;\n }\n\n public offset = 6;\n public skidding = 0;\n public interaction: TriggerInteractions = 'hover';\n private positionAnimationFrame = 0;\n\n private timeout?: number;\n\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n public constructor() {\n super();\n this.stealOverlayContentPromise = new Promise(\n (res) => (this.stealOverlayContentResolver = res)\n );\n }\n\n private _modalRoot?: ActiveOverlay;\n\n public get hasModalRoot(): boolean {\n return !!this._modalRoot;\n }\n\n public feature(): void {\n // eslint-disable-next-line spectrum-web-components/document-active-element\n if (!this.contains(document.activeElement)) {\n this.tabIndex = -1;\n }\n const parentOverlay = parentOverlayOf(this.trigger);\n const parentIsModal = parentOverlay && parentOverlay.slot === 'open';\n if (parentIsModal) {\n this._modalRoot = parentOverlay._modalRoot || parentOverlay;\n }\n // If an overlay it triggered from within a \"modal\" overlay, it needs to continue\n // to act like one to get treated correctly in regards to tab trapping.\n if (this.interaction === 'modal' || this._modalRoot) {\n this.slot = 'open';\n if (this.interaction === 'modal') {\n this.setAttribute('aria-modal', 'true');\n }\n // If this isn't a modal root, walk up the overlays to the next modal root\n // and \"feature\" each on of the intervening overlays.\n if (this._modalRoot) {\n parentOverlay?.feature();\n }\n }\n }\n\n public obscure(\n nextOverlayInteraction: TriggerInteractions\n ): ActiveOverlay | undefined {\n if (this.slot && nextOverlayInteraction === 'modal') {\n this.removeAttribute('slot');\n this.removeAttribute('aria-modal');\n // Obscure upto and including the next modal root.\n if (this.interaction !== 'modal') {\n const parentOverlay = parentOverlayOf(this.trigger);\n this._modalRoot = parentOverlay?.obscure(\n nextOverlayInteraction\n );\n return this._modalRoot;\n }\n return this;\n }\n return undefined;\n }\n\n public override async willUpdate(): Promise<void> {\n if (this.hasUpdated) return;\n\n /* c8 ignore next */\n if (!this.overlayContent || !this.trigger) return;\n\n this.stealOverlayContent(\n this.overlayContent as HTMLElement & { placement: Placement }\n );\n\n this.state = 'active';\n this.feature();\n if (this.placement === 'none') {\n this.style.setProperty(\n '--swc-visual-viewport-height',\n `${window.innerHeight}px`\n );\n } else if (this.placement) {\n await this.updateOverlayPosition();\n document.addEventListener(\n 'sp-update-overlays',\n this.updateOverlayPosition\n );\n window.addEventListener('scroll', this.updateOverlayPosition);\n }\n const actions: Promise<unknown>[] = [];\n if (this.placement && this.placement !== 'none') {\n actions.push(this.applyContentAnimation('sp-overlay-fade-in'));\n }\n if (\n typeof (this.overlayContent as SpectrumElement).updateComplete !==\n 'undefined'\n ) {\n actions.push(\n (this.overlayContent as SpectrumElement).updateComplete\n );\n }\n this.childrenReady = Promise.all(actions);\n }\n\n public async openCallback(\n lifecycleCallback: () => Promise<void> | void\n ): Promise<void> {\n await this.updateComplete;\n if (this.receivesFocus) {\n await this.focus();\n }\n\n await lifecycleCallback();\n\n this.trigger.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>('sp-opened', {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail: {\n interaction: this.interaction,\n },\n })\n );\n }\n\n private open(openDetail: OverlayOpenDetail): void {\n this.extractDetail(openDetail);\n }\n\n private extractDetail(detail: OverlayOpenDetail): void {\n this.overlayContent = detail.content;\n this.overlayContentTip = detail.contentTip;\n this.trigger = detail.trigger;\n this.virtualTrigger = detail.virtualTrigger;\n this.placement = detail.placement;\n this.offset = detail.offset;\n this.skidding = detail.skidding || 0;\n this.interaction = detail.interaction;\n this.theme = detail.theme;\n this.receivesFocus = detail.receivesFocus;\n this.root = detail.root;\n }\n\n public dispose(): void {\n /* c8 ignore next */\n if (this.state !== 'dispose') return;\n\n /* c8 ignore next 4 */\n if (this.timeout) {\n clearTimeout(this.timeout);\n delete this.timeout;\n }\n\n this.trigger.removeEventListener(\n 'keydown',\n this.handleInlineTriggerKeydown\n );\n\n this.returnOverlayContent();\n this.state = 'disposed';\n\n if (this.willNotifyClosed) {\n this.overlayContent.dispatchEvent(new Event('sp-overlay-closed'));\n this.willNotifyClosed = false;\n }\n }\n\n private stealOverlayContent(\n element: HTMLElement & { placement: Placement }\n ): void {\n this.originalPlacement = element.getAttribute('placement') as Placement;\n this.restoreContent = reparentChildren([element], this, {\n position: 'beforeend',\n prepareCallback: (el) => {\n const slotName = el.slot;\n const placement = el.placement;\n el.removeAttribute('slot');\n return (el) => {\n el.slot = slotName;\n el.placement = placement;\n };\n },\n });\n this.stealOverlayContentResolver();\n }\n\n private willNotifyClosed = false;\n\n private returnOverlayContent(): void {\n /* c8 ignore next */\n if (!this.restoreContent) return;\n\n const [element] = this.restoreContent();\n this.restoreContent = undefined;\n this.willNotifyClosed = true;\n\n if (this.originalPlacement) {\n element.setAttribute('placement', this.originalPlacement);\n delete this.originalPlacement;\n }\n }\n\n private initialHeight!: number;\n private isConstrained = false;\n\n public updateOverlayPosition = async (): Promise<void> => {\n if (!this.placement || this.placement === 'none') {\n return;\n }\n await (document.fonts ? document.fonts.ready : Promise.resolve());\n\n function roundByDPR(num: number): number {\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\n const REQUIRED_DISTANCE_TO_EDGE = 8;\n // See: https://github.com/adobe/spectrum-web-components/issues/910\n const MIN_OVERLAY_HEIGHT = 100;\n\n const flipMiddleware = this.virtualTrigger\n ? flip({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n fallbackPlacements: getFallbackPlacements(this.placement),\n })\n : flip({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n });\n\n const middleware = [\n offset({\n mainAxis: this.offset,\n crossAxis: this.skidding,\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 =\n !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(this.style, {\n maxWidth: `${Math.floor(availableWidth)}px`,\n maxHeight: appliedHeight,\n height: appliedHeight,\n });\n },\n }),\n ];\n if (this.overlayContentTip) {\n middleware.push(arrow({ element: this.overlayContentTip }));\n }\n const { x, y, placement, middlewareData } = await computePosition(\n this.virtualTrigger || this.trigger,\n this,\n {\n placement: this.placement,\n middleware,\n }\n );\n\n Object.assign(this.style, {\n top: '0px',\n left: '0px',\n transform: `translate(${roundByDPR(x)}px, ${roundByDPR(y)}px)`,\n });\n\n if (placement !== this.getAttribute('actual-placement')) {\n this.setAttribute('actual-placement', placement);\n this.overlayContent.setAttribute('placement', placement);\n }\n\n if (this.overlayContentTip && middlewareData.arrow) {\n const { x: arrowX, y: arrowY } = middlewareData.arrow;\n\n Object.assign(this.overlayContentTip.style, {\n left: arrowX != null ? `${roundByDPR(arrowX)}px` : '',\n top: arrowY != null ? `${roundByDPR(arrowY)}px` : '',\n right: '',\n bottom: '',\n });\n }\n };\n\n public async hide(animated = true): Promise<void> {\n this.state = 'hiding';\n if (animated) {\n await this.applyContentAnimation('sp-overlay-fade-out');\n }\n this.state = 'dispose';\n }\n\n private schedulePositionUpdate(): void {\n // Edge needs a little time to update the DOM before computing the layout\n cancelAnimationFrame(this.positionAnimationFrame);\n this.positionAnimationFrame = requestAnimationFrame(() =>\n this.updateOverlayPosition()\n );\n }\n\n private onSlotChange(): void {\n this.schedulePositionUpdate();\n }\n\n public handleInlineTriggerKeydown = (event: KeyboardEvent): void => {\n const { code, shiftKey } = event;\n /* c8 ignore next */\n if (code !== 'Tab') return;\n if (shiftKey) {\n this.tabbingAway = true;\n this.dispatchEvent(new Event('close'));\n return;\n }\n\n event.stopPropagation();\n event.preventDefault();\n this.focus();\n };\n\n public applyContentAnimation(\n animation: ContentAnimation\n ): Promise<boolean> {\n if (this.placement === 'none') {\n return Promise.resolve(true);\n }\n return new Promise((resolve): void => {\n const contents = this.shadowRoot.querySelector(\n '#contents'\n ) as HTMLElement;\n const doneHandler = (event: AnimationEvent): void => {\n if (animation !== event.animationName) return;\n contents.removeEventListener('animationend', doneHandler);\n contents.removeEventListener('animationcancel', doneHandler);\n this.animating = false;\n resolve(event.type === 'animationcancel');\n };\n contents.addEventListener('animationend', doneHandler);\n contents.addEventListener('animationcancel', doneHandler);\n\n contents.style.animationName = animation;\n this.animating = true;\n });\n }\n\n public renderTheme(content: TemplateResult): TemplateResult {\n const { color, scale, lang, theme } = this.theme;\n return html`\n <sp-theme\n theme=${ifDefined(theme)}\n color=${ifDefined(color)}\n scale=${ifDefined(scale)}\n lang=${ifDefined(lang)}\n part=\"theme\"\n >\n ${content}\n </sp-theme>\n `;\n }\n\n public override render(): TemplateResult {\n const content = html`\n <div id=\"contents\">\n <slot @slotchange=${this.onSlotChange}></slot>\n </div>\n `;\n return this.hasTheme ? this.renderTheme(content) : content;\n }\n\n public static create(details: OverlayOpenDetail): ActiveOverlay {\n const overlay = new ActiveOverlay();\n\n if (details.content) {\n overlay.open(details);\n }\n\n return overlay;\n }\n\n private stealOverlayContentPromise = Promise.resolve();\n private stealOverlayContentResolver!: () => void;\n\n protected override async getUpdateComplete(): Promise<boolean> {\n const actions: Promise<unknown>[] = [\n super.getUpdateComplete(),\n this.stealOverlayContentPromise,\n ];\n if (this.childrenReady) {\n actions.push(this.childrenReady);\n }\n const [complete] = await Promise.all(actions);\n return complete as boolean;\n }\n\n override disconnectedCallback(): void {\n document.removeEventListener(\n 'sp-update-overlays',\n this.updateOverlayPosition\n );\n window.removeEventListener('scroll', this.updateOverlayPosition);\n super.disconnectedCallback();\n }\n}\n"],
|
|
5
|
-
"mappings": "qNAYA,OAEI,QAAAA,EACA,mBAAAC,MAEG,gCACP,OAAS,aAAAC,MAAiB,kDAC1B,OAAS,YAAAC,MAAgB,kDACzB,OAAS,oBAAAC,MAAwB,2DACjC,OAAS,oBAAAC,MAAwB,4DAMjC,OAAOC,MAAY,0BACnB,OAAS,mBAAAC,MAAuB,qBAQhC,OACI,SAAAC,EACA,mBAAAC,EACA,QAAAC,EAEA,UAAAC,EACA,SAAAC,EACA,QAAAC,MACG,mBAcP,MAAMC,EASF,CACA,QAAS,OACT,OAAQ,CACJ,KAAM,CACF,GAAI,CACA,OAAQ,QACZ,CACJ,EACA,OAAQ,CACJ,GAAI,CACA,OAAQ,SACR,KAAM,MACV,CACJ,EACA,OAAQ,CACJ,GAAI,CACA,QAAS,SACb,CACJ,EACA,QAAS,CACL,GAAI,CACA,SAAU,UACd,CACJ,EACA,SAAU,CACN,GAAI,CAAC,CACT,CACJ,CACJ,EAEMC,EAAkB,CACpBC,EACAC,IAEKD,EAEAC,GACEH,EAAa,OAAOE,GAAO,GAAGC,IAAUD,EAH5BF,EAAa,QAM9BI,EACFC,GACwB,CA7G5B,IAAAC,EA4HI,OAAOA,EAd+D,CAClE,KAAM,CAAC,QAAS,SAAU,KAAK,EAC/B,aAAc,CAAC,cAAe,SAAU,KAAK,EAC7C,WAAY,CAAC,YAAa,SAAU,KAAK,EACzC,MAAO,CAAC,OAAQ,SAAU,KAAK,EAC/B,cAAe,CAAC,aAAc,SAAU,KAAK,EAC7C,YAAa,CAAC,WAAY,SAAU,KAAK,EACzC,IAAK,CAAC,SAAU,OAAQ,OAAO,EAC/B,YAAa,CAAC,eAAgB,OAAQ,OAAO,EAC7C,UAAW,CAAC,aAAc,OAAQ,OAAO,EACzC,OAAQ,CAAC,MAAO,OAAQ,OAAO,EAC/B,eAAgB,CAAC,YAAa,OAAQ,OAAO,EAC7C,aAAc,CAAC,UAAW,OAAQ,OAAO,CAC7C,EACiBD,KAAV,KAAAC,EAAwB,CAACD,CAAS,CAC7C,EAOaE,EAAN,cAA4BpB,CAAgB,CA+ExC,aAAc,CACjB,MAAM,EAtEV,KAAO,OAASc,EAAgB,EAkBhC,KAAO,UAAY,GAKnB,KAAO,MAKH,CAAC,EAIL,KAAO,YAAc,GA0BrB,KAAO,OAAS,EAChB,KAAO,SAAW,EAClB,KAAO,YAAmC,QAC1C,KAAQ,uBAAyB,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { reparentChildren } from '@spectrum-web-components/shared/src/reparent-children.js';\nimport { firstFocusableIn } from '@spectrum-web-components/shared/src/first-focusable-in.js';\nimport type {\n Color,\n Scale,\n ThemeVariant,\n} from '@spectrum-web-components/theme/src/Theme.js';\nimport styles from './active-overlay.css.js';\nimport { parentOverlayOf } from './overlay-utils.js';\nimport {\n OverlayOpenCloseDetail,\n OverlayOpenDetail,\n Placement,\n TriggerInteractions,\n} from './overlay-types.js';\nimport type { VirtualTrigger } from './VirtualTrigger.js';\nimport {\n arrow,\n computePosition,\n flip,\n Placement as FloatingUIPlacement,\n offset,\n shift,\n size,\n} from '@floating-ui/dom';\n\nexport interface PositionResult {\n arrowOffsetLeft: number;\n arrowOffsetTop: number;\n maxHeight: number;\n placement: string;\n positionLeft: number;\n positionTop: number;\n}\n\ntype OverlayStateType = 'idle' | 'active' | 'hiding' | 'dispose' | 'disposed';\ntype ContentAnimation = 'sp-overlay-fade-in' | 'sp-overlay-fade-out';\n\nconst stateMachine: {\n initial: OverlayStateType;\n states: {\n [stateName: string]: {\n on: {\n [transitionName: string]: OverlayStateType;\n };\n };\n };\n} = {\n initial: 'idle',\n states: {\n idle: {\n on: {\n active: 'active',\n },\n },\n active: {\n on: {\n hiding: 'hiding',\n idle: 'idle',\n },\n },\n hiding: {\n on: {\n dispose: 'dispose',\n },\n },\n dispose: {\n on: {\n disposed: 'disposed',\n },\n },\n disposed: {\n on: {},\n },\n },\n};\n\nconst stateTransition = (\n state?: OverlayStateType,\n event?: string\n): OverlayStateType => {\n if (!state) return stateMachine.initial;\n /* c8 ignore next */\n if (!event) return state;\n return stateMachine.states[state].on[event] || state;\n};\n\nconst getFallbackPlacements = (\n placement: FloatingUIPlacement\n): FloatingUIPlacement[] => {\n const fallbacks: Record<FloatingUIPlacement, FloatingUIPlacement[]> = {\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 * @element active-overlay\n *\n * @slot - content to display in the overlay\n */\nexport class ActiveOverlay extends SpectrumElement {\n public overlayContent!: HTMLElement;\n public overlayContentTip?: HTMLElement;\n public trigger!: HTMLElement;\n public root?: HTMLElement;\n public virtualTrigger?: VirtualTrigger;\n\n protected childrenReady!: Promise<unknown[]>;\n\n @property()\n public _state = stateTransition();\n public get state(): OverlayStateType {\n return this._state;\n }\n public set state(state: OverlayStateType) {\n const nextState = stateTransition(this.state, state);\n if (nextState === this.state) {\n return;\n }\n this._state = nextState;\n if (this.state === 'active' || this.state === 'hiding') {\n this.setAttribute('state', this.state);\n } else {\n this.removeAttribute('state');\n }\n }\n\n @property({ reflect: true, type: Boolean })\n public animating = false;\n\n @property({ reflect: true })\n public placement?: Placement;\n @property({ attribute: false })\n public theme: {\n color?: Color;\n scale?: Scale;\n lang?: string;\n theme?: ThemeVariant;\n } = {};\n @property({ attribute: false })\n public receivesFocus?: 'auto';\n\n public tabbingAway = false;\n private originalPlacement?: Placement;\n private restoreContent?: () => Element[];\n\n public override async focus(): Promise<void> {\n const firstFocusable = firstFocusableIn(this);\n if (firstFocusable) {\n if ((firstFocusable as SpectrumElement).updateComplete) {\n await firstFocusable.updateComplete;\n }\n const activeElement = (this.getRootNode() as Document)\n .activeElement;\n if (activeElement === this || !this.contains(activeElement)) {\n firstFocusable.focus();\n }\n /* c8 ignore next 3 */\n } else {\n super.focus();\n }\n this.removeAttribute('tabindex');\n }\n\n private get hasTheme(): boolean {\n return !!this.theme.color || !!this.theme.scale || !!this.theme.lang;\n }\n\n public offset = 6;\n public skidding = 0;\n public interaction: TriggerInteractions = 'hover';\n private positionAnimationFrame = 0;\n\n private timeout?: number;\n\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n public constructor() {\n super();\n this.stealOverlayContentPromise = new Promise(\n (res) => (this.stealOverlayContentResolver = res)\n );\n }\n\n private _modalRoot?: ActiveOverlay;\n\n public get hasModalRoot(): boolean {\n return !!this._modalRoot;\n }\n\n public feature(): void {\n // eslint-disable-next-line spectrum-web-components/document-active-element\n if (!this.contains(document.activeElement)) {\n this.tabIndex = -1;\n }\n const parentOverlay = parentOverlayOf(this.trigger);\n const parentIsModal = parentOverlay && parentOverlay.slot === 'open';\n if (parentIsModal) {\n this._modalRoot = parentOverlay._modalRoot || parentOverlay;\n }\n // If an overlay it triggered from within a \"modal\" overlay, it needs to continue\n // to act like one to get treated correctly in regards to tab trapping.\n if (this.interaction === 'modal' || this._modalRoot) {\n this.slot = 'open';\n if (this.interaction === 'modal') {\n this.setAttribute('aria-modal', 'true');\n }\n // If this isn't a modal root, walk up the overlays to the next modal root\n // and \"feature\" each on of the intervening overlays.\n if (this._modalRoot) {\n parentOverlay?.feature();\n }\n }\n }\n\n public obscure(\n nextOverlayInteraction: TriggerInteractions\n ): ActiveOverlay | undefined {\n if (this.slot && nextOverlayInteraction === 'modal') {\n this.removeAttribute('slot');\n this.removeAttribute('aria-modal');\n // Obscure upto and including the next modal root.\n if (this.interaction !== 'modal') {\n const parentOverlay = parentOverlayOf(this.trigger);\n this._modalRoot = parentOverlay?.obscure(\n nextOverlayInteraction\n );\n return this._modalRoot;\n }\n return this;\n }\n return undefined;\n }\n\n public override async willUpdate(): Promise<void> {\n if (this.hasUpdated) return;\n\n /* c8 ignore next */\n if (!this.overlayContent || !this.trigger) return;\n\n this.stealOverlayContent(\n this.overlayContent as HTMLElement & { placement: Placement }\n );\n\n this.state = 'active';\n\n // force paint\n // this prevents a timing issue that can show up in tests as\n // 'Error: Timeout: Wait for decorator to become ready...'\n this.offsetWidth;\n\n this.feature();\n if (this.placement === 'none') {\n this.style.setProperty(\n '--swc-visual-viewport-height',\n `${window.innerHeight}px`\n );\n } else if (this.placement) {\n await this.updateOverlayPosition();\n document.addEventListener(\n 'sp-update-overlays',\n this.updateOverlayPosition\n );\n window.addEventListener('scroll', this.updateOverlayPosition);\n }\n const actions: Promise<unknown>[] = [];\n if (this.placement && this.placement !== 'none') {\n actions.push(this.applyContentAnimation('sp-overlay-fade-in'));\n }\n if (\n typeof (this.overlayContent as SpectrumElement).updateComplete !==\n 'undefined'\n ) {\n actions.push(\n (this.overlayContent as SpectrumElement).updateComplete\n );\n }\n this.childrenReady = Promise.all(actions);\n }\n\n public async openCallback(\n lifecycleCallback: () => Promise<void> | void\n ): Promise<void> {\n await this.updateComplete;\n if (this.receivesFocus) {\n await this.focus();\n }\n\n await lifecycleCallback();\n\n this.trigger.dispatchEvent(\n new CustomEvent<OverlayOpenCloseDetail>('sp-opened', {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail: {\n interaction: this.interaction,\n },\n })\n );\n }\n\n private open(openDetail: OverlayOpenDetail): void {\n this.extractDetail(openDetail);\n }\n\n private extractDetail(detail: OverlayOpenDetail): void {\n this.overlayContent = detail.content;\n this.overlayContentTip = detail.contentTip;\n this.trigger = detail.trigger;\n this.virtualTrigger = detail.virtualTrigger;\n this.placement = detail.placement;\n this.offset = detail.offset;\n this.skidding = detail.skidding || 0;\n this.interaction = detail.interaction;\n this.theme = detail.theme;\n this.receivesFocus = detail.receivesFocus;\n this.root = detail.root;\n }\n\n public dispose(): void {\n /* c8 ignore next */\n if (this.state !== 'dispose') return;\n\n /* c8 ignore next 4 */\n if (this.timeout) {\n clearTimeout(this.timeout);\n delete this.timeout;\n }\n\n this.trigger.removeEventListener(\n 'keydown',\n this.handleInlineTriggerKeydown\n );\n\n this.returnOverlayContent();\n this.state = 'disposed';\n\n if (this.willNotifyClosed) {\n this.overlayContent.dispatchEvent(new Event('sp-overlay-closed'));\n this.willNotifyClosed = false;\n }\n }\n\n private stealOverlayContent(\n element: HTMLElement & { placement: Placement }\n ): void {\n this.originalPlacement = element.getAttribute('placement') as Placement;\n this.restoreContent = reparentChildren([element], this, {\n position: 'beforeend',\n prepareCallback: (el) => {\n const slotName = el.slot;\n const placement = el.placement;\n el.removeAttribute('slot');\n return (el) => {\n el.slot = slotName;\n el.placement = placement;\n };\n },\n });\n this.stealOverlayContentResolver();\n }\n\n private willNotifyClosed = false;\n\n private returnOverlayContent(): void {\n /* c8 ignore next */\n if (!this.restoreContent) return;\n\n const [element] = this.restoreContent();\n this.restoreContent = undefined;\n this.willNotifyClosed = true;\n\n if (this.originalPlacement) {\n element.setAttribute('placement', this.originalPlacement);\n delete this.originalPlacement;\n }\n }\n\n private initialHeight!: number;\n private isConstrained = false;\n\n public updateOverlayPosition = async (): Promise<void> => {\n if (!this.placement || this.placement === 'none') {\n return;\n }\n await (document.fonts ? document.fonts.ready : Promise.resolve());\n\n function roundByDPR(num: number): number {\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\n const REQUIRED_DISTANCE_TO_EDGE = 8;\n // See: https://github.com/adobe/spectrum-web-components/issues/910\n const MIN_OVERLAY_HEIGHT = 100;\n\n const flipMiddleware = this.virtualTrigger\n ? flip({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n fallbackPlacements: getFallbackPlacements(this.placement),\n })\n : flip({\n padding: REQUIRED_DISTANCE_TO_EDGE,\n });\n\n const middleware = [\n offset({\n mainAxis: this.offset,\n crossAxis: this.skidding,\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 =\n !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(this.style, {\n maxWidth: `${Math.floor(availableWidth)}px`,\n maxHeight: appliedHeight,\n height: appliedHeight,\n });\n },\n }),\n ];\n if (this.overlayContentTip) {\n middleware.push(arrow({ element: this.overlayContentTip }));\n }\n const { x, y, placement, middlewareData } = await computePosition(\n this.virtualTrigger || this.trigger,\n this,\n {\n placement: this.placement,\n middleware,\n }\n );\n\n Object.assign(this.style, {\n top: '0px',\n left: '0px',\n transform: `translate(${roundByDPR(x)}px, ${roundByDPR(y)}px)`,\n });\n\n if (placement !== this.getAttribute('actual-placement')) {\n this.setAttribute('actual-placement', placement);\n this.overlayContent.setAttribute('placement', placement);\n }\n\n if (this.overlayContentTip && middlewareData.arrow) {\n const { x: arrowX, y: arrowY } = middlewareData.arrow;\n\n Object.assign(this.overlayContentTip.style, {\n left: arrowX != null ? `${roundByDPR(arrowX)}px` : '',\n top: arrowY != null ? `${roundByDPR(arrowY)}px` : '',\n right: '',\n bottom: '',\n });\n }\n };\n\n public async hide(animated = true): Promise<void> {\n this.state = 'hiding';\n if (animated) {\n await this.applyContentAnimation('sp-overlay-fade-out');\n }\n this.state = 'dispose';\n }\n\n private schedulePositionUpdate(): void {\n // Edge needs a little time to update the DOM before computing the layout\n cancelAnimationFrame(this.positionAnimationFrame);\n this.positionAnimationFrame = requestAnimationFrame(() =>\n this.updateOverlayPosition()\n );\n }\n\n private onSlotChange(): void {\n this.schedulePositionUpdate();\n }\n\n public handleInlineTriggerKeydown = (event: KeyboardEvent): void => {\n const { code, shiftKey } = event;\n /* c8 ignore next */\n if (code !== 'Tab') return;\n if (shiftKey) {\n this.tabbingAway = true;\n this.dispatchEvent(new Event('close'));\n return;\n }\n\n event.stopPropagation();\n event.preventDefault();\n this.focus();\n };\n\n public applyContentAnimation(\n animation: ContentAnimation\n ): Promise<boolean> {\n if (this.placement === 'none') {\n return Promise.resolve(true);\n }\n return new Promise((resolve): void => {\n const contents = this.shadowRoot.querySelector(\n '#contents'\n ) as HTMLElement;\n const doneHandler = (event: AnimationEvent): void => {\n if (animation !== event.animationName) return;\n contents.removeEventListener('animationend', doneHandler);\n contents.removeEventListener('animationcancel', doneHandler);\n this.animating = false;\n resolve(event.type === 'animationcancel');\n };\n contents.addEventListener('animationend', doneHandler);\n contents.addEventListener('animationcancel', doneHandler);\n\n contents.style.animationName = animation;\n this.animating = true;\n });\n }\n\n public renderTheme(content: TemplateResult): TemplateResult {\n const { color, scale, lang, theme } = this.theme;\n return html`\n <sp-theme\n theme=${ifDefined(theme)}\n color=${ifDefined(color)}\n scale=${ifDefined(scale)}\n lang=${ifDefined(lang)}\n part=\"theme\"\n >\n ${content}\n </sp-theme>\n `;\n }\n\n public override render(): TemplateResult {\n const content = html`\n <div id=\"contents\">\n <slot @slotchange=${this.onSlotChange}></slot>\n </div>\n `;\n return this.hasTheme ? this.renderTheme(content) : content;\n }\n\n public static create(details: OverlayOpenDetail): ActiveOverlay {\n const overlay = new ActiveOverlay();\n\n if (details.content) {\n overlay.open(details);\n }\n\n return overlay;\n }\n\n private stealOverlayContentPromise = Promise.resolve();\n private stealOverlayContentResolver!: () => void;\n\n protected override async getUpdateComplete(): Promise<boolean> {\n const actions: Promise<unknown>[] = [\n super.getUpdateComplete(),\n this.stealOverlayContentPromise,\n ];\n if (this.childrenReady) {\n actions.push(this.childrenReady);\n }\n const [complete] = await Promise.all(actions);\n return complete as boolean;\n }\n\n override disconnectedCallback(): void {\n document.removeEventListener(\n 'sp-update-overlays',\n this.updateOverlayPosition\n );\n window.removeEventListener('scroll', this.updateOverlayPosition);\n super.disconnectedCallback();\n }\n}\n"],
|
|
5
|
+
"mappings": "qNAYA,OAEI,QAAAA,EACA,mBAAAC,MAEG,gCACP,OAAS,aAAAC,MAAiB,kDAC1B,OAAS,YAAAC,MAAgB,kDACzB,OAAS,oBAAAC,MAAwB,2DACjC,OAAS,oBAAAC,MAAwB,4DAMjC,OAAOC,MAAY,0BACnB,OAAS,mBAAAC,MAAuB,qBAQhC,OACI,SAAAC,EACA,mBAAAC,EACA,QAAAC,EAEA,UAAAC,EACA,SAAAC,EACA,QAAAC,MACG,mBAcP,MAAMC,EASF,CACA,QAAS,OACT,OAAQ,CACJ,KAAM,CACF,GAAI,CACA,OAAQ,QACZ,CACJ,EACA,OAAQ,CACJ,GAAI,CACA,OAAQ,SACR,KAAM,MACV,CACJ,EACA,OAAQ,CACJ,GAAI,CACA,QAAS,SACb,CACJ,EACA,QAAS,CACL,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AAAA,wBACf9D,EAAU2D,CAAK;AAAA,wBACf3D,EAAU4D,CAAK;AAAA,uBAChB5D,EAAU6D,CAAI;AAAA;AAAA;AAAA,kBAGnBH;AAAA;AAAA,SAGd,CAEgB,QAAyB,CACrC,MAAMA,EAAU5D;AAAA;AAAA,oCAEY,KAAK;AAAA;AAAA,UAGjC,OAAO,KAAK,SAAW,KAAK,YAAY4D,CAAO,EAAIA,CACvD,CAEA,OAAc,OAAOK,EAA2C,CAC5D,MAAMC,EAAU,IAAI7C,EAEpB,OAAI4C,EAAQ,SACRC,EAAQ,KAAKD,CAAO,EAGjBC,CACX,CAKA,MAAyB,mBAAsC,CAC3D,MAAMlB,EAA8B,CAChC,MAAM,kBAAkB,EACxB,KAAK,0BACT,EACI,KAAK,eACLA,EAAQ,KAAK,KAAK,aAAa,EAEnC,KAAM,CAACmB,CAAQ,EAAI,MAAM,QAAQ,IAAInB,CAAO,EAC5C,OAAOmB,CACX,CAES,sBAA6B,CAClC,SAAS,oBACL,qBACA,KAAK,qBACT,EACA,OAAO,oBAAoB,SAAU,KAAK,qBAAqB,EAC/D,MAAM,qBAAqB,CAC/B,CACJ,EAlfO,WAAM,cAAN9C,EAUI+C,EAAA,CADNjE,EAAS,GATD,cAUF,sBAkBAiE,EAAA,CADNjE,EAAS,CAAE,QAAS,GAAM,KAAM,OAAQ,CAAC,GA3BjC,cA4BF,yBAGAiE,EAAA,CADNjE,EAAS,CAAE,QAAS,EAAK,CAAC,GA9BlB,cA+BF,yBAEAiE,EAAA,CADNjE,EAAS,CAAE,UAAW,EAAM,CAAC,GAhCrB,cAiCF,qBAOAiE,EAAA,CADNjE,EAAS,CAAE,UAAW,EAAM,CAAC,GAvCrB,cAwCF",
|
|
6
6
|
"names": ["html", "SpectrumElement", "ifDefined", "property", "reparentChildren", "firstFocusableIn", "styles", "parentOverlayOf", "arrow", "computePosition", "flip", "offset", "shift", "size", "stateMachine", "stateTransition", "state", "event", "getFallbackPlacements", "placement", "_a", "_ActiveOverlay", "roundByDPR", "num", "dpr", "REQUIRED_DISTANCE_TO_EDGE", "MIN_OVERLAY_HEIGHT", "flipMiddleware", "middleware", "availableWidth", "availableHeight", "floating", "maxHeight", "actualHeight", "appliedHeight", "x", "y", "middlewareData", "arrowX", "arrowY", "code", "shiftKey", "res", "nextState", "firstFocusable", "activeElement", "parentOverlay", "nextOverlayInteraction", "actions", "lifecycleCallback", "openDetail", "detail", "element", "el", "slotName", "animated", "animation", "resolve", "contents", "doneHandler", "content", "color", "scale", "lang", "theme", "details", "overlay", "complete", "__decorateClass"]
|
|
7
7
|
}
|
package/src/overlay-stack.d.ts
CHANGED
package/src/overlay-stack.dev.js
CHANGED
|
@@ -13,6 +13,9 @@ function isLeftClick(event) {
|
|
|
13
13
|
function hasModifier(event) {
|
|
14
14
|
return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
|
|
15
15
|
}
|
|
16
|
+
function nextFrame() {
|
|
17
|
+
return new Promise((res) => requestAnimationFrame(() => res()));
|
|
18
|
+
}
|
|
16
19
|
export class OverlayStack {
|
|
17
20
|
constructor() {
|
|
18
21
|
this.overlays = [];
|
|
@@ -106,8 +109,19 @@ export class OverlayStack {
|
|
|
106
109
|
this.handlingResize = false;
|
|
107
110
|
});
|
|
108
111
|
};
|
|
112
|
+
this.initTabTrapping();
|
|
109
113
|
}
|
|
110
114
|
initTabTrapping() {
|
|
115
|
+
if (document.readyState === "loading") {
|
|
116
|
+
document.addEventListener(
|
|
117
|
+
"readystatechange",
|
|
118
|
+
() => {
|
|
119
|
+
this.initTabTrapping();
|
|
120
|
+
},
|
|
121
|
+
{ once: true }
|
|
122
|
+
);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
111
125
|
if (this.trappingInited)
|
|
112
126
|
return;
|
|
113
127
|
this.trappingInited = true;
|
|
@@ -282,26 +296,24 @@ export class OverlayStack {
|
|
|
282
296
|
topOverlay.obscure(activeOverlay.interaction);
|
|
283
297
|
}
|
|
284
298
|
document.body.appendChild(activeOverlay);
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
);
|
|
299
|
+
await nextFrame();
|
|
300
|
+
this.overlays.push(activeOverlay);
|
|
301
|
+
await activeOverlay.updateComplete;
|
|
302
|
+
this.addOverlayEventListeners(activeOverlay);
|
|
303
|
+
if (typeof contentWithLifecycle.open !== "undefined") {
|
|
304
|
+
await nextFrame();
|
|
305
|
+
contentWithLifecycle.open = true;
|
|
306
|
+
}
|
|
307
|
+
let cb = () => {
|
|
308
|
+
return;
|
|
309
|
+
};
|
|
310
|
+
if (contentWithLifecycle.overlayOpenCallback) {
|
|
311
|
+
const { trigger: trigger2 } = activeOverlay;
|
|
312
|
+
const { overlayOpenCallback } = contentWithLifecycle;
|
|
313
|
+
cb = async () => await overlayOpenCallback({ trigger: trigger2 });
|
|
314
|
+
}
|
|
315
|
+
await activeOverlay.openCallback(cb);
|
|
316
|
+
return false;
|
|
305
317
|
}
|
|
306
318
|
addOverlayEventListeners(activeOverlay) {
|
|
307
319
|
activeOverlay.addEventListener("close", () => {
|
|
@@ -473,6 +485,7 @@ export class OverlayStack {
|
|
|
473
485
|
} else {
|
|
474
486
|
this.manageFocusAfterCloseWhenLastOverlay(overlay);
|
|
475
487
|
}
|
|
488
|
+
await overlay.updateComplete;
|
|
476
489
|
overlay.remove();
|
|
477
490
|
overlay.dispose();
|
|
478
491
|
overlay.trigger.dispatchEvent(
|