@flexilla/alpine-modal 0.0.2 → 0.0.3
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 +226 -193
- package/dist/cdn.min.js +1 -1
- package/dist/module.cjs.js +226 -193
- package/dist/module.esm.js +226 -193
- package/package.json +3 -3
- package/src/index.js +34 -9
package/dist/module.cjs.js
CHANGED
|
@@ -24,247 +24,280 @@ __export(module_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(module_exports);
|
|
25
25
|
|
|
26
26
|
// ../../node_modules/@flexilla/modal/dist/modal.js
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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 C = Object.defineProperty;
|
|
28
|
+
var x = (o, t, e) => t in o ? C(o, t, { enumerable: true, configurable: true, writable: true, value: e }) : o[t] = e;
|
|
29
|
+
var a = (o, t, e) => x(o, typeof t != "symbol" ? t + "" : t, e);
|
|
30
|
+
var r = (o, t = document.body) => t.querySelector(o);
|
|
31
|
+
var u = (o, t = document.body) => Array.from(t.querySelectorAll(o));
|
|
32
|
+
var I = ({
|
|
33
|
+
newElement: o,
|
|
34
|
+
existingElement: t
|
|
54
35
|
}) => {
|
|
55
|
-
if (!(
|
|
36
|
+
if (!(o instanceof HTMLElement) || !(t instanceof HTMLElement))
|
|
56
37
|
throw new Error("Both parameters must be valid HTML elements.");
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
|
|
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
|
|
64
|
-
element:
|
|
65
|
-
callback:
|
|
66
|
-
type:
|
|
67
|
-
keysCheck:
|
|
44
|
+
var L = ({
|
|
45
|
+
element: o,
|
|
46
|
+
callback: t,
|
|
47
|
+
type: e,
|
|
48
|
+
keysCheck: n
|
|
68
49
|
}) => {
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
const
|
|
72
|
-
|
|
50
|
+
const s = getComputedStyle(o), i = s.animation;
|
|
51
|
+
if (i !== "none" && i !== "" && !n.includes(i)) {
|
|
52
|
+
const l = "animationend", d = () => {
|
|
53
|
+
o.removeEventListener(l, d), t();
|
|
73
54
|
};
|
|
74
|
-
|
|
55
|
+
o.addEventListener(l, d, { once: true });
|
|
75
56
|
} else
|
|
76
|
-
|
|
57
|
+
t();
|
|
77
58
|
};
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
element:
|
|
81
|
-
callback:
|
|
59
|
+
var g = ({ element: o, callback: t }) => {
|
|
60
|
+
L({
|
|
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
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
};
|
|
90
|
-
var W = (t) => {
|
|
91
|
-
var e;
|
|
92
|
-
t instanceof HTMLElement && ((e = t.parentElement) == null || e.removeChild(t));
|
|
67
|
+
var v = (o, t, e) => {
|
|
68
|
+
const n = new CustomEvent(t, { detail: e });
|
|
69
|
+
o.dispatchEvent(n);
|
|
93
70
|
};
|
|
94
|
-
var
|
|
95
|
-
|
|
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 f = (o, t, e) => {
|
|
72
|
+
if (!(t instanceof HTMLElement))
|
|
100
73
|
throw new Error("No modal-content found");
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
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
|
|
106
|
-
if (!
|
|
107
|
-
|
|
78
|
+
var B = (o, t, e) => {
|
|
79
|
+
if (!o) {
|
|
80
|
+
t || (document.body.style.overflowY = "auto");
|
|
108
81
|
return;
|
|
109
82
|
}
|
|
110
|
-
|
|
83
|
+
u("[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
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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 E = 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, s;
|
|
94
|
+
return this.initGlobalRegistry(), (s = (n = window.$flexillaInstances[t]) == null ? void 0 : n.find(
|
|
95
|
+
(i) => i.element === e
|
|
96
|
+
)) == null ? void 0 : s.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
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var k = (o) => {
|
|
105
|
+
var t;
|
|
106
|
+
o instanceof HTMLElement && ((t = o.parentElement) == null || t.removeChild(o));
|
|
107
|
+
};
|
|
108
|
+
var T = ({ modalContent: o, overlayClassName: t }) => {
|
|
109
|
+
const e = document.createElement("span");
|
|
110
|
+
return e.setAttribute("aria-hidden", "true"), I({ newElement: e, existingElement: o }), e.classList.add(...t), e.setAttribute("data-modal-overlay", ""), e;
|
|
195
111
|
};
|
|
196
|
-
var
|
|
112
|
+
var h = class h2 {
|
|
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
117
|
* @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
|
|
203
118
|
*/
|
|
204
|
-
constructor(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
119
|
+
constructor(t, e = {}, n) {
|
|
120
|
+
a(this, "modalElement");
|
|
121
|
+
a(this, "modalId");
|
|
122
|
+
a(this, "modalContent");
|
|
123
|
+
a(this, "triggerButton");
|
|
124
|
+
a(this, "overlayElement");
|
|
125
|
+
a(this, "dispatchEventToDocument");
|
|
126
|
+
a(this, "options");
|
|
127
|
+
a(this, "state");
|
|
128
|
+
a(this, "animationEnter");
|
|
129
|
+
a(this, "animationExit");
|
|
130
|
+
a(this, "animateContent");
|
|
131
|
+
a(this, "hasDefaultOverlay");
|
|
132
|
+
a(this, "enableStackedModals");
|
|
133
|
+
a(this, "preventCloseModal");
|
|
134
|
+
a(this, "isKeyDownEventRegistered");
|
|
135
|
+
a(this, "closeButtons");
|
|
136
|
+
a(this, "overlayClassName");
|
|
137
|
+
a(this, "allowBodyScroll");
|
|
138
|
+
a(this, "initAsOpen");
|
|
139
|
+
a(this, "closeAll", (t2) => {
|
|
140
|
+
if (this.enableStackedModals)
|
|
141
|
+
return;
|
|
142
|
+
const e2 = u("[data-fx-modal][data-state=open]");
|
|
143
|
+
for (const n2 of e2) {
|
|
144
|
+
const s2 = n2.dataset.modalId;
|
|
145
|
+
if (s2 !== t2.dataset.modalId) {
|
|
146
|
+
n2.blur(), r("[data-modal-overlay]", n2).setAttribute("data-state", "close");
|
|
147
|
+
const l2 = r("[data-modal-content]", n2);
|
|
148
|
+
f(n2, l2, "close"), document.dispatchEvent(new CustomEvent(`modal:${s2}:close`));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
a(this, "closeModalEsc", (t2) => {
|
|
153
|
+
t2.key === "Escape" && (t2.preventDefault(), this.preventCloseModal || this.hideModal());
|
|
154
|
+
});
|
|
155
|
+
a(this, "initModal", (t2, e2) => {
|
|
156
|
+
var m2;
|
|
157
|
+
if (!(t2 instanceof HTMLElement))
|
|
158
|
+
throw new Error("Modal Element must be a valid element");
|
|
159
|
+
const { allowBodyScroll: n2, animateContent: s2, 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 = ((m2 = t2.dataset.modalOverlay) == null ? void 0 : m2.split(" ")) || (l2 == null ? void 0 : l2.split(" ")) || "", this.isKeyDownEventRegistered = false, t2.setAttribute("data-allow-body-scroll", `${this.allowBodyScroll}`), this.closeButtons = u("[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 = s2, this.animationEnter = this.modalContent.dataset.enterAnimation || "", this.animationExit = this.modalContent.dataset.exitAnimation || "", this.modalContent.setAttribute("data-state", "close");
|
|
161
|
+
});
|
|
162
|
+
a(this, "closeModalOnX", (t2) => {
|
|
163
|
+
t2.preventDefault(), this.hideModal();
|
|
164
|
+
});
|
|
165
|
+
a(this, "addEvents", () => {
|
|
166
|
+
if (this.triggerButton instanceof HTMLElement && this.triggerButton.addEventListener("click", this.showModal), this.closeButtons.length > 0)
|
|
167
|
+
for (const t2 of this.closeButtons)
|
|
168
|
+
t2.addEventListener("click", this.closeModalOnX);
|
|
169
|
+
this.dispatchEventToDocument && document.addEventListener(`modal:${this.modalId}:open`, this.showModal), this.dispatchEventToDocument && document.addEventListener(`modal:${this.modalId}:close`, this.hideModal);
|
|
170
|
+
});
|
|
171
|
+
a(this, "showModal", () => {
|
|
172
|
+
var e2, n2, s2, i2, l2;
|
|
173
|
+
if (!(!this.initAsOpen && this.modalElement.getAttribute("data-state") === "open")) {
|
|
174
|
+
if (this.initAsOpen = false, this.closeAll(this.modalElement), this.overlayElement = this.hasDefaultOverlay ? this.overlayElement : T({
|
|
175
|
+
modalContent: this.modalContent,
|
|
176
|
+
overlayClassName: this.overlayClassName
|
|
177
|
+
}), (e2 = this.overlayElement) == null || e2.setAttribute("data-state", "open"), v(this.modalElement, "modal-open", { modalId: this.modalId }), this.animateContent || this.animationEnter !== "") {
|
|
178
|
+
const d2 = this.animateContent ? this.animateContent.enterAnimation : this.animationEnter;
|
|
179
|
+
d2 && d2 !== "" && this.modalContent.style.setProperty("--un-modal-animation", d2), f(this.modalElement, this.modalContent, "open"), g({
|
|
180
|
+
element: this.modalContent,
|
|
181
|
+
callback: () => {
|
|
182
|
+
this.modalContent.style.removeProperty("--un-modal-animation");
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
} else
|
|
186
|
+
f(this.modalElement, this.modalContent, "open");
|
|
187
|
+
this.allowBodyScroll || (document.body.style.overflow = "hidden"), this.isKeyDownEventRegistered || (document.addEventListener("keydown", this.closeModalEsc), this.isKeyDownEventRegistered = true), this.modalElement.focus(), this.preventCloseModal || this.overlayElement.addEventListener("click", this.hideModal), (s2 = (n2 = this.options).onShow) == null || s2.call(n2), (l2 = (i2 = this.options).onToggle) == null || l2.call(i2, { isHidden: false });
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
a(this, "hideModal", () => {
|
|
191
|
+
var l2, d2, m2, y, w;
|
|
192
|
+
let t2 = false;
|
|
193
|
+
v(this.modalElement, "before-hide", {
|
|
194
|
+
modalId: this.modalId,
|
|
195
|
+
setExitAction: (c) => {
|
|
196
|
+
t2 = c;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
const e2 = (m2 = (d2 = (l2 = this.options).beforeHide) == null ? void 0 : d2.call(l2)) == null ? void 0 : m2.cancelAction;
|
|
200
|
+
if (t2 || e2)
|
|
201
|
+
return;
|
|
202
|
+
const n2 = () => {
|
|
203
|
+
f(this.modalElement, this.modalContent, "close"), B(this.enableStackedModals || false, this.allowBodyScroll || false, this.modalElement), this.hasDefaultOverlay || k(this.overlayElement), v(this.modalElement, "modal-close", { modalId: this.modalElement.id });
|
|
204
|
+
}, s2 = () => {
|
|
205
|
+
var c, p, b, M;
|
|
206
|
+
this.isKeyDownEventRegistered && (document.removeEventListener("keydown", this.closeModalEsc), this.isKeyDownEventRegistered = false), this.modalElement.blur(), (p = (c = this.options).onHide) == null || p.call(c), (M = (b = this.options).onToggle) == null || M.call(b, { isHidden: true });
|
|
207
|
+
}, i2 = ((y = this.animateContent) == null ? void 0 : y.exitAnimation) && this.animateContent.exitAnimation !== "" || this.animationExit && this.animationExit !== "";
|
|
208
|
+
if ((w = this.overlayElement) == null || w.setAttribute("data-state", "close"), this.modalContent.setAttribute("data-state", "close"), i2) {
|
|
209
|
+
const c = this.animationExit ? this.animationExit : this.animateContent && this.animateContent.exitAnimation || "";
|
|
210
|
+
this.modalContent.style.setProperty("--un-modal-animation", c);
|
|
211
|
+
}
|
|
212
|
+
g({
|
|
213
|
+
element: this.modalContent,
|
|
214
|
+
callback: () => {
|
|
215
|
+
i2 && this.modalContent.style.removeProperty("--un-modal-animation"), n2(), s2();
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
a(this, "cleanup", () => {
|
|
220
|
+
if (this.triggerButton instanceof HTMLElement && this.triggerButton.removeEventListener("click", this.showModal), this.closeButtons.length > 0)
|
|
221
|
+
for (const t2 of this.closeButtons)
|
|
222
|
+
t2.removeEventListener("click", this.closeModalOnX);
|
|
223
|
+
!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), E.removeInstance("modal", this.modalElement);
|
|
224
|
+
});
|
|
225
|
+
const s = typeof t == "string" ? r(t) : t;
|
|
226
|
+
if (!(s instanceof HTMLElement))
|
|
214
227
|
throw new Error("Modal element not found or invalid. Please provide a valid HTMLElement or selector.");
|
|
215
|
-
this.modalElement =
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
218
|
-
return
|
|
228
|
+
this.modalElement = s, this.options = e, this.state = (e == null ? void 0 : e.defaultState) || this.modalElement.dataset.state || "close";
|
|
229
|
+
const i = E.getInstance("modal", this.modalElement);
|
|
230
|
+
if (i)
|
|
231
|
+
return i;
|
|
219
232
|
this.modalElement.hasAttribute("data-fx-modal") || this.modalElement.setAttribute("data-fx-modal", "");
|
|
220
|
-
const
|
|
221
|
-
|
|
233
|
+
const l = r("[data-modal-content]", s);
|
|
234
|
+
if (!(l instanceof HTMLElement))
|
|
235
|
+
throw new Error("Modal content element not found or invalid. Please provide a valid HTMLElement or selector.");
|
|
236
|
+
this.modalContent = l;
|
|
237
|
+
const d = s.dataset.modalId;
|
|
238
|
+
this.modalId = `${d}`;
|
|
239
|
+
const m = (typeof n == "string" ? r(n) : n) || r(`[data-modal-target='${d}']`);
|
|
240
|
+
this.triggerButton = m, this.initModal(this.modalElement, this.options), this.addEvents(), this.state === "open" ? (this.initAsOpen = true, this.showModal()) : this.initAsOpen = false, this.dispatchEventToDocument = this.options.dispatchEventToDocument || true, E.register("modal", this.modalElement, this);
|
|
222
241
|
}
|
|
223
242
|
};
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
for (const
|
|
227
|
-
new
|
|
243
|
+
a(h, "autoInit", (t = "[data-fx-modal]") => {
|
|
244
|
+
const e = u(t);
|
|
245
|
+
for (const n of e)
|
|
246
|
+
new h(n);
|
|
228
247
|
}), /**
|
|
229
248
|
* 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
249
|
*/
|
|
243
|
-
|
|
244
|
-
var
|
|
250
|
+
a(h, "init", (t, e = {}, n) => new h(t, e, n));
|
|
251
|
+
var A = h;
|
|
245
252
|
|
|
246
253
|
// src/index.js
|
|
247
254
|
function Modal(Alpine) {
|
|
248
255
|
Alpine.directive("modal", (el, {}, { cleanup }) => {
|
|
249
256
|
const modalId = el.getAttribute("data-modal-id");
|
|
250
257
|
if (!modalId) {
|
|
251
|
-
console.error(
|
|
258
|
+
console.error(
|
|
259
|
+
"\u274C data-modal-id is required but missing on element:",
|
|
260
|
+
el
|
|
261
|
+
);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const content = el.querySelector("[data-modal-content]");
|
|
265
|
+
if (!content) {
|
|
266
|
+
console.error(
|
|
267
|
+
"\u274C data-modal-content Element is required but missing in Modal Element:",
|
|
268
|
+
el
|
|
269
|
+
);
|
|
252
270
|
return;
|
|
253
271
|
}
|
|
254
|
-
const
|
|
272
|
+
const trigger = document.querySelector(
|
|
273
|
+
`[data-modal-trigger][data-modal-id="${modalId}"]`
|
|
274
|
+
);
|
|
275
|
+
const modalInstance = new A(el, {
|
|
276
|
+
dispatchEventToDocument: false
|
|
277
|
+
});
|
|
255
278
|
if (!Alpine.store("modals")) {
|
|
256
279
|
Alpine.store("modals", {});
|
|
257
280
|
}
|
|
258
281
|
Alpine.store("modals")[modalId] = modalInstance;
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
282
|
+
const showModal = () => {
|
|
283
|
+
modalInstance.showModal();
|
|
284
|
+
};
|
|
285
|
+
const hideModal = () => {
|
|
286
|
+
modalInstance.hideModal();
|
|
287
|
+
};
|
|
288
|
+
document.addEventListener(`modal:${modalId}:open`, showModal);
|
|
289
|
+
document.addEventListener(`modal:${modalId}:close`, hideModal);
|
|
290
|
+
if (trigger instanceof HTMLElement) {
|
|
291
|
+
trigger.addEventListener("click", showModal);
|
|
292
|
+
}
|
|
263
293
|
cleanup(() => {
|
|
264
|
-
document.removeEventListener(`modal:${modalId}:open`, openHandler);
|
|
265
|
-
document.removeEventListener(`modal:${modalId}:close`, closeHandler);
|
|
266
294
|
modalInstance.cleanup();
|
|
267
295
|
delete Alpine.store("modals")[modalId];
|
|
296
|
+
if (trigger instanceof HTMLElement) {
|
|
297
|
+
trigger.removeEventListener("click", showModal);
|
|
298
|
+
}
|
|
299
|
+
document.removeEventListener(`modal:${modalId}:open`, showModal);
|
|
300
|
+
document.removeEventListener(`modal:${modalId}:close`, hideModal);
|
|
268
301
|
});
|
|
269
302
|
});
|
|
270
303
|
Alpine.magic("modal", () => (id) => {
|