vanilla-drawers 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/drawers.es.js +154 -147
- package/dist/drawers.umd.js +2 -2
- package/package.json +1 -1
package/dist/drawers.es.js
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
var Q = (r,
|
2
|
-
if (!
|
1
|
+
var Q = (r, t, e) => {
|
2
|
+
if (!t.has(r))
|
3
3
|
throw TypeError("Cannot " + e);
|
4
4
|
};
|
5
|
-
var
|
6
|
-
if (
|
5
|
+
var n = (r, t, e) => (Q(r, t, "read from private field"), e ? e.call(r) : t.get(r)), m = (r, t, e) => {
|
6
|
+
if (t.has(r))
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
8
|
-
|
9
|
-
}, b = (r,
|
8
|
+
t instanceof WeakSet ? t.add(r) : t.set(r, e);
|
9
|
+
}, b = (r, t, e, a) => (Q(r, t, "write to private field"), a ? a.call(r, e) : t.set(r, e), e);
|
10
10
|
function ne(r) {
|
11
11
|
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
|
12
12
|
}
|
13
13
|
var re = { exports: {} };
|
14
14
|
(function(r) {
|
15
|
-
var
|
16
|
-
function
|
15
|
+
var t = Object.prototype.hasOwnProperty, e = "~";
|
16
|
+
function a() {
|
17
17
|
}
|
18
|
-
Object.create && (
|
18
|
+
Object.create && (a.prototype = /* @__PURE__ */ Object.create(null), new a().__proto__ || (e = !1));
|
19
19
|
function s(h, i, o) {
|
20
20
|
this.fn = h, this.context = i, this.once = o || !1;
|
21
21
|
}
|
@@ -26,17 +26,17 @@ var re = { exports: {} };
|
|
26
26
|
return h._events[w] ? h._events[w].fn ? h._events[w] = [h._events[w], g] : h._events[w].push(g) : (h._events[w] = g, h._eventsCount++), h;
|
27
27
|
}
|
28
28
|
function d(h, i) {
|
29
|
-
--h._eventsCount === 0 ? h._events = new
|
29
|
+
--h._eventsCount === 0 ? h._events = new a() : delete h._events[i];
|
30
30
|
}
|
31
31
|
function u() {
|
32
|
-
this._events = new
|
32
|
+
this._events = new a(), this._eventsCount = 0;
|
33
33
|
}
|
34
34
|
u.prototype.eventNames = function() {
|
35
35
|
var i = [], o, c;
|
36
36
|
if (this._eventsCount === 0)
|
37
37
|
return i;
|
38
38
|
for (c in o = this._events)
|
39
|
-
|
39
|
+
t.call(o, c) && i.push(e ? c.slice(1) : c);
|
40
40
|
return Object.getOwnPropertySymbols ? i.concat(Object.getOwnPropertySymbols(o)) : i;
|
41
41
|
}, u.prototype.listeners = function(i) {
|
42
42
|
var o = e ? e + i : i, c = this._events[o];
|
@@ -54,46 +54,46 @@ var re = { exports: {} };
|
|
54
54
|
var j = e ? e + i : i;
|
55
55
|
if (!this._events[j])
|
56
56
|
return !1;
|
57
|
-
var
|
58
|
-
if (
|
59
|
-
switch (
|
57
|
+
var l = this._events[j], S = arguments.length, k, y;
|
58
|
+
if (l.fn) {
|
59
|
+
switch (l.once && this.removeListener(i, l.fn, void 0, !0), S) {
|
60
60
|
case 1:
|
61
|
-
return
|
61
|
+
return l.fn.call(l.context), !0;
|
62
62
|
case 2:
|
63
|
-
return
|
63
|
+
return l.fn.call(l.context, o), !0;
|
64
64
|
case 3:
|
65
|
-
return
|
65
|
+
return l.fn.call(l.context, o, c), !0;
|
66
66
|
case 4:
|
67
|
-
return
|
67
|
+
return l.fn.call(l.context, o, c, v), !0;
|
68
68
|
case 5:
|
69
|
-
return
|
69
|
+
return l.fn.call(l.context, o, c, v, g), !0;
|
70
70
|
case 6:
|
71
|
-
return
|
71
|
+
return l.fn.call(l.context, o, c, v, g, w), !0;
|
72
72
|
}
|
73
73
|
for (y = 1, k = new Array(S - 1); y < S; y++)
|
74
74
|
k[y - 1] = arguments[y];
|
75
|
-
|
75
|
+
l.fn.apply(l.context, k);
|
76
76
|
} else {
|
77
|
-
var ie =
|
77
|
+
var ie = l.length, q;
|
78
78
|
for (y = 0; y < ie; y++)
|
79
|
-
switch (
|
79
|
+
switch (l[y].once && this.removeListener(i, l[y].fn, void 0, !0), S) {
|
80
80
|
case 1:
|
81
|
-
|
81
|
+
l[y].fn.call(l[y].context);
|
82
82
|
break;
|
83
83
|
case 2:
|
84
|
-
|
84
|
+
l[y].fn.call(l[y].context, o);
|
85
85
|
break;
|
86
86
|
case 3:
|
87
|
-
|
87
|
+
l[y].fn.call(l[y].context, o, c);
|
88
88
|
break;
|
89
89
|
case 4:
|
90
|
-
|
90
|
+
l[y].fn.call(l[y].context, o, c, v);
|
91
91
|
break;
|
92
92
|
default:
|
93
93
|
if (!k)
|
94
|
-
for (
|
95
|
-
k[
|
96
|
-
|
94
|
+
for (q = 1, k = new Array(S - 1); q < S; q++)
|
95
|
+
k[q - 1] = arguments[q];
|
96
|
+
l[y].fn.apply(l[y].context, k);
|
97
97
|
}
|
98
98
|
}
|
99
99
|
return !0;
|
@@ -111,27 +111,27 @@ var re = { exports: {} };
|
|
111
111
|
if (w.fn)
|
112
112
|
w.fn === o && (!v || w.once) && (!c || w.context === c) && d(this, g);
|
113
113
|
else {
|
114
|
-
for (var j = 0,
|
115
|
-
(w[j].fn !== o || v && !w[j].once || c && w[j].context !== c) &&
|
116
|
-
|
114
|
+
for (var j = 0, l = [], S = w.length; j < S; j++)
|
115
|
+
(w[j].fn !== o || v && !w[j].once || c && w[j].context !== c) && l.push(w[j]);
|
116
|
+
l.length ? this._events[g] = l.length === 1 ? l[0] : l : d(this, g);
|
117
117
|
}
|
118
118
|
return this;
|
119
119
|
}, u.prototype.removeAllListeners = function(i) {
|
120
120
|
var o;
|
121
|
-
return i ? (o = e ? e + i : i, this._events[o] && d(this, o)) : (this._events = new
|
121
|
+
return i ? (o = e ? e + i : i, this._events[o] && d(this, o)) : (this._events = new a(), this._eventsCount = 0), this;
|
122
122
|
}, u.prototype.off = u.prototype.removeListener, u.prototype.addListener = u.prototype.on, u.prefixed = e, u.EventEmitter = u, r.exports = u;
|
123
123
|
})(re);
|
124
124
|
var oe = re.exports;
|
125
125
|
const ae = /* @__PURE__ */ ne(oe);
|
126
|
-
var le = function(
|
127
|
-
return ce(
|
126
|
+
var le = function(t) {
|
127
|
+
return ce(t) && !he(t);
|
128
128
|
};
|
129
129
|
function ce(r) {
|
130
130
|
return !!r && typeof r == "object";
|
131
131
|
}
|
132
132
|
function he(r) {
|
133
|
-
var
|
134
|
-
return
|
133
|
+
var t = Object.prototype.toString.call(r);
|
134
|
+
return t === "[object RegExp]" || t === "[object Date]" || de(r);
|
135
135
|
}
|
136
136
|
var ue = typeof Symbol == "function" && Symbol.for, fe = ue ? Symbol.for("react.element") : 60103;
|
137
137
|
function de(r) {
|
@@ -140,59 +140,59 @@ function de(r) {
|
|
140
140
|
function pe(r) {
|
141
141
|
return Array.isArray(r) ? [] : {};
|
142
142
|
}
|
143
|
-
function
|
144
|
-
return
|
143
|
+
function B(r, t) {
|
144
|
+
return t.clone !== !1 && t.isMergeableObject(r) ? N(pe(r), r, t) : r;
|
145
145
|
}
|
146
|
-
function we(r,
|
147
|
-
return r.concat(
|
148
|
-
return
|
146
|
+
function we(r, t, e) {
|
147
|
+
return r.concat(t).map(function(a) {
|
148
|
+
return B(a, e);
|
149
149
|
});
|
150
150
|
}
|
151
|
-
function ye(r,
|
152
|
-
if (!
|
153
|
-
return
|
154
|
-
var e =
|
155
|
-
return typeof e == "function" ? e :
|
151
|
+
function ye(r, t) {
|
152
|
+
if (!t.customMerge)
|
153
|
+
return N;
|
154
|
+
var e = t.customMerge(r);
|
155
|
+
return typeof e == "function" ? e : N;
|
156
156
|
}
|
157
157
|
function me(r) {
|
158
|
-
return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(r).filter(function(
|
159
|
-
return Object.propertyIsEnumerable.call(r,
|
158
|
+
return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(r).filter(function(t) {
|
159
|
+
return Object.propertyIsEnumerable.call(r, t);
|
160
160
|
}) : [];
|
161
161
|
}
|
162
162
|
function W(r) {
|
163
163
|
return Object.keys(r).concat(me(r));
|
164
164
|
}
|
165
|
-
function se(r,
|
165
|
+
function se(r, t) {
|
166
166
|
try {
|
167
|
-
return
|
167
|
+
return t in r;
|
168
168
|
} catch {
|
169
169
|
return !1;
|
170
170
|
}
|
171
171
|
}
|
172
|
-
function be(r,
|
173
|
-
return se(r,
|
172
|
+
function be(r, t) {
|
173
|
+
return se(r, t) && !(Object.hasOwnProperty.call(r, t) && Object.propertyIsEnumerable.call(r, t));
|
174
174
|
}
|
175
|
-
function ge(r,
|
176
|
-
var
|
175
|
+
function ge(r, t, e) {
|
176
|
+
var a = {};
|
177
177
|
return e.isMergeableObject(r) && W(r).forEach(function(s) {
|
178
|
-
|
179
|
-
}), W(
|
180
|
-
be(r, s) || (se(r, s) && e.isMergeableObject(
|
181
|
-
}),
|
178
|
+
a[s] = B(r[s], e);
|
179
|
+
}), W(t).forEach(function(s) {
|
180
|
+
be(r, s) || (se(r, s) && e.isMergeableObject(t[s]) ? a[s] = ye(s, e)(r[s], t[s], e) : a[s] = B(t[s], e));
|
181
|
+
}), a;
|
182
182
|
}
|
183
|
-
function
|
184
|
-
e = e || {}, e.arrayMerge = e.arrayMerge || we, e.isMergeableObject = e.isMergeableObject || le, e.cloneUnlessOtherwiseSpecified =
|
185
|
-
var
|
186
|
-
return f ?
|
183
|
+
function N(r, t, e) {
|
184
|
+
e = e || {}, e.arrayMerge = e.arrayMerge || we, e.isMergeableObject = e.isMergeableObject || le, e.cloneUnlessOtherwiseSpecified = B;
|
185
|
+
var a = Array.isArray(t), s = Array.isArray(r), f = a === s;
|
186
|
+
return f ? a ? e.arrayMerge(r, t, e) : ge(r, t, e) : B(t, e);
|
187
187
|
}
|
188
|
-
|
189
|
-
if (!Array.isArray(
|
188
|
+
N.all = function(t, e) {
|
189
|
+
if (!Array.isArray(t))
|
190
190
|
throw new Error("first argument should be an array");
|
191
|
-
return
|
192
|
-
return
|
191
|
+
return t.reduce(function(a, s) {
|
192
|
+
return N(a, s, e);
|
193
193
|
}, {});
|
194
194
|
};
|
195
|
-
var Oe =
|
195
|
+
var Oe = N, ve = Oe;
|
196
196
|
const Ee = /* @__PURE__ */ ne(ve);
|
197
197
|
/*!
|
198
198
|
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
@@ -204,14 +204,14 @@ function X(r) {
|
|
204
204
|
return Object.prototype.toString.call(r) === "[object Object]";
|
205
205
|
}
|
206
206
|
function Ae(r) {
|
207
|
-
var
|
208
|
-
return X(r) === !1 ? !1 : (
|
207
|
+
var t, e;
|
208
|
+
return X(r) === !1 ? !1 : (t = r.constructor, t === void 0 ? !0 : (e = t.prototype, !(X(e) === !1 || e.hasOwnProperty("isPrototypeOf") === !1)));
|
209
209
|
}
|
210
210
|
function J(r) {
|
211
211
|
return r instanceof Element ? r : document.querySelector(r);
|
212
212
|
}
|
213
213
|
async function H(r) {
|
214
|
-
return await new Promise((
|
214
|
+
return await new Promise((t) => setTimeout(t, r));
|
215
215
|
}
|
216
216
|
const Ce = '[data-elem="drawer.panel"]', K = "data-drawers-group", _e = [
|
217
217
|
"a[href]",
|
@@ -248,43 +248,43 @@ function ee(r) {
|
|
248
248
|
isMergeableObject: Ae
|
249
249
|
});
|
250
250
|
}
|
251
|
-
var A, E, T,
|
251
|
+
var A, E, T, G;
|
252
252
|
class V {
|
253
|
-
constructor({ target:
|
253
|
+
constructor({ target: t, type: e, owner: a }) {
|
254
254
|
m(this, A, void 0);
|
255
255
|
m(this, E, void 0);
|
256
256
|
m(this, T, void 0);
|
257
|
-
m(this,
|
258
|
-
const s = J(
|
257
|
+
m(this, G, !1);
|
258
|
+
const s = J(t);
|
259
259
|
if (!s)
|
260
260
|
throw new Error("Trigger element cannot be found");
|
261
|
-
b(this, A, s), b(this, E,
|
261
|
+
b(this, A, s), b(this, E, a), b(this, T, e), this.init();
|
262
262
|
}
|
263
263
|
// Accessors
|
264
264
|
get isActive() {
|
265
|
-
return
|
265
|
+
return n(this, G);
|
266
266
|
}
|
267
267
|
get owner() {
|
268
|
-
return
|
268
|
+
return n(this, E);
|
269
269
|
}
|
270
270
|
// Methods
|
271
271
|
init() {
|
272
|
-
|
272
|
+
n(this, A).addEventListener("click", (t) => this.clickHandler(t)), n(this, E).on("open", () => this.setActive(!0)), n(this, E).on("close", () => this.setActive(!1));
|
273
273
|
}
|
274
|
-
clickHandler(
|
275
|
-
|
274
|
+
clickHandler(t) {
|
275
|
+
t.__drawerTrigger = this, n(this, T) === "open" ? n(this, E).isOpen || n(this, E).open(n(this, A)) : n(this, T) === "close" ? n(this, E).isOpen && n(this, E).close(n(this, A)) : n(this, E).isOpen ? n(this, E).close(n(this, A)) : n(this, E).open(n(this, A));
|
276
276
|
}
|
277
|
-
setActive(
|
278
|
-
b(this,
|
277
|
+
setActive(t) {
|
278
|
+
b(this, G, t), t ? n(this, A).classList.add("drawer-trigger_active") : n(this, A).classList.remove("drawer-trigger_active");
|
279
279
|
}
|
280
280
|
}
|
281
|
-
A = new WeakMap(), E = new WeakMap(), T = new WeakMap(),
|
282
|
-
var p,
|
281
|
+
A = new WeakMap(), E = new WeakMap(), T = new WeakMap(), G = new WeakMap();
|
282
|
+
var p, $, O, x, F, D;
|
283
283
|
class je extends ae {
|
284
|
-
constructor({ target: e, options:
|
284
|
+
constructor({ target: e, options: a }) {
|
285
285
|
super();
|
286
286
|
m(this, p, void 0);
|
287
|
-
m(this,
|
287
|
+
m(this, $, void 0);
|
288
288
|
m(this, O, void 0);
|
289
289
|
m(this, x, void 0);
|
290
290
|
m(this, F, void 0);
|
@@ -294,84 +294,84 @@ class je extends ae {
|
|
294
294
|
if (((o = u.__drawerTrigger) == null ? void 0 : o.owner) === this)
|
295
295
|
return;
|
296
296
|
const h = u.target;
|
297
|
-
if (u.composedPath(),
|
297
|
+
if (u.composedPath(), n(this, O).panel.contains(h))
|
298
298
|
return;
|
299
299
|
const i = h == null ? void 0 : h.closest("[data-drawer]");
|
300
|
-
i ? i.getAttribute("data-drawer") ===
|
300
|
+
i ? i.getAttribute("data-drawer") === n(this, D) ? this.handleUnderlayClick(u) : this.handleOtherDrawerClick(u) : this.handleOutsideClick(u);
|
301
301
|
}, this.handleKeydown = (u) => {
|
302
|
-
|
302
|
+
n(this, p).closeOnEsc && u.key === "Escape" && this.close();
|
303
303
|
};
|
304
|
-
const s = ee(
|
304
|
+
const s = ee(a ? [Z, a] : [Z]), f = J(e);
|
305
305
|
if (f === null)
|
306
306
|
throw new Error("Drawer's root cannot be found");
|
307
307
|
b(this, D, f.getAttribute("data-drawer"));
|
308
308
|
const d = f.querySelector(Ce);
|
309
309
|
if (d === null)
|
310
|
-
throw new Error(`Drawer's panel cannot be found. Alias: ${
|
310
|
+
throw new Error(`Drawer's panel cannot be found. Alias: ${n(this, D)}`);
|
311
311
|
b(this, O, {
|
312
312
|
root: f,
|
313
313
|
panel: d
|
314
|
-
}), this.setOptions(s),
|
314
|
+
}), this.setOptions(s), n(this, O).panel.setAttribute("tabindex", "-1"), n(this, O).root.classList.add("drawer_initialized");
|
315
315
|
}
|
316
316
|
addEventListeners() {
|
317
|
-
|
317
|
+
n(this, O).root.addEventListener("keydown", this.handleKeydown), document.addEventListener("click", this.handleDocumentClick);
|
318
318
|
}
|
319
319
|
removeEventListeners() {
|
320
|
-
|
320
|
+
n(this, O).root.removeEventListener("keydown", this.handleKeydown), document.removeEventListener("click", this.handleDocumentClick);
|
321
321
|
}
|
322
322
|
// Accessors
|
323
323
|
get isOpen() {
|
324
|
-
return
|
324
|
+
return n(this, x);
|
325
325
|
}
|
326
326
|
get isModal() {
|
327
|
-
return
|
327
|
+
return n(this, p).modal;
|
328
328
|
}
|
329
329
|
set isModal(e) {
|
330
|
-
|
330
|
+
n(this, O).root.classList[e ? "add" : "remove"]("drawer_modal");
|
331
331
|
}
|
332
332
|
set zIndex(e) {
|
333
|
-
|
333
|
+
n(this, O).root.style.setProperty("--z-index", String(e)), b(this, $, e);
|
334
334
|
}
|
335
335
|
get zIndex() {
|
336
|
-
return
|
336
|
+
return n(this, $);
|
337
337
|
}
|
338
338
|
// Methods
|
339
339
|
async open(e) {
|
340
|
-
await H(0), !
|
340
|
+
await H(0), !n(this, x) && (this.emit("beforeOpen", { drawer: this, trigger: e }), b(this, x, !0), n(this, O).root.classList.add(n(this, p).openClass), this.emit("open", { drawer: this, trigger: e }), typeof n(this, p).openAnimationDuration == "number" && H(n(this, p).openAnimationDuration), this.emit("openAnimationEnd", { drawer: this, trigger: e }), this.focus(), this.addEventListeners());
|
341
341
|
}
|
342
342
|
async close(e) {
|
343
|
-
|
343
|
+
n(this, p).onCloseConfirm && !n(this, p).onCloseConfirm(this, e) || (this.emit("beforeClose", { drawer: this, trigger: e }), this.removeEventListeners(), b(this, x, !1), n(this, O).root.classList.remove(n(this, p).openClass), this.emit("close", { drawer: this, trigger: e }), typeof n(this, p).closeAnimationDuration == "number" && H(n(this, p).closeAnimationDuration), this.emit("closeAnimationEnd", { drawer: this, trigger: e }));
|
344
344
|
}
|
345
345
|
handleOtherDrawerClick(e) {
|
346
346
|
}
|
347
347
|
handleOutsideClick(e) {
|
348
|
-
|
348
|
+
n(this, p).closeOnOutsideClick && (typeof n(this, p).closeOnOutsideClick == "object" && n(this, p).closeOnOutsideClick.hasOwnProperty("checkTarget") ? n(this, p).closeOnOutsideClick.checkTarget(e.target) && this.close() : this.close());
|
349
349
|
}
|
350
350
|
handleUnderlayClick(e) {
|
351
|
-
|
351
|
+
n(this, p).closeOnOutsideClick && this.close();
|
352
352
|
}
|
353
353
|
focus() {
|
354
|
-
|
354
|
+
n(this, p).focusOnChild && this.focusChild() || this.focusSelf();
|
355
355
|
}
|
356
356
|
focusSelf() {
|
357
|
-
|
357
|
+
n(this, O).panel.focus();
|
358
358
|
}
|
359
359
|
focusChild() {
|
360
|
-
const e =
|
360
|
+
const e = n(this, O).panel.querySelector(_e.join(","));
|
361
361
|
return e ? (e.focus(), !0) : !1;
|
362
362
|
}
|
363
363
|
setOptions(e) {
|
364
|
-
var
|
365
|
-
e.hasOwnProperty("modal") && ((
|
364
|
+
var a;
|
365
|
+
e.hasOwnProperty("modal") && ((a = n(this, p)) == null ? void 0 : a.modal) !== e.modal && (this.isModal = e.modal), b(this, p, n(this, p) ? ee([n(this, p), e]) : e);
|
366
366
|
}
|
367
367
|
assignGroup(e) {
|
368
368
|
b(this, F, e);
|
369
369
|
}
|
370
370
|
}
|
371
|
-
p = new WeakMap(),
|
371
|
+
p = new WeakMap(), $ = new WeakMap(), O = new WeakMap(), x = new WeakMap(), F = new WeakMap(), D = new WeakMap();
|
372
372
|
var P, C, _, I, L, M;
|
373
373
|
class te {
|
374
|
-
constructor(
|
374
|
+
constructor(t) {
|
375
375
|
m(this, P, void 0);
|
376
376
|
m(this, C, void 0);
|
377
377
|
m(this, _, void 0);
|
@@ -379,57 +379,57 @@ class te {
|
|
379
379
|
m(this, L, void 0);
|
380
380
|
m(this, M, void 0);
|
381
381
|
b(this, C, []), b(this, _, []), b(this, L, /* @__PURE__ */ new Set()), b(this, M, /* @__PURE__ */ new Map()), this.onBeforeOpen = ({ drawer: s, trigger: f }) => {
|
382
|
-
s.isModal ? (
|
382
|
+
s.isModal ? (n(this, M).set(s, n(this, C).length), n(this, C).push(s), s.zIndex = n(this, _).length + n(this, C).length) : (n(this, M).set(s, n(this, _).length), n(this, _).push(s), s.zIndex = n(this, _).length, n(this, C).length > 0 && n(this, C).forEach((d, u) => d.zIndex = n(this, _).length + u + 1)), this.lockScroll(s);
|
383
383
|
}, this.onCloseAnimationEnd = ({ drawer: s, trigger: f }) => {
|
384
|
-
const d = s.isModal ?
|
385
|
-
for (delete d[
|
384
|
+
const d = s.isModal ? n(this, C) : n(this, _);
|
385
|
+
for (delete d[n(this, M).get(s)]; d.length && !d.at(-1); )
|
386
386
|
d.pop();
|
387
|
-
|
387
|
+
n(this, M).delete(s), this.unlockScroll(s);
|
388
388
|
};
|
389
|
-
const e = J(
|
389
|
+
const e = J(t);
|
390
390
|
if (e === null)
|
391
391
|
throw new Error("Drawer's group root cannot be found");
|
392
392
|
b(this, P, e);
|
393
|
-
const
|
394
|
-
if (
|
393
|
+
const a = n(this, P).closest("[data-scrollable], html") || n(this, P).matches("[data-scrollable], html") && n(this, P);
|
394
|
+
if (a === null)
|
395
395
|
throw new Error("Scrollable container for group root cannot be found");
|
396
|
-
b(this, I,
|
396
|
+
b(this, I, a);
|
397
397
|
}
|
398
|
-
add(
|
399
|
-
|
398
|
+
add(t) {
|
399
|
+
t.on("beforeOpen", this.onBeforeOpen), t.on("closeAnimationEnd", this.onCloseAnimationEnd), t.assignGroup(this);
|
400
400
|
}
|
401
|
-
lockScroll(
|
402
|
-
|
401
|
+
lockScroll(t) {
|
402
|
+
n(this, L).size === 0 && n(this, I).classList.add("scroll-lock-by-drawer"), n(this, L).add(t);
|
403
403
|
}
|
404
|
-
unlockScroll(
|
405
|
-
|
404
|
+
unlockScroll(t) {
|
405
|
+
n(this, L).delete(t), n(this, L).size === 0 && n(this, I).classList.remove("scroll-lock-by-drawer");
|
406
406
|
}
|
407
407
|
}
|
408
408
|
P = new WeakMap(), C = new WeakMap(), _ = new WeakMap(), I = new WeakMap(), L = new WeakMap(), M = new WeakMap();
|
409
|
-
var
|
410
|
-
const
|
409
|
+
var z, U;
|
410
|
+
const R = class R {
|
411
411
|
constructor() {
|
412
|
-
m(this, $, /* @__PURE__ */ new Map());
|
413
412
|
m(this, z, /* @__PURE__ */ new Map());
|
414
|
-
|
415
|
-
|
416
|
-
|
413
|
+
m(this, U, /* @__PURE__ */ new Map());
|
414
|
+
if (R.instance)
|
415
|
+
return R.instance;
|
416
|
+
R.instance = this;
|
417
417
|
}
|
418
|
-
init(
|
418
|
+
init(t) {
|
419
419
|
document.querySelectorAll(`[${K}]`).forEach((f) => {
|
420
420
|
const d = f.getAttribute(K);
|
421
|
-
typeof d == "string" &&
|
422
|
-
}),
|
421
|
+
typeof d == "string" && n(this, U).set(d, new te(f));
|
422
|
+
}), n(this, U).set("default", new te(document.documentElement)), document.querySelectorAll("[data-drawer]").forEach((f) => {
|
423
423
|
var o;
|
424
424
|
const d = f.getAttribute("data-drawer");
|
425
425
|
if (typeof d != "string")
|
426
426
|
return;
|
427
|
-
const u = new je({ target: f, options:
|
428
|
-
|
427
|
+
const u = new je({ target: f, options: t });
|
428
|
+
n(this, z).set(d, u);
|
429
429
|
const h = f.closest(`[${K}]`), i = h ? h.getAttribute(K) : "default";
|
430
430
|
if (typeof i != "string")
|
431
431
|
throw new Error("Group doesn't have alias set correctly");
|
432
|
-
(o =
|
432
|
+
(o = n(this, U).get(i)) == null || o.add(u);
|
433
433
|
}), document.querySelectorAll("[data-drawer-open], [data-drawer-close], [data-drawer-toggle]").forEach((f) => {
|
434
434
|
if (f.hasAttribute("data-drawer-open")) {
|
435
435
|
const d = f.getAttribute("data-drawer-open");
|
@@ -443,20 +443,27 @@ const q = class q {
|
|
443
443
|
}
|
444
444
|
});
|
445
445
|
}
|
446
|
-
open(
|
446
|
+
open(t, { trigger: e, options: a } = {}) {
|
447
447
|
var s;
|
448
|
-
(s = this.get(
|
448
|
+
(s = this.get(t)) == null || s.open(e);
|
449
449
|
}
|
450
|
-
close(
|
450
|
+
close(t, { trigger: e, options: a } = {}) {
|
451
451
|
var s;
|
452
|
-
(s = this.get(
|
452
|
+
(s = this.get(t)) == null || s.close(e);
|
453
453
|
}
|
454
|
-
get(
|
455
|
-
return typeof
|
454
|
+
get(t) {
|
455
|
+
return typeof t == "string" && n(this, z).get(t) || null;
|
456
|
+
}
|
457
|
+
on(t, e, a) {
|
458
|
+
var s;
|
459
|
+
t ? (s = this.get(t)) == null || s.on(e, a) : Object.keys(n(this, z)).forEach((f) => {
|
460
|
+
var d;
|
461
|
+
return (d = this.get(f)) == null ? void 0 : d.on(e, a);
|
462
|
+
});
|
456
463
|
}
|
457
464
|
};
|
458
|
-
|
459
|
-
let Y =
|
465
|
+
z = new WeakMap(), U = new WeakMap();
|
466
|
+
let Y = R;
|
460
467
|
typeof window < "u" && (window.hasOwnProperty("app") || (window.app = {}), window.app.drawers = new Y());
|
461
468
|
export {
|
462
469
|
je as Drawer,
|
package/dist/drawers.umd.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
(function(p,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(p=typeof globalThis<"u"?globalThis:p||self,b(p.Drawers={}))})(this,function(p){"use strict";var le=(p,b,_)=>{if(!b.has(p))throw TypeError("Cannot "+_)};var t=(p,b,_)=>(le(p,b,"read from private field"),_?_.call(p):b.get(p)),g=(p,b,_)=>{if(b.has(p))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(p):b.set(p,_)},O=(p,b,_,V)=>(le(p,b,"write to private field"),V?V.call(p,_):b.set(p,_),_);var j,A,U,
|
1
|
+
(function(p,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(p=typeof globalThis<"u"?globalThis:p||self,b(p.Drawers={}))})(this,function(p){"use strict";var le=(p,b,_)=>{if(!b.has(p))throw TypeError("Cannot "+_)};var t=(p,b,_)=>(le(p,b,"read from private field"),_?_.call(p):b.get(p)),g=(p,b,_)=>{if(b.has(p))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(p):b.set(p,_)},O=(p,b,_,V)=>(le(p,b,"write to private field"),V?V.call(p,_):b.set(p,_),_);var j,A,U,$,w,K,E,P,W,N,D,S,L,q,k,x,G,R;function b(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var _={exports:{}};(function(r){var n=Object.prototype.hasOwnProperty,e="~";function a(){}Object.create&&(a.prototype=Object.create(null),new a().__proto__||(e=!1));function s(u,i,o){this.fn=u,this.context=i,this.once=o||!1}function f(u,i,o,c,C){if(typeof o!="function")throw new TypeError("The listener must be a function");var v=new s(o,c||u,C),y=e?e+i:i;return u._events[y]?u._events[y].fn?u._events[y]=[u._events[y],v]:u._events[y].push(v):(u._events[y]=v,u._eventsCount++),u}function d(u,i){--u._eventsCount===0?u._events=new a:delete u._events[i]}function h(){this._events=new a,this._eventsCount=0}h.prototype.eventNames=function(){var i=[],o,c;if(this._eventsCount===0)return i;for(c in o=this._events)n.call(o,c)&&i.push(e?c.slice(1):c);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(o)):i},h.prototype.listeners=function(i){var o=e?e+i:i,c=this._events[o];if(!c)return[];if(c.fn)return[c.fn];for(var C=0,v=c.length,y=new Array(v);C<v;C++)y[C]=c[C].fn;return y},h.prototype.listenerCount=function(i){var o=e?e+i:i,c=this._events[o];return c?c.fn?1:c.length:0},h.prototype.emit=function(i,o,c,C,v,y){var M=e?e+i:i;if(!this._events[M])return!1;var l=this._events[M],T=arguments.length,I,m;if(l.fn){switch(l.once&&this.removeListener(i,l.fn,void 0,!0),T){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,o),!0;case 3:return l.fn.call(l.context,o,c),!0;case 4:return l.fn.call(l.context,o,c,C),!0;case 5:return l.fn.call(l.context,o,c,C,v),!0;case 6:return l.fn.call(l.context,o,c,C,v,y),!0}for(m=1,I=new Array(T-1);m<T;m++)I[m-1]=arguments[m];l.fn.apply(l.context,I)}else{var Se=l.length,H;for(m=0;m<Se;m++)switch(l[m].once&&this.removeListener(i,l[m].fn,void 0,!0),T){case 1:l[m].fn.call(l[m].context);break;case 2:l[m].fn.call(l[m].context,o);break;case 3:l[m].fn.call(l[m].context,o,c);break;case 4:l[m].fn.call(l[m].context,o,c,C);break;default:if(!I)for(H=1,I=new Array(T-1);H<T;H++)I[H-1]=arguments[H];l[m].fn.apply(l[m].context,I)}}return!0},h.prototype.on=function(i,o,c){return f(this,i,o,c,!1)},h.prototype.once=function(i,o,c){return f(this,i,o,c,!0)},h.prototype.removeListener=function(i,o,c,C){var v=e?e+i:i;if(!this._events[v])return this;if(!o)return d(this,v),this;var y=this._events[v];if(y.fn)y.fn===o&&(!C||y.once)&&(!c||y.context===c)&&d(this,v);else{for(var M=0,l=[],T=y.length;M<T;M++)(y[M].fn!==o||C&&!y[M].once||c&&y[M].context!==c)&&l.push(y[M]);l.length?this._events[v]=l.length===1?l[0]:l:d(this,v)}return this},h.prototype.removeAllListeners=function(i){var o;return i?(o=e?e+i:i,this._events[o]&&d(this,o)):(this._events=new a,this._eventsCount=0),this},h.prototype.off=h.prototype.removeListener,h.prototype.addListener=h.prototype.on,h.prefixed=e,h.EventEmitter=h,r.exports=h})(_);var V=_.exports;const ae=b(V);var ce=function(n){return ue(n)&&!he(n)};function ue(r){return!!r&&typeof r=="object"}function he(r){var n=Object.prototype.toString.call(r);return n==="[object RegExp]"||n==="[object Date]"||pe(r)}var fe=typeof Symbol=="function"&&Symbol.for,de=fe?Symbol.for("react.element"):60103;function pe(r){return r.$$typeof===de}function we(r){return Array.isArray(r)?[]:{}}function B(r,n){return n.clone!==!1&&n.isMergeableObject(r)?z(we(r),r,n):r}function ye(r,n,e){return r.concat(n).map(function(a){return B(a,e)})}function me(r,n){if(!n.customMerge)return z;var e=n.customMerge(r);return typeof e=="function"?e:z}function be(r){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(r).filter(function(n){return Object.propertyIsEnumerable.call(r,n)}):[]}function te(r){return Object.keys(r).concat(be(r))}function ne(r,n){try{return n in r}catch{return!1}}function ge(r,n){return ne(r,n)&&!(Object.hasOwnProperty.call(r,n)&&Object.propertyIsEnumerable.call(r,n))}function Oe(r,n,e){var a={};return e.isMergeableObject(r)&&te(r).forEach(function(s){a[s]=B(r[s],e)}),te(n).forEach(function(s){ge(r,s)||(ne(r,s)&&e.isMergeableObject(n[s])?a[s]=me(s,e)(r[s],n[s],e):a[s]=B(n[s],e))}),a}function z(r,n,e){e=e||{},e.arrayMerge=e.arrayMerge||ye,e.isMergeableObject=e.isMergeableObject||ce,e.cloneUnlessOtherwiseSpecified=B;var a=Array.isArray(n),s=Array.isArray(r),f=a===s;return f?a?e.arrayMerge(r,n,e):Oe(r,n,e):B(n,e)}z.all=function(n,e){if(!Array.isArray(n))throw new Error("first argument should be an array");return n.reduce(function(a,s){return z(a,s,e)},{})};var ve=z,Ee=ve;const Ae=b(Ee);/*!
|
2
2
|
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
3
3
|
*
|
4
4
|
* Copyright (c) 2014-2017, Jon Schlinkert.
|
5
5
|
* Released under the MIT License.
|
6
|
-
*/function re(r){return Object.prototype.toString.call(r)==="[object Object]"}function Ce(r){var n,e;return re(r)===!1?!1:(n=r.constructor,n===void 0?!0:(e=n.prototype,!(re(e)===!1||e.hasOwnProperty("isPrototypeOf")===!1)))}function X(r){return r instanceof Element?r:document.querySelector(r)}async function Z(r){return await new Promise(n=>setTimeout(n,r))}const _e='[data-elem="drawer.panel"]',Y="data-drawers-group",je=["a[href]","area[href]",'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',"select:not([disabled]):not([aria-hidden])","textarea:not([disabled]):not([aria-hidden])","button:not([disabled]):not([aria-hidden])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'],se={modal:!0,focusOnChild:!0,closeOnEsc:!0,closeOnOutsideClick:!0,closeOnUnderlayClick:!0,onCloseConfirm:()=>!0,onBeforeClose:null,onClose:null,onCloseAnimationEnd:null,onBeforeOpen:null,onOpen:null,onOpenAnimationEnd:null,openClass:"drawer_open",openAnimationDuration:0,closeAnimationDuration:0,lockPageScroll:!0};function ie(r){return Ae.all(r,{isMergeableObject:Ce})}class J{constructor({target:n,type:e,owner:
|
6
|
+
*/function re(r){return Object.prototype.toString.call(r)==="[object Object]"}function Ce(r){var n,e;return re(r)===!1?!1:(n=r.constructor,n===void 0?!0:(e=n.prototype,!(re(e)===!1||e.hasOwnProperty("isPrototypeOf")===!1)))}function X(r){return r instanceof Element?r:document.querySelector(r)}async function Z(r){return await new Promise(n=>setTimeout(n,r))}const _e='[data-elem="drawer.panel"]',Y="data-drawers-group",je=["a[href]","area[href]",'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',"select:not([disabled]):not([aria-hidden])","textarea:not([disabled]):not([aria-hidden])","button:not([disabled]):not([aria-hidden])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'],se={modal:!0,focusOnChild:!0,closeOnEsc:!0,closeOnOutsideClick:!0,closeOnUnderlayClick:!0,onCloseConfirm:()=>!0,onBeforeClose:null,onClose:null,onCloseAnimationEnd:null,onBeforeOpen:null,onOpen:null,onOpenAnimationEnd:null,openClass:"drawer_open",openAnimationDuration:0,closeAnimationDuration:0,lockPageScroll:!0};function ie(r){return Ae.all(r,{isMergeableObject:Ce})}class J{constructor({target:n,type:e,owner:a}){g(this,j,void 0);g(this,A,void 0);g(this,U,void 0);g(this,$,!1);const s=X(n);if(!s)throw new Error("Trigger element cannot be found");O(this,j,s),O(this,A,a),O(this,U,e),this.init()}get isActive(){return t(this,$)}get owner(){return t(this,A)}init(){t(this,j).addEventListener("click",n=>this.clickHandler(n)),t(this,A).on("open",()=>this.setActive(!0)),t(this,A).on("close",()=>this.setActive(!1))}clickHandler(n){n.__drawerTrigger=this,t(this,U)==="open"?t(this,A).isOpen||t(this,A).open(t(this,j)):t(this,U)==="close"?t(this,A).isOpen&&t(this,A).close(t(this,j)):t(this,A).isOpen?t(this,A).close(t(this,j)):t(this,A).open(t(this,j))}setActive(n){O(this,$,n),n?t(this,j).classList.add("drawer-trigger_active"):t(this,j).classList.remove("drawer-trigger_active")}}j=new WeakMap,A=new WeakMap,U=new WeakMap,$=new WeakMap;class oe extends ae{constructor({target:e,options:a}){super();g(this,w,void 0);g(this,K,void 0);g(this,E,void 0);g(this,P,void 0);g(this,W,void 0);g(this,N,void 0);this.handleDocumentClick=async h=>{var o;if(((o=h.__drawerTrigger)==null?void 0:o.owner)===this)return;const u=h.target;if(h.composedPath(),t(this,E).panel.contains(u))return;const i=u==null?void 0:u.closest("[data-drawer]");i?i.getAttribute("data-drawer")===t(this,N)?this.handleUnderlayClick(h):this.handleOtherDrawerClick(h):this.handleOutsideClick(h)},this.handleKeydown=h=>{t(this,w).closeOnEsc&&h.key==="Escape"&&this.close()};const s=ie(a?[se,a]:[se]),f=X(e);if(f===null)throw new Error("Drawer's root cannot be found");O(this,N,f.getAttribute("data-drawer"));const d=f.querySelector(_e);if(d===null)throw new Error(`Drawer's panel cannot be found. Alias: ${t(this,N)}`);O(this,E,{root:f,panel:d}),this.setOptions(s),t(this,E).panel.setAttribute("tabindex","-1"),t(this,E).root.classList.add("drawer_initialized")}addEventListeners(){t(this,E).root.addEventListener("keydown",this.handleKeydown),document.addEventListener("click",this.handleDocumentClick)}removeEventListeners(){t(this,E).root.removeEventListener("keydown",this.handleKeydown),document.removeEventListener("click",this.handleDocumentClick)}get isOpen(){return t(this,P)}get isModal(){return t(this,w).modal}set isModal(e){t(this,E).root.classList[e?"add":"remove"]("drawer_modal")}set zIndex(e){t(this,E).root.style.setProperty("--z-index",String(e)),O(this,K,e)}get zIndex(){return t(this,K)}async open(e){await Z(0),!t(this,P)&&(this.emit("beforeOpen",{drawer:this,trigger:e}),O(this,P,!0),t(this,E).root.classList.add(t(this,w).openClass),this.emit("open",{drawer:this,trigger:e}),typeof t(this,w).openAnimationDuration=="number"&&Z(t(this,w).openAnimationDuration),this.emit("openAnimationEnd",{drawer:this,trigger:e}),this.focus(),this.addEventListeners())}async close(e){t(this,w).onCloseConfirm&&!t(this,w).onCloseConfirm(this,e)||(this.emit("beforeClose",{drawer:this,trigger:e}),this.removeEventListeners(),O(this,P,!1),t(this,E).root.classList.remove(t(this,w).openClass),this.emit("close",{drawer:this,trigger:e}),typeof t(this,w).closeAnimationDuration=="number"&&Z(t(this,w).closeAnimationDuration),this.emit("closeAnimationEnd",{drawer:this,trigger:e}))}handleOtherDrawerClick(e){}handleOutsideClick(e){t(this,w).closeOnOutsideClick&&(typeof t(this,w).closeOnOutsideClick=="object"&&t(this,w).closeOnOutsideClick.hasOwnProperty("checkTarget")?t(this,w).closeOnOutsideClick.checkTarget(e.target)&&this.close():this.close())}handleUnderlayClick(e){t(this,w).closeOnOutsideClick&&this.close()}focus(){t(this,w).focusOnChild&&this.focusChild()||this.focusSelf()}focusSelf(){t(this,E).panel.focus()}focusChild(){const e=t(this,E).panel.querySelector(je.join(","));return e?(e.focus(),!0):!1}setOptions(e){var a;e.hasOwnProperty("modal")&&((a=t(this,w))==null?void 0:a.modal)!==e.modal&&(this.isModal=e.modal),O(this,w,t(this,w)?ie([t(this,w),e]):e)}assignGroup(e){O(this,W,e)}}w=new WeakMap,K=new WeakMap,E=new WeakMap,P=new WeakMap,W=new WeakMap,N=new WeakMap;class ee{constructor(n){g(this,D,void 0);g(this,S,void 0);g(this,L,void 0);g(this,q,void 0);g(this,k,void 0);g(this,x,void 0);O(this,S,[]),O(this,L,[]),O(this,k,new Set),O(this,x,new Map),this.onBeforeOpen=({drawer:s,trigger:f})=>{s.isModal?(t(this,x).set(s,t(this,S).length),t(this,S).push(s),s.zIndex=t(this,L).length+t(this,S).length):(t(this,x).set(s,t(this,L).length),t(this,L).push(s),s.zIndex=t(this,L).length,t(this,S).length>0&&t(this,S).forEach((d,h)=>d.zIndex=t(this,L).length+h+1)),this.lockScroll(s)},this.onCloseAnimationEnd=({drawer:s,trigger:f})=>{const d=s.isModal?t(this,S):t(this,L);for(delete d[t(this,x).get(s)];d.length&&!d.at(-1);)d.pop();t(this,x).delete(s),this.unlockScroll(s)};const e=X(n);if(e===null)throw new Error("Drawer's group root cannot be found");O(this,D,e);const a=t(this,D).closest("[data-scrollable], html")||t(this,D).matches("[data-scrollable], html")&&t(this,D);if(a===null)throw new Error("Scrollable container for group root cannot be found");O(this,q,a)}add(n){n.on("beforeOpen",this.onBeforeOpen),n.on("closeAnimationEnd",this.onCloseAnimationEnd),n.assignGroup(this)}lockScroll(n){t(this,k).size===0&&t(this,q).classList.add("scroll-lock-by-drawer"),t(this,k).add(n)}unlockScroll(n){t(this,k).delete(n),t(this,k).size===0&&t(this,q).classList.remove("scroll-lock-by-drawer")}}D=new WeakMap,S=new WeakMap,L=new WeakMap,q=new WeakMap,k=new WeakMap,x=new WeakMap;const F=class F{constructor(){g(this,G,new Map);g(this,R,new Map);if(F.instance)return F.instance;F.instance=this}init(n){document.querySelectorAll(`[${Y}]`).forEach(f=>{const d=f.getAttribute(Y);typeof d=="string"&&t(this,R).set(d,new ee(f))}),t(this,R).set("default",new ee(document.documentElement)),document.querySelectorAll("[data-drawer]").forEach(f=>{var o;const d=f.getAttribute("data-drawer");if(typeof d!="string")return;const h=new oe({target:f,options:n});t(this,G).set(d,h);const u=f.closest(`[${Y}]`),i=u?u.getAttribute(Y):"default";if(typeof i!="string")throw new Error("Group doesn't have alias set correctly");(o=t(this,R).get(i))==null||o.add(h)}),document.querySelectorAll("[data-drawer-open], [data-drawer-close], [data-drawer-toggle]").forEach(f=>{if(f.hasAttribute("data-drawer-open")){const d=f.getAttribute("data-drawer-open");new J({target:f,type:"open",owner:this.get(d)})}else if(f.hasAttribute("data-drawer-close")){const d=f.getAttribute("data-drawer-close");new J({target:f,type:"close",owner:this.get(d)})}else{const d=f.getAttribute("data-drawer-toggle");new J({target:f,type:"toggle",owner:this.get(d)})}})}open(n,{trigger:e,options:a}={}){var s;(s=this.get(n))==null||s.open(e)}close(n,{trigger:e,options:a}={}){var s;(s=this.get(n))==null||s.close(e)}get(n){return typeof n=="string"&&t(this,G).get(n)||null}on(n,e,a){var s;n?(s=this.get(n))==null||s.on(e,a):Object.keys(t(this,G)).forEach(f=>{var d;return(d=this.get(f))==null?void 0:d.on(e,a)})}};G=new WeakMap,R=new WeakMap;let Q=F;typeof window<"u"&&(window.hasOwnProperty("app")||(window.app={}),window.app.drawers=new Q),p.Drawer=oe,p.DrawersGroup=ee,p.Trigger=J,p.default=Q,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|