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