@flexilla/offcanvas
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -47,2 +47,7 @@ declare type BackdropHidden = { | ||
close(): void; | ||
/** | ||
* auto init Offcanvas based on the selector provided | ||
* @param selector {string} default is [data-fx-offcanvas] attribute | ||
*/ | ||
static autoInit: (selector?: string) => void; | ||
} | ||
@@ -49,0 +54,0 @@ |
@@ -1,5 +0,5 @@ | ||
var h = Object.defineProperty; | ||
var m = (e, t, s) => t in e ? h(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s; | ||
var n = (e, t, s) => (m(e, typeof t != "symbol" ? t + "" : t, s), s); | ||
const r = (e, t = document.body) => t.querySelector(e), d = (e, t = document.body) => Array.from(t.querySelectorAll(e)), C = ({ | ||
var C = Object.defineProperty; | ||
var E = (e, t, s) => t in e ? C(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s; | ||
var n = (e, t, s) => (E(e, typeof t != "symbol" ? t + "" : t, s), s); | ||
const f = (e, t = document.body) => t.querySelector(e), c = (e, t = document.body) => Array.from(t.querySelectorAll(e)), u = ({ | ||
newElement: e, | ||
@@ -15,3 +15,3 @@ existingElement: t | ||
throw new Error("Existing element must have a parent element."); | ||
}, u = ({ | ||
}, p = ({ | ||
element: e, | ||
@@ -28,3 +28,3 @@ callback: t | ||
) : t(); | ||
}, E = (e) => { | ||
}, b = (e) => { | ||
if (!e) | ||
@@ -37,12 +37,12 @@ return; | ||
return s || ""; | ||
}, p = (e, t) => { | ||
}, g = (e, t) => { | ||
t.removeChild(e); | ||
}, v = (e, t) => { | ||
u({ | ||
}, m = (e, t) => { | ||
p({ | ||
element: e, | ||
callback() { | ||
p(e, t); | ||
g(e, t); | ||
} | ||
}); | ||
}, b = (e, t, s) => { | ||
}, y = (e, t, s) => { | ||
if (!e && t === "") | ||
@@ -52,24 +52,23 @@ return; | ||
a.setAttribute("aria-hidden", "true"), a.setAttribute("data-state", "visible"), a.setAttribute("data-fx-offcanvas-overlay", ""), a.setAttribute("data-offcanvas-el", s); | ||
const i = E(e), o = i !== "" && i || t; | ||
const i = b(e), o = i !== "" && i || t; | ||
if (o === "") | ||
return; | ||
const l = o.split(" "); | ||
return o !== "" && a.classList.add(...l), a; | ||
}, c = (e, t, s) => { | ||
e.setAttribute("aria-hidden", s === "open" ? "false" : "true"), e.setAttribute("data-state", s), t || g(s); | ||
}, g = (e) => { | ||
const r = o.split(" "); | ||
return o !== "" && a.classList.add(...r), a; | ||
}, v = (e, t, s) => { | ||
e.setAttribute("aria-hidden", s === "open" ? "false" : "true"), e.setAttribute("data-state", s), t || O(s); | ||
}, O = (e) => { | ||
document.body.style.overflow = e === "open" ? "hidden" : "", document.body.style.overflowY = e === "open" ? "hidden" : "auto"; | ||
}, y = (e, t) => { | ||
}, k = (e, t) => { | ||
if (e === t) | ||
return; | ||
e.setAttribute("aria-hidden", "true"), e.setAttribute("data-state", "close"); | ||
const s = r(`[data-fx-offcanvas-overlay][data-offcanvas-el=${e.getAttribute("id")}]`, e.parentElement); | ||
s instanceof HTMLElement && v(s, e.parentElement); | ||
}, O = (e) => { | ||
const t = d("[data-fx-offcanvas][data-state=open]"); | ||
const s = f(`[data-fx-offcanvas-overlay][data-offcanvas-el=${e.getAttribute("id")}]`, e.parentElement); | ||
s instanceof HTMLElement && m(s, e.parentElement); | ||
}, A = (e) => { | ||
const t = c("[data-fx-offcanvas][data-state=open]"); | ||
if (!(t.length <= 0)) | ||
for (const s of t) | ||
y(s, e); | ||
}; | ||
class A { | ||
k(s, e); | ||
}, l = class l { | ||
/** | ||
@@ -88,12 +87,12 @@ * Offcanvas Component | ||
n(this, "backdrop"); | ||
const a = typeof t == "string" ? r(t) : t; | ||
const a = typeof t == "string" ? f(t) : t; | ||
if (!(a instanceof HTMLElement)) | ||
throw new Error("Invalid Offcanvas, the provided Element is not a valid HTMLElement"); | ||
const { staticBackdrop: i, allowBodyScroll: o, backdrop: l } = s; | ||
const { staticBackdrop: i, allowBodyScroll: o, backdrop: r } = s; | ||
this.offCanvasElement = a, this.setupAttributes(), this.staticBackdrop = i || a.hasAttribute("data-static-backdrop") && a.dataset.staticBackdrop !== "false" || !1, this.allowBodyScroll = o || a.hasAttribute("data-allow-body-scroll") && a.dataset.allowBodyScroll !== "false" || !1; | ||
const f = this.offCanvasElement.getAttribute("id"); | ||
this.offCanvasTriggers = this.findOffCanvasElements("[data-offcanvas-trigger]", f), this.offCanvasCloseBtns = this.findOffCanvasElements("[data-offcanvas-close]", f), this.backdrop = l, this.backdropClass = this.offCanvasElement.dataset.offcanvasBackdrop || "", this.init(); | ||
const d = this.offCanvasElement.getAttribute("id"); | ||
this.offCanvasTriggers = this.findOffCanvasElements("[data-offcanvas-trigger]", d), this.offCanvasCloseBtns = this.findOffCanvasElements("[data-offcanvas-close]", d), this.backdrop = r, this.backdropClass = this.offCanvasElement.dataset.offcanvasBackdrop || "", this.init(); | ||
} | ||
findOffCanvasElements(t, s) { | ||
return d(`${t}[data-target=${s}]`); | ||
return c(`${t}[data-target=${s}]`); | ||
} | ||
@@ -111,11 +110,11 @@ setupAttributes() { | ||
closeOffCanvas() { | ||
const t = this.offCanvasElement.getAttribute("id"), s = r(`[data-fx-offcanvas-overlay][data-offcanvas-el=${t}]`, this.offCanvasElement.parentElement); | ||
c( | ||
const t = this.offCanvasElement.getAttribute("id"), s = f(`[data-fx-offcanvas-overlay][data-offcanvas-el=${t}]`, this.offCanvasElement.parentElement); | ||
v( | ||
this.offCanvasElement, | ||
this.allowBodyScroll, | ||
"close" | ||
), s instanceof HTMLElement && v(s, this.offCanvasElement.parentElement), document.removeEventListener("keydown", this.closeWithEsc), !this.allowBodyScroll && !s && document.removeEventListener("click", (a) => this.closeWhenClickOutSide(a)); | ||
), s instanceof HTMLElement && m(s, this.offCanvasElement.parentElement), document.removeEventListener("keydown", this.closeWithEsc), !this.allowBodyScroll && !s && document.removeEventListener("click", (a) => this.closeWhenClickOutSide(a)); | ||
} | ||
openOffCanvas() { | ||
O(this.offCanvasElement), c( | ||
A(this.offCanvasElement), v( | ||
this.offCanvasElement, | ||
@@ -125,3 +124,3 @@ this.allowBodyScroll, | ||
); | ||
const t = this.offCanvasElement.getAttribute("id"), s = b( | ||
const t = this.offCanvasElement.getAttribute("id"), s = y( | ||
this.backdrop, | ||
@@ -131,3 +130,3 @@ this.backdropClass, | ||
); | ||
s instanceof HTMLElement && (C({ newElement: s, existingElement: this.offCanvasElement }), this.staticBackdrop || s.addEventListener("click", () => { | ||
s instanceof HTMLElement && (u({ newElement: s, existingElement: this.offCanvasElement }), this.staticBackdrop || s.addEventListener("click", () => { | ||
this.closeOffCanvas(); | ||
@@ -162,5 +161,15 @@ })), document.addEventListener("keydown", (a) => this.closeWithEsc(a)); | ||
} | ||
} | ||
}; | ||
/** | ||
* auto init Offcanvas based on the selector provided | ||
* @param selector {string} default is [data-fx-offcanvas] attribute | ||
*/ | ||
n(l, "autoInit", (t = "[data-fx-offcanvas]") => { | ||
const s = c(t); | ||
for (const a of s) | ||
new l(a); | ||
}); | ||
let h = l; | ||
export { | ||
A as OffCanvas | ||
h as OffCanvas | ||
}; |
{ | ||
"name": "@flexilla/offcanvas", | ||
"private": false, | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"type": "module", | ||
@@ -68,3 +68,3 @@ "description": "An offcanvas component for creating responsive and off-screen navigation panels in web applications.", | ||
"author": "johnkat-mj", | ||
"gitHead": "b182c7035953bc34e8f350b834df9862bec8acb5" | ||
"gitHead": "8435693ee1ff8e2f9d279b5d4026949530d7d05d" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15521
243