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