@flexilla/alpine-offcanvas 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn.js +45 -57
- package/dist/cdn.min.js +1 -1
- package/dist/module.cjs.js +45 -57
- package/dist/module.esm.js +45 -57
- package/package.json +3 -3
package/dist/cdn.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
var w = (t, e, n) => e in t ? g(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n;
|
|
5
5
|
var o = (t, e, n) => w(t, typeof e != "symbol" ? e + "" : e, n);
|
|
6
6
|
var m = (t, e = document.body) => e.querySelector(t);
|
|
7
|
-
var
|
|
7
|
+
var h = (t, e = document.body) => Array.from(e.querySelectorAll(t));
|
|
8
8
|
var y = ({
|
|
9
9
|
newElement: t,
|
|
10
10
|
existingElement: e
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
}) => {
|
|
26
26
|
const a = getComputedStyle(t), i = a.transition;
|
|
27
27
|
if (i !== "none" && i !== "" && !s.includes(i)) {
|
|
28
|
-
const l = "transitionend",
|
|
29
|
-
t.removeEventListener(l,
|
|
28
|
+
const l = "transitionend", c = () => {
|
|
29
|
+
t.removeEventListener(l, c), e();
|
|
30
30
|
};
|
|
31
|
-
t.addEventListener(l,
|
|
31
|
+
t.addEventListener(l, c, { once: true });
|
|
32
32
|
} else
|
|
33
33
|
e();
|
|
34
34
|
};
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
keysCheck: ["all 0s ease 0s", "all"]
|
|
44
44
|
});
|
|
45
45
|
};
|
|
46
|
-
var
|
|
46
|
+
var v = (t, e, n) => {
|
|
47
47
|
const s = new CustomEvent(e, { detail: n });
|
|
48
48
|
t.dispatchEvent(s);
|
|
49
49
|
};
|
|
50
|
-
function
|
|
50
|
+
function B(t) {
|
|
51
51
|
const e = () => {
|
|
52
52
|
document.querySelector(
|
|
53
53
|
"[data-fx-component]:not([data-component-initialized])"
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
};
|
|
56
56
|
e();
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function A(t, e, n = "move") {
|
|
59
59
|
if (!(t instanceof HTMLElement))
|
|
60
60
|
throw new Error("Source element must be an HTMLElement");
|
|
61
61
|
if (!(e instanceof HTMLElement))
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
var
|
|
89
|
+
var I = (t) => {
|
|
90
90
|
var e;
|
|
91
91
|
return (e = t.parentElement) == null ? void 0 : e.removeChild(t);
|
|
92
92
|
};
|
|
@@ -94,11 +94,11 @@
|
|
|
94
94
|
t.setAttribute("data-state", "invisible"), O({
|
|
95
95
|
element: t,
|
|
96
96
|
callback() {
|
|
97
|
-
|
|
97
|
+
I(t);
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
100
|
};
|
|
101
|
-
var
|
|
101
|
+
var L = (t, e) => {
|
|
102
102
|
const n = t;
|
|
103
103
|
if (n === "" || !n)
|
|
104
104
|
return;
|
|
@@ -109,23 +109,23 @@
|
|
|
109
109
|
return n !== "" && s.classList.add(...a), s;
|
|
110
110
|
};
|
|
111
111
|
var u = (t, e, n) => {
|
|
112
|
-
t.setAttribute("aria-hidden", n === "open" ? "false" : "true"), t.setAttribute("data-state", n), e ||
|
|
112
|
+
t.setAttribute("aria-hidden", n === "open" ? "false" : "true"), t.setAttribute("data-state", n), e || S(n);
|
|
113
113
|
};
|
|
114
|
-
var
|
|
114
|
+
var S = (t) => {
|
|
115
115
|
document.body.style.overflow = t === "open" ? "hidden" : "", document.body.style.overflowY = t === "open" ? "hidden" : "auto";
|
|
116
116
|
};
|
|
117
|
-
var
|
|
117
|
+
var T = (t, e) => {
|
|
118
118
|
if (t === e)
|
|
119
119
|
return;
|
|
120
120
|
t.setAttribute("aria-hidden", "true"), t.setAttribute("data-state", "close");
|
|
121
121
|
const n = m(`[data-fx-offcanvas-overlay][data-offcanvas-el=${t.getAttribute("id")}]`, t.parentElement);
|
|
122
122
|
n instanceof HTMLElement && C(n);
|
|
123
123
|
};
|
|
124
|
-
var
|
|
125
|
-
const e =
|
|
124
|
+
var x = (t) => {
|
|
125
|
+
const e = h("[data-fx-offcanvas][data-state=open]");
|
|
126
126
|
if (!(e.length <= 0))
|
|
127
127
|
for (const n of e)
|
|
128
|
-
|
|
128
|
+
T(n, t);
|
|
129
129
|
};
|
|
130
130
|
var d = class {
|
|
131
131
|
static initGlobalRegistry() {
|
|
@@ -174,41 +174,52 @@
|
|
|
174
174
|
o(this, "offCanvasElement");
|
|
175
175
|
o(this, "offCanvasTriggers");
|
|
176
176
|
o(this, "offCanvasCloseBtns");
|
|
177
|
+
o(this, "offCanvasId", "");
|
|
178
|
+
o(this, "dispatchEventToDocument");
|
|
177
179
|
o(this, "allowBodyScroll");
|
|
178
180
|
o(this, "staticBackdrop");
|
|
179
181
|
o(this, "backdrop");
|
|
180
182
|
o(this, "options");
|
|
181
183
|
o(this, "teleporter");
|
|
182
184
|
o(this, "moveElOnInit", () => {
|
|
183
|
-
|
|
185
|
+
B(() => this.teleporter.append());
|
|
184
186
|
});
|
|
185
187
|
o(this, "closeWhenClickOutSide", (e2) => {
|
|
186
188
|
const n2 = this.offCanvasElement.getAttribute("data-state") === "open", s2 = !this.offCanvasElement.contains(e2.target) && ![...this.offCanvasTriggers].includes(e2.target);
|
|
187
189
|
n2 && s2 && this.closeOffCanvas();
|
|
188
190
|
});
|
|
189
191
|
o(this, "closeOffCanvas", () => {
|
|
190
|
-
var i2, l2,
|
|
192
|
+
var i2, l2, c2, r2, p;
|
|
191
193
|
let e2 = false;
|
|
192
|
-
if (
|
|
194
|
+
if (v(this.offCanvasElement, "offcanvas-before-hide", {
|
|
193
195
|
offcanvasId: this.offCanvasElement.id,
|
|
194
196
|
setExitAction: (b) => {
|
|
195
197
|
e2 = b;
|
|
196
198
|
}
|
|
197
|
-
}), ((
|
|
199
|
+
}), ((c2 = (l2 = (i2 = this.options).beforeHide) == null ? void 0 : l2.call(i2)) == null ? void 0 : c2.cancelAction) || e2)
|
|
198
200
|
return;
|
|
199
201
|
const s2 = this.offCanvasElement.getAttribute("id"), a2 = m(`[data-fx-offcanvas-overlay][data-offcanvas-el=${s2}]`);
|
|
200
202
|
a2 instanceof HTMLElement && C(a2), this.offCanvasElement.blur(), u(
|
|
201
203
|
this.offCanvasElement,
|
|
202
204
|
this.allowBodyScroll,
|
|
203
205
|
"close"
|
|
204
|
-
), document.removeEventListener("keydown", this.closeWithEsc), !this.allowBodyScroll && !a2 && document.removeEventListener("click", this.closeWhenClickOutSide), (p = (
|
|
206
|
+
), document.removeEventListener("keydown", this.closeWithEsc), !this.allowBodyScroll && !a2 && document.removeEventListener("click", this.closeWhenClickOutSide), (p = (r2 = this.options).onHide) == null || p.call(r2), v(this.offCanvasElement, "offcanvas-close", { offcanvasId: this.offCanvasElement.id });
|
|
205
207
|
});
|
|
206
208
|
o(this, "closeWithEsc", (e2) => {
|
|
207
209
|
e2.key === "Escape" && (e2.preventDefault(), this.closeOffCanvas());
|
|
208
210
|
});
|
|
211
|
+
o(this, "closeFromCloseBtn", (e2) => {
|
|
212
|
+
e2.target.blur(), this.closeOffCanvas();
|
|
213
|
+
});
|
|
209
214
|
o(this, "changeState", () => {
|
|
210
215
|
this.offCanvasElement.getAttribute("data-state") === "open" ? this.closeOffCanvas() : this.openOffCanvas();
|
|
211
216
|
});
|
|
217
|
+
o(this, "open", () => {
|
|
218
|
+
this.openOffCanvas();
|
|
219
|
+
});
|
|
220
|
+
o(this, "close", () => {
|
|
221
|
+
this.closeOffCanvas();
|
|
222
|
+
});
|
|
212
223
|
o(this, "setOptions", ({ allowBodyscroll: e2 }) => {
|
|
213
224
|
e2 !== void 0 && (this.allowBodyScroll = e2);
|
|
214
225
|
});
|
|
@@ -220,65 +231,42 @@
|
|
|
220
231
|
if (a)
|
|
221
232
|
return a;
|
|
222
233
|
d.setup(this.offCanvasElement), this.options = n;
|
|
223
|
-
const { staticBackdrop: i, allowBodyScroll: l, backdrop:
|
|
234
|
+
const { staticBackdrop: i, allowBodyScroll: l, backdrop: c } = this.options;
|
|
224
235
|
this.setupAttributes(), this.staticBackdrop = i || s.hasAttribute("data-static-backdrop") && s.dataset.staticBackdrop !== "false" || false, this.allowBodyScroll = l || s.hasAttribute("data-allow-body-scroll") && s.dataset.allowBodyScroll !== "false" || false;
|
|
225
|
-
const
|
|
226
|
-
|
|
236
|
+
const r = this.offCanvasElement.getAttribute("id");
|
|
237
|
+
if (!r || r === "")
|
|
238
|
+
throw new Error("\u274C id is required but missing on element:");
|
|
239
|
+
this.offCanvasId = r, this.offCanvasTriggers = this.findOffCanvasElements("[data-offcanvas-trigger]", false, r), this.offCanvasCloseBtns = this.findOffCanvasElements("[data-offcanvas-close]", true, r, this.offCanvasElement), this.backdrop = c || this.offCanvasElement.dataset.offcanvasBackdrop || "", this.dispatchEventToDocument = this.dispatchEventToDocument = this.options.dispatchEventToDocument || true, this.teleporter = A(this.offCanvasElement, document.body, "move"), this.setupOffcanvas(), this.moveElOnInit(), d.register("offcanvas", this.offCanvasElement, this), d.initialized(this.offCanvasElement);
|
|
227
240
|
}
|
|
228
241
|
findOffCanvasElements(e, n, s, a) {
|
|
229
|
-
return n ?
|
|
242
|
+
return n ? h(`${e}`, a) : h(`${e}[data-target=${s}]`);
|
|
230
243
|
}
|
|
231
244
|
setupAttributes() {
|
|
232
245
|
this.offCanvasElement.hasAttribute("data-fx-offcanvas") || this.offCanvasElement.setAttribute("data-fx-offcanvas", "");
|
|
233
246
|
}
|
|
234
247
|
openOffCanvas() {
|
|
235
248
|
var s, a, i, l;
|
|
236
|
-
(a = (s = this.options).beforeShow) == null || a.call(s),
|
|
249
|
+
(a = (s = this.options).beforeShow) == null || a.call(s), x(this.offCanvasElement), u(
|
|
237
250
|
this.offCanvasElement,
|
|
238
251
|
this.allowBodyScroll,
|
|
239
252
|
"open"
|
|
240
253
|
);
|
|
241
|
-
const e = this.offCanvasElement.getAttribute("id"), n =
|
|
254
|
+
const e = this.offCanvasElement.getAttribute("id"), n = L(
|
|
242
255
|
this.backdrop,
|
|
243
256
|
e
|
|
244
257
|
);
|
|
245
|
-
n instanceof HTMLElement && (y({ newElement: n, existingElement: this.offCanvasElement }), this.staticBackdrop || n.addEventListener("click", this.closeOffCanvas)), document.addEventListener("keydown", this.closeWithEsc), (l = (i = this.options).onShow) == null || l.call(i),
|
|
258
|
+
n instanceof HTMLElement && (y({ newElement: n, existingElement: this.offCanvasElement }), this.staticBackdrop || n.addEventListener("click", this.closeOffCanvas)), document.addEventListener("keydown", this.closeWithEsc), (l = (i = this.options).onShow) == null || l.call(i), v(this.offCanvasElement, "offcanvas-open", { offcanvasId: this.offCanvasElement.id });
|
|
246
259
|
}
|
|
247
260
|
initCloseBtns() {
|
|
248
261
|
for (const e of this.offCanvasCloseBtns)
|
|
249
|
-
e.addEventListener("click", this.
|
|
262
|
+
e.addEventListener("click", this.closeFromCloseBtn);
|
|
250
263
|
}
|
|
251
264
|
initTriggers() {
|
|
252
265
|
for (const e of this.offCanvasTriggers)
|
|
253
266
|
e.addEventListener("click", this.changeState);
|
|
254
267
|
}
|
|
255
268
|
setupOffcanvas() {
|
|
256
|
-
this.initTriggers(), this.initCloseBtns();
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Opens the offcanvas element.
|
|
260
|
-
* @example
|
|
261
|
-
* ```ts
|
|
262
|
-
* const offcanvas = new Offcanvas('#sidebar');
|
|
263
|
-
* offcanvas.open();
|
|
264
|
-
* ```
|
|
265
|
-
*/
|
|
266
|
-
open() {
|
|
267
|
-
this.openOffCanvas();
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Closes the offcanvas element.
|
|
271
|
-
* This method will trigger the beforeHide callback if provided,
|
|
272
|
-
* remove the backdrop if present, and finally trigger the onHide callback.
|
|
273
|
-
*
|
|
274
|
-
* @example
|
|
275
|
-
* ```ts
|
|
276
|
-
* const offcanvas = new Offcanvas('#sidebar');
|
|
277
|
-
* offcanvas.close();
|
|
278
|
-
* ```
|
|
279
|
-
*/
|
|
280
|
-
close() {
|
|
281
|
-
this.closeOffCanvas();
|
|
269
|
+
this.initTriggers(), this.initCloseBtns(), this.dispatchEventToDocument && document.addEventListener(`sheet:${this.offCanvasId}:open`, this.open), this.dispatchEventToDocument && document.addEventListener(`sheet:${this.offCanvasId}:close`, this.close);
|
|
282
270
|
}
|
|
283
271
|
/**
|
|
284
272
|
* Cleans up the offcanvas instance by removing event listeners and references.
|
|
@@ -296,11 +284,11 @@
|
|
|
296
284
|
e.removeEventListener("click", this.changeState);
|
|
297
285
|
for (const e of this.offCanvasCloseBtns)
|
|
298
286
|
e.removeEventListener("click", this.closeOffCanvas);
|
|
299
|
-
document.removeEventListener("keydown", this.closeWithEsc), this.allowBodyScroll || document.removeEventListener("click", this.closeWhenClickOutSide), d.removeInstance("offcanvas", this.offCanvasElement);
|
|
287
|
+
document.removeEventListener("keydown", this.closeWithEsc), this.allowBodyScroll || document.removeEventListener("click", this.closeWhenClickOutSide), this.dispatchEventToDocument && document.removeEventListener(`sheet:${this.offCanvasId}:open`, this.open), this.dispatchEventToDocument && document.removeEventListener(`sheet:${this.offCanvasId}:close`, this.close), d.removeInstance("offcanvas", this.offCanvasElement);
|
|
300
288
|
}
|
|
301
289
|
};
|
|
302
290
|
o(f, "autoInit", (e = "[data-fx-offcanvas]") => {
|
|
303
|
-
const n =
|
|
291
|
+
const n = h(e);
|
|
304
292
|
for (const s of n)
|
|
305
293
|
new f(s);
|
|
306
294
|
}), /**
|
package/dist/cdn.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var T=Object.defineProperty,x=(t,e,s)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,o=(t,e,s)=>x(t,typeof e!="symbol"?e+"":e,s),C=(t,e=document.body)=>e.querySelector(t),u=(t,e=document.body)=>Array.from(e.querySelectorAll(t)),A=({newElement:t,existingElement:e})=>{if(!(t instanceof HTMLElement)||!(e instanceof HTMLElement))throw new Error("Both parameters must be valid HTML elements.");let s=e.parentElement;if(s)s.insertBefore(t,e);else throw new Error("Existing element must have a parent element.")},$=({element:t,callback:e,type:s,keysCheck:n})=>{let a=getComputedStyle(t),l=a.transition;if(l!=="none"&&l!==""&&!n.includes(l)){let r="transitionend",h=()=>{t.removeEventListener(r,h),e()};t.addEventListener(r,h,{once:!0})}else e()},S=({element:t,callback:e})=>{$({element:t,callback:e,type:"transition",keysCheck:["all 0s ease 0s","all"]})},E=(t,e,s)=>{let n=new CustomEvent(e,{detail:s});t.dispatchEvent(n)};function H(t){let e=()=>{document.querySelector("[data-fx-component]:not([data-component-initialized])")?requestAnimationFrame(e):t()};e()}function N(t,e,s="move"){if(!(t instanceof HTMLElement))throw new Error("Source element must be an HTMLElement");if(!(e instanceof HTMLElement))throw new Error("Target element must be an HTMLElement");if(!["move","detachable"].includes(s))throw new Error(`Invalid teleport mode: ${s}. Must be "move" or "detachable".`);let n=document.createComment("teleporter-placeholder"),a=t.parentNode;return a?a.insertBefore(n,t):console.warn("Element has no parent; placeholder not inserted."),s==="move"?(t.parentNode&&e.appendChild(t),{append(){t.parentNode!==e&&e.appendChild(t)},remove(){n!=null&&n.parentNode&&t.parentNode&&n.parentNode.insertBefore(t,n)},restore(){n!=null&&n.parentNode&&t.parentNode!==a&&n.parentNode.insertBefore(t,n)}}):(t.parentNode&&e.appendChild(t),{append(){e.contains(t)||e.appendChild(t)},remove(){t.parentNode&&t.remove()},restore(){n!=null&&n.parentNode&&!t.parentNode&&n.parentNode.insertBefore(t,n)}})}var M=t=>{var e;return(e=t.parentElement)==null?void 0:e.removeChild(t)},L=t=>{t.setAttribute("data-state","invisible"),S({element:t,callback(){M(t)}})},D=(t,e)=>{let s=t;if(s===""||!s)return;let n=document.createElement("div");if(n.setAttribute("aria-hidden","true"),n.setAttribute("data-state","visible"),n.setAttribute("data-fx-offcanvas-overlay",""),n.setAttribute("data-offcanvas-el",e),s==="")return;let a=s.split(" ");return s!==""&&n.classList.add(...a),n},y=(t,e,s)=>{t.setAttribute("aria-hidden",s==="open"?"false":"true"),t.setAttribute("data-state",s),e||W(s)},W=t=>{document.body.style.overflow=t==="open"?"hidden":"",document.body.style.overflowY=t==="open"?"hidden":"auto"},q=(t,e)=>{if(t===e)return;t.setAttribute("aria-hidden","true"),t.setAttribute("data-state","close");let s=C(`[data-fx-offcanvas-overlay][data-offcanvas-el=${t.getAttribute("id")}]`,t.parentElement);s instanceof HTMLElement&&L(s)},z=t=>{let e=u("[data-fx-offcanvas][data-state=open]");if(!(e.length<=0))for(let s of e)q(s,t)},c=class{static initGlobalRegistry(){window.$flexillaInstances||(window.$flexillaInstances={})}static register(e,s,n){return this.initGlobalRegistry(),window.$flexillaInstances[e]||(window.$flexillaInstances[e]=[]),this.getInstance(e,s)||(window.$flexillaInstances[e].push({element:s,instance:n}),n)}static getInstance(e,s){var n,a;return this.initGlobalRegistry(),(a=(n=window.$flexillaInstances[e])==null?void 0:n.find(l=>l.element===s))==null?void 0:a.instance}static removeInstance(e,s){this.initGlobalRegistry(),window.$flexillaInstances[e]&&(window.$flexillaInstances[e]=window.$flexillaInstances[e].filter(n=>n.element!==s))}static setup(e){e.setAttribute("data-fx-component","fx")}static initialized(e){e.setAttribute("data-component-initialized","initialized")}},d=class{constructor(e,s={}){o(this,"offCanvasElement"),o(this,"offCanvasTriggers"),o(this,"offCanvasCloseBtns"),o(this,"offCanvasId",""),o(this,"dispatchEventToDocument"),o(this,"allowBodyScroll"),o(this,"staticBackdrop"),o(this,"backdrop"),o(this,"options"),o(this,"teleporter"),o(this,"moveElOnInit",()=>{H(()=>this.teleporter.append())}),o(this,"closeWhenClickOutSide",i=>{let v=this.offCanvasElement.getAttribute("data-state")==="open",m=!this.offCanvasElement.contains(i.target)&&![...this.offCanvasTriggers].includes(i.target);v&&m&&this.closeOffCanvas()}),o(this,"closeOffCanvas",()=>{var i,v,m,b,w;let g=!1;if(E(this.offCanvasElement,"offcanvas-before-hide",{offcanvasId:this.offCanvasElement.id,setExitAction:O=>{g=O}}),((m=(v=(i=this.options).beforeHide)==null?void 0:v.call(i))==null?void 0:m.cancelAction)||g)return;let I=this.offCanvasElement.getAttribute("id"),p=C(`[data-fx-offcanvas-overlay][data-offcanvas-el=${I}]`);p instanceof HTMLElement&&L(p),this.offCanvasElement.blur(),y(this.offCanvasElement,this.allowBodyScroll,"close"),document.removeEventListener("keydown",this.closeWithEsc),!this.allowBodyScroll&&!p&&document.removeEventListener("click",this.closeWhenClickOutSide),(w=(b=this.options).onHide)==null||w.call(b),E(this.offCanvasElement,"offcanvas-close",{offcanvasId:this.offCanvasElement.id})}),o(this,"closeWithEsc",i=>{i.key==="Escape"&&(i.preventDefault(),this.closeOffCanvas())}),o(this,"closeFromCloseBtn",i=>{i.target.blur(),this.closeOffCanvas()}),o(this,"changeState",()=>{this.offCanvasElement.getAttribute("data-state")==="open"?this.closeOffCanvas():this.openOffCanvas()}),o(this,"open",()=>{this.openOffCanvas()}),o(this,"close",()=>{this.closeOffCanvas()}),o(this,"setOptions",({allowBodyscroll:i})=>{i!==void 0&&(this.allowBodyScroll=i)});let n=typeof e=="string"?C(e):e;if(!(n instanceof HTMLElement))throw new Error("Invalid Offcanvas, the provided Element is not a valid HTMLElement");this.offCanvasElement=n;let a=c.getInstance("offcanvas",n);if(a)return a;c.setup(this.offCanvasElement),this.options=s;let{staticBackdrop:l,allowBodyScroll:r,backdrop:h}=this.options;this.setupAttributes(),this.staticBackdrop=l||n.hasAttribute("data-static-backdrop")&&n.dataset.staticBackdrop!=="false"||!1,this.allowBodyScroll=r||n.hasAttribute("data-allow-body-scroll")&&n.dataset.allowBodyScroll!=="false"||!1;let f=this.offCanvasElement.getAttribute("id");if(!f||f==="")throw new Error("\u274C id is required but missing on element:");this.offCanvasId=f,this.offCanvasTriggers=this.findOffCanvasElements("[data-offcanvas-trigger]",!1,f),this.offCanvasCloseBtns=this.findOffCanvasElements("[data-offcanvas-close]",!0,f,this.offCanvasElement),this.backdrop=h||this.offCanvasElement.dataset.offcanvasBackdrop||"",this.dispatchEventToDocument=this.dispatchEventToDocument=this.options.dispatchEventToDocument||!0,this.teleporter=N(this.offCanvasElement,document.body,"move"),this.setupOffcanvas(),this.moveElOnInit(),c.register("offcanvas",this.offCanvasElement,this),c.initialized(this.offCanvasElement)}findOffCanvasElements(e,s,n,a){return s?u(`${e}`,a):u(`${e}[data-target=${n}]`)}setupAttributes(){this.offCanvasElement.hasAttribute("data-fx-offcanvas")||this.offCanvasElement.setAttribute("data-fx-offcanvas","")}openOffCanvas(){var e,s,n,a;(s=(e=this.options).beforeShow)==null||s.call(e),z(this.offCanvasElement),y(this.offCanvasElement,this.allowBodyScroll,"open");let l=this.offCanvasElement.getAttribute("id"),r=D(this.backdrop,l);r instanceof HTMLElement&&(A({newElement:r,existingElement:this.offCanvasElement}),this.staticBackdrop||r.addEventListener("click",this.closeOffCanvas)),document.addEventListener("keydown",this.closeWithEsc),(a=(n=this.options).onShow)==null||a.call(n),E(this.offCanvasElement,"offcanvas-open",{offcanvasId:this.offCanvasElement.id})}initCloseBtns(){for(let e of this.offCanvasCloseBtns)e.addEventListener("click",this.closeFromCloseBtn)}initTriggers(){for(let e of this.offCanvasTriggers)e.addEventListener("click",this.changeState)}setupOffcanvas(){this.initTriggers(),this.initCloseBtns(),this.dispatchEventToDocument&&document.addEventListener(`sheet:${this.offCanvasId}:open`,this.open),this.dispatchEventToDocument&&document.addEventListener(`sheet:${this.offCanvasId}:close`,this.close)}cleanup(){for(let e of this.offCanvasTriggers)e.removeEventListener("click",this.changeState);for(let e of this.offCanvasCloseBtns)e.removeEventListener("click",this.closeOffCanvas);document.removeEventListener("keydown",this.closeWithEsc),this.allowBodyScroll||document.removeEventListener("click",this.closeWhenClickOutSide),this.dispatchEventToDocument&&document.removeEventListener(`sheet:${this.offCanvasId}:open`,this.open),this.dispatchEventToDocument&&document.removeEventListener(`sheet:${this.offCanvasId}:close`,this.close),c.removeInstance("offcanvas",this.offCanvasElement)}};o(d,"autoInit",(t="[data-fx-offcanvas]")=>{let e=u(t);for(let s of e)new d(s)}),o(d,"init",(t,e={})=>new d(t,e));var k=d;function F(t){t.directive("offcanvas",(e,{},{cleanup:s})=>{let n=e.getAttribute("id");if(!n){console.error("\u274C id is required but missing on element:",e);return}let a=new k(e);t.store("sheets")||t.store("sheets",{}),t.store("sheets")[n]=a;let l=()=>a.open(),r=()=>a.close();document.addEventListener(`sheet:${n}:open`,l),document.addEventListener(`sheet:${n}:close`,r),s(()=>{document.removeEventListener(`sheet:${n}:open`,l),document.removeEventListener(`sheet:${n}:close`,r),a.cleanup(),delete t.store("sheets")[n]})}),t.magic("offcanvas",e=>s=>t.store("sheets")?t.store("sheets")[s]?t.store("sheets")[s]:(console.warn(`\u26A0\uFE0F No offcanvas instance found for ID: ${s}`),null):(console.warn("\u26A0\uFE0F Alpine store for Offcanvas is not initialized."),null))}var B=F;document.addEventListener("alpine:init",()=>{B(window.Alpine)});})();
|
package/dist/module.cjs.js
CHANGED
|
@@ -28,7 +28,7 @@ var g = Object.defineProperty;
|
|
|
28
28
|
var w = (t, e, n) => e in t ? g(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n;
|
|
29
29
|
var o = (t, e, n) => w(t, typeof e != "symbol" ? e + "" : e, n);
|
|
30
30
|
var m = (t, e = document.body) => e.querySelector(t);
|
|
31
|
-
var
|
|
31
|
+
var h = (t, e = document.body) => Array.from(e.querySelectorAll(t));
|
|
32
32
|
var y = ({
|
|
33
33
|
newElement: t,
|
|
34
34
|
existingElement: e
|
|
@@ -49,10 +49,10 @@ var k = ({
|
|
|
49
49
|
}) => {
|
|
50
50
|
const a = getComputedStyle(t), i = a.transition;
|
|
51
51
|
if (i !== "none" && i !== "" && !s.includes(i)) {
|
|
52
|
-
const l = "transitionend",
|
|
53
|
-
t.removeEventListener(l,
|
|
52
|
+
const l = "transitionend", c = () => {
|
|
53
|
+
t.removeEventListener(l, c), e();
|
|
54
54
|
};
|
|
55
|
-
t.addEventListener(l,
|
|
55
|
+
t.addEventListener(l, c, { once: true });
|
|
56
56
|
} else
|
|
57
57
|
e();
|
|
58
58
|
};
|
|
@@ -67,11 +67,11 @@ var O = ({
|
|
|
67
67
|
keysCheck: ["all 0s ease 0s", "all"]
|
|
68
68
|
});
|
|
69
69
|
};
|
|
70
|
-
var
|
|
70
|
+
var v = (t, e, n) => {
|
|
71
71
|
const s = new CustomEvent(e, { detail: n });
|
|
72
72
|
t.dispatchEvent(s);
|
|
73
73
|
};
|
|
74
|
-
function
|
|
74
|
+
function B(t) {
|
|
75
75
|
const e = () => {
|
|
76
76
|
document.querySelector(
|
|
77
77
|
"[data-fx-component]:not([data-component-initialized])"
|
|
@@ -79,7 +79,7 @@ function A(t) {
|
|
|
79
79
|
};
|
|
80
80
|
e();
|
|
81
81
|
}
|
|
82
|
-
function
|
|
82
|
+
function A(t, e, n = "move") {
|
|
83
83
|
if (!(t instanceof HTMLElement))
|
|
84
84
|
throw new Error("Source element must be an HTMLElement");
|
|
85
85
|
if (!(e instanceof HTMLElement))
|
|
@@ -110,7 +110,7 @@ function B(t, e, n = "move") {
|
|
|
110
110
|
}
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
-
var
|
|
113
|
+
var I = (t) => {
|
|
114
114
|
var e;
|
|
115
115
|
return (e = t.parentElement) == null ? void 0 : e.removeChild(t);
|
|
116
116
|
};
|
|
@@ -118,11 +118,11 @@ var C = (t) => {
|
|
|
118
118
|
t.setAttribute("data-state", "invisible"), O({
|
|
119
119
|
element: t,
|
|
120
120
|
callback() {
|
|
121
|
-
|
|
121
|
+
I(t);
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
124
|
};
|
|
125
|
-
var
|
|
125
|
+
var L = (t, e) => {
|
|
126
126
|
const n = t;
|
|
127
127
|
if (n === "" || !n)
|
|
128
128
|
return;
|
|
@@ -133,23 +133,23 @@ var x = (t, e) => {
|
|
|
133
133
|
return n !== "" && s.classList.add(...a), s;
|
|
134
134
|
};
|
|
135
135
|
var u = (t, e, n) => {
|
|
136
|
-
t.setAttribute("aria-hidden", n === "open" ? "false" : "true"), t.setAttribute("data-state", n), e ||
|
|
136
|
+
t.setAttribute("aria-hidden", n === "open" ? "false" : "true"), t.setAttribute("data-state", n), e || S(n);
|
|
137
137
|
};
|
|
138
|
-
var
|
|
138
|
+
var S = (t) => {
|
|
139
139
|
document.body.style.overflow = t === "open" ? "hidden" : "", document.body.style.overflowY = t === "open" ? "hidden" : "auto";
|
|
140
140
|
};
|
|
141
|
-
var
|
|
141
|
+
var T = (t, e) => {
|
|
142
142
|
if (t === e)
|
|
143
143
|
return;
|
|
144
144
|
t.setAttribute("aria-hidden", "true"), t.setAttribute("data-state", "close");
|
|
145
145
|
const n = m(`[data-fx-offcanvas-overlay][data-offcanvas-el=${t.getAttribute("id")}]`, t.parentElement);
|
|
146
146
|
n instanceof HTMLElement && C(n);
|
|
147
147
|
};
|
|
148
|
-
var
|
|
149
|
-
const e =
|
|
148
|
+
var x = (t) => {
|
|
149
|
+
const e = h("[data-fx-offcanvas][data-state=open]");
|
|
150
150
|
if (!(e.length <= 0))
|
|
151
151
|
for (const n of e)
|
|
152
|
-
|
|
152
|
+
T(n, t);
|
|
153
153
|
};
|
|
154
154
|
var d = class {
|
|
155
155
|
static initGlobalRegistry() {
|
|
@@ -198,41 +198,52 @@ var f = class f2 {
|
|
|
198
198
|
o(this, "offCanvasElement");
|
|
199
199
|
o(this, "offCanvasTriggers");
|
|
200
200
|
o(this, "offCanvasCloseBtns");
|
|
201
|
+
o(this, "offCanvasId", "");
|
|
202
|
+
o(this, "dispatchEventToDocument");
|
|
201
203
|
o(this, "allowBodyScroll");
|
|
202
204
|
o(this, "staticBackdrop");
|
|
203
205
|
o(this, "backdrop");
|
|
204
206
|
o(this, "options");
|
|
205
207
|
o(this, "teleporter");
|
|
206
208
|
o(this, "moveElOnInit", () => {
|
|
207
|
-
|
|
209
|
+
B(() => this.teleporter.append());
|
|
208
210
|
});
|
|
209
211
|
o(this, "closeWhenClickOutSide", (e2) => {
|
|
210
212
|
const n2 = this.offCanvasElement.getAttribute("data-state") === "open", s2 = !this.offCanvasElement.contains(e2.target) && ![...this.offCanvasTriggers].includes(e2.target);
|
|
211
213
|
n2 && s2 && this.closeOffCanvas();
|
|
212
214
|
});
|
|
213
215
|
o(this, "closeOffCanvas", () => {
|
|
214
|
-
var i2, l2,
|
|
216
|
+
var i2, l2, c2, r2, p;
|
|
215
217
|
let e2 = false;
|
|
216
|
-
if (
|
|
218
|
+
if (v(this.offCanvasElement, "offcanvas-before-hide", {
|
|
217
219
|
offcanvasId: this.offCanvasElement.id,
|
|
218
220
|
setExitAction: (b) => {
|
|
219
221
|
e2 = b;
|
|
220
222
|
}
|
|
221
|
-
}), ((
|
|
223
|
+
}), ((c2 = (l2 = (i2 = this.options).beforeHide) == null ? void 0 : l2.call(i2)) == null ? void 0 : c2.cancelAction) || e2)
|
|
222
224
|
return;
|
|
223
225
|
const s2 = this.offCanvasElement.getAttribute("id"), a2 = m(`[data-fx-offcanvas-overlay][data-offcanvas-el=${s2}]`);
|
|
224
226
|
a2 instanceof HTMLElement && C(a2), this.offCanvasElement.blur(), u(
|
|
225
227
|
this.offCanvasElement,
|
|
226
228
|
this.allowBodyScroll,
|
|
227
229
|
"close"
|
|
228
|
-
), document.removeEventListener("keydown", this.closeWithEsc), !this.allowBodyScroll && !a2 && document.removeEventListener("click", this.closeWhenClickOutSide), (p = (
|
|
230
|
+
), document.removeEventListener("keydown", this.closeWithEsc), !this.allowBodyScroll && !a2 && document.removeEventListener("click", this.closeWhenClickOutSide), (p = (r2 = this.options).onHide) == null || p.call(r2), v(this.offCanvasElement, "offcanvas-close", { offcanvasId: this.offCanvasElement.id });
|
|
229
231
|
});
|
|
230
232
|
o(this, "closeWithEsc", (e2) => {
|
|
231
233
|
e2.key === "Escape" && (e2.preventDefault(), this.closeOffCanvas());
|
|
232
234
|
});
|
|
235
|
+
o(this, "closeFromCloseBtn", (e2) => {
|
|
236
|
+
e2.target.blur(), this.closeOffCanvas();
|
|
237
|
+
});
|
|
233
238
|
o(this, "changeState", () => {
|
|
234
239
|
this.offCanvasElement.getAttribute("data-state") === "open" ? this.closeOffCanvas() : this.openOffCanvas();
|
|
235
240
|
});
|
|
241
|
+
o(this, "open", () => {
|
|
242
|
+
this.openOffCanvas();
|
|
243
|
+
});
|
|
244
|
+
o(this, "close", () => {
|
|
245
|
+
this.closeOffCanvas();
|
|
246
|
+
});
|
|
236
247
|
o(this, "setOptions", ({ allowBodyscroll: e2 }) => {
|
|
237
248
|
e2 !== void 0 && (this.allowBodyScroll = e2);
|
|
238
249
|
});
|
|
@@ -244,65 +255,42 @@ var f = class f2 {
|
|
|
244
255
|
if (a)
|
|
245
256
|
return a;
|
|
246
257
|
d.setup(this.offCanvasElement), this.options = n;
|
|
247
|
-
const { staticBackdrop: i, allowBodyScroll: l, backdrop:
|
|
258
|
+
const { staticBackdrop: i, allowBodyScroll: l, backdrop: c } = this.options;
|
|
248
259
|
this.setupAttributes(), this.staticBackdrop = i || s.hasAttribute("data-static-backdrop") && s.dataset.staticBackdrop !== "false" || false, this.allowBodyScroll = l || s.hasAttribute("data-allow-body-scroll") && s.dataset.allowBodyScroll !== "false" || false;
|
|
249
|
-
const
|
|
250
|
-
|
|
260
|
+
const r = this.offCanvasElement.getAttribute("id");
|
|
261
|
+
if (!r || r === "")
|
|
262
|
+
throw new Error("\u274C id is required but missing on element:");
|
|
263
|
+
this.offCanvasId = r, this.offCanvasTriggers = this.findOffCanvasElements("[data-offcanvas-trigger]", false, r), this.offCanvasCloseBtns = this.findOffCanvasElements("[data-offcanvas-close]", true, r, this.offCanvasElement), this.backdrop = c || this.offCanvasElement.dataset.offcanvasBackdrop || "", this.dispatchEventToDocument = this.dispatchEventToDocument = this.options.dispatchEventToDocument || true, this.teleporter = A(this.offCanvasElement, document.body, "move"), this.setupOffcanvas(), this.moveElOnInit(), d.register("offcanvas", this.offCanvasElement, this), d.initialized(this.offCanvasElement);
|
|
251
264
|
}
|
|
252
265
|
findOffCanvasElements(e, n, s, a) {
|
|
253
|
-
return n ?
|
|
266
|
+
return n ? h(`${e}`, a) : h(`${e}[data-target=${s}]`);
|
|
254
267
|
}
|
|
255
268
|
setupAttributes() {
|
|
256
269
|
this.offCanvasElement.hasAttribute("data-fx-offcanvas") || this.offCanvasElement.setAttribute("data-fx-offcanvas", "");
|
|
257
270
|
}
|
|
258
271
|
openOffCanvas() {
|
|
259
272
|
var s, a, i, l;
|
|
260
|
-
(a = (s = this.options).beforeShow) == null || a.call(s),
|
|
273
|
+
(a = (s = this.options).beforeShow) == null || a.call(s), x(this.offCanvasElement), u(
|
|
261
274
|
this.offCanvasElement,
|
|
262
275
|
this.allowBodyScroll,
|
|
263
276
|
"open"
|
|
264
277
|
);
|
|
265
|
-
const e = this.offCanvasElement.getAttribute("id"), n =
|
|
278
|
+
const e = this.offCanvasElement.getAttribute("id"), n = L(
|
|
266
279
|
this.backdrop,
|
|
267
280
|
e
|
|
268
281
|
);
|
|
269
|
-
n instanceof HTMLElement && (y({ newElement: n, existingElement: this.offCanvasElement }), this.staticBackdrop || n.addEventListener("click", this.closeOffCanvas)), document.addEventListener("keydown", this.closeWithEsc), (l = (i = this.options).onShow) == null || l.call(i),
|
|
282
|
+
n instanceof HTMLElement && (y({ newElement: n, existingElement: this.offCanvasElement }), this.staticBackdrop || n.addEventListener("click", this.closeOffCanvas)), document.addEventListener("keydown", this.closeWithEsc), (l = (i = this.options).onShow) == null || l.call(i), v(this.offCanvasElement, "offcanvas-open", { offcanvasId: this.offCanvasElement.id });
|
|
270
283
|
}
|
|
271
284
|
initCloseBtns() {
|
|
272
285
|
for (const e of this.offCanvasCloseBtns)
|
|
273
|
-
e.addEventListener("click", this.
|
|
286
|
+
e.addEventListener("click", this.closeFromCloseBtn);
|
|
274
287
|
}
|
|
275
288
|
initTriggers() {
|
|
276
289
|
for (const e of this.offCanvasTriggers)
|
|
277
290
|
e.addEventListener("click", this.changeState);
|
|
278
291
|
}
|
|
279
292
|
setupOffcanvas() {
|
|
280
|
-
this.initTriggers(), this.initCloseBtns();
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Opens the offcanvas element.
|
|
284
|
-
* @example
|
|
285
|
-
* ```ts
|
|
286
|
-
* const offcanvas = new Offcanvas('#sidebar');
|
|
287
|
-
* offcanvas.open();
|
|
288
|
-
* ```
|
|
289
|
-
*/
|
|
290
|
-
open() {
|
|
291
|
-
this.openOffCanvas();
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Closes the offcanvas element.
|
|
295
|
-
* This method will trigger the beforeHide callback if provided,
|
|
296
|
-
* remove the backdrop if present, and finally trigger the onHide callback.
|
|
297
|
-
*
|
|
298
|
-
* @example
|
|
299
|
-
* ```ts
|
|
300
|
-
* const offcanvas = new Offcanvas('#sidebar');
|
|
301
|
-
* offcanvas.close();
|
|
302
|
-
* ```
|
|
303
|
-
*/
|
|
304
|
-
close() {
|
|
305
|
-
this.closeOffCanvas();
|
|
293
|
+
this.initTriggers(), this.initCloseBtns(), this.dispatchEventToDocument && document.addEventListener(`sheet:${this.offCanvasId}:open`, this.open), this.dispatchEventToDocument && document.addEventListener(`sheet:${this.offCanvasId}:close`, this.close);
|
|
306
294
|
}
|
|
307
295
|
/**
|
|
308
296
|
* Cleans up the offcanvas instance by removing event listeners and references.
|
|
@@ -320,11 +308,11 @@ var f = class f2 {
|
|
|
320
308
|
e.removeEventListener("click", this.changeState);
|
|
321
309
|
for (const e of this.offCanvasCloseBtns)
|
|
322
310
|
e.removeEventListener("click", this.closeOffCanvas);
|
|
323
|
-
document.removeEventListener("keydown", this.closeWithEsc), this.allowBodyScroll || document.removeEventListener("click", this.closeWhenClickOutSide), d.removeInstance("offcanvas", this.offCanvasElement);
|
|
311
|
+
document.removeEventListener("keydown", this.closeWithEsc), this.allowBodyScroll || document.removeEventListener("click", this.closeWhenClickOutSide), this.dispatchEventToDocument && document.removeEventListener(`sheet:${this.offCanvasId}:open`, this.open), this.dispatchEventToDocument && document.removeEventListener(`sheet:${this.offCanvasId}:close`, this.close), d.removeInstance("offcanvas", this.offCanvasElement);
|
|
324
312
|
}
|
|
325
313
|
};
|
|
326
314
|
o(f, "autoInit", (e = "[data-fx-offcanvas]") => {
|
|
327
|
-
const n =
|
|
315
|
+
const n = h(e);
|
|
328
316
|
for (const s of n)
|
|
329
317
|
new f(s);
|
|
330
318
|
}), /**
|
package/dist/module.esm.js
CHANGED
|
@@ -3,7 +3,7 @@ var g = Object.defineProperty;
|
|
|
3
3
|
var w = (t, e, n) => e in t ? g(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n;
|
|
4
4
|
var o = (t, e, n) => w(t, typeof e != "symbol" ? e + "" : e, n);
|
|
5
5
|
var m = (t, e = document.body) => e.querySelector(t);
|
|
6
|
-
var
|
|
6
|
+
var h = (t, e = document.body) => Array.from(e.querySelectorAll(t));
|
|
7
7
|
var y = ({
|
|
8
8
|
newElement: t,
|
|
9
9
|
existingElement: e
|
|
@@ -24,10 +24,10 @@ var k = ({
|
|
|
24
24
|
}) => {
|
|
25
25
|
const a = getComputedStyle(t), i = a.transition;
|
|
26
26
|
if (i !== "none" && i !== "" && !s.includes(i)) {
|
|
27
|
-
const l = "transitionend",
|
|
28
|
-
t.removeEventListener(l,
|
|
27
|
+
const l = "transitionend", c = () => {
|
|
28
|
+
t.removeEventListener(l, c), e();
|
|
29
29
|
};
|
|
30
|
-
t.addEventListener(l,
|
|
30
|
+
t.addEventListener(l, c, { once: true });
|
|
31
31
|
} else
|
|
32
32
|
e();
|
|
33
33
|
};
|
|
@@ -42,11 +42,11 @@ var O = ({
|
|
|
42
42
|
keysCheck: ["all 0s ease 0s", "all"]
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
|
-
var
|
|
45
|
+
var v = (t, e, n) => {
|
|
46
46
|
const s = new CustomEvent(e, { detail: n });
|
|
47
47
|
t.dispatchEvent(s);
|
|
48
48
|
};
|
|
49
|
-
function
|
|
49
|
+
function B(t) {
|
|
50
50
|
const e = () => {
|
|
51
51
|
document.querySelector(
|
|
52
52
|
"[data-fx-component]:not([data-component-initialized])"
|
|
@@ -54,7 +54,7 @@ function A(t) {
|
|
|
54
54
|
};
|
|
55
55
|
e();
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function A(t, e, n = "move") {
|
|
58
58
|
if (!(t instanceof HTMLElement))
|
|
59
59
|
throw new Error("Source element must be an HTMLElement");
|
|
60
60
|
if (!(e instanceof HTMLElement))
|
|
@@ -85,7 +85,7 @@ function B(t, e, n = "move") {
|
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
var
|
|
88
|
+
var I = (t) => {
|
|
89
89
|
var e;
|
|
90
90
|
return (e = t.parentElement) == null ? void 0 : e.removeChild(t);
|
|
91
91
|
};
|
|
@@ -93,11 +93,11 @@ var C = (t) => {
|
|
|
93
93
|
t.setAttribute("data-state", "invisible"), O({
|
|
94
94
|
element: t,
|
|
95
95
|
callback() {
|
|
96
|
-
|
|
96
|
+
I(t);
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
99
|
};
|
|
100
|
-
var
|
|
100
|
+
var L = (t, e) => {
|
|
101
101
|
const n = t;
|
|
102
102
|
if (n === "" || !n)
|
|
103
103
|
return;
|
|
@@ -108,23 +108,23 @@ var x = (t, e) => {
|
|
|
108
108
|
return n !== "" && s.classList.add(...a), s;
|
|
109
109
|
};
|
|
110
110
|
var u = (t, e, n) => {
|
|
111
|
-
t.setAttribute("aria-hidden", n === "open" ? "false" : "true"), t.setAttribute("data-state", n), e ||
|
|
111
|
+
t.setAttribute("aria-hidden", n === "open" ? "false" : "true"), t.setAttribute("data-state", n), e || S(n);
|
|
112
112
|
};
|
|
113
|
-
var
|
|
113
|
+
var S = (t) => {
|
|
114
114
|
document.body.style.overflow = t === "open" ? "hidden" : "", document.body.style.overflowY = t === "open" ? "hidden" : "auto";
|
|
115
115
|
};
|
|
116
|
-
var
|
|
116
|
+
var T = (t, e) => {
|
|
117
117
|
if (t === e)
|
|
118
118
|
return;
|
|
119
119
|
t.setAttribute("aria-hidden", "true"), t.setAttribute("data-state", "close");
|
|
120
120
|
const n = m(`[data-fx-offcanvas-overlay][data-offcanvas-el=${t.getAttribute("id")}]`, t.parentElement);
|
|
121
121
|
n instanceof HTMLElement && C(n);
|
|
122
122
|
};
|
|
123
|
-
var
|
|
124
|
-
const e =
|
|
123
|
+
var x = (t) => {
|
|
124
|
+
const e = h("[data-fx-offcanvas][data-state=open]");
|
|
125
125
|
if (!(e.length <= 0))
|
|
126
126
|
for (const n of e)
|
|
127
|
-
|
|
127
|
+
T(n, t);
|
|
128
128
|
};
|
|
129
129
|
var d = class {
|
|
130
130
|
static initGlobalRegistry() {
|
|
@@ -173,41 +173,52 @@ var f = class f2 {
|
|
|
173
173
|
o(this, "offCanvasElement");
|
|
174
174
|
o(this, "offCanvasTriggers");
|
|
175
175
|
o(this, "offCanvasCloseBtns");
|
|
176
|
+
o(this, "offCanvasId", "");
|
|
177
|
+
o(this, "dispatchEventToDocument");
|
|
176
178
|
o(this, "allowBodyScroll");
|
|
177
179
|
o(this, "staticBackdrop");
|
|
178
180
|
o(this, "backdrop");
|
|
179
181
|
o(this, "options");
|
|
180
182
|
o(this, "teleporter");
|
|
181
183
|
o(this, "moveElOnInit", () => {
|
|
182
|
-
|
|
184
|
+
B(() => this.teleporter.append());
|
|
183
185
|
});
|
|
184
186
|
o(this, "closeWhenClickOutSide", (e2) => {
|
|
185
187
|
const n2 = this.offCanvasElement.getAttribute("data-state") === "open", s2 = !this.offCanvasElement.contains(e2.target) && ![...this.offCanvasTriggers].includes(e2.target);
|
|
186
188
|
n2 && s2 && this.closeOffCanvas();
|
|
187
189
|
});
|
|
188
190
|
o(this, "closeOffCanvas", () => {
|
|
189
|
-
var i2, l2,
|
|
191
|
+
var i2, l2, c2, r2, p;
|
|
190
192
|
let e2 = false;
|
|
191
|
-
if (
|
|
193
|
+
if (v(this.offCanvasElement, "offcanvas-before-hide", {
|
|
192
194
|
offcanvasId: this.offCanvasElement.id,
|
|
193
195
|
setExitAction: (b) => {
|
|
194
196
|
e2 = b;
|
|
195
197
|
}
|
|
196
|
-
}), ((
|
|
198
|
+
}), ((c2 = (l2 = (i2 = this.options).beforeHide) == null ? void 0 : l2.call(i2)) == null ? void 0 : c2.cancelAction) || e2)
|
|
197
199
|
return;
|
|
198
200
|
const s2 = this.offCanvasElement.getAttribute("id"), a2 = m(`[data-fx-offcanvas-overlay][data-offcanvas-el=${s2}]`);
|
|
199
201
|
a2 instanceof HTMLElement && C(a2), this.offCanvasElement.blur(), u(
|
|
200
202
|
this.offCanvasElement,
|
|
201
203
|
this.allowBodyScroll,
|
|
202
204
|
"close"
|
|
203
|
-
), document.removeEventListener("keydown", this.closeWithEsc), !this.allowBodyScroll && !a2 && document.removeEventListener("click", this.closeWhenClickOutSide), (p = (
|
|
205
|
+
), document.removeEventListener("keydown", this.closeWithEsc), !this.allowBodyScroll && !a2 && document.removeEventListener("click", this.closeWhenClickOutSide), (p = (r2 = this.options).onHide) == null || p.call(r2), v(this.offCanvasElement, "offcanvas-close", { offcanvasId: this.offCanvasElement.id });
|
|
204
206
|
});
|
|
205
207
|
o(this, "closeWithEsc", (e2) => {
|
|
206
208
|
e2.key === "Escape" && (e2.preventDefault(), this.closeOffCanvas());
|
|
207
209
|
});
|
|
210
|
+
o(this, "closeFromCloseBtn", (e2) => {
|
|
211
|
+
e2.target.blur(), this.closeOffCanvas();
|
|
212
|
+
});
|
|
208
213
|
o(this, "changeState", () => {
|
|
209
214
|
this.offCanvasElement.getAttribute("data-state") === "open" ? this.closeOffCanvas() : this.openOffCanvas();
|
|
210
215
|
});
|
|
216
|
+
o(this, "open", () => {
|
|
217
|
+
this.openOffCanvas();
|
|
218
|
+
});
|
|
219
|
+
o(this, "close", () => {
|
|
220
|
+
this.closeOffCanvas();
|
|
221
|
+
});
|
|
211
222
|
o(this, "setOptions", ({ allowBodyscroll: e2 }) => {
|
|
212
223
|
e2 !== void 0 && (this.allowBodyScroll = e2);
|
|
213
224
|
});
|
|
@@ -219,65 +230,42 @@ var f = class f2 {
|
|
|
219
230
|
if (a)
|
|
220
231
|
return a;
|
|
221
232
|
d.setup(this.offCanvasElement), this.options = n;
|
|
222
|
-
const { staticBackdrop: i, allowBodyScroll: l, backdrop:
|
|
233
|
+
const { staticBackdrop: i, allowBodyScroll: l, backdrop: c } = this.options;
|
|
223
234
|
this.setupAttributes(), this.staticBackdrop = i || s.hasAttribute("data-static-backdrop") && s.dataset.staticBackdrop !== "false" || false, this.allowBodyScroll = l || s.hasAttribute("data-allow-body-scroll") && s.dataset.allowBodyScroll !== "false" || false;
|
|
224
|
-
const
|
|
225
|
-
|
|
235
|
+
const r = this.offCanvasElement.getAttribute("id");
|
|
236
|
+
if (!r || r === "")
|
|
237
|
+
throw new Error("\u274C id is required but missing on element:");
|
|
238
|
+
this.offCanvasId = r, this.offCanvasTriggers = this.findOffCanvasElements("[data-offcanvas-trigger]", false, r), this.offCanvasCloseBtns = this.findOffCanvasElements("[data-offcanvas-close]", true, r, this.offCanvasElement), this.backdrop = c || this.offCanvasElement.dataset.offcanvasBackdrop || "", this.dispatchEventToDocument = this.dispatchEventToDocument = this.options.dispatchEventToDocument || true, this.teleporter = A(this.offCanvasElement, document.body, "move"), this.setupOffcanvas(), this.moveElOnInit(), d.register("offcanvas", this.offCanvasElement, this), d.initialized(this.offCanvasElement);
|
|
226
239
|
}
|
|
227
240
|
findOffCanvasElements(e, n, s, a) {
|
|
228
|
-
return n ?
|
|
241
|
+
return n ? h(`${e}`, a) : h(`${e}[data-target=${s}]`);
|
|
229
242
|
}
|
|
230
243
|
setupAttributes() {
|
|
231
244
|
this.offCanvasElement.hasAttribute("data-fx-offcanvas") || this.offCanvasElement.setAttribute("data-fx-offcanvas", "");
|
|
232
245
|
}
|
|
233
246
|
openOffCanvas() {
|
|
234
247
|
var s, a, i, l;
|
|
235
|
-
(a = (s = this.options).beforeShow) == null || a.call(s),
|
|
248
|
+
(a = (s = this.options).beforeShow) == null || a.call(s), x(this.offCanvasElement), u(
|
|
236
249
|
this.offCanvasElement,
|
|
237
250
|
this.allowBodyScroll,
|
|
238
251
|
"open"
|
|
239
252
|
);
|
|
240
|
-
const e = this.offCanvasElement.getAttribute("id"), n =
|
|
253
|
+
const e = this.offCanvasElement.getAttribute("id"), n = L(
|
|
241
254
|
this.backdrop,
|
|
242
255
|
e
|
|
243
256
|
);
|
|
244
|
-
n instanceof HTMLElement && (y({ newElement: n, existingElement: this.offCanvasElement }), this.staticBackdrop || n.addEventListener("click", this.closeOffCanvas)), document.addEventListener("keydown", this.closeWithEsc), (l = (i = this.options).onShow) == null || l.call(i),
|
|
257
|
+
n instanceof HTMLElement && (y({ newElement: n, existingElement: this.offCanvasElement }), this.staticBackdrop || n.addEventListener("click", this.closeOffCanvas)), document.addEventListener("keydown", this.closeWithEsc), (l = (i = this.options).onShow) == null || l.call(i), v(this.offCanvasElement, "offcanvas-open", { offcanvasId: this.offCanvasElement.id });
|
|
245
258
|
}
|
|
246
259
|
initCloseBtns() {
|
|
247
260
|
for (const e of this.offCanvasCloseBtns)
|
|
248
|
-
e.addEventListener("click", this.
|
|
261
|
+
e.addEventListener("click", this.closeFromCloseBtn);
|
|
249
262
|
}
|
|
250
263
|
initTriggers() {
|
|
251
264
|
for (const e of this.offCanvasTriggers)
|
|
252
265
|
e.addEventListener("click", this.changeState);
|
|
253
266
|
}
|
|
254
267
|
setupOffcanvas() {
|
|
255
|
-
this.initTriggers(), this.initCloseBtns();
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Opens the offcanvas element.
|
|
259
|
-
* @example
|
|
260
|
-
* ```ts
|
|
261
|
-
* const offcanvas = new Offcanvas('#sidebar');
|
|
262
|
-
* offcanvas.open();
|
|
263
|
-
* ```
|
|
264
|
-
*/
|
|
265
|
-
open() {
|
|
266
|
-
this.openOffCanvas();
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Closes the offcanvas element.
|
|
270
|
-
* This method will trigger the beforeHide callback if provided,
|
|
271
|
-
* remove the backdrop if present, and finally trigger the onHide callback.
|
|
272
|
-
*
|
|
273
|
-
* @example
|
|
274
|
-
* ```ts
|
|
275
|
-
* const offcanvas = new Offcanvas('#sidebar');
|
|
276
|
-
* offcanvas.close();
|
|
277
|
-
* ```
|
|
278
|
-
*/
|
|
279
|
-
close() {
|
|
280
|
-
this.closeOffCanvas();
|
|
268
|
+
this.initTriggers(), this.initCloseBtns(), this.dispatchEventToDocument && document.addEventListener(`sheet:${this.offCanvasId}:open`, this.open), this.dispatchEventToDocument && document.addEventListener(`sheet:${this.offCanvasId}:close`, this.close);
|
|
281
269
|
}
|
|
282
270
|
/**
|
|
283
271
|
* Cleans up the offcanvas instance by removing event listeners and references.
|
|
@@ -295,11 +283,11 @@ var f = class f2 {
|
|
|
295
283
|
e.removeEventListener("click", this.changeState);
|
|
296
284
|
for (const e of this.offCanvasCloseBtns)
|
|
297
285
|
e.removeEventListener("click", this.closeOffCanvas);
|
|
298
|
-
document.removeEventListener("keydown", this.closeWithEsc), this.allowBodyScroll || document.removeEventListener("click", this.closeWhenClickOutSide), d.removeInstance("offcanvas", this.offCanvasElement);
|
|
286
|
+
document.removeEventListener("keydown", this.closeWithEsc), this.allowBodyScroll || document.removeEventListener("click", this.closeWhenClickOutSide), this.dispatchEventToDocument && document.removeEventListener(`sheet:${this.offCanvasId}:open`, this.open), this.dispatchEventToDocument && document.removeEventListener(`sheet:${this.offCanvasId}:close`, this.close), d.removeInstance("offcanvas", this.offCanvasElement);
|
|
299
287
|
}
|
|
300
288
|
};
|
|
301
289
|
o(f, "autoInit", (e = "[data-fx-offcanvas]") => {
|
|
302
|
-
const n =
|
|
290
|
+
const n = h(e);
|
|
303
291
|
for (const s of n)
|
|
304
292
|
new f(s);
|
|
305
293
|
}), /**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flexilla/alpine-offcanvas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "AlpineJS plugin for adding offcanvas functionality to your AlpineJS components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
],
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@flexilla/alpine-offcanvas": "^0.0.3",
|
|
64
|
-
"@flexilla/offcanvas": "^2.
|
|
64
|
+
"@flexilla/offcanvas": "^2.2.0"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "c8e56ff1b93e24b1ab969b09b35afab38ca71d4c"
|
|
67
67
|
}
|