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