Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-accessible-treeview

Package Overview
Dependencies
Maintainers
4
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-accessible-treeview - npm Package Compare versions

Comparing version 2.1.4 to 2.2.0

dist/__mocks__/styleMock.d.ts

2

dist/react-accessible-treeview.cjs.js

@@ -1,1 +0,1 @@

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),a=e(t),r=e(require("classnames")),n=e(require("prop-types"));function d(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function l(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?d(Object(a),!0).forEach((function(t){i(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):d(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function i(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function s(){return(s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(e[r]=a[r])}return e}).apply(this,arguments)}function c(e,t){if(null==e)return{};var a,r,n=function(e,t){if(null==e)return{};var a,r,n={},d=Object.keys(e);for(r=0;r<d.length;r++)a=d[r],t.indexOf(a)>=0||(n[a]=e[a]);return n}(e,t);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(e);for(r=0;r<d.length;r++)a=d[r],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==a)return;var r,n,d=[],l=!0,i=!1;try{for(a=a.call(e);!(l=(r=a.next()).done)&&(d.push(r.value),!t||d.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==a.return||a.return()}finally{if(i)throw n}}return d}(e,t)||f(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e){return function(e){if(Array.isArray(e))return p(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||f(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(e,t){if(e){if("string"==typeof e)return p(e,t);var a=Object.prototype.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?p(e,t):void 0}}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var a=0,r=new Array(t);a<t;a++)r[a]=e[a];return r}function h(e,t){var a="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!a){if(Array.isArray(e)||(a=f(e))||t&&e&&"number"==typeof e.length){a&&(e=a);var r=0,n=function(){};return{s:n,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var d,l=!0,i=!1;return{s:function(){a=a.call(e)},n:function(){var e=a.next();return l=e.done,e},e:function(e){i=!0,d=e},f:function(){try{l||null==a.return||a.return()}finally{if(i)throw d}}}}var v=function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return function(e){var a,r=h(t);try{for(r.s();!(a=r.n()).done;){var n=a.value;if(n&&n(e),e.defaultPrevented)break}}catch(e){r.e(e)}finally{r.f()}}},I=function(e,t){var a,r=new Set,n=h(e);try{for(n.s();!(a=n.n()).done;){var d=a.value;t.has(d)||r.add(d)}}catch(e){n.e(e)}finally{n.f()}return r},S=function(e,t){return new Set([].concat(u(I(e,t)),u(I(t,e))))},b=function(e){var a=t.useRef();return t.useEffect((function(){a.current=e}),[e]),a.current},y=function(e,t){return null!=e[t].children&&e[t].children.length>0},m=function(e,t){return e[t].parent},g=function(e,t,a){var r=[];return function e(t,n){var d=t[n];if(null!=d.children){var l,i=h(d.children.filter((function(e){return!a.has(e)})));try{for(i.s();!(l=i.n()).done;){var s=l.value;r.push(s),e(t,s)}}catch(e){i.e(e)}finally{i.f()}}}(e,t),r},w=function(e,t,a){var r=m(e,t);if(null!=r){var n=e[r],d=n.children.indexOf(t)+a;if(n.children[d])return n.children[d]}return null},E=function(e,t,a){var r=e[t];for(e[0].id===t&&(r=e[e[t].children[e[t].children.length-1]]);a.has(r.id)&&y(e,r.id);)r=e[r.children[r.children.length-1]];return r.id},W=function(e,t,a){if(t===e[0].children[0])return null;var r=w(e,t,-1);return null==r?m(e,t):E(e,r,a)},x=function(e,t,a){var r=e[t].id;if(y(e,r)&&a.has(r))return e[r].children[0];for(;;){var n=w(e,r,1);if(null!=n)return n;if(null==(r=m(e,r)))return null}},A=function(e){var t=e.data,a=e.expandedIds,r=e.from,n=e.to,d=[],l=Object.keys(t).length,i=0,s=r;if(d.push(r),r<n)for(;i<l&&(s=x(t,s,a),d.push(s),null!=s&&s!==n);)i+=1;else if(r>n)for(;i<l&&(s=W(t,s,a),d.push(s),null!=s&&s!==n);)i+=1;return d},O=function(e){var t=e.isSelected,a=e.isDisabled,r=e.multiSelect;if(!a)return r?t:!!t||void 0},C=function(e,t,a){return t.concat.apply(t,u(t.filter((function(t){return y(e,t)})).map((function(t){return g(e,t,a)}))))},D=function(e,t,a){window.navigator.userAgent.match(/Trident/)?setTimeout((function(){return!t.contains(document.activeElement)&&a()}),0):!t.contains(e.nativeEvent.relatedTarget)&&a()},k=["data","nodeRenderer","onSelect","onExpand","className","multiSelect","propagateSelect","propagateSelectUpwards","propagateCollapse","expandOnKeyboardSelect","togglableSelect","defaultExpandedIds","defaultSelectedIds","defaultDisabledIds","clickAction","onBlur"],N=["data","element","expandedIds","getClasses","baseClassNames","level"],j=["0"],U={root:"tree",node:"tree-node",branch:"tree-node__branch",branchWrapper:"tree-branch-wrapper",leafListItem:"tree-leaf-list-item",leaf:"tree-node__leaf",nodeGroup:"tree-node-group"},L="COLLAPSE",P="COLLAPSE_MANY",F="EXPAND",R="EXPAND_MANY",T="HALF_SELECT",_="SELECT",K="DESELECT",B="TOGGLE",H="TOGGLE_SELECT",z="SELECT_MANY",G="EXCLUSIVE_CHANGE_SELECT_MANY",M="FOCUS",q="BLUR",X="DISABLE",Y="ENABLE",V=function(e,t){switch(t.type){case L:var a=new Set(e.expandedIds);return a.delete(t.id),l(l({},e),{},{expandedIds:a,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case P:var r,n=new Set(e.expandedIds),d=h(t.ids);try{for(d.s();!(r=d.n()).done;){var i=r.value;n.delete(i)}}catch(e){d.e(e)}finally{d.f()}return l(l({},e),{},{expandedIds:n,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case F:var s=new Set(e.expandedIds);return s.add(t.id),l(l({},e),{},{expandedIds:s,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case R:var c=new Set([].concat(u(e.expandedIds),u(t.ids)));return l(l({},e),{},{expandedIds:c,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case B:var o=new Set(e.expandedIds);return e.expandedIds.has(t.id)?o.delete(t.id):o.add(t.id),l(l({},e),{},{expandedIds:o,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case T:if(e.disabledIds.has(t.id))return e;var f=new Set(e.halfSelectedIds),p=new Set(e.selectedIds);return f.add(t.id),p.delete(t.id),l(l({},e),{},{selectedIds:p,halfSelectedIds:f,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case _:if(e.disabledIds.has(t.id))return e;var v;t.multiSelect?(v=new Set(e.selectedIds)).add(t.id):(v=new Set).add(t.id);var S=new Set(e.halfSelectedIds);return S.delete(t.id),l(l({},e),{},{selectedIds:v,halfSelectedIds:S,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case K:if(e.disabledIds.has(t.id))return e;var b;t.multiSelect?(b=new Set(e.selectedIds)).delete(t.id):b=new Set;var y=new Set(e.halfSelectedIds);return y.delete(t.id),l(l({},e),{},{selectedIds:b,halfSelectedIds:y,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case H:if(e.disabledIds.has(t.id))return e;var m,g=e.selectedIds.has(t.id);t.multiSelect?(m=new Set(e.selectedIds),g?m.delete(t.id):m.add(t.id)):(m=new Set,g||m.add(t.id));var w=new Set(e.halfSelectedIds);return w.delete(t.id),l(l({},e),{},{selectedIds:m,halfSelectedIds:w,tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case z:var E,W=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){E=t.select?new Set([].concat(u(e.selectedIds),u(W))):I(e.selectedIds,new Set(W));var x=I(e.halfSelectedIds,E);return l(l({},e),{},{selectedIds:E,halfSelectedIds:x,lastAction:t.type,lastInteractedWith:t.lastInteractedWith})}return e;case G:var A,O=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){A=t.select?new Set(O):I(e.selectedIds,new Set(O));var C=I(e.halfSelectedIds,A);return l(l({},e),{},{selectedIds:A,halfSelectedIds:C,lastAction:t.type,lastInteractedWith:t.lastInteractedWith})}return e;case M:return l(l({},e),{},{tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case q:return l(l({},e),{},{isFocused:!1});case X:var D=new Set(e.disabledIds);return D.add(t.id),l(l({},e),{},{disabledIds:D});case Y:var k=new Set(e.disabledIds);return k.delete(t.id),l(l({},e),{},{disabledIds:k});default:throw new Error("Invalid action passed to the reducer")}},$=function(e){var a=e.data,r=e.defaultExpandedIds,n=e.defaultSelectedIds,d=e.defaultDisabledIds,l=e.nodeRefs,i=e.onSelect,s=e.onExpand,c=e.multiSelect,u=e.propagateSelectUpwards,f=o(t.useReducer(V,{selectedIds:new Set(n),tabbableId:a[0].children[0],isFocused:!1,expandedIds:new Set(r),halfSelectedIds:new Set,lastUserSelect:a[0].children[0],lastInteractedWith:null,disabledIds:new Set(d)}),2),p=f[0],v=f[1],I=p.selectedIds,g=p.expandedIds,w=p.disabledIds,E=p.tabbableId,W=p.halfSelectedIds,x=p.lastAction,A=p.lastInteractedWith,O=b(I)||new Set,C=S(I,O);t.useEffect((function(){if(i!==Q){var e,t=h(C);try{for(t.s();!(e=t.n()).done;){var r=e.value,n=y(a,r);i({element:a[r],isBranch:n,isExpanded:n?g.has(r):void 0,isSelected:I.has(r),isDisabled:w.has(r),isHalfSelected:n?W.has(r):void 0,treeState:p})}}catch(e){t.e(e)}finally{t.f()}}}),[a,I,g,w,W,C,i,p]);var D=b(g)||new Set;return t.useEffect((function(){var e=S(g,D);if(s!==Q){var t,r=h(e);try{for(r.s();!(t=r.n()).done;){var n=t.value;s({element:a[n],isExpanded:g.has(n),isSelected:I.has(n),isDisabled:w.has(n),isHalfSelected:W.has(n),treeState:p})}}catch(e){r.e(e)}finally{r.f()}}}),[a,I,g,w,W,D,s,p]),t.useEffect((function(){if(u&&c){var e=new Set(C);A&&e.add(A);var t,r=function(e,t,a,r){var n,d={every:new Set,some:new Set,none:new Set},l=h(t);try{for(l.s();!(n=l.n()).done;)for(var i=n.value;;){var s=m(e,i);if(0===s||r.has(s))break;var c=e[s].children.filter((function(e){return!r.has(e)}));if(0===c.length)break;c.some((function(e){return a.has(e)}))?c.every((function(e){return a.has(e)}))?d.every.add(s):d.some.add(s):d.none.add(s),i=s}}catch(e){l.e(e)}finally{l.f()}return d}(a,e,I,w),n=r.every,d=r.some,l=r.none,i=h(n);try{for(i.s();!(t=i.n()).done;){var s=t.value;I.has(s)||v({type:_,id:s,multiSelect:c,keepFocus:!0,NotUserAction:!0,lastInteractedWith:A})}}catch(e){i.e(e)}finally{i.f()}var o,f=h(d);try{for(f.s();!(o=f.n()).done;){var p=o.value;W.has(p)||v({type:T,id:p,multiSelect:c,keepFocus:!0,NotUserAction:!0,lastInteractedWith:A})}}catch(e){f.e(e)}finally{f.f()}var S,b=h(l);try{for(b.s();!(S=b.n()).done;){var y=S.value;(I.has(y)||W.has(y))&&v({type:K,id:y,multiSelect:c,keepFocus:!0,NotUserAction:!0,lastInteractedWith:A})}}catch(e){b.e(e)}finally{b.f()}}}),[a,c,u,I,g,w,W,x,O,C,A]),t.useEffect((function(){var e;if(null!=A&&null!=E){var t=l.current[E];null!=(e=t)&&e.focus&&e.focus()}}),[E,l,A]),[p,v]},J={select:"SELECT",focus:"FOCUS",exclusiveSelect:"EXCLUSIVE_SELECT"},Q=function(){},Z=a.forwardRef((function(e,n){var d=e.data,l=e.nodeRenderer,i=e.onSelect,u=void 0===i?Q:i,f=e.onExpand,p=void 0===f?Q:f,h=e.className,v=void 0===h?"":h,I=e.multiSelect,S=void 0!==I&&I,b=e.propagateSelect,y=void 0!==b&&b,m=e.propagateSelectUpwards,g=void 0!==m&&m,w=e.propagateCollapse,E=void 0!==w&&w,W=e.expandOnKeyboardSelect,x=void 0!==W&&W,A=e.togglableSelect,O=void 0!==A&&A,C=e.defaultExpandedIds,N=void 0===C?[]:C,j=e.defaultSelectedIds,L=void 0===j?[]:j,P=e.defaultDisabledIds,F=void 0===P?[]:P,R=e.clickAction,T=void 0===R?J.select:R,_=e.onBlur,K=c(e,k),B=t.useRef({}),H=o($({data:d,defaultExpandedIds:N,defaultSelectedIds:L,defaultDisabledIds:F,nodeRefs:B,onSelect:u,onExpand:p,multiSelect:S,propagateSelect:y,propagateSelectUpwards:g}),2),z=H[0],G=H[1];y=y&&S;var M=t.useRef();return null!=n&&(M=n),a.createElement("ul",s({className:r(U.root,v),role:"tree","aria-multiselectable":S,ref:M,onBlur:function(e){D(e,M.current,(function(){_&&_({treeState:z,dispatch:G}),G({type:q})}))},onKeyDown:ae({data:d,tabbableId:z.tabbableId,expandedIds:z.expandedIds,selectedIds:z.selectedIds,disabledIds:z.disabledIds,halfSelectedIds:z.halfSelectedIds,dispatch:G,propagateCollapse:E,propagateSelect:y,multiSelect:S,expandOnKeyboardSelect:x,togglableSelect:O})},K),d[0].children.map((function(e,t){return a.createElement(ee,s({key:e,data:d,element:d[e],setsize:d[0].children.length,posinset:t+1,level:1},z,{state:z,dispatch:G,nodeRefs:B,baseClassNames:U,nodeRenderer:l,propagateCollapse:E,propagateSelect:y,propagateSelectUpwards:g,multiSelect:S,togglableSelect:O,clickAction:T}))})))})),ee=function(e){var t=e.element,n=e.dispatch,d=e.data,l=e.selectedIds,c=e.tabbableId,o=e.isFocused,f=e.expandedIds,p=e.disabledIds,h=e.halfSelectedIds,I=e.lastUserSelect,S=e.nodeRefs,b=e.baseClassNames,m=e.nodeRenderer,w=e.setsize,E=e.posinset,W=e.level,x=e.propagateCollapse,D=e.propagateSelect,k=e.multiSelect,N=e.togglableSelect,j=e.clickAction,U=e.state,L=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(f.has(t.id)&&x){var a=[t.id].concat(u(g(d,t.id,new Set)));n({type:P,ids:a,lastInteractedWith:t.id})}else n({type:B,id:t.id,lastInteractedWith:t.id})},F=function(){return n({type:M,id:t.id,lastInteractedWith:t.id})},R=function(e){if(e.shiftKey){var a=A({data:d,expandedIds:f,from:I,to:t.id,lastInteractedWith:t.id}).filter((function(e){return!p.has(e)}));a=D?C(d,a,p):a,n({type:G,select:!0,multiSelect:k,ids:a,lastInteractedWith:t.id})}else e.ctrlKey||j===J.select?(n({type:N?H:_,id:t.id,multiSelect:k,lastInteractedWith:t.id}),D&&!p.has(t.id)&&n({type:z,ids:C(d,[t.id],p),select:!N||!l.has(t.id),multiSelect:k,lastInteractedWith:t.id})):j===J.exclusiveSelect?n({type:N?H:_,id:t.id,multiSelect:!1,lastInteractedWith:t.id}):j===J.focus&&n({type:M,id:t.id,lastInteractedWith:t.id})},T=function(e){var a;return r(e,(i(a={},"".concat(e,"--expanded"),f.has(t.id)),i(a,"".concat(e,"--selected"),l.has(t.id)),i(a,"".concat(e,"--focused"),c===t.id&&o),a))};return y(d,t.id)?a.createElement("li",{role:"treeitem","aria-expanded":f.has(t.id),"aria-selected":O({isSelected:l.has(t.id),isDisabled:p.has(t.id),multiSelect:k}),"aria-setsize":w,"aria-posinset":E,"aria-level":W,disabled:p.has(t.id),"aria-disabled":p.has(t.id),tabIndex:c===t.id?0:-1,ref:function(e){return S.current[t.id]=e},className:b.branchWrapper},m({element:t,isBranch:!0,isSelected:l.has(t.id),isHalfSelected:h.has(t.id),isExpanded:f.has(t.id),isDisabled:p.has(t.id),dispatch:n,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onClick;return{onClick:null==t?v(R,L,F):v(t,F),className:r(T(b.node),b.branch)}},setsize:w,posinset:E,level:W,handleSelect:R,handleExpand:L,treeState:U}),a.createElement(te,s({element:t,getClasses:T},e))):a.createElement("li",{role:"none",className:T(b.leafListItem)},m({element:t,isBranch:!1,isSelected:l.has(t.id),isHalfSelected:void 0,isExpanded:!1,isDisabled:p.has(t.id),dispatch:n,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=e.onClick;return{role:"treeitem",tabIndex:c===t.id?0:-1,onClick:v(null==a?R:a,F),ref:function(e){return S.current[t.id]=e},className:r(T(b.node),b.leaf),"aria-setsize":w,"aria-posinset":E,"aria-level":W,"aria-selected":O({isSelected:l.has(t.id),isDisabled:p.has(t.id),multiSelect:k}),disabled:p.has(t.id),"aria-disabled":p.has(t.id)}},setsize:w,posinset:E,level:W,handleSelect:R,handleExpand:Q,treeState:U}))},te=function(e){var t=e.data,r=e.element,n=e.expandedIds,d=e.getClasses,l=e.baseClassNames,i=e.level,o=c(e,N);return a.createElement("ul",{role:"group",className:d(l.nodeGroup)},n.has(r.id)&&r.children.map((function(e,d){return a.createElement(ee,s({data:t,expandedIds:n,baseClassNames:l,key:e,element:t[e],setsize:r.children.length,posinset:d+1,level:i+1},o))})))},ae=function(e){var t=e.data,a=e.expandedIds,r=e.selectedIds,n=e.disabledIds,d=e.tabbableId,l=e.dispatch,i=e.propagateCollapse,s=e.propagateSelect,o=e.multiSelect,f=e.expandOnKeyboardSelect,p=e.togglableSelect;return function(e){var h=t[d],v=h.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();t[0];var I=c(t,j),S=Object.values(I).map((function(e){return e.id})).filter((function(e){return!n.has(e)}));l({type:z,multiSelect:o,select:Array.from(r).filter((function(e){return!n.has(e)})).length!==S.length,ids:S,lastInteractedWith:h.id})}else if(e.shiftKey&&("Home"===e.key||"End"===e.key)){var b="Home"===e.key?t[0].children[0]:E(t,v,a),w=A({data:t,expandedIds:a,from:v,to:b}).filter((function(e){return!n.has(e)}));l({type:z,multiSelect:o,select:!0,ids:s?C(t,w,n):w}),l({type:M,id:b,lastInteractedWith:b})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var O=W(t,v,a);return void(null==O&&n.has(O)||(l({type:z,ids:s?C(t,[O],n):[O],select:!0,multiSelect:o,lastInteractedWith:O}),l({type:M,id:O,lastInteractedWith:O})));case"ArrowDown":e.preventDefault();var D=x(t,v,a);return void(null==D&&n.has(D)||(l({type:z,ids:s?C(t,[D],n):[D],multiSelect:o,select:!0,lastInteractedWith:D}),l({type:M,id:D,lastInteractedWith:D})))}switch(e.key){case"ArrowDown":e.preventDefault();var k=x(t,v,a);return void(null!=k&&l({type:M,id:k,lastInteractedWith:k}));case"ArrowUp":e.preventDefault();var N=W(t,v,a);return void(null!=N&&l({type:M,id:N,lastInteractedWith:N}));case"ArrowLeft":if(e.preventDefault(),y(t,v)&&a.has(d))if(i){var U=[v].concat(u(g(t,v,new Set)));l({type:P,ids:U,lastInteractedWith:h.id})}else l({type:L,id:v,lastInteractedWith:v});else if(!t[0].children.includes(v)){var T=m(t,v);l({type:M,id:T,lastInteractedWith:T})}return;case"ArrowRight":return e.preventDefault(),void(y(t,v)&&(a.has(d)?l({type:M,id:h.children[0],lastInteractedWith:h.children[0]}):l({type:F,id:v,lastInteractedWith:v})));case"Home":e.preventDefault(),l({type:M,id:t[0].children[0],lastInteractedWith:t[0].children[0]});break;case"End":e.preventDefault();var K=E(t,t[0].id,a);return void l({type:M,id:K,lastInteractedWith:K});case"*":e.preventDefault();var G=t[m(t,v)].children.filter((function(e){return y(t,e)}));return void l({type:R,ids:G,lastInteractedWith:v});case"Enter":case" ":case"Spacebar":return e.preventDefault(),l({type:p?H:_,id:v,multiSelect:o,lastInteractedWith:v}),s&&!n.has(h.id)&&l({type:z,ids:C(t,[v],n),select:!p||!r.has(v),multiSelect:o,lastInteractedWith:v}),void(f&&l({type:B,id:v,lastInteractedWith:v}));default:if(1===e.key.length)for(var q=x(t,v,a);q!==v;)if(null!=q){if(t[q].name[0].toLowerCase()===e.key.toLowerCase())return void l({type:M,id:q,lastInteractedWith:v});q=x(t,q,a)}else q=t[0].children[0];return}}}};Z.propTypes={data:n.array.isRequired,onSelect:n.func,onExpand:n.func,className:n.string,nodeRenderer:n.func.isRequired,defaultExpandedIds:n.array,defaultSelectedIds:n.array,defaultDisabledIds:n.array,propagateCollapse:n.bool,propagateSelect:n.bool,propagateSelectUpwards:n.bool,multiSelect:n.bool,expandOnKeyboardSelect:n.bool,togglableSelect:n.bool,clickAction:n.oneOf(Object.values(J))},exports.default=Z,exports.flattenTree=function(e){var t=0,a=[];return function e(r,n){if(r.id=t,r.parent=n,a[t]=r,t+=1,null!=r.children&&0!==r.children.length){var d,l=h(r.children);try{for(l.s();!(d=l.n()).done;){e(d.value,r.id)}}catch(e){l.e(e)}finally{l.f()}r.children=r.children.map((function(e){return e.id}))}}(e,null),a};
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("classnames")),a=e(require("prop-types")),n=require("react"),r=e(n);function l(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function d(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==a)return;var n,r,l=[],d=!0,s=!1;try{for(a=a.call(e);!(d=(n=a.next()).done)&&(l.push(n.value),!t||l.length!==t);d=!0);}catch(e){s=!0,r=e}finally{try{d||null==a.return||a.return()}finally{if(s)throw r}}return l}(e,t)||i(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e){return function(e){if(Array.isArray(e))return c(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||i(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){if(e){if("string"==typeof e)return c(e,t);var a=Object.prototype.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?c(e,t):void 0}}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var a=0,n=new Array(t);a<t;a++)n[a]=e[a];return n}function o(e,t){var a="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!a){if(Array.isArray(e)||(a=i(e))||t&&e&&"number"==typeof e.length){a&&(e=a);var n=0,r=function(){};return{s:r,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var l,d=!0,s=!1;return{s:function(){a=a.call(e)},n:function(){var e=a.next();return d=e.done,e},e:function(e){s=!0,l=e},f:function(){try{d||null==a.return||a.return()}finally{if(s)throw l}}}}function u(e,t){var a={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(a[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(a[n[r]]=e[n[r]])}return a}var f=function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return function(e){var a,n=o(t);try{for(n.s();!(a=n.n()).done;){var r=a.value;if(r&&r(e),e.defaultPrevented)break}}catch(e){n.e(e)}finally{n.f()}}},h=function(e,t){var a,n=new Set,r=o(e);try{for(r.s();!(a=r.n()).done;){var l=a.value;t.has(l)||n.add(l)}}catch(e){r.e(e)}finally{r.f()}return n},p=function(e,t){return new Set([].concat(s(h(e,t)),s(h(t,e))))},v=function(e){var t=n.useRef();return n.useEffect((function(){t.current=e}),[e]),t.current},b=function(e,t){return null!=e[t].children&&e[t].children.length>0},I=function(e,t){return e[t].parent},S=function(e,t,a){var n=[];return function e(t,r){var l=t[r];if(null!=l.children){var d,s=o(l.children.filter((function(e){return!a.has(e)})));try{for(s.s();!(d=s.n()).done;){var i=d.value;n.push(i),e(t,i)}}catch(e){s.e(e)}finally{s.f()}}}(e,t),n},y=function(e,t,a){var n=I(e,t);if(null!=n){var r=e[n],l=r.children.indexOf(t)+a;if(r.children[l])return r.children[l]}return null},m=function(e,t,a){var n=e[t];for(e[0].id===t&&(n=e[e[t].children[e[t].children.length-1]]);a.has(n.id)&&b(e,n.id);)n=e[n.children[n.children.length-1]];return n.id},g=function(e,t,a){if(t===e[0].children[0])return null;var n=y(e,t,-1);return null==n?I(e,t):m(e,n,a)},w=function(e,t,a){var n=e[t].id;if(b(e,n)&&a.has(n))return e[n].children[0];for(;;){var r=y(e,n,1);if(null!=r)return r;if(null==(n=I(e,n)))return null}},E=function(e){var t=e.data,a=e.expandedIds,n=e.from,r=e.to,l=[],d=Object.keys(t).length,s=0,i=n;if(l.push(n),n<r)for(;s<d&&(null!=(i=w(t,i,a))&&l.push(i),null!=i&&i!==r);)s+=1;else if(n>r)for(;s<d&&(null!=(i=g(t,i,a))&&l.push(i),null!=i&&i!==r);)s+=1;return l},O=function(e){var t=e.isSelected,a=e.isDisabled,n=e.multiSelect;return a||n?t:!!t||void 0},W=function(e){var t=e.isSelected,a=e.isDisabled,n=e.isHalfSelected,r=e.multiSelect;return a?t:n?"mixed":r?t:!!t||void 0},x=function(e,t,a){return t.concat.apply(t,s(t.filter((function(t){return b(e,t)})).map((function(t){return S(e,t,a)}))))},A=function(e,t,a){null!=t?window.navigator.userAgent.match(/Trident/)?setTimeout((function(){return!t.contains(document.activeElement)&&a()}),0):!t.contains(e.nativeEvent.relatedTarget)&&a():console.warn("ref not set on <ul>")},j={root:"tree",node:"tree-node",branch:"tree-node__branch",branchWrapper:"tree-branch-wrapper",leafListItem:"tree-leaf-list-item",leaf:"tree-node__leaf",nodeGroup:"tree-node-group"},C="COLLAPSE",D="COLLAPSE_MANY",k="EXPAND",L="EXPAND_MANY",N="HALF_SELECT",U="SELECT",R="DESELECT",T="TOGGLE",F="TOGGLE_SELECT",_="SELECT_MANY",B="EXCLUSIVE_CHANGE_SELECT_MANY",K="FOCUS",z="BLUR",H="DISABLE",P="ENABLE",G=function(e,t){switch(t.type){case C:var a=new Set(e.expandedIds);return a.delete(t.id),Object.assign(Object.assign({},e),{expandedIds:a,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case D:var n,r=new Set(e.expandedIds),l=o(t.ids);try{for(l.s();!(n=l.n()).done;){var d=n.value;r.delete(d)}}catch(e){l.e(e)}finally{l.f()}return Object.assign(Object.assign({},e),{expandedIds:r,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case k:var i=new Set(e.expandedIds);return i.add(t.id),Object.assign(Object.assign({},e),{expandedIds:i,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case L:var c=new Set([].concat(s(e.expandedIds),s(t.ids)));return Object.assign(Object.assign({},e),{expandedIds:c,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case T:var u=new Set(e.expandedIds);return e.expandedIds.has(t.id)?u.delete(t.id):u.add(t.id),Object.assign(Object.assign({},e),{expandedIds:u,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case N:if(e.disabledIds.has(t.id))return e;var f=new Set(e.halfSelectedIds),p=new Set(e.selectedIds);return f.add(t.id),p.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:p,halfSelectedIds:f,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case U:if(!t.controlled&&e.disabledIds.has(t.id))return e;var v;t.multiSelect?(v=new Set(e.selectedIds)).add(t.id):(v=new Set).add(t.id);var b=new Set(e.halfSelectedIds);return b.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:v,halfSelectedIds:b,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case R:if(!t.controlled&&e.disabledIds.has(t.id))return e;var I;t.multiSelect?(I=new Set(e.selectedIds)).delete(t.id):I=new Set;var S=new Set(e.halfSelectedIds);return S.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:I,halfSelectedIds:S,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case F:if(e.disabledIds.has(t.id))return e;var y,m=e.selectedIds.has(t.id);t.multiSelect?(y=new Set(e.selectedIds),m?y.delete(t.id):y.add(t.id)):(y=new Set,m||y.add(t.id));var g=new Set(e.halfSelectedIds);return g.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:y,halfSelectedIds:g,tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case _:var w,E=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){w=t.select?new Set([].concat(s(e.selectedIds),s(E))):h(e.selectedIds,new Set(E));var O=h(e.halfSelectedIds,w);return Object.assign(Object.assign({},e),{selectedIds:w,halfSelectedIds:O,lastAction:t.type,lastInteractedWith:t.lastInteractedWith})}return e;case B:var W,x=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){W=t.select?new Set(x):h(e.selectedIds,new Set(x));var A=h(e.halfSelectedIds,W);return Object.assign(Object.assign({},e),{selectedIds:W,halfSelectedIds:A,lastAction:t.type,lastInteractedWith:t.lastInteractedWith})}return e;case K:return Object.assign(Object.assign({},e),{tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case z:return Object.assign(Object.assign({},e),{isFocused:!1});case H:var j=new Set(e.disabledIds);return j.add(t.id),Object.assign(Object.assign({},e),{disabledIds:j});case P:var G=new Set(e.disabledIds);return G.delete(t.id),Object.assign(Object.assign({},e),{disabledIds:G});default:throw new Error("Invalid action passed to the reducer")}},M=function(e){var t=e.data,a=e.controlledIds,r=e.defaultExpandedIds,l=e.defaultSelectedIds,s=e.defaultDisabledIds,i=e.nodeRefs,c=e.onSelect,u=e.onExpand,f=e.onLoadData,S=e.togglableSelect,y=e.multiSelect,m=e.propagateSelect,g=e.propagateSelectUpwards,w=d(n.useReducer(G,{selectedIds:new Set(a||l),tabbableId:t[0].children[0],isFocused:!1,expandedIds:new Set(r),halfSelectedIds:new Set,lastUserSelect:t[0].children[0],lastInteractedWith:null,disabledIds:new Set(s)}),2),E=w[0],O=w[1],W=E.selectedIds,A=E.expandedIds,j=E.disabledIds,D=E.tabbableId,L=E.halfSelectedIds,F=E.lastAction,B=E.lastInteractedWith,z=v(W)||new Set,H=p(W,z);n.useEffect((function(){if(null!=c&&c!==V){var e,a=o(H);try{for(a.s();!(e=a.n()).done;){var n=e.value,r=b(t,n)||!!t[D].isBranch;c({element:t[n],isBranch:r,isExpanded:!!r&&A.has(n),isSelected:W.has(n),isDisabled:j.has(n),isHalfSelected:!!r&&L.has(n),treeState:E})}}catch(e){a.e(e)}finally{a.f()}}}),[t,W,A,j,L,H,c,E]);var P=v(A)||new Set;n.useEffect((function(){var e=p(A,P);if(null!=u&&u!==V){var a,n=o(e);try{for(n.s();!(a=n.n()).done;){var r=a.value;u({element:t[r],isExpanded:A.has(r),isSelected:W.has(r),isDisabled:j.has(r),isHalfSelected:L.has(r),treeState:E})}}catch(e){n.e(e)}finally{n.f()}}}),[t,W,A,j,L,P,u,E]);var M,q,X=(M=t,q=n.useRef(),n.useEffect((function(){q.current=M})),q.current||new Set);return n.useEffect((function(){var e=p(A,P);if(f){var a,n=o(e);try{for(n.s();!(a=n.n()).done;){var r=a.value;f({element:t[r],isExpanded:A.has(r),isSelected:W.has(r),isDisabled:j.has(r),isHalfSelected:L.has(r),treeState:E})}}catch(e){n.e(e)}finally{n.f()}if(X!==t&&S&&m){var l,d=o(A);try{for(d.s();!(l=d.n()).done;){var s=l.value;W.has(s)&&O({type:_,ids:x(t,[s],j),select:!0,multiSelect:y,lastInteractedWith:s})}}catch(e){d.e(e)}finally{d.f()}}}}),[t,W,A,j,L,P,f,E]),n.useEffect((function(){var e=new Set(a),n=h(e,z),r=h(z,e);if(r.size){var l,d=o(r);try{for(d.s();!(l=d.n()).done;){var s=l.value;O({type:R,id:s,multiSelect:y,controlled:!0,lastInteractedWith:s})}}catch(e){d.e(e)}finally{d.f()}}if(n.size){var i,c=o(n);try{for(c.s();!(i=c.n()).done;){var u=i.value;O({type:U,id:u,multiSelect:y,controlled:!0,lastInteractedWith:u}),m&&!j.has(u)&&O({type:_,ids:x(t,[u],j),select:!0,multiSelect:y,lastInteractedWith:u})}}catch(e){c.e(e)}finally{c.f()}}}),[a]),n.useEffect((function(){if(g&&y){var e=new Set(H);B&&F!==K&&F!==C&&F!==k&&F!==T&&e.add(B);var a,n=function(e,t,a,n){var r,l={every:new Set,some:new Set,none:new Set},d=o(t);try{for(d.s();!(r=d.n()).done;)for(var s=r.value;;){var i=I(e,s);if(0===i||null==i||null!=i&&n.has(i))break;var c=e[i].children.filter((function(e){return!n.has(e)}));if(0===c.length)break;c.some((function(e){return a.has(e)||l.some.has(e)}))?c.every((function(e){return a.has(e)}))?l.every.add(i):l.some.add(i):l.none.add(i),s=i}}catch(e){d.e(e)}finally{d.f()}return l}(t,e,W,j),r=n.every,l=n.some,d=n.none,s=o(r);try{for(s.s();!(a=s.n()).done;){var i=a.value;W.has(i)||O({type:U,id:i,multiSelect:y,keepFocus:!0,NotUserAction:!0,lastInteractedWith:B})}}catch(e){s.e(e)}finally{s.f()}var c,u=o(l);try{for(u.s();!(c=u.n()).done;){var f=c.value;L.has(f)||O({type:N,id:f,lastInteractedWith:B})}}catch(e){u.e(e)}finally{u.f()}var h,p=o(d);try{for(p.s();!(h=p.n()).done;){var v=h.value;(W.has(v)||L.has(v))&&O({type:R,id:v,multiSelect:y,keepFocus:!0,NotUserAction:!0,lastInteractedWith:B})}}catch(e){p.e(e)}finally{p.f()}}}),[t,y,g,W,A,j,L,F,z,H,B]),n.useEffect((function(){null!=B&&(null!=D&&null!=(null==i?void 0:i.current)&&function(e){null!=e&&e.focus&&e.focus()}(i.current[D]))}),[D,i,B]),[E,O]},q={select:"SELECT",focus:"FOCUS",exclusiveSelect:"EXCLUSIVE_SELECT"},X=Object.freeze(Object.values(q)),Y=Object.freeze(Object.values({check:"check",select:"select"})),V=function(){},$=r.forwardRef((function(e,a){var l=e.data,s=e.selectedIds,i=e.nodeRenderer,c=e.onSelect,o=void 0===c?V:c,f=e.onExpand,h=void 0===f?V:f,p=e.onLoadData,v=e.className,b=void 0===v?"":v,I=e.multiSelect,S=void 0!==I&&I,y=e.propagateSelect,m=void 0!==y&&y,g=e.propagateSelectUpwards,w=void 0!==g&&g,E=e.propagateCollapse,O=void 0!==E&&E,W=e.expandOnKeyboardSelect,x=void 0!==W&&W,C=e.togglableSelect,D=void 0!==C&&C,k=e.defaultExpandedIds,L=void 0===k?[]:k,N=e.defaultSelectedIds,U=void 0===N?[]:N,R=e.defaultDisabledIds,T=void 0===R?[]:R,F=e.clickAction,_=void 0===F?q.select:F,B=e.nodeAction,K=void 0===B?"select":B,H=e.onBlur,P=u(e,["data","selectedIds","nodeRenderer","onSelect","onExpand","onLoadData","className","multiSelect","propagateSelect","propagateSelectUpwards","propagateCollapse","expandOnKeyboardSelect","togglableSelect","defaultExpandedIds","defaultSelectedIds","defaultDisabledIds","clickAction","nodeAction","onBlur"]),G=n.useRef({}),X=d(M({data:l,controlledIds:s,defaultExpandedIds:L,defaultSelectedIds:U,defaultDisabledIds:T,nodeRefs:G,onSelect:o,onExpand:h,onLoadData:p,togglableSelect:D,multiSelect:S,propagateSelect:m,propagateSelectUpwards:w}),2),Y=X[0],$=X[1];m=m&&S;var Q=n.useRef(null);return null!=a&&(Q=a),r.createElement("ul",Object.assign({className:t(j.root,b),role:"tree","aria-multiselectable":"select"===K?S:void 0,ref:Q,onBlur:function(e){A(e,Q.current,(function(){H&&H({treeState:Y,dispatch:$}),$({type:z})}))},onKeyDown:ee({data:l,tabbableId:Y.tabbableId,expandedIds:Y.expandedIds,selectedIds:Y.selectedIds,disabledIds:Y.disabledIds,halfSelectedIds:Y.halfSelectedIds,dispatch:$,propagateCollapse:O,propagateSelect:m,multiSelect:S,expandOnKeyboardSelect:x,togglableSelect:D})},P),l[0].children.map((function(e,t){return r.createElement(J,Object.assign({key:e,data:l,element:l[e],setsize:l[0].children.length,posinset:t+1,level:1},Y,{state:Y,dispatch:$,nodeRefs:G,baseClassNames:j,nodeRenderer:i,propagateCollapse:O,propagateSelect:m,propagateSelectUpwards:w,multiSelect:S,togglableSelect:D,clickAction:_,nodeAction:K}))})))})),J=function(e){var a=e.element,n=e.dispatch,d=e.data,i=e.selectedIds,c=e.tabbableId,o=e.isFocused,u=e.expandedIds,h=e.disabledIds,p=e.halfSelectedIds,v=e.lastUserSelect,I=e.nodeRefs,y=e.baseClassNames,m=e.nodeRenderer,g=e.nodeAction,w=e.setsize,A=e.posinset,j=e.level,C=e.propagateCollapse,k=e.propagateSelect,L=e.multiSelect,N=e.togglableSelect,R=e.clickAction,z=e.state,H=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(u.has(a.id)&&C){var t=[a.id].concat(s(S(d,a.id,new Set)));n({type:D,ids:t,lastInteractedWith:a.id})}else n({type:T,id:a.id,lastInteractedWith:a.id})},P=function(){return n({type:K,id:a.id,lastInteractedWith:a.id})},G=function(e){if(e.shiftKey){var t=E({data:d,expandedIds:u,from:v,to:a.id}).filter((function(e){return!h.has(e)}));t=k?x(d,t,h):t,n({type:B,select:!0,multiSelect:L,ids:t,lastInteractedWith:a.id})}else e.ctrlKey||q.select?(n({type:N?F:U,id:a.id,multiSelect:L,lastInteractedWith:a.id}),k&&!h.has(a.id)&&n({type:_,ids:x(d,[a.id],h),select:!N||!i.has(a.id),multiSelect:L,lastInteractedWith:a.id})):R===q.exclusiveSelect?n({type:N?F:U,id:a.id,multiSelect:!1,lastInteractedWith:a.id}):R===q.focus&&n({type:K,id:a.id,lastInteractedWith:a.id})},M=function(e){var n;return t(e,(l(n={},"".concat(e,"--expanded"),u.has(a.id)),l(n,"".concat(e,"--selected"),i.has(a.id)),l(n,"".concat(e,"--focused"),c===a.id&&o),n))},X="select"===g?{"aria-selected":O({isSelected:i.has(a.id),isDisabled:h.has(a.id),multiSelect:L})}:{"aria-checked":W({isSelected:i.has(a.id),isDisabled:h.has(a.id),isHalfSelected:p.has(a.id),multiSelect:L})};return b(d,a.id)||a.isBranch?r.createElement("li",Object.assign({role:"treeitem","aria-expanded":u.has(a.id),"aria-setsize":w,"aria-posinset":A,"aria-level":j,"aria-disabled":h.has(a.id),tabIndex:c===a.id?0:-1,ref:function(e){null!=(null==I?void 0:I.current)&&null!=e&&(I.current[a.id]=e)},className:y.branchWrapper},X),r.createElement(r.Fragment,null,m({element:a,isBranch:!0,isSelected:i.has(a.id),isHalfSelected:p.has(a.id),isExpanded:u.has(a.id),isDisabled:h.has(a.id),dispatch:n,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=e.onClick;return{onClick:null==a?f(G,H,P):f(a,P),className:t(M(y.node),y.branch)}},setsize:w,posinset:A,level:j,handleSelect:G,handleExpand:H,treeState:z}),r.createElement(Z,Object.assign({getClasses:M},Q(e))))):r.createElement("li",{role:"none",className:M(y.leafListItem)},m({element:a,isBranch:!1,isSelected:i.has(a.id),isHalfSelected:!1,isExpanded:!1,isDisabled:h.has(a.id),dispatch:n,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.onClick;return Object.assign({role:"treeitem",tabIndex:c===a.id?0:-1,onClick:f(null==n?G:n,P),ref:function(e){null!=(null==I?void 0:I.current)&&(I.current[a.id]=e)},className:t(M(y.node),y.leaf),"aria-setsize":w,"aria-posinset":A,"aria-level":j,disabled:h.has(a.id),"aria-disabled":h.has(a.id)},X)},setsize:w,posinset:A,level:j,handleSelect:G,handleExpand:V,treeState:z}))},Q=function(e){e.setsize,e.posinset;return u(e,["setsize","posinset"])},Z=function(e){var t=e.data,a=e.element,n=e.expandedIds,l=e.getClasses,d=e.baseClassNames,s=e.level,i=u(e,["data","element","expandedIds","getClasses","baseClassNames","level"]);return r.createElement("ul",{role:"group",className:l(d.nodeGroup)},n.has(a.id)&&a.children.length>0&&a.children.map((function(e,l){return r.createElement(J,Object.assign({data:t,expandedIds:n,baseClassNames:d,key:e,element:t[e],setsize:a.children.length,posinset:l+1,level:s+1},i))})))},ee=function(e){var t=e.data,a=e.expandedIds,n=e.selectedIds,r=e.disabledIds,l=e.tabbableId,d=e.dispatch,i=e.propagateCollapse,c=e.propagateSelect,o=e.multiSelect,f=e.expandOnKeyboardSelect,h=e.togglableSelect;return function(e){var p=t[l],v=p.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();t[0];var y=u(t,["0"]),O=Object.values(y).map((function(e){return e.id})).filter((function(e){return!r.has(e)}));d({type:_,multiSelect:o,select:Array.from(n).filter((function(e){return!r.has(e)})).length!==O.length,ids:O,lastInteractedWith:p.id})}else if(e.shiftKey&&("Home"===e.key||"End"===e.key)){var W="Home"===e.key?t[0].children[0]:m(t,v,a),A=E({data:t,expandedIds:a,from:v,to:W}).filter((function(e){return!r.has(e)}));d({type:_,multiSelect:o,select:!0,ids:c?x(t,A,r):A}),d({type:K,id:W,lastInteractedWith:W})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var j=g(t,v,a);return void(null==j||r.has(j)||(d({type:_,ids:c?x(t,[j],r):[j],select:!0,multiSelect:o,lastInteractedWith:j}),d({type:K,id:j,lastInteractedWith:j})));case"ArrowDown":e.preventDefault();var N=w(t,v,a);return void(null==N||r.has(N)||(d({type:_,ids:c?x(t,[N],r):[N],multiSelect:o,select:!0,lastInteractedWith:N}),d({type:K,id:N,lastInteractedWith:N})))}switch(e.key){case"ArrowDown":e.preventDefault();var R=w(t,v,a);return void(null!=R&&d({type:K,id:R,lastInteractedWith:R}));case"ArrowUp":e.preventDefault();var B=g(t,v,a);return void(null!=B&&d({type:K,id:B,lastInteractedWith:B}));case"ArrowLeft":if(e.preventDefault(),(b(t,v)||p.isBranch)&&a.has(l))if(i){var z=[v].concat(s(S(t,v,new Set)));d({type:D,ids:z,lastInteractedWith:p.id})}else d({type:C,id:v,lastInteractedWith:v});else if(!t[0].children.includes(v)){var H=I(t,v);if(null==H)throw new Error("parentId of root element is null");d({type:K,id:H,lastInteractedWith:H})}return;case"ArrowRight":return e.preventDefault(),void((b(t,v)||p.isBranch)&&(a.has(l)?d({type:K,id:p.children[0],lastInteractedWith:p.children[0]}):d({type:k,id:v,lastInteractedWith:v})));case"Home":e.preventDefault(),d({type:K,id:t[0].children[0],lastInteractedWith:t[0].children[0]});break;case"End":e.preventDefault();var P=m(t,t[0].id,a);return void d({type:K,id:P,lastInteractedWith:P});case"*":e.preventDefault();var G=I(t,v);if(null==G)throw new Error("parentId of element is null");var M=t[G].children.filter((function(e){return b(t,e)||t[e].isBranch}));return void d({type:L,ids:M,lastInteractedWith:v});case"Enter":case" ":case"Spacebar":return e.preventDefault(),d({type:h?F:U,id:v,multiSelect:o,lastInteractedWith:v}),c&&!r.has(p.id)&&d({type:_,ids:x(t,[v],r),select:!h||!n.has(v),multiSelect:o,lastInteractedWith:v}),void(f&&d({type:T,id:v,lastInteractedWith:v}));default:if(1===e.key.length)for(var q=w(t,v,a);q!==v;)if(null!=q){if(t[q].name[0].toLowerCase()===e.key.toLowerCase())return void d({type:K,id:q,lastInteractedWith:v});q=w(t,q,a)}else q=t[0].children[0];return}}}};$.propTypes={data:a.array.isRequired,onSelect:a.func,onExpand:a.func,className:a.string,nodeRenderer:a.func.isRequired,defaultExpandedIds:a.array,defaultSelectedIds:a.array,selectedIds:a.array,defaultDisabledIds:a.array,propagateCollapse:a.bool,propagateSelect:a.bool,propagateSelectUpwards:a.bool,multiSelect:a.bool,expandOnKeyboardSelect:a.bool,togglableSelect:a.bool,nodeAction:a.oneOf(Y),clickAction:a.oneOf(X),onBlur:a.func,onLoadData:a.func},exports.CLICK_ACTIONS=X,exports.default=$,exports.flattenTree=function(e){var t=0,a=[];return function e(n,r){var l={id:t,name:n.name,children:[],parent:r};if(a[t]=l,t+=1,null!=n.children&&0!==n.children.length){var d,s=o(n.children);try{for(s.s();!(d=s.n()).done;){e(d.value,l.id)}}catch(e){s.e(e)}finally{s.f()}l.children=a.filter((function(e){return e.parent===l.id})).map((function(e){return e.id}))}}(e,null),a};

@@ -1,1 +0,1 @@

import e,{useRef as t,useEffect as a,useReducer as n}from"react";import r from"classnames";import d from"prop-types";function l(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function i(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?l(Object(a),!0).forEach((function(t){s(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):l(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function s(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function c(){return(c=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e}).apply(this,arguments)}function o(e,t){if(null==e)return{};var a,n,r=function(e,t){if(null==e)return{};var a,n,r={},d=Object.keys(e);for(n=0;n<d.length;n++)a=d[n],t.indexOf(a)>=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(e);for(n=0;n<d.length;n++)a=d[n],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==a)return;var n,r,d=[],l=!0,i=!1;try{for(a=a.call(e);!(l=(n=a.next()).done)&&(d.push(n.value),!t||d.length!==t);l=!0);}catch(e){i=!0,r=e}finally{try{l||null==a.return||a.return()}finally{if(i)throw r}}return d}(e,t)||p(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(e){return function(e){if(Array.isArray(e))return h(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||p(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(e,t){if(e){if("string"==typeof e)return h(e,t);var a=Object.prototype.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?h(e,t):void 0}}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var a=0,n=new Array(t);a<t;a++)n[a]=e[a];return n}function v(e,t){var a="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!a){if(Array.isArray(e)||(a=p(e))||t&&e&&"number"==typeof e.length){a&&(e=a);var n=0,r=function(){};return{s:r,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var d,l=!0,i=!1;return{s:function(){a=a.call(e)},n:function(){var e=a.next();return l=e.done,e},e:function(e){i=!0,d=e},f:function(){try{l||null==a.return||a.return()}finally{if(i)throw d}}}}var I=function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return function(e){var a,n=v(t);try{for(n.s();!(a=n.n()).done;){var r=a.value;if(r&&r(e),e.defaultPrevented)break}}catch(e){n.e(e)}finally{n.f()}}},S=function(e,t){var a,n=new Set,r=v(e);try{for(r.s();!(a=r.n()).done;){var d=a.value;t.has(d)||n.add(d)}}catch(e){r.e(e)}finally{r.f()}return n},b=function(e,t){return new Set([].concat(f(S(e,t)),f(S(t,e))))},y=function(e){var n=t();return a((function(){n.current=e}),[e]),n.current},m=function(e,t){return null!=e[t].children&&e[t].children.length>0},g=function(e,t){return e[t].parent},w=function(e,t,a){var n=[];return function e(t,r){var d=t[r];if(null!=d.children){var l,i=v(d.children.filter((function(e){return!a.has(e)})));try{for(i.s();!(l=i.n()).done;){var s=l.value;n.push(s),e(t,s)}}catch(e){i.e(e)}finally{i.f()}}}(e,t),n},E=function(e,t,a){var n=g(e,t);if(null!=n){var r=e[n],d=r.children.indexOf(t)+a;if(r.children[d])return r.children[d]}return null},W=function(e,t,a){var n=e[t];for(e[0].id===t&&(n=e[e[t].children[e[t].children.length-1]]);a.has(n.id)&&m(e,n.id);)n=e[n.children[n.children.length-1]];return n.id},x=function(e,t,a){if(t===e[0].children[0])return null;var n=E(e,t,-1);return null==n?g(e,t):W(e,n,a)},A=function(e,t,a){var n=e[t].id;if(m(e,n)&&a.has(n))return e[n].children[0];for(;;){var r=E(e,n,1);if(null!=r)return r;if(null==(n=g(e,n)))return null}},O=function(e){var t=e.data,a=e.expandedIds,n=e.from,r=e.to,d=[],l=Object.keys(t).length,i=0,s=n;if(d.push(n),n<r)for(;i<l&&(s=A(t,s,a),d.push(s),null!=s&&s!==r);)i+=1;else if(n>r)for(;i<l&&(s=x(t,s,a),d.push(s),null!=s&&s!==r);)i+=1;return d},C=function(e){var t=0,a=[];return function e(n,r){if(n.id=t,n.parent=r,a[t]=n,t+=1,null!=n.children&&0!==n.children.length){var d,l=v(n.children);try{for(l.s();!(d=l.n()).done;){e(d.value,n.id)}}catch(e){l.e(e)}finally{l.f()}n.children=n.children.map((function(e){return e.id}))}}(e,null),a},D=function(e){var t=e.isSelected,a=e.isDisabled,n=e.multiSelect;if(!a)return n?t:!!t||void 0},k=function(e,t,a){return t.concat.apply(t,f(t.filter((function(t){return m(e,t)})).map((function(t){return w(e,t,a)}))))},N=function(e,t,a){window.navigator.userAgent.match(/Trident/)?setTimeout((function(){return!t.contains(document.activeElement)&&a()}),0):!t.contains(e.nativeEvent.relatedTarget)&&a()},U=["data","nodeRenderer","onSelect","onExpand","className","multiSelect","propagateSelect","propagateSelectUpwards","propagateCollapse","expandOnKeyboardSelect","togglableSelect","defaultExpandedIds","defaultSelectedIds","defaultDisabledIds","clickAction","onBlur"],j=["data","element","expandedIds","getClasses","baseClassNames","level"],L=["0"],P={root:"tree",node:"tree-node",branch:"tree-node__branch",branchWrapper:"tree-branch-wrapper",leafListItem:"tree-leaf-list-item",leaf:"tree-node__leaf",nodeGroup:"tree-node-group"},F="COLLAPSE",T="COLLAPSE_MANY",K="EXPAND",R="EXPAND_MANY",_="HALF_SELECT",B="SELECT",H="DESELECT",z="TOGGLE",G="TOGGLE_SELECT",M="SELECT_MANY",X="EXCLUSIVE_CHANGE_SELECT_MANY",Y="FOCUS",q="BLUR",V="DISABLE",$="ENABLE",J=function(e,t){switch(t.type){case F:var a=new Set(e.expandedIds);return a.delete(t.id),i(i({},e),{},{expandedIds:a,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case T:var n,r=new Set(e.expandedIds),d=v(t.ids);try{for(d.s();!(n=d.n()).done;){var l=n.value;r.delete(l)}}catch(e){d.e(e)}finally{d.f()}return i(i({},e),{},{expandedIds:r,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case K:var s=new Set(e.expandedIds);return s.add(t.id),i(i({},e),{},{expandedIds:s,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case R:var c=new Set([].concat(f(e.expandedIds),f(t.ids)));return i(i({},e),{},{expandedIds:c,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case z:var o=new Set(e.expandedIds);return e.expandedIds.has(t.id)?o.delete(t.id):o.add(t.id),i(i({},e),{},{expandedIds:o,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case _:if(e.disabledIds.has(t.id))return e;var u=new Set(e.halfSelectedIds),p=new Set(e.selectedIds);return u.add(t.id),p.delete(t.id),i(i({},e),{},{selectedIds:p,halfSelectedIds:u,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case B:if(e.disabledIds.has(t.id))return e;var h;t.multiSelect?(h=new Set(e.selectedIds)).add(t.id):(h=new Set).add(t.id);var I=new Set(e.halfSelectedIds);return I.delete(t.id),i(i({},e),{},{selectedIds:h,halfSelectedIds:I,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case H:if(e.disabledIds.has(t.id))return e;var b;t.multiSelect?(b=new Set(e.selectedIds)).delete(t.id):b=new Set;var y=new Set(e.halfSelectedIds);return y.delete(t.id),i(i({},e),{},{selectedIds:b,halfSelectedIds:y,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case G:if(e.disabledIds.has(t.id))return e;var m,g=e.selectedIds.has(t.id);t.multiSelect?(m=new Set(e.selectedIds),g?m.delete(t.id):m.add(t.id)):(m=new Set,g||m.add(t.id));var w=new Set(e.halfSelectedIds);return w.delete(t.id),i(i({},e),{},{selectedIds:m,halfSelectedIds:w,tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case M:var E,W=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){E=t.select?new Set([].concat(f(e.selectedIds),f(W))):S(e.selectedIds,new Set(W));var x=S(e.halfSelectedIds,E);return i(i({},e),{},{selectedIds:E,halfSelectedIds:x,lastAction:t.type,lastInteractedWith:t.lastInteractedWith})}return e;case X:var A,O=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){A=t.select?new Set(O):S(e.selectedIds,new Set(O));var C=S(e.halfSelectedIds,A);return i(i({},e),{},{selectedIds:A,halfSelectedIds:C,lastAction:t.type,lastInteractedWith:t.lastInteractedWith})}return e;case Y:return i(i({},e),{},{tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case q:return i(i({},e),{},{isFocused:!1});case V:var D=new Set(e.disabledIds);return D.add(t.id),i(i({},e),{},{disabledIds:D});case $:var k=new Set(e.disabledIds);return k.delete(t.id),i(i({},e),{},{disabledIds:k});default:throw new Error("Invalid action passed to the reducer")}},Q=function(e){var t=e.data,r=e.defaultExpandedIds,d=e.defaultSelectedIds,l=e.defaultDisabledIds,i=e.nodeRefs,s=e.onSelect,c=e.onExpand,o=e.multiSelect,f=e.propagateSelectUpwards,p=u(n(J,{selectedIds:new Set(d),tabbableId:t[0].children[0],isFocused:!1,expandedIds:new Set(r),halfSelectedIds:new Set,lastUserSelect:t[0].children[0],lastInteractedWith:null,disabledIds:new Set(l)}),2),h=p[0],I=p[1],S=h.selectedIds,w=h.expandedIds,E=h.disabledIds,W=h.tabbableId,x=h.halfSelectedIds,A=h.lastAction,O=h.lastInteractedWith,C=y(S)||new Set,D=b(S,C);a((function(){if(s!==ee){var e,a=v(D);try{for(a.s();!(e=a.n()).done;){var n=e.value,r=m(t,n);s({element:t[n],isBranch:r,isExpanded:r?w.has(n):void 0,isSelected:S.has(n),isDisabled:E.has(n),isHalfSelected:r?x.has(n):void 0,treeState:h})}}catch(e){a.e(e)}finally{a.f()}}}),[t,S,w,E,x,D,s,h]);var k=y(w)||new Set;return a((function(){var e=b(w,k);if(c!==ee){var a,n=v(e);try{for(n.s();!(a=n.n()).done;){var r=a.value;c({element:t[r],isExpanded:w.has(r),isSelected:S.has(r),isDisabled:E.has(r),isHalfSelected:x.has(r),treeState:h})}}catch(e){n.e(e)}finally{n.f()}}}),[t,S,w,E,x,k,c,h]),a((function(){if(f&&o){var e=new Set(D);O&&e.add(O);var a,n=function(e,t,a,n){var r,d={every:new Set,some:new Set,none:new Set},l=v(t);try{for(l.s();!(r=l.n()).done;)for(var i=r.value;;){var s=g(e,i);if(0===s||n.has(s))break;var c=e[s].children.filter((function(e){return!n.has(e)}));if(0===c.length)break;c.some((function(e){return a.has(e)}))?c.every((function(e){return a.has(e)}))?d.every.add(s):d.some.add(s):d.none.add(s),i=s}}catch(e){l.e(e)}finally{l.f()}return d}(t,e,S,E),r=n.every,d=n.some,l=n.none,i=v(r);try{for(i.s();!(a=i.n()).done;){var s=a.value;S.has(s)||I({type:B,id:s,multiSelect:o,keepFocus:!0,NotUserAction:!0,lastInteractedWith:O})}}catch(e){i.e(e)}finally{i.f()}var c,u=v(d);try{for(u.s();!(c=u.n()).done;){var p=c.value;x.has(p)||I({type:_,id:p,multiSelect:o,keepFocus:!0,NotUserAction:!0,lastInteractedWith:O})}}catch(e){u.e(e)}finally{u.f()}var h,b=v(l);try{for(b.s();!(h=b.n()).done;){var y=h.value;(S.has(y)||x.has(y))&&I({type:H,id:y,multiSelect:o,keepFocus:!0,NotUserAction:!0,lastInteractedWith:O})}}catch(e){b.e(e)}finally{b.f()}}}),[t,o,f,S,w,E,x,A,C,D,O]),a((function(){var e;if(null!=O&&null!=W){var t=i.current[W];null!=(e=t)&&e.focus&&e.focus()}}),[W,i,O]),[h,I]},Z={select:"SELECT",focus:"FOCUS",exclusiveSelect:"EXCLUSIVE_SELECT"},ee=function(){},te=e.forwardRef((function(a,n){var d=a.data,l=a.nodeRenderer,i=a.onSelect,s=void 0===i?ee:i,f=a.onExpand,p=void 0===f?ee:f,h=a.className,v=void 0===h?"":h,I=a.multiSelect,S=void 0!==I&&I,b=a.propagateSelect,y=void 0!==b&&b,m=a.propagateSelectUpwards,g=void 0!==m&&m,w=a.propagateCollapse,E=void 0!==w&&w,W=a.expandOnKeyboardSelect,x=void 0!==W&&W,A=a.togglableSelect,O=void 0!==A&&A,C=a.defaultExpandedIds,D=void 0===C?[]:C,k=a.defaultSelectedIds,j=void 0===k?[]:k,L=a.defaultDisabledIds,F=void 0===L?[]:L,T=a.clickAction,K=void 0===T?Z.select:T,R=a.onBlur,_=o(a,U),B=t({}),H=u(Q({data:d,defaultExpandedIds:D,defaultSelectedIds:j,defaultDisabledIds:F,nodeRefs:B,onSelect:s,onExpand:p,multiSelect:S,propagateSelect:y,propagateSelectUpwards:g}),2),z=H[0],G=H[1];y=y&&S;var M=t();return null!=n&&(M=n),e.createElement("ul",c({className:r(P.root,v),role:"tree","aria-multiselectable":S,ref:M,onBlur:function(e){N(e,M.current,(function(){R&&R({treeState:z,dispatch:G}),G({type:q})}))},onKeyDown:re({data:d,tabbableId:z.tabbableId,expandedIds:z.expandedIds,selectedIds:z.selectedIds,disabledIds:z.disabledIds,halfSelectedIds:z.halfSelectedIds,dispatch:G,propagateCollapse:E,propagateSelect:y,multiSelect:S,expandOnKeyboardSelect:x,togglableSelect:O})},_),d[0].children.map((function(t,a){return e.createElement(ae,c({key:t,data:d,element:d[t],setsize:d[0].children.length,posinset:a+1,level:1},z,{state:z,dispatch:G,nodeRefs:B,baseClassNames:P,nodeRenderer:l,propagateCollapse:E,propagateSelect:y,propagateSelectUpwards:g,multiSelect:S,togglableSelect:O,clickAction:K}))})))})),ae=function(t){var a=t.element,n=t.dispatch,d=t.data,l=t.selectedIds,i=t.tabbableId,o=t.isFocused,u=t.expandedIds,p=t.disabledIds,h=t.halfSelectedIds,v=t.lastUserSelect,S=t.nodeRefs,b=t.baseClassNames,y=t.nodeRenderer,g=t.setsize,E=t.posinset,W=t.level,x=t.propagateCollapse,A=t.propagateSelect,C=t.multiSelect,N=t.togglableSelect,U=t.clickAction,j=t.state,L=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(u.has(a.id)&&x){var t=[a.id].concat(f(w(d,a.id,new Set)));n({type:T,ids:t,lastInteractedWith:a.id})}else n({type:z,id:a.id,lastInteractedWith:a.id})},P=function(){return n({type:Y,id:a.id,lastInteractedWith:a.id})},F=function(e){if(e.shiftKey){var t=O({data:d,expandedIds:u,from:v,to:a.id,lastInteractedWith:a.id}).filter((function(e){return!p.has(e)}));t=A?k(d,t,p):t,n({type:X,select:!0,multiSelect:C,ids:t,lastInteractedWith:a.id})}else e.ctrlKey||U===Z.select?(n({type:N?G:B,id:a.id,multiSelect:C,lastInteractedWith:a.id}),A&&!p.has(a.id)&&n({type:M,ids:k(d,[a.id],p),select:!N||!l.has(a.id),multiSelect:C,lastInteractedWith:a.id})):U===Z.exclusiveSelect?n({type:N?G:B,id:a.id,multiSelect:!1,lastInteractedWith:a.id}):U===Z.focus&&n({type:Y,id:a.id,lastInteractedWith:a.id})},K=function(e){var t;return r(e,(s(t={},"".concat(e,"--expanded"),u.has(a.id)),s(t,"".concat(e,"--selected"),l.has(a.id)),s(t,"".concat(e,"--focused"),i===a.id&&o),t))};return m(d,a.id)?e.createElement("li",{role:"treeitem","aria-expanded":u.has(a.id),"aria-selected":D({isSelected:l.has(a.id),isDisabled:p.has(a.id),multiSelect:C}),"aria-setsize":g,"aria-posinset":E,"aria-level":W,disabled:p.has(a.id),"aria-disabled":p.has(a.id),tabIndex:i===a.id?0:-1,ref:function(e){return S.current[a.id]=e},className:b.branchWrapper},y({element:a,isBranch:!0,isSelected:l.has(a.id),isHalfSelected:h.has(a.id),isExpanded:u.has(a.id),isDisabled:p.has(a.id),dispatch:n,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onClick;return{onClick:null==t?I(F,L,P):I(t,P),className:r(K(b.node),b.branch)}},setsize:g,posinset:E,level:W,handleSelect:F,handleExpand:L,treeState:j}),e.createElement(ne,c({element:a,getClasses:K},t))):e.createElement("li",{role:"none",className:K(b.leafListItem)},y({element:a,isBranch:!1,isSelected:l.has(a.id),isHalfSelected:void 0,isExpanded:!1,isDisabled:p.has(a.id),dispatch:n,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onClick;return{role:"treeitem",tabIndex:i===a.id?0:-1,onClick:I(null==t?F:t,P),ref:function(e){return S.current[a.id]=e},className:r(K(b.node),b.leaf),"aria-setsize":g,"aria-posinset":E,"aria-level":W,"aria-selected":D({isSelected:l.has(a.id),isDisabled:p.has(a.id),multiSelect:C}),disabled:p.has(a.id),"aria-disabled":p.has(a.id)}},setsize:g,posinset:E,level:W,handleSelect:F,handleExpand:ee,treeState:j}))},ne=function(t){var a=t.data,n=t.element,r=t.expandedIds,d=t.getClasses,l=t.baseClassNames,i=t.level,s=o(t,j);return e.createElement("ul",{role:"group",className:d(l.nodeGroup)},r.has(n.id)&&n.children.map((function(t,d){return e.createElement(ae,c({data:a,expandedIds:r,baseClassNames:l,key:t,element:a[t],setsize:n.children.length,posinset:d+1,level:i+1},s))})))},re=function(e){var t=e.data,a=e.expandedIds,n=e.selectedIds,r=e.disabledIds,d=e.tabbableId,l=e.dispatch,i=e.propagateCollapse,s=e.propagateSelect,c=e.multiSelect,u=e.expandOnKeyboardSelect,p=e.togglableSelect;return function(e){var h=t[d],v=h.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();t[0];var I=o(t,L),S=Object.values(I).map((function(e){return e.id})).filter((function(e){return!r.has(e)}));l({type:M,multiSelect:c,select:Array.from(n).filter((function(e){return!r.has(e)})).length!==S.length,ids:S,lastInteractedWith:h.id})}else if(e.shiftKey&&("Home"===e.key||"End"===e.key)){var b="Home"===e.key?t[0].children[0]:W(t,v,a),y=O({data:t,expandedIds:a,from:v,to:b}).filter((function(e){return!r.has(e)}));l({type:M,multiSelect:c,select:!0,ids:s?k(t,y,r):y}),l({type:Y,id:b,lastInteractedWith:b})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var E=x(t,v,a);return void(null==E&&r.has(E)||(l({type:M,ids:s?k(t,[E],r):[E],select:!0,multiSelect:c,lastInteractedWith:E}),l({type:Y,id:E,lastInteractedWith:E})));case"ArrowDown":e.preventDefault();var C=A(t,v,a);return void(null==C&&r.has(C)||(l({type:M,ids:s?k(t,[C],r):[C],multiSelect:c,select:!0,lastInteractedWith:C}),l({type:Y,id:C,lastInteractedWith:C})))}switch(e.key){case"ArrowDown":e.preventDefault();var D=A(t,v,a);return void(null!=D&&l({type:Y,id:D,lastInteractedWith:D}));case"ArrowUp":e.preventDefault();var N=x(t,v,a);return void(null!=N&&l({type:Y,id:N,lastInteractedWith:N}));case"ArrowLeft":if(e.preventDefault(),m(t,v)&&a.has(d))if(i){var U=[v].concat(f(w(t,v,new Set)));l({type:T,ids:U,lastInteractedWith:h.id})}else l({type:F,id:v,lastInteractedWith:v});else if(!t[0].children.includes(v)){var j=g(t,v);l({type:Y,id:j,lastInteractedWith:j})}return;case"ArrowRight":return e.preventDefault(),void(m(t,v)&&(a.has(d)?l({type:Y,id:h.children[0],lastInteractedWith:h.children[0]}):l({type:K,id:v,lastInteractedWith:v})));case"Home":e.preventDefault(),l({type:Y,id:t[0].children[0],lastInteractedWith:t[0].children[0]});break;case"End":e.preventDefault();var P=W(t,t[0].id,a);return void l({type:Y,id:P,lastInteractedWith:P});case"*":e.preventDefault();var _=t[g(t,v)].children.filter((function(e){return m(t,e)}));return void l({type:R,ids:_,lastInteractedWith:v});case"Enter":case" ":case"Spacebar":return e.preventDefault(),l({type:p?G:B,id:v,multiSelect:c,lastInteractedWith:v}),s&&!r.has(h.id)&&l({type:M,ids:k(t,[v],r),select:!p||!n.has(v),multiSelect:c,lastInteractedWith:v}),void(u&&l({type:z,id:v,lastInteractedWith:v}));default:if(1===e.key.length)for(var H=A(t,v,a);H!==v;)if(null!=H){if(t[H].name[0].toLowerCase()===e.key.toLowerCase())return void l({type:Y,id:H,lastInteractedWith:v});H=A(t,H,a)}else H=t[0].children[0];return}}}};te.propTypes={data:d.array.isRequired,onSelect:d.func,onExpand:d.func,className:d.string,nodeRenderer:d.func.isRequired,defaultExpandedIds:d.array,defaultSelectedIds:d.array,defaultDisabledIds:d.array,propagateCollapse:d.bool,propagateSelect:d.bool,propagateSelectUpwards:d.bool,multiSelect:d.bool,expandOnKeyboardSelect:d.bool,togglableSelect:d.bool,clickAction:d.oneOf(Object.values(Z))};export default te;export{C as flattenTree};
import e from"classnames";import t from"prop-types";import a,{useRef as n,useEffect as r,useReducer as l}from"react";function d(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==a)return;var n,r,l=[],d=!0,i=!1;try{for(a=a.call(e);!(d=(n=a.next()).done)&&(l.push(n.value),!t||l.length!==t);d=!0);}catch(e){i=!0,r=e}finally{try{d||null==a.return||a.return()}finally{if(i)throw r}}return l}(e,t)||c(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e){return function(e){if(Array.isArray(e))return o(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||c(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e,t){if(e){if("string"==typeof e)return o(e,t);var a=Object.prototype.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?o(e,t):void 0}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var a=0,n=new Array(t);a<t;a++)n[a]=e[a];return n}function u(e,t){var a="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!a){if(Array.isArray(e)||(a=c(e))||t&&e&&"number"==typeof e.length){a&&(e=a);var n=0,r=function(){};return{s:r,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var l,d=!0,i=!1;return{s:function(){a=a.call(e)},n:function(){var e=a.next();return d=e.done,e},e:function(e){i=!0,l=e},f:function(){try{d||null==a.return||a.return()}finally{if(i)throw l}}}}function f(e,t){var a={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(a[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(a[n[r]]=e[n[r]])}return a}var h=function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return function(e){var a,n=u(t);try{for(n.s();!(a=n.n()).done;){var r=a.value;if(r&&r(e),e.defaultPrevented)break}}catch(e){n.e(e)}finally{n.f()}}},p=function(e,t){var a,n=new Set,r=u(e);try{for(r.s();!(a=r.n()).done;){var l=a.value;t.has(l)||n.add(l)}}catch(e){r.e(e)}finally{r.f()}return n},v=function(e,t){return new Set([].concat(s(p(e,t)),s(p(t,e))))},b=function(e){var t=n();return r((function(){t.current=e}),[e]),t.current},S=function(e,t){return null!=e[t].children&&e[t].children.length>0},I=function(e,t){return e[t].parent},y=function(e,t,a){var n=[];return function e(t,r){var l=t[r];if(null!=l.children){var d,i=u(l.children.filter((function(e){return!a.has(e)})));try{for(i.s();!(d=i.n()).done;){var s=d.value;n.push(s),e(t,s)}}catch(e){i.e(e)}finally{i.f()}}}(e,t),n},m=function(e,t,a){var n=I(e,t);if(null!=n){var r=e[n],l=r.children.indexOf(t)+a;if(r.children[l])return r.children[l]}return null},g=function(e,t,a){var n=e[t];for(e[0].id===t&&(n=e[e[t].children[e[t].children.length-1]]);a.has(n.id)&&S(e,n.id);)n=e[n.children[n.children.length-1]];return n.id},w=function(e,t,a){if(t===e[0].children[0])return null;var n=m(e,t,-1);return null==n?I(e,t):g(e,n,a)},E=function(e,t,a){var n=e[t].id;if(S(e,n)&&a.has(n))return e[n].children[0];for(;;){var r=m(e,n,1);if(null!=r)return r;if(null==(n=I(e,n)))return null}},O=function(e){var t=e.data,a=e.expandedIds,n=e.from,r=e.to,l=[],d=Object.keys(t).length,i=0,s=n;if(l.push(n),n<r)for(;i<d&&(null!=(s=E(t,s,a))&&l.push(s),null!=s&&s!==r);)i+=1;else if(n>r)for(;i<d&&(null!=(s=w(t,s,a))&&l.push(s),null!=s&&s!==r);)i+=1;return l},W=function(e){var t=0,a=[];return function e(n,r){var l={id:t,name:n.name,children:[],parent:r};if(a[t]=l,t+=1,null!=n.children&&0!==n.children.length){var d,i=u(n.children);try{for(i.s();!(d=i.n()).done;){e(d.value,l.id)}}catch(e){i.e(e)}finally{i.f()}l.children=a.filter((function(e){return e.parent===l.id})).map((function(e){return e.id}))}}(e,null),a},A=function(e){var t=e.isSelected,a=e.isDisabled,n=e.multiSelect;return a||n?t:!!t||void 0},x=function(e){var t=e.isSelected,a=e.isDisabled,n=e.isHalfSelected,r=e.multiSelect;return a?t:n?"mixed":r?t:!!t||void 0},j=function(e,t,a){return t.concat.apply(t,s(t.filter((function(t){return S(e,t)})).map((function(t){return y(e,t,a)}))))},C=function(e,t,a){null!=t?window.navigator.userAgent.match(/Trident/)?setTimeout((function(){return!t.contains(document.activeElement)&&a()}),0):!t.contains(e.nativeEvent.relatedTarget)&&a():console.warn("ref not set on <ul>")},D={root:"tree",node:"tree-node",branch:"tree-node__branch",branchWrapper:"tree-branch-wrapper",leafListItem:"tree-leaf-list-item",leaf:"tree-node__leaf",nodeGroup:"tree-node-group"},k="COLLAPSE",L="COLLAPSE_MANY",N="EXPAND",U="EXPAND_MANY",F="HALF_SELECT",T="SELECT",B="DESELECT",K="TOGGLE",R="TOGGLE_SELECT",z="SELECT_MANY",_="EXCLUSIVE_CHANGE_SELECT_MANY",H="FOCUS",P="BLUR",G="DISABLE",M="ENABLE",X=function(e,t){switch(t.type){case k:var a=new Set(e.expandedIds);return a.delete(t.id),Object.assign(Object.assign({},e),{expandedIds:a,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case L:var n,r=new Set(e.expandedIds),l=u(t.ids);try{for(l.s();!(n=l.n()).done;){var d=n.value;r.delete(d)}}catch(e){l.e(e)}finally{l.f()}return Object.assign(Object.assign({},e),{expandedIds:r,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case N:var i=new Set(e.expandedIds);return i.add(t.id),Object.assign(Object.assign({},e),{expandedIds:i,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case U:var c=new Set([].concat(s(e.expandedIds),s(t.ids)));return Object.assign(Object.assign({},e),{expandedIds:c,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case K:var o=new Set(e.expandedIds);return e.expandedIds.has(t.id)?o.delete(t.id):o.add(t.id),Object.assign(Object.assign({},e),{expandedIds:o,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case F:if(e.disabledIds.has(t.id))return e;var f=new Set(e.halfSelectedIds),h=new Set(e.selectedIds);return f.add(t.id),h.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:h,halfSelectedIds:f,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case T:if(!t.controlled&&e.disabledIds.has(t.id))return e;var v;t.multiSelect?(v=new Set(e.selectedIds)).add(t.id):(v=new Set).add(t.id);var b=new Set(e.halfSelectedIds);return b.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:v,halfSelectedIds:b,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case B:if(!t.controlled&&e.disabledIds.has(t.id))return e;var S;t.multiSelect?(S=new Set(e.selectedIds)).delete(t.id):S=new Set;var I=new Set(e.halfSelectedIds);return I.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:S,halfSelectedIds:I,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case R:if(e.disabledIds.has(t.id))return e;var y,m=e.selectedIds.has(t.id);t.multiSelect?(y=new Set(e.selectedIds),m?y.delete(t.id):y.add(t.id)):(y=new Set,m||y.add(t.id));var g=new Set(e.halfSelectedIds);return g.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:y,halfSelectedIds:g,tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case z:var w,E=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){w=t.select?new Set([].concat(s(e.selectedIds),s(E))):p(e.selectedIds,new Set(E));var O=p(e.halfSelectedIds,w);return Object.assign(Object.assign({},e),{selectedIds:w,halfSelectedIds:O,lastAction:t.type,lastInteractedWith:t.lastInteractedWith})}return e;case _:var W,A=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){W=t.select?new Set(A):p(e.selectedIds,new Set(A));var x=p(e.halfSelectedIds,W);return Object.assign(Object.assign({},e),{selectedIds:W,halfSelectedIds:x,lastAction:t.type,lastInteractedWith:t.lastInteractedWith})}return e;case H:return Object.assign(Object.assign({},e),{tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case P:return Object.assign(Object.assign({},e),{isFocused:!1});case G:var j=new Set(e.disabledIds);return j.add(t.id),Object.assign(Object.assign({},e),{disabledIds:j});case M:var C=new Set(e.disabledIds);return C.delete(t.id),Object.assign(Object.assign({},e),{disabledIds:C});default:throw new Error("Invalid action passed to the reducer")}},Y=function(e){var t=e.data,a=e.controlledIds,d=e.defaultExpandedIds,s=e.defaultSelectedIds,c=e.defaultDisabledIds,o=e.nodeRefs,f=e.onSelect,h=e.onExpand,y=e.onLoadData,m=e.togglableSelect,g=e.multiSelect,w=e.propagateSelect,E=e.propagateSelectUpwards,O=i(l(X,{selectedIds:new Set(a||s),tabbableId:t[0].children[0],isFocused:!1,expandedIds:new Set(d),halfSelectedIds:new Set,lastUserSelect:t[0].children[0],lastInteractedWith:null,disabledIds:new Set(c)}),2),W=O[0],A=O[1],x=W.selectedIds,C=W.expandedIds,D=W.disabledIds,L=W.tabbableId,U=W.halfSelectedIds,R=W.lastAction,_=W.lastInteractedWith,P=b(x)||new Set,G=v(x,P);r((function(){if(null!=f&&f!==J){var e,a=u(G);try{for(a.s();!(e=a.n()).done;){var n=e.value,r=S(t,n)||!!t[L].isBranch;f({element:t[n],isBranch:r,isExpanded:!!r&&C.has(n),isSelected:x.has(n),isDisabled:D.has(n),isHalfSelected:!!r&&U.has(n),treeState:W})}}catch(e){a.e(e)}finally{a.f()}}}),[t,x,C,D,U,G,f,W]);var M=b(C)||new Set;r((function(){var e=v(C,M);if(null!=h&&h!==J){var a,n=u(e);try{for(n.s();!(a=n.n()).done;){var r=a.value;h({element:t[r],isExpanded:C.has(r),isSelected:x.has(r),isDisabled:D.has(r),isHalfSelected:U.has(r),treeState:W})}}catch(e){n.e(e)}finally{n.f()}}}),[t,x,C,D,U,M,h,W]);var Y,q,V=(Y=t,q=n(),r((function(){q.current=Y})),q.current||new Set);return r((function(){var e=v(C,M);if(y){var a,n=u(e);try{for(n.s();!(a=n.n()).done;){var r=a.value;y({element:t[r],isExpanded:C.has(r),isSelected:x.has(r),isDisabled:D.has(r),isHalfSelected:U.has(r),treeState:W})}}catch(e){n.e(e)}finally{n.f()}if(V!==t&&m&&w){var l,d=u(C);try{for(d.s();!(l=d.n()).done;){var i=l.value;x.has(i)&&A({type:z,ids:j(t,[i],D),select:!0,multiSelect:g,lastInteractedWith:i})}}catch(e){d.e(e)}finally{d.f()}}}}),[t,x,C,D,U,M,y,W]),r((function(){var e=new Set(a),n=p(e,P),r=p(P,e);if(r.size){var l,d=u(r);try{for(d.s();!(l=d.n()).done;){var i=l.value;A({type:B,id:i,multiSelect:g,controlled:!0,lastInteractedWith:i})}}catch(e){d.e(e)}finally{d.f()}}if(n.size){var s,c=u(n);try{for(c.s();!(s=c.n()).done;){var o=s.value;A({type:T,id:o,multiSelect:g,controlled:!0,lastInteractedWith:o}),w&&!D.has(o)&&A({type:z,ids:j(t,[o],D),select:!0,multiSelect:g,lastInteractedWith:o})}}catch(e){c.e(e)}finally{c.f()}}}),[a]),r((function(){if(E&&g){var e=new Set(G);_&&R!==H&&R!==k&&R!==N&&R!==K&&e.add(_);var a,n=function(e,t,a,n){var r,l={every:new Set,some:new Set,none:new Set},d=u(t);try{for(d.s();!(r=d.n()).done;)for(var i=r.value;;){var s=I(e,i);if(0===s||null==s||null!=s&&n.has(s))break;var c=e[s].children.filter((function(e){return!n.has(e)}));if(0===c.length)break;c.some((function(e){return a.has(e)||l.some.has(e)}))?c.every((function(e){return a.has(e)}))?l.every.add(s):l.some.add(s):l.none.add(s),i=s}}catch(e){d.e(e)}finally{d.f()}return l}(t,e,x,D),r=n.every,l=n.some,d=n.none,i=u(r);try{for(i.s();!(a=i.n()).done;){var s=a.value;x.has(s)||A({type:T,id:s,multiSelect:g,keepFocus:!0,NotUserAction:!0,lastInteractedWith:_})}}catch(e){i.e(e)}finally{i.f()}var c,o=u(l);try{for(o.s();!(c=o.n()).done;){var f=c.value;U.has(f)||A({type:F,id:f,lastInteractedWith:_})}}catch(e){o.e(e)}finally{o.f()}var h,p=u(d);try{for(p.s();!(h=p.n()).done;){var v=h.value;(x.has(v)||U.has(v))&&A({type:B,id:v,multiSelect:g,keepFocus:!0,NotUserAction:!0,lastInteractedWith:_})}}catch(e){p.e(e)}finally{p.f()}}}),[t,g,E,x,C,D,U,R,P,G,_]),r((function(){null!=_&&(null!=L&&null!=(null==o?void 0:o.current)&&function(e){null!=e&&e.focus&&e.focus()}(o.current[L]))}),[L,o,_]),[W,A]},q={select:"SELECT",focus:"FOCUS",exclusiveSelect:"EXCLUSIVE_SELECT"},V=Object.freeze(Object.values(q)),$=Object.freeze(Object.values({check:"check",select:"select"})),J=function(){},Q=a.forwardRef((function(t,r){var l=t.data,d=t.selectedIds,s=t.nodeRenderer,c=t.onSelect,o=void 0===c?J:c,u=t.onExpand,h=void 0===u?J:u,p=t.onLoadData,v=t.className,b=void 0===v?"":v,S=t.multiSelect,I=void 0!==S&&S,y=t.propagateSelect,m=void 0!==y&&y,g=t.propagateSelectUpwards,w=void 0!==g&&g,E=t.propagateCollapse,O=void 0!==E&&E,W=t.expandOnKeyboardSelect,A=void 0!==W&&W,x=t.togglableSelect,j=void 0!==x&&x,k=t.defaultExpandedIds,L=void 0===k?[]:k,N=t.defaultSelectedIds,U=void 0===N?[]:N,F=t.defaultDisabledIds,T=void 0===F?[]:F,B=t.clickAction,K=void 0===B?q.select:B,R=t.nodeAction,z=void 0===R?"select":R,_=t.onBlur,H=f(t,["data","selectedIds","nodeRenderer","onSelect","onExpand","onLoadData","className","multiSelect","propagateSelect","propagateSelectUpwards","propagateCollapse","expandOnKeyboardSelect","togglableSelect","defaultExpandedIds","defaultSelectedIds","defaultDisabledIds","clickAction","nodeAction","onBlur"]),G=n({}),M=i(Y({data:l,controlledIds:d,defaultExpandedIds:L,defaultSelectedIds:U,defaultDisabledIds:T,nodeRefs:G,onSelect:o,onExpand:h,onLoadData:p,togglableSelect:j,multiSelect:I,propagateSelect:m,propagateSelectUpwards:w}),2),X=M[0],V=M[1];m=m&&I;var $=n(null);return null!=r&&($=r),a.createElement("ul",Object.assign({className:e(D.root,b),role:"tree","aria-multiselectable":"select"===z?I:void 0,ref:$,onBlur:function(e){C(e,$.current,(function(){_&&_({treeState:X,dispatch:V}),V({type:P})}))},onKeyDown:ae({data:l,tabbableId:X.tabbableId,expandedIds:X.expandedIds,selectedIds:X.selectedIds,disabledIds:X.disabledIds,halfSelectedIds:X.halfSelectedIds,dispatch:V,propagateCollapse:O,propagateSelect:m,multiSelect:I,expandOnKeyboardSelect:A,togglableSelect:j})},H),l[0].children.map((function(e,t){return a.createElement(Z,Object.assign({key:e,data:l,element:l[e],setsize:l[0].children.length,posinset:t+1,level:1},X,{state:X,dispatch:V,nodeRefs:G,baseClassNames:D,nodeRenderer:s,propagateCollapse:O,propagateSelect:m,propagateSelectUpwards:w,multiSelect:I,togglableSelect:j,clickAction:K,nodeAction:z}))})))})),Z=function(t){var n=t.element,r=t.dispatch,l=t.data,i=t.selectedIds,c=t.tabbableId,o=t.isFocused,u=t.expandedIds,f=t.disabledIds,p=t.halfSelectedIds,v=t.lastUserSelect,b=t.nodeRefs,I=t.baseClassNames,m=t.nodeRenderer,g=t.nodeAction,w=t.setsize,E=t.posinset,W=t.level,C=t.propagateCollapse,D=t.propagateSelect,k=t.multiSelect,N=t.togglableSelect,U=t.clickAction,F=t.state,B=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(u.has(n.id)&&C){var t=[n.id].concat(s(y(l,n.id,new Set)));r({type:L,ids:t,lastInteractedWith:n.id})}else r({type:K,id:n.id,lastInteractedWith:n.id})},P=function(){return r({type:H,id:n.id,lastInteractedWith:n.id})},G=function(e){if(e.shiftKey){var t=O({data:l,expandedIds:u,from:v,to:n.id}).filter((function(e){return!f.has(e)}));t=D?j(l,t,f):t,r({type:_,select:!0,multiSelect:k,ids:t,lastInteractedWith:n.id})}else e.ctrlKey||q.select?(r({type:N?R:T,id:n.id,multiSelect:k,lastInteractedWith:n.id}),D&&!f.has(n.id)&&r({type:z,ids:j(l,[n.id],f),select:!N||!i.has(n.id),multiSelect:k,lastInteractedWith:n.id})):U===q.exclusiveSelect?r({type:N?R:T,id:n.id,multiSelect:!1,lastInteractedWith:n.id}):U===q.focus&&r({type:H,id:n.id,lastInteractedWith:n.id})},M=function(t){var a;return e(t,(d(a={},"".concat(t,"--expanded"),u.has(n.id)),d(a,"".concat(t,"--selected"),i.has(n.id)),d(a,"".concat(t,"--focused"),c===n.id&&o),a))},X="select"===g?{"aria-selected":A({isSelected:i.has(n.id),isDisabled:f.has(n.id),multiSelect:k})}:{"aria-checked":x({isSelected:i.has(n.id),isDisabled:f.has(n.id),isHalfSelected:p.has(n.id),multiSelect:k})};return S(l,n.id)||n.isBranch?a.createElement("li",Object.assign({role:"treeitem","aria-expanded":u.has(n.id),"aria-setsize":w,"aria-posinset":E,"aria-level":W,"aria-disabled":f.has(n.id),tabIndex:c===n.id?0:-1,ref:function(e){null!=(null==b?void 0:b.current)&&null!=e&&(b.current[n.id]=e)},className:I.branchWrapper},X),a.createElement(a.Fragment,null,m({element:n,isBranch:!0,isSelected:i.has(n.id),isHalfSelected:p.has(n.id),isExpanded:u.has(n.id),isDisabled:f.has(n.id),dispatch:r,getNodeProps:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=t.onClick;return{onClick:null==a?h(G,B,P):h(a,P),className:e(M(I.node),I.branch)}},setsize:w,posinset:E,level:W,handleSelect:G,handleExpand:B,treeState:F}),a.createElement(te,Object.assign({getClasses:M},ee(t))))):a.createElement("li",{role:"none",className:M(I.leafListItem)},m({element:n,isBranch:!1,isSelected:i.has(n.id),isHalfSelected:!1,isExpanded:!1,isDisabled:f.has(n.id),dispatch:r,getNodeProps:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=t.onClick;return Object.assign({role:"treeitem",tabIndex:c===n.id?0:-1,onClick:h(null==a?G:a,P),ref:function(e){null!=(null==b?void 0:b.current)&&(b.current[n.id]=e)},className:e(M(I.node),I.leaf),"aria-setsize":w,"aria-posinset":E,"aria-level":W,disabled:f.has(n.id),"aria-disabled":f.has(n.id)},X)},setsize:w,posinset:E,level:W,handleSelect:G,handleExpand:J,treeState:F}))},ee=function(e){e.setsize,e.posinset;return f(e,["setsize","posinset"])},te=function(e){var t=e.data,n=e.element,r=e.expandedIds,l=e.getClasses,d=e.baseClassNames,i=e.level,s=f(e,["data","element","expandedIds","getClasses","baseClassNames","level"]);return a.createElement("ul",{role:"group",className:l(d.nodeGroup)},r.has(n.id)&&n.children.length>0&&n.children.map((function(e,l){return a.createElement(Z,Object.assign({data:t,expandedIds:r,baseClassNames:d,key:e,element:t[e],setsize:n.children.length,posinset:l+1,level:i+1},s))})))},ae=function(e){var t=e.data,a=e.expandedIds,n=e.selectedIds,r=e.disabledIds,l=e.tabbableId,d=e.dispatch,i=e.propagateCollapse,c=e.propagateSelect,o=e.multiSelect,u=e.expandOnKeyboardSelect,h=e.togglableSelect;return function(e){var p=t[l],v=p.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();t[0];var b=f(t,["0"]),m=Object.values(b).map((function(e){return e.id})).filter((function(e){return!r.has(e)}));d({type:z,multiSelect:o,select:Array.from(n).filter((function(e){return!r.has(e)})).length!==m.length,ids:m,lastInteractedWith:p.id})}else if(e.shiftKey&&("Home"===e.key||"End"===e.key)){var W="Home"===e.key?t[0].children[0]:g(t,v,a),A=O({data:t,expandedIds:a,from:v,to:W}).filter((function(e){return!r.has(e)}));d({type:z,multiSelect:o,select:!0,ids:c?j(t,A,r):A}),d({type:H,id:W,lastInteractedWith:W})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var x=w(t,v,a);return void(null==x||r.has(x)||(d({type:z,ids:c?j(t,[x],r):[x],select:!0,multiSelect:o,lastInteractedWith:x}),d({type:H,id:x,lastInteractedWith:x})));case"ArrowDown":e.preventDefault();var C=E(t,v,a);return void(null==C||r.has(C)||(d({type:z,ids:c?j(t,[C],r):[C],multiSelect:o,select:!0,lastInteractedWith:C}),d({type:H,id:C,lastInteractedWith:C})))}switch(e.key){case"ArrowDown":e.preventDefault();var D=E(t,v,a);return void(null!=D&&d({type:H,id:D,lastInteractedWith:D}));case"ArrowUp":e.preventDefault();var F=w(t,v,a);return void(null!=F&&d({type:H,id:F,lastInteractedWith:F}));case"ArrowLeft":if(e.preventDefault(),(S(t,v)||p.isBranch)&&a.has(l))if(i){var B=[v].concat(s(y(t,v,new Set)));d({type:L,ids:B,lastInteractedWith:p.id})}else d({type:k,id:v,lastInteractedWith:v});else if(!t[0].children.includes(v)){var _=I(t,v);if(null==_)throw new Error("parentId of root element is null");d({type:H,id:_,lastInteractedWith:_})}return;case"ArrowRight":return e.preventDefault(),void((S(t,v)||p.isBranch)&&(a.has(l)?d({type:H,id:p.children[0],lastInteractedWith:p.children[0]}):d({type:N,id:v,lastInteractedWith:v})));case"Home":e.preventDefault(),d({type:H,id:t[0].children[0],lastInteractedWith:t[0].children[0]});break;case"End":e.preventDefault();var P=g(t,t[0].id,a);return void d({type:H,id:P,lastInteractedWith:P});case"*":e.preventDefault();var G=I(t,v);if(null==G)throw new Error("parentId of element is null");var M=t[G].children.filter((function(e){return S(t,e)||t[e].isBranch}));return void d({type:U,ids:M,lastInteractedWith:v});case"Enter":case" ":case"Spacebar":return e.preventDefault(),d({type:h?R:T,id:v,multiSelect:o,lastInteractedWith:v}),c&&!r.has(p.id)&&d({type:z,ids:j(t,[v],r),select:!h||!n.has(v),multiSelect:o,lastInteractedWith:v}),void(u&&d({type:K,id:v,lastInteractedWith:v}));default:if(1===e.key.length)for(var X=E(t,v,a);X!==v;)if(null!=X){if(t[X].name[0].toLowerCase()===e.key.toLowerCase())return void d({type:H,id:X,lastInteractedWith:v});X=E(t,X,a)}else X=t[0].children[0];return}}}};Q.propTypes={data:t.array.isRequired,onSelect:t.func,onExpand:t.func,className:t.string,nodeRenderer:t.func.isRequired,defaultExpandedIds:t.array,defaultSelectedIds:t.array,selectedIds:t.array,defaultDisabledIds:t.array,propagateCollapse:t.bool,propagateSelect:t.bool,propagateSelectUpwards:t.bool,multiSelect:t.bool,expandOnKeyboardSelect:t.bool,togglableSelect:t.bool,nodeAction:t.oneOf($),clickAction:t.oneOf(V),onBlur:t.func,onLoadData:t.func};export default Q;export{V as CLICK_ACTIONS,W as flattenTree};
{
"name": "react-accessible-treeview",
"description": "A react component that implements the treeview pattern as described by the WAI-ARIA Authoring Practices.",
"version": "2.1.4",
"version": "2.2.0",
"author": "lissitz (https://github.com/lissitz)",
"main": "dist/react-accessible-treeview.cjs.js",
"module": "dist/react-accessible-treeview.esm.js",
"types": "dist/index.d.ts",
"peerDependencies": {

@@ -23,17 +24,20 @@ "classnames": "^2.2.6",

"@storybook/react": "^5.1.11",
"@testing-library/dom": "^6.1.0",
"@testing-library/jest-dom": "^4.1.0",
"@testing-library/react": "^9.1.3",
"babel-jest": "^24.9.0",
"babel-loader": "^8.0.6",
"babel-preset-react-app": "^10.0.1",
"@testing-library/dom": "^8.16.0",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^12.1.5",
"@types/jest": "^28.1.3",
"@typescript-eslint/eslint-plugin": "^5.30.5",
"@typescript-eslint/parser": "^5.30.5",
"babel-jest": "^28.1.3",
"babel-loader": "^8.2.5",
"classnames": "^2.2.6",
"eslint": "^6.1.0",
"eslint-config-react-app": "^5.0.0",
"eslint-plugin-flowtype": "^4.2.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.14.3",
"eslint-plugin-react-hooks": "^2.0.0",
"jest": "^24.9.0",
"eslint": "^8.19.0",
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-flowtype": "^4.7.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.6.0",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^2.5.1",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"lint-staged": "^9.2.2",

@@ -48,3 +52,7 @@ "prettier": "^1.18.2",

"rollup-plugin-node-resolve": "^5.1.0",
"rollup-plugin-terser": "^5.1.1"
"rollup-plugin-terser": "^5.1.1",
"rollup-plugin-typescript2": "^0.32.1",
"ts-jest": "^28.0.5",
"tslib": "^2.4.0",
"typescript": "^4.7.4"
},

@@ -57,8 +65,10 @@ "scripts": {

"prepare": "npm run build",
"test": "jest"
"test": "jest --detectOpenHandles",
"type-check": "tsc --noEmit",
"lint": "eslint \"src/**/*\""
},
"files": [
"dist",
"src/index.js",
"src/TreeView/*.js"
"src/index.ts",
"src/TreeView/*.ts(x)"
],

@@ -65,0 +75,0 @@ "license": "MIT",

@@ -33,2 +33,3 @@ # react-accessible-treeview [![Build Status](https://travis-ci.org/lissitz/react-accessible-treeview.svg?branch=master)](https://travis-ci.org/lissitz/react-accessible-treeview) [![Greenkeeper badge](https://badges.greenkeeper.io/lissitz/react-accessible-treeview.svg)](https://greenkeeper.io/) [![npm version](https://badge.fury.io/js/react-accessible-treeview.svg)](https://badge.fury.io/js/react-accessible-treeview) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

| `defaultDisabledIds` | `array` | `[]` | Array with the ids of the default disabled nodes |
| `selectedIds` | `array` | `[]` | (Controlled) Array with the ids that should be selected |
| `clickAction` | `enum` | `SELECT` | Action to perform on click. One of: EXCLUSIVE_SELECT, FOCUS, SELECT |

@@ -94,3 +95,3 @@ | `onBlur` | `func` | `noop` | Custom onBlur event that is triggered when focusing out of the component as a whole (moving focus between the nodes won't trigger it). |

| `dispatch` | `function` | Function to dispatch actions |
| `treeState` | `function` | state of the treeview |
| `treeState` | `object` | state of the treeview |

@@ -97,0 +98,0 @@ <br/> <br/>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc