@flexilla/utilities
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -1,14 +0,16 @@ | ||
import { keyboardNavigation as e } from "./accessibility.js"; | ||
import { toggleDataAttribute as a } from "./toggler.js"; | ||
import { $ as i, $$ as p, $d as m } from "./selector.js"; | ||
import { afterTransition as x, appendBefore as $, setAttributes as b } from "./dom-utilities.js"; | ||
import { keyboardNavigation as r } from "./accessibility.js"; | ||
import { actionToggler as a } from "./toggler.js"; | ||
import { $ as n, $$ as f, $d as p } from "./selector.js"; | ||
import { afterAnimation as s, afterTransition as d, appendBefore as x, dispatchCustomEvent as $, setAttributes as g } from "./dom-utilities.js"; | ||
export { | ||
i as $, | ||
p as $$, | ||
m as $d, | ||
x as afterTransition, | ||
$ as appendBefore, | ||
e as keyboardNavigation, | ||
b as setAttributes, | ||
a as toggleDataAttribute | ||
n as $, | ||
f as $$, | ||
p as $d, | ||
a as actionToggler, | ||
s as afterAnimation, | ||
d as afterTransition, | ||
x as appendBefore, | ||
$ as dispatchCustomEvent, | ||
r as keyboardNavigation, | ||
g as setAttributes | ||
}; |
@@ -1,2 +0,2 @@ | ||
export declare const keyboardNavigation: ({ element, targetChildren, direction }: KeyDirAccessibilityOptions) => { | ||
export declare const keyboardNavigation: ({ containerElement, targetChildren, direction }: KeyDirAccessibilityOptions) => { | ||
make: () => void; | ||
@@ -7,4 +7,4 @@ destroy: () => void; | ||
export declare type KeyDirAccessibilityOptions = { | ||
element: HTMLElement | string; | ||
targetChildren?: string; | ||
containerElement?: HTMLElement | string; | ||
targetChildren?: string | HTMLElement[]; | ||
direction: "up-down" | "left-right" | "all"; | ||
@@ -11,0 +11,0 @@ }; |
@@ -1,38 +0,43 @@ | ||
import { $getEl as p, $$ as b } from "./selector.js"; | ||
const m = ({ element: c, targetChildren: k = "a:not([disabled]), button:not([disabled])", direction: r }) => { | ||
const o = p(c), t = b(k, o), l = (a) => { | ||
if (t.length === 0) | ||
import { $getEl as m, $$ as w } from "./selector.js"; | ||
const A = ({ containerElement: b, targetChildren: a = "a:not([disabled]), button:not([disabled])", direction: n }) => { | ||
let s = !1; | ||
const l = m(b) || document.body, t = typeof a == "string" ? w(a, l) : a, f = (r) => { | ||
if (r.preventDefault(), l.focus(), t.length === 0) return; | ||
const c = r.key, u = document.activeElement; | ||
let e = t.findIndex((o) => o === u); | ||
if (e === -1) { | ||
c === "ArrowUp" || c === "ArrowLeft" ? t[t.length - 1].focus() : t[0].focus(); | ||
return; | ||
const s = a.key, g = document.activeElement; | ||
let e = t.findIndex((n) => n === g); | ||
e === -1 && (s === "ArrowUp" ? t[t.length - 1].focus() : t[0].focus()); | ||
const f = (n) => n > 0 ? n - 1 : t.length - 1, u = (n) => n < t.length - 1 ? n + 1 : 0; | ||
switch (s) { | ||
} | ||
const i = (o) => o > 0 ? o - 1 : t.length - 1, d = (o) => o < t.length - 1 ? o + 1 : 0, p = n === "all" || n === "up-down", k = n === "all" || n === "left-right"; | ||
switch (c) { | ||
case "ArrowDown": | ||
a.preventDefault(), (r === "all" || r === "up-down") && (e = u(e)); | ||
p && (r.preventDefault(), e = d(e)); | ||
break; | ||
case "ArrowRight": | ||
a.preventDefault(), (r === "all" || r === "left-right") && (e = u(e)); | ||
k && (r.preventDefault(), e = d(e)); | ||
break; | ||
case "ArrowUp": | ||
a.preventDefault(), (r === "all" || r === "up-down") && (e = f(e)); | ||
p && (r.preventDefault(), e = i(e)); | ||
break; | ||
case "ArrowLeft": | ||
a.preventDefault(), (r === "all" || r === "left-right") && (e = f(e)); | ||
k && (r.preventDefault(), e = i(e)); | ||
break; | ||
case "Home": | ||
a.preventDefault(), e = 0; | ||
r.preventDefault(), e = 0; | ||
break; | ||
case "End": | ||
a.preventDefault(), e = t.length - 1; | ||
r.preventDefault(), e = t.length - 1; | ||
break; | ||
default: | ||
return; | ||
} | ||
t[e].focus(); | ||
t[e] !== u && t[e].focus(); | ||
}; | ||
return { | ||
make: () => { | ||
o.addEventListener("keydown", l); | ||
s || (document.addEventListener("keydown", f), s = !0); | ||
}, | ||
destroy: () => { | ||
o.removeEventListener("keydown", l); | ||
s && (document.removeEventListener("keydown", f), s = !1); | ||
} | ||
@@ -42,3 +47,3 @@ }; | ||
export { | ||
m as keyboardNavigation | ||
A as keyboardNavigation | ||
}; |
@@ -0,1 +1,6 @@ | ||
export declare const afterAnimation: ({ element, callback, }: { | ||
element: HTMLElement; | ||
callback: () => void; | ||
}) => void; | ||
export declare const afterTransition: ({ element, callback, }: { | ||
@@ -11,4 +16,6 @@ element: HTMLElement; | ||
export declare const dispatchCustomEvent: <T extends object>(element: HTMLElement, eventName: string, detail: T) => void; | ||
export declare const setAttributes: (element: HTMLElement, attributes: Record<string, string>) => void; | ||
export { } |
@@ -1,32 +0,54 @@ | ||
const o = ({ | ||
const m = ({ | ||
newElement: t, | ||
existingElement: n | ||
existingElement: e | ||
}) => { | ||
if (!(t instanceof HTMLElement) || !(n instanceof HTMLElement)) | ||
if (!(t instanceof HTMLElement) || !(e instanceof HTMLElement)) | ||
throw new Error("Both parameters must be valid HTML elements."); | ||
const e = n.parentElement; | ||
if (e) | ||
e.insertBefore(t, n); | ||
else | ||
throw new Error("Existing element must have a parent element."); | ||
}, s = (t, n) => { | ||
for (const [e, r] of Object.entries(n)) | ||
t.setAttribute(e, r); | ||
}, i = ({ | ||
const n = e.parentElement; | ||
if (n) n.insertBefore(t, e); | ||
else throw new Error("Existing element must have a parent element."); | ||
}, l = (t, e) => { | ||
for (const [n, o] of Object.entries(e)) | ||
t.setAttribute(n, o); | ||
}, c = ({ | ||
element: t, | ||
callback: n | ||
callback: e, | ||
type: n, | ||
keysCheck: o | ||
}) => { | ||
const e = getComputedStyle(t).transition; | ||
e !== "none" && e !== "" && e !== "all 0s ease 0s" && e !== "all" ? t.addEventListener( | ||
"transitionend", | ||
function r() { | ||
t.removeEventListener("transitionend", r), n(); | ||
}, | ||
{ once: !0 } | ||
) : n(); | ||
const i = getComputedStyle(t), s = n === "transition" ? i.transition : i.animation; | ||
if (s !== "none" && s !== "" && !o.includes(s)) { | ||
const a = n === "transition" ? "transitionend" : "animationend", r = () => { | ||
t.removeEventListener(a, r), e(); | ||
}; | ||
t.addEventListener(a, r, { once: !0 }); | ||
} else | ||
e(); | ||
}, u = ({ | ||
element: t, | ||
callback: e | ||
}) => { | ||
c({ | ||
element: t, | ||
callback: e, | ||
type: "transition", | ||
keysCheck: ["all 0s ease 0s", "all"] | ||
}); | ||
}, d = ({ element: t, callback: e }) => { | ||
c({ | ||
element: t, | ||
callback: e, | ||
type: "animation", | ||
keysCheck: ["none 0s ease 0s 1 normal none running"] | ||
}); | ||
}, f = (t, e, n) => { | ||
const o = new CustomEvent(e, { detail: n }); | ||
t.dispatchEvent(o); | ||
}; | ||
export { | ||
i as afterTransition, | ||
o as appendBefore, | ||
s as setAttributes | ||
d as afterAnimation, | ||
u as afterTransition, | ||
m as appendBefore, | ||
f as dispatchCustomEvent, | ||
l as setAttributes | ||
}; |
@@ -0,1 +1,3 @@ | ||
export declare const actionToggler: (options: TogglerOptions) => void; | ||
declare type AttributeMap = { | ||
@@ -5,13 +7,16 @@ [key: string]: string; | ||
export declare const toggleDataAttribute: (options: TogglerOptions) => void; | ||
export declare type TogglerOptions = { | ||
trigger: HTMLElement | string; | ||
target: HTMLElement | string; | ||
attributes: { | ||
from: AttributeMap; | ||
to: AttributeMap; | ||
}; | ||
onToggle?: ({ isExpanded }: { | ||
isExpanded: boolean; | ||
}) => void; | ||
targets: { | ||
element: HTMLElement | string; | ||
attributes: { | ||
initial: AttributeMap; | ||
to: AttributeMap; | ||
}; | ||
}[]; | ||
}; | ||
export { } |
@@ -1,13 +0,21 @@ | ||
import { setAttributes as a } from "./dom-utilities.js"; | ||
import { $getEl as r } from "./selector.js"; | ||
const u = (o) => { | ||
const { trigger: i, target: s, attributes: e } = o, n = r(i), g = r(s); | ||
let t = !0; | ||
n.addEventListener("click", () => { | ||
const m = t ? e.from : e.to; | ||
a(g, m), t = !t; | ||
import { setAttributes as o } from "./dom-utilities.js"; | ||
import { $getEl as n } from "./selector.js"; | ||
const u = (l) => { | ||
const { trigger: c, targets: a, onToggle: i } = l, s = n(c); | ||
let t = !1; | ||
(() => { | ||
for (const e of a) { | ||
const r = n(e.element); | ||
o(r, e.attributes.initial), t = !0; | ||
} | ||
})(), s.addEventListener("click", () => { | ||
for (const e of a) { | ||
const r = n(e.element), g = t ? e.attributes.to : e.attributes.initial; | ||
o(r, g); | ||
} | ||
t = !t, i == null || i({ isExpanded: !t }), s.ariaExpanded = t ? "false" : "true"; | ||
}); | ||
}; | ||
export { | ||
u as toggleDataAttribute | ||
u as actionToggler | ||
}; |
@@ -13,2 +13,9 @@ export declare const $$: (selector: string, parentElement?: HTMLElement) => HTMLElement[]; | ||
export declare const actionToggler: (options: TogglerOptions) => void; | ||
export declare const afterAnimation: ({ element, callback, }: { | ||
element: HTMLElement; | ||
callback: () => void; | ||
}) => void; | ||
export declare const afterTransition: ({ element, callback, }: { | ||
@@ -28,3 +35,5 @@ element: HTMLElement; | ||
export declare const keyboardNavigation: ({ element, targetChildren, direction }: KeyDirAccessibilityOptions) => { | ||
export declare const dispatchCustomEvent: <T extends object>(element: HTMLElement, eventName: string, detail: T) => void; | ||
export declare const keyboardNavigation: ({ containerElement, targetChildren, direction }: KeyDirAccessibilityOptions) => { | ||
make: () => void; | ||
@@ -35,4 +44,4 @@ destroy: () => void; | ||
export declare type KeyDirAccessibilityOptions = { | ||
element: HTMLElement | string; | ||
targetChildren?: string; | ||
containerElement?: HTMLElement | string; | ||
targetChildren?: string | HTMLElement[]; | ||
direction: "up-down" | "left-right" | "all"; | ||
@@ -43,13 +52,16 @@ }; | ||
export declare const toggleDataAttribute: (options: TogglerOptions) => void; | ||
export declare type TogglerOptions = { | ||
trigger: HTMLElement | string; | ||
target: HTMLElement | string; | ||
attributes: { | ||
from: AttributeMap; | ||
to: AttributeMap; | ||
}; | ||
onToggle?: ({ isExpanded }: { | ||
isExpanded: boolean; | ||
}) => void; | ||
targets: { | ||
element: HTMLElement | string; | ||
attributes: { | ||
initial: AttributeMap; | ||
to: AttributeMap; | ||
}; | ||
}[]; | ||
}; | ||
export { } |
@@ -1,14 +0,16 @@ | ||
import { keyboardNavigation as e } from "./accessibility.js"; | ||
import { toggleDataAttribute as a } from "./toggler.js"; | ||
import { $ as i, $$ as p, $d as m } from "./selector.js"; | ||
import { afterTransition as x, appendBefore as $, setAttributes as b } from "./dom-utilities.js"; | ||
import { keyboardNavigation as r } from "./accessibility.js"; | ||
import { actionToggler as a } from "./toggler.js"; | ||
import { $ as n, $$ as f, $d as p } from "./selector.js"; | ||
import { afterAnimation as s, afterTransition as d, appendBefore as x, dispatchCustomEvent as $, setAttributes as g } from "./dom-utilities.js"; | ||
export { | ||
i as $, | ||
p as $$, | ||
m as $d, | ||
x as afterTransition, | ||
$ as appendBefore, | ||
e as keyboardNavigation, | ||
b as setAttributes, | ||
a as toggleDataAttribute | ||
n as $, | ||
f as $$, | ||
p as $d, | ||
a as actionToggler, | ||
s as afterAnimation, | ||
d as afterTransition, | ||
x as appendBefore, | ||
$ as dispatchCustomEvent, | ||
r as keyboardNavigation, | ||
g as setAttributes | ||
}; |
{ | ||
"name": "@flexilla/utilities", | ||
"private": false, | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"type": "module", | ||
@@ -99,3 +99,3 @@ "description": "Utilities package for flexilla library", | ||
"author": "johnkat-mj", | ||
"gitHead": "98932fa7279389be90368e974e58fab0fb1ba654" | ||
"gitHead": "2eb26c556c72eb0c607dfc2de61b3ca6ef3128c9" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
16080
292
0