@flexilla/alpine-modal 0.0.2 → 0.0.4

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.
@@ -24,247 +24,302 @@ __export(module_exports, {
24
24
  module.exports = __toCommonJS(module_exports);
25
25
 
26
26
  // ../../node_modules/@flexilla/modal/dist/modal.js
27
- var j = Object.defineProperty;
28
- var z = (t, e, n) => e in t ? j(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n;
29
- var c = (t, e, n) => z(t, typeof e != "symbol" ? e + "" : e, n);
30
- var O = class {
31
- static initGlobalRegistry() {
32
- window.$flexillaInstances || (window.$flexillaInstances = {});
33
- }
34
- static register(e, n, a) {
35
- return this.initGlobalRegistry(), window.$flexillaInstances[e] || (window.$flexillaInstances[e] = []), this.getInstance(e, n) || (window.$flexillaInstances[e].push({ element: n, instance: a }), a);
36
- }
37
- static getInstance(e, n) {
38
- var a, d;
39
- return this.initGlobalRegistry(), (d = (a = window.$flexillaInstances[e]) == null ? void 0 : a.find(
40
- (s) => s.element === n
41
- )) == null ? void 0 : d.instance;
42
- }
43
- static removeInstance(e, n) {
44
- this.initGlobalRegistry(), window.$flexillaInstances[e] && (window.$flexillaInstances[e] = window.$flexillaInstances[e].filter(
45
- (a) => a.element !== n
46
- ));
47
- }
48
- };
49
- var r = (t, e = document.body) => e.querySelector(t);
50
- var H = (t, e = document.body) => Array.from(e.querySelectorAll(t));
51
- var J = ({
52
- newElement: t,
53
- existingElement: e
27
+ var p = Object.defineProperty;
28
+ var b = (o, t, e) => t in o ? p(o, t, { enumerable: true, configurable: true, writable: true, value: e }) : o[t] = e;
29
+ var s = (o, t, e) => b(o, typeof t != "symbol" ? t + "" : t, e);
30
+ var r = (o, t = document.body) => t.querySelector(o);
31
+ var c = (o, t = document.body) => Array.from(t.querySelectorAll(o));
32
+ var M = ({
33
+ newElement: o,
34
+ existingElement: t
54
35
  }) => {
55
- if (!(t instanceof HTMLElement) || !(e instanceof HTMLElement))
36
+ if (!(o instanceof HTMLElement) || !(t instanceof HTMLElement))
56
37
  throw new Error("Both parameters must be valid HTML elements.");
57
- const n = e.parentElement;
58
- if (n)
59
- n.insertBefore(t, e);
38
+ const e = t.parentElement;
39
+ if (e)
40
+ e.insertBefore(o, t);
60
41
  else
61
42
  throw new Error("Existing element must have a parent element.");
62
43
  };
63
- var Q = ({
64
- element: t,
65
- callback: e,
66
- type: n,
67
- keysCheck: a
44
+ var g = ({
45
+ element: o,
46
+ callback: t,
47
+ type: e,
48
+ keysCheck: n
68
49
  }) => {
69
- const d = getComputedStyle(t), s = d.animation;
70
- if (s !== "none" && s !== "" && !a.includes(s)) {
71
- const f = "animationend", u = () => {
72
- t.removeEventListener(f, u), e();
50
+ const a = getComputedStyle(o), i = a.animation;
51
+ if (i !== "none" && i !== "" && !n.includes(i)) {
52
+ const l = "animationend", d = () => {
53
+ o.removeEventListener(l, d), t();
73
54
  };
74
- t.addEventListener(f, u, { once: true });
55
+ o.addEventListener(l, d, { once: true });
75
56
  } else
76
- e();
57
+ t();
77
58
  };
78
- var N = ({ element: t, callback: e }) => {
79
- Q({
80
- element: t,
81
- callback: e,
59
+ var y = ({ element: o, callback: t }) => {
60
+ g({
61
+ element: o,
62
+ callback: t,
82
63
  type: "animation",
83
64
  keysCheck: ["none 0s ease 0s 1 normal none running"]
84
65
  });
85
66
  };
86
- var B = (t, e, n) => {
87
- const a = new CustomEvent(e, { detail: n });
88
- t.dispatchEvent(a);
89
- };
90
- var W = (t) => {
91
- var e;
92
- t instanceof HTMLElement && ((e = t.parentElement) == null || e.removeChild(t));
67
+ var f = (o, t, e) => {
68
+ const n = new CustomEvent(t, { detail: e });
69
+ o.dispatchEvent(n);
93
70
  };
94
- var U = ({ modalContent: t, overlayClassName: e }) => {
95
- const n = document.createElement("span");
96
- return n.setAttribute("aria-hidden", "true"), J({ newElement: n, existingElement: t }), n.classList.add(...e), n.setAttribute("data-modal-overlay", ""), n;
97
- };
98
- var k = (t, e, n) => {
99
- if (!(e instanceof HTMLElement))
71
+ var E = (o, t, e) => {
72
+ if (!(t instanceof HTMLElement))
100
73
  throw new Error("No modal-content found");
101
- t.setAttribute("aria-hidden", n === "open" ? "false" : "true"), t.setAttribute("data-state", n), e.setAttribute("data-state", n);
102
- const a = r("[data-modal-overlay]", t);
103
- a instanceof HTMLElement && a.setAttribute("data-state", n);
74
+ o.setAttribute("aria-hidden", e === "open" ? "false" : "true"), o.setAttribute("data-state", e), t.setAttribute("data-state", e);
75
+ const n = r("[data-modal-overlay]", o);
76
+ n instanceof HTMLElement && n.setAttribute("data-state", e);
104
77
  };
105
- var V = (t, e, n) => {
106
- if (!t) {
107
- e || (document.body.style.overflowY = "auto");
78
+ var A = (o, t, e) => {
79
+ if (!o) {
80
+ t || (document.body.style.overflowY = "auto");
108
81
  return;
109
82
  }
110
- H("[data-fx-modal][data-state=open]:not([data-allow-body-scroll=true]").filter((s) => s !== n).length === 0 && !e && (document.body.style.overflowY = "auto");
83
+ c("[data-fx-modal][data-state=open]:not([data-allow-body-scroll=true]").filter((i) => i !== e).length === 0 && !t && (document.body.style.overflowY = "auto");
111
84
  };
112
- var Z = (t, e, n) => {
113
- var q;
114
- if (!(t instanceof HTMLElement))
115
- throw new Error("Modal Element must be a valid element");
116
- const { animateContent: a, allowBodyScroll: d, preventCloseModal: s, overlayClass: f, onShow: u, onHide: h, onToggle: m, beforeHide: b, enableStackedModals: g } = n, p = d || t.hasAttribute("data-allow-body-scroll") && t.getAttribute("data-allow-body-scroll") !== "false", F = s || t.hasAttribute("data-prevent-close-modal") && t.getAttribute("data-prevent-close-modal") !== "false", C = g || t.hasAttribute("data-enable-stacked") && t.getAttribute("data-enable-stacked") !== "false", K = (f == null ? void 0 : f.split(" ")) || ((q = t.dataset.modalOverlay) == null ? void 0 : q.split(" ")) || "";
117
- let x = false;
118
- t.setAttribute("data-allow-body-scroll", `${p}`);
119
- const o = r("[data-modal-content]", t), L = H("[data-close-modal]", t);
120
- let i = null, S = false;
121
- if (r("[data-modal-overlay]", t) instanceof HTMLElement && (i = r("[data-modal-overlay]", t), i.setAttribute("data-overlay-nature", "default"), S = true), !(o instanceof HTMLElement))
122
- throw new Error("Modal content element not found");
123
- const D = o.dataset.enterAnimation || "", P = o.dataset.exitAnimation || "";
124
- o.setAttribute("data-state", "close");
125
- const R = (l) => {
126
- l.key === "Escape" && (l.preventDefault(), F || A());
127
- }, X = (l) => {
128
- if (C)
129
- return;
130
- const w = H("[data-fx-modal][data-state=open]");
131
- for (const y of w)
132
- if (y !== l) {
133
- const M = r("[data-modal-overlay]", y);
134
- M.setAttribute("data-state", "close");
135
- const I = r("[data-modal-content]", y), E = M.getAttribute("data-overlay-nature") === "default";
136
- k(y, I, "close"), E || W(M);
137
- }
138
- }, T = () => {
139
- if (t.getAttribute("data-state") !== "open") {
140
- if (X(t), i = S ? i : U({
141
- modalContent: o,
142
- overlayClassName: K
143
- }), i == null || i.setAttribute("data-state", "open"), B(t, "modal-open", { modalId: t.id }), a || D !== "") {
144
- const w = a ? a.enterAnimation : D;
145
- w !== "" && o.style.setProperty("--un-modal-animation", w), k(t, o, "open"), N({
146
- element: o,
147
- callback: () => {
148
- o.style.removeProperty("--un-modal-animation");
149
- }
150
- });
151
- } else
152
- k(t, o, "open");
153
- p || (document.body.style.overflow = "hidden"), x || (document.addEventListener("keydown", R), x = true), t.focus(), s || i.addEventListener("click", A), u == null || u(), m == null || m({ isHidden: false });
154
- }
155
- }, A = () => {
156
- var E;
157
- let l = false;
158
- B(t, "before-hide", {
159
- modalId: t.id,
160
- setExitAction: ($) => {
161
- l = $;
162
- }
163
- });
164
- const w = (E = b == null ? void 0 : b()) == null ? void 0 : E.cancelAction;
165
- if (l || w)
166
- return;
167
- const y = () => {
168
- k(t, o, "close"), V(C, p, t), S || W(i), B(t, "modal-close", { modalId: t.id });
169
- }, M = () => {
170
- x && (document.removeEventListener("keydown", R), x = false), t.blur(), h == null || h(), m == null || m({ isHidden: true });
171
- }, I = (a == null ? void 0 : a.exitAnimation) && a.exitAnimation !== "" || P !== "";
172
- if (i == null || i.setAttribute("data-state", "close"), o.setAttribute("data-state", "close"), I) {
173
- const $ = a ? a.exitAnimation || "" : P;
174
- o.style.setProperty("--un-modal-animation", $);
175
- }
176
- N({
177
- element: o,
178
- callback: () => {
179
- I && o.style.removeProperty("--un-modal-animation"), y(), M();
180
- }
181
- });
182
- }, G = (l) => {
183
- l.preventDefault(), A();
184
- };
185
- return { autoInitModal: () => {
186
- if (e instanceof HTMLElement && e.addEventListener("click", T), L.length > 0)
187
- for (const l of L)
188
- l.addEventListener("click", G);
189
- }, showModal: T, hideModal: A, isHidden: () => t.dataset.state === "close", cleanup: () => {
190
- if (e instanceof HTMLElement && e.removeEventListener("click", T), L.length > 0)
191
- for (const l of L)
192
- l.removeEventListener("click", G);
193
- !s && i instanceof HTMLElement && i.removeEventListener("click", A), O.removeInstance("modal", t);
194
- } };
85
+ var v = class {
86
+ static initGlobalRegistry() {
87
+ window.$flexillaInstances || (window.$flexillaInstances = {});
88
+ }
89
+ static register(t, e, n) {
90
+ return this.initGlobalRegistry(), window.$flexillaInstances[t] || (window.$flexillaInstances[t] = []), this.getInstance(t, e) || (window.$flexillaInstances[t].push({ element: e, instance: n }), n);
91
+ }
92
+ static getInstance(t, e) {
93
+ var n, a;
94
+ return this.initGlobalRegistry(), (a = (n = window.$flexillaInstances[t]) == null ? void 0 : n.find(
95
+ (i) => i.element === e
96
+ )) == null ? void 0 : a.instance;
97
+ }
98
+ static removeInstance(t, e) {
99
+ this.initGlobalRegistry(), window.$flexillaInstances[t] && (window.$flexillaInstances[t] = window.$flexillaInstances[t].filter(
100
+ (n) => n.element !== e
101
+ ));
102
+ }
195
103
  };
196
- var v = class v2 {
104
+ var C = (o) => {
105
+ var t;
106
+ o instanceof HTMLElement && ((t = o.parentElement) == null || t.removeChild(o));
107
+ };
108
+ var x = ({ modalContent: o, overlayClassName: t }) => {
109
+ const e = document.createElement("span");
110
+ return e.setAttribute("aria-hidden", "true"), M({ newElement: e, existingElement: o }), e.classList.add(...t), e.setAttribute("data-modal-overlay", ""), e;
111
+ };
112
+ var m = class m2 {
197
113
  /**
198
114
  * Creates a new Modal instance
199
115
  * @param modal - The modal element or selector string to initialize
200
116
  * @param options - Configuration options for the modal behavior
201
- * @param triggerElement - Optional trigger element or selector that opens the modal
202
- * @throws {Error} When the provided modal element is invalid or cannot be found
117
+ * @param triggerElements - Optional trigger elements or selectors that open the modal
203
118
  */
204
- constructor(e, n = {}, a) {
205
- c(this, "modalElement");
206
- c(this, "showModal");
207
- c(this, "hideModal");
208
- c(this, "cleanup");
209
- c(this, "isHidden");
210
- c(this, "options");
211
- c(this, "state");
212
- const d = typeof e == "string" ? r(e) : e;
213
- if (!(d instanceof HTMLElement))
214
- throw new Error("Modal element not found or invalid. Please provide a valid HTMLElement or selector.");
215
- this.modalElement = d, this.options = n, this.state = (n == null ? void 0 : n.defaultState) || this.modalElement.dataset.state || "close";
216
- const s = O.getInstance("modal", this.modalElement);
217
- if (s)
218
- return s;
119
+ constructor(t, e = {}, n) {
120
+ s(this, "modalElement");
121
+ s(this, "modalId");
122
+ s(this, "modalContent");
123
+ s(this, "triggerButtons", []);
124
+ s(this, "overlayElement");
125
+ s(this, "dispatchEventToDocument");
126
+ s(this, "options");
127
+ s(this, "state");
128
+ s(this, "animationEnter");
129
+ s(this, "animationExit");
130
+ s(this, "animateContent");
131
+ s(this, "hasDefaultOverlay");
132
+ s(this, "enableStackedModals");
133
+ s(this, "preventCloseModal");
134
+ s(this, "isKeyDownEventRegistered");
135
+ s(this, "closeButtons");
136
+ s(this, "overlayClassName");
137
+ s(this, "allowBodyScroll");
138
+ s(this, "initAsOpen");
139
+ s(this, "closeAll", (t2) => {
140
+ if (this.enableStackedModals)
141
+ return;
142
+ const e2 = c("[data-fx-modal][data-state=open]");
143
+ for (const n2 of e2) {
144
+ const a2 = n2.dataset.modalId;
145
+ if (a2 !== t2.dataset.modalId) {
146
+ n2.blur(), r("[data-modal-overlay]", n2).setAttribute("data-state", "close");
147
+ const l2 = r("[data-modal-content]", n2);
148
+ E(n2, l2, "close"), document.dispatchEvent(new CustomEvent(`modal:${a2}:close`));
149
+ }
150
+ }
151
+ });
152
+ s(this, "closeModalEsc", (t2) => {
153
+ t2.key === "Escape" && (t2.preventDefault(), this.preventCloseModal || this.hideModal());
154
+ });
155
+ s(this, "initModal", (t2, e2) => {
156
+ var h;
157
+ if (!(t2 instanceof HTMLDialogElement))
158
+ throw new Error("Modal Element must be a valid HTMLDialog Element");
159
+ const { allowBodyScroll: n2, animateContent: a2, preventCloseModal: i2, overlayClass: l2, enableStackedModals: d2 } = e2;
160
+ this.allowBodyScroll = t2.hasAttribute("data-allow-body-scroll") && t2.getAttribute("data-allow-body-scroll") !== "false" || n2 || false, this.preventCloseModal = t2.hasAttribute("data-prevent-close-modal") && t2.getAttribute("data-prevent-close-modal") !== "false" || i2 || false, this.enableStackedModals = t2.hasAttribute("data-enable-stacked") && t2.getAttribute("data-enable-stacked") !== "false" || d2 || false, this.overlayClassName = ((h = t2.dataset.modalOverlay) == null ? void 0 : h.split(" ")) || (l2 == null ? void 0 : l2.split(" ")) || "", this.isKeyDownEventRegistered = false, t2.setAttribute("data-allow-body-scroll", `${this.allowBodyScroll}`), this.closeButtons = c("[data-close-modal]", t2), this.hasDefaultOverlay = false, r("[data-modal-overlay]", t2) instanceof HTMLElement && (this.overlayElement = r("[data-modal-overlay]", t2), this.overlayElement.setAttribute("data-overlay-nature", "default"), this.hasDefaultOverlay = true), this.animateContent = a2, this.animationEnter = this.modalContent.dataset.enterAnimation || "", this.animationExit = this.modalContent.dataset.exitAnimation || "", this.overlayElement && this.overlayElement.setAttribute("data-state", "close"), this.addEvents();
161
+ });
162
+ s(this, "closeModalOnX", (t2) => {
163
+ t2.preventDefault(), this.hideModal();
164
+ });
165
+ s(this, "addEvents", () => {
166
+ for (const t2 of this.triggerButtons)
167
+ t2.addEventListener("click", this.showModal);
168
+ if (this.closeButtons.length > 0)
169
+ for (const t2 of this.closeButtons)
170
+ t2.addEventListener("click", this.closeModalOnX);
171
+ this.dispatchEventToDocument && document.addEventListener(`modal:${this.modalId}:open`, this.showModal), this.dispatchEventToDocument && document.addEventListener(`modal:${this.modalId}:close`, this.hideModal);
172
+ });
173
+ s(this, "showModal", () => {
174
+ var e2, n2, a2, i2, l2;
175
+ if (!(!this.initAsOpen && this.modalElement.getAttribute("data-state") === "open")) {
176
+ if (this.initAsOpen = false, this.closeAll(this.modalElement), this.overlayElement = this.hasDefaultOverlay ? this.overlayElement : x({
177
+ modalContent: this.modalContent,
178
+ overlayClassName: this.overlayClassName
179
+ }), (e2 = this.overlayElement) == null || e2.setAttribute("data-state", "open"), f(this.modalElement, "modal-open", { modalId: this.modalId }), this.animateContent || this.animationEnter !== "") {
180
+ const d2 = this.animateContent ? this.animateContent.enterAnimation : this.animationEnter;
181
+ d2 && d2 !== "" && this.modalContent.style.setProperty("--un-modal-animation", d2), E(this.modalElement, this.modalContent, "open"), y({
182
+ element: this.modalContent,
183
+ callback: () => {
184
+ this.modalContent.style.removeProperty("--un-modal-animation");
185
+ }
186
+ });
187
+ } else
188
+ E(this.modalElement, this.modalContent, "open");
189
+ this.allowBodyScroll || (document.body.style.overflow = "hidden"), this.isKeyDownEventRegistered || (document.addEventListener("keydown", this.closeModalEsc), this.isKeyDownEventRegistered = true), this.modalContent.focus(), this.preventCloseModal || this.overlayElement.addEventListener("click", this.hideModal), (a2 = (n2 = this.options).onShow) == null || a2.call(n2), (l2 = (i2 = this.options).onToggle) == null || l2.call(i2, { isHidden: false }), this.modalElement.showModal();
190
+ }
191
+ });
192
+ s(this, "closeModal", () => {
193
+ this.modalElement.setAttribute("aria-hidden", "true"), this.modalElement.setAttribute("data-state", "close"), this.modalElement.blur(), A(this.enableStackedModals || false, this.allowBodyScroll || false, this.modalElement), this.hasDefaultOverlay || C(this.overlayElement), f(this.modalElement, "modal-close", { modalId: this.modalElement.id });
194
+ });
195
+ s(this, "closeLastAction", () => {
196
+ var t2, e2, n2, a2;
197
+ this.isKeyDownEventRegistered && (document.removeEventListener("keydown", this.closeModalEsc), this.isKeyDownEventRegistered = false), this.modalElement.blur(), (e2 = (t2 = this.options).onHide) == null || e2.call(t2), (a2 = (n2 = this.options).onToggle) == null || a2.call(n2, { isHidden: true });
198
+ });
199
+ s(this, "hideModal", () => {
200
+ var a2, i2, l2, d2, h;
201
+ let t2 = false;
202
+ f(this.modalElement, "before-hide", {
203
+ modalId: this.modalId,
204
+ setExitAction: (u) => {
205
+ t2 = u;
206
+ }
207
+ });
208
+ const e2 = (l2 = (i2 = (a2 = this.options).beforeHide) == null ? void 0 : i2.call(a2)) == null ? void 0 : l2.cancelAction;
209
+ if (t2 || e2)
210
+ return;
211
+ const n2 = ((d2 = this.animateContent) == null ? void 0 : d2.exitAnimation) && this.animateContent.exitAnimation !== "" || this.animationExit && this.animationExit !== "";
212
+ if ((h = this.overlayElement) == null || h.setAttribute("data-state", "close"), this.modalContent.setAttribute("data-state", "close"), n2) {
213
+ const u = this.animationExit ? this.animationExit : this.animateContent && this.animateContent.exitAnimation || "";
214
+ this.modalContent.style.setProperty("--un-modal-animation", u);
215
+ }
216
+ y({
217
+ element: this.modalContent,
218
+ callback: () => {
219
+ n2 && this.modalContent.style.removeProperty("--un-modal-animation"), this.closeModal(), this.closeLastAction(), document.activeElement instanceof HTMLElement && document.activeElement.blur(), this.modalElement.close("modal-closed");
220
+ }
221
+ });
222
+ });
223
+ s(this, "cleanup", () => {
224
+ for (const t2 of this.triggerButtons)
225
+ t2.removeEventListener("click", this.showModal);
226
+ if (this.closeButtons.length > 0)
227
+ for (const t2 of this.closeButtons)
228
+ t2.removeEventListener("click", this.closeModalOnX);
229
+ !this.preventCloseModal && this.overlayElement instanceof HTMLElement && this.overlayElement.removeEventListener("click", this.hideModal), this.dispatchEventToDocument && document.removeEventListener(`modal:${this.modalId}:open`, this.showModal), this.dispatchEventToDocument && document.removeEventListener(`modal:${this.modalId}:close`, this.hideModal), v.removeInstance("modal", this.modalElement);
230
+ });
231
+ s(this, "setOptions", ({ state: t2, allowBodyscroll: e2 }) => {
232
+ t2 && (this.state = t2), e2 !== void 0 && (this.allowBodyScroll = e2), this.state === "open" ? this.showModal() : this.state === "close" && this.hideModal();
233
+ });
234
+ const a = typeof t == "string" ? r(t) : t;
235
+ if (!(a instanceof HTMLDialogElement))
236
+ throw new Error("Modal element not found or invalid. Please provide a valid HTMLDialogElement or selector.");
237
+ this.modalElement = a, this.options = e, this.state = (e == null ? void 0 : e.defaultState) || this.modalElement.dataset.state || "close";
238
+ const i = v.getInstance("modal", this.modalElement);
239
+ if (i)
240
+ return i;
219
241
  this.modalElement.hasAttribute("data-fx-modal") || this.modalElement.setAttribute("data-fx-modal", "");
220
- const f = d.dataset.modalId, u = (typeof a == "string" ? r(a) : a) || r(`[data-modal-target='${f}']`), { showModal: h, hideModal: m, autoInitModal: b, isHidden: g, cleanup: p } = Z(d, u, this.options);
221
- this.state === "open" && h(), b(), this.showModal = h, this.hideModal = m, this.isHidden = g, this.cleanup = p, O.register("modal", this.modalElement, this);
242
+ const l = r("[data-modal-content]", a);
243
+ if (!(l instanceof HTMLElement))
244
+ throw new Error("Modal content element not found or invalid. Please provide a valid HTMLElement or selector.");
245
+ this.modalContent = l;
246
+ const d = a.dataset.modalId;
247
+ this.modalId = `${d}`, this.initializeTriggers(n, d), this.dispatchEventToDocument = this.options.dispatchEventToDocument || true, this.initModal(this.modalElement, this.options), this.state === "open" ? (this.initAsOpen = true, this.showModal()) : (this.initAsOpen = false, this.modalElement.blur(), this.modalContent.setAttribute("data-state", "close"), this.modalElement.setAttribute("aria-hidden", "true"), this.modalElement.setAttribute("data-state", "close")), v.register("modal", this.modalElement, this);
248
+ }
249
+ initializeTriggers(t, e) {
250
+ if (!t && e) {
251
+ const a = c(`[data-modal-target='${e}'], [data-modal-trigger][data-modal-id='${e}']`);
252
+ this.triggerButtons = a;
253
+ return;
254
+ }
255
+ if (!t)
256
+ return;
257
+ const n = Array.isArray(t) ? t : [t];
258
+ this.triggerButtons = n.map((a) => {
259
+ if (typeof a == "string") {
260
+ const i = r(a);
261
+ if (!(i instanceof HTMLElement))
262
+ throw new Error(`Trigger element not found: ${a}`);
263
+ return i;
264
+ }
265
+ if (!(a instanceof HTMLElement))
266
+ throw new Error("Invalid trigger element provided");
267
+ return a;
268
+ });
222
269
  }
223
270
  };
224
- c(v, "autoInit", (e = "[data-fx-modal]") => {
225
- const n = H(e);
226
- for (const a of n)
227
- new v(a);
271
+ s(m, "autoInit", (t = "[data-fx-modal]") => {
272
+ const e = c(t);
273
+ for (const n of e)
274
+ new m(n);
228
275
  }), /**
229
276
  * Creates and initializes a new Modal instance
230
- * @param modal - The modal element or selector string
231
- * @param options - Configuration options for the modal
232
- * @param triggerElement - Optional trigger element or selector
233
- * @returns {Modal} A new Modal instance
234
- *
235
- * @example
236
- * ```typescript
237
- * const modal = Modal.init('#myModal', {
238
- * defaultState: 'open',
239
- * allowBodyScroll: true
240
- * });
241
- * ```
242
277
  */
243
- c(v, "init", (e, n = {}, a) => new v(e, n, a));
244
- var Y = v;
278
+ s(m, "init", (t, e = {}, n) => new m(t, e, n));
279
+ var w = m;
245
280
 
246
281
  // src/index.js
247
282
  function Modal(Alpine) {
248
283
  Alpine.directive("modal", (el, {}, { cleanup }) => {
249
284
  const modalId = el.getAttribute("data-modal-id");
250
285
  if (!modalId) {
251
- console.error("\u274C data-modal-id is required but missing on element:", el);
286
+ console.error(
287
+ "\u274C data-modal-id is required but missing on element:",
288
+ el
289
+ );
290
+ return;
291
+ }
292
+ if (!(el instanceof HTMLDialogElement)) {
293
+ console.error(
294
+ "\u274C x-modal must be used only on an HTMLDialogElement:",
295
+ el
296
+ );
252
297
  return;
253
298
  }
254
- const modalInstance = new Y(el);
299
+ const content = el.querySelector("[data-modal-content]");
300
+ if (!content) {
301
+ console.error(
302
+ "\u274C data-modal-content Element is required but missing in Modal Element:",
303
+ el
304
+ );
305
+ return;
306
+ }
307
+ const modalInstance = new w(el, {
308
+ dispatchEventToDocument: false
309
+ });
255
310
  if (!Alpine.store("modals")) {
256
311
  Alpine.store("modals", {});
257
312
  }
258
313
  Alpine.store("modals")[modalId] = modalInstance;
259
- const openHandler = () => modalInstance.showModal();
260
- const closeHandler = () => modalInstance.hideModal();
261
- document.addEventListener(`modal:${modalId}:open`, openHandler);
262
- document.addEventListener(`modal:${modalId}:close`, closeHandler);
314
+ const showModal = () => modalInstance.showModal();
315
+ const hideModal = () => modalInstance.hideModal();
316
+ document.addEventListener(`modal:${modalId}:open`, showModal);
317
+ document.addEventListener(`modal:${modalId}:close`, hideModal);
263
318
  cleanup(() => {
264
- document.removeEventListener(`modal:${modalId}:open`, openHandler);
265
- document.removeEventListener(`modal:${modalId}:close`, closeHandler);
266
319
  modalInstance.cleanup();
267
320
  delete Alpine.store("modals")[modalId];
321
+ document.removeEventListener(`modal:${modalId}:open`, showModal);
322
+ document.removeEventListener(`modal:${modalId}:close`, hideModal);
268
323
  });
269
324
  });
270
325
  Alpine.magic("modal", () => (id) => {