UNPKG

@progress/kendo-react-treeview

Version:

React TreeView displays hierarchical data in a traditional tree structure, supports user interaction. KendoReact TreeView package

90 lines (89 loc) 2.44 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import { isArray as I, resolveItemsIds as g, updateItem as C, getNestedValue as E } from "@progress/kendo-react-common"; import { EXPAND_FIELD as D, SELECT_FIELD as L, CHECK_FIELD as o, CHILDREN_FIELD as N, CHECK_INDETERMINATE_FIELD as _ } from "./utils/consts.mjs"; function A(n, t) { if (!n || !n.length) return []; let e = n; const l = t.cloneField || "cloned", f = t.expandField || D, s = t.selectField || L, c = t.checkField || o, i = t.childrenField || N; return e = r(e, f, t.expand, l, i), e = r(e, s, t.select, l, i), e = r(e, c, t.check, l, i), p(e, i, t.check), e; } function r(n, t, e, l, f) { if (e) { const { ids: s, field: c } = m(e, t), i = !I(e) && e.idField ? g(s, e.idField, n, f) : s; return h(n, i, c, l, f); } return n; } function m(n, t) { let e, l; return I(n) ? (e = n, l = t) : (e = n.ids || [], l = n.operationField || t), { ids: e, field: l }; } function h(n, t, e, l, f) { let s = n; return t.forEach((c) => { s = C(s, c, (i) => F(e, i), l, f); }), s; } function F(n, t) { const e = (n || "").split("."); let l = t; for (let f = 0; f < e.length; f++) { const s = e[f]; if (f === e.length - 1) l[s] = !0; else if (l[s] !== void 0) l[s] = { ...l[s] }, l = l[s]; else return; } } function p(n, t, e) { if (e && !I(e) && e.applyCheckIndeterminate) { const { field: l } = m(e, o), f = e.checkIndeterminateField || _; for (let s = 0; s < n.length; s++) { const c = n[s], i = c[t]; i && u( i, E(l, c) ? [] : [c], t, l, f ); } } } function u(n, t, e, l, f) { let s = !1; for (let c = 0; c < n.length; c++) { const i = n[c]; if (E(l, i)) { if (!s) for (let d = 0; d < t.length; d++) F(f, t[d]); s = !0, i[e] && u( i[e], [], e, l, f ); } else i[e] && u( i[e], s ? [i] : t.concat([i]), e, l, f ); } } export { A as processTreeViewItems };