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