UNPKG

@progress/kendo-react-treeview

Version:

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

66 lines (65 loc) 2.27 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 { getNestedValue as I, isArray as x, getAllDirectIndirectChildrenIds as m, areAllDirectChildrenChecked as p, getAllParents as g, treeIdUtils as u } from "@progress/kendo-react-common"; import { CHILDREN_FIELD as O } from "./utils/consts.mjs"; function b(i, n, t, s = {}, d) { if (!t || !t.length) return []; const { ids: l, idField: r } = k(n), c = r ? I(r, i.item) : i.itemHierarchicalIndex, h = l.indexOf(c), o = h === -1, a = d || O; let e; return s.singleMode ? e = o ? [c] : [] : (e = l.slice(), o ? e.push(c) : e.splice(h, 1), s.checkChildren && C(i.item, i.itemHierarchicalIndex, o, r, a, e), s.checkParents && D(i.itemHierarchicalIndex, o, r, a, e, t)), x(n) ? e : Object.assign({}, n, { ids: e }); } function k(i) { let n, t; return x(i) ? n = i : (n = i.ids || [], t = i.idField), { ids: n, idField: t }; } function C(i, n, t, s, d, l) { m(i, n, d, s).forEach((r) => { t && l.indexOf(r) === -1 ? l.push(r) : !t && l.indexOf(r) > -1 && l.splice(l.indexOf(r), 1); }); } function D(i, n, t, s, d, l) { const r = a(); let c = r.next(); n ? h() : o(); function h() { for (; !c.done; ) { const { id: e, item: f } = c.value; if (d.indexOf(e) === -1 && p(f, e, t, s, d)) d.push(e), c = r.next(); else break; } } function o() { for (; !c.done; ) { const { id: e } = c.value, f = d.indexOf(e); if (f > -1) d.splice(f, 1), c = r.next(); else break; } } function* a() { if (t) { const e = g(i, s, l); for (let f = e.length - 1; f > -1; f--) yield { id: I(t, e[f]), item: n ? e[f] : void 0 }; } else { let e = u.getDirectParentId(i); for (; e; ) yield { id: e, item: n ? u.getItemById(e, l, s) : void 0 }, e = u.getDirectParentId(e); } } } export { b as handleTreeViewCheckChange };