UNPKG

@blocklet/ui-react

Version:

Some useful front-end web components that can be used in Blocklets.

62 lines (61 loc) 2.19 kB
import H from "semver"; const d = (n, r, e = "children") => n.map((t) => Array.isArray(t[e]) ? r({ ...t, [e]: d(t[e], r, e) }) : r(t)), C = (n, r = "children") => { const e = []; return d(n, (t) => e.push(t), r), e; }, S = (n, r = "children") => { let e = 0; return d(n, () => e++, r), e; }, R = (n, r, e = "children") => n.map((t) => ({ ...t })).filter((t) => { const s = t[e]; if (Array.isArray(s)) { const o = R(s, r, e); t[e] = o?.length ? o : void 0; } const c = { filteredChildren: t[e], isLeaf: !s?.length }; return r(t, c); }), x = (n) => /^https?:\/\//.test(n), P = (n) => /^[\w-]+:[\w-]+$/.test(n), V = (n) => { if (!n || !n?.startsWith("/")) return !1; const r = (s) => s.endsWith("/") ? s : `${s}/`, e = r(window.location.pathname), t = r(new URL(n, window.location.origin).pathname); return e.startsWith(t); }, W = (n = []) => { const r = n.map((t, s) => ({ path: t, index: s })).filter((t) => V(t.path)); return r?.length ? r.slice(1).reduce((t, s) => t.path.length >= s.path.length ? t : s, r[0]).index : -1; }, k = (n, r = {}) => { const { columns: e = 1, breakInside: t = !1, groupHeight: s = 48, itemHeight: c = 24, childrenKey: o = "items" } = r, p = n.reduce((u, g) => u + s + (g[o]?.length || 0) * c, 0), l = Math.ceil(p / e), h = [[]]; let i = 0, a = 0; const m = l * 0.2, f = (u) => a > l - m && i < e - 1 && a + u > l + m; return n.forEach((u) => { const g = s + (u[o]?.length || 0) * c; t && f(s) && (i++, a = 0, h[i] = []), !t && a > 0 && f(g) && (i++, a = 0, h[i] = []), h[i].push({ ...u, group: !0 }), a += s, u[o] && u[o].forEach((w) => { t && f(c) && (i++, a = 0, h[i] = []), h[i].push({ ...w, group: !1 }), a += c; }); }), h; }, v = (n, r) => { const e = (c) => { const o = c.match(/^(\d+\.\d+\.\d+(?:-[^-]+?-\d{8}))/); return o ? o[1] : c; }, t = e(n), s = e(r); return t === s && n !== r ? !1 : H.gte(t, s); }; export { v as compareVersions, S as countRecursive, R as filterRecursive, C as flatRecursive, P as isIconifyString, x as isUrl, d as mapRecursive, V as matchPath, W as matchPaths, k as splitNavColumns };