UNPKG

@progress/kendo-react-common

Version:

React Common package delivers common utilities that can be used with the KendoReact UI components. KendoReact Common Utilities package

9 lines (8 loc) 2.83 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./itemIdUtils.js"),C=require("./SortedPublicItemIds.js"),a=require("./misc.js");function f(e,s){const t=a.getNestedValue(s,e);return!!(t&&t.length)}function N(e,s){return s.expanded(e)&&f(e,s.getChildrenField())}function v(e,s,t,n){const u=g([e],s,t,n);return u.length?u[0]:void 0}function g(e,s,t,n){const u=[],r=new C.SortedPublicItemIds;return r.init(e),A(r,s,t,c.EMPTY_ID,u,n),u}function b(e,s,t,n,u){const r=Number(c.getRootParentId(s));if(r>=e.length)return e;let o=e,l=e[r];return l[n]||(o=e.slice(),l=o[r]=Object.assign({},l,{[n]:!0})),c.isIdZeroLevel(s)?t(l):l[u]&&(l[u]=b(l[u],c.getIdWithoutRootParentId(s),t,n,u)),o}function p(e,s,t){const n=c.getAllShortIds(e);let u=s;for(let r=0;r<n.length;r++){const o=u[Number(n[r])];if(t.disabled(o))return!1;u=o[t.getChildrenField()]}return!0}function x(e,s,t,n){return n?r(e):u(e,s);function u(o,l){let i=[];const d=o[t]||[];for(let I=0;I<d.length;I++){const h=c.createId(I,l);i.push(h),i=i.concat(u(d[I],h))}return i}function r(o){let l=[];const i=o[t]||[];for(let d=0;d<i.length;d++)l.push(a.getNestedValue(n,i[d])),l=l.concat(r(i[d]));return l}}function E(e,s,t,n,u){return(e[n]||[]).every((o,l)=>u.indexOf(t?a.getNestedValue(t,o):c.createId(l,s))>-1)}function R(e,s,t){const n=[],u=c.getAllShortIds(e);let r=t;for(let o=0;o<u.length-1&&r;o++){const l=r[Number(u[o])];n.push(l),r=l[s]}return n}function P(e,s,t){const n=t.slice();if(c.isIdZeroLevel(e))n.splice(Number(e),1);else{const u=Number(c.getRootParentId(e)),r=n[u]={...n[u]};r[s]=P(c.getIdWithoutRootParentId(e),s,r[s])}return n}function m(e,s,t,n,u){const r=u.slice();if(c.isIdZeroLevel(n))if(s==="child"){const o=r[Number(n)]={...r[Number(n)]};o[t]?(o[t]=o[t].slice(),o[t].push(e)):o[t]=[e]}else r.splice(Number(n)+(s==="after"?1:0),0,e);else{const o=Number(c.getRootParentId(n)),l=r[o]={...r[o]};l[t]=m(e,s,t,c.getIdWithoutRootParentId(n),l[t])}return r}function A(e,s,t,n,u,r){for(let o=0;o<t.length;o++){const l=t[o],i=c.createId(o,n);e.hasId(a.getNestedValue(s,l))&&u.push(i),f(l,r)&&A(e,s,a.getNestedValue(r,l),i,u,r)}}exports.addItem=m;exports.areAllDirectChildrenChecked=E;exports.getAllDirectIndirectChildrenIds=x;exports.getAllParents=R;exports.hasChildren=f;exports.isEnabledAndAllParentsEnabled=p;exports.isItemExpandedAndWithChildren=N;exports.removeItem=P;exports.resolveItemId=v;exports.resolveItemsIds=g;exports.updateItem=b;