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