@apia/tree 0.1.3 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1 +1,1450 @@
1
- import{jsx as f,jsxs as O,Fragment as k}from"react/jsx-runtime";import{useMount as D,useDebounceFn as ve,useUnmount as be}from"ahooks";import p,{useState as Ne,useEffect as Fe,memo as ye}from"react";import{shallowEqual as N}from"react-redux";import{Spinner as T,Box as m}from"theme-ui";import{EventEmitter as A,PropsStore as Pe,addBoundary as Ee,getSpecificParent as _,usePropsSelector as b,formatMessage as Oe,useLatest as we}from"@apia/util";import{IconButton as Ie}from"@apia/components";import{makeStyledComponent as _e,getVariant as x}from"@apia/theme";import{Icon as K}from"@apia/icons";import{uniqueId as xe}from"lodash-es";const $=(t,e,r)=>{const o=t.propsStore.getFieldProps(e);if(e!=="root"&&(o.isDisabled||!o.isExpanded)||o.children.length===0)return null;for(let l=o.children.length-1;l>=0;l--){const s=o.children[l],d=t.propsStore.getFieldProps(s);if(!r||!d.isFiltered){const i=$(t,s,r);return i!==null?i:s}}return null},$e=(t,e,r)=>{var o,l;const s=t.propsStore.getFieldProps(e),d=t.propsStore.getFieldProps(s.parentId);let i=(l=(o=d.children)==null?void 0:o.findIndex(n=>n===s.id))!=null?l:-1;for(;i>0;){const n=t.propsStore.getFieldProps(d.children[i-1]),a=$(t,n.id,r);if(a!==null)return a;if(!r||!n.isFiltered)return n.id;i--}return s.parentId==="root"?null:s.parentId},L=(t,e)=>{const r=t.propsStore.getFieldProps(e);for(const o of r.children)if(!t.propsStore.getFieldProps(o).isFiltered)return o;return null},y=(t,e,r,o)=>{var l,s;const d=t.propsStore.getFieldProps(e),i=t.propsStore.getFieldProps(d.parentId);let n=(s=(l=i.children)==null?void 0:l.findIndex(a=>a===d.id))!=null?s:1/0;if(!r&&d.isExpanded){if(!o&&d.children.length>0)return d.children[0];const a=L(t,d.id);if(a!==null)return a}for(;n<i.children.length-1;){const a=i.children[n+1];if(!o||!t.propsStore.getFieldProps(a).isFiltered)return a;n++}return d.parentId==="root"?null:y(t,i.id,!0,o)},Le=(t,e,r,o)=>{let l=e;do if(l=y(t,l,!1,o),l!==null){const i=t.propsStore.getFieldProps(l);if((!i.isFiltered||!o)&&i.label.toUpperCase().startsWith(r.toUpperCase()))return l}while(l!==null);const s=t.propsStore.getFieldProps(e),d=t.propsStore.getFieldProps(s.parentId).children.findIndex(i=>i===e);if(s.parentId!=="root"||d>0){const[i]=t.propsStore.getFieldProps("root").children,n=t.propsStore.getFieldProps(i);if(i&&(!o||!n.isFiltered)&&n.label.toUpperCase().startsWith(r.toUpperCase()))return i;l=i;do if(l=y(t,l,!1,o),l){const a=t.propsStore.getFieldProps(l);if((!o||!a.isFiltered)&&a.label.toUpperCase().startsWith(r.toUpperCase()))return l}while(l!==e&&l!==null)}return null},M=(t,e)=>{const r=[e];let o=e;do o=t.propsStore.getFieldProps(o).parentId,r.unshift(o);while(o!=="root");return r},je=(t,e,r)=>{const o=M(t,e),l=M(t,r);for(let s=o.length-1;s>=0;s--){const d=l.indexOf(o[s]);if(d!==-1)return{commonAncestor:o[s],oneNodeAncestorChild:o[s+1],anotherNodeAncestorChild:l[d+1]}}return console.warn("This point should have never been reached since the root node is common to all nodes",{oneNodeId:e,anotherNodeId:r,oneNodePath:o,anotherNodePath:l}),null},R=t=>{t.state.filteredNodes.forEach(r=>{t.propsStore.updateField(r,{isFiltered:!1},{noEmit:!0})});const e=t.propsStore.getFieldProps("root").children[0];e&&t.setFocusedNode(e),t.setState({filteredNodes:[]})},B=(t,e,r="root")=>{let o=!1,l=null;const s=t.propsStore.getFieldProps(r);r!=="root"&&s.label.match(new RegExp(e,"i"))&&(t.propsStore.updateField(r,{isFiltered:!1}),o=!0,l=s.id,t.setState({filteredNodes:t.state.filteredNodes.filter(i=>i!==r)}));let d=!1;return s.children.forEach(i=>{d=B(t,e,i)||o,o=d||o,o&&!l&&(l=i)}),d&&(t.propsStore.updateField(r,{isExpanded:!0}),o&&!l&&(l=r)),o||(t.propsStore.updateField(r,{isFiltered:!0},{noEmit:!0}),t.setState({filteredNodes:[...t.state.filteredNodes,r]})),l!==null&&t.setFocusedNode(l),o},j=(t,e,r,o)=>{const l=je(t,e,r);if(l){const{anotherNodeAncestorChild:s,commonAncestor:d,oneNodeAncestorChild:i}=l,n=t.propsStore.getFieldProps(d),a=n.children.findIndex(g=>g===i),c=n.children.findIndex(g=>g===s);let u=a>=c?r:e;const h=a<c?r:e;t.toggleNodeSelectedState(u,!0);do u=y(t,u,o),u!==null&&t.toggleNodeSelectedState(u,!0);while(u!==h&&u!==null)}};var Ce=Object.defineProperty,Ue=Object.defineProperties,ke=Object.getOwnPropertyDescriptors,z=Object.getOwnPropertySymbols,De=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable,G=(t,e,r)=>e in t?Ce(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e)=>{for(var r in e||(e={}))De.call(e,r)&&G(t,r,e[r]);if(z)for(var r of z(e))Te.call(e,r)&&G(t,r,e[r]);return t},H=(t,e)=>Ue(t,ke(e));const P={},W=new class extends A{emit(t,e){super.emit(t,e),P[e.name]=e.controller}};function q(t){const[e,r]=Ne(P[t]);return Fe(()=>(P[t]!==e&&r(P[t]),W.on("addController",o=>{o.name===t&&r(o.controller)})),[]),e}function Ae(t){return P[t]}class V extends A{constructor(e,r,o=new Pe({logCommands:{propsStore:`treeProps_${e}`,propsLog:`treeLog_${e}`,propsSuscriptors:`propsSuscriptors_${e}`,updateProp:`updateProp_${e}`}})){var l;super(),this.name=e,this.propsStore=o,this.hasApendedFirstChild=!1,this.missingParents=[],this.nonEmittedUpdates=[],this.stateKey="treeState",this.previousNodes=[],this._configuration=r??{current:{emitUpdates:!0}},this._configuration.current.emitUpdates=(l=this._configuration.current.emitUpdates)!=null?l:!0,this.setState(this.getInitialState()),W.emit("addController",{name:e,controller:this}),this.initRoot()}get configuration(){return v({},this._configuration)}get state(){return this.propsStore.getFieldProps(this.stateKey)}get stateStore(){return this.propsStore}destructor(){this.propsStore.destructor()}append(e){var r,o,l,s,d;const i=H(v({},e),{nodeProps:(r=e.nodeProps)!=null?r:{}});let n;i.parentId!==void 0&&(o=this.propsStore.getFieldProps(i.parentId))!=null&&o.children?n=i.parentId:(n="root",i.parentId&&this.missingParents.push(i.parentId),i.actualParentId=i.parentId,i.parentId="root"),this.propsStore.updateField(i.id,H(v({},i),{children:(l=i.children)!=null?l:[]}),{isUrgent:!0}),this.setState({length:this.state.length+1}),this.missingParents.includes(i.id)&&(this.propsStore.getFieldProps("root").children.forEach(a=>{this.propsStore.getFieldProps(a).actualParentId===i.id&&this.move(a,i.id)}),this.missingParents=this.missingParents.filter(a=>a!==i.id)),this.propsStore.updateField(n,{children:[...this.propsStore.getFieldProps(n).children,i.id]},{noEmit:!((s=this._configuration.current)!=null&&s.emitUpdates)}),(d=this._configuration.current)!=null&&d.emitUpdates||this.nonEmittedUpdates.push(n),this.hasApendedFirstChild||(this.hasApendedFirstChild=!0,this.setFocusedNode(i.id,!0)),i.isExpanded&&this.toggleNodeExpandedState(i.id,!0)}batchInit(){this.config({emitUpdates:!1}),this.setState({isLoading:!0},{isUrgent:!0})}batchFinish(){this.config({emitUpdates:!0}),setTimeout(()=>this.setState({isLoading:!1}),0);const e=[...this.getNodesIds()];this.previousNodes.filter(r=>!e.find(o=>o===r)).forEach(r=>this.remove(r)),this.config({emitUpdates:!0}),setTimeout(()=>this.setState({isLoading:!1}),0)}config(e){var r;!((r=this._configuration.current)!=null&&r.emitUpdates)&&e.emitUpdates&&(this.nonEmittedUpdates.forEach(o=>this.propsStore.updateField(o,{children:[...this.propsStore.getFieldProps(o).children]})),this.nonEmittedUpdates=[]),Object.assign(this._configuration.current,e)}deselectAll(){this.state.selectedNodes.forEach(e=>this.propsStore.updateField(e,{isSelected:!1})),this.setState({selectedNodes:[]})}forceEmitUpdate(){var e;this.propsStore.updateField("root",{forceUpdate:((e=this.propsStore.getFieldProps("root").forceUpdate)!=null?e:0)+1})}getInitialState(){return{expandedNodes:[],filteredNodes:[],focusedNode:null,isLoading:!1,length:0,selectedNodes:[]}}getNodesAsArray(){const e=v({},this.propsStore.fields);return delete e[this.stateKey],delete e.root,Object.values(e)}getNodesIds(){const e=v({},this.propsStore.fields);return delete e[this.stateKey],delete e.root,Object.keys(e)}getParentId(e){return this.propsStore.getFieldProps(e).parentId}handleKey(e){var r;const o=this.state.focusedNode,l=this.propsStore.getFieldProps(o);if(e.key==="*"){if(this.state.focusedNode===null)return;this.propsStore.getFieldProps(this.propsStore.getFieldProps(this.state.focusedNode).parentId).children.forEach(s=>this.toggleNodeExpandedState(s,!0))}else if(e.key.match(/^\w$/)){const s=Le(this,o,e.key,!0);s!==null&&(this.setFocusedNode(s),this.emit("mustFocus",s))}else switch(e.code){case"Home":{const s=L(this,"root");if(s===null)return;e.shiftKey&&e.ctrlKey&&this.state.focusedNode!==null&&j(this,s,this.state.focusedNode,!0),this.setFocusedNode(s),this.emit("mustFocus",s);break}case"End":{const s=$(this,"root",!0);s!==null&&(e.shiftKey&&e.ctrlKey&&this.state.focusedNode!==null&&j(this,s,this.state.focusedNode,!0),this.setFocusedNode(s),this.emit("mustFocus",s));break}case"ArrowRight":{if(l.isLeaf)return;if(e.preventDefault(),l.isExpanded){const s=L(this,l.id);s!==null&&(this.setFocusedNode(s),this.emit("mustFocus",s))}else this.toggleNodeExpandedState(l.id,!0);break}case"ArrowLeft":{e.preventDefault(),l.isLeaf||!l.isExpanded?l.parentId!=="root"&&l.parentId!==void 0&&(this.setFocusedNode(l.parentId),this.emit("mustFocus",l.parentId)):this.toggleNodeExpandedState(l.id,!1);break}case"ArrowUp":{e.preventDefault();const s=$e(this,l.id,!0);s!==null?(e.shiftKey&&this.toggleNodeSelectedState(s,!0),this.setFocusedNode(s),this.emit("mustFocus",s)):this.emit("onArrowUpOnFirstElement",!0);break}case"ArrowDown":{e.preventDefault();const s=y(this,l.id,!1,!0);s!==null&&(e.shiftKey&&this.toggleNodeSelectedState(s,!0),this.setFocusedNode(s),this.emit("mustFocus",s));break}case"Space":{if((r=this._configuration.current)!=null&&r.disableSelection)return;e.preventDefault(),this.toggleNodeSelectedState(l.id);break}}}isNode(e){return typeof e=="object"&&"parentId"in e}isNodeContainer(e){return typeof e=="object"&&!this.isNode(e)}includes(e){return!!this.propsStore.getFieldProps(e.id)}initRoot(){this.propsStore.updateField("root",{children:[],id:"root"},{isUrgent:!0})}move(e,r,o){var l,s;const d=this.propsStore.getFieldProps(this.propsStore.getFieldProps(e).parentId),i=this.propsStore.getFieldProps(r);if(!d){console.warn("The current node does not belong to the tree.",e);return}if(!i){console.warn("The destination node does not belong to the tree. No action will be made",r);return}if(d.children=(l=d.children)==null?void 0:l.filter(n=>n!==e),i.children||(i.children=[]),!o)i.children.push(e);else if(o.position)i.children.splice(o.position-1,0,e);else{const n=o.after?o.after:o.before,a=n&&this.isNode(n)?n.id:n,c=i.children.findIndex(h=>h===a),u=Ee(o.before!==void 0?c:c+1,0);u===-1||u===i.children.length?i.children.push(e):i.children.splice(u,0,e)}this.propsStore.updateField(d.id,{children:[...(s=d.children)!=null?s:[]]}),this.propsStore.updateField(i.id,{children:[...i.children]}),this.propsStore.updateField(e,{parentId:i.id})}remove(e,r=!0){var o,l;const s=this.isNode(e)?e.id:e,d=this.propsStore.getFieldProps(s);if(!d)return;const i=this.propsStore.getFieldProps(d.parentId);i&&this.propsStore.updateField(i.id,{children:(o=i.children)==null?void 0:o.filter(n=>n!==s)}),(l=d.children)==null||l.forEach(n=>{r?this.remove(n):this.move(n,"root")}),this.setState({selectedNodes:this.state.selectedNodes.filter(n=>n!==s),focusedNode:this.state.focusedNode===s?null:this.state.focusedNode,length:this.state.length-1}),this.propsStore.removeField(s)}removeMultiple(e,r=!0){e.forEach(o=>this.remove(o,r))}removeAll(){var e;((e=this.configuration.current)==null?void 0:e.emitUpdates)===!1?(this.previousNodes=this.getNodesIds(),this.propsStore.updateField("root",{children:[],id:"root"},{isUrgent:!0,noEmit:!0})):(this.hasApendedFirstChild=!1,this.setState({focusedNode:null},{isUrgent:!0}),this.setSelectedNodes([]),this.initRoot(),Object.keys(this.propsStore.fields).forEach(r=>{["root",this.stateKey].includes(r)||this.propsStore.removeField(r)}))}selectAll(){this.setState({selectedNodes:this.getNodesIds()}),this.state.selectedNodes.forEach(e=>this.propsStore.updateField(e,{isSelected:!0}))}setFocusedNode(e,r){var o,l;this.state.focusedNode!==null&&this.propsStore.updateField(this.state.focusedNode,{isFocused:!1}),this.setState({focusedNode:e}),!((o=this._configuration.current)!=null&&o.isMultiple)&&!r&&((l=this._configuration.current)==null?void 0:l.selectionMode)!=="explicit"&&this.setSelectedNodes([e]),this.propsStore.updateField(e,{isFocused:!0})}setSelectedNodes(e,r=!1){var o;(o=this._configuration.current)!=null&&o.disableSelection&&!r||(this.state.selectedNodes.forEach(l=>this.propsStore.updateField(l,{isSelected:!1})),this.setState({selectedNodes:e.filter(l=>{const{isSelectable:s}=this.propsStore.getFieldProps(l);return s!==!1&&this.propsStore.updateField(l,{isSelected:!0}),s!==!1})}))}setSelectedNodesByClickEvent(e){var r,o,l,s;if((r=this._configuration.current)!=null&&r.disableSelection)return;const d=(o=_(e.target,i=>i.getAttribute("role")==="treeitem"))==null?void 0:o.getAttribute("data-key");if(d){const i=this.propsStore.getFieldProps(d);if(i.isDisabled||i.isSelectable===!1)return;const n=[...this.state.selectedNodes],a=(l=this._configuration.current)!=null&&l.isMultiple?i.isSelected?n.filter(c=>c!==d):[...n,d]:[d];this.setState({selectedNodes:a}),n.forEach(c=>{a.includes(c)||this.propsStore.updateField(c,{isSelected:!1})}),this.propsStore.updateField(d,{isSelected:(s=this._configuration.current)!=null&&s.isMultiple?!i.isSelected:!0})}else console.warn("Cannot set selection, no treeitem found",e)}setState(e,r){this.propsStore.updateField(this.stateKey,v(v({},this.state),e),r)}toggleNodeExpandedState(e,r){var o,l,s,d,i;const n=this.propsStore.getFieldProps(e);if(!(n.isDisabled||n.isLeaf||n.isLoading))if((o=this._configuration.current)!=null&&o.onLoadData&&!n.hasLoaded)this.propsStore.updateField(e,{isLoading:!0}),(l=this._configuration.current)==null||l.onLoadData(n).finally(()=>{var a,c;this.propsStore.updateField(e,{isLoading:!1,isExpanded:!0,hasLoaded:!0}),this.setState({expandedNodes:[...this.state.expandedNodes,e]}),(c=(a=this._configuration.current)==null?void 0:a.onExpand)==null||c.call(a,this.propsStore.getFieldProps(e))});else{const{expandedNodes:a}=this.state,c=r!==void 0?r:!a.includes(e);if((s=this.propsStore.getFieldProps(e))!=null&&s.isDisabled)return;this.setState({expandedNodes:c?[...a,e]:a.filter(u=>u!==e)}),this.propsStore.updateField(e,{isExpanded:c}),(i=(d=this._configuration.current)==null?void 0:d.onExpand)==null||i.call(d,this.propsStore.getFieldProps(e))}}toggleNodeSelectedState(e,r){var o,l;if((o=this._configuration.current)!=null&&o.disableSelection)return;const s=this.propsStore.getFieldProps(e);if(s.isDisabled||s.isSelectable===!1)return;const d=r!==void 0?r:!this.state.selectedNodes.includes(e);d&&!((l=this._configuration.current)!=null&&l.isMultiple)&&this.state.selectedNodes[0]&&this.toggleNodeSelectedState(this.state.selectedNodes[0],!1),this.propsStore.updateField(e,{isSelected:d}),this.setState({selectedNodes:d?[...this.state.selectedNodes,e]:this.state.selectedNodes.filter(i=>i!==e)})}}function Y(t,e){var r;return b((r=t?.stateKey)!=null?r:"__NO__TREE__KEY__",v({propsStore:t?.propsStore},e))}function Ke(t,e){var r;const o=q(t);return{selection:b((r=o?.stateKey)!=null?r:"__NO__TREE__KEY__",v({propsStore:o?.propsStore},e)),handler:o}}var Me=Object.defineProperty,Re=Object.defineProperties,Be=Object.getOwnPropertyDescriptors,J=Object.getOwnPropertySymbols,ze=Object.prototype.hasOwnProperty,Ge=Object.prototype.propertyIsEnumerable,Q=(t,e,r)=>e in t?Me(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,He=(t,e)=>{for(var r in e||(e={}))ze.call(e,r)&&Q(t,r,e[r]);if(J)for(var r of J(e))Ge.call(e,r)&&Q(t,r,e[r]);return t},We=(t,e)=>Re(t,Be(e));function X(t,e){return`${t}__${e}`}function qe(t,e,r,o){var l;switch(r){case"node":{const s=o,d=Ae(e);return We(He({"aria-disabled":s.isDisabled,"aria-expanded":s.isLeaf?void 0:!!s.isExpanded,"aria-label":s.label},(l=d.configuration.current)!=null&&l.disableSelection?void 0:{"aria-selected":s.isSelectable!==!1&&!s.isDisabled?!!s.isSelected:void 0}),{className:s.className,color:s.color,"data-key":s.id,id:X(e,s.id),role:"treeitem",title:s.title})}default:return{role:"tree","aria-multiselectable":o.isMultiple}}}var Ve=Object.defineProperty,Ye=Object.defineProperties,Je=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,Qe=Object.prototype.hasOwnProperty,Xe=Object.prototype.propertyIsEnumerable,ee=(t,e,r)=>e in t?Ve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ze=(t,e)=>{for(var r in e||(e={}))Qe.call(e,r)&&ee(t,r,e[r]);if(Z)for(var r of Z(e))Xe.call(e,r)&&ee(t,r,e[r]);return t},et=(t,e)=>Ye(t,Je(e));const tt={height:"iconmd",width:"iconmd",background:"palette.background.paper"},rt=_e("LoaderSpinner","layout.common.components.loaderSpinner",tt,({className:t})=>f(T,et(Ze({},x("layout.common.components.loaderSpinner")),{className:t})));var ot=Object.defineProperty,te=Object.getOwnPropertySymbols,st=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable,re=(t,e,r)=>e in t?ot(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,lt=(t,e)=>{for(var r in e||(e={}))st.call(e,r)&&re(t,r,e[r]);if(te)for(var r of te(e))it.call(e,r)&&re(t,r,e[r]);return t};const nt=({isLoading:t,onDelete:e,searchString:r})=>!r&&!t?null:f(m,{className:`tree__searchLabelBox ${t?"isLoading":""}`,children:t?f(rt,{className:"tree__loading"}):O(m,{as:"label",className:"tree__searchLabel",children:[Oe(window.LBL_FILTERING_BY,{TOK1:r}),f(Ie,lt({icon:"Close","aria-label":window.LBL_DELETE_FILTER,onClick:e,title:window.LBL_DELETE_FILTER,size:"Sm"},x("icon-inherit")))]})}),oe=p.createContext({});function w(){const t=p.useContext(oe);if(!t)throw new Error("There is no tree context");return t}const dt=({children:t,value:e})=>{const r=p.useMemo(()=>oe.Provider,[]);return f(r,{value:e,children:t})},at=t=>{var e;return f(K,{name:t.icon,title:"",size:(e=t.iconSize)!=null?e:"iconSm"})},ct=t=>f(m,{as:"span",children:t.label}),pt=({level:t})=>f(k,{children:Array(t).fill("").map((e,r)=>r).map(e=>f(m,{className:"spacer"},e))});var ut=Object.defineProperty,ht=Object.defineProperties,ft=Object.getOwnPropertyDescriptors,se=Object.getOwnPropertySymbols,gt=Object.prototype.hasOwnProperty,St=Object.prototype.propertyIsEnumerable,ie=(t,e,r)=>e in t?ut(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,le=(t,e)=>{for(var r in e||(e={}))gt.call(e,r)&&ie(t,r,e[r]);if(se)for(var r of se(e))St.call(e,r)&&ie(t,r,e[r]);return t},mt=(t,e)=>ht(t,ft(e));const vt=({level:t,treeKey:e})=>{var r,o,l;const{handler:s,treeProps:{toggleNodesOnLabelClick:d}}=w(),i=b(e,{selector:h=>h,comparator:(h,g)=>N(h,g)&&N(h?.children,g?.children),propsStore:s.propsStore}),n=p.useMemo(()=>{var h;return(h=i.labelRenderer)!=null?h:ct},[i.labelRenderer]),a=p.useCallback(()=>{s.toggleNodeExpandedState(e)},[s,e]),c=p.useMemo(()=>typeof i.icon=="string"?at:i.icon,[i.icon]),u=p.useCallback(()=>{i.allowToggleExpandedFromLabel!==!1&&s.toggleNodeExpandedState(e)},[s,i.allowToggleExpandedFromLabel,e]);return O(m,{as:"span",className:`tree__nodeItemLabel ${i.isFocused?"focus":""}`,children:[f(pt,{level:t}),(i.isLoading||i.isExpanded&&i.isLeaf!==!0||i.isLeaf===!1||((o=(r=i.children)==null?void 0:r.length)!=null?o:0)>0||i.isLeaf===void 0&&!i.hasLoaded&&((l=s.configuration.current)==null?void 0:l.onLoadData))&&f(m,{className:"tree__expanderWrapper",children:i.isLoading?f(T,{sx:{width:"iconSm",height:"iconSm"}}):f(K,{className:"tree__expandIcon",onClick:a,name:i.isExpanded?"MinusFilled":"PlusFilled",title:"",size:"iconSm"})}),i.icon&&c&&f(c,le({},i)),f(m,{as:"span",className:"tree__nodeItemLabelRenderer",onClick:d!==!1?u:void 0,children:f(n,mt(le({},i),{level:t}))})]})};var bt=p.memo(vt),Nt=Object.defineProperty,Ft=Object.defineProperties,yt=Object.getOwnPropertyDescriptors,ne=Object.getOwnPropertySymbols,Pt=Object.prototype.hasOwnProperty,Et=Object.prototype.propertyIsEnumerable,de=(t,e,r)=>e in t?Nt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ot=(t,e)=>{for(var r in e||(e={}))Pt.call(e,r)&&de(t,r,e[r]);if(ne)for(var r of ne(e))Et.call(e,r)&&de(t,r,e[r]);return t},wt=(t,e)=>Ft(t,yt(e));const It=({level:t,treeKey:e})=>{const{handler:r,name:o,forceUpdate:l,treeProps:s}=w(),d=b(e,{selector:n=>n,comparator:(n,a)=>N(n,a)&&N(n?.children,a?.children),propsStore:r.propsStore}),i=p.useMemo(()=>{var n,a;return(a=(n=d.children)==null?void 0:n.map(c=>r.propsStore.getFieldProps(c)))!=null?a:[]},[d.children,r.propsStore]);return f(k,{children:O(m,wt(Ot({as:"li"},qe(s,o,"node",d)),{children:[f(bt,{level:t,treeKey:e}),f(he,{forceUpdate:l,role:"group",level:t,nodes:i})]}))})};var _t=p.memo(It),xt=Object.defineProperty,$t=Object.defineProperties,Lt=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertySymbols,ae=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable,pe=(t,e,r)=>e in t?xt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jt=(t,e)=>{for(var r in e||(e={}))ae.call(e,r)&&pe(t,r,e[r]);if(I)for(var r of I(e))ce.call(e,r)&&pe(t,r,e[r]);return t},Ct=(t,e)=>$t(t,Lt(e)),Ut=(t,e)=>{var r={};for(var o in t)ae.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o]);if(t!=null&&I)for(var o of I(t))e.indexOf(o)<0&&ce.call(t,o)&&(r[o]=t[o]);return r};const ue=p.forwardRef((t,e)=>{var r=t,{level:o,nodes:l,forceUpdate:s}=r,d=Ut(r,["level","nodes","forceUpdate"]);const{handler:i}=w();return f(m,Ct(jt({ref:e,as:"ul"},d),{children:l?.map(n=>{const a=i.propsStore.getFieldProps(n.id);return a?a.isFiltered?null:f(_t,{level:o+1,treeKey:n.id},n.id):null})}))});ue.displayName="TreeItemChildren";var he=p.memo(ue);function fe({name:t,treeProps:e}){const r=we(e),o=p.useMemo(()=>new V(t,r),[]);D(()=>{var n;(n=e?.initialNodes)==null||n.forEach(a=>o.append(a))});const l=b("root",{comparator:N,propsStore:o.propsStore,selector:n=>{var a;return{children:(a=n.children)!=null?a:[],forceUpdate:n.forceUpdate}}}),s=p.useMemo(()=>`keyHandler${xe()}`,[]),d=p.useRef(null),i=p.useCallback((n,a=3)=>{var c,u;if(d.current){const h=d.current.querySelector(`[data-key="${n}"]`);if((c=d.current)==null||c.focus(),h){const g=((u=e.focusGetter)!=null?u:S=>S.querySelector(":scope > .tree__nodeItemLabel"))(h),F=o.propsStore.getFieldProps(n);(!e.focusGetter||!F.labelRenderer)&&g.classList.add("focused"),g.scrollIntoView({inline:"nearest",block:"nearest"})}else a>0&&setTimeout(()=>i(n,a-1),30)}},[o.propsStore,e.focusGetter]);return p.useEffect(()=>{const n=o.on("mustFocus",c=>i(c)),a=o.on("onArrowUpOnFirstElement",()=>{var c;return(c=e.onArrowUpOnFirstElement)==null?void 0:c.call(e)});return()=>{n(),a()}},[i,o,e]),{data:l,handler:o,keyHandler:{id:s,onKeyDown:p.useCallback(n=>{var a;if(n.key==="Enter"){const c=o.state.focusedNode;if(c){const u=o.propsStore.getFieldProps(c);(a=e.onNodeClick)==null||a.call(e,n,u)}}else o.handleKey(n)},[o,e]),onMouseDown:p.useCallback(n=>{var a;o.state.focusedNode!==null&&n.shiftKey&&(a=o.configuration.current)!=null&&a.isMultiple&&n.preventDefault()},[o.configuration,o.state.focusedNode]),onClick:p.useCallback(n=>{var a,c;if(_(n.target,h=>h.classList.contains("tree__expandIcon")))return;const u=_(n.target,h=>!!h.getAttribute("data-key"));if(u){const h=o.state.focusedNode,g=u.getAttribute("data-key"),F=o.propsStore.getFieldProps(g);(a=e.onNodeClick)==null||a.call(e,n,F),h!==null&&n.shiftKey&&(c=o.configuration.current)!=null&&c.isMultiple?j(o,h,g,!0):(o.setFocusedNode(g),o.setSelectedNodesByClickEvent(n)),g&&i(g)}},[i,o,e]),ref:d}}}var kt=Object.defineProperty,Dt=Object.defineProperties,Tt=Object.getOwnPropertyDescriptors,ge=Object.getOwnPropertySymbols,At=Object.prototype.hasOwnProperty,Kt=Object.prototype.propertyIsEnumerable,Se=(t,e,r)=>e in t?kt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,C=(t,e)=>{for(var r in e||(e={}))At.call(e,r)&&Se(t,r,e[r]);if(ge)for(var r of ge(e))Kt.call(e,r)&&Se(t,r,e[r]);return t},Mt=(t,e)=>Dt(t,Tt(e));const Rt=t=>{var e,r,o;const{data:l,handler:s,keyHandler:d}=fe({name:t.name,treeProps:C({},t)}),[i,n]=p.useState(!1),[a,c]=p.useState(""),u=Y(s,{selector:S=>S.isLoading});p.useEffect(()=>{n(u)},[u]);const h=ve(()=>{t.filterString!==void 0&&(n(!0),p.startTransition(()=>{c(t.filterString)}),t.filterString!==void 0&&t.filterString!==""?(R(s),B(s,t.filterString),s.forceEmitUpdate()):(R(s),s.forceEmitUpdate()),setTimeout(()=>n(!1),0))},{wait:200});p.useEffect(()=>{h.run(),t.filterString||h.flush()},[t.filterString]),b(s.stateKey,{propsStore:s.propsStore,selector:S=>S,comparator:(S,E)=>{var U;return t.onSelect&&!N(S?.selectedNodes,E?.selectedNodes)&&t.onSelect(((U=E?.selectedNodes)!=null?U:[]).map(me=>s.propsStore.getFieldProps(me))),!0}});const{focusedNode:g}=b(s.stateKey,{propsStore:s.propsStore,selector:S=>({focusedNode:S.focusedNode})});D(()=>{t.getHandler&&t.getHandler(s)}),be(()=>s.destructor());const F=p.useMemo(()=>({handler:s,name:t.name,forceUpdate:l.forceUpdate,focusGetter:t.focusGetter,treeProps:t}),[s,t,l.forceUpdate]);return f(dt,{value:F,children:O(m,Mt(C({className:`tree ${(e=t.className)!=null?e:""}`},x((r=t.variant)!=null?r:"layout.common.trees.primary")),{children:[f(nt,{isLoading:(o=t.isLoading)!=null?o:i,onDelete:t.onDeleteFilterString,searchString:t.hideSearchLabel?"":a}),f(he,C({"aria-activedescendant":g!==null?X(t.name,g):void 0,"aria-label":t.label,as:"ul",forceUpdate:l.forceUpdate,level:-1,nodes:p.useMemo(()=>l.children.map(S=>s.propsStore.getFieldProps(S)),[l.children,s.propsStore]),role:"tree",tabIndex:0},d))]}))})};var Bt=ye(Rt);export{Bt as Tree,V as TreeDataController,w as useTreeContext,fe as useTreeData,q as useTreeDataController,Y as useTreeSelector,Ke as useTreeSelectorByName};
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { useMount, useDebounceFn, useUnmount } from 'ahooks';
3
+ import React, { useState, useEffect, memo } from 'react';
4
+ import { shallowEqual } from 'react-redux';
5
+ import { makeStyledComponent, Spinner, getVariant, Box } from '@apia/theme';
6
+ import { EventEmitter, PropsStore, addBoundary, getSpecificParent, usePropsSelector, formatMessage, useLatest } from '@apia/util';
7
+ import { IconButton } from '@apia/components';
8
+ import { Icon } from '@apia/icons';
9
+ import { uniqueId } from 'lodash-es';
10
+
11
+ const getLastVisibleChild = (handler, id, avoidFiltered) => {
12
+ const nodeProps = handler.propsStore.getFieldProps(id);
13
+ if (id !== "root" && (nodeProps.isDisabled || !nodeProps.isExpanded) || nodeProps.children.length === 0)
14
+ return null;
15
+ for (let i = nodeProps.children.length - 1; i >= 0; i--) {
16
+ const currentId = nodeProps.children[i];
17
+ const currentProps = handler.propsStore.getFieldProps(currentId);
18
+ if (!avoidFiltered || !currentProps.isFiltered) {
19
+ const lastChildrenLastChildren = getLastVisibleChild(
20
+ handler,
21
+ currentId,
22
+ avoidFiltered
23
+ );
24
+ return lastChildrenLastChildren !== null ? lastChildrenLastChildren : currentId;
25
+ }
26
+ }
27
+ return null;
28
+ };
29
+ const getPreviousChild = (handler, id, avoidFiltered) => {
30
+ var _a, _b;
31
+ const nodeProps = handler.propsStore.getFieldProps(id);
32
+ const fatherProps = handler.propsStore.getFieldProps(nodeProps.parentId);
33
+ let childPosition = (_b = (_a = fatherProps.children) == null ? void 0 : _a.findIndex((current) => current === nodeProps.id)) != null ? _b : -1;
34
+ while (childPosition > 0) {
35
+ const prevSibling = handler.propsStore.getFieldProps(
36
+ fatherProps.children[childPosition - 1]
37
+ );
38
+ const prevSiblingLastChild = getLastVisibleChild(
39
+ handler,
40
+ prevSibling.id,
41
+ avoidFiltered
42
+ );
43
+ if (prevSiblingLastChild !== null)
44
+ return prevSiblingLastChild;
45
+ if (!avoidFiltered || !prevSibling.isFiltered)
46
+ return prevSibling.id;
47
+ childPosition--;
48
+ }
49
+ if (nodeProps.parentId === "root")
50
+ return null;
51
+ return nodeProps.parentId;
52
+ };
53
+ const getFirstNonFilteredChild = (handler, id) => {
54
+ const nodeProps = handler.propsStore.getFieldProps(id);
55
+ for (const child of nodeProps.children) {
56
+ if (!handler.propsStore.getFieldProps(child).isFiltered)
57
+ return child;
58
+ }
59
+ return null;
60
+ };
61
+ const getNextChild = (handler, id, avoidChildren, avoidFiltered) => {
62
+ var _a, _b;
63
+ const nodeProps = handler.propsStore.getFieldProps(id);
64
+ const fatherProps = handler.propsStore.getFieldProps(nodeProps.parentId);
65
+ let childPosition = (_b = (_a = fatherProps.children) == null ? void 0 : _a.findIndex((current) => current === nodeProps.id)) != null ? _b : Infinity;
66
+ if (!avoidChildren && nodeProps.isExpanded) {
67
+ if (!avoidFiltered && nodeProps.children.length > 0)
68
+ return nodeProps.children[0];
69
+ const firstNonFilteredChild = getFirstNonFilteredChild(
70
+ handler,
71
+ nodeProps.id
72
+ );
73
+ if (firstNonFilteredChild !== null)
74
+ return firstNonFilteredChild;
75
+ }
76
+ while (childPosition < fatherProps.children.length - 1) {
77
+ const nextSibling = fatherProps.children[childPosition + 1];
78
+ if (!avoidFiltered || !handler.propsStore.getFieldProps(nextSibling).isFiltered)
79
+ return nextSibling;
80
+ childPosition++;
81
+ }
82
+ if (nodeProps.parentId === "root")
83
+ return null;
84
+ return getNextChild(handler, fatherProps.id, true, avoidFiltered);
85
+ };
86
+ const getNextNodeWithKey = (handler, id, firstKey, avoidFiltered) => {
87
+ let nextChildWithKey = id;
88
+ do {
89
+ nextChildWithKey = getNextChild(
90
+ handler,
91
+ nextChildWithKey,
92
+ false,
93
+ avoidFiltered
94
+ );
95
+ if (nextChildWithKey !== null) {
96
+ const nodeProps2 = handler.propsStore.getFieldProps(nextChildWithKey);
97
+ if ((!nodeProps2.isFiltered || !avoidFiltered) && nodeProps2.label.toUpperCase().startsWith(firstKey.toUpperCase()))
98
+ return nextChildWithKey;
99
+ }
100
+ } while (nextChildWithKey !== null);
101
+ const nodeProps = handler.propsStore.getFieldProps(id);
102
+ const positionInParent = handler.propsStore.getFieldProps(nodeProps.parentId).children.findIndex((current) => current === id);
103
+ if (nodeProps.parentId !== "root" || positionInParent > 0) {
104
+ const [firstChildOfTree] = handler.propsStore.getFieldProps("root").children;
105
+ const firstChildProps = handler.propsStore.getFieldProps(firstChildOfTree);
106
+ if (firstChildOfTree && (!avoidFiltered || !firstChildProps.isFiltered) && firstChildProps.label.toUpperCase().startsWith(firstKey.toUpperCase()))
107
+ return firstChildOfTree;
108
+ nextChildWithKey = firstChildOfTree;
109
+ do {
110
+ nextChildWithKey = getNextChild(
111
+ handler,
112
+ nextChildWithKey,
113
+ false,
114
+ avoidFiltered
115
+ );
116
+ if (nextChildWithKey) {
117
+ const currentNodeProps = handler.propsStore.getFieldProps(nextChildWithKey);
118
+ if ((!avoidFiltered || !currentNodeProps.isFiltered) && currentNodeProps.label.toUpperCase().startsWith(firstKey.toUpperCase()))
119
+ return nextChildWithKey;
120
+ }
121
+ } while (nextChildWithKey !== id && nextChildWithKey !== null);
122
+ }
123
+ return null;
124
+ };
125
+ const getNodePath = (handler, nodeId) => {
126
+ const path = [nodeId];
127
+ let currentStep = nodeId;
128
+ do {
129
+ currentStep = handler.propsStore.getFieldProps(currentStep).parentId;
130
+ path.unshift(currentStep);
131
+ } while (currentStep !== "root");
132
+ return path;
133
+ };
134
+ const getCommonAncestor = (handler, oneNodeId, anotherNodeId) => {
135
+ const oneNodePath = getNodePath(handler, oneNodeId);
136
+ const anotherNodePath = getNodePath(handler, anotherNodeId);
137
+ for (let i = oneNodePath.length - 1; i >= 0; i--) {
138
+ const anotherNodeIndex = anotherNodePath.indexOf(oneNodePath[i]);
139
+ if (anotherNodeIndex !== -1)
140
+ return {
141
+ commonAncestor: oneNodePath[i],
142
+ oneNodeAncestorChild: oneNodePath[i + 1],
143
+ anotherNodeAncestorChild: anotherNodePath[anotherNodeIndex + 1]
144
+ };
145
+ }
146
+ console.warn(
147
+ "This point should have never been reached since the root node is common to all nodes",
148
+ { oneNodeId, anotherNodeId, oneNodePath, anotherNodePath }
149
+ );
150
+ return null;
151
+ };
152
+ const unfilterNodes = (handler) => {
153
+ handler.state.filteredNodes.forEach((current) => {
154
+ handler.propsStore.updateField(
155
+ current,
156
+ { isFiltered: false },
157
+ { noEmit: true }
158
+ );
159
+ });
160
+ const firstChild = handler.propsStore.getFieldProps("root").children[0];
161
+ if (firstChild)
162
+ handler.setFocusedNode(firstChild);
163
+ handler.setState({ filteredNodes: [] });
164
+ };
165
+ const matchNodesAgainstString = (handler, searchString, nodeId = "root") => {
166
+ let hasMatched = false;
167
+ let matchNode = null;
168
+ const nodeProps = handler.propsStore.getFieldProps(nodeId);
169
+ if (nodeId !== "root" && nodeProps.label.match(new RegExp(searchString, "i"))) {
170
+ handler.propsStore.updateField(nodeId, { isFiltered: false });
171
+ hasMatched = true;
172
+ matchNode = nodeProps.id;
173
+ handler.setState({
174
+ filteredNodes: handler.state.filteredNodes.filter(
175
+ (current) => current !== nodeId
176
+ )
177
+ });
178
+ }
179
+ let hasChildrenMatched = false;
180
+ nodeProps.children.forEach((current) => {
181
+ hasChildrenMatched = matchNodesAgainstString(handler, searchString, current) || hasMatched;
182
+ hasMatched = hasChildrenMatched || hasMatched;
183
+ if (hasMatched && !matchNode)
184
+ matchNode = current;
185
+ });
186
+ if (hasChildrenMatched) {
187
+ handler.propsStore.updateField(nodeId, { isExpanded: true });
188
+ if (hasMatched && !matchNode)
189
+ matchNode = nodeId;
190
+ }
191
+ if (!hasMatched) {
192
+ handler.propsStore.updateField(
193
+ nodeId,
194
+ { isFiltered: true },
195
+ { noEmit: true }
196
+ );
197
+ handler.setState({
198
+ filteredNodes: [...handler.state.filteredNodes, nodeId]
199
+ });
200
+ }
201
+ if (matchNode !== null)
202
+ handler.setFocusedNode(matchNode);
203
+ return hasMatched;
204
+ };
205
+ const selectAllNodesBetweenTwoNodes = (handler, oneNodeId, anotherNodeId, avoidFiltered) => {
206
+ const commonAncestorData = getCommonAncestor(
207
+ handler,
208
+ oneNodeId,
209
+ anotherNodeId
210
+ );
211
+ if (commonAncestorData) {
212
+ const { anotherNodeAncestorChild, commonAncestor, oneNodeAncestorChild } = commonAncestorData;
213
+ const ancestorProps = handler.propsStore.getFieldProps(commonAncestor);
214
+ const oneNodePosition = ancestorProps.children.findIndex(
215
+ (current) => current === oneNodeAncestorChild
216
+ );
217
+ const anotherNodePosition = ancestorProps.children.findIndex(
218
+ (current) => current === anotherNodeAncestorChild
219
+ );
220
+ let currentId = oneNodePosition >= anotherNodePosition ? anotherNodeId : oneNodeId;
221
+ const lastNodeId = oneNodePosition < anotherNodePosition ? anotherNodeId : oneNodeId;
222
+ handler.toggleNodeSelectedState(currentId, true);
223
+ do {
224
+ currentId = getNextChild(handler, currentId, avoidFiltered);
225
+ if (currentId !== null)
226
+ handler.toggleNodeSelectedState(currentId, true);
227
+ } while (currentId !== lastNodeId && currentId !== null);
228
+ }
229
+ };
230
+
231
+ var __defProp$7 = Object.defineProperty;
232
+ var __defProps$6 = Object.defineProperties;
233
+ var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
234
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
235
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
236
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
237
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
238
+ var __spreadValues$7 = (a, b) => {
239
+ for (var prop in b || (b = {}))
240
+ if (__hasOwnProp$7.call(b, prop))
241
+ __defNormalProp$7(a, prop, b[prop]);
242
+ if (__getOwnPropSymbols$7)
243
+ for (var prop of __getOwnPropSymbols$7(b)) {
244
+ if (__propIsEnum$7.call(b, prop))
245
+ __defNormalProp$7(a, prop, b[prop]);
246
+ }
247
+ return a;
248
+ };
249
+ var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
250
+ const trees = {};
251
+ const treesRecordEmitter = new class TreesRecordEmitter extends EventEmitter {
252
+ emit(eventName, params) {
253
+ super.emit(eventName, params);
254
+ trees[params.name] = params.controller;
255
+ }
256
+ }();
257
+ function useTreeDataController(name) {
258
+ const [controller, setDataController] = useState(
259
+ trees[name]
260
+ );
261
+ useEffect(() => {
262
+ if (trees[name] !== controller)
263
+ setDataController(trees[name]);
264
+ return treesRecordEmitter.on("addController", (ev) => {
265
+ if (ev.name === name)
266
+ setDataController(ev.controller);
267
+ });
268
+ }, []);
269
+ return controller;
270
+ }
271
+ function getTreeDataController(name) {
272
+ return trees[name];
273
+ }
274
+ class TreeDataController extends EventEmitter {
275
+ constructor(name, configuration, propsStore = new PropsStore({
276
+ logCommands: {
277
+ propsStore: `treeProps_${name}`,
278
+ propsLog: `treeLog_${name}`,
279
+ propsSuscriptors: `propsSuscriptors_${name}`,
280
+ updateProp: `updateProp_${name}`
281
+ }
282
+ })) {
283
+ var _a;
284
+ super();
285
+ this.name = name;
286
+ this.propsStore = propsStore;
287
+ this.hasApendedFirstChild = false;
288
+ /**
289
+ * Este array se usa para conocer los padres faltantes al momento de la
290
+ * construcción del árbol, de forma de optimizar el proceso
291
+ */
292
+ this.missingParents = [];
293
+ this.nonEmittedUpdates = [];
294
+ this.stateKey = "treeState";
295
+ this.previousNodes = [];
296
+ this._configuration = configuration != null ? configuration : {
297
+ current: { emitUpdates: true }
298
+ };
299
+ this._configuration.current.emitUpdates = (_a = this._configuration.current.emitUpdates) != null ? _a : true;
300
+ this.setState(this.getInitialState());
301
+ treesRecordEmitter.emit("addController", {
302
+ name,
303
+ controller: this
304
+ });
305
+ this.initRoot();
306
+ }
307
+ get configuration() {
308
+ return __spreadValues$7({}, this._configuration);
309
+ }
310
+ get state() {
311
+ return this.propsStore.getFieldProps(
312
+ this.stateKey
313
+ );
314
+ }
315
+ get stateStore() {
316
+ return this.propsStore;
317
+ }
318
+ destructor() {
319
+ this.propsStore.destructor();
320
+ }
321
+ append(node) {
322
+ var _a, _b, _c, _d, _e;
323
+ const newNode = __spreadProps$6(__spreadValues$7({}, node), { nodeProps: (_a = node.nodeProps) != null ? _a : {} });
324
+ let father;
325
+ if (newNode.parentId !== void 0 && ((_b = this.propsStore.getFieldProps(newNode.parentId)) == null ? void 0 : _b.children)) {
326
+ father = newNode.parentId;
327
+ } else {
328
+ father = "root";
329
+ if (newNode.parentId)
330
+ this.missingParents.push(newNode.parentId);
331
+ newNode.actualParentId = newNode.parentId;
332
+ newNode.parentId = "root";
333
+ }
334
+ this.propsStore.updateField(
335
+ newNode.id,
336
+ __spreadProps$6(__spreadValues$7({}, newNode), {
337
+ children: (_c = newNode.children) != null ? _c : []
338
+ }),
339
+ { isUrgent: true }
340
+ );
341
+ this.setState({ length: this.state.length + 1 });
342
+ if (this.missingParents.includes(newNode.id)) {
343
+ this.propsStore.getFieldProps("root").children.forEach((currentChild) => {
344
+ if (this.propsStore.getFieldProps(currentChild).actualParentId === newNode.id) {
345
+ this.move(currentChild, newNode.id);
346
+ }
347
+ });
348
+ this.missingParents = this.missingParents.filter(
349
+ (current) => current !== newNode.id
350
+ );
351
+ }
352
+ this.propsStore.updateField(
353
+ father,
354
+ {
355
+ children: [
356
+ ...this.propsStore.getFieldProps(father).children,
357
+ newNode.id
358
+ ]
359
+ },
360
+ { noEmit: !((_d = this._configuration.current) == null ? void 0 : _d.emitUpdates) }
361
+ );
362
+ if (!((_e = this._configuration.current) == null ? void 0 : _e.emitUpdates))
363
+ this.nonEmittedUpdates.push(father);
364
+ if (!this.hasApendedFirstChild) {
365
+ this.hasApendedFirstChild = true;
366
+ this.setFocusedNode(newNode.id, true);
367
+ }
368
+ if (newNode.isExpanded)
369
+ this.toggleNodeExpandedState(newNode.id, true);
370
+ }
371
+ /**
372
+ * Cuando se quieren agregar muchos nodos, es conveniente llamar primero al
373
+ * método batchInit y luego de finalizar, al método batchFinish()
374
+ */
375
+ batchInit() {
376
+ this.config({ emitUpdates: false });
377
+ this.setState({ isLoading: true }, { isUrgent: true });
378
+ }
379
+ /**
380
+ * Cuando se quieren agregar muchos nodos, es conveniente llamar primero al
381
+ * método batchInit y luego de finalizar, al método batchFinish()
382
+ */
383
+ batchFinish() {
384
+ this.config({ emitUpdates: true });
385
+ setTimeout(() => this.setState({ isLoading: false }), 0);
386
+ const children = [...this.getNodesIds()];
387
+ const deleteNodes = this.previousNodes.filter(
388
+ (current) => !children.find((search) => search === current)
389
+ );
390
+ deleteNodes.forEach((current) => this.remove(current));
391
+ this.config({ emitUpdates: true });
392
+ setTimeout(() => this.setState({ isLoading: false }), 0);
393
+ }
394
+ config(newConf) {
395
+ var _a;
396
+ if (!((_a = this._configuration.current) == null ? void 0 : _a.emitUpdates) && newConf.emitUpdates) {
397
+ this.nonEmittedUpdates.forEach(
398
+ (current) => this.propsStore.updateField(current, {
399
+ children: [...this.propsStore.getFieldProps(current).children]
400
+ })
401
+ );
402
+ this.nonEmittedUpdates = [];
403
+ }
404
+ Object.assign(
405
+ this._configuration.current,
406
+ newConf
407
+ );
408
+ }
409
+ deselectAll() {
410
+ this.state.selectedNodes.forEach(
411
+ (currentId) => this.propsStore.updateField(currentId, { isSelected: false })
412
+ );
413
+ this.setState({ selectedNodes: [] });
414
+ }
415
+ forceEmitUpdate() {
416
+ var _a;
417
+ this.propsStore.updateField("root", {
418
+ forceUpdate: ((_a = this.propsStore.getFieldProps("root").forceUpdate) != null ? _a : 0) + 1
419
+ });
420
+ }
421
+ getInitialState() {
422
+ return {
423
+ expandedNodes: [],
424
+ filteredNodes: [],
425
+ focusedNode: null,
426
+ isLoading: false,
427
+ length: 0,
428
+ selectedNodes: []
429
+ };
430
+ }
431
+ getNodesAsArray() {
432
+ const allFields = __spreadValues$7({}, this.propsStore.fields);
433
+ delete allFields[this.stateKey];
434
+ delete allFields.root;
435
+ return Object.values(allFields);
436
+ }
437
+ /**
438
+ * Devuelve un array que contiene el id de todos los nodos pertenecientes al
439
+ * árbol
440
+ */
441
+ getNodesIds() {
442
+ const allFields = __spreadValues$7({}, this.propsStore.fields);
443
+ delete allFields[this.stateKey];
444
+ delete allFields.root;
445
+ return Object.keys(allFields);
446
+ }
447
+ getParentId(parentId) {
448
+ return this.propsStore.getFieldProps(parentId).parentId;
449
+ }
450
+ /**
451
+ * Este método permite controlar el comportamiento con el teclado desde fuera
452
+ * del componente.
453
+ */
454
+ handleKey(ev) {
455
+ var _a;
456
+ const focusedId = this.state.focusedNode;
457
+ const nodeProps = this.propsStore.getFieldProps(focusedId);
458
+ if (ev.key === "*") {
459
+ if (this.state.focusedNode === null)
460
+ return;
461
+ const parent = this.propsStore.getFieldProps(
462
+ this.propsStore.getFieldProps(this.state.focusedNode).parentId
463
+ );
464
+ parent.children.forEach(
465
+ (current) => this.toggleNodeExpandedState(current, true)
466
+ );
467
+ } else if (ev.key.match(/^\w$/)) {
468
+ const nextChildWithKey = getNextNodeWithKey(
469
+ this,
470
+ focusedId,
471
+ ev.key,
472
+ true
473
+ );
474
+ if (nextChildWithKey !== null) {
475
+ this.setFocusedNode(nextChildWithKey);
476
+ this.emit("mustFocus", nextChildWithKey);
477
+ }
478
+ } else
479
+ switch (ev.code) {
480
+ case "Home": {
481
+ const firstChild = getFirstNonFilteredChild(this, "root");
482
+ if (firstChild === null)
483
+ return;
484
+ if (ev.shiftKey && ev.ctrlKey && this.state.focusedNode !== null) {
485
+ selectAllNodesBetweenTwoNodes(
486
+ this,
487
+ firstChild,
488
+ this.state.focusedNode,
489
+ true
490
+ );
491
+ }
492
+ this.setFocusedNode(firstChild);
493
+ this.emit("mustFocus", firstChild);
494
+ break;
495
+ }
496
+ case "End": {
497
+ const lastVisibleChild = getLastVisibleChild(this, "root", true);
498
+ if (lastVisibleChild !== null) {
499
+ if (ev.shiftKey && ev.ctrlKey && this.state.focusedNode !== null) {
500
+ selectAllNodesBetweenTwoNodes(
501
+ this,
502
+ lastVisibleChild,
503
+ this.state.focusedNode,
504
+ true
505
+ );
506
+ }
507
+ this.setFocusedNode(lastVisibleChild);
508
+ this.emit("mustFocus", lastVisibleChild);
509
+ }
510
+ break;
511
+ }
512
+ case "ArrowRight": {
513
+ if (nodeProps.isLeaf)
514
+ return;
515
+ ev.preventDefault();
516
+ if (nodeProps.isExpanded) {
517
+ const firstChild = getFirstNonFilteredChild(this, nodeProps.id);
518
+ if (firstChild !== null) {
519
+ this.setFocusedNode(firstChild);
520
+ this.emit("mustFocus", firstChild);
521
+ }
522
+ } else
523
+ this.toggleNodeExpandedState(nodeProps.id, true);
524
+ break;
525
+ }
526
+ case "ArrowLeft": {
527
+ ev.preventDefault();
528
+ if (nodeProps.isLeaf || !nodeProps.isExpanded) {
529
+ if (nodeProps.parentId !== "root" && nodeProps.parentId !== void 0) {
530
+ this.setFocusedNode(nodeProps.parentId);
531
+ this.emit("mustFocus", nodeProps.parentId);
532
+ }
533
+ } else
534
+ this.toggleNodeExpandedState(nodeProps.id, false);
535
+ break;
536
+ }
537
+ case "ArrowUp": {
538
+ ev.preventDefault();
539
+ const prevChild = getPreviousChild(this, nodeProps.id, true);
540
+ if (prevChild !== null) {
541
+ if (ev.shiftKey)
542
+ this.toggleNodeSelectedState(prevChild, true);
543
+ this.setFocusedNode(prevChild);
544
+ this.emit("mustFocus", prevChild);
545
+ } else
546
+ this.emit("onArrowUpOnFirstElement", true);
547
+ break;
548
+ }
549
+ case "ArrowDown": {
550
+ ev.preventDefault();
551
+ const nextChild = getNextChild(this, nodeProps.id, false, true);
552
+ if (nextChild !== null) {
553
+ if (ev.shiftKey)
554
+ this.toggleNodeSelectedState(nextChild, true);
555
+ this.setFocusedNode(nextChild);
556
+ this.emit("mustFocus", nextChild);
557
+ }
558
+ break;
559
+ }
560
+ case "Space": {
561
+ if ((_a = this._configuration.current) == null ? void 0 : _a.disableSelection)
562
+ return;
563
+ ev.preventDefault();
564
+ this.toggleNodeSelectedState(nodeProps.id);
565
+ break;
566
+ }
567
+ }
568
+ }
569
+ isNode(node) {
570
+ return typeof node === "object" && "parentId" in node;
571
+ }
572
+ isNodeContainer(node) {
573
+ return typeof node === "object" && !this.isNode(node);
574
+ }
575
+ includes(searchNode) {
576
+ return !!this.propsStore.getFieldProps(searchNode.id);
577
+ }
578
+ initRoot() {
579
+ this.propsStore.updateField(
580
+ "root",
581
+ { children: [], id: "root" },
582
+ { isUrgent: true }
583
+ );
584
+ }
585
+ move(moveNode, destinationNode, afterOrBefore) {
586
+ var _a, _b;
587
+ const currentFather = this.propsStore.getFieldProps(
588
+ this.propsStore.getFieldProps(moveNode).parentId
589
+ );
590
+ const newFather = this.propsStore.getFieldProps(destinationNode);
591
+ if (!currentFather) {
592
+ console.warn("The current node does not belong to the tree.", moveNode);
593
+ return;
594
+ }
595
+ if (!newFather) {
596
+ console.warn(
597
+ "The destination node does not belong to the tree. No action will be made",
598
+ destinationNode
599
+ );
600
+ return;
601
+ }
602
+ currentFather.children = (_a = currentFather.children) == null ? void 0 : _a.filter(
603
+ (search) => search !== moveNode
604
+ );
605
+ if (!newFather.children)
606
+ newFather.children = [];
607
+ if (!afterOrBefore)
608
+ newFather.children.push(moveNode);
609
+ else if (afterOrBefore.position) {
610
+ newFather.children.splice(afterOrBefore.position - 1, 0, moveNode);
611
+ } else {
612
+ const key = afterOrBefore.after ? afterOrBefore.after : afterOrBefore.before;
613
+ const relatedNodeKey = key && this.isNode(key) ? key.id : key;
614
+ const relatedNodeIndex = newFather.children.findIndex(
615
+ (search) => search === relatedNodeKey
616
+ );
617
+ const actualIndex = addBoundary(
618
+ afterOrBefore.before !== void 0 ? relatedNodeIndex : relatedNodeIndex + 1,
619
+ 0
620
+ );
621
+ if (actualIndex === -1 || actualIndex === newFather.children.length)
622
+ newFather.children.push(moveNode);
623
+ else
624
+ newFather.children.splice(actualIndex, 0, moveNode);
625
+ }
626
+ this.propsStore.updateField(currentFather.id, {
627
+ children: [...(_b = currentFather.children) != null ? _b : []]
628
+ });
629
+ this.propsStore.updateField(newFather.id, {
630
+ children: [...newFather.children]
631
+ });
632
+ this.propsStore.updateField(moveNode, {
633
+ parentId: newFather.id
634
+ });
635
+ }
636
+ /**
637
+ * Borra el nodo del árbol, y dependiendo del parámetro removeChildren, borra
638
+ * también sus hijos.
639
+ *
640
+ * @param removeChildren - Si se pasa en false, los nodos hijos son movidos al root
641
+ */
642
+ remove(removeNode, removeChildren = true) {
643
+ var _a, _b;
644
+ const removeNodeId = this.isNode(removeNode) ? removeNode.id : removeNode;
645
+ const removingNode = this.propsStore.getFieldProps(removeNodeId);
646
+ if (!removingNode)
647
+ return;
648
+ const father = this.propsStore.getFieldProps(removingNode.parentId);
649
+ if (father) {
650
+ this.propsStore.updateField(father.id, {
651
+ children: (_a = father.children) == null ? void 0 : _a.filter((search) => search !== removeNodeId)
652
+ });
653
+ }
654
+ (_b = removingNode.children) == null ? void 0 : _b.forEach((current) => {
655
+ if (removeChildren) {
656
+ this.remove(current);
657
+ } else {
658
+ this.move(current, "root");
659
+ }
660
+ });
661
+ this.setState({
662
+ selectedNodes: this.state.selectedNodes.filter(
663
+ (current) => current !== removeNodeId
664
+ ),
665
+ focusedNode: this.state.focusedNode === removeNodeId ? null : this.state.focusedNode,
666
+ length: this.state.length - 1
667
+ });
668
+ this.propsStore.removeField(removeNodeId);
669
+ }
670
+ removeMultiple(nodes, removeChildren = true) {
671
+ nodes.forEach((current) => this.remove(current, removeChildren));
672
+ }
673
+ /**
674
+ * Borra todos los nodos del árbol.
675
+ */
676
+ removeAll() {
677
+ var _a;
678
+ if (((_a = this.configuration.current) == null ? void 0 : _a.emitUpdates) === false) {
679
+ this.previousNodes = this.getNodesIds();
680
+ this.propsStore.updateField(
681
+ "root",
682
+ { children: [], id: "root" },
683
+ { isUrgent: true, noEmit: true }
684
+ );
685
+ } else {
686
+ this.hasApendedFirstChild = false;
687
+ this.setState({ focusedNode: null }, { isUrgent: true });
688
+ this.setSelectedNodes([]);
689
+ this.initRoot();
690
+ Object.keys(this.propsStore.fields).forEach((current) => {
691
+ if (!["root", this.stateKey].includes(current))
692
+ this.propsStore.removeField(current);
693
+ });
694
+ }
695
+ }
696
+ selectAll() {
697
+ this.setState({
698
+ selectedNodes: this.getNodesIds()
699
+ });
700
+ this.state.selectedNodes.forEach(
701
+ (currentId) => this.propsStore.updateField(currentId, { isSelected: true })
702
+ );
703
+ }
704
+ setFocusedNode(key, avoidSelection) {
705
+ var _a, _b;
706
+ if (this.state.focusedNode !== null)
707
+ this.propsStore.updateField(this.state.focusedNode, { isFocused: false });
708
+ this.setState({
709
+ focusedNode: key
710
+ });
711
+ if (!((_a = this._configuration.current) == null ? void 0 : _a.isMultiple) && !avoidSelection && ((_b = this._configuration.current) == null ? void 0 : _b.selectionMode) !== "explicit")
712
+ this.setSelectedNodes([key]);
713
+ this.propsStore.updateField(key, { isFocused: true });
714
+ }
715
+ setSelectedNodes(nodes, force = false) {
716
+ var _a;
717
+ if (((_a = this._configuration.current) == null ? void 0 : _a.disableSelection) && !force)
718
+ return;
719
+ this.state.selectedNodes.forEach(
720
+ (current) => this.propsStore.updateField(current, { isSelected: false })
721
+ );
722
+ this.setState({
723
+ selectedNodes: nodes.filter((current) => {
724
+ const { isSelectable } = this.propsStore.getFieldProps(current);
725
+ if (isSelectable !== false)
726
+ this.propsStore.updateField(current, { isSelected: true });
727
+ return isSelectable !== false;
728
+ })
729
+ });
730
+ }
731
+ setSelectedNodesByClickEvent(ev) {
732
+ var _a, _b, _c, _d;
733
+ if ((_a = this._configuration.current) == null ? void 0 : _a.disableSelection)
734
+ return;
735
+ const nodeKey = (_b = getSpecificParent(
736
+ ev.target,
737
+ (current) => current.getAttribute("role") === "treeitem"
738
+ )) == null ? void 0 : _b.getAttribute("data-key");
739
+ if (nodeKey) {
740
+ const nodeProps = this.propsStore.getFieldProps(nodeKey);
741
+ if (nodeProps.isDisabled || nodeProps.isSelectable === false)
742
+ return;
743
+ const previousSelectionKeys = [...this.state.selectedNodes];
744
+ const newSelection = ((_c = this._configuration.current) == null ? void 0 : _c.isMultiple) ? nodeProps.isSelected ? previousSelectionKeys.filter((current) => current !== nodeKey) : [...previousSelectionKeys, nodeKey] : [nodeKey];
745
+ this.setState({
746
+ selectedNodes: newSelection
747
+ });
748
+ previousSelectionKeys.forEach((current) => {
749
+ if (!newSelection.includes(current))
750
+ this.propsStore.updateField(current, { isSelected: false });
751
+ });
752
+ this.propsStore.updateField(nodeKey, {
753
+ isSelected: ((_d = this._configuration.current) == null ? void 0 : _d.isMultiple) ? !nodeProps.isSelected : true
754
+ });
755
+ } else
756
+ console.warn("Cannot set selection, no treeitem found", ev);
757
+ }
758
+ setState(updateProps, conf) {
759
+ this.propsStore.updateField(
760
+ this.stateKey,
761
+ __spreadValues$7(__spreadValues$7({}, this.state), updateProps),
762
+ conf
763
+ );
764
+ }
765
+ toggleNodeExpandedState(key, shouldExpand) {
766
+ var _a, _b, _c, _d, _e;
767
+ const nodeProps = this.propsStore.getFieldProps(key);
768
+ if (nodeProps.isDisabled || nodeProps.isLeaf || nodeProps.isLoading)
769
+ return;
770
+ if (((_a = this._configuration.current) == null ? void 0 : _a.onLoadData) && !nodeProps.hasLoaded) {
771
+ this.propsStore.updateField(key, { isLoading: true });
772
+ (_b = this._configuration.current) == null ? void 0 : _b.onLoadData(nodeProps).finally(() => {
773
+ var _a2, _b2;
774
+ this.propsStore.updateField(key, {
775
+ isLoading: false,
776
+ isExpanded: true,
777
+ hasLoaded: true
778
+ });
779
+ this.setState({
780
+ expandedNodes: [...this.state.expandedNodes, key]
781
+ });
782
+ (_b2 = (_a2 = this._configuration.current) == null ? void 0 : _a2.onExpand) == null ? void 0 : _b2.call(
783
+ _a2,
784
+ this.propsStore.getFieldProps(key)
785
+ );
786
+ });
787
+ } else {
788
+ const { expandedNodes } = this.state;
789
+ const shouldExpandInner = shouldExpand !== void 0 ? shouldExpand : !expandedNodes.includes(key);
790
+ if ((_c = this.propsStore.getFieldProps(key)) == null ? void 0 : _c.isDisabled)
791
+ return;
792
+ this.setState({
793
+ expandedNodes: shouldExpandInner ? [...expandedNodes, key] : expandedNodes.filter((current) => current !== key)
794
+ });
795
+ this.propsStore.updateField(key, { isExpanded: shouldExpandInner });
796
+ (_e = (_d = this._configuration.current) == null ? void 0 : _d.onExpand) == null ? void 0 : _e.call(
797
+ _d,
798
+ this.propsStore.getFieldProps(key)
799
+ );
800
+ }
801
+ }
802
+ toggleNodeSelectedState(key, isSelected) {
803
+ var _a, _b;
804
+ if ((_a = this._configuration.current) == null ? void 0 : _a.disableSelection)
805
+ return;
806
+ const nodeProps = this.propsStore.getFieldProps(key);
807
+ if (nodeProps.isDisabled || nodeProps.isSelectable === false)
808
+ return;
809
+ const shouldSelect = isSelected !== void 0 ? isSelected : !this.state.selectedNodes.includes(key);
810
+ if (shouldSelect && !((_b = this._configuration.current) == null ? void 0 : _b.isMultiple) && this.state.selectedNodes[0])
811
+ this.toggleNodeSelectedState(this.state.selectedNodes[0], false);
812
+ this.propsStore.updateField(key, { isSelected: shouldSelect });
813
+ this.setState({
814
+ selectedNodes: shouldSelect ? [...this.state.selectedNodes, key] : this.state.selectedNodes.filter((current) => current !== key)
815
+ });
816
+ }
817
+ }
818
+ function useTreeSelector(handler, configuration) {
819
+ var _a;
820
+ return usePropsSelector(
821
+ (_a = handler == null ? void 0 : handler.stateKey) != null ? _a : "__NO__TREE__KEY__",
822
+ __spreadValues$7({
823
+ propsStore: handler == null ? void 0 : handler.propsStore
824
+ }, configuration)
825
+ );
826
+ }
827
+ function useTreeSelectorByName(treeName, configuration) {
828
+ var _a;
829
+ const handler = useTreeDataController(treeName);
830
+ const selection = usePropsSelector(
831
+ (_a = handler == null ? void 0 : handler.stateKey) != null ? _a : "__NO__TREE__KEY__",
832
+ __spreadValues$7({
833
+ propsStore: handler == null ? void 0 : handler.propsStore
834
+ }, configuration)
835
+ );
836
+ return { selection, handler };
837
+ }
838
+
839
+ var __defProp$6 = Object.defineProperty;
840
+ var __defProps$5 = Object.defineProperties;
841
+ var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
842
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
843
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
844
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
845
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
846
+ var __spreadValues$6 = (a, b) => {
847
+ for (var prop in b || (b = {}))
848
+ if (__hasOwnProp$6.call(b, prop))
849
+ __defNormalProp$6(a, prop, b[prop]);
850
+ if (__getOwnPropSymbols$6)
851
+ for (var prop of __getOwnPropSymbols$6(b)) {
852
+ if (__propIsEnum$6.call(b, prop))
853
+ __defNormalProp$6(a, prop, b[prop]);
854
+ }
855
+ return a;
856
+ };
857
+ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
858
+ function getActiveDescendantName(treeName, nodeId) {
859
+ return `${treeName}__${nodeId}`;
860
+ }
861
+ function getDomProps(_, treeName, type, par) {
862
+ var _a;
863
+ switch (type) {
864
+ case "node": {
865
+ const node = par;
866
+ const tree = getTreeDataController(treeName);
867
+ return __spreadProps$5(__spreadValues$6({
868
+ "aria-disabled": node.isDisabled,
869
+ "aria-expanded": node.isLeaf ? void 0 : !!node.isExpanded,
870
+ "aria-label": node.label
871
+ }, ((_a = tree.configuration.current) == null ? void 0 : _a.disableSelection) ? void 0 : {
872
+ "aria-selected": node.isSelectable !== false && !node.isDisabled ? !!node.isSelected : void 0
873
+ }), {
874
+ className: node.className,
875
+ color: node.color,
876
+ "data-key": node.id,
877
+ id: getActiveDescendantName(treeName, node.id),
878
+ role: "treeitem",
879
+ title: node.title
880
+ });
881
+ }
882
+ default: {
883
+ const tree = par;
884
+ return {
885
+ role: "tree",
886
+ "aria-multiselectable": tree.isMultiple
887
+ };
888
+ }
889
+ }
890
+ }
891
+
892
+ var __defProp$5 = Object.defineProperty;
893
+ var __defProps$4 = Object.defineProperties;
894
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
895
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
896
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
897
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
898
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
899
+ var __spreadValues$5 = (a, b) => {
900
+ for (var prop in b || (b = {}))
901
+ if (__hasOwnProp$5.call(b, prop))
902
+ __defNormalProp$5(a, prop, b[prop]);
903
+ if (__getOwnPropSymbols$5)
904
+ for (var prop of __getOwnPropSymbols$5(b)) {
905
+ if (__propIsEnum$5.call(b, prop))
906
+ __defNormalProp$5(a, prop, b[prop]);
907
+ }
908
+ return a;
909
+ };
910
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
911
+ const styles = {
912
+ height: "iconmd",
913
+ width: "iconmd",
914
+ background: "palette.background.paper"
915
+ };
916
+ const LoaderSpinner = makeStyledComponent(
917
+ "LoaderSpinner",
918
+ "layout.common.components.loaderSpinner",
919
+ styles,
920
+ ({ className }) => {
921
+ return /* @__PURE__ */ jsx(
922
+ Spinner,
923
+ __spreadProps$4(__spreadValues$5({}, getVariant("layout.common.components.loaderSpinner")), {
924
+ className
925
+ })
926
+ );
927
+ }
928
+ );
929
+
930
+ var __defProp$4 = Object.defineProperty;
931
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
932
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
933
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
934
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
935
+ var __spreadValues$4 = (a, b) => {
936
+ for (var prop in b || (b = {}))
937
+ if (__hasOwnProp$4.call(b, prop))
938
+ __defNormalProp$4(a, prop, b[prop]);
939
+ if (__getOwnPropSymbols$4)
940
+ for (var prop of __getOwnPropSymbols$4(b)) {
941
+ if (__propIsEnum$4.call(b, prop))
942
+ __defNormalProp$4(a, prop, b[prop]);
943
+ }
944
+ return a;
945
+ };
946
+ const SearchLabel = ({
947
+ isLoading: isSearching,
948
+ onDelete,
949
+ searchString
950
+ }) => {
951
+ if (!searchString && !isSearching)
952
+ return null;
953
+ return /* @__PURE__ */ jsx(Box, { className: `tree__searchLabelBox ${isSearching ? "isLoading" : ""}`, children: isSearching ? /* @__PURE__ */ jsx(LoaderSpinner, { className: "tree__loading" }) : /* @__PURE__ */ jsxs(Box, { as: "label", className: "tree__searchLabel", children: [
954
+ formatMessage(window.LBL_FILTERING_BY, { TOK1: searchString }),
955
+ /* @__PURE__ */ jsx(
956
+ IconButton,
957
+ __spreadValues$4({
958
+ icon: "Close",
959
+ "aria-label": window.LBL_DELETE_FILTER,
960
+ onClick: onDelete,
961
+ title: window.LBL_DELETE_FILTER,
962
+ size: "Sm"
963
+ }, getVariant("icon-inherit"))
964
+ )
965
+ ] }) });
966
+ };
967
+
968
+ const TreeContext = React.createContext({});
969
+ function useTreeContext() {
970
+ const context = React.useContext(TreeContext);
971
+ if (!context)
972
+ throw new Error("There is no tree context");
973
+ return context;
974
+ }
975
+ const TreeContextProvider = ({
976
+ children,
977
+ value
978
+ }) => {
979
+ const Provider = React.useMemo(() => {
980
+ return TreeContext.Provider;
981
+ }, []);
982
+ return /* @__PURE__ */ jsx(Provider, { value, children });
983
+ };
984
+
985
+ const DefaultIconRenderer = (props) => {
986
+ var _a;
987
+ return /* @__PURE__ */ jsx(
988
+ Icon,
989
+ {
990
+ name: props.icon,
991
+ title: "",
992
+ size: (_a = props.iconSize) != null ? _a : "iconSm"
993
+ }
994
+ );
995
+ };
996
+
997
+ const DefaultLabelRenderer = (props) => {
998
+ return /* @__PURE__ */ jsx(Box, { as: "span", children: props.label });
999
+ };
1000
+
1001
+ const Spacer = ({ level }) => {
1002
+ return /* @__PURE__ */ jsx(Fragment, { children: Array(level).fill("").map((_, i) => i).map((current) => /* @__PURE__ */ jsx(Box, { className: "spacer" }, current)) });
1003
+ };
1004
+
1005
+ var __defProp$3 = Object.defineProperty;
1006
+ var __defProps$3 = Object.defineProperties;
1007
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
1008
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
1009
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
1010
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
1011
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1012
+ var __spreadValues$3 = (a, b) => {
1013
+ for (var prop in b || (b = {}))
1014
+ if (__hasOwnProp$3.call(b, prop))
1015
+ __defNormalProp$3(a, prop, b[prop]);
1016
+ if (__getOwnPropSymbols$3)
1017
+ for (var prop of __getOwnPropSymbols$3(b)) {
1018
+ if (__propIsEnum$3.call(b, prop))
1019
+ __defNormalProp$3(a, prop, b[prop]);
1020
+ }
1021
+ return a;
1022
+ };
1023
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
1024
+ const TreeItemLabel = ({ level, treeKey }) => {
1025
+ var _a, _b, _c;
1026
+ const {
1027
+ handler,
1028
+ treeProps: { toggleNodesOnLabelClick }
1029
+ } = useTreeContext();
1030
+ const props = usePropsSelector(treeKey, {
1031
+ selector: (current) => current,
1032
+ comparator: (prevProps, newProps) => {
1033
+ return shallowEqual(prevProps, newProps) && shallowEqual(prevProps == null ? void 0 : prevProps.children, newProps == null ? void 0 : newProps.children);
1034
+ },
1035
+ propsStore: handler.propsStore
1036
+ });
1037
+ const Renderer = React.useMemo(
1038
+ () => {
1039
+ var _a2;
1040
+ return (_a2 = props.labelRenderer) != null ? _a2 : DefaultLabelRenderer;
1041
+ },
1042
+ [props.labelRenderer]
1043
+ );
1044
+ const handleToggle = React.useCallback(() => {
1045
+ handler.toggleNodeExpandedState(treeKey);
1046
+ }, [handler, treeKey]);
1047
+ const IconRenderer = React.useMemo(() => {
1048
+ return typeof props.icon === "string" ? DefaultIconRenderer : props.icon;
1049
+ }, [props.icon]);
1050
+ const onClick = React.useCallback(() => {
1051
+ if (props.allowToggleExpandedFromLabel !== false)
1052
+ handler.toggleNodeExpandedState(treeKey);
1053
+ }, [handler, props.allowToggleExpandedFromLabel, treeKey]);
1054
+ return /* @__PURE__ */ jsxs(
1055
+ Box,
1056
+ {
1057
+ as: "span",
1058
+ className: `tree__nodeItemLabel ${props.isFocused ? "focus" : ""}`,
1059
+ children: [
1060
+ /* @__PURE__ */ jsx(Spacer, { level }),
1061
+ (props.isLoading || props.isExpanded && props.isLeaf !== true || props.isLeaf === false || ((_b = (_a = props.children) == null ? void 0 : _a.length) != null ? _b : 0) > 0 || props.isLeaf === void 0 && !props.hasLoaded && ((_c = handler.configuration.current) == null ? void 0 : _c.onLoadData)) && /* @__PURE__ */ jsx(Box, { className: "tree__expanderWrapper", children: props.isLoading ? /* @__PURE__ */ jsx(Spinner, { sx: { width: "iconSm", height: "iconSm" } }) : /* @__PURE__ */ jsx(
1062
+ Icon,
1063
+ {
1064
+ className: "tree__expandIcon",
1065
+ onClick: handleToggle,
1066
+ name: props.isExpanded ? "MinusFilled" : "PlusFilled",
1067
+ title: "",
1068
+ size: "iconSm"
1069
+ }
1070
+ ) }),
1071
+ props.icon && IconRenderer && /* @__PURE__ */ jsx(IconRenderer, __spreadValues$3({}, props)),
1072
+ /* @__PURE__ */ jsx(
1073
+ Box,
1074
+ {
1075
+ as: "span",
1076
+ className: "tree__nodeItemLabelRenderer",
1077
+ onClick: toggleNodesOnLabelClick !== false ? onClick : void 0,
1078
+ children: /* @__PURE__ */ jsx(Renderer, __spreadProps$3(__spreadValues$3({}, props), { level }))
1079
+ }
1080
+ )
1081
+ ]
1082
+ }
1083
+ );
1084
+ };
1085
+ var TreeItemLabel$1 = React.memo(TreeItemLabel);
1086
+
1087
+ var __defProp$2 = Object.defineProperty;
1088
+ var __defProps$2 = Object.defineProperties;
1089
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
1090
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
1091
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
1092
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
1093
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1094
+ var __spreadValues$2 = (a, b) => {
1095
+ for (var prop in b || (b = {}))
1096
+ if (__hasOwnProp$2.call(b, prop))
1097
+ __defNormalProp$2(a, prop, b[prop]);
1098
+ if (__getOwnPropSymbols$2)
1099
+ for (var prop of __getOwnPropSymbols$2(b)) {
1100
+ if (__propIsEnum$2.call(b, prop))
1101
+ __defNormalProp$2(a, prop, b[prop]);
1102
+ }
1103
+ return a;
1104
+ };
1105
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1106
+ const TreeItem = ({ level, treeKey }) => {
1107
+ const { handler, name, forceUpdate, treeProps } = useTreeContext();
1108
+ const props = usePropsSelector(treeKey, {
1109
+ selector: (current) => current,
1110
+ comparator: (prevProps, newProps) => {
1111
+ return shallowEqual(prevProps, newProps) && shallowEqual(prevProps == null ? void 0 : prevProps.children, newProps == null ? void 0 : newProps.children);
1112
+ },
1113
+ propsStore: handler.propsStore
1114
+ });
1115
+ const nodes = React.useMemo(
1116
+ () => {
1117
+ var _a, _b;
1118
+ return (_b = (_a = props.children) == null ? void 0 : _a.map(
1119
+ (current) => handler.propsStore.getFieldProps(current)
1120
+ )) != null ? _b : [];
1121
+ },
1122
+ [props.children, handler.propsStore]
1123
+ );
1124
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Box, __spreadProps$2(__spreadValues$2({ as: "li" }, getDomProps(treeProps, name, "node", props)), { children: [
1125
+ /* @__PURE__ */ jsx(TreeItemLabel$1, { level, treeKey }),
1126
+ /* @__PURE__ */ jsx(
1127
+ TreeItemChildren$1,
1128
+ {
1129
+ forceUpdate,
1130
+ role: "group",
1131
+ level,
1132
+ nodes
1133
+ }
1134
+ )
1135
+ ] })) });
1136
+ };
1137
+ var TreeItem$1 = React.memo(TreeItem);
1138
+
1139
+ var __defProp$1 = Object.defineProperty;
1140
+ var __defProps$1 = Object.defineProperties;
1141
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
1142
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1143
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1144
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1145
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1146
+ var __spreadValues$1 = (a, b) => {
1147
+ for (var prop in b || (b = {}))
1148
+ if (__hasOwnProp$1.call(b, prop))
1149
+ __defNormalProp$1(a, prop, b[prop]);
1150
+ if (__getOwnPropSymbols$1)
1151
+ for (var prop of __getOwnPropSymbols$1(b)) {
1152
+ if (__propIsEnum$1.call(b, prop))
1153
+ __defNormalProp$1(a, prop, b[prop]);
1154
+ }
1155
+ return a;
1156
+ };
1157
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1158
+ var __objRest = (source, exclude) => {
1159
+ var target = {};
1160
+ for (var prop in source)
1161
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
1162
+ target[prop] = source[prop];
1163
+ if (source != null && __getOwnPropSymbols$1)
1164
+ for (var prop of __getOwnPropSymbols$1(source)) {
1165
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
1166
+ target[prop] = source[prop];
1167
+ }
1168
+ return target;
1169
+ };
1170
+ const TreeItemChildren = React.forwardRef((_a, ref) => {
1171
+ var _b = _a, { level, nodes, forceUpdate } = _b, props = __objRest(_b, ["level", "nodes", "forceUpdate"]);
1172
+ const { handler } = useTreeContext();
1173
+ return /* @__PURE__ */ jsx(Box, __spreadProps$1(__spreadValues$1({ ref, as: "ul" }, props), { children: nodes == null ? void 0 : nodes.map((current) => {
1174
+ const currentProps = handler.propsStore.getFieldProps(current.id);
1175
+ if (!currentProps)
1176
+ return null;
1177
+ return currentProps.isFiltered ? null : /* @__PURE__ */ jsx(TreeItem$1, { level: level + 1, treeKey: current.id }, current.id);
1178
+ }) }));
1179
+ });
1180
+ TreeItemChildren.displayName = "TreeItemChildren";
1181
+ var TreeItemChildren$1 = React.memo(TreeItemChildren);
1182
+
1183
+ function useTreeData({ name, treeProps }) {
1184
+ const props = useLatest(treeProps);
1185
+ const handler = React.useMemo(
1186
+ () => new TreeDataController(name, props),
1187
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1188
+ []
1189
+ );
1190
+ useMount(() => {
1191
+ var _a;
1192
+ (_a = treeProps == null ? void 0 : treeProps.initialNodes) == null ? void 0 : _a.forEach((current) => handler.append(current));
1193
+ });
1194
+ const data = usePropsSelector("root", {
1195
+ comparator: shallowEqual,
1196
+ propsStore: handler.propsStore,
1197
+ selector: (current) => {
1198
+ var _a;
1199
+ return {
1200
+ children: (_a = current.children) != null ? _a : [],
1201
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
1202
+ forceUpdate: current.forceUpdate
1203
+ };
1204
+ }
1205
+ });
1206
+ const keyHandlerId = React.useMemo(() => `keyHandler${uniqueId()}`, []);
1207
+ const keyHandlerRef = React.useRef(null);
1208
+ const focusOnNode = React.useCallback(
1209
+ (key, retry = 3) => {
1210
+ var _a, _b;
1211
+ if (keyHandlerRef.current) {
1212
+ const focusElement = keyHandlerRef.current.querySelector(
1213
+ `[data-key="${key}"]`
1214
+ );
1215
+ (_a = keyHandlerRef.current) == null ? void 0 : _a.focus();
1216
+ if (focusElement) {
1217
+ const actualFocusElement = ((_b = treeProps.focusGetter) != null ? _b : (liElement) => liElement.querySelector(
1218
+ ":scope > .tree__nodeItemLabel"
1219
+ ))(focusElement);
1220
+ const nodeProps = handler.propsStore.getFieldProps(key);
1221
+ if (!treeProps.focusGetter || !nodeProps.labelRenderer)
1222
+ actualFocusElement.classList.add("focused");
1223
+ actualFocusElement.scrollIntoView({
1224
+ inline: "nearest",
1225
+ block: "nearest"
1226
+ });
1227
+ } else if (retry > 0)
1228
+ setTimeout(() => focusOnNode(key, retry - 1), 30);
1229
+ }
1230
+ },
1231
+ [handler.propsStore, treeProps.focusGetter]
1232
+ );
1233
+ React.useEffect(() => {
1234
+ const unsuscribe1 = handler.on("mustFocus", (node) => focusOnNode(node));
1235
+ const unsuscribe2 = handler.on(
1236
+ "onArrowUpOnFirstElement",
1237
+ () => {
1238
+ var _a;
1239
+ return (_a = treeProps.onArrowUpOnFirstElement) == null ? void 0 : _a.call(treeProps);
1240
+ }
1241
+ );
1242
+ return () => {
1243
+ unsuscribe1();
1244
+ unsuscribe2();
1245
+ };
1246
+ }, [focusOnNode, handler, treeProps]);
1247
+ return {
1248
+ data,
1249
+ handler,
1250
+ keyHandler: {
1251
+ id: keyHandlerId,
1252
+ onKeyDown: React.useCallback(
1253
+ (ev) => {
1254
+ var _a;
1255
+ if (ev.key === "Enter") {
1256
+ const key = handler.state.focusedNode;
1257
+ if (key) {
1258
+ const nodeProps = handler.propsStore.getFieldProps(key);
1259
+ (_a = treeProps.onNodeClick) == null ? void 0 : _a.call(treeProps, ev, nodeProps);
1260
+ }
1261
+ } else {
1262
+ handler.handleKey(ev);
1263
+ }
1264
+ },
1265
+ [handler, treeProps]
1266
+ ),
1267
+ onMouseDown: React.useCallback(
1268
+ (ev) => {
1269
+ var _a;
1270
+ const previousFocused = handler.state.focusedNode;
1271
+ if (previousFocused !== null && ev.shiftKey && ((_a = handler.configuration.current) == null ? void 0 : _a.isMultiple))
1272
+ ev.preventDefault();
1273
+ },
1274
+ [handler.configuration, handler.state.focusedNode]
1275
+ ),
1276
+ onClick: React.useCallback(
1277
+ (ev) => {
1278
+ var _a, _b;
1279
+ if (getSpecificParent(
1280
+ ev.target,
1281
+ (current) => current.classList.contains("tree__expandIcon")
1282
+ ))
1283
+ return;
1284
+ const node = getSpecificParent(
1285
+ ev.target,
1286
+ (current) => !!current.getAttribute("data-key")
1287
+ );
1288
+ if (node) {
1289
+ const previousFocused = handler.state.focusedNode;
1290
+ const key = node.getAttribute("data-key");
1291
+ const nodeProps = handler.propsStore.getFieldProps(key);
1292
+ (_a = treeProps.onNodeClick) == null ? void 0 : _a.call(treeProps, ev, nodeProps);
1293
+ if (previousFocused !== null && ev.shiftKey && ((_b = handler.configuration.current) == null ? void 0 : _b.isMultiple)) {
1294
+ selectAllNodesBetweenTwoNodes(
1295
+ handler,
1296
+ previousFocused,
1297
+ key,
1298
+ true
1299
+ );
1300
+ } else {
1301
+ handler.setFocusedNode(key);
1302
+ handler.setSelectedNodesByClickEvent(ev);
1303
+ }
1304
+ if (key)
1305
+ focusOnNode(key);
1306
+ }
1307
+ },
1308
+ [focusOnNode, handler, treeProps]
1309
+ ),
1310
+ ref: keyHandlerRef
1311
+ }
1312
+ };
1313
+ }
1314
+
1315
+ var __defProp = Object.defineProperty;
1316
+ var __defProps = Object.defineProperties;
1317
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1318
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1319
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
1320
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
1321
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1322
+ var __spreadValues = (a, b) => {
1323
+ for (var prop in b || (b = {}))
1324
+ if (__hasOwnProp.call(b, prop))
1325
+ __defNormalProp(a, prop, b[prop]);
1326
+ if (__getOwnPropSymbols)
1327
+ for (var prop of __getOwnPropSymbols(b)) {
1328
+ if (__propIsEnum.call(b, prop))
1329
+ __defNormalProp(a, prop, b[prop]);
1330
+ }
1331
+ return a;
1332
+ };
1333
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1334
+ const Tree = (props) => {
1335
+ var _a, _b, _c;
1336
+ const { data, handler, keyHandler } = useTreeData({
1337
+ name: props.name,
1338
+ treeProps: __spreadValues({}, props)
1339
+ });
1340
+ const [isLoading, setIsLoading] = React.useState(false);
1341
+ const [currentSearchString, setCurrentSearchString] = React.useState("");
1342
+ const isTreeLoading = useTreeSelector(handler, {
1343
+ selector: (current) => current.isLoading
1344
+ });
1345
+ React.useEffect(() => {
1346
+ setIsLoading(isTreeLoading);
1347
+ }, [isTreeLoading]);
1348
+ const search = useDebounceFn(
1349
+ () => {
1350
+ if (props.filterString === void 0)
1351
+ return;
1352
+ setIsLoading(true);
1353
+ React.startTransition(() => {
1354
+ setCurrentSearchString(props.filterString);
1355
+ });
1356
+ if (props.filterString !== void 0 && props.filterString !== "") {
1357
+ unfilterNodes(handler);
1358
+ matchNodesAgainstString(handler, props.filterString);
1359
+ handler.forceEmitUpdate();
1360
+ } else {
1361
+ unfilterNodes(handler);
1362
+ handler.forceEmitUpdate();
1363
+ }
1364
+ setTimeout(() => setIsLoading(false), 0);
1365
+ },
1366
+ { wait: 200 }
1367
+ );
1368
+ React.useEffect(() => {
1369
+ search.run();
1370
+ if (!props.filterString)
1371
+ search.flush();
1372
+ }, [props.filterString]);
1373
+ usePropsSelector(
1374
+ handler.stateKey,
1375
+ {
1376
+ propsStore: handler.propsStore,
1377
+ selector: (current) => current,
1378
+ comparator: (prevProps, newProps) => {
1379
+ var _a2;
1380
+ if (props.onSelect && !shallowEqual(prevProps == null ? void 0 : prevProps.selectedNodes, newProps == null ? void 0 : newProps.selectedNodes)) {
1381
+ props.onSelect(
1382
+ ((_a2 = newProps == null ? void 0 : newProps.selectedNodes) != null ? _a2 : []).map(
1383
+ (currentId) => handler.propsStore.getFieldProps(currentId)
1384
+ )
1385
+ );
1386
+ }
1387
+ return true;
1388
+ }
1389
+ }
1390
+ );
1391
+ const { focusedNode } = usePropsSelector(handler.stateKey, {
1392
+ propsStore: handler.propsStore,
1393
+ selector: (current) => ({
1394
+ focusedNode: current.focusedNode
1395
+ })
1396
+ });
1397
+ useMount(() => {
1398
+ if (props.getHandler)
1399
+ props.getHandler(handler);
1400
+ });
1401
+ useUnmount(() => handler.destructor());
1402
+ const contextValue = React.useMemo(() => {
1403
+ const actualValue = {
1404
+ handler,
1405
+ name: props.name,
1406
+ forceUpdate: data.forceUpdate,
1407
+ focusGetter: props.focusGetter,
1408
+ treeProps: props
1409
+ };
1410
+ return actualValue;
1411
+ }, [handler, props, data.forceUpdate]);
1412
+ return /* @__PURE__ */ jsx(TreeContextProvider, { value: contextValue, children: /* @__PURE__ */ jsxs(
1413
+ Box,
1414
+ __spreadProps(__spreadValues({
1415
+ className: `tree ${(_a = props.className) != null ? _a : ""}`
1416
+ }, getVariant((_b = props.variant) != null ? _b : "layout.common.trees.primary")), {
1417
+ children: [
1418
+ /* @__PURE__ */ jsx(
1419
+ SearchLabel,
1420
+ {
1421
+ isLoading: (_c = props.isLoading) != null ? _c : isLoading,
1422
+ onDelete: props.onDeleteFilterString,
1423
+ searchString: props.hideSearchLabel ? "" : currentSearchString
1424
+ }
1425
+ ),
1426
+ /* @__PURE__ */ jsx(
1427
+ TreeItemChildren$1,
1428
+ __spreadValues({
1429
+ "aria-activedescendant": focusedNode !== null ? getActiveDescendantName(props.name, focusedNode) : void 0,
1430
+ "aria-label": props.label,
1431
+ as: "ul",
1432
+ forceUpdate: data.forceUpdate,
1433
+ level: -1,
1434
+ nodes: React.useMemo(
1435
+ () => data.children.map(
1436
+ (current) => handler.propsStore.getFieldProps(current)
1437
+ ),
1438
+ [data.children, handler.propsStore]
1439
+ ),
1440
+ role: "tree",
1441
+ tabIndex: 0
1442
+ }, keyHandler)
1443
+ )
1444
+ ]
1445
+ })
1446
+ ) });
1447
+ };
1448
+ var Tree$1 = memo(Tree);
1449
+
1450
+ export { Tree$1 as Tree, TreeDataController, useTreeContext, useTreeData, useTreeDataController, useTreeSelector, useTreeSelectorByName };