import { Modal } from "./chunk.JEBKOPXW.js"; import { lockBodyScrolling, unlockBodyScrolling } from "./chunk.RK73WSZS.js"; import { dialog_styles_default } from "./chunk.WH4QNFFK.js"; import { SlIconButton } from "./chunk.Y77CZW56.js"; import { getAnimation, setDefaultAnimation } from "./chunk.RCZVQXWP.js"; import { waitForEvent } from "./chunk.B4BZKR24.js"; import { animateTo, stopAnimations } from "./chunk.S7GYYU7Z.js"; import { LocalizeController } from "./chunk.NH3SRVOC.js"; import { o } from "./chunk.2URMUHDY.js"; import { HasSlotController } from "./chunk.NYIIDP5N.js"; import { e } from "./chunk.UZVKBFXH.js"; import { watch } from "./chunk.FA5RT4K4.js"; import { ShoelaceElement, e as e2, n } from "./chunk.SEXBCYCU.js"; import { x } from "./chunk.CXZZ2LVK.js"; import { __decorateClass } from "./chunk.KIILAQWQ.js"; // src/components/dialog/dialog.component.ts var SlDialog = class extends ShoelaceElement { constructor() { super(...arguments); this.hasSlotController = new HasSlotController(this, "footer"); this.localize = new LocalizeController(this); this.modal = new Modal(this); this.open = false; this.label = ""; this.noHeader = false; this.handleDocumentKeyDown = (event) => { if (event.key === "Escape" && this.modal.isActive() && this.open) { event.stopPropagation(); this.requestClose("keyboard"); } }; } firstUpdated() { this.dialog.hidden = !this.open; if (this.open) { this.addOpenListeners(); this.modal.activate(); lockBodyScrolling(this); } } disconnectedCallback() { var _a; super.disconnectedCallback(); this.modal.deactivate(); unlockBodyScrolling(this); (_a = this.closeWatcher) == null ? void 0 : _a.destroy(); } requestClose(source) { const slRequestClose = this.emit("sl-request-close", { cancelable: true, detail: { source } }); if (slRequestClose.defaultPrevented) { const animation = getAnimation(this, "dialog.denyClose", { dir: this.localize.dir() }); animateTo(this.panel, animation.keyframes, animation.options); return; } this.hide(); } addOpenListeners() { var _a; if ("CloseWatcher" in window) { (_a = this.closeWatcher) == null ? void 0 : _a.destroy(); this.closeWatcher = new CloseWatcher(); this.closeWatcher.onclose = () => this.requestClose("keyboard"); } else { document.addEventListener("keydown", this.handleDocumentKeyDown); } } removeOpenListeners() { var _a; (_a = this.closeWatcher) == null ? void 0 : _a.destroy(); document.removeEventListener("keydown", this.handleDocumentKeyDown); } async handleOpenChange() { if (this.open) { this.emit("sl-show"); this.addOpenListeners(); this.originalTrigger = document.activeElement; this.modal.activate(); lockBodyScrolling(this); const autoFocusTarget = this.querySelector("[autofocus]"); if (autoFocusTarget) { autoFocusTarget.removeAttribute("autofocus"); } await Promise.all([stopAnimations(this.dialog), stopAnimations(this.overlay)]); this.dialog.hidden = false; requestAnimationFrame(() => { const slInitialFocus = this.emit("sl-initial-focus", { cancelable: true }); if (!slInitialFocus.defaultPrevented) { if (autoFocusTarget) { autoFocusTarget.focus({ preventScroll: true }); } else { this.panel.focus({ preventScroll: true }); } } if (autoFocusTarget) { autoFocusTarget.setAttribute("autofocus", ""); } }); const panelAnimation = getAnimation(this, "dialog.show", { dir: this.localize.dir() }); const overlayAnimation = getAnimation(this, "dialog.overlay.show", { dir: this.localize.dir() }); await Promise.all([ animateTo(this.panel, panelAnimation.keyframes, panelAnimation.options), animateTo(this.overlay, overlayAnimation.keyframes, overlayAnimation.options) ]); this.emit("sl-after-show"); } else { this.emit("sl-hide"); this.removeOpenListeners(); this.modal.deactivate(); await Promise.all([stopAnimations(this.dialog), stopAnimations(this.overlay)]); const panelAnimation = getAnimation(this, "dialog.hide", { dir: this.localize.dir() }); const overlayAnimation = getAnimation(this, "dialog.overlay.hide", { dir: this.localize.dir() }); await Promise.all([ animateTo(this.overlay, overlayAnimation.keyframes, overlayAnimation.options).then(() => { this.overlay.hidden = true; }), animateTo(this.panel, panelAnimation.keyframes, panelAnimation.options).then(() => { this.panel.hidden = true; }) ]); this.dialog.hidden = true; this.overlay.hidden = false; this.panel.hidden = false; unlockBodyScrolling(this); const trigger = this.originalTrigger; if (typeof (trigger == null ? void 0 : trigger.focus) === "function") { setTimeout(() => trigger.focus()); } this.emit("sl-after-hide"); } } /** Shows the dialog. */ async show() { if (this.open) { return void 0; } this.open = true; return waitForEvent(this, "sl-after-show"); } /** Hides the dialog */ async hide() { if (!this.open) { return void 0; } this.open = false; return waitForEvent(this, "sl-after-hide"); } render() { return x`