vanilla-drawers 1.1.23 → 1.2.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/README.md +4 -1
- package/dist/drawers.es.js +260 -261
- package/dist/drawers.umd.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
@@ -12,7 +12,10 @@
|
|
12
12
|
* Каждая отедельная группа может установить блокировку скролла ближайшего к ней контейнера `[data-scrollable], html`
|
13
13
|
(добавляет class scroll-lock-by-drawer)
|
14
14
|
* Служебный класс drawer-trigger_active добавляется ко всем связанным тригерам (кнопкам открытия/закрытия), пока окно открыто
|
15
|
-
|
15
|
+
1.2.0
|
16
|
+
* Добавлены события beforeInit, afterInit для менеджера окон
|
17
|
+
* scrollLock стал доступен из менеджера окон ( scrollLock(container, symbol));
|
18
|
+
* На группу вешаются классы _has-modals-open, _has-non-modals-open
|
16
19
|
# to do
|
17
20
|
* Набор встроенных диалоговых окон alert, confirm, prompt etc
|
18
21
|
* Опционально фокус на первом поле вводе по открытию
|
package/dist/drawers.es.js
CHANGED
@@ -1,62 +1,62 @@
|
|
1
|
-
var
|
1
|
+
var X = (n, t, e) => {
|
2
2
|
if (!t.has(n))
|
3
3
|
throw TypeError("Cannot " + e);
|
4
4
|
};
|
5
|
-
var
|
5
|
+
var s = (n, t, e) => (X(n, t, "read from private field"), e ? e.call(n) : t.get(n)), y = (n, t, e) => {
|
6
6
|
if (t.has(n))
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
8
8
|
t instanceof WeakSet ? t.add(n) : t.set(n, e);
|
9
|
-
},
|
10
|
-
function
|
9
|
+
}, m = (n, t, e, l) => (X(n, t, "write to private field"), l ? l.call(n, e) : t.set(n, e), e);
|
10
|
+
function re(n) {
|
11
11
|
return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
|
12
12
|
}
|
13
|
-
var
|
13
|
+
var oe = { exports: {} };
|
14
14
|
(function(n) {
|
15
15
|
var t = Object.prototype.hasOwnProperty, e = "~";
|
16
|
-
function
|
16
|
+
function l() {
|
17
17
|
}
|
18
|
-
Object.create && (
|
19
|
-
function
|
20
|
-
this.fn =
|
18
|
+
Object.create && (l.prototype = /* @__PURE__ */ Object.create(null), new l().__proto__ || (e = !1));
|
19
|
+
function a(o, i, c) {
|
20
|
+
this.fn = o, this.context = i, this.once = c || !1;
|
21
21
|
}
|
22
|
-
function
|
22
|
+
function v(o, i, c, h, g) {
|
23
23
|
if (typeof c != "function")
|
24
24
|
throw new TypeError("The listener must be a function");
|
25
|
-
var
|
26
|
-
return
|
25
|
+
var b = new a(c, h || o, g), f = e ? e + i : i;
|
26
|
+
return o._events[f] ? o._events[f].fn ? o._events[f] = [o._events[f], b] : o._events[f].push(b) : (o._events[f] = b, o._eventsCount++), o;
|
27
27
|
}
|
28
|
-
function w(
|
29
|
-
--
|
28
|
+
function w(o, i) {
|
29
|
+
--o._eventsCount === 0 ? o._events = new l() : delete o._events[i];
|
30
30
|
}
|
31
|
-
function
|
32
|
-
this._events = new
|
31
|
+
function r() {
|
32
|
+
this._events = new l(), this._eventsCount = 0;
|
33
33
|
}
|
34
|
-
|
35
|
-
var
|
34
|
+
r.prototype.eventNames = function() {
|
35
|
+
var i = [], c, h;
|
36
36
|
if (this._eventsCount === 0)
|
37
|
-
return
|
37
|
+
return i;
|
38
38
|
for (h in c = this._events)
|
39
|
-
t.call(c, h) &&
|
40
|
-
return Object.getOwnPropertySymbols ?
|
41
|
-
},
|
42
|
-
var c = e ? e +
|
39
|
+
t.call(c, h) && i.push(e ? h.slice(1) : h);
|
40
|
+
return Object.getOwnPropertySymbols ? i.concat(Object.getOwnPropertySymbols(c)) : i;
|
41
|
+
}, r.prototype.listeners = function(i) {
|
42
|
+
var c = e ? e + i : i, h = this._events[c];
|
43
43
|
if (!h)
|
44
44
|
return [];
|
45
45
|
if (h.fn)
|
46
46
|
return [h.fn];
|
47
|
-
for (var
|
48
|
-
|
49
|
-
return
|
50
|
-
},
|
51
|
-
var c = e ? e +
|
47
|
+
for (var g = 0, b = h.length, f = new Array(b); g < b; g++)
|
48
|
+
f[g] = h[g].fn;
|
49
|
+
return f;
|
50
|
+
}, r.prototype.listenerCount = function(i) {
|
51
|
+
var c = e ? e + i : i, h = this._events[c];
|
52
52
|
return h ? h.fn ? 1 : h.length : 0;
|
53
|
-
},
|
54
|
-
var
|
55
|
-
if (!this._events[
|
53
|
+
}, r.prototype.emit = function(i, c, h, g, b, f) {
|
54
|
+
var k = e ? e + i : i;
|
55
|
+
if (!this._events[k])
|
56
56
|
return !1;
|
57
|
-
var u = this._events[
|
57
|
+
var u = this._events[k], L = arguments.length, M, p;
|
58
58
|
if (u.fn) {
|
59
|
-
switch (u.once && this.removeListener(
|
59
|
+
switch (u.once && this.removeListener(i, u.fn, void 0, !0), L) {
|
60
60
|
case 1:
|
61
61
|
return u.fn.call(u.context), !0;
|
62
62
|
case 2:
|
@@ -64,103 +64,103 @@ var ie = { exports: {} };
|
|
64
64
|
case 3:
|
65
65
|
return u.fn.call(u.context, c, h), !0;
|
66
66
|
case 4:
|
67
|
-
return u.fn.call(u.context, c, h,
|
67
|
+
return u.fn.call(u.context, c, h, g), !0;
|
68
68
|
case 5:
|
69
|
-
return u.fn.call(u.context, c, h,
|
69
|
+
return u.fn.call(u.context, c, h, g, b), !0;
|
70
70
|
case 6:
|
71
|
-
return u.fn.call(u.context, c, h,
|
71
|
+
return u.fn.call(u.context, c, h, g, b, f), !0;
|
72
72
|
}
|
73
|
-
for (
|
74
|
-
|
75
|
-
u.fn.apply(u.context,
|
73
|
+
for (p = 1, M = new Array(L - 1); p < L; p++)
|
74
|
+
M[p - 1] = arguments[p];
|
75
|
+
u.fn.apply(u.context, M);
|
76
76
|
} else {
|
77
|
-
var
|
78
|
-
for (
|
79
|
-
switch (u[
|
77
|
+
var ce = u.length, z;
|
78
|
+
for (p = 0; p < ce; p++)
|
79
|
+
switch (u[p].once && this.removeListener(i, u[p].fn, void 0, !0), L) {
|
80
80
|
case 1:
|
81
|
-
u[
|
81
|
+
u[p].fn.call(u[p].context);
|
82
82
|
break;
|
83
83
|
case 2:
|
84
|
-
u[
|
84
|
+
u[p].fn.call(u[p].context, c);
|
85
85
|
break;
|
86
86
|
case 3:
|
87
|
-
u[
|
87
|
+
u[p].fn.call(u[p].context, c, h);
|
88
88
|
break;
|
89
89
|
case 4:
|
90
|
-
u[
|
90
|
+
u[p].fn.call(u[p].context, c, h, g);
|
91
91
|
break;
|
92
92
|
default:
|
93
|
-
if (!
|
94
|
-
for (
|
95
|
-
|
96
|
-
u[
|
93
|
+
if (!M)
|
94
|
+
for (z = 1, M = new Array(L - 1); z < L; z++)
|
95
|
+
M[z - 1] = arguments[z];
|
96
|
+
u[p].fn.apply(u[p].context, M);
|
97
97
|
}
|
98
98
|
}
|
99
99
|
return !0;
|
100
|
-
},
|
101
|
-
return
|
102
|
-
},
|
103
|
-
return
|
104
|
-
},
|
105
|
-
var
|
106
|
-
if (!this._events[
|
100
|
+
}, r.prototype.on = function(i, c, h) {
|
101
|
+
return v(this, i, c, h, !1);
|
102
|
+
}, r.prototype.once = function(i, c, h) {
|
103
|
+
return v(this, i, c, h, !0);
|
104
|
+
}, r.prototype.removeListener = function(i, c, h, g) {
|
105
|
+
var b = e ? e + i : i;
|
106
|
+
if (!this._events[b])
|
107
107
|
return this;
|
108
108
|
if (!c)
|
109
|
-
return w(this,
|
110
|
-
var
|
111
|
-
if (
|
112
|
-
|
109
|
+
return w(this, b), this;
|
110
|
+
var f = this._events[b];
|
111
|
+
if (f.fn)
|
112
|
+
f.fn === c && (!g || f.once) && (!h || f.context === h) && w(this, b);
|
113
113
|
else {
|
114
|
-
for (var
|
115
|
-
(
|
116
|
-
u.length ? this._events[
|
114
|
+
for (var k = 0, u = [], L = f.length; k < L; k++)
|
115
|
+
(f[k].fn !== c || g && !f[k].once || h && f[k].context !== h) && u.push(f[k]);
|
116
|
+
u.length ? this._events[b] = u.length === 1 ? u[0] : u : w(this, b);
|
117
117
|
}
|
118
118
|
return this;
|
119
|
-
},
|
119
|
+
}, r.prototype.removeAllListeners = function(i) {
|
120
120
|
var c;
|
121
|
-
return
|
122
|
-
},
|
123
|
-
})(
|
124
|
-
var
|
125
|
-
const
|
126
|
-
var
|
127
|
-
return
|
121
|
+
return i ? (c = e ? e + i : i, this._events[c] && w(this, c)) : (this._events = new l(), this._eventsCount = 0), this;
|
122
|
+
}, r.prototype.off = r.prototype.removeListener, r.prototype.addListener = r.prototype.on, r.prefixed = e, r.EventEmitter = r, n.exports = r;
|
123
|
+
})(oe);
|
124
|
+
var he = oe.exports;
|
125
|
+
const ie = /* @__PURE__ */ re(he);
|
126
|
+
var ue = function(t) {
|
127
|
+
return de(t) && !fe(t);
|
128
128
|
};
|
129
|
-
function
|
129
|
+
function de(n) {
|
130
130
|
return !!n && typeof n == "object";
|
131
131
|
}
|
132
|
-
function
|
132
|
+
function fe(n) {
|
133
133
|
var t = Object.prototype.toString.call(n);
|
134
|
-
return t === "[object RegExp]" || t === "[object Date]" ||
|
134
|
+
return t === "[object RegExp]" || t === "[object Date]" || me(n);
|
135
135
|
}
|
136
|
-
var
|
137
|
-
function
|
138
|
-
return n.$$typeof ===
|
136
|
+
var pe = typeof Symbol == "function" && Symbol.for, we = pe ? Symbol.for("react.element") : 60103;
|
137
|
+
function me(n) {
|
138
|
+
return n.$$typeof === we;
|
139
139
|
}
|
140
|
-
function
|
140
|
+
function ge(n) {
|
141
141
|
return Array.isArray(n) ? [] : {};
|
142
142
|
}
|
143
143
|
function q(n, t) {
|
144
|
-
return t.clone !== !1 && t.isMergeableObject(n) ?
|
144
|
+
return t.clone !== !1 && t.isMergeableObject(n) ? U(ge(n), n, t) : n;
|
145
145
|
}
|
146
|
-
function
|
147
|
-
return n.concat(t).map(function(
|
148
|
-
return q(
|
146
|
+
function ye(n, t, e) {
|
147
|
+
return n.concat(t).map(function(l) {
|
148
|
+
return q(l, e);
|
149
149
|
});
|
150
150
|
}
|
151
|
-
function
|
151
|
+
function be(n, t) {
|
152
152
|
if (!t.customMerge)
|
153
|
-
return
|
153
|
+
return U;
|
154
154
|
var e = t.customMerge(n);
|
155
|
-
return typeof e == "function" ? e :
|
155
|
+
return typeof e == "function" ? e : U;
|
156
156
|
}
|
157
|
-
function
|
157
|
+
function ve(n) {
|
158
158
|
return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(n).filter(function(t) {
|
159
159
|
return Object.propertyIsEnumerable.call(n, t);
|
160
160
|
}) : [];
|
161
161
|
}
|
162
|
-
function
|
163
|
-
return Object.keys(n).concat(
|
162
|
+
function Z(n) {
|
163
|
+
return Object.keys(n).concat(ve(n));
|
164
164
|
}
|
165
165
|
function ae(n, t) {
|
166
166
|
try {
|
@@ -169,59 +169,59 @@ function ae(n, t) {
|
|
169
169
|
return !1;
|
170
170
|
}
|
171
171
|
}
|
172
|
-
function
|
172
|
+
function Oe(n, t) {
|
173
173
|
return ae(n, t) && !(Object.hasOwnProperty.call(n, t) && Object.propertyIsEnumerable.call(n, t));
|
174
174
|
}
|
175
|
-
function
|
176
|
-
var
|
177
|
-
return e.isMergeableObject(n) &&
|
178
|
-
|
179
|
-
}),
|
180
|
-
|
181
|
-
}),
|
175
|
+
function Ae(n, t, e) {
|
176
|
+
var l = {};
|
177
|
+
return e.isMergeableObject(n) && Z(n).forEach(function(a) {
|
178
|
+
l[a] = q(n[a], e);
|
179
|
+
}), Z(t).forEach(function(a) {
|
180
|
+
Oe(n, a) || (ae(n, a) && e.isMergeableObject(t[a]) ? l[a] = be(a, e)(n[a], t[a], e) : l[a] = q(t[a], e));
|
181
|
+
}), l;
|
182
182
|
}
|
183
|
-
function
|
184
|
-
e = e || {}, e.arrayMerge = e.arrayMerge ||
|
185
|
-
var
|
186
|
-
return
|
183
|
+
function U(n, t, e) {
|
184
|
+
e = e || {}, e.arrayMerge = e.arrayMerge || ye, e.isMergeableObject = e.isMergeableObject || ue, e.cloneUnlessOtherwiseSpecified = q;
|
185
|
+
var l = Array.isArray(t), a = Array.isArray(n), v = l === a;
|
186
|
+
return v ? l ? e.arrayMerge(n, t, e) : Ae(n, t, e) : q(t, e);
|
187
187
|
}
|
188
|
-
|
188
|
+
U.all = function(t, e) {
|
189
189
|
if (!Array.isArray(t))
|
190
190
|
throw new Error("first argument should be an array");
|
191
|
-
return t.reduce(function(
|
192
|
-
return
|
191
|
+
return t.reduce(function(l, a) {
|
192
|
+
return U(l, a, e);
|
193
193
|
}, {});
|
194
194
|
};
|
195
|
-
var
|
196
|
-
const
|
195
|
+
var Ce = U, _e = Ce;
|
196
|
+
const Ee = /* @__PURE__ */ re(_e);
|
197
197
|
/*!
|
198
198
|
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
199
199
|
*
|
200
200
|
* Copyright (c) 2014-2017, Jon Schlinkert.
|
201
201
|
* Released under the MIT License.
|
202
202
|
*/
|
203
|
-
function
|
203
|
+
function ee(n) {
|
204
204
|
return Object.prototype.toString.call(n) === "[object Object]";
|
205
205
|
}
|
206
|
-
function
|
206
|
+
function ke(n) {
|
207
207
|
var t, e;
|
208
|
-
return
|
208
|
+
return ee(n) === !1 ? !1 : (t = n.constructor, t === void 0 ? !0 : (e = t.prototype, !(ee(e) === !1 || e.hasOwnProperty("isPrototypeOf") === !1)));
|
209
209
|
}
|
210
|
-
function
|
210
|
+
function Q(n) {
|
211
211
|
return n instanceof Element ? n : document.querySelector(n);
|
212
212
|
}
|
213
|
-
async function
|
213
|
+
async function H(n) {
|
214
214
|
return await new Promise((t) => setTimeout(t, n));
|
215
215
|
}
|
216
|
-
var
|
216
|
+
var Le = (n, t, e) => {
|
217
217
|
if (!t.has(n))
|
218
218
|
throw TypeError("Cannot " + e);
|
219
|
-
},
|
219
|
+
}, T = (n, t, e) => (Le(n, t, "read from private field"), e ? e.call(n) : t.get(n)), te = (n, t, e) => {
|
220
220
|
if (t.has(n))
|
221
221
|
throw TypeError("Cannot add the same private member more than once");
|
222
222
|
t instanceof WeakSet ? t.add(n) : t.set(n, e);
|
223
|
-
},
|
224
|
-
const
|
223
|
+
}, N, $;
|
224
|
+
const Se = '[data-elem="drawer.panel"]', K = "data-drawers-group", Me = [
|
225
225
|
"a[href]",
|
226
226
|
"area[href]",
|
227
227
|
'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',
|
@@ -233,7 +233,7 @@ const Me = '[data-elem="drawer.panel"]', K = "data-drawers-group", De = [
|
|
233
233
|
"embed",
|
234
234
|
"[contenteditable]",
|
235
235
|
'[tabindex]:not([tabindex^="-"])'
|
236
|
-
],
|
236
|
+
], Y = {
|
237
237
|
modal: !0,
|
238
238
|
focusOnChild: !0,
|
239
239
|
closeOnEsc: !0,
|
@@ -256,76 +256,76 @@ const Me = '[data-elem="drawer.panel"]', K = "data-drawers-group", De = [
|
|
256
256
|
unlockDelay: 300
|
257
257
|
}
|
258
258
|
};
|
259
|
-
function
|
260
|
-
return
|
261
|
-
isMergeableObject:
|
259
|
+
function ne(n) {
|
260
|
+
return Ee.all(n, {
|
261
|
+
isMergeableObject: ke
|
262
262
|
});
|
263
263
|
}
|
264
|
-
var
|
265
|
-
class
|
266
|
-
constructor({ target: t, type: e, owner:
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
const
|
272
|
-
if (!
|
264
|
+
var E, O, P, G;
|
265
|
+
class V {
|
266
|
+
constructor({ target: t, type: e, owner: l }) {
|
267
|
+
y(this, E, void 0);
|
268
|
+
y(this, O, void 0);
|
269
|
+
y(this, P, void 0);
|
270
|
+
y(this, G, !1);
|
271
|
+
const a = Q(t);
|
272
|
+
if (!a)
|
273
273
|
throw new Error("Trigger element cannot be found");
|
274
|
-
if (!
|
274
|
+
if (!l)
|
275
275
|
throw new Error("Owning drawer instance hasn't been provided");
|
276
|
-
|
276
|
+
m(this, E, a), m(this, O, l), m(this, P, e), this.init();
|
277
277
|
}
|
278
278
|
// Accessors
|
279
279
|
get isActive() {
|
280
|
-
return
|
280
|
+
return s(this, G);
|
281
281
|
}
|
282
282
|
get owner() {
|
283
|
-
return
|
283
|
+
return s(this, O);
|
284
284
|
}
|
285
285
|
// Methods
|
286
286
|
init() {
|
287
|
-
|
287
|
+
s(this, E).addEventListener("click", (t) => this.clickHandler(t)), s(this, O).on("open", () => this.setActive(!0)), s(this, O).on("close", () => this.setActive(!1));
|
288
288
|
}
|
289
289
|
clickHandler(t) {
|
290
|
-
t.__drawerTrigger = this,
|
290
|
+
t.__drawerTrigger = this, s(this, P) === "open" ? s(this, O).isOpen || s(this, O).open(s(this, E)) : s(this, P) === "close" ? s(this, O).isOpen && s(this, O).close(s(this, E)) : s(this, O).isOpen ? s(this, O).close(s(this, E)) : s(this, O).open(s(this, E));
|
291
291
|
}
|
292
292
|
setActive(t) {
|
293
|
-
|
293
|
+
m(this, G, t), t ? s(this, E).classList.add("drawer-trigger_active") : s(this, E).classList.remove("drawer-trigger_active");
|
294
294
|
}
|
295
295
|
}
|
296
|
-
|
297
|
-
var d,
|
298
|
-
class xe extends
|
299
|
-
constructor({ target: e, options:
|
296
|
+
E = new WeakMap(), O = new WeakMap(), P = new WeakMap(), G = new WeakMap();
|
297
|
+
var d, R, x, W, I;
|
298
|
+
class xe extends ie {
|
299
|
+
constructor({ target: e, options: l }) {
|
300
300
|
super();
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
this.handleDocumentClick = async (
|
301
|
+
y(this, d, void 0);
|
302
|
+
y(this, R, void 0);
|
303
|
+
y(this, x, void 0);
|
304
|
+
y(this, W, void 0);
|
305
|
+
y(this, I, void 0);
|
306
|
+
this.handleDocumentClick = async (r) => {
|
307
307
|
var c;
|
308
|
-
if (((c =
|
308
|
+
if (((c = r.__drawerTrigger) == null ? void 0 : c.owner) === this)
|
309
309
|
return;
|
310
|
-
const
|
311
|
-
if (
|
310
|
+
const o = r.target;
|
311
|
+
if (r.composedPath(), this.dom.panel.contains(o))
|
312
312
|
return;
|
313
|
-
const
|
314
|
-
|
315
|
-
}, this.handleKeydown = (
|
316
|
-
|
313
|
+
const i = o == null ? void 0 : o.closest("[data-drawer]");
|
314
|
+
i ? i.getAttribute("data-drawer") === s(this, I) ? this.handleUnderlayClick(r) : this.handleOtherDrawerClick(r) : this.handleOutsideClick(r);
|
315
|
+
}, this.handleKeydown = (r) => {
|
316
|
+
s(this, d).closeOnEsc && r.key === "Escape" && this.close();
|
317
317
|
};
|
318
|
-
const
|
319
|
-
if (
|
318
|
+
const a = ne(l ? [Y, l] : [Y]), v = Q(e);
|
319
|
+
if (v === null)
|
320
320
|
throw new Error("Drawer's root cannot be found");
|
321
|
-
|
322
|
-
const w =
|
321
|
+
m(this, I, v.getAttribute("data-drawer"));
|
322
|
+
const w = v.querySelector(Se);
|
323
323
|
if (w === null)
|
324
|
-
throw new Error(`Drawer's panel cannot be found. Alias: ${
|
324
|
+
throw new Error(`Drawer's panel cannot be found. Alias: ${s(this, I)}`);
|
325
325
|
this.dom = {
|
326
|
-
root:
|
326
|
+
root: v,
|
327
327
|
panel: w
|
328
|
-
}, this.setOptions(
|
328
|
+
}, this.setOptions(a), this.dom.panel.setAttribute("tabindex", "-1"), this.dom.root.classList.add("drawer_initialized");
|
329
329
|
}
|
330
330
|
addEventListeners() {
|
331
331
|
this.dom.root.addEventListener("keydown", this.handleKeydown), document.addEventListener("click", this.handleDocumentClick);
|
@@ -335,189 +335,188 @@ class xe extends de {
|
|
335
335
|
}
|
336
336
|
get scrollUnlockDelay() {
|
337
337
|
var e;
|
338
|
-
return ((e =
|
338
|
+
return ((e = s(this, d).lockScroll) == null ? void 0 : e.unlockDelay) || 0;
|
339
339
|
}
|
340
340
|
// Accessors
|
341
341
|
get isOpen() {
|
342
|
-
return
|
342
|
+
return s(this, x);
|
343
343
|
}
|
344
344
|
get isModal() {
|
345
|
-
return
|
345
|
+
return s(this, d).modal;
|
346
346
|
}
|
347
347
|
set isModal(e) {
|
348
348
|
this.dom.root.classList[e ? "add" : "remove"]("drawer_modal");
|
349
349
|
}
|
350
350
|
get willLockScroll() {
|
351
|
-
return
|
351
|
+
return s(this, d).lockPageScroll;
|
352
352
|
}
|
353
353
|
set zIndex(e) {
|
354
|
-
this.dom.root.style.setProperty("--z-index", String(e)),
|
354
|
+
this.dom.root.style.setProperty("--z-index", String(e)), m(this, R, e);
|
355
355
|
}
|
356
356
|
get zIndex() {
|
357
|
-
return
|
357
|
+
return s(this, R);
|
358
358
|
}
|
359
359
|
// Methods
|
360
360
|
async open(e) {
|
361
|
-
await
|
361
|
+
await H(0), !s(this, x) && (this.emit("beforeOpen", { drawer: this, trigger: e }), m(this, x, !0), this.dom.root.classList.add(s(this, d).openingClass), this.emit("open", { drawer: this, trigger: e }), typeof s(this, d).openAnimationDuration == "number" && await H(s(this, d).openAnimationDuration), this.dom.root.classList.remove(s(this, d).openingClass), this.dom.root.classList.add(s(this, d).openClass), this.emit("openAnimationEnd", { drawer: this, trigger: e }), this.focus(), this.addEventListeners());
|
362
362
|
}
|
363
363
|
async close(e) {
|
364
|
-
|
364
|
+
s(this, d).onCloseConfirm && !s(this, d).onCloseConfirm(this, e) || (this.emit("beforeClose", { drawer: this, trigger: e }), this.removeEventListeners(), m(this, x, !1), this.dom.root.classList.remove(s(this, d).openClass), this.dom.root.classList.add(s(this, d).closingClass), this.emit("close", { drawer: this, trigger: e }), typeof s(this, d).closeAnimationDuration == "number" && await H(s(this, d).closeAnimationDuration), this.dom.root.classList.remove(s(this, d).closingClass), this.emit("closeAnimationEnd", { drawer: this, trigger: e }));
|
365
365
|
}
|
366
366
|
handleOtherDrawerClick(e) {
|
367
367
|
}
|
368
368
|
handleOutsideClick(e) {
|
369
|
-
|
369
|
+
s(this, d).closeOnOutsideClick && (typeof s(this, d).closeOnOutsideClick == "object" && s(this, d).closeOnOutsideClick.hasOwnProperty("checkTarget") ? s(this, d).closeOnOutsideClick.checkTarget(e.target) && this.close() : this.close());
|
370
370
|
}
|
371
371
|
handleUnderlayClick(e) {
|
372
|
-
|
372
|
+
s(this, d).closeOnOutsideClick && this.close();
|
373
373
|
}
|
374
374
|
focus() {
|
375
|
-
|
375
|
+
s(this, d).focusOnChild && this.focusChild() || this.focusSelf();
|
376
376
|
}
|
377
377
|
focusSelf() {
|
378
378
|
this.dom.panel.focus();
|
379
379
|
}
|
380
380
|
focusChild() {
|
381
|
-
const e = this.dom.panel.querySelector(
|
381
|
+
const e = this.dom.panel.querySelector(Me.join(","));
|
382
382
|
return e ? (e.focus(), !0) : !1;
|
383
383
|
}
|
384
384
|
setOptions(e) {
|
385
|
-
var
|
386
|
-
e.hasOwnProperty("modal") && ((
|
385
|
+
var l;
|
386
|
+
e.hasOwnProperty("modal") && ((l = s(this, d)) == null ? void 0 : l.modal) !== e.modal && (this.isModal = e.modal), m(this, d, s(this, d) ? ne([s(this, d), e]) : e);
|
387
387
|
}
|
388
388
|
assignGroup(e) {
|
389
|
-
|
389
|
+
m(this, W, e);
|
390
390
|
}
|
391
391
|
}
|
392
|
-
d = new WeakMap(),
|
393
|
-
var
|
392
|
+
d = new WeakMap(), R = new WeakMap(), x = new WeakMap(), W = new WeakMap(), I = new WeakMap();
|
393
|
+
var j, D;
|
394
394
|
class je {
|
395
395
|
constructor() {
|
396
|
-
|
397
|
-
|
396
|
+
y(this, j, null);
|
397
|
+
y(this, D, /* @__PURE__ */ new Map());
|
398
398
|
}
|
399
399
|
lock(t, e) {
|
400
|
-
|
401
|
-
const
|
402
|
-
|
400
|
+
s(this, j) !== null && (clearTimeout(s(this, j)), m(this, j, null)), s(this, D).has(t) || s(this, D).set(t, /* @__PURE__ */ new Set());
|
401
|
+
const l = s(this, D).get(t);
|
402
|
+
l.size === 0 && t.classList.add("scroll-lock-by-drawer"), l.add(e);
|
403
403
|
}
|
404
404
|
unlock(t, e) {
|
405
|
-
const
|
406
|
-
|
405
|
+
const l = s(this, D).get(t);
|
406
|
+
l == null || l.delete(e), (!l || l.size === 0) && m(this, j, setTimeout(() => t.classList.remove("scroll-lock-by-drawer"), e.scrollUnlockDelay));
|
407
407
|
}
|
408
408
|
}
|
409
|
-
|
410
|
-
const
|
409
|
+
j = new WeakMap(), D = new WeakMap();
|
410
|
+
const J = new je();
|
411
|
+
var _, A, C, B, S;
|
412
|
+
class se {
|
411
413
|
constructor(t) {
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
414
|
+
y(this, _, void 0);
|
415
|
+
y(this, A, void 0);
|
416
|
+
y(this, C, void 0);
|
417
|
+
y(this, B, void 0);
|
418
|
+
y(this, S, void 0);
|
419
|
+
m(this, A, []), m(this, C, []), m(this, S, /* @__PURE__ */ new Map()), this.onBeforeOpen = ({ drawer: a, trigger: v }) => {
|
420
|
+
a.isModal ? (s(this, S).set(a, s(this, A).length), s(this, A).push(a), a.zIndex = s(this, C).length + s(this, A).length) : (s(this, S).set(a, s(this, C).length), s(this, C).push(a), a.zIndex = s(this, C).length, s(this, A).length > 0 && s(this, A).forEach((w, r) => w.zIndex = s(this, C).length + r + 1)), s(this, _).classList.toggle("_has-drawers-open", !!(s(this, C).length || s(this, A).length)), s(this, _).classList.toggle("_has-non-modals-open", !!s(this, C).length), s(this, _).classList.toggle("_has-modals-open", !!s(this, A).length), a.willLockScroll && this.lockScroll(a);
|
421
|
+
}, this.onCloseAnimationEnd = ({ drawer: a, trigger: v }) => {
|
422
|
+
const w = a.isModal ? s(this, A) : s(this, C);
|
423
|
+
for (delete w[s(this, S).get(a)]; w.length && !w.at(-1); )
|
417
424
|
w.pop();
|
418
|
-
|
425
|
+
s(this, S).delete(a), this.unlockScroll(a), s(this, _).classList.toggle("_has-drawers-open", !!(s(this, C).length || s(this, A).length)), s(this, _).classList.toggle("_has-non-modals-open", !!s(this, C).length), s(this, _).classList.toggle("_has-modals-open", !!s(this, A).length);
|
419
426
|
};
|
420
|
-
const e =
|
427
|
+
const e = Q(t);
|
421
428
|
if (e === null)
|
422
429
|
throw new Error("Drawer's group root cannot be found");
|
423
|
-
|
424
|
-
const
|
425
|
-
if (
|
430
|
+
m(this, _, e);
|
431
|
+
const l = s(this, _).closest("[data-scrollable], html") || s(this, _).matches("[data-scrollable], html") && s(this, _);
|
432
|
+
if (l === null)
|
426
433
|
throw new Error("Scrollable container for group root cannot be found");
|
427
|
-
|
434
|
+
m(this, B, l);
|
428
435
|
}
|
429
436
|
add(t) {
|
430
437
|
t.on("beforeOpen", this.onBeforeOpen), t.on("closeAnimationEnd", this.onCloseAnimationEnd), t.assignGroup(this);
|
431
438
|
}
|
432
439
|
lockScroll(t) {
|
433
|
-
|
440
|
+
J.lock(s(this, B), t);
|
434
441
|
}
|
435
442
|
unlockScroll(t) {
|
436
|
-
|
443
|
+
J.unlock(s(this, B), t);
|
437
444
|
}
|
438
|
-
}
|
439
|
-
|
440
|
-
|
441
|
-
L = /* @__PURE__ */ new WeakMap();
|
442
|
-
N = /* @__PURE__ */ new WeakMap();
|
443
|
-
P = /* @__PURE__ */ new WeakMap();
|
444
|
-
ce.scrollLock = new je();
|
445
|
-
let se = ce;
|
446
|
-
const Te = class F {
|
445
|
+
}
|
446
|
+
_ = new WeakMap(), A = new WeakMap(), C = new WeakMap(), B = new WeakMap(), S = new WeakMap();
|
447
|
+
const De = class F extends ie {
|
447
448
|
constructor() {
|
448
|
-
if (
|
449
|
+
if (super(), te(this, N, /* @__PURE__ */ new Map()), te(this, $, /* @__PURE__ */ new Map()), F.instance)
|
449
450
|
return F.instance;
|
450
451
|
F.instance = this;
|
451
452
|
}
|
452
|
-
init(t =
|
453
|
-
document.querySelectorAll(`[${K}]`).forEach((
|
454
|
-
const
|
455
|
-
typeof
|
456
|
-
}),
|
457
|
-
var
|
458
|
-
const
|
459
|
-
if (typeof
|
453
|
+
init(t = Y) {
|
454
|
+
this.emit("beforeInit"), document.querySelectorAll(`[${K}]`).forEach((r) => {
|
455
|
+
const o = r.getAttribute(K);
|
456
|
+
typeof o == "string" && T(this, $).set(o, new se(r));
|
457
|
+
}), T(this, $).set("default", new se(document.documentElement)), document.querySelectorAll("[data-drawer]").forEach((r) => {
|
458
|
+
var g;
|
459
|
+
const o = r.getAttribute("data-drawer");
|
460
|
+
if (typeof o != "string")
|
460
461
|
return;
|
461
|
-
const
|
462
|
-
|
463
|
-
const c =
|
462
|
+
const i = new xe({ target: r, options: { ...t, modal: r.matches("[data-modal]") ? r.matches(':not([data-modal="false"]') : t.modal } });
|
463
|
+
T(this, N).set(o, i);
|
464
|
+
const c = r.closest(`[${K}]`), h = c ? c.getAttribute(K) : "default";
|
464
465
|
if (typeof h != "string")
|
465
466
|
throw new Error("Group doesn't have alias set correctly");
|
466
|
-
(
|
467
|
-
}), document.querySelectorAll("[data-drawer-open], [data-drawer-close], [data-drawer-toggle]").forEach((
|
468
|
-
if (
|
469
|
-
const
|
470
|
-
|
471
|
-
const
|
472
|
-
w(
|
473
|
-
} else if (
|
474
|
-
const
|
475
|
-
|
476
|
-
const
|
477
|
-
w(
|
467
|
+
(g = T(this, $).get(h)) == null || g.add(i);
|
468
|
+
}), document.querySelectorAll("[data-drawer-open], [data-drawer-close], [data-drawer-toggle]").forEach((r) => {
|
469
|
+
if (r.hasAttribute("data-drawer-open")) {
|
470
|
+
const o = r.getAttribute("data-drawer-open");
|
471
|
+
v(r, o);
|
472
|
+
const i = this.get(o);
|
473
|
+
w(r, i, o), new V({ target: r, type: "open", owner: i });
|
474
|
+
} else if (r.hasAttribute("data-drawer-close")) {
|
475
|
+
const o = r.getAttribute("data-drawer-close");
|
476
|
+
v(r, o);
|
477
|
+
const i = this.get(o);
|
478
|
+
w(r, i, o), new V({ target: r, type: "close", owner: i });
|
478
479
|
} else {
|
479
|
-
const
|
480
|
-
|
481
|
-
const
|
482
|
-
w(
|
480
|
+
const o = r.getAttribute("data-drawer-toggle");
|
481
|
+
v(r, o);
|
482
|
+
const i = this.get(o);
|
483
|
+
w(r, i, o), new V({ target: r, type: "toggle", owner: i });
|
483
484
|
}
|
484
|
-
});
|
485
|
-
function
|
486
|
-
if (!
|
487
|
-
throw new Error(`Drawer alias should be specified in the trigger attribute. Trigger elem: ${
|
485
|
+
}), this.emit("afterInit");
|
486
|
+
function v(r, o) {
|
487
|
+
if (!o)
|
488
|
+
throw new Error(`Drawer alias should be specified in the trigger attribute. Trigger elem: ${r}`);
|
488
489
|
}
|
489
|
-
function w(
|
490
|
-
if (!
|
491
|
-
throw new Error(`Drawer hasn't been found for the trigger elem: ${
|
490
|
+
function w(r, o, i) {
|
491
|
+
if (!o)
|
492
|
+
throw new Error(`Drawer hasn't been found for the trigger elem: ${r}. Alias: ${i}`);
|
492
493
|
}
|
493
494
|
}
|
494
|
-
open(t, { trigger: e, options:
|
495
|
-
var
|
496
|
-
(
|
495
|
+
open(t, { trigger: e, options: l } = {}) {
|
496
|
+
var a;
|
497
|
+
(a = this.get(t)) == null || a.open(e);
|
497
498
|
}
|
498
|
-
close(t, { trigger: e, options:
|
499
|
-
var
|
500
|
-
(
|
499
|
+
close(t, { trigger: e, options: l } = {}) {
|
500
|
+
var a;
|
501
|
+
(a = this.get(t)) == null || a.close(e);
|
501
502
|
}
|
502
503
|
get(t) {
|
503
|
-
return typeof t == "string" &&
|
504
|
+
return typeof t == "string" && T(this, N).get(t) || null;
|
504
505
|
}
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
(l = this.get(t)) == null || l.on(e, o);
|
509
|
-
else
|
510
|
-
for (const [g, w] of f(this, W))
|
511
|
-
w.on(e, o);
|
506
|
+
globalOn(t, e) {
|
507
|
+
for (const [l, a] of T(this, N))
|
508
|
+
a.on(t, e);
|
512
509
|
}
|
513
510
|
};
|
514
|
-
|
511
|
+
N = /* @__PURE__ */ new WeakMap();
|
515
512
|
$ = /* @__PURE__ */ new WeakMap();
|
516
|
-
let
|
517
|
-
|
513
|
+
let le = De;
|
514
|
+
le.prototype.scrollLock = J;
|
515
|
+
typeof window < "u" && (window.hasOwnProperty("app") || (window.app = {}), window.app.drawers = new le());
|
518
516
|
export {
|
519
517
|
xe as Drawer,
|
520
518
|
se as DrawersGroup,
|
521
|
-
|
522
|
-
|
519
|
+
V as Trigger,
|
520
|
+
le as default,
|
521
|
+
J as scrollLock
|
523
522
|
};
|
package/dist/drawers.umd.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
var
|
1
|
+
var ue=(f,y,k)=>{if(!y.has(f))throw TypeError("Cannot "+k)};var n=(f,y,k)=>(ue(f,y,"read from private field"),k?k.call(f):y.get(f)),v=(f,y,k)=>{if(y.has(f))throw TypeError("Cannot add the same private member more than once");y instanceof WeakSet?y.add(f):y.set(f,k)},g=(f,y,k,G)=>(ue(f,y,"write to private field"),G?G.call(f,k):y.set(f,k),k);(function(f,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(f=typeof globalThis<"u"?globalThis:f||self,y(f.Drawers={}))})(this,function(f){var S,_,z,F,d,W,T,Q,N,x,P,L,C,E,$,D;"use strict";const y="";function k(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var G={exports:{}};(function(s){var t=Object.prototype.hasOwnProperty,e="~";function l(){}Object.create&&(l.prototype=Object.create(null),new l().__proto__||(e=!1));function a(o,i,c){this.fn=o,this.context=i,this.once=c||!1}function A(o,i,c,h,b){if(typeof c!="function")throw new TypeError("The listener must be a function");var O=new a(c,h||o,b),p=e?e+i:i;return o._events[p]?o._events[p].fn?o._events[p]=[o._events[p],O]:o._events[p].push(O):(o._events[p]=O,o._eventsCount++),o}function m(o,i){--o._eventsCount===0?o._events=new l:delete o._events[i]}function r(){this._events=new l,this._eventsCount=0}r.prototype.eventNames=function(){var i=[],c,h;if(this._eventsCount===0)return i;for(h in c=this._events)t.call(c,h)&&i.push(e?h.slice(1):h);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(c)):i},r.prototype.listeners=function(i){var c=e?e+i:i,h=this._events[c];if(!h)return[];if(h.fn)return[h.fn];for(var b=0,O=h.length,p=new Array(O);b<O;b++)p[b]=h[b].fn;return p},r.prototype.listenerCount=function(i){var c=e?e+i:i,h=this._events[c];return h?h.fn?1:h.length:0},r.prototype.emit=function(i,c,h,b,O,p){var M=e?e+i:i;if(!this._events[M])return!1;var u=this._events[M],j=arguments.length,I,w;if(u.fn){switch(u.once&&this.removeListener(i,u.fn,void 0,!0),j){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,c),!0;case 3:return u.fn.call(u.context,c,h),!0;case 4:return u.fn.call(u.context,c,h,b),!0;case 5:return u.fn.call(u.context,c,h,b,O),!0;case 6:return u.fn.call(u.context,c,h,b,O,p),!0}for(w=1,I=new Array(j-1);w<j;w++)I[w-1]=arguments[w];u.fn.apply(u.context,I)}else{var Pe=u.length,H;for(w=0;w<Pe;w++)switch(u[w].once&&this.removeListener(i,u[w].fn,void 0,!0),j){case 1:u[w].fn.call(u[w].context);break;case 2:u[w].fn.call(u[w].context,c);break;case 3:u[w].fn.call(u[w].context,c,h);break;case 4:u[w].fn.call(u[w].context,c,h,b);break;default:if(!I)for(H=1,I=new Array(j-1);H<j;H++)I[H-1]=arguments[H];u[w].fn.apply(u[w].context,I)}}return!0},r.prototype.on=function(i,c,h){return A(this,i,c,h,!1)},r.prototype.once=function(i,c,h){return A(this,i,c,h,!0)},r.prototype.removeListener=function(i,c,h,b){var O=e?e+i:i;if(!this._events[O])return this;if(!c)return m(this,O),this;var p=this._events[O];if(p.fn)p.fn===c&&(!b||p.once)&&(!h||p.context===h)&&m(this,O);else{for(var M=0,u=[],j=p.length;M<j;M++)(p[M].fn!==c||b&&!p[M].once||h&&p[M].context!==h)&&u.push(p[M]);u.length?this._events[O]=u.length===1?u[0]:u:m(this,O)}return this},r.prototype.removeAllListeners=function(i){var c;return i?(c=e?e+i:i,this._events[c]&&m(this,c)):(this._events=new l,this._eventsCount=0),this},r.prototype.off=r.prototype.removeListener,r.prototype.addListener=r.prototype.on,r.prefixed=e,r.EventEmitter=r,s.exports=r})(G);var de=G.exports;const re=k(de);var fe=function(t){return pe(t)&&!we(t)};function pe(s){return!!s&&typeof s=="object"}function we(s){var t=Object.prototype.toString.call(s);return t==="[object RegExp]"||t==="[object Date]"||ye(s)}var me=typeof Symbol=="function"&&Symbol.for,ge=me?Symbol.for("react.element"):60103;function ye(s){return s.$$typeof===ge}function be(s){return Array.isArray(s)?[]:{}}function q(s,t){return t.clone!==!1&&t.isMergeableObject(s)?B(be(s),s,t):s}function ve(s,t,e){return s.concat(t).map(function(l){return q(l,e)})}function Oe(s,t){if(!t.customMerge)return B;var e=t.customMerge(s);return typeof e=="function"?e:B}function Ae(s){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(s).filter(function(t){return Object.propertyIsEnumerable.call(s,t)}):[]}function oe(s){return Object.keys(s).concat(Ae(s))}function ie(s,t){try{return t in s}catch{return!1}}function _e(s,t){return ie(s,t)&&!(Object.hasOwnProperty.call(s,t)&&Object.propertyIsEnumerable.call(s,t))}function Ce(s,t,e){var l={};return e.isMergeableObject(s)&&oe(s).forEach(function(a){l[a]=q(s[a],e)}),oe(t).forEach(function(a){_e(s,a)||(ie(s,a)&&e.isMergeableObject(t[a])?l[a]=Oe(a,e)(s[a],t[a],e):l[a]=q(t[a],e))}),l}function B(s,t,e){e=e||{},e.arrayMerge=e.arrayMerge||ve,e.isMergeableObject=e.isMergeableObject||fe,e.cloneUnlessOtherwiseSpecified=q;var l=Array.isArray(t),a=Array.isArray(s),A=l===a;return A?l?e.arrayMerge(s,t,e):Ce(s,t,e):q(t,e)}B.all=function(t,e){if(!Array.isArray(t))throw new Error("first argument should be an array");return t.reduce(function(l,a){return B(l,a,e)},{})};var Ee=B,ke=Ee;const Le=k(ke);/*!
|
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 ie(n){return Object.prototype.toString.call(n)==="[object Object]"}function je(n){var t,e;return ie(n)===!1?!1:(t=n.constructor,t===void 0?!0:(e=t.prototype,!(ie(e)===!1||e.hasOwnProperty("isPrototypeOf")===!1)))}function Z(n){return n instanceof Element?n:document.querySelector(n)}async function ee(n){return await new Promise(t=>setTimeout(t,n))}var ae=(n,t,e)=>{if(!t.has(n))throw TypeError("Cannot "+e)},f=(n,t,e)=>(ae(n,t,"read from private field"),e?e.call(n):t.get(n)),j=(n,t,e)=>{if(t.has(n))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(n):t.set(n,e)},le=(n,t,e,l)=>(ae(n,t,"write to private field"),l?l.call(n,e):t.set(n,e),e),z,L,M,R,G,B,K;const Te='[data-elem="drawer.panel"]',Y="data-drawers-group",xe=["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^="-"])'],te={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",closingClass:"drawer_closing",openingClass:"drawer_opening",openAnimationDuration:0,closeAnimationDuration:0,lockPageScroll:!0,lockScroll:{unlockDelay:300}};function ce(n){return De.all(n,{isMergeableObject:je})}class J{constructor({target:t,type:e,owner:l}){E(this,k,void 0);E(this,_,void 0);E(this,N,void 0);E(this,F,!1);const a=Z(t);if(!a)throw new Error("Trigger element cannot be found");if(!l)throw new Error("Owning drawer instance hasn't been provided");C(this,k,a),C(this,_,l),C(this,N,e),this.init()}get isActive(){return r(this,F)}get owner(){return r(this,_)}init(){r(this,k).addEventListener("click",t=>this.clickHandler(t)),r(this,_).on("open",()=>this.setActive(!0)),r(this,_).on("close",()=>this.setActive(!1))}clickHandler(t){t.__drawerTrigger=this,r(this,N)==="open"?r(this,_).isOpen||r(this,_).open(r(this,k)):r(this,N)==="close"?r(this,_).isOpen&&r(this,_).close(r(this,k)):r(this,_).isOpen?r(this,_).close(r(this,k)):r(this,_).open(r(this,k))}setActive(t){C(this,F,t),t?r(this,k).classList.add("drawer-trigger_active"):r(this,k).classList.remove("drawer-trigger_active")}}k=new WeakMap,_=new WeakMap,N=new WeakMap,F=new WeakMap;class he extends we{constructor({target:e,options:l}){super();E(this,d,void 0);E(this,H,void 0);E(this,T,void 0);E(this,Q,void 0);E(this,W,void 0);this.handleDocumentClick=async s=>{var c;if(((c=s.__drawerTrigger)==null?void 0:c.owner)===this)return;const o=s.target;if(s.composedPath(),this.dom.panel.contains(o))return;const i=o==null?void 0:o.closest("[data-drawer]");i?i.getAttribute("data-drawer")===r(this,W)?this.handleUnderlayClick(s):this.handleOtherDrawerClick(s):this.handleOutsideClick(s)},this.handleKeydown=s=>{r(this,d).closeOnEsc&&s.key==="Escape"&&this.close()};const a=ce(l?[te,l]:[te]),b=Z(e);if(b===null)throw new Error("Drawer's root cannot be found");C(this,W,b.getAttribute("data-drawer"));const m=b.querySelector(Te);if(m===null)throw new Error(`Drawer's panel cannot be found. Alias: ${r(this,W)}`);this.dom={root:b,panel:m},this.setOptions(a),this.dom.panel.setAttribute("tabindex","-1"),this.dom.root.classList.add("drawer_initialized")}addEventListeners(){this.dom.root.addEventListener("keydown",this.handleKeydown),document.addEventListener("click",this.handleDocumentClick)}removeEventListeners(){this.dom.root.removeEventListener("keydown",this.handleKeydown),document.removeEventListener("click",this.handleDocumentClick)}get scrollUnlockDelay(){var e;return((e=r(this,d).lockScroll)==null?void 0:e.unlockDelay)||0}get isOpen(){return r(this,T)}get isModal(){return r(this,d).modal}set isModal(e){this.dom.root.classList[e?"add":"remove"]("drawer_modal")}get willLockScroll(){return r(this,d).lockPageScroll}set zIndex(e){this.dom.root.style.setProperty("--z-index",String(e)),C(this,H,e)}get zIndex(){return r(this,H)}async open(e){await ee(0),!r(this,T)&&(this.emit("beforeOpen",{drawer:this,trigger:e}),C(this,T,!0),this.dom.root.classList.add(r(this,d).openingClass),this.emit("open",{drawer:this,trigger:e}),typeof r(this,d).openAnimationDuration=="number"&&await ee(r(this,d).openAnimationDuration),this.dom.root.classList.remove(r(this,d).openingClass),this.dom.root.classList.add(r(this,d).openClass),this.emit("openAnimationEnd",{drawer:this,trigger:e}),this.focus(),this.addEventListeners())}async close(e){r(this,d).onCloseConfirm&&!r(this,d).onCloseConfirm(this,e)||(this.emit("beforeClose",{drawer:this,trigger:e}),this.removeEventListeners(),C(this,T,!1),this.dom.root.classList.remove(r(this,d).openClass),this.dom.root.classList.add(r(this,d).closingClass),this.emit("close",{drawer:this,trigger:e}),typeof r(this,d).closeAnimationDuration=="number"&&await ee(r(this,d).closeAnimationDuration),this.dom.root.classList.remove(r(this,d).closingClass),this.emit("closeAnimationEnd",{drawer:this,trigger:e}))}handleOtherDrawerClick(e){}handleOutsideClick(e){r(this,d).closeOnOutsideClick&&(typeof r(this,d).closeOnOutsideClick=="object"&&r(this,d).closeOnOutsideClick.hasOwnProperty("checkTarget")?r(this,d).closeOnOutsideClick.checkTarget(e.target)&&this.close():this.close())}handleUnderlayClick(e){r(this,d).closeOnOutsideClick&&this.close()}focus(){r(this,d).focusOnChild&&this.focusChild()||this.focusSelf()}focusSelf(){this.dom.panel.focus()}focusChild(){const e=this.dom.panel.querySelector(xe.join(","));return e?(e.focus(),!0):!1}setOptions(e){var l;e.hasOwnProperty("modal")&&((l=r(this,d))==null?void 0:l.modal)!==e.modal&&(this.isModal=e.modal),C(this,d,r(this,d)?ce([r(this,d),e]):e)}assignGroup(e){C(this,Q,e)}}d=new WeakMap,H=new WeakMap,T=new WeakMap,Q=new WeakMap,W=new WeakMap;class Pe{constructor(){E(this,x,null);E(this,P,new Map)}lock(t,e){r(this,x)!==null&&(clearTimeout(r(this,x)),C(this,x,null)),r(this,P).has(t)||r(this,P).set(t,new Set);const l=r(this,P).get(t);l.size===0&&t.classList.add("scroll-lock-by-drawer"),l.add(e)}unlock(t,e){const l=r(this,P).get(t);l==null||l.delete(e),(!l||l.size===0)&&C(this,x,setTimeout(()=>t.classList.remove("scroll-lock-by-drawer"),e.scrollUnlockDelay))}}x=new WeakMap,P=new WeakMap;const ue=class re{constructor(t){j(this,z,void 0),j(this,L,[]),j(this,M,[]),j(this,R,void 0),j(this,G,new Map),this.onBeforeOpen=({drawer:a,trigger:b})=>{a.isModal?(f(this,G).set(a,f(this,L).length),f(this,L).push(a),a.zIndex=f(this,M).length+f(this,L).length):(f(this,G).set(a,f(this,M).length),f(this,M).push(a),a.zIndex=f(this,M).length,f(this,L).length>0&&f(this,L).forEach((m,s)=>m.zIndex=f(this,M).length+s+1)),a.willLockScroll&&this.lockScroll(a)},this.onCloseAnimationEnd=({drawer:a,trigger:b})=>{const m=a.isModal?f(this,L):f(this,M);for(delete m[f(this,G).get(a)];m.length&&!m.at(-1);)m.pop();f(this,G).delete(a),this.unlockScroll(a)};const e=Z(t);if(e===null)throw new Error("Drawer's group root cannot be found");le(this,z,e);const l=f(this,z).closest("[data-scrollable], html")||f(this,z).matches("[data-scrollable], html")&&f(this,z);if(l===null)throw new Error("Scrollable container for group root cannot be found");le(this,R,l)}add(t){t.on("beforeOpen",this.onBeforeOpen),t.on("closeAnimationEnd",this.onCloseAnimationEnd),t.assignGroup(this)}lockScroll(t){re.scrollLock.lock(f(this,R),t)}unlockScroll(t){re.scrollLock.unlock(f(this,R),t)}};z=new WeakMap,L=new WeakMap,M=new WeakMap,R=new WeakMap,G=new WeakMap,ue.scrollLock=new Pe;let ne=ue;const Ie=class X{constructor(){if(j(this,B,new Map),j(this,K,new Map),X.instance)return X.instance;X.instance=this}init(t=te){document.querySelectorAll(`[${Y}]`).forEach(s=>{const o=s.getAttribute(Y);typeof o=="string"&&f(this,K).set(o,new ne(s))}),f(this,K).set("default",new ne(document.documentElement)),document.querySelectorAll("[data-drawer]").forEach(s=>{var v;const o=s.getAttribute("data-drawer");if(typeof o!="string")return;const i=new he({target:s,options:{...t,modal:s.matches("[data-modal]")?s.matches(':not([data-modal="false"]'):t.modal}});f(this,B).set(o,i);const c=s.closest(`[${Y}]`),h=c?c.getAttribute(Y):"default";if(typeof h!="string")throw new Error("Group doesn't have alias set correctly");(v=f(this,K).get(h))==null||v.add(i)}),document.querySelectorAll("[data-drawer-open], [data-drawer-close], [data-drawer-toggle]").forEach(s=>{if(s.hasAttribute("data-drawer-open")){const o=s.getAttribute("data-drawer-open");b(s,o);const i=this.get(o);m(s,i,o),new J({target:s,type:"open",owner:i})}else if(s.hasAttribute("data-drawer-close")){const o=s.getAttribute("data-drawer-close");b(s,o);const i=this.get(o);m(s,i,o),new J({target:s,type:"close",owner:i})}else{const o=s.getAttribute("data-drawer-toggle");b(s,o);const i=this.get(o);m(s,i,o),new J({target:s,type:"toggle",owner:i})}});function b(s,o){if(!o)throw new Error(`Drawer alias should be specified in the trigger attribute. Trigger elem: ${s}`)}function m(s,o,i){if(!o)throw new Error(`Drawer hasn't been found for the trigger elem: ${s}. Alias: ${i}`)}}open(t,{trigger:e,options:l}={}){var a;(a=this.get(t))==null||a.open(e)}close(t,{trigger:e,options:l}={}){var a;(a=this.get(t))==null||a.close(e)}get(t){return typeof t=="string"&&f(this,B).get(t)||null}on(t,e,l){var a;if(t)(a=this.get(t))==null||a.on(e,l);else for(const[b,m]of f(this,B))m.on(e,l)}};B=new WeakMap,K=new WeakMap;let de=Ie;typeof window<"u"&&(window.hasOwnProperty("app")||(window.app={}),window.app.drawers=new de),p.Drawer=he,p.DrawersGroup=ne,p.Trigger=J,p.default=de,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
6
|
+
*/function ae(s){return Object.prototype.toString.call(s)==="[object Object]"}function Se(s){var t,e;return ae(s)===!1?!1:(t=s.constructor,t===void 0?!0:(e=t.prototype,!(ae(e)===!1||e.hasOwnProperty("isPrototypeOf")===!1)))}function Z(s){return s instanceof Element?s:document.querySelector(s)}async function ee(s){return await new Promise(t=>setTimeout(t,s))}var Me=(s,t,e)=>{if(!t.has(s))throw TypeError("Cannot "+e)},U=(s,t,e)=>(Me(s,t,"read from private field"),e?e.call(s):t.get(s)),le=(s,t,e)=>{if(t.has(s))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(s):t.set(s,e)},R,K;const De='[data-elem="drawer.panel"]',V="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^="-"])'],te={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",closingClass:"drawer_closing",openingClass:"drawer_opening",openAnimationDuration:0,closeAnimationDuration:0,lockPageScroll:!0,lockScroll:{unlockDelay:300}};function ce(s){return Le.all(s,{isMergeableObject:Se})}class Y{constructor({target:t,type:e,owner:l}){v(this,S,void 0);v(this,_,void 0);v(this,z,void 0);v(this,F,!1);const a=Z(t);if(!a)throw new Error("Trigger element cannot be found");if(!l)throw new Error("Owning drawer instance hasn't been provided");g(this,S,a),g(this,_,l),g(this,z,e),this.init()}get isActive(){return n(this,F)}get owner(){return n(this,_)}init(){n(this,S).addEventListener("click",t=>this.clickHandler(t)),n(this,_).on("open",()=>this.setActive(!0)),n(this,_).on("close",()=>this.setActive(!1))}clickHandler(t){t.__drawerTrigger=this,n(this,z)==="open"?n(this,_).isOpen||n(this,_).open(n(this,S)):n(this,z)==="close"?n(this,_).isOpen&&n(this,_).close(n(this,S)):n(this,_).isOpen?n(this,_).close(n(this,S)):n(this,_).open(n(this,S))}setActive(t){g(this,F,t),t?n(this,S).classList.add("drawer-trigger_active"):n(this,S).classList.remove("drawer-trigger_active")}}S=new WeakMap,_=new WeakMap,z=new WeakMap,F=new WeakMap;class he extends re{constructor({target:e,options:l}){super();v(this,d,void 0);v(this,W,void 0);v(this,T,void 0);v(this,Q,void 0);v(this,N,void 0);this.handleDocumentClick=async r=>{var c;if(((c=r.__drawerTrigger)==null?void 0:c.owner)===this)return;const o=r.target;if(r.composedPath(),this.dom.panel.contains(o))return;const i=o==null?void 0:o.closest("[data-drawer]");i?i.getAttribute("data-drawer")===n(this,N)?this.handleUnderlayClick(r):this.handleOtherDrawerClick(r):this.handleOutsideClick(r)},this.handleKeydown=r=>{n(this,d).closeOnEsc&&r.key==="Escape"&&this.close()};const a=ce(l?[te,l]:[te]),A=Z(e);if(A===null)throw new Error("Drawer's root cannot be found");g(this,N,A.getAttribute("data-drawer"));const m=A.querySelector(De);if(m===null)throw new Error(`Drawer's panel cannot be found. Alias: ${n(this,N)}`);this.dom={root:A,panel:m},this.setOptions(a),this.dom.panel.setAttribute("tabindex","-1"),this.dom.root.classList.add("drawer_initialized")}addEventListeners(){this.dom.root.addEventListener("keydown",this.handleKeydown),document.addEventListener("click",this.handleDocumentClick)}removeEventListeners(){this.dom.root.removeEventListener("keydown",this.handleKeydown),document.removeEventListener("click",this.handleDocumentClick)}get scrollUnlockDelay(){var e;return((e=n(this,d).lockScroll)==null?void 0:e.unlockDelay)||0}get isOpen(){return n(this,T)}get isModal(){return n(this,d).modal}set isModal(e){this.dom.root.classList[e?"add":"remove"]("drawer_modal")}get willLockScroll(){return n(this,d).lockPageScroll}set zIndex(e){this.dom.root.style.setProperty("--z-index",String(e)),g(this,W,e)}get zIndex(){return n(this,W)}async open(e){await ee(0),!n(this,T)&&(this.emit("beforeOpen",{drawer:this,trigger:e}),g(this,T,!0),this.dom.root.classList.add(n(this,d).openingClass),this.emit("open",{drawer:this,trigger:e}),typeof n(this,d).openAnimationDuration=="number"&&await ee(n(this,d).openAnimationDuration),this.dom.root.classList.remove(n(this,d).openingClass),this.dom.root.classList.add(n(this,d).openClass),this.emit("openAnimationEnd",{drawer:this,trigger:e}),this.focus(),this.addEventListeners())}async close(e){n(this,d).onCloseConfirm&&!n(this,d).onCloseConfirm(this,e)||(this.emit("beforeClose",{drawer:this,trigger:e}),this.removeEventListeners(),g(this,T,!1),this.dom.root.classList.remove(n(this,d).openClass),this.dom.root.classList.add(n(this,d).closingClass),this.emit("close",{drawer:this,trigger:e}),typeof n(this,d).closeAnimationDuration=="number"&&await ee(n(this,d).closeAnimationDuration),this.dom.root.classList.remove(n(this,d).closingClass),this.emit("closeAnimationEnd",{drawer:this,trigger:e}))}handleOtherDrawerClick(e){}handleOutsideClick(e){n(this,d).closeOnOutsideClick&&(typeof n(this,d).closeOnOutsideClick=="object"&&n(this,d).closeOnOutsideClick.hasOwnProperty("checkTarget")?n(this,d).closeOnOutsideClick.checkTarget(e.target)&&this.close():this.close())}handleUnderlayClick(e){n(this,d).closeOnOutsideClick&&this.close()}focus(){n(this,d).focusOnChild&&this.focusChild()||this.focusSelf()}focusSelf(){this.dom.panel.focus()}focusChild(){const e=this.dom.panel.querySelector(je.join(","));return e?(e.focus(),!0):!1}setOptions(e){var l;e.hasOwnProperty("modal")&&((l=n(this,d))==null?void 0:l.modal)!==e.modal&&(this.isModal=e.modal),g(this,d,n(this,d)?ce([n(this,d),e]):e)}assignGroup(e){g(this,Q,e)}}d=new WeakMap,W=new WeakMap,T=new WeakMap,Q=new WeakMap,N=new WeakMap;class Te{constructor(){v(this,x,null);v(this,P,new Map)}lock(t,e){n(this,x)!==null&&(clearTimeout(n(this,x)),g(this,x,null)),n(this,P).has(t)||n(this,P).set(t,new Set);const l=n(this,P).get(t);l.size===0&&t.classList.add("scroll-lock-by-drawer"),l.add(e)}unlock(t,e){const l=n(this,P).get(t);l==null||l.delete(e),(!l||l.size===0)&&g(this,x,setTimeout(()=>t.classList.remove("scroll-lock-by-drawer"),e.scrollUnlockDelay))}}x=new WeakMap,P=new WeakMap;const J=new Te;class ne{constructor(t){v(this,L,void 0);v(this,C,void 0);v(this,E,void 0);v(this,$,void 0);v(this,D,void 0);g(this,C,[]),g(this,E,[]),g(this,D,new Map),this.onBeforeOpen=({drawer:a,trigger:A})=>{a.isModal?(n(this,D).set(a,n(this,C).length),n(this,C).push(a),a.zIndex=n(this,E).length+n(this,C).length):(n(this,D).set(a,n(this,E).length),n(this,E).push(a),a.zIndex=n(this,E).length,n(this,C).length>0&&n(this,C).forEach((m,r)=>m.zIndex=n(this,E).length+r+1)),n(this,L).classList.toggle("_has-drawers-open",!!(n(this,E).length||n(this,C).length)),n(this,L).classList.toggle("_has-non-modals-open",!!n(this,E).length),n(this,L).classList.toggle("_has-modals-open",!!n(this,C).length),a.willLockScroll&&this.lockScroll(a)},this.onCloseAnimationEnd=({drawer:a,trigger:A})=>{const m=a.isModal?n(this,C):n(this,E);for(delete m[n(this,D).get(a)];m.length&&!m.at(-1);)m.pop();n(this,D).delete(a),this.unlockScroll(a),n(this,L).classList.toggle("_has-drawers-open",!!(n(this,E).length||n(this,C).length)),n(this,L).classList.toggle("_has-non-modals-open",!!n(this,E).length),n(this,L).classList.toggle("_has-modals-open",!!n(this,C).length)};const e=Z(t);if(e===null)throw new Error("Drawer's group root cannot be found");g(this,L,e);const l=n(this,L).closest("[data-scrollable], html")||n(this,L).matches("[data-scrollable], html")&&n(this,L);if(l===null)throw new Error("Scrollable container for group root cannot be found");g(this,$,l)}add(t){t.on("beforeOpen",this.onBeforeOpen),t.on("closeAnimationEnd",this.onCloseAnimationEnd),t.assignGroup(this)}lockScroll(t){J.lock(n(this,$),t)}unlockScroll(t){J.unlock(n(this,$),t)}}L=new WeakMap,C=new WeakMap,E=new WeakMap,$=new WeakMap,D=new WeakMap;const xe=class X extends re{constructor(){if(super(),le(this,R,new Map),le(this,K,new Map),X.instance)return X.instance;X.instance=this}init(t=te){this.emit("beforeInit"),document.querySelectorAll(`[${V}]`).forEach(r=>{const o=r.getAttribute(V);typeof o=="string"&&U(this,K).set(o,new ne(r))}),U(this,K).set("default",new ne(document.documentElement)),document.querySelectorAll("[data-drawer]").forEach(r=>{var b;const o=r.getAttribute("data-drawer");if(typeof o!="string")return;const i=new he({target:r,options:{...t,modal:r.matches("[data-modal]")?r.matches(':not([data-modal="false"]'):t.modal}});U(this,R).set(o,i);const c=r.closest(`[${V}]`),h=c?c.getAttribute(V):"default";if(typeof h!="string")throw new Error("Group doesn't have alias set correctly");(b=U(this,K).get(h))==null||b.add(i)}),document.querySelectorAll("[data-drawer-open], [data-drawer-close], [data-drawer-toggle]").forEach(r=>{if(r.hasAttribute("data-drawer-open")){const o=r.getAttribute("data-drawer-open");A(r,o);const i=this.get(o);m(r,i,o),new Y({target:r,type:"open",owner:i})}else if(r.hasAttribute("data-drawer-close")){const o=r.getAttribute("data-drawer-close");A(r,o);const i=this.get(o);m(r,i,o),new Y({target:r,type:"close",owner:i})}else{const o=r.getAttribute("data-drawer-toggle");A(r,o);const i=this.get(o);m(r,i,o),new Y({target:r,type:"toggle",owner:i})}}),this.emit("afterInit");function A(r,o){if(!o)throw new Error(`Drawer alias should be specified in the trigger attribute. Trigger elem: ${r}`)}function m(r,o,i){if(!o)throw new Error(`Drawer hasn't been found for the trigger elem: ${r}. Alias: ${i}`)}}open(t,{trigger:e,options:l}={}){var a;(a=this.get(t))==null||a.open(e)}close(t,{trigger:e,options:l}={}){var a;(a=this.get(t))==null||a.close(e)}get(t){return typeof t=="string"&&U(this,R).get(t)||null}globalOn(t,e){for(const[l,a]of U(this,R))a.on(t,e)}};R=new WeakMap,K=new WeakMap;let se=xe;se.prototype.scrollLock=J,typeof window<"u"&&(window.hasOwnProperty("app")||(window.app={}),window.app.drawers=new se),f.Drawer=he,f.DrawersGroup=ne,f.Trigger=Y,f.default=se,f.scrollLock=J,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|