ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
50 lines (49 loc) • 1.37 kB
JavaScript
const h = (t) => !!t.children && t.children.length > 0;
function f(t, e) {
if (!e || e.length === 0 || !t) return;
const i = (l, r = 0) => {
if (r >= e.length) return;
const s = e[r];
for (const c of l)
if (c.path === s)
return r === e.length - 1 ? c : c.children ? i(c.children, r + 1) : void 0;
};
return i(t);
}
function u(t, e, i, l, r) {
const s = e[i], c = i === e.length - 1;
return t.map((n) => {
if (n.path !== s) return n;
if (c)
switch (l) {
case "update":
return { ...n, ...r };
case "delete":
return null;
case "add": {
const o = r, d = n.children ? [...n.children, o] : [o];
return { ...n, children: d };
}
default:
return n;
}
if (n.children) {
const o = u(n.children, e, i + 1, l, r);
return { ...n, children: o.filter(Boolean) };
}
return n;
});
}
function g(t, e, i = !1) {
if (!e) return { node: void 0, isValid: !1 };
const l = Array.isArray(e) ? e.filter(Boolean) : e.split("/").filter(Boolean);
if (l.length === 0) return { node: void 0, isValid: !1 };
const r = f(t, l), s = i ? !!r && (!r.children || r.children.length === 0) : !!r;
return { node: r, isValid: s };
}
export {
g as findNodeAndValidate,
f as getNodeByPath,
h as isFolderNode,
u as walkTree
};