vanilla-drawers 1.0.5 → 1.0.6
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/drawers.es.js +51 -50
- package/dist/drawers.umd.js +2 -2
- package/package.json +48 -48
package/dist/drawers.es.js
CHANGED
@@ -74,7 +74,7 @@ var ne = { exports: {} };
|
|
74
74
|
k[y - 1] = arguments[y];
|
75
75
|
a.fn.apply(a.context, k);
|
76
76
|
} else {
|
77
|
-
var se = a.length,
|
77
|
+
var se = a.length, z;
|
78
78
|
for (y = 0; y < se; y++)
|
79
79
|
switch (a[y].once && this.removeListener(i, a[y].fn, void 0, !0), S) {
|
80
80
|
case 1:
|
@@ -91,8 +91,8 @@ var ne = { exports: {} };
|
|
91
91
|
break;
|
92
92
|
default:
|
93
93
|
if (!k)
|
94
|
-
for (
|
95
|
-
k[
|
94
|
+
for (z = 1, k = new Array(S - 1); z < S; z++)
|
95
|
+
k[z - 1] = arguments[z];
|
96
96
|
a[y].fn.apply(a[y].context, k);
|
97
97
|
}
|
98
98
|
}
|
@@ -140,19 +140,19 @@ function fe(r) {
|
|
140
140
|
function de(r) {
|
141
141
|
return Array.isArray(r) ? [] : {};
|
142
142
|
}
|
143
|
-
function
|
144
|
-
return t.clone !== !1 && t.isMergeableObject(r) ?
|
143
|
+
function N(r, t) {
|
144
|
+
return t.clone !== !1 && t.isMergeableObject(r) ? I(de(r), r, t) : r;
|
145
145
|
}
|
146
146
|
function pe(r, t, e) {
|
147
147
|
return r.concat(t).map(function(l) {
|
148
|
-
return
|
148
|
+
return N(l, e);
|
149
149
|
});
|
150
150
|
}
|
151
151
|
function we(r, t) {
|
152
152
|
if (!t.customMerge)
|
153
|
-
return
|
153
|
+
return I;
|
154
154
|
var e = t.customMerge(r);
|
155
|
-
return typeof e == "function" ? e :
|
155
|
+
return typeof e == "function" ? e : I;
|
156
156
|
}
|
157
157
|
function ye(r) {
|
158
158
|
return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(r).filter(function(t) {
|
@@ -175,24 +175,24 @@ function be(r, t) {
|
|
175
175
|
function me(r, t, e) {
|
176
176
|
var l = {};
|
177
177
|
return e.isMergeableObject(r) && W(r).forEach(function(s) {
|
178
|
-
l[s] =
|
178
|
+
l[s] = N(r[s], e);
|
179
179
|
}), W(t).forEach(function(s) {
|
180
|
-
be(r, s) || (re(r, s) && e.isMergeableObject(t[s]) ? l[s] = we(s, e)(r[s], t[s], e) : l[s] =
|
180
|
+
be(r, s) || (re(r, s) && e.isMergeableObject(t[s]) ? l[s] = we(s, e)(r[s], t[s], e) : l[s] = N(t[s], e));
|
181
181
|
}), l;
|
182
182
|
}
|
183
|
-
function
|
184
|
-
e = e || {}, e.arrayMerge = e.arrayMerge || pe, e.isMergeableObject = e.isMergeableObject || ae, e.cloneUnlessOtherwiseSpecified =
|
183
|
+
function I(r, t, e) {
|
184
|
+
e = e || {}, e.arrayMerge = e.arrayMerge || pe, e.isMergeableObject = e.isMergeableObject || ae, e.cloneUnlessOtherwiseSpecified = N;
|
185
185
|
var l = Array.isArray(t), s = Array.isArray(r), f = l === s;
|
186
|
-
return f ? l ? e.arrayMerge(r, t, e) : me(r, t, e) :
|
186
|
+
return f ? l ? e.arrayMerge(r, t, e) : me(r, t, e) : N(t, e);
|
187
187
|
}
|
188
|
-
|
188
|
+
I.all = function(t, e) {
|
189
189
|
if (!Array.isArray(t))
|
190
190
|
throw new Error("first argument should be an array");
|
191
191
|
return t.reduce(function(l, s) {
|
192
|
-
return
|
192
|
+
return I(l, s, e);
|
193
193
|
}, {});
|
194
194
|
};
|
195
|
-
var ge =
|
195
|
+
var ge = I, Oe = ge;
|
196
196
|
const ve = /* @__PURE__ */ te(Oe);
|
197
197
|
/*!
|
198
198
|
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
@@ -213,7 +213,7 @@ function J(r) {
|
|
213
213
|
async function H(r) {
|
214
214
|
return await new Promise((t) => setTimeout(t, r));
|
215
215
|
}
|
216
|
-
const Ee = '[data-elem="drawer.panel"]',
|
216
|
+
const Ee = '[data-elem="drawer.panel"]', K = "data-drawers-group", Ce = [
|
217
217
|
"a[href]",
|
218
218
|
"area[href]",
|
219
219
|
'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',
|
@@ -248,13 +248,13 @@ function ee(r) {
|
|
248
248
|
isMergeableObject: Ae
|
249
249
|
});
|
250
250
|
}
|
251
|
-
var E, A, P,
|
251
|
+
var E, A, P, q;
|
252
252
|
class V {
|
253
253
|
constructor({ target: t, type: e, owner: l }) {
|
254
254
|
b(this, E, void 0);
|
255
255
|
b(this, A, void 0);
|
256
256
|
b(this, P, void 0);
|
257
|
-
b(this,
|
257
|
+
b(this, q, !1);
|
258
258
|
const s = J(t);
|
259
259
|
if (!s)
|
260
260
|
throw new Error("Trigger element cannot be found");
|
@@ -262,7 +262,7 @@ class V {
|
|
262
262
|
}
|
263
263
|
// Accessors
|
264
264
|
get isActive() {
|
265
|
-
return n(this,
|
265
|
+
return n(this, q);
|
266
266
|
}
|
267
267
|
get owner() {
|
268
268
|
return n(this, A);
|
@@ -275,20 +275,20 @@ class V {
|
|
275
275
|
t.__drawerTrigger = this, n(this, P) === "open" ? n(this, A).isOpen || n(this, A).open(n(this, E)) : n(this, P) === "close" ? n(this, A).isOpen && n(this, A).close(n(this, E)) : n(this, A).isOpen ? n(this, A).close(n(this, E)) : n(this, A).open(n(this, E));
|
276
276
|
}
|
277
277
|
setActive(t) {
|
278
|
-
m(this,
|
278
|
+
m(this, q, t), t ? n(this, E).classList.add("drawer-trigger_active") : n(this, E).classList.remove("drawer-trigger_active");
|
279
279
|
}
|
280
280
|
}
|
281
|
-
E = new WeakMap(), A = new WeakMap(), P = new WeakMap(),
|
282
|
-
var p,
|
281
|
+
E = new WeakMap(), A = new WeakMap(), P = new WeakMap(), q = new WeakMap();
|
282
|
+
var p, R, O, x, F, T;
|
283
283
|
class _e extends oe {
|
284
284
|
constructor({ target: e, options: l }) {
|
285
285
|
super();
|
286
286
|
b(this, p, void 0);
|
287
|
-
b(this,
|
287
|
+
b(this, R, void 0);
|
288
288
|
b(this, O, void 0);
|
289
289
|
b(this, x, void 0);
|
290
290
|
b(this, F, void 0);
|
291
|
-
b(this,
|
291
|
+
b(this, T, void 0);
|
292
292
|
this.handleDocumentClick = async (u) => {
|
293
293
|
var o;
|
294
294
|
if (((o = u.__drawerTrigger) == null ? void 0 : o.owner) === this)
|
@@ -297,20 +297,21 @@ class _e extends oe {
|
|
297
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") === n(this,
|
300
|
+
i ? i.getAttribute("data-drawer") === n(this, T) ? 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
304
|
const s = ee(l ? [Z, l] : [Z]), f = J(e);
|
305
305
|
if (f === null)
|
306
306
|
throw new Error("Drawer's root cannot be found");
|
307
|
+
m(this, T, f.getAttribute("data-drawer"));
|
307
308
|
const d = f.querySelector(Ee);
|
308
309
|
if (d === null)
|
309
|
-
throw new Error(
|
310
|
+
throw new Error(`Drawer's panel cannot be found. Alias: ${n(this, T)}`);
|
310
311
|
m(this, O, {
|
311
312
|
root: f,
|
312
313
|
panel: d
|
313
|
-
}),
|
314
|
+
}), this.setOptions(s), n(this, O).panel.setAttribute("tabindex", "-1"), n(this, O).root.classList.add("drawer_initialized");
|
314
315
|
}
|
315
316
|
addEventListeners() {
|
316
317
|
n(this, O).root.addEventListener("keydown", this.handleKeydown), document.addEventListener("click", this.handleDocumentClick);
|
@@ -329,10 +330,10 @@ class _e extends oe {
|
|
329
330
|
n(this, O).root.classList[e ? "add" : "remove"]("drawer_modal");
|
330
331
|
}
|
331
332
|
set zIndex(e) {
|
332
|
-
n(this, O).root.style.setProperty("--z-index", String(e)), m(this,
|
333
|
+
n(this, O).root.style.setProperty("--z-index", String(e)), m(this, R, e);
|
333
334
|
}
|
334
335
|
get zIndex() {
|
335
|
-
return n(this,
|
336
|
+
return n(this, R);
|
336
337
|
}
|
337
338
|
// Methods
|
338
339
|
async open(e) {
|
@@ -367,14 +368,14 @@ class _e extends oe {
|
|
367
368
|
m(this, F, e);
|
368
369
|
}
|
369
370
|
}
|
370
|
-
p = new WeakMap(),
|
371
|
-
var B, C, _,
|
371
|
+
p = new WeakMap(), R = new WeakMap(), O = new WeakMap(), x = new WeakMap(), F = new WeakMap(), T = new WeakMap();
|
372
|
+
var B, C, _, D, L, M;
|
372
373
|
class je {
|
373
374
|
constructor(t) {
|
374
375
|
b(this, B, void 0);
|
375
376
|
b(this, C, void 0);
|
376
377
|
b(this, _, void 0);
|
377
|
-
b(this,
|
378
|
+
b(this, D, void 0);
|
378
379
|
b(this, L, void 0);
|
379
380
|
b(this, M, void 0);
|
380
381
|
m(this, C, []), m(this, _, []), m(this, L, /* @__PURE__ */ new Set()), m(this, M, /* @__PURE__ */ new Map()), this.onBeforeOpen = ({ drawer: s, trigger: f }) => {
|
@@ -392,32 +393,32 @@ class je {
|
|
392
393
|
const l = n(this, B).closest("[data-scrollable], html");
|
393
394
|
if (l === null)
|
394
395
|
throw new Error("Scrollable container for group root cannot be found");
|
395
|
-
m(this,
|
396
|
+
m(this, D, l);
|
396
397
|
}
|
397
398
|
add(t) {
|
398
399
|
t.on("beforeOpen", this.onBeforeOpen), t.on("closeAnimationEnd", this.onCloseAnimationEnd), t.assignGroup(this);
|
399
400
|
}
|
400
401
|
lockScroll(t) {
|
401
|
-
n(this, L).size === 0 && n(this,
|
402
|
+
n(this, L).size === 0 && n(this, D).classList.add("scroll-lock-by-drawer"), n(this, L).add(t);
|
402
403
|
}
|
403
404
|
unlockScroll(t) {
|
404
|
-
n(this, L).delete(t), n(this, L).size === 0 && n(this,
|
405
|
+
n(this, L).delete(t), n(this, L).size === 0 && n(this, D).classList.remove("scroll-lock-by-drawer");
|
405
406
|
}
|
406
407
|
}
|
407
|
-
B = new WeakMap(), C = new WeakMap(), _ = new WeakMap(),
|
408
|
-
var G,
|
409
|
-
const
|
408
|
+
B = new WeakMap(), C = new WeakMap(), _ = new WeakMap(), D = new WeakMap(), L = new WeakMap(), M = new WeakMap();
|
409
|
+
var G, $;
|
410
|
+
const U = class U {
|
410
411
|
constructor() {
|
411
412
|
b(this, G, /* @__PURE__ */ new Map());
|
412
|
-
b(this,
|
413
|
-
if (
|
414
|
-
return
|
415
|
-
|
413
|
+
b(this, $, /* @__PURE__ */ new Map());
|
414
|
+
if (U.instance)
|
415
|
+
return U.instance;
|
416
|
+
U.instance = this;
|
416
417
|
}
|
417
418
|
init(t) {
|
418
|
-
document.querySelectorAll(`[${
|
419
|
-
const d = f.getAttribute(
|
420
|
-
typeof d == "string" && n(this,
|
419
|
+
document.querySelectorAll(`[${K}]`).forEach((f) => {
|
420
|
+
const d = f.getAttribute(K);
|
421
|
+
typeof d == "string" && n(this, $).set(d, new je(f));
|
421
422
|
}), document.querySelectorAll("[data-drawer]").forEach((f) => {
|
422
423
|
var o;
|
423
424
|
const d = f.getAttribute("data-drawer");
|
@@ -425,10 +426,10 @@ const z = class z {
|
|
425
426
|
return;
|
426
427
|
const u = new _e({ target: f, options: t });
|
427
428
|
n(this, G).set(d, u);
|
428
|
-
const h = f.closest(`[${
|
429
|
+
const h = f.closest(`[${K}]`), i = h == null ? void 0 : h.getAttribute(K);
|
429
430
|
if (typeof i != "string")
|
430
431
|
throw new Error("Group doesn't have alias set correctly");
|
431
|
-
(o = n(this,
|
432
|
+
(o = n(this, $).get(i)) == null || o.add(u);
|
432
433
|
}), document.querySelectorAll("[data-drawer-open], [data-drawer-close], [data-drawer-toggle]").forEach((f) => {
|
433
434
|
if (f.hasAttribute("data-drawer-open")) {
|
434
435
|
const d = f.getAttribute("data-drawer-open");
|
@@ -454,8 +455,8 @@ const z = class z {
|
|
454
455
|
return typeof t == "string" && n(this, G).get(t) || null;
|
455
456
|
}
|
456
457
|
};
|
457
|
-
G = new WeakMap(),
|
458
|
-
let Y =
|
458
|
+
G = new WeakMap(), $ = new WeakMap();
|
459
|
+
let Y = U;
|
459
460
|
typeof window < "u" && (window.hasOwnProperty("app") || (window.app = {}), window.app.drawers = new Y());
|
460
461
|
export {
|
461
462
|
_e as Drawer,
|
package/dist/drawers.umd.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
(function(p,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(p=typeof globalThis<"u"?globalThis:p||self,m(p.Drawers={}))})(this,function(p){"use strict";var ae=(p,m,_)=>{if(!m.has(p))throw TypeError("Cannot "+_)};var t=(p,m,_)=>(ae(p,m,"read from private field"),_?_.call(p):m.get(p)),g=(p,m,_)=>{if(m.has(p))throw TypeError("Cannot add the same private member more than once");m instanceof WeakSet?m.add(p):m.set(p,_)},O=(p,m,_,V)=>(ae(p,m,"write to private field"),V?V.call(p,_):m.set(p,_),_);var j,E,z,
|
1
|
+
(function(p,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(p=typeof globalThis<"u"?globalThis:p||self,m(p.Drawers={}))})(this,function(p){"use strict";var ae=(p,m,_)=>{if(!m.has(p))throw TypeError("Cannot "+_)};var t=(p,m,_)=>(ae(p,m,"read from private field"),_?_.call(p):m.get(p)),g=(p,m,_)=>{if(m.has(p))throw TypeError("Cannot add the same private member more than once");m instanceof WeakSet?m.add(p):m.set(p,_)},O=(p,m,_,V)=>(ae(p,m,"write to private field"),V?V.call(p,_):m.set(p,_),_);var j,E,z,G,w,R,A,P,W,U,B,S,L,N,k,x,$,K;function m(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 u(){}Object.create&&(u.prototype=Object.create(null),new u().__proto__||(e=!1));function s(c,i,o){this.fn=c,this.context=i,this.once=o||!1}function f(c,i,o,l,C){if(typeof o!="function")throw new TypeError("The listener must be a function");var v=new s(o,l||c,C),y=e?e+i:i;return c._events[y]?c._events[y].fn?c._events[y]=[c._events[y],v]:c._events[y].push(v):(c._events[y]=v,c._eventsCount++),c}function d(c,i){--c._eventsCount===0?c._events=new u:delete c._events[i]}function h(){this._events=new u,this._eventsCount=0}h.prototype.eventNames=function(){var i=[],o,l;if(this._eventsCount===0)return i;for(l in o=this._events)n.call(o,l)&&i.push(e?l.slice(1):l);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(o)):i},h.prototype.listeners=function(i){var o=e?e+i:i,l=this._events[o];if(!l)return[];if(l.fn)return[l.fn];for(var C=0,v=l.length,y=new Array(v);C<v;C++)y[C]=l[C].fn;return y},h.prototype.listenerCount=function(i){var o=e?e+i:i,l=this._events[o];return l?l.fn?1:l.length:0},h.prototype.emit=function(i,o,l,C,v,y){var M=e?e+i:i;if(!this._events[M])return!1;var a=this._events[M],T=arguments.length,D,b;if(a.fn){switch(a.once&&this.removeListener(i,a.fn,void 0,!0),T){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,o),!0;case 3:return a.fn.call(a.context,o,l),!0;case 4:return a.fn.call(a.context,o,l,C),!0;case 5:return a.fn.call(a.context,o,l,C,v),!0;case 6:return a.fn.call(a.context,o,l,C,v,y),!0}for(b=1,D=new Array(T-1);b<T;b++)D[b-1]=arguments[b];a.fn.apply(a.context,D)}else{var Se=a.length,H;for(b=0;b<Se;b++)switch(a[b].once&&this.removeListener(i,a[b].fn,void 0,!0),T){case 1:a[b].fn.call(a[b].context);break;case 2:a[b].fn.call(a[b].context,o);break;case 3:a[b].fn.call(a[b].context,o,l);break;case 4:a[b].fn.call(a[b].context,o,l,C);break;default:if(!D)for(H=1,D=new Array(T-1);H<T;H++)D[H-1]=arguments[H];a[b].fn.apply(a[b].context,D)}}return!0},h.prototype.on=function(i,o,l){return f(this,i,o,l,!1)},h.prototype.once=function(i,o,l){return f(this,i,o,l,!0)},h.prototype.removeListener=function(i,o,l,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)&&(!l||y.context===l)&&d(this,v);else{for(var M=0,a=[],T=y.length;M<T;M++)(y[M].fn!==o||C&&!y[M].once||l&&y[M].context!==l)&&a.push(y[M]);a.length?this._events[v]=a.length===1?a[0]:a: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 u,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 le=m(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 q(r,n){return n.clone!==!1&&n.isMergeableObject(r)?I(we(r),r,n):r}function ye(r,n,e){return r.concat(n).map(function(u){return q(u,e)})}function be(r,n){if(!n.customMerge)return I;var e=n.customMerge(r);return typeof e=="function"?e:I}function me(r){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(r).filter(function(n){return Object.propertyIsEnumerable.call(r,n)}):[]}function ee(r){return Object.keys(r).concat(me(r))}function te(r,n){try{return n in r}catch{return!1}}function ge(r,n){return te(r,n)&&!(Object.hasOwnProperty.call(r,n)&&Object.propertyIsEnumerable.call(r,n))}function Oe(r,n,e){var u={};return e.isMergeableObject(r)&&ee(r).forEach(function(s){u[s]=q(r[s],e)}),ee(n).forEach(function(s){ge(r,s)||(te(r,s)&&e.isMergeableObject(n[s])?u[s]=be(s,e)(r[s],n[s],e):u[s]=q(n[s],e))}),u}function I(r,n,e){e=e||{},e.arrayMerge=e.arrayMerge||ye,e.isMergeableObject=e.isMergeableObject||ce,e.cloneUnlessOtherwiseSpecified=q;var u=Array.isArray(n),s=Array.isArray(r),f=u===s;return f?u?e.arrayMerge(r,n,e):Oe(r,n,e):q(n,e)}I.all=function(n,e){if(!Array.isArray(n))throw new Error("first argument should be an array");return n.reduce(function(u,s){return I(u,s,e)},{})};var ve=I,Ae=ve;const Ee=m(Ae);/*!
|
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 ne(r){return Object.prototype.toString.call(r)==="[object Object]"}function Ce(r){var n,e;return ne(r)===!1?!1:(n=r.constructor,n===void 0?!0:(e=n.prototype,!(ne(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^="-"])'],re={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 se(r){return Ee.all(r,{isMergeableObject:Ce})}class J{constructor({target:n,type:e,owner:u}){g(this,j,void 0);g(this,E,void 0);g(this,z,void 0);g(this,
|
6
|
+
*/function ne(r){return Object.prototype.toString.call(r)==="[object Object]"}function Ce(r){var n,e;return ne(r)===!1?!1:(n=r.constructor,n===void 0?!0:(e=n.prototype,!(ne(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^="-"])'],re={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 se(r){return Ee.all(r,{isMergeableObject:Ce})}class J{constructor({target:n,type:e,owner:u}){g(this,j,void 0);g(this,E,void 0);g(this,z,void 0);g(this,G,!1);const s=X(n);if(!s)throw new Error("Trigger element cannot be found");O(this,j,s),O(this,E,u),O(this,z,e),this.init()}get isActive(){return t(this,G)}get owner(){return t(this,E)}init(){t(this,j).addEventListener("click",n=>this.clickHandler(n)),t(this,E).on("open",()=>this.setActive(!0)),t(this,E).on("close",()=>this.setActive(!1))}clickHandler(n){n.__drawerTrigger=this,t(this,z)==="open"?t(this,E).isOpen||t(this,E).open(t(this,j)):t(this,z)==="close"?t(this,E).isOpen&&t(this,E).close(t(this,j)):t(this,E).isOpen?t(this,E).close(t(this,j)):t(this,E).open(t(this,j))}setActive(n){O(this,G,n),n?t(this,j).classList.add("drawer-trigger_active"):t(this,j).classList.remove("drawer-trigger_active")}}j=new WeakMap,E=new WeakMap,z=new WeakMap,G=new WeakMap;class ie extends le{constructor({target:e,options:u}){super();g(this,w,void 0);g(this,R,void 0);g(this,A,void 0);g(this,P,void 0);g(this,W,void 0);g(this,U,void 0);this.handleDocumentClick=async h=>{var o;if(((o=h.__drawerTrigger)==null?void 0:o.owner)===this)return;const c=h.target;if(h.composedPath(),t(this,A).panel.contains(c))return;const i=c==null?void 0:c.closest("[data-drawer]");i?i.getAttribute("data-drawer")===t(this,U)?this.handleUnderlayClick(h):this.handleOtherDrawerClick(h):this.handleOutsideClick(h)},this.handleKeydown=h=>{t(this,w).closeOnEsc&&h.key==="Escape"&&this.close()};const s=se(u?[re,u]:[re]),f=X(e);if(f===null)throw new Error("Drawer's root cannot be found");O(this,U,f.getAttribute("data-drawer"));const d=f.querySelector(_e);if(d===null)throw new Error(`Drawer's panel cannot be found. Alias: ${t(this,U)}`);O(this,A,{root:f,panel:d}),this.setOptions(s),t(this,A).panel.setAttribute("tabindex","-1"),t(this,A).root.classList.add("drawer_initialized")}addEventListeners(){t(this,A).root.addEventListener("keydown",this.handleKeydown),document.addEventListener("click",this.handleDocumentClick)}removeEventListeners(){t(this,A).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,A).root.classList[e?"add":"remove"]("drawer_modal")}set zIndex(e){t(this,A).root.style.setProperty("--z-index",String(e)),O(this,R,e)}get zIndex(){return t(this,R)}async open(e){await Z(0),!t(this,P)&&(this.emit("beforeOpen",{drawer:this,trigger:e}),O(this,P,!0),t(this,A).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,A).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,A).panel.focus()}focusChild(){const e=t(this,A).panel.querySelector(je.join(","));return e?(e.focus(),!0):!1}setOptions(e){var u;e.hasOwnProperty("modal")&&((u=t(this,w))==null?void 0:u.modal)!==e.modal&&(this.isModal=e.modal),O(this,w,t(this,w)?se([t(this,w),e]):e)}assignGroup(e){O(this,W,e)}}w=new WeakMap,R=new WeakMap,A=new WeakMap,P=new WeakMap,W=new WeakMap,U=new WeakMap;class oe{constructor(n){g(this,B,void 0);g(this,S,void 0);g(this,L,void 0);g(this,N,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,B,e);const u=t(this,B).closest("[data-scrollable], html");if(u===null)throw new Error("Scrollable container for group root cannot be found");O(this,N,u)}add(n){n.on("beforeOpen",this.onBeforeOpen),n.on("closeAnimationEnd",this.onCloseAnimationEnd),n.assignGroup(this)}lockScroll(n){t(this,k).size===0&&t(this,N).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,N).classList.remove("scroll-lock-by-drawer")}}B=new WeakMap,S=new WeakMap,L=new WeakMap,N=new WeakMap,k=new WeakMap,x=new WeakMap;const F=class F{constructor(){g(this,$,new Map);g(this,K,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,K).set(d,new oe(f))}),document.querySelectorAll("[data-drawer]").forEach(f=>{var o;const d=f.getAttribute("data-drawer");if(typeof d!="string")return;const h=new ie({target:f,options:n});t(this,$).set(d,h);const c=f.closest(`[${Y}]`),i=c==null?void 0:c.getAttribute(Y);if(typeof i!="string")throw new Error("Group doesn't have alias set correctly");(o=t(this,K).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:u}={}){var s;(s=this.get(n))==null||s.open(e)}close(n,{trigger:e,options:u}={}){var s;(s=this.get(n))==null||s.close(e)}get(n){return typeof n=="string"&&t(this,$).get(n)||null}};$=new WeakMap,K=new WeakMap;let Q=F;typeof window<"u"&&(window.hasOwnProperty("app")||(window.app={}),window.app.drawers=new Q),p.Drawer=ie,p.DrawersGroup=oe,p.Trigger=J,p.default=Q,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
@@ -1,48 +1,48 @@
|
|
1
|
-
{
|
2
|
-
"name": "vanilla-drawers",
|
3
|
-
"version": "1.0.
|
4
|
-
"description": "Drawers controller.",
|
5
|
-
"files": [
|
6
|
-
"dist"
|
7
|
-
],
|
8
|
-
"main": "./dist/drawers.umd.js",
|
9
|
-
"module": "./dist/drawers.js",
|
10
|
-
"type": "module",
|
11
|
-
"exports": {
|
12
|
-
".": {
|
13
|
-
"import": "./dist/drawers.js",
|
14
|
-
"require": "./dist/drawers.umd.js"
|
15
|
-
}
|
16
|
-
},
|
17
|
-
"
|
18
|
-
"
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
"
|
23
|
-
|
24
|
-
|
25
|
-
"
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
"
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
"@babel/
|
38
|
-
"
|
39
|
-
"
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"
|
43
|
-
"
|
44
|
-
|
45
|
-
|
46
|
-
"
|
47
|
-
}
|
48
|
-
}
|
1
|
+
{
|
2
|
+
"name": "vanilla-drawers",
|
3
|
+
"version": "1.0.6",
|
4
|
+
"description": "Drawers controller.",
|
5
|
+
"files": [
|
6
|
+
"dist"
|
7
|
+
],
|
8
|
+
"main": "./dist/drawers.umd.js",
|
9
|
+
"module": "./dist/drawers.js",
|
10
|
+
"type": "module",
|
11
|
+
"exports": {
|
12
|
+
".": {
|
13
|
+
"import": "./dist/drawers.js",
|
14
|
+
"require": "./dist/drawers.umd.js"
|
15
|
+
}
|
16
|
+
},
|
17
|
+
"scripts": {
|
18
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
19
|
+
},
|
20
|
+
"repository": {
|
21
|
+
"type": "git",
|
22
|
+
"url": "git+https://github.com/techno-trump/drawers.git"
|
23
|
+
},
|
24
|
+
"keywords": [
|
25
|
+
"drawer",
|
26
|
+
"popup",
|
27
|
+
"modal",
|
28
|
+
"dialog"
|
29
|
+
],
|
30
|
+
"author": "Anton Kalinichenko",
|
31
|
+
"license": "GPL-3.0",
|
32
|
+
"bugs": {
|
33
|
+
"url": "https://github.com/techno-trump/drawers/issues"
|
34
|
+
},
|
35
|
+
"homepage": "https://github.com/techno-trump/drawers#readme",
|
36
|
+
"devDependencies": {
|
37
|
+
"@babel/core": "^7.23.6",
|
38
|
+
"@babel/plugin-transform-class-properties": "^7.23.3",
|
39
|
+
"@babel/preset-env": "^7.23.6",
|
40
|
+
"@babel/preset-typescript": "^7.23.3",
|
41
|
+
"deepmerge": "^4.3.1",
|
42
|
+
"eslint": "^8.56.0",
|
43
|
+
"eventemitter3": "^5.0.1",
|
44
|
+
"is-plain-object": "^5.0.0",
|
45
|
+
"typescript": "^5.3.3",
|
46
|
+
"vite": "^5.0.10"
|
47
|
+
}
|
48
|
+
}
|