@frontify/fondue
Version:
Design system of Frontify
90 lines (89 loc) • 3.34 kB
JavaScript
import { ROOT_ID as C } from "./constants.es.js";
import { CheckboxState as x } from "../../Checkbox/Checkbox.es.js";
const _ = (o, n) => {
let l = x.Unchecked;
return o ? l = x.Checked : n && (l = x.Mixed), l;
}, P = (o, n, l = !1) => o.filter(
(f) => (l ? !1 : n.includes(c(f))) || n.includes(a([c(f)])[0])
).map((f) => f.id), E = (o, n) => {
var l;
for (const f of o) {
if (f.id === n)
return f;
if (f.nodes && ((l = f.nodes) == null ? void 0 : l.length) > 0) {
const r = E(f.nodes, n);
if (r)
return r;
}
}
return null;
}, b = (o, n, l) => {
var f;
for (const r of o) {
if (l !== null && r.id === n)
return l;
if (r.nodes && ((f = r.nodes) == null ? void 0 : f.length) > 0) {
const i = b(r.nodes, n, r);
if (i)
return i;
}
}
return null;
}, M = (o, n, l) => {
var $, B;
const f = b(o, n, null);
l = f != null && f.id ? F(f, l) : l;
const r = E(o, n);
if (!r)
return l;
const i = c(r), u = P((r == null ? void 0 : r.nodes) ?? [], l);
if ((($ = r == null ? void 0 : r.nodes) == null ? void 0 : $.length) ?? 0) {
const s = ((B = r == null ? void 0 : r.nodes) == null ? void 0 : B.map((y) => c(y))) ?? [];
l = l.includes(i) ? g(l, s, !1) : t(l, s, !1), u.length === 0 && (l = t(l, [i], !0));
}
for (const s of (r == null ? void 0 : r.nodes) ?? [])
l = M(o, s.id, l);
let h = f;
const O = [];
for (; h !== null; )
O.push(h), h = b(o, h.id, null);
for (const s of O)
l = F(s, l);
return l;
}, F = (o, n) => {
var d;
const l = c(o), f = n.includes(l), r = P((o == null ? void 0 : o.nodes) ?? [], n), i = P((o == null ? void 0 : o.nodes) ?? [], n, !0), u = ((d = o == null ? void 0 : o.nodes) == null ? void 0 : d.length) ?? 0;
return r.length === 0 ? (n = f ? t(n, [l], !1) : n, n = t(n, [l], !0)) : r.length === u && i.length === 0 ? (n = f ? n : g(n, [l], !1), n = t(n, [l], !0)) : o != null && o.id && (n = g(n, [l], !0), n = t(n, [l], !1)), n;
}, p = (o) => {
const n = [];
let l = o;
const f = o.map((r) => r.split("/").pop());
for (const r of o) {
const i = r.split("/").shift();
i === C || i === a([C])[0] || !f.includes(i) && !f.includes(D([i ?? ""])[0] ?? "") && n.push(r);
}
return n.length > 0 && (l = t(o, n, !1), l = p(l)), l;
}, a = (o) => o.map((n) => `*${n}`), D = (o) => o.map((n) => n.replace(/^\*/, "")), c = (o) => o.extendedId ?? `${o.parentId}/${o.id}`, t = (o, n, l) => (n = l ? a(n) : n, [...new Set(n.length > 0 ? o.filter((f) => !n.includes(f)) : o)]), g = (o, n, l) => (n = (l ? a(n) : n).filter((f) => f !== ""), [...new Set(n.length > 0 ? [...o, ...n] : o)]), j = (o, n, l, f = !1) => {
let r = [];
const i = E(l, o);
if (!i)
return n;
const u = c(i);
return n.includes(u) && !f ? r = t(n, [u], !1) : (r = g(n, [u], !1), r = t(r, [u], !0)), r = M(l, o, r), p(r);
};
export {
g as addSelectedIds,
M as addSelectedItemsFromSelection,
p as cleanOrphanSelectedIds,
a as convertToPartialSelectedId,
F as fixParentSelectionState,
c as getExtendedId,
_ as getMultiselectCheckBoxState,
j as getNewSelectedItems,
b as getParentSelectedTreeItem,
P as getSelectedChildrenItems,
E as getSelectedTreeItem,
D as removePartialFlagSelectedId,
t as removeSelectedIds
};
//# sourceMappingURL=multiselect.es.js.map