react-accessible-treeview
Advanced tools
Comparing version 2.5.3 to 2.5.4
@@ -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=e(require("classnames")),n=e(require("prop-types")),a=require("react"),l=e(a);function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function d(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var a,l,r=[],d=!0,i=!1;try{for(n=n.call(e);!(d=(a=n.next()).done)&&(r.push(a.value),!t||r.length!==t);d=!0);}catch(e){i=!0,l=e}finally{try{d||null==n.return||n.return()}finally{if(i)throw l}}return r}(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 n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}function u(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=c(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var a=0,l=function(){};return{s:l,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:l}}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 r,d=!0,i=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return d=e.done,e},e:function(e){i=!0,r=e},f:function(){try{d||null==n.return||n.return()}finally{if(i)throw r}}}}function f(e,t){var n={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(n[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(a=Object.getOwnPropertySymbols(e);l<a.length;l++)t.indexOf(a[l])<0&&Object.prototype.propertyIsEnumerable.call(e,a[l])&&(n[a[l]]=e[a[l]])}return n}var h=function(){},p=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){var n,a=u(t);try{for(a.s();!(n=a.n()).done;){var l=n.value;if(l&&l(e),e.defaultPrevented)break}}catch(e){a.e(e)}finally{a.f()}}},v=function(e,t){var n,a=new Set,l=u(e);try{for(l.s();!(n=l.n()).done;){var r=n.value;t.has(r)||a.add(r)}}catch(e){l.e(e)}finally{l.f()}return a},S=function(e,t){return new Set([].concat(s(v(e,t)),s(v(t,e))))},y=function(e){var t=a.useRef();return a.useEffect((function(){t.current=e}),[e]),t.current},b=function(e,t){var n;return!!(null===(n=M(e,t).children)||void 0===n?void 0:n.length)},I=function(e,t){return M(e,t).parent},g=function(e,t,n){for(var a=t,l=[];;){var r=I(e,a);if(0===r||null==r||null!=r&&n.has(r))break;l.push(r),a=r}return l},m=function(e,t,n){var a=[];return function e(t,l){var r=M(t,l);if(null!=r.children){var d,i=u(r.children.filter((function(e){return!n.has(e)})));try{for(i.s();!(d=i.n()).done;){var s=d.value;a.push(s),e(t,s)}}catch(e){i.e(e)}finally{i.f()}}}(e,t),a},w=function(e,t,n){var a=I(e,t);if(null!=a){var l=M(e,a),r=l.children.indexOf(t)+n;if(l.children[r])return l.children[r]}return null},E=function(e,t,n){var a=M(e,t);for(k(e).id===t&&(a=M(e,M(e,t).children[M(e,t).children.length-1]));n.has(a.id)&&b(e,a.id);)a=M(e,a.children[a.children.length-1]);return a.id},O=function(e,t,n){if(t===k(e).children[0])return null;var a=w(e,t,-1);return null==a?I(e,t):E(e,a,n)},A=function(e,t,n){var a=M(e,t).id;if(b(e,a)&&n.has(a))return M(e,a).children[0];for(;;){var l=w(e,a,1);if(null!=l)return l;if(null==(a=I(e,a)))return null}},x=function(e){var t=e.data,n=e.expandedIds,a=e.from,l=e.to,r=[],d=t.length,i=0,s=a;if(r.push(a),a<l)for(;i<d&&(null!=(s=A(t,s,n))&&r.push(s),null!=s&&s!==l);)i+=1;else if(a>l)for(;i<d&&(null!=(s=O(t,s,n))&&r.push(s),null!=s&&s!==l);)i+=1;return r},W=function(e){var t=e.isSelected,n=e.isDisabled,a=e.multiSelect;return n||a?t:!!t||void 0},j=function(e){var t=e.isSelected,n=e.isDisabled,a=e.isHalfSelected,l=e.multiSelect;return n?t:a?"mixed":l?t:!!t||void 0},T=function(e,t,n){return t.concat.apply(t,s(t.filter((function(t){return b(e,t)})).map((function(t){return m(e,t,n)}))))},C=function(e,t,n){null!=t?window.navigator.userAgent.match(/Trident/)?setTimeout((function(){return!t.contains(document.activeElement)&&n()}),0):!t.contains(e.nativeEvent.relatedTarget)&&n():console.warn("ref not set on <ul>")},D=function(e,t,n){return b(e,t)&&n.has(t)&&m(e,t,new Set).some((function(e){return n.has(e)}))},N=function(e,t,n){return b(e,t)&&!n.has(t)&&m(e,t,new Set).every((function(e){return n.has(e)}))},L=function(e,t,n){return b(e,t)&&n.has(t)&&m(e,t,new Set).every((function(e){return n.has(e)}))},k=function(e){var t=e.find((function(e){return null===e.parent}));if(!t)throw Error("TreeView data must contain parent node.");return t},M=function(e,t){var n=e.find((function(e){return e.id===t}));if(null==n)throw Error("Node with id=".concat(t," doesn't exist in the tree."));return n},U=function(e){var t=Array.from(new Set(e));return e.length!==t.length},R="COLLAPSE",_="COLLAPSE_MANY",F="EXPAND",B="EXPAND_MANY",z="HALF_SELECT",K="SELECT",H="DESELECT",P="TOGGLE",G="TOGGLE_SELECT",V="SELECT_MANY",q="EXCLUSIVE_CHANGE_SELECT_MANY",Y="FOCUS",X="BLUR",$="DISABLE",J="ENABLE",Q="CLEAR_MANUALLY_TOGGLED",Z="CONTROLLED_SELECT_MANY",ee=function(e,t){switch(t.type){case R:var n=new Set(e.expandedIds);return n.delete(t.id),Object.assign(Object.assign({},e),{expandedIds:n,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case _:var a,l=new Set(e.expandedIds),r=u(t.ids);try{for(r.s();!(a=r.n()).done;){var d=a.value;l.delete(d)}}catch(e){r.e(e)}finally{r.f()}return Object.assign(Object.assign({},e),{expandedIds:l,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case F: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 B: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 P: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 z: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 K:if(!t.NotUserAction&&e.disabledIds.has(t.id))return e;var p;t.multiSelect?(p=new Set(e.selectedIds)).add(t.id):(p=new Set).add(t.id);var S=new Set(e.halfSelectedIds);return S.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:p,halfSelectedIds:S,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled});case H:if(!t.NotUserAction&&e.disabledIds.has(t.id))return e;var y,b=new Set(e.selectedIds);return b.delete(t.id),t.multiSelect?(y=new Set(e.halfSelectedIds)).delete(t.id):y=new Set,Object.assign(Object.assign({},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,lastManuallyToggled:t.lastManuallyToggled});case G:if(e.disabledIds.has(t.id))return e;var I,g=e.selectedIds.has(t.id);t.multiSelect?(I=new Set(e.selectedIds),g?I.delete(t.id):I.add(t.id)):(I=new Set,g||I.add(t.id));var m=new Set(e.halfSelectedIds);return m.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:I,halfSelectedIds:m,tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled});case V: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))):v(e.selectedIds,new Set(E));var O=v(e.halfSelectedIds,w);return Object.assign(Object.assign({},e),{selectedIds:w,halfSelectedIds:O,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled})}return e;case q:var A,x=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){A=t.select?new Set(x):v(e.selectedIds,new Set(x));var W=v(e.halfSelectedIds,A);return Object.assign(Object.assign({},e),{selectedIds:A,halfSelectedIds:W,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled})}return e;case Z:var j;if(t.multiSelect)j=new Set(t.ids);else{j=new Set,t.ids.length>1&&console.warn("Tree in singleSelect mode, only the first item from selectedIds will be selected.");var T=t.ids[0];T&&j.add(T)}var C=new Set(e.halfSelectedIds);t.ids.every((function(e){return C.delete(e)}));var D=new Set(t.ids);return Object.assign(Object.assign({},e),{selectedIds:j,halfSelectedIds:C,controlledIds:D,isFocused:!0,lastAction:t.type});case Y:return Object.assign(Object.assign({},e),{tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case X:return Object.assign(Object.assign({},e),{isFocused:!1});case $:var N=new Set(e.disabledIds);return N.add(t.id),Object.assign(Object.assign({},e),{disabledIds:N});case J:var L=new Set(e.disabledIds);return L.delete(t.id),Object.assign(Object.assign({},e),{disabledIds:L});case Q:return Object.assign(Object.assign({},e),{lastManuallyToggled:null});default:throw new Error("Invalid action passed to the reducer")}},te={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"},ne={select:"SELECT",focus:"FOCUS",exclusiveSelect:"EXCLUSIVE_SELECT"},ae=Object.freeze(Object.values(ne)),le=Object.freeze(Object.values({check:"check",select:"select"})),re=function(e){var n=e.element,a=e.dispatch,r=e.data,i=e.selectedIds,c=e.tabbableId,o=e.isFocused,u=e.expandedIds,v=e.disabledIds,S=e.halfSelectedIds,y=e.lastUserSelect,I=e.nodeRefs,g=e.leafRefs,w=e.baseClassNames,E=e.nodeRenderer,O=e.nodeAction,A=e.setsize,C=e.posinset,N=e.level,k=e.propagateCollapse,M=e.propagateSelect,U=e.multiSelect,R=e.togglableSelect,F=e.clickAction,B=e.state,H=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(u.has(n.id)&&k){var t=[n.id].concat(s(m(r,n.id,new Set)));a({type:_,ids:t,lastInteractedWith:n.id})}else a({type:P,id:n.id,lastInteractedWith:n.id})},X=function(){return a({type:Y,id:n.id,lastInteractedWith:n.id})},$=function(e){if(e.shiftKey){var t=x({data:r,expandedIds:u,from:y,to:n.id}).filter((function(e){return!v.has(e)}));t=M?T(r,t,v):t,a({type:q,select:!0,multiSelect:U,ids:t,lastInteractedWith:n.id,lastManuallyToggled:n.id})}else if(e.ctrlKey||F===ne.select){var l=D(r,n.id,i),d=L(r,n.id,i);a({type:R?l&&!d?z:G:K,id:n.id,multiSelect:U,lastInteractedWith:n.id,lastManuallyToggled:n.id}),M&&!v.has(n.id)&&a({type:V,ids:T(r,[n.id],v),select:!R||!i.has(n.id),multiSelect:U,lastInteractedWith:n.id,lastManuallyToggled:n.id})}else F===ne.exclusiveSelect?a({type:R?G:K,id:n.id,multiSelect:!1,lastInteractedWith:n.id,lastManuallyToggled:n.id}):F===ne.focus&&a({type:Y,id:n.id,lastInteractedWith:n.id})},J=function(e){var a;return t(e,(d(a={},"".concat(e,"--expanded"),u.has(n.id)),d(a,"".concat(e,"--selected"),i.has(n.id)),d(a,"".concat(e,"--focused"),c===n.id&&o),a))},Q="select"===O?{"aria-selected":W({isSelected:i.has(n.id),isDisabled:v.has(n.id),multiSelect:U})}:{"aria-checked":j({isSelected:i.has(n.id),isDisabled:v.has(n.id),isHalfSelected:S.has(n.id),multiSelect:U})};return b(r,n.id)||n.isBranch?l.createElement("li",Object.assign({role:"treeitem","aria-expanded":u.has(n.id),"aria-setsize":A,"aria-posinset":C,"aria-level":N,"aria-disabled":v.has(n.id),tabIndex:c===n.id?0:-1,ref:function(e){null!=(null==I?void 0:I.current)&&null!=e&&(I.current[n.id]=e)},className:w.branchWrapper},Q),l.createElement(l.Fragment,null,E({element:n,isBranch:!0,isSelected:i.has(n.id),isHalfSelected:S.has(n.id),isExpanded:u.has(n.id),isDisabled:v.has(n.id),dispatch:a,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=e.onClick;return{onClick:null==a?p($,H,X):p(a,X),className:t(J(w.node),w.branch),ref:function(e){null!=(null==g?void 0:g.current)&&(g.current[n.id]=e)}}},setsize:A,posinset:C,level:N,handleSelect:$,handleExpand:H,treeState:B}),l.createElement(de,Object.assign({getClasses:J},function(e){e.setsize,e.posinset;return f(e,["setsize","posinset"])}(e))))):l.createElement("li",{role:"none",className:J(w.leafListItem)},E({element:n,isBranch:!1,isSelected:i.has(n.id),isHalfSelected:!1,isExpanded:!1,isDisabled:v.has(n.id),dispatch:a,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=e.onClick;return Object.assign({role:"treeitem",tabIndex:c===n.id?0:-1,onClick:p(null==a?$:a,X),ref:function(e){null!=(null==I?void 0:I.current)&&null!=(null==g?void 0:g.current)&&(I.current[n.id]=e,g.current[n.id]=e)},className:t(J(w.node),w.leaf),"aria-setsize":A,"aria-posinset":C,"aria-level":N,disabled:v.has(n.id),"aria-disabled":v.has(n.id)},Q)},setsize:A,posinset:C,level:N,handleSelect:$,handleExpand:h,treeState:B}))},de=function(e){var t=e.data,n=e.element,a=e.expandedIds,d=e.getClasses,i=e.baseClassNames,s=e.level,c=f(e,["data","element","expandedIds","getClasses","baseClassNames","level"]);return l.createElement("ul",{role:"group",className:d(i.nodeGroup)},a.has(n.id)&&n.children.length>0&&n.children.map((function(e,d){return l.createElement(re,Object.assign({data:t,expandedIds:a,baseClassNames:i,key:"".concat(e,"-").concat(r(e)),element:M(t,e),setsize:n.children.length,posinset:d+1,level:s+1},c))})))},ie=function(e){var t=e.data,n=e.controlledSelectedIds,l=e.controlledExpandedIds,r=e.defaultExpandedIds,d=e.defaultSelectedIds,c=e.defaultDisabledIds,o=e.nodeRefs,f=e.leafRefs,p=e.onSelect,w=e.onNodeSelect,E=e.onExpand,O=e.onLoadData,A=e.togglableSelect,x=e.multiSelect,W=e.propagateSelect,j=e.propagateSelectUpwards,C=k(t),D=i(a.useReducer(ee,{selectedIds:new Set(n||d),controlledIds:new Set(n),tabbableId:C.children[0],isFocused:!1,expandedIds:new Set(l||r),halfSelectedIds:new Set,lastUserSelect:C.children[0],lastInteractedWith:null,lastManuallyToggled:null,disabledIds:new Set(c)}),2),L=D[0],U=D[1],G=L.selectedIds,q=L.controlledIds,X=L.expandedIds,$=L.disabledIds,J=L.tabbableId,te=L.halfSelectedIds,ne=L.lastAction,ae=L.lastInteractedWith,le=L.lastManuallyToggled,re=y(G)||new Set,de=S(G,re);a.useEffect((function(){var e;if(null!=p&&p!==h){var n,a=u(de);try{for(a.s();!(n=a.n()).done;){var l=n.value,r=b(t,l)||!!(null===(e=M(t,J))||void 0===e?void 0:e.isBranch);p({element:M(t,l),isBranch:r,isExpanded:!!r&&X.has(l),isSelected:G.has(l),isDisabled:$.has(l),isHalfSelected:!!r&&te.has(l),treeState:L})}}catch(e){a.e(e)}finally{a.f()}}}),[t,G,X,$,te,de,p,L]),a.useEffect((function(){null!=w&&w!==h&&null!=le&&de.size&&(w({element:M(t,le),isSelected:G.has(le),isBranch:b(t,le),treeState:L}),U({type:Q}))}),[le,G,de]);var ie=y(X)||new Set;a.useEffect((function(){var e=S(X,ie);if(null!=E&&E!==h){var n,a=u(e);try{for(a.s();!(n=a.n()).done;){var l=n.value;E({element:M(t,l),isExpanded:X.has(l),isSelected:G.has(l),isDisabled:$.has(l),isHalfSelected:te.has(l),treeState:L})}}catch(e){a.e(e)}finally{a.f()}}}),[t,G,X,$,te,ie,E,L]);var se,ce,oe=(se=t,ce=a.useRef(),a.useEffect((function(){ce.current=se})),ce.current||new Map);a.useEffect((function(){var e=S(X,ie);if(O){var n,a=u(e);try{for(a.s();!(n=a.n()).done;){var l=n.value;O({element:M(t,l),isExpanded:X.has(l),isSelected:G.has(l),isDisabled:$.has(l),isHalfSelected:te.has(l),treeState:L})}}catch(e){a.e(e)}finally{a.f()}if(oe!==t&&A&&W){var r,d=u(X);try{for(d.s();!(r=d.n()).done;){var i=r.value;G.has(i)&&U({type:V,ids:T(t,[i],$),select:!0,multiSelect:x,lastInteractedWith:i})}}catch(e){d.e(e)}finally{d.f()}}}}),[t,G,X,$,te,ie,O,L]);var ue=S(new Set(n),q);return a.useEffect((function(){if(n){ue.size&&U({type:Z,ids:n,multiSelect:x});var e,a=u(n);try{for(a.s();!(e=a.n()).done;){var l=e.value;W&&!$.has(l)&&U({type:V,ids:T(t,[l],$),select:!0,multiSelect:x})}}catch(e){a.e(e)}finally{a.f()}}}),[n]),a.useEffect((function(){var e=new Set(l),n=v(e,ie),a=v(ie,e);if(a.size){var r,d=u(a);try{for(d.s();!(r=d.n()).done;){var i=r.value;if(b(t,i)||M(t,i).isBranch){var c=[i].concat(s(m(t,i,new Set)));U({type:_,ids:c,lastInteractedWith:i})}}}catch(e){d.e(e)}finally{d.f()}}if(n.size){var o,f=u(n);try{for(f.s();!(o=f.n()).done;){var h=o.value;if(b(t,h)||M(t,h).isBranch){var p=I(t,h);U(p?{type:B,ids:[h,p],lastInteractedWith:h}:{type:F,id:h,lastInteractedWith:h})}}}catch(e){f.e(e)}finally{f.f()}}}),[l]),a.useEffect((function(){if(j){var e=new Set([].concat(s(de),s(q)));ae&&ne!==Y&&ne!==R&&ne!==F&&ne!==P&&e.add(ae);var n,a=function(e,t,n,a,l,r){var d,i={every:new Set,some:new Set,none:new Set},s=u(t);try{for(s.s();!(d=s.n()).done;)for(var c=d.value;;){var o=I(e,c);if(0===o||null==o||null!=o&&a.has(o))break;var f=M(e,o).children.filter((function(e){return!a.has(e)}));if(0===f.length)break;if(f.some((function(e){return n.has(e)||i.some.has(e)||l.has(e)})))f.every((function(e){return n.has(e)}))?i.every.add(o):i.some.add(o);else{var h=g(e,c,a).find((function(e){return n.has(e)}));if(!r&&h){m(e,h,a).forEach((function(e){l.has(e)&&i.none.add(e)}));break}i.none.add(o)}c=o}}catch(e){s.e(e)}finally{s.f()}return i}(t,e,G,$,te,x),l=a.every,r=a.some,d=a.none,i=u(l);try{for(i.s();!(n=i.n()).done;){var c=n.value;G.has(c)||U({type:K,id:c,multiSelect:x||N(t,c,G),keepFocus:!0,NotUserAction:!0,lastInteractedWith:ae})}}catch(e){i.e(e)}finally{i.f()}var o,f=u(r);try{for(f.s();!(o=f.n()).done;){var h=o.value;te.has(h)||U({type:z,id:h,lastInteractedWith:ae})}}catch(e){f.e(e)}finally{f.f()}var p,v=u(d);try{for(v.s();!(p=v.n()).done;){var S=p.value;(G.has(S)||te.has(S))&&U({type:H,id:S,multiSelect:x,keepFocus:!0,NotUserAction:!0,lastInteractedWith:ae,lastManuallyToggled:le})}}catch(e){v.e(e)}finally{v.f()}}}),[t,x,j,G,X,$,te,ne,re,de,ae,ue]),a.useEffect((function(){if(null!=ae&&null!=J&&null!=(null==o?void 0:o.current)&&null!=(null==f?void 0:f.current)){var e=o.current[J];!function(e){null!=e&&e.scrollIntoView&&e.scrollIntoView({block:"nearest"})}(f.current[ae]),function(e){null!=e&&e.focus&&e.focus({preventScroll:!0})}(e)}}),[J,o,f,ae]),[L,U]},se=l.forwardRef((function(e,n){var d=e.data,s=e.selectedIds,c=e.nodeRenderer,o=e.onSelect,u=void 0===o?h:o,p=e.onNodeSelect,v=void 0===p?h:p,S=e.onExpand,y=void 0===S?h:S,b=e.onLoadData,I=e.className,g=void 0===I?"":I,m=e.multiSelect,w=void 0!==m&&m,E=e.propagateSelect,O=void 0!==E&&E,A=e.propagateSelectUpwards,x=void 0!==A&&A,W=e.propagateCollapse,j=void 0!==W&&W,T=e.expandOnKeyboardSelect,D=void 0!==T&&T,N=e.togglableSelect,L=void 0!==N&&N,R=e.defaultExpandedIds,_=void 0===R?[]:R,F=e.defaultSelectedIds,B=void 0===F?[]:F,z=e.defaultDisabledIds,K=void 0===z?[]:z,H=e.clickAction,P=void 0===H?ne.select:H,G=e.nodeAction,V=void 0===G?"select":G,q=e.expandedIds,Y=e.onBlur,$=f(e,["data","selectedIds","nodeRenderer","onSelect","onNodeSelect","onExpand","onLoadData","className","multiSelect","propagateSelect","propagateSelectUpwards","propagateCollapse","expandOnKeyboardSelect","togglableSelect","defaultExpandedIds","defaultSelectedIds","defaultDisabledIds","clickAction","nodeAction","expandedIds","onBlur"]);!function(e){if(U(e.map((function(e){return e.id}))))throw Error("Multiple TreeView nodes have the same ID. IDs must be unique.");if(e.forEach((function(e){if(e.id===e.parent)throw Error("Node with id=".concat(e.id," has parent reference to itself."));if(U(e.children))throw Error("Node with id=".concat(e.id," contains duplicate ids in its children."))})),1!==e.filter((function(e){return null===e.parent})).length)throw Error("TreeView can have only one root node.")}(d);var J=a.useRef({}),Q=a.useRef({}),Z=i(ie({data:d,controlledSelectedIds:s,controlledExpandedIds:q,defaultExpandedIds:_,defaultSelectedIds:B,defaultDisabledIds:K,nodeRefs:J,leafRefs:Q,onSelect:u,onNodeSelect:v,onExpand:y,onLoadData:b,togglableSelect:L,multiSelect:w,propagateSelect:O,propagateSelectUpwards:x}),2),ee=Z[0],ae=Z[1];O=O&&w;var le=a.useRef(null);return null!=n&&(le=n),l.createElement("ul",Object.assign({className:t(te.root,g),role:"tree","aria-multiselectable":"select"===V?w:void 0,ref:le,onBlur:function(e){C(e,le.current,(function(){Y&&Y({treeState:ee,dispatch:ae}),ae({type:X})}))},onKeyDown:ce({data:d,tabbableId:ee.tabbableId,expandedIds:ee.expandedIds,selectedIds:ee.selectedIds,disabledIds:ee.disabledIds,halfSelectedIds:ee.halfSelectedIds,clickAction:P,dispatch:ae,propagateCollapse:j,propagateSelect:O,multiSelect:w,expandOnKeyboardSelect:D,togglableSelect:L})},$),k(d).children.map((function(e,t){return l.createElement(re,Object.assign({key:"".concat(e,"-").concat(r(e)),data:d,element:M(d,e),setsize:k(d).children.length,posinset:t+1,level:1},ee,{state:ee,dispatch:ae,nodeRefs:J,leafRefs:Q,baseClassNames:te,nodeRenderer:c,propagateCollapse:j,propagateSelect:O,propagateSelectUpwards:x,multiSelect:w,togglableSelect:L,clickAction:P,nodeAction:V}))})))})),ce=function(e){var t=e.data,n=e.expandedIds,a=e.selectedIds,l=e.disabledIds,r=e.tabbableId,d=e.dispatch,i=e.propagateCollapse,c=e.propagateSelect,o=e.multiSelect,u=e.expandOnKeyboardSelect,f=e.togglableSelect,h=e.clickAction;return function(e){var p=M(t,r),v=p.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();var S=t.filter((function(e){return null!==e.parent})).map((function(e){return e.id})).filter((function(e){return!l.has(e)}));d({type:V,multiSelect:o,select:Array.from(a).filter((function(e){return!l.has(e)})).length!==S.length,ids:S,lastInteractedWith:p.id})}else if(e.shiftKey&&("Home"===e.key||"End"===e.key)){var y="Home"===e.key?k(t).children[0]:E(t,v,n),g=x({data:t,expandedIds:n,from:v,to:y}).filter((function(e){return!l.has(e)}));d({type:V,multiSelect:o,select:!0,ids:c?T(t,g,l):g}),d({type:Y,id:y,lastInteractedWith:y})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var w=O(t,v,n);return void(null==w||l.has(w)||(d({type:V,ids:c?T(t,[w],l):[w],select:!0,multiSelect:o,lastInteractedWith:w,lastManuallyToggled:w}),d({type:Y,id:w,lastInteractedWith:w})));case"ArrowDown":e.preventDefault();var W=A(t,v,n);return void(null==W||l.has(W)||(d({type:V,ids:c?T(t,[W],l):[W],multiSelect:o,select:!0,lastInteractedWith:W,lastManuallyToggled:W}),d({type:Y,id:W,lastInteractedWith:W})))}switch(e.key){case"ArrowDown":e.preventDefault();var j=A(t,v,n);return void(null!=j&&d({type:Y,id:j,lastInteractedWith:j}));case"ArrowUp":e.preventDefault();var C=O(t,v,n);return void(null!=C&&d({type:Y,id:C,lastInteractedWith:C}));case"ArrowLeft":if(e.preventDefault(),(b(t,v)||p.isBranch)&&n.has(r))if(i){var N=[v].concat(s(m(t,v,new Set)));d({type:_,ids:N,lastInteractedWith:p.id})}else d({type:R,id:v,lastInteractedWith:v});else if(!k(t).children.includes(v)){var U=I(t,v);if(null==U)throw new Error("parentId of root element is null");d({type:Y,id:U,lastInteractedWith:U})}return;case"ArrowRight":return e.preventDefault(),void((b(t,v)||p.isBranch)&&(n.has(r)?d({type:Y,id:p.children[0],lastInteractedWith:p.children[0]}):d({type:F,id:v,lastInteractedWith:v})));case"Home":e.preventDefault(),d({type:Y,id:k(t).children[0],lastInteractedWith:k(t).children[0]});break;case"End":e.preventDefault();var H=E(t,k(t).id,n);return void d({type:Y,id:H,lastInteractedWith:H});case"*":e.preventDefault();var q=I(t,v);if(null==q)throw new Error("parentId of element is null");var X=M(t,q).children.filter((function(e){return b(t,e)||M(t,e).isBranch}));return void d({type:B,ids:X,lastInteractedWith:v});case"Enter":case" ":case"Spacebar":if(e.preventDefault(),h===ne.focus)return;var $=D(t,p.id,a),J=L(t,p.id,a);return d({type:f?$&&!J?z:G:K,id:v,multiSelect:o,lastInteractedWith:v,lastManuallyToggled:v}),c&&!l.has(p.id)&&d({type:V,ids:T(t,[v],l),select:!f||!a.has(v),multiSelect:o,lastInteractedWith:v,lastManuallyToggled:v}),void(u&&d({type:P,id:v,lastInteractedWith:v}));default:if(1===e.key.length)for(var Q=A(t,v,n);Q!==v;)if(null!=Q){if(M(t,Q).name[0].toLowerCase()===e.key.toLowerCase())return void d({type:Y,id:Q,lastInteractedWith:v});Q=A(t,Q,n)}else Q=k(t).children[0];return}}}};se.propTypes={data:n.array.isRequired,onSelect:n.func,onNodeSelect:n.func,onExpand:n.func,className:n.string,nodeRenderer:n.func.isRequired,defaultExpandedIds:n.array,defaultSelectedIds:n.array,expandedIds:n.array,selectedIds:n.array,defaultDisabledIds:n.array,propagateCollapse:n.bool,propagateSelect:n.bool,propagateSelectUpwards:n.bool,multiSelect:n.bool,expandOnKeyboardSelect:n.bool,togglableSelect:n.bool,nodeAction:n.oneOf(le),clickAction:n.oneOf(ae),onBlur:n.func,onLoadData:n.func},exports.CLICK_ACTIONS=ae,exports.default=se,exports.flattenTree=function(e){var t=0,n=[];return function e(a,l){var r,d={id:a.id||t,name:a.name,children:[],parent:l};if(n.find((function(e){return e.id===d.id})))throw Error("Multiple TreeView nodes have the same ID (".concat(d.id,"). IDs must be unique."));if(n.push(d),t+=1,null===(r=a.children)||void 0===r?void 0:r.length){var i,s=u(a.children);try{for(s.s();!(i=s.n()).done;){e(i.value,d.id)}}catch(e){s.e(e)}finally{s.f()}var c,o=u(n.values());try{for(o.s();!(c=o.n()).done;){var f=c.value;f.parent===d.id&&d.children.push(f.id)}}catch(e){o.e(e)}finally{o.f()}}}(e,null),n}; | ||
"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")),n=e(require("prop-types")),a=require("react"),l=e(a);function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function d(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var a,l,r=[],d=!0,i=!1;try{for(n=n.call(e);!(d=(a=n.next()).done)&&(r.push(a.value),!t||r.length!==t);d=!0);}catch(e){i=!0,l=e}finally{try{d||null==n.return||n.return()}finally{if(i)throw l}}return r}(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 n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}function u(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=c(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var a=0,l=function(){};return{s:l,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:l}}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 r,d=!0,i=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return d=e.done,e},e:function(e){i=!0,r=e},f:function(){try{d||null==n.return||n.return()}finally{if(i)throw r}}}}function f(e,t){var n={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(n[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(a=Object.getOwnPropertySymbols(e);l<a.length;l++)t.indexOf(a[l])<0&&Object.prototype.propertyIsEnumerable.call(e,a[l])&&(n[a[l]]=e[a[l]])}return n}var h=function(){},p=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){var n,a=u(t);try{for(a.s();!(n=a.n()).done;){var l=n.value;if(l&&l(e),e.defaultPrevented)break}}catch(e){a.e(e)}finally{a.f()}}},v=function(e,t){var n,a=new Set,l=u(e);try{for(l.s();!(n=l.n()).done;){var r=n.value;t.has(r)||a.add(r)}}catch(e){l.e(e)}finally{l.f()}return a},S=function(e,t){return new Set([].concat(s(v(e,t)),s(v(t,e))))},y=function(e){var t=a.useRef();return a.useEffect((function(){t.current=e}),[e]),t.current},b=function(e,t){var n;return!!(null===(n=U(e,t).children)||void 0===n?void 0:n.length)},I=function(e,t){return U(e,t).parent},g=function(e,t,n){for(var a=t,l=[];;){var r=I(e,a);if(0===r||null==r||null!=r&&n.has(r))break;l.push(r),a=r}return l},m=function(e,t,n){var a=[];return function e(t,l){var r=U(t,l);if(null!=r.children){var d,i=u(r.children.filter((function(e){return!n.has(e)})));try{for(i.s();!(d=i.n()).done;){var s=d.value;a.push(s),e(t,s)}}catch(e){i.e(e)}finally{i.f()}}}(e,t),a},w=function(e,t){var n=U(e,t);return null==n.children?[]:n.children},E=function(e,t,n){var a=I(e,t);if(null!=a){var l=U(e,a),r=l.children.indexOf(t)+n;if(l.children[r])return l.children[r]}return null},O=function(e,t,n){var a=U(e,t);for(M(e).id===t&&(a=U(e,U(e,t).children[U(e,t).children.length-1]));n.has(a.id)&&b(e,a.id);)a=U(e,a.children[a.children.length-1]);return a.id},A=function(e,t,n){if(t===M(e).children[0])return null;var a=E(e,t,-1);return null==a?I(e,t):O(e,a,n)},x=function(e,t,n){var a=U(e,t).id;if(b(e,a)&&n.has(a))return U(e,a).children[0];for(;;){var l=E(e,a,1);if(null!=l)return l;if(null==(a=I(e,a)))return null}},W=function(e){var t=e.data,n=e.expandedIds,a=e.from,l=e.to,r=[],d=t.length,i=0,s=a;if(r.push(a),a<l)for(;i<d&&(null!=(s=x(t,s,n))&&r.push(s),null!=s&&s!==l);)i+=1;else if(a>l)for(;i<d&&(null!=(s=A(t,s,n))&&r.push(s),null!=s&&s!==l);)i+=1;return r},j=function(e){var t=e.isSelected,n=e.isDisabled,a=e.multiSelect;return n||a?t:!!t||void 0},T=function(e){var t=e.isSelected,n=e.isDisabled,a=e.isHalfSelected,l=e.multiSelect;return n?t:a?"mixed":l?t:!!t||void 0},C=function(e,t,n){return t.concat.apply(t,s(t.filter((function(t){return b(e,t)})).map((function(t){return m(e,t,n)}))))},D=function(e,t,n){null!=t?window.navigator.userAgent.match(/Trident/)?setTimeout((function(){return!t.contains(document.activeElement)&&n()}),0):!t.contains(e.nativeEvent.relatedTarget)&&n():console.warn("ref not set on <ul>")},N=function(e,t,n){return b(e,t)&&n.has(t)&&m(e,t,new Set).some((function(e){return n.has(e)}))},L=function(e,t,n){var a=w(e,t);return b(e,t)&&!n.has(t)&&1===a.length&&a.every((function(e){return n.has(e)}))},k=function(e,t,n){var a=w(e,t);return b(e,t)&&n.has(t)&&1===a.length&&a.every((function(e){return n.has(e)}))},M=function(e){var t=e.find((function(e){return null===e.parent}));if(!t)throw Error("TreeView data must contain parent node.");return t},U=function(e,t){var n=e.find((function(e){return e.id===t}));if(null==n)throw Error("Node with id=".concat(t," doesn't exist in the tree."));return n},R=function(e){var t=Array.from(new Set(e));return e.length!==t.length},_="COLLAPSE",F="COLLAPSE_MANY",B="EXPAND",z="EXPAND_MANY",K="HALF_SELECT",H="SELECT",P="DESELECT",G="TOGGLE",V="TOGGLE_SELECT",q="SELECT_MANY",Y="EXCLUSIVE_CHANGE_SELECT_MANY",X="FOCUS",$="BLUR",J="DISABLE",Q="ENABLE",Z="CLEAR_MANUALLY_TOGGLED",ee="CONTROLLED_SELECT_MANY",te=function(e,t){switch(t.type){case _:var n=new Set(e.expandedIds);return n.delete(t.id),Object.assign(Object.assign({},e),{expandedIds:n,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case F:var a,l=new Set(e.expandedIds),r=u(t.ids);try{for(r.s();!(a=r.n()).done;){var d=a.value;l.delete(d)}}catch(e){r.e(e)}finally{r.f()}return Object.assign(Object.assign({},e),{expandedIds:l,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case B: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 z: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 G: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 K: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 H:if(!t.NotUserAction&&e.disabledIds.has(t.id))return e;var p;t.multiSelect?(p=new Set(e.selectedIds)).add(t.id):(p=new Set).add(t.id);var S=new Set(e.halfSelectedIds);return S.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:p,halfSelectedIds:S,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled});case P:if(!t.NotUserAction&&e.disabledIds.has(t.id))return e;var y,b=new Set(e.selectedIds);return b.delete(t.id),t.multiSelect?(y=new Set(e.halfSelectedIds)).delete(t.id):y=new Set,Object.assign(Object.assign({},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,lastManuallyToggled:t.lastManuallyToggled});case V:if(e.disabledIds.has(t.id))return e;var I,g=e.selectedIds.has(t.id);t.multiSelect?(I=new Set(e.selectedIds),g?I.delete(t.id):I.add(t.id)):(I=new Set,g||I.add(t.id));var m=new Set(e.halfSelectedIds);return m.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:I,halfSelectedIds:m,tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled});case q: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))):v(e.selectedIds,new Set(E));var O=v(e.halfSelectedIds,w);return Object.assign(Object.assign({},e),{selectedIds:w,halfSelectedIds:O,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled})}return e;case Y:var A,x=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){A=t.select?new Set(x):v(e.selectedIds,new Set(x));var W=v(e.halfSelectedIds,A);return Object.assign(Object.assign({},e),{selectedIds:A,halfSelectedIds:W,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled})}return e;case ee:var j;if(t.multiSelect)j=new Set(t.ids);else{j=new Set,t.ids.length>1&&console.warn("Tree in singleSelect mode, only the first item from selectedIds will be selected.");var T=t.ids[0];T&&j.add(T)}var C=new Set(e.halfSelectedIds);t.ids.every((function(e){return C.delete(e)}));var D=new Set(t.ids);return Object.assign(Object.assign({},e),{selectedIds:j,halfSelectedIds:C,controlledIds:D,isFocused:!0,lastAction:t.type});case X:return Object.assign(Object.assign({},e),{tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case $:return Object.assign(Object.assign({},e),{isFocused:!1});case J:var N=new Set(e.disabledIds);return N.add(t.id),Object.assign(Object.assign({},e),{disabledIds:N});case Q:var L=new Set(e.disabledIds);return L.delete(t.id),Object.assign(Object.assign({},e),{disabledIds:L});case Z:return Object.assign(Object.assign({},e),{lastManuallyToggled:null});default:throw new Error("Invalid action passed to the reducer")}},ne={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"},ae={select:"SELECT",focus:"FOCUS",exclusiveSelect:"EXCLUSIVE_SELECT"},le=Object.freeze(Object.values(ae)),re=Object.freeze(Object.values({check:"check",select:"select"})),de=function(e){var n=e.element,a=e.dispatch,r=e.data,i=e.selectedIds,c=e.tabbableId,o=e.isFocused,u=e.expandedIds,v=e.disabledIds,S=e.halfSelectedIds,y=e.lastUserSelect,I=e.nodeRefs,g=e.leafRefs,w=e.baseClassNames,E=e.nodeRenderer,O=e.nodeAction,A=e.setsize,x=e.posinset,D=e.level,L=e.propagateCollapse,M=e.propagateSelect,U=e.multiSelect,R=e.togglableSelect,_=e.clickAction,B=e.state,z=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(u.has(n.id)&&L){var t=[n.id].concat(s(m(r,n.id,new Set)));a({type:F,ids:t,lastInteractedWith:n.id})}else a({type:G,id:n.id,lastInteractedWith:n.id})},P=function(){return a({type:X,id:n.id,lastInteractedWith:n.id})},$=function(e){if(e.shiftKey){var t=W({data:r,expandedIds:u,from:y,to:n.id}).filter((function(e){return!v.has(e)}));t=M?C(r,t,v):t,a({type:Y,select:!0,multiSelect:U,ids:t,lastInteractedWith:n.id,lastManuallyToggled:n.id})}else if(e.ctrlKey||_===ae.select){var l=N(r,n.id,i),d=k(r,n.id,i);a({type:R?l&&!d?K:V:H,id:n.id,multiSelect:U,lastInteractedWith:n.id,lastManuallyToggled:n.id}),M&&!v.has(n.id)&&a({type:q,ids:C(r,[n.id],v),select:!R||!i.has(n.id),multiSelect:U,lastInteractedWith:n.id,lastManuallyToggled:n.id})}else _===ae.exclusiveSelect?a({type:R?V:H,id:n.id,multiSelect:!1,lastInteractedWith:n.id,lastManuallyToggled:n.id}):_===ae.focus&&a({type:X,id:n.id,lastInteractedWith:n.id})},J=function(e){var a;return t(e,(d(a={},"".concat(e,"--expanded"),u.has(n.id)),d(a,"".concat(e,"--selected"),i.has(n.id)),d(a,"".concat(e,"--focused"),c===n.id&&o),a))},Q="select"===O?{"aria-selected":j({isSelected:i.has(n.id),isDisabled:v.has(n.id),multiSelect:U})}:{"aria-checked":T({isSelected:i.has(n.id),isDisabled:v.has(n.id),isHalfSelected:S.has(n.id),multiSelect:U})};return b(r,n.id)||n.isBranch?l.createElement("li",Object.assign({role:"treeitem","aria-expanded":u.has(n.id),"aria-setsize":A,"aria-posinset":x,"aria-level":D,"aria-disabled":v.has(n.id),tabIndex:c===n.id?0:-1,ref:function(e){null!=(null==I?void 0:I.current)&&null!=e&&(I.current[n.id]=e)},className:w.branchWrapper},Q),l.createElement(l.Fragment,null,E({element:n,isBranch:!0,isSelected:i.has(n.id),isHalfSelected:S.has(n.id),isExpanded:u.has(n.id),isDisabled:v.has(n.id),dispatch:a,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=e.onClick;return{onClick:null==a?p($,z,P):p(a,P),className:t(J(w.node),w.branch),ref:function(e){null!=(null==g?void 0:g.current)&&(g.current[n.id]=e)}}},setsize:A,posinset:x,level:D,handleSelect:$,handleExpand:z,treeState:B}),l.createElement(ie,Object.assign({getClasses:J},function(e){e.setsize,e.posinset;return f(e,["setsize","posinset"])}(e))))):l.createElement("li",{role:"none",className:J(w.leafListItem)},E({element:n,isBranch:!1,isSelected:i.has(n.id),isHalfSelected:!1,isExpanded:!1,isDisabled:v.has(n.id),dispatch:a,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=e.onClick;return Object.assign({role:"treeitem",tabIndex:c===n.id?0:-1,onClick:p(null==a?$:a,P),ref:function(e){null!=(null==I?void 0:I.current)&&null!=(null==g?void 0:g.current)&&(I.current[n.id]=e,g.current[n.id]=e)},className:t(J(w.node),w.leaf),"aria-setsize":A,"aria-posinset":x,"aria-level":D,disabled:v.has(n.id),"aria-disabled":v.has(n.id)},Q)},setsize:A,posinset:x,level:D,handleSelect:$,handleExpand:h,treeState:B}))},ie=function(e){var t=e.data,n=e.element,a=e.expandedIds,d=e.getClasses,i=e.baseClassNames,s=e.level,c=f(e,["data","element","expandedIds","getClasses","baseClassNames","level"]);return l.createElement("ul",{role:"group",className:d(i.nodeGroup)},a.has(n.id)&&n.children.length>0&&n.children.map((function(e,d){return l.createElement(de,Object.assign({data:t,expandedIds:a,baseClassNames:i,key:"".concat(e,"-").concat(r(e)),element:U(t,e),setsize:n.children.length,posinset:d+1,level:s+1},c))})))},se=function(e){var t=e.data,n=e.controlledSelectedIds,l=e.controlledExpandedIds,r=e.defaultExpandedIds,d=e.defaultSelectedIds,c=e.defaultDisabledIds,o=e.nodeRefs,f=e.leafRefs,p=e.onSelect,w=e.onNodeSelect,E=e.onExpand,O=e.onLoadData,A=e.togglableSelect,x=e.multiSelect,W=e.propagateSelect,j=e.propagateSelectUpwards,T=M(t),D=i(a.useReducer(te,{selectedIds:new Set(n||d),controlledIds:new Set(n),tabbableId:T.children[0],isFocused:!1,expandedIds:new Set(l||r),halfSelectedIds:new Set,lastUserSelect:T.children[0],lastInteractedWith:null,lastManuallyToggled:null,disabledIds:new Set(c)}),2),N=D[0],k=D[1],R=N.selectedIds,V=N.controlledIds,Y=N.expandedIds,$=N.disabledIds,J=N.tabbableId,Q=N.halfSelectedIds,ne=N.lastAction,ae=N.lastInteractedWith,le=N.lastManuallyToggled,re=y(R)||new Set,de=S(R,re);a.useEffect((function(){var e;if(null!=p&&p!==h){var n,a=u(de);try{for(a.s();!(n=a.n()).done;){var l=n.value,r=b(t,l)||!!(null===(e=U(t,J))||void 0===e?void 0:e.isBranch);p({element:U(t,l),isBranch:r,isExpanded:!!r&&Y.has(l),isSelected:R.has(l),isDisabled:$.has(l),isHalfSelected:!!r&&Q.has(l),treeState:N})}}catch(e){a.e(e)}finally{a.f()}}}),[t,R,Y,$,Q,de,p,N]),a.useEffect((function(){null!=w&&w!==h&&null!=le&&de.size&&(w({element:U(t,le),isSelected:R.has(le),isBranch:b(t,le),treeState:N}),k({type:Z}))}),[le,R,de]);var ie=y(Y)||new Set;a.useEffect((function(){var e=S(Y,ie);if(null!=E&&E!==h){var n,a=u(e);try{for(a.s();!(n=a.n()).done;){var l=n.value;E({element:U(t,l),isExpanded:Y.has(l),isSelected:R.has(l),isDisabled:$.has(l),isHalfSelected:Q.has(l),treeState:N})}}catch(e){a.e(e)}finally{a.f()}}}),[t,R,Y,$,Q,ie,E,N]);var se,ce,oe=(se=t,ce=a.useRef(),a.useEffect((function(){ce.current=se})),ce.current||new Map);a.useEffect((function(){var e=S(Y,ie);if(O){var n,a=u(e);try{for(a.s();!(n=a.n()).done;){var l=n.value;O({element:U(t,l),isExpanded:Y.has(l),isSelected:R.has(l),isDisabled:$.has(l),isHalfSelected:Q.has(l),treeState:N})}}catch(e){a.e(e)}finally{a.f()}if(oe!==t&&A&&W){var r,d=u(Y);try{for(d.s();!(r=d.n()).done;){var i=r.value;R.has(i)&&k({type:q,ids:C(t,[i],$),select:!0,multiSelect:x,lastInteractedWith:i})}}catch(e){d.e(e)}finally{d.f()}}}}),[t,R,Y,$,Q,ie,O,N]);var ue=S(new Set(n),V);return a.useEffect((function(){if(n){ue.size&&k({type:ee,ids:n,multiSelect:x});var e,a=u(n);try{for(a.s();!(e=a.n()).done;){var l=e.value;W&&!$.has(l)&&k({type:q,ids:C(t,[l],$),select:!0,multiSelect:x})}}catch(e){a.e(e)}finally{a.f()}}}),[n]),a.useEffect((function(){var e=new Set(l),n=v(e,ie),a=v(ie,e);if(a.size){var r,d=u(a);try{for(d.s();!(r=d.n()).done;){var i=r.value;if(b(t,i)||U(t,i).isBranch){var c=[i].concat(s(m(t,i,new Set)));k({type:F,ids:c,lastInteractedWith:i})}}}catch(e){d.e(e)}finally{d.f()}}if(n.size){var o,f=u(n);try{for(f.s();!(o=f.n()).done;){var h=o.value;if(b(t,h)||U(t,h).isBranch){var p=I(t,h);k(p?{type:z,ids:[h,p],lastInteractedWith:h}:{type:B,id:h,lastInteractedWith:h})}}}catch(e){f.e(e)}finally{f.f()}}}),[l]),a.useEffect((function(){if(j){var e=new Set([].concat(s(de),s(V)));ae&&ne!==X&&ne!==_&&ne!==B&&ne!==G&&e.add(ae);var n,a=function(e,t,n,a,l,r){var d,i={every:new Set,some:new Set,none:new Set},s=u(t);try{for(s.s();!(d=s.n()).done;)for(var c=d.value;;){var o=I(e,c);if(0===o||null==o||null!=o&&a.has(o))break;var f=U(e,o).children.filter((function(e){return!a.has(e)}));if(0===f.length)break;if(f.some((function(e){return n.has(e)||i.some.has(e)||l.has(e)})))f.every((function(e){return n.has(e)}))?i.every.add(o):i.some.add(o);else{var h=g(e,c,a).find((function(e){return n.has(e)}));if(!r&&h){m(e,h,a).forEach((function(e){l.has(e)&&i.none.add(e)}));break}i.none.add(o)}c=o}}catch(e){s.e(e)}finally{s.f()}return i}(t,e,R,$,Q,x),l=a.every,r=a.some,d=a.none,i=u(l);try{for(i.s();!(n=i.n()).done;){var c=n.value;R.has(c)||k({type:H,id:c,multiSelect:x||L(t,c,R),keepFocus:!0,NotUserAction:!0,lastInteractedWith:ae})}}catch(e){i.e(e)}finally{i.f()}var o,f=u(r);try{for(f.s();!(o=f.n()).done;){var h=o.value;Q.has(h)||k({type:K,id:h,lastInteractedWith:ae})}}catch(e){f.e(e)}finally{f.f()}var p,v=u(d);try{for(v.s();!(p=v.n()).done;){var S=p.value;(R.has(S)||Q.has(S))&&k({type:P,id:S,multiSelect:x,keepFocus:!0,NotUserAction:!0,lastInteractedWith:ae,lastManuallyToggled:le})}}catch(e){v.e(e)}finally{v.f()}}}),[t,x,j,R,Y,$,Q,ne,re,de,ae,ue]),a.useEffect((function(){if(null!=ae&&null!=J&&null!=(null==o?void 0:o.current)&&null!=(null==f?void 0:f.current)){var e=o.current[J];!function(e){null!=e&&e.scrollIntoView&&e.scrollIntoView({block:"nearest"})}(f.current[ae]),function(e){null!=e&&e.focus&&e.focus({preventScroll:!0})}(e)}}),[J,o,f,ae]),[N,k]},ce=l.forwardRef((function(e,n){var d=e.data,s=e.selectedIds,c=e.nodeRenderer,o=e.onSelect,u=void 0===o?h:o,p=e.onNodeSelect,v=void 0===p?h:p,S=e.onExpand,y=void 0===S?h:S,b=e.onLoadData,I=e.className,g=void 0===I?"":I,m=e.multiSelect,w=void 0!==m&&m,E=e.propagateSelect,O=void 0!==E&&E,A=e.propagateSelectUpwards,x=void 0!==A&&A,W=e.propagateCollapse,j=void 0!==W&&W,T=e.expandOnKeyboardSelect,C=void 0!==T&&T,N=e.togglableSelect,L=void 0!==N&&N,k=e.defaultExpandedIds,_=void 0===k?[]:k,F=e.defaultSelectedIds,B=void 0===F?[]:F,z=e.defaultDisabledIds,K=void 0===z?[]:z,H=e.clickAction,P=void 0===H?ae.select:H,G=e.nodeAction,V=void 0===G?"select":G,q=e.expandedIds,Y=e.onBlur,X=f(e,["data","selectedIds","nodeRenderer","onSelect","onNodeSelect","onExpand","onLoadData","className","multiSelect","propagateSelect","propagateSelectUpwards","propagateCollapse","expandOnKeyboardSelect","togglableSelect","defaultExpandedIds","defaultSelectedIds","defaultDisabledIds","clickAction","nodeAction","expandedIds","onBlur"]);!function(e){if(R(e.map((function(e){return e.id}))))throw Error("Multiple TreeView nodes have the same ID. IDs must be unique.");if(e.forEach((function(e){if(e.id===e.parent)throw Error("Node with id=".concat(e.id," has parent reference to itself."));if(R(e.children))throw Error("Node with id=".concat(e.id," contains duplicate ids in its children."))})),1!==e.filter((function(e){return null===e.parent})).length)throw Error("TreeView can have only one root node.")}(d);var J=a.useRef({}),Q=a.useRef({}),Z=i(se({data:d,controlledSelectedIds:s,controlledExpandedIds:q,defaultExpandedIds:_,defaultSelectedIds:B,defaultDisabledIds:K,nodeRefs:J,leafRefs:Q,onSelect:u,onNodeSelect:v,onExpand:y,onLoadData:b,togglableSelect:L,multiSelect:w,propagateSelect:O,propagateSelectUpwards:x}),2),ee=Z[0],te=Z[1];O=O&&w;var le=a.useRef(null);return null!=n&&(le=n),l.createElement("ul",Object.assign({className:t(ne.root,g),role:"tree","aria-multiselectable":"select"===V?w:void 0,ref:le,onBlur:function(e){D(e,le.current,(function(){Y&&Y({treeState:ee,dispatch:te}),te({type:$})}))},onKeyDown:oe({data:d,tabbableId:ee.tabbableId,expandedIds:ee.expandedIds,selectedIds:ee.selectedIds,disabledIds:ee.disabledIds,halfSelectedIds:ee.halfSelectedIds,clickAction:P,dispatch:te,propagateCollapse:j,propagateSelect:O,multiSelect:w,expandOnKeyboardSelect:C,togglableSelect:L})},X),M(d).children.map((function(e,t){return l.createElement(de,Object.assign({key:"".concat(e,"-").concat(r(e)),data:d,element:U(d,e),setsize:M(d).children.length,posinset:t+1,level:1},ee,{state:ee,dispatch:te,nodeRefs:J,leafRefs:Q,baseClassNames:ne,nodeRenderer:c,propagateCollapse:j,propagateSelect:O,propagateSelectUpwards:x,multiSelect:w,togglableSelect:L,clickAction:P,nodeAction:V}))})))})),oe=function(e){var t=e.data,n=e.expandedIds,a=e.selectedIds,l=e.disabledIds,r=e.tabbableId,d=e.dispatch,i=e.propagateCollapse,c=e.propagateSelect,o=e.multiSelect,u=e.expandOnKeyboardSelect,f=e.togglableSelect,h=e.clickAction;return function(e){var p=U(t,r),v=p.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();var S=t.filter((function(e){return null!==e.parent})).map((function(e){return e.id})).filter((function(e){return!l.has(e)}));d({type:q,multiSelect:o,select:Array.from(a).filter((function(e){return!l.has(e)})).length!==S.length,ids:S,lastInteractedWith:p.id})}else if(e.shiftKey&&("Home"===e.key||"End"===e.key)){var y="Home"===e.key?M(t).children[0]:O(t,v,n),g=W({data:t,expandedIds:n,from:v,to:y}).filter((function(e){return!l.has(e)}));d({type:q,multiSelect:o,select:!0,ids:c?C(t,g,l):g}),d({type:X,id:y,lastInteractedWith:y})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var w=A(t,v,n);return void(null==w||l.has(w)||(d({type:q,ids:c?C(t,[w],l):[w],select:!0,multiSelect:o,lastInteractedWith:w,lastManuallyToggled:w}),d({type:X,id:w,lastInteractedWith:w})));case"ArrowDown":e.preventDefault();var E=x(t,v,n);return void(null==E||l.has(E)||(d({type:q,ids:c?C(t,[E],l):[E],multiSelect:o,select:!0,lastInteractedWith:E,lastManuallyToggled:E}),d({type:X,id:E,lastInteractedWith:E})))}switch(e.key){case"ArrowDown":e.preventDefault();var j=x(t,v,n);return void(null!=j&&d({type:X,id:j,lastInteractedWith:j}));case"ArrowUp":e.preventDefault();var T=A(t,v,n);return void(null!=T&&d({type:X,id:T,lastInteractedWith:T}));case"ArrowLeft":if(e.preventDefault(),(b(t,v)||p.isBranch)&&n.has(r))if(i){var D=[v].concat(s(m(t,v,new Set)));d({type:F,ids:D,lastInteractedWith:p.id})}else d({type:_,id:v,lastInteractedWith:v});else if(!M(t).children.includes(v)){var L=I(t,v);if(null==L)throw new Error("parentId of root element is null");d({type:X,id:L,lastInteractedWith:L})}return;case"ArrowRight":return e.preventDefault(),void((b(t,v)||p.isBranch)&&(n.has(r)?d({type:X,id:p.children[0],lastInteractedWith:p.children[0]}):d({type:B,id:v,lastInteractedWith:v})));case"Home":e.preventDefault(),d({type:X,id:M(t).children[0],lastInteractedWith:M(t).children[0]});break;case"End":e.preventDefault();var R=O(t,M(t).id,n);return void d({type:X,id:R,lastInteractedWith:R});case"*":e.preventDefault();var P=I(t,v);if(null==P)throw new Error("parentId of element is null");var Y=U(t,P).children.filter((function(e){return b(t,e)||U(t,e).isBranch}));return void d({type:z,ids:Y,lastInteractedWith:v});case"Enter":case" ":case"Spacebar":if(e.preventDefault(),h===ae.focus)return;var $=N(t,p.id,a),J=k(t,p.id,a);return d({type:f?$&&!J?K:V:H,id:v,multiSelect:o,lastInteractedWith:v,lastManuallyToggled:v}),c&&!l.has(p.id)&&d({type:q,ids:C(t,[v],l),select:!f||!a.has(v),multiSelect:o,lastInteractedWith:v,lastManuallyToggled:v}),void(u&&d({type:G,id:v,lastInteractedWith:v}));default:if(1===e.key.length)for(var Q=x(t,v,n);Q!==v;)if(null!=Q){if(U(t,Q).name[0].toLowerCase()===e.key.toLowerCase())return void d({type:X,id:Q,lastInteractedWith:v});Q=x(t,Q,n)}else Q=M(t).children[0];return}}}};ce.propTypes={data:n.array.isRequired,onSelect:n.func,onNodeSelect:n.func,onExpand:n.func,className:n.string,nodeRenderer:n.func.isRequired,defaultExpandedIds:n.array,defaultSelectedIds:n.array,expandedIds:n.array,selectedIds:n.array,defaultDisabledIds:n.array,propagateCollapse:n.bool,propagateSelect:n.bool,propagateSelectUpwards:n.bool,multiSelect:n.bool,expandOnKeyboardSelect:n.bool,togglableSelect:n.bool,nodeAction:n.oneOf(re),clickAction:n.oneOf(le),onBlur:n.func,onLoadData:n.func},exports.CLICK_ACTIONS=le,exports.default=ce,exports.flattenTree=function(e){var t=0,n=[];return function e(a,l){var r,d={id:a.id||t,name:a.name,children:[],parent:l};if(n.find((function(e){return e.id===d.id})))throw Error("Multiple TreeView nodes have the same ID (".concat(d.id,"). IDs must be unique."));if(n.push(d),t+=1,null===(r=a.children)||void 0===r?void 0:r.length){var i,s=u(a.children);try{for(s.s();!(i=s.n()).done;){e(i.value,d.id)}}catch(e){s.e(e)}finally{s.f()}var c,o=u(n.values());try{for(o.s();!(c=o.n()).done;){var f=c.value;f.parent===d.id&&d.children.push(f.id)}}catch(e){o.e(e)}finally{o.f()}}}(e,null),n}; |
@@ -1,1 +0,1 @@ | ||
import e from"classnames";import t from"prop-types";import a,{useRef as n,useEffect as l,useReducer as r}from"react";function d(e){return(d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(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(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,l,r=[],d=!0,i=!1;try{for(a=a.call(e);!(d=(n=a.next()).done)&&(r.push(n.value),!t||r.length!==t);d=!0);}catch(e){i=!0,l=e}finally{try{d||null==a.return||a.return()}finally{if(i)throw l}}return r}(e,t)||o(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 c(e){return function(e){if(Array.isArray(e))return u(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||o(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 o(e,t){if(e){if("string"==typeof e)return u(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)?u(e,t):void 0}}function u(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 f(e,t){var a="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!a){if(Array.isArray(e)||(a=o(e))||t&&e&&"number"==typeof e.length){a&&(e=a);var n=0,l=function(){};return{s:l,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:l}}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 r,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,r=e},f:function(){try{d||null==a.return||a.return()}finally{if(i)throw r}}}}function h(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 l=0;for(n=Object.getOwnPropertySymbols(e);l<n.length;l++)t.indexOf(n[l])<0&&Object.prototype.propertyIsEnumerable.call(e,n[l])&&(a[n[l]]=e[n[l]])}return a}var p=function(){},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,n=f(t);try{for(n.s();!(a=n.n()).done;){var l=a.value;if(l&&l(e),e.defaultPrevented)break}}catch(e){n.e(e)}finally{n.f()}}},S=function(e,t){var a,n=new Set,l=f(e);try{for(l.s();!(a=l.n()).done;){var r=a.value;t.has(r)||n.add(r)}}catch(e){l.e(e)}finally{l.f()}return n},y=function(e,t){return new Set([].concat(c(S(e,t)),c(S(t,e))))},b=function(e){var t=n();return l((function(){t.current=e}),[e]),t.current},I=function(e,t){var a;return!!(null===(a=R(e,t).children)||void 0===a?void 0:a.length)},g=function(e,t){return R(e,t).parent},m=function(e,t,a){for(var n=t,l=[];;){var r=g(e,n);if(0===r||null==r||null!=r&&a.has(r))break;l.push(r),n=r}return l},w=function(e,t,a){var n=[];return function e(t,l){var r=R(t,l);if(null!=r.children){var d,i=f(r.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},E=function(e,t,a){var n=g(e,t);if(null!=n){var l=R(e,n),r=l.children.indexOf(t)+a;if(l.children[r])return l.children[r]}return null},O=function(e,t,a){var n=R(e,t);for(U(e).id===t&&(n=R(e,R(e,t).children[R(e,t).children.length-1]));a.has(n.id)&&I(e,n.id);)n=R(e,n.children[n.children.length-1]);return n.id},A=function(e,t,a){if(t===U(e).children[0])return null;var n=E(e,t,-1);return null==n?g(e,t):O(e,n,a)},x=function(e,t,a){var n=R(e,t).id;if(I(e,n)&&a.has(n))return R(e,n).children[0];for(;;){var l=E(e,n,1);if(null!=l)return l;if(null==(n=g(e,n)))return null}},W=function(e){var t=e.data,a=e.expandedIds,n=e.from,l=e.to,r=[],d=t.length,i=0,s=n;if(r.push(n),n<l)for(;i<d&&(null!=(s=x(t,s,a))&&r.push(s),null!=s&&s!==l);)i+=1;else if(n>l)for(;i<d&&(null!=(s=A(t,s,a))&&r.push(s),null!=s&&s!==l);)i+=1;return r},j=function(e){var t=0,a=[];return function e(n,l){var r,d={id:n.id||t,name:n.name,children:[],parent:l};if(a.find((function(e){return e.id===d.id})))throw Error("Multiple TreeView nodes have the same ID (".concat(d.id,"). IDs must be unique."));if(a.push(d),t+=1,null===(r=n.children)||void 0===r?void 0:r.length){var i,s=f(n.children);try{for(s.s();!(i=s.n()).done;){e(i.value,d.id)}}catch(e){s.e(e)}finally{s.f()}var c,o=f(a.values());try{for(o.s();!(c=o.n()).done;){var u=c.value;u.parent===d.id&&d.children.push(u.id)}}catch(e){o.e(e)}finally{o.f()}}}(e,null),a},T=function(e){var t=e.isSelected,a=e.isDisabled,n=e.multiSelect;return a||n?t:!!t||void 0},D=function(e){var t=e.isSelected,a=e.isDisabled,n=e.isHalfSelected,l=e.multiSelect;return a?t:n?"mixed":l?t:!!t||void 0},N=function(e,t,a){return t.concat.apply(t,c(t.filter((function(t){return I(e,t)})).map((function(t){return w(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>")},L=function(e,t,a){return I(e,t)&&a.has(t)&&w(e,t,new Set).some((function(e){return a.has(e)}))},k=function(e,t,a){return I(e,t)&&!a.has(t)&&w(e,t,new Set).every((function(e){return a.has(e)}))},M=function(e,t,a){return I(e,t)&&a.has(t)&&w(e,t,new Set).every((function(e){return a.has(e)}))},U=function(e){var t=e.find((function(e){return null===e.parent}));if(!t)throw Error("TreeView data must contain parent node.");return t},R=function(e,t){var a=e.find((function(e){return e.id===t}));if(null==a)throw Error("Node with id=".concat(t," doesn't exist in the tree."));return a},F=function(e){var t=Array.from(new Set(e));return e.length!==t.length},B="COLLAPSE",_="COLLAPSE_MANY",z="EXPAND",K="EXPAND_MANY",H="HALF_SELECT",P="SELECT",G="DESELECT",V="TOGGLE",Y="TOGGLE_SELECT",q="SELECT_MANY",X="EXCLUSIVE_CHANGE_SELECT_MANY",$="FOCUS",J="BLUR",Q="DISABLE",Z="ENABLE",ee="CLEAR_MANUALLY_TOGGLED",te="CONTROLLED_SELECT_MANY",ae=function(e,t){switch(t.type){case B: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 _:var n,l=new Set(e.expandedIds),r=f(t.ids);try{for(r.s();!(n=r.n()).done;){var d=n.value;l.delete(d)}}catch(e){r.e(e)}finally{r.f()}return Object.assign(Object.assign({},e),{expandedIds:l,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case z: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 K:var s=new Set([].concat(c(e.expandedIds),c(t.ids)));return Object.assign(Object.assign({},e),{expandedIds:s,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case V: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 H:if(e.disabledIds.has(t.id))return e;var u=new Set(e.halfSelectedIds),h=new Set(e.selectedIds);return u.add(t.id),h.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:h,halfSelectedIds:u,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case P:if(!t.NotUserAction&&e.disabledIds.has(t.id))return e;var p;t.multiSelect?(p=new Set(e.selectedIds)).add(t.id):(p=new Set).add(t.id);var v=new Set(e.halfSelectedIds);return v.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:p,halfSelectedIds:v,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled});case G:if(!t.NotUserAction&&e.disabledIds.has(t.id))return e;var y,b=new Set(e.selectedIds);return b.delete(t.id),t.multiSelect?(y=new Set(e.halfSelectedIds)).delete(t.id):y=new Set,Object.assign(Object.assign({},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,lastManuallyToggled:t.lastManuallyToggled});case Y:if(e.disabledIds.has(t.id))return e;var I,g=e.selectedIds.has(t.id);t.multiSelect?(I=new Set(e.selectedIds),g?I.delete(t.id):I.add(t.id)):(I=new Set,g||I.add(t.id));var m=new Set(e.halfSelectedIds);return m.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:I,halfSelectedIds:m,tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled});case q:var w,E=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){w=t.select?new Set([].concat(c(e.selectedIds),c(E))):S(e.selectedIds,new Set(E));var O=S(e.halfSelectedIds,w);return Object.assign(Object.assign({},e),{selectedIds:w,halfSelectedIds:O,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled})}return e;case X:var A,x=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){A=t.select?new Set(x):S(e.selectedIds,new Set(x));var W=S(e.halfSelectedIds,A);return Object.assign(Object.assign({},e),{selectedIds:A,halfSelectedIds:W,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled})}return e;case te:var j;if(t.multiSelect)j=new Set(t.ids);else{j=new Set,t.ids.length>1&&console.warn("Tree in singleSelect mode, only the first item from selectedIds will be selected.");var T=t.ids[0];T&&j.add(T)}var D=new Set(e.halfSelectedIds);t.ids.every((function(e){return D.delete(e)}));var N=new Set(t.ids);return Object.assign(Object.assign({},e),{selectedIds:j,halfSelectedIds:D,controlledIds:N,isFocused:!0,lastAction:t.type});case $:return Object.assign(Object.assign({},e),{tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case J:return Object.assign(Object.assign({},e),{isFocused:!1});case Q:var C=new Set(e.disabledIds);return C.add(t.id),Object.assign(Object.assign({},e),{disabledIds:C});case Z:var L=new Set(e.disabledIds);return L.delete(t.id),Object.assign(Object.assign({},e),{disabledIds:L});case ee:return Object.assign(Object.assign({},e),{lastManuallyToggled:null});default:throw new Error("Invalid action passed to the reducer")}},ne={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"},le={select:"SELECT",focus:"FOCUS",exclusiveSelect:"EXCLUSIVE_SELECT"},re=Object.freeze(Object.values(le)),de=Object.freeze(Object.values({check:"check",select:"select"})),ie=function(t){var n=t.element,l=t.dispatch,r=t.data,d=t.selectedIds,s=t.tabbableId,o=t.isFocused,u=t.expandedIds,f=t.disabledIds,S=t.halfSelectedIds,y=t.lastUserSelect,b=t.nodeRefs,g=t.leafRefs,m=t.baseClassNames,E=t.nodeRenderer,O=t.nodeAction,A=t.setsize,x=t.posinset,j=t.level,C=t.propagateCollapse,k=t.propagateSelect,U=t.multiSelect,R=t.togglableSelect,F=t.clickAction,B=t.state,z=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(u.has(n.id)&&C){var t=[n.id].concat(c(w(r,n.id,new Set)));l({type:_,ids:t,lastInteractedWith:n.id})}else l({type:V,id:n.id,lastInteractedWith:n.id})},K=function(){return l({type:$,id:n.id,lastInteractedWith:n.id})},G=function(e){if(e.shiftKey){var t=W({data:r,expandedIds:u,from:y,to:n.id}).filter((function(e){return!f.has(e)}));t=k?N(r,t,f):t,l({type:X,select:!0,multiSelect:U,ids:t,lastInteractedWith:n.id,lastManuallyToggled:n.id})}else if(e.ctrlKey||F===le.select){var a=L(r,n.id,d),i=M(r,n.id,d);l({type:R?a&&!i?H:Y:P,id:n.id,multiSelect:U,lastInteractedWith:n.id,lastManuallyToggled:n.id}),k&&!f.has(n.id)&&l({type:q,ids:N(r,[n.id],f),select:!R||!d.has(n.id),multiSelect:U,lastInteractedWith:n.id,lastManuallyToggled:n.id})}else F===le.exclusiveSelect?l({type:R?Y:P,id:n.id,multiSelect:!1,lastInteractedWith:n.id,lastManuallyToggled:n.id}):F===le.focus&&l({type:$,id:n.id,lastInteractedWith:n.id})},J=function(t){var a;return e(t,(i(a={},"".concat(t,"--expanded"),u.has(n.id)),i(a,"".concat(t,"--selected"),d.has(n.id)),i(a,"".concat(t,"--focused"),s===n.id&&o),a))},Q="select"===O?{"aria-selected":T({isSelected:d.has(n.id),isDisabled:f.has(n.id),multiSelect:U})}:{"aria-checked":D({isSelected:d.has(n.id),isDisabled:f.has(n.id),isHalfSelected:S.has(n.id),multiSelect:U})};return I(r,n.id)||n.isBranch?a.createElement("li",Object.assign({role:"treeitem","aria-expanded":u.has(n.id),"aria-setsize":A,"aria-posinset":x,"aria-level":j,"aria-disabled":f.has(n.id),tabIndex:s===n.id?0:-1,ref:function(e){null!=(null==b?void 0:b.current)&&null!=e&&(b.current[n.id]=e)},className:m.branchWrapper},Q),a.createElement(a.Fragment,null,E({element:n,isBranch:!0,isSelected:d.has(n.id),isHalfSelected:S.has(n.id),isExpanded:u.has(n.id),isDisabled:f.has(n.id),dispatch:l,getNodeProps:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=t.onClick;return{onClick:null==a?v(G,z,K):v(a,K),className:e(J(m.node),m.branch),ref:function(e){null!=(null==g?void 0:g.current)&&(g.current[n.id]=e)}}},setsize:A,posinset:x,level:j,handleSelect:G,handleExpand:z,treeState:B}),a.createElement(se,Object.assign({getClasses:J},function(e){e.setsize,e.posinset;return h(e,["setsize","posinset"])}(t))))):a.createElement("li",{role:"none",className:J(m.leafListItem)},E({element:n,isBranch:!1,isSelected:d.has(n.id),isHalfSelected:!1,isExpanded:!1,isDisabled:f.has(n.id),dispatch:l,getNodeProps:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=t.onClick;return Object.assign({role:"treeitem",tabIndex:s===n.id?0:-1,onClick:v(null==a?G:a,K),ref:function(e){null!=(null==b?void 0:b.current)&&null!=(null==g?void 0:g.current)&&(b.current[n.id]=e,g.current[n.id]=e)},className:e(J(m.node),m.leaf),"aria-setsize":A,"aria-posinset":x,"aria-level":j,disabled:f.has(n.id),"aria-disabled":f.has(n.id)},Q)},setsize:A,posinset:x,level:j,handleSelect:G,handleExpand:p,treeState:B}))},se=function(e){var t=e.data,n=e.element,l=e.expandedIds,r=e.getClasses,i=e.baseClassNames,s=e.level,c=h(e,["data","element","expandedIds","getClasses","baseClassNames","level"]);return a.createElement("ul",{role:"group",className:r(i.nodeGroup)},l.has(n.id)&&n.children.length>0&&n.children.map((function(e,r){return a.createElement(ie,Object.assign({data:t,expandedIds:l,baseClassNames:i,key:"".concat(e,"-").concat(d(e)),element:R(t,e),setsize:n.children.length,posinset:r+1,level:s+1},c))})))},ce=function(e){var t=e.data,a=e.controlledSelectedIds,d=e.controlledExpandedIds,i=e.defaultExpandedIds,o=e.defaultSelectedIds,u=e.defaultDisabledIds,h=e.nodeRefs,v=e.leafRefs,E=e.onSelect,O=e.onNodeSelect,A=e.onExpand,x=e.onLoadData,W=e.togglableSelect,j=e.multiSelect,T=e.propagateSelect,D=e.propagateSelectUpwards,C=U(t),L=s(r(ae,{selectedIds:new Set(a||o),controlledIds:new Set(a),tabbableId:C.children[0],isFocused:!1,expandedIds:new Set(d||i),halfSelectedIds:new Set,lastUserSelect:C.children[0],lastInteractedWith:null,lastManuallyToggled:null,disabledIds:new Set(u)}),2),M=L[0],F=L[1],Y=M.selectedIds,X=M.controlledIds,J=M.expandedIds,Q=M.disabledIds,Z=M.tabbableId,ne=M.halfSelectedIds,le=M.lastAction,re=M.lastInteractedWith,de=M.lastManuallyToggled,ie=b(Y)||new Set,se=y(Y,ie);l((function(){var e;if(null!=E&&E!==p){var a,n=f(se);try{for(n.s();!(a=n.n()).done;){var l=a.value,r=I(t,l)||!!(null===(e=R(t,Z))||void 0===e?void 0:e.isBranch);E({element:R(t,l),isBranch:r,isExpanded:!!r&&J.has(l),isSelected:Y.has(l),isDisabled:Q.has(l),isHalfSelected:!!r&&ne.has(l),treeState:M})}}catch(e){n.e(e)}finally{n.f()}}}),[t,Y,J,Q,ne,se,E,M]),l((function(){null!=O&&O!==p&&null!=de&&se.size&&(O({element:R(t,de),isSelected:Y.has(de),isBranch:I(t,de),treeState:M}),F({type:ee}))}),[de,Y,se]);var ce=b(J)||new Set;l((function(){var e=y(J,ce);if(null!=A&&A!==p){var a,n=f(e);try{for(n.s();!(a=n.n()).done;){var l=a.value;A({element:R(t,l),isExpanded:J.has(l),isSelected:Y.has(l),isDisabled:Q.has(l),isHalfSelected:ne.has(l),treeState:M})}}catch(e){n.e(e)}finally{n.f()}}}),[t,Y,J,Q,ne,ce,A,M]);var oe,ue,fe=(oe=t,ue=n(),l((function(){ue.current=oe})),ue.current||new Map);l((function(){var e=y(J,ce);if(x){var a,n=f(e);try{for(n.s();!(a=n.n()).done;){var l=a.value;x({element:R(t,l),isExpanded:J.has(l),isSelected:Y.has(l),isDisabled:Q.has(l),isHalfSelected:ne.has(l),treeState:M})}}catch(e){n.e(e)}finally{n.f()}if(fe!==t&&W&&T){var r,d=f(J);try{for(d.s();!(r=d.n()).done;){var i=r.value;Y.has(i)&&F({type:q,ids:N(t,[i],Q),select:!0,multiSelect:j,lastInteractedWith:i})}}catch(e){d.e(e)}finally{d.f()}}}}),[t,Y,J,Q,ne,ce,x,M]);var he=y(new Set(a),X);return l((function(){if(a){he.size&&F({type:te,ids:a,multiSelect:j});var e,n=f(a);try{for(n.s();!(e=n.n()).done;){var l=e.value;T&&!Q.has(l)&&F({type:q,ids:N(t,[l],Q),select:!0,multiSelect:j})}}catch(e){n.e(e)}finally{n.f()}}}),[a]),l((function(){var e=new Set(d),a=S(e,ce),n=S(ce,e);if(n.size){var l,r=f(n);try{for(r.s();!(l=r.n()).done;){var i=l.value;if(I(t,i)||R(t,i).isBranch){var s=[i].concat(c(w(t,i,new Set)));F({type:_,ids:s,lastInteractedWith:i})}}}catch(e){r.e(e)}finally{r.f()}}if(a.size){var o,u=f(a);try{for(u.s();!(o=u.n()).done;){var h=o.value;if(I(t,h)||R(t,h).isBranch){var p=g(t,h);F(p?{type:K,ids:[h,p],lastInteractedWith:h}:{type:z,id:h,lastInteractedWith:h})}}}catch(e){u.e(e)}finally{u.f()}}}),[d]),l((function(){if(D){var e=new Set([].concat(c(se),c(X)));re&&le!==$&&le!==B&&le!==z&&le!==V&&e.add(re);var a,n=function(e,t,a,n,l,r){var d,i={every:new Set,some:new Set,none:new Set},s=f(t);try{for(s.s();!(d=s.n()).done;)for(var c=d.value;;){var o=g(e,c);if(0===o||null==o||null!=o&&n.has(o))break;var u=R(e,o).children.filter((function(e){return!n.has(e)}));if(0===u.length)break;if(u.some((function(e){return a.has(e)||i.some.has(e)||l.has(e)})))u.every((function(e){return a.has(e)}))?i.every.add(o):i.some.add(o);else{var h=m(e,c,n).find((function(e){return a.has(e)}));if(!r&&h){w(e,h,n).forEach((function(e){l.has(e)&&i.none.add(e)}));break}i.none.add(o)}c=o}}catch(e){s.e(e)}finally{s.f()}return i}(t,e,Y,Q,ne,j),l=n.every,r=n.some,d=n.none,i=f(l);try{for(i.s();!(a=i.n()).done;){var s=a.value;Y.has(s)||F({type:P,id:s,multiSelect:j||k(t,s,Y),keepFocus:!0,NotUserAction:!0,lastInteractedWith:re})}}catch(e){i.e(e)}finally{i.f()}var o,u=f(r);try{for(u.s();!(o=u.n()).done;){var h=o.value;ne.has(h)||F({type:H,id:h,lastInteractedWith:re})}}catch(e){u.e(e)}finally{u.f()}var p,v=f(d);try{for(v.s();!(p=v.n()).done;){var S=p.value;(Y.has(S)||ne.has(S))&&F({type:G,id:S,multiSelect:j,keepFocus:!0,NotUserAction:!0,lastInteractedWith:re,lastManuallyToggled:de})}}catch(e){v.e(e)}finally{v.f()}}}),[t,j,D,Y,J,Q,ne,le,ie,se,re,he]),l((function(){if(null!=re&&null!=Z&&null!=(null==h?void 0:h.current)&&null!=(null==v?void 0:v.current)){var e=h.current[Z];!function(e){null!=e&&e.scrollIntoView&&e.scrollIntoView({block:"nearest"})}(v.current[re]),function(e){null!=e&&e.focus&&e.focus({preventScroll:!0})}(e)}}),[Z,h,v,re]),[M,F]},oe=a.forwardRef((function(t,l){var r=t.data,i=t.selectedIds,c=t.nodeRenderer,o=t.onSelect,u=void 0===o?p:o,f=t.onNodeSelect,v=void 0===f?p:f,S=t.onExpand,y=void 0===S?p:S,b=t.onLoadData,I=t.className,g=void 0===I?"":I,m=t.multiSelect,w=void 0!==m&&m,E=t.propagateSelect,O=void 0!==E&&E,A=t.propagateSelectUpwards,x=void 0!==A&&A,W=t.propagateCollapse,j=void 0!==W&&W,T=t.expandOnKeyboardSelect,D=void 0!==T&&T,N=t.togglableSelect,L=void 0!==N&&N,k=t.defaultExpandedIds,M=void 0===k?[]:k,B=t.defaultSelectedIds,_=void 0===B?[]:B,z=t.defaultDisabledIds,K=void 0===z?[]:z,H=t.clickAction,P=void 0===H?le.select:H,G=t.nodeAction,V=void 0===G?"select":G,Y=t.expandedIds,q=t.onBlur,X=h(t,["data","selectedIds","nodeRenderer","onSelect","onNodeSelect","onExpand","onLoadData","className","multiSelect","propagateSelect","propagateSelectUpwards","propagateCollapse","expandOnKeyboardSelect","togglableSelect","defaultExpandedIds","defaultSelectedIds","defaultDisabledIds","clickAction","nodeAction","expandedIds","onBlur"]);!function(e){if(F(e.map((function(e){return e.id}))))throw Error("Multiple TreeView nodes have the same ID. IDs must be unique.");if(e.forEach((function(e){if(e.id===e.parent)throw Error("Node with id=".concat(e.id," has parent reference to itself."));if(F(e.children))throw Error("Node with id=".concat(e.id," contains duplicate ids in its children."))})),1!==e.filter((function(e){return null===e.parent})).length)throw Error("TreeView can have only one root node.")}(r);var $=n({}),Q=n({}),Z=s(ce({data:r,controlledSelectedIds:i,controlledExpandedIds:Y,defaultExpandedIds:M,defaultSelectedIds:_,defaultDisabledIds:K,nodeRefs:$,leafRefs:Q,onSelect:u,onNodeSelect:v,onExpand:y,onLoadData:b,togglableSelect:L,multiSelect:w,propagateSelect:O,propagateSelectUpwards:x}),2),ee=Z[0],te=Z[1];O=O&&w;var ae=n(null);return null!=l&&(ae=l),a.createElement("ul",Object.assign({className:e(ne.root,g),role:"tree","aria-multiselectable":"select"===V?w:void 0,ref:ae,onBlur:function(e){C(e,ae.current,(function(){q&&q({treeState:ee,dispatch:te}),te({type:J})}))},onKeyDown:ue({data:r,tabbableId:ee.tabbableId,expandedIds:ee.expandedIds,selectedIds:ee.selectedIds,disabledIds:ee.disabledIds,halfSelectedIds:ee.halfSelectedIds,clickAction:P,dispatch:te,propagateCollapse:j,propagateSelect:O,multiSelect:w,expandOnKeyboardSelect:D,togglableSelect:L})},X),U(r).children.map((function(e,t){return a.createElement(ie,Object.assign({key:"".concat(e,"-").concat(d(e)),data:r,element:R(r,e),setsize:U(r).children.length,posinset:t+1,level:1},ee,{state:ee,dispatch:te,nodeRefs:$,leafRefs:Q,baseClassNames:ne,nodeRenderer:c,propagateCollapse:j,propagateSelect:O,propagateSelectUpwards:x,multiSelect:w,togglableSelect:L,clickAction:P,nodeAction:V}))})))})),ue=function(e){var t=e.data,a=e.expandedIds,n=e.selectedIds,l=e.disabledIds,r=e.tabbableId,d=e.dispatch,i=e.propagateCollapse,s=e.propagateSelect,o=e.multiSelect,u=e.expandOnKeyboardSelect,f=e.togglableSelect,h=e.clickAction;return function(e){var p=R(t,r),v=p.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();var S=t.filter((function(e){return null!==e.parent})).map((function(e){return e.id})).filter((function(e){return!l.has(e)}));d({type:q,multiSelect:o,select:Array.from(n).filter((function(e){return!l.has(e)})).length!==S.length,ids:S,lastInteractedWith:p.id})}else if(e.shiftKey&&("Home"===e.key||"End"===e.key)){var y="Home"===e.key?U(t).children[0]:O(t,v,a),b=W({data:t,expandedIds:a,from:v,to:y}).filter((function(e){return!l.has(e)}));d({type:q,multiSelect:o,select:!0,ids:s?N(t,b,l):b}),d({type:$,id:y,lastInteractedWith:y})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var m=A(t,v,a);return void(null==m||l.has(m)||(d({type:q,ids:s?N(t,[m],l):[m],select:!0,multiSelect:o,lastInteractedWith:m,lastManuallyToggled:m}),d({type:$,id:m,lastInteractedWith:m})));case"ArrowDown":e.preventDefault();var E=x(t,v,a);return void(null==E||l.has(E)||(d({type:q,ids:s?N(t,[E],l):[E],multiSelect:o,select:!0,lastInteractedWith:E,lastManuallyToggled:E}),d({type:$,id:E,lastInteractedWith:E})))}switch(e.key){case"ArrowDown":e.preventDefault();var j=x(t,v,a);return void(null!=j&&d({type:$,id:j,lastInteractedWith:j}));case"ArrowUp":e.preventDefault();var T=A(t,v,a);return void(null!=T&&d({type:$,id:T,lastInteractedWith:T}));case"ArrowLeft":if(e.preventDefault(),(I(t,v)||p.isBranch)&&a.has(r))if(i){var D=[v].concat(c(w(t,v,new Set)));d({type:_,ids:D,lastInteractedWith:p.id})}else d({type:B,id:v,lastInteractedWith:v});else if(!U(t).children.includes(v)){var C=g(t,v);if(null==C)throw new Error("parentId of root element is null");d({type:$,id:C,lastInteractedWith:C})}return;case"ArrowRight":return e.preventDefault(),void((I(t,v)||p.isBranch)&&(a.has(r)?d({type:$,id:p.children[0],lastInteractedWith:p.children[0]}):d({type:z,id:v,lastInteractedWith:v})));case"Home":e.preventDefault(),d({type:$,id:U(t).children[0],lastInteractedWith:U(t).children[0]});break;case"End":e.preventDefault();var k=O(t,U(t).id,a);return void d({type:$,id:k,lastInteractedWith:k});case"*":e.preventDefault();var F=g(t,v);if(null==F)throw new Error("parentId of element is null");var G=R(t,F).children.filter((function(e){return I(t,e)||R(t,e).isBranch}));return void d({type:K,ids:G,lastInteractedWith:v});case"Enter":case" ":case"Spacebar":if(e.preventDefault(),h===le.focus)return;var X=L(t,p.id,n),J=M(t,p.id,n);return d({type:f?X&&!J?H:Y:P,id:v,multiSelect:o,lastInteractedWith:v,lastManuallyToggled:v}),s&&!l.has(p.id)&&d({type:q,ids:N(t,[v],l),select:!f||!n.has(v),multiSelect:o,lastInteractedWith:v,lastManuallyToggled:v}),void(u&&d({type:V,id:v,lastInteractedWith:v}));default:if(1===e.key.length)for(var Q=x(t,v,a);Q!==v;)if(null!=Q){if(R(t,Q).name[0].toLowerCase()===e.key.toLowerCase())return void d({type:$,id:Q,lastInteractedWith:v});Q=x(t,Q,a)}else Q=U(t).children[0];return}}}};oe.propTypes={data:t.array.isRequired,onSelect:t.func,onNodeSelect:t.func,onExpand:t.func,className:t.string,nodeRenderer:t.func.isRequired,defaultExpandedIds:t.array,defaultSelectedIds:t.array,expandedIds: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(de),clickAction:t.oneOf(re),onBlur:t.func,onLoadData:t.func};export default oe;export{re as CLICK_ACTIONS,j as flattenTree}; | ||
import e from"classnames";import t from"prop-types";import n,{useRef as a,useEffect as l,useReducer as r}from"react";function d(e){return(d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var a,l,r=[],d=!0,i=!1;try{for(n=n.call(e);!(d=(a=n.next()).done)&&(r.push(a.value),!t||r.length!==t);d=!0);}catch(e){i=!0,l=e}finally{try{d||null==n.return||n.return()}finally{if(i)throw l}}return r}(e,t)||o(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 c(e){return function(e){if(Array.isArray(e))return u(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||o(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 o(e,t){if(e){if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(e,t):void 0}}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}function f(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=o(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var a=0,l=function(){};return{s:l,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:l}}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 r,d=!0,i=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return d=e.done,e},e:function(e){i=!0,r=e},f:function(){try{d||null==n.return||n.return()}finally{if(i)throw r}}}}function h(e,t){var n={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(n[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(a=Object.getOwnPropertySymbols(e);l<a.length;l++)t.indexOf(a[l])<0&&Object.prototype.propertyIsEnumerable.call(e,a[l])&&(n[a[l]]=e[a[l]])}return n}var p=function(){},v=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){var n,a=f(t);try{for(a.s();!(n=a.n()).done;){var l=n.value;if(l&&l(e),e.defaultPrevented)break}}catch(e){a.e(e)}finally{a.f()}}},S=function(e,t){var n,a=new Set,l=f(e);try{for(l.s();!(n=l.n()).done;){var r=n.value;t.has(r)||a.add(r)}}catch(e){l.e(e)}finally{l.f()}return a},y=function(e,t){return new Set([].concat(c(S(e,t)),c(S(t,e))))},b=function(e){var t=a();return l((function(){t.current=e}),[e]),t.current},I=function(e,t){var n;return!!(null===(n=F(e,t).children)||void 0===n?void 0:n.length)},g=function(e,t){return F(e,t).parent},m=function(e,t,n){for(var a=t,l=[];;){var r=g(e,a);if(0===r||null==r||null!=r&&n.has(r))break;l.push(r),a=r}return l},w=function(e,t,n){var a=[];return function e(t,l){var r=F(t,l);if(null!=r.children){var d,i=f(r.children.filter((function(e){return!n.has(e)})));try{for(i.s();!(d=i.n()).done;){var s=d.value;a.push(s),e(t,s)}}catch(e){i.e(e)}finally{i.f()}}}(e,t),a},E=function(e,t){var n=F(e,t);return null==n.children?[]:n.children},O=function(e,t,n){var a=g(e,t);if(null!=a){var l=F(e,a),r=l.children.indexOf(t)+n;if(l.children[r])return l.children[r]}return null},A=function(e,t,n){var a=F(e,t);for(R(e).id===t&&(a=F(e,F(e,t).children[F(e,t).children.length-1]));n.has(a.id)&&I(e,a.id);)a=F(e,a.children[a.children.length-1]);return a.id},x=function(e,t,n){if(t===R(e).children[0])return null;var a=O(e,t,-1);return null==a?g(e,t):A(e,a,n)},W=function(e,t,n){var a=F(e,t).id;if(I(e,a)&&n.has(a))return F(e,a).children[0];for(;;){var l=O(e,a,1);if(null!=l)return l;if(null==(a=g(e,a)))return null}},j=function(e){var t=e.data,n=e.expandedIds,a=e.from,l=e.to,r=[],d=t.length,i=0,s=a;if(r.push(a),a<l)for(;i<d&&(null!=(s=W(t,s,n))&&r.push(s),null!=s&&s!==l);)i+=1;else if(a>l)for(;i<d&&(null!=(s=x(t,s,n))&&r.push(s),null!=s&&s!==l);)i+=1;return r},T=function(e){var t=0,n=[];return function e(a,l){var r,d={id:a.id||t,name:a.name,children:[],parent:l};if(n.find((function(e){return e.id===d.id})))throw Error("Multiple TreeView nodes have the same ID (".concat(d.id,"). IDs must be unique."));if(n.push(d),t+=1,null===(r=a.children)||void 0===r?void 0:r.length){var i,s=f(a.children);try{for(s.s();!(i=s.n()).done;){e(i.value,d.id)}}catch(e){s.e(e)}finally{s.f()}var c,o=f(n.values());try{for(o.s();!(c=o.n()).done;){var u=c.value;u.parent===d.id&&d.children.push(u.id)}}catch(e){o.e(e)}finally{o.f()}}}(e,null),n},D=function(e){var t=e.isSelected,n=e.isDisabled,a=e.multiSelect;return n||a?t:!!t||void 0},N=function(e){var t=e.isSelected,n=e.isDisabled,a=e.isHalfSelected,l=e.multiSelect;return n?t:a?"mixed":l?t:!!t||void 0},C=function(e,t,n){return t.concat.apply(t,c(t.filter((function(t){return I(e,t)})).map((function(t){return w(e,t,n)}))))},L=function(e,t,n){null!=t?window.navigator.userAgent.match(/Trident/)?setTimeout((function(){return!t.contains(document.activeElement)&&n()}),0):!t.contains(e.nativeEvent.relatedTarget)&&n():console.warn("ref not set on <ul>")},k=function(e,t,n){return I(e,t)&&n.has(t)&&w(e,t,new Set).some((function(e){return n.has(e)}))},M=function(e,t,n){var a=E(e,t);return I(e,t)&&!n.has(t)&&1===a.length&&a.every((function(e){return n.has(e)}))},U=function(e,t,n){var a=E(e,t);return I(e,t)&&n.has(t)&&1===a.length&&a.every((function(e){return n.has(e)}))},R=function(e){var t=e.find((function(e){return null===e.parent}));if(!t)throw Error("TreeView data must contain parent node.");return t},F=function(e,t){var n=e.find((function(e){return e.id===t}));if(null==n)throw Error("Node with id=".concat(t," doesn't exist in the tree."));return n},B=function(e){var t=Array.from(new Set(e));return e.length!==t.length},_="COLLAPSE",z="COLLAPSE_MANY",K="EXPAND",H="EXPAND_MANY",P="HALF_SELECT",G="SELECT",V="DESELECT",Y="TOGGLE",q="TOGGLE_SELECT",X="SELECT_MANY",$="EXCLUSIVE_CHANGE_SELECT_MANY",J="FOCUS",Q="BLUR",Z="DISABLE",ee="ENABLE",te="CLEAR_MANUALLY_TOGGLED",ne="CONTROLLED_SELECT_MANY",ae=function(e,t){switch(t.type){case _:var n=new Set(e.expandedIds);return n.delete(t.id),Object.assign(Object.assign({},e),{expandedIds:n,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case z:var a,l=new Set(e.expandedIds),r=f(t.ids);try{for(r.s();!(a=r.n()).done;){var d=a.value;l.delete(d)}}catch(e){r.e(e)}finally{r.f()}return Object.assign(Object.assign({},e),{expandedIds:l,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 H:var s=new Set([].concat(c(e.expandedIds),c(t.ids)));return Object.assign(Object.assign({},e),{expandedIds:s,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case Y: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 P:if(e.disabledIds.has(t.id))return e;var u=new Set(e.halfSelectedIds),h=new Set(e.selectedIds);return u.add(t.id),h.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:h,halfSelectedIds:u,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case G:if(!t.NotUserAction&&e.disabledIds.has(t.id))return e;var p;t.multiSelect?(p=new Set(e.selectedIds)).add(t.id):(p=new Set).add(t.id);var v=new Set(e.halfSelectedIds);return v.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:p,halfSelectedIds:v,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled});case V:if(!t.NotUserAction&&e.disabledIds.has(t.id))return e;var y,b=new Set(e.selectedIds);return b.delete(t.id),t.multiSelect?(y=new Set(e.halfSelectedIds)).delete(t.id):y=new Set,Object.assign(Object.assign({},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,lastManuallyToggled:t.lastManuallyToggled});case q:if(e.disabledIds.has(t.id))return e;var I,g=e.selectedIds.has(t.id);t.multiSelect?(I=new Set(e.selectedIds),g?I.delete(t.id):I.add(t.id)):(I=new Set,g||I.add(t.id));var m=new Set(e.halfSelectedIds);return m.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:I,halfSelectedIds:m,tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled});case X:var w,E=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){w=t.select?new Set([].concat(c(e.selectedIds),c(E))):S(e.selectedIds,new Set(E));var O=S(e.halfSelectedIds,w);return Object.assign(Object.assign({},e),{selectedIds:w,halfSelectedIds:O,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled})}return e;case $:var A,x=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){A=t.select?new Set(x):S(e.selectedIds,new Set(x));var W=S(e.halfSelectedIds,A);return Object.assign(Object.assign({},e),{selectedIds:A,halfSelectedIds:W,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled})}return e;case ne:var j;if(t.multiSelect)j=new Set(t.ids);else{j=new Set,t.ids.length>1&&console.warn("Tree in singleSelect mode, only the first item from selectedIds will be selected.");var T=t.ids[0];T&&j.add(T)}var D=new Set(e.halfSelectedIds);t.ids.every((function(e){return D.delete(e)}));var N=new Set(t.ids);return Object.assign(Object.assign({},e),{selectedIds:j,halfSelectedIds:D,controlledIds:N,isFocused:!0,lastAction:t.type});case J:return Object.assign(Object.assign({},e),{tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case Q:return Object.assign(Object.assign({},e),{isFocused:!1});case Z:var C=new Set(e.disabledIds);return C.add(t.id),Object.assign(Object.assign({},e),{disabledIds:C});case ee:var L=new Set(e.disabledIds);return L.delete(t.id),Object.assign(Object.assign({},e),{disabledIds:L});case te:return Object.assign(Object.assign({},e),{lastManuallyToggled:null});default:throw new Error("Invalid action passed to the reducer")}},le={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"},re={select:"SELECT",focus:"FOCUS",exclusiveSelect:"EXCLUSIVE_SELECT"},de=Object.freeze(Object.values(re)),ie=Object.freeze(Object.values({check:"check",select:"select"})),se=function(t){var a=t.element,l=t.dispatch,r=t.data,d=t.selectedIds,s=t.tabbableId,o=t.isFocused,u=t.expandedIds,f=t.disabledIds,S=t.halfSelectedIds,y=t.lastUserSelect,b=t.nodeRefs,g=t.leafRefs,m=t.baseClassNames,E=t.nodeRenderer,O=t.nodeAction,A=t.setsize,x=t.posinset,W=t.level,T=t.propagateCollapse,L=t.propagateSelect,M=t.multiSelect,R=t.togglableSelect,F=t.clickAction,B=t.state,_=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(u.has(a.id)&&T){var t=[a.id].concat(c(w(r,a.id,new Set)));l({type:z,ids:t,lastInteractedWith:a.id})}else l({type:Y,id:a.id,lastInteractedWith:a.id})},K=function(){return l({type:J,id:a.id,lastInteractedWith:a.id})},H=function(e){if(e.shiftKey){var t=j({data:r,expandedIds:u,from:y,to:a.id}).filter((function(e){return!f.has(e)}));t=L?C(r,t,f):t,l({type:$,select:!0,multiSelect:M,ids:t,lastInteractedWith:a.id,lastManuallyToggled:a.id})}else if(e.ctrlKey||F===re.select){var n=k(r,a.id,d),i=U(r,a.id,d);l({type:R?n&&!i?P:q:G,id:a.id,multiSelect:M,lastInteractedWith:a.id,lastManuallyToggled:a.id}),L&&!f.has(a.id)&&l({type:X,ids:C(r,[a.id],f),select:!R||!d.has(a.id),multiSelect:M,lastInteractedWith:a.id,lastManuallyToggled:a.id})}else F===re.exclusiveSelect?l({type:R?q:G,id:a.id,multiSelect:!1,lastInteractedWith:a.id,lastManuallyToggled:a.id}):F===re.focus&&l({type:J,id:a.id,lastInteractedWith:a.id})},V=function(t){var n;return e(t,(i(n={},"".concat(t,"--expanded"),u.has(a.id)),i(n,"".concat(t,"--selected"),d.has(a.id)),i(n,"".concat(t,"--focused"),s===a.id&&o),n))},Q="select"===O?{"aria-selected":D({isSelected:d.has(a.id),isDisabled:f.has(a.id),multiSelect:M})}:{"aria-checked":N({isSelected:d.has(a.id),isDisabled:f.has(a.id),isHalfSelected:S.has(a.id),multiSelect:M})};return I(r,a.id)||a.isBranch?n.createElement("li",Object.assign({role:"treeitem","aria-expanded":u.has(a.id),"aria-setsize":A,"aria-posinset":x,"aria-level":W,"aria-disabled":f.has(a.id),tabIndex:s===a.id?0:-1,ref:function(e){null!=(null==b?void 0:b.current)&&null!=e&&(b.current[a.id]=e)},className:m.branchWrapper},Q),n.createElement(n.Fragment,null,E({element:a,isBranch:!0,isSelected:d.has(a.id),isHalfSelected:S.has(a.id),isExpanded:u.has(a.id),isDisabled:f.has(a.id),dispatch:l,getNodeProps:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.onClick;return{onClick:null==n?v(H,_,K):v(n,K),className:e(V(m.node),m.branch),ref:function(e){null!=(null==g?void 0:g.current)&&(g.current[a.id]=e)}}},setsize:A,posinset:x,level:W,handleSelect:H,handleExpand:_,treeState:B}),n.createElement(ce,Object.assign({getClasses:V},function(e){e.setsize,e.posinset;return h(e,["setsize","posinset"])}(t))))):n.createElement("li",{role:"none",className:V(m.leafListItem)},E({element:a,isBranch:!1,isSelected:d.has(a.id),isHalfSelected:!1,isExpanded:!1,isDisabled:f.has(a.id),dispatch:l,getNodeProps:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.onClick;return Object.assign({role:"treeitem",tabIndex:s===a.id?0:-1,onClick:v(null==n?H:n,K),ref:function(e){null!=(null==b?void 0:b.current)&&null!=(null==g?void 0:g.current)&&(b.current[a.id]=e,g.current[a.id]=e)},className:e(V(m.node),m.leaf),"aria-setsize":A,"aria-posinset":x,"aria-level":W,disabled:f.has(a.id),"aria-disabled":f.has(a.id)},Q)},setsize:A,posinset:x,level:W,handleSelect:H,handleExpand:p,treeState:B}))},ce=function(e){var t=e.data,a=e.element,l=e.expandedIds,r=e.getClasses,i=e.baseClassNames,s=e.level,c=h(e,["data","element","expandedIds","getClasses","baseClassNames","level"]);return n.createElement("ul",{role:"group",className:r(i.nodeGroup)},l.has(a.id)&&a.children.length>0&&a.children.map((function(e,r){return n.createElement(se,Object.assign({data:t,expandedIds:l,baseClassNames:i,key:"".concat(e,"-").concat(d(e)),element:F(t,e),setsize:a.children.length,posinset:r+1,level:s+1},c))})))},oe=function(e){var t=e.data,n=e.controlledSelectedIds,d=e.controlledExpandedIds,i=e.defaultExpandedIds,o=e.defaultSelectedIds,u=e.defaultDisabledIds,h=e.nodeRefs,v=e.leafRefs,E=e.onSelect,O=e.onNodeSelect,A=e.onExpand,x=e.onLoadData,W=e.togglableSelect,j=e.multiSelect,T=e.propagateSelect,D=e.propagateSelectUpwards,N=R(t),L=s(r(ae,{selectedIds:new Set(n||o),controlledIds:new Set(n),tabbableId:N.children[0],isFocused:!1,expandedIds:new Set(d||i),halfSelectedIds:new Set,lastUserSelect:N.children[0],lastInteractedWith:null,lastManuallyToggled:null,disabledIds:new Set(u)}),2),k=L[0],U=L[1],B=k.selectedIds,q=k.controlledIds,$=k.expandedIds,Q=k.disabledIds,Z=k.tabbableId,ee=k.halfSelectedIds,le=k.lastAction,re=k.lastInteractedWith,de=k.lastManuallyToggled,ie=b(B)||new Set,se=y(B,ie);l((function(){var e;if(null!=E&&E!==p){var n,a=f(se);try{for(a.s();!(n=a.n()).done;){var l=n.value,r=I(t,l)||!!(null===(e=F(t,Z))||void 0===e?void 0:e.isBranch);E({element:F(t,l),isBranch:r,isExpanded:!!r&&$.has(l),isSelected:B.has(l),isDisabled:Q.has(l),isHalfSelected:!!r&&ee.has(l),treeState:k})}}catch(e){a.e(e)}finally{a.f()}}}),[t,B,$,Q,ee,se,E,k]),l((function(){null!=O&&O!==p&&null!=de&&se.size&&(O({element:F(t,de),isSelected:B.has(de),isBranch:I(t,de),treeState:k}),U({type:te}))}),[de,B,se]);var ce=b($)||new Set;l((function(){var e=y($,ce);if(null!=A&&A!==p){var n,a=f(e);try{for(a.s();!(n=a.n()).done;){var l=n.value;A({element:F(t,l),isExpanded:$.has(l),isSelected:B.has(l),isDisabled:Q.has(l),isHalfSelected:ee.has(l),treeState:k})}}catch(e){a.e(e)}finally{a.f()}}}),[t,B,$,Q,ee,ce,A,k]);var oe,ue,fe=(oe=t,ue=a(),l((function(){ue.current=oe})),ue.current||new Map);l((function(){var e=y($,ce);if(x){var n,a=f(e);try{for(a.s();!(n=a.n()).done;){var l=n.value;x({element:F(t,l),isExpanded:$.has(l),isSelected:B.has(l),isDisabled:Q.has(l),isHalfSelected:ee.has(l),treeState:k})}}catch(e){a.e(e)}finally{a.f()}if(fe!==t&&W&&T){var r,d=f($);try{for(d.s();!(r=d.n()).done;){var i=r.value;B.has(i)&&U({type:X,ids:C(t,[i],Q),select:!0,multiSelect:j,lastInteractedWith:i})}}catch(e){d.e(e)}finally{d.f()}}}}),[t,B,$,Q,ee,ce,x,k]);var he=y(new Set(n),q);return l((function(){if(n){he.size&&U({type:ne,ids:n,multiSelect:j});var e,a=f(n);try{for(a.s();!(e=a.n()).done;){var l=e.value;T&&!Q.has(l)&&U({type:X,ids:C(t,[l],Q),select:!0,multiSelect:j})}}catch(e){a.e(e)}finally{a.f()}}}),[n]),l((function(){var e=new Set(d),n=S(e,ce),a=S(ce,e);if(a.size){var l,r=f(a);try{for(r.s();!(l=r.n()).done;){var i=l.value;if(I(t,i)||F(t,i).isBranch){var s=[i].concat(c(w(t,i,new Set)));U({type:z,ids:s,lastInteractedWith:i})}}}catch(e){r.e(e)}finally{r.f()}}if(n.size){var o,u=f(n);try{for(u.s();!(o=u.n()).done;){var h=o.value;if(I(t,h)||F(t,h).isBranch){var p=g(t,h);U(p?{type:H,ids:[h,p],lastInteractedWith:h}:{type:K,id:h,lastInteractedWith:h})}}}catch(e){u.e(e)}finally{u.f()}}}),[d]),l((function(){if(D){var e=new Set([].concat(c(se),c(q)));re&&le!==J&&le!==_&&le!==K&&le!==Y&&e.add(re);var n,a=function(e,t,n,a,l,r){var d,i={every:new Set,some:new Set,none:new Set},s=f(t);try{for(s.s();!(d=s.n()).done;)for(var c=d.value;;){var o=g(e,c);if(0===o||null==o||null!=o&&a.has(o))break;var u=F(e,o).children.filter((function(e){return!a.has(e)}));if(0===u.length)break;if(u.some((function(e){return n.has(e)||i.some.has(e)||l.has(e)})))u.every((function(e){return n.has(e)}))?i.every.add(o):i.some.add(o);else{var h=m(e,c,a).find((function(e){return n.has(e)}));if(!r&&h){w(e,h,a).forEach((function(e){l.has(e)&&i.none.add(e)}));break}i.none.add(o)}c=o}}catch(e){s.e(e)}finally{s.f()}return i}(t,e,B,Q,ee,j),l=a.every,r=a.some,d=a.none,i=f(l);try{for(i.s();!(n=i.n()).done;){var s=n.value;B.has(s)||U({type:G,id:s,multiSelect:j||M(t,s,B),keepFocus:!0,NotUserAction:!0,lastInteractedWith:re})}}catch(e){i.e(e)}finally{i.f()}var o,u=f(r);try{for(u.s();!(o=u.n()).done;){var h=o.value;ee.has(h)||U({type:P,id:h,lastInteractedWith:re})}}catch(e){u.e(e)}finally{u.f()}var p,v=f(d);try{for(v.s();!(p=v.n()).done;){var S=p.value;(B.has(S)||ee.has(S))&&U({type:V,id:S,multiSelect:j,keepFocus:!0,NotUserAction:!0,lastInteractedWith:re,lastManuallyToggled:de})}}catch(e){v.e(e)}finally{v.f()}}}),[t,j,D,B,$,Q,ee,le,ie,se,re,he]),l((function(){if(null!=re&&null!=Z&&null!=(null==h?void 0:h.current)&&null!=(null==v?void 0:v.current)){var e=h.current[Z];!function(e){null!=e&&e.scrollIntoView&&e.scrollIntoView({block:"nearest"})}(v.current[re]),function(e){null!=e&&e.focus&&e.focus({preventScroll:!0})}(e)}}),[Z,h,v,re]),[k,U]},ue=n.forwardRef((function(t,l){var r=t.data,i=t.selectedIds,c=t.nodeRenderer,o=t.onSelect,u=void 0===o?p:o,f=t.onNodeSelect,v=void 0===f?p:f,S=t.onExpand,y=void 0===S?p:S,b=t.onLoadData,I=t.className,g=void 0===I?"":I,m=t.multiSelect,w=void 0!==m&&m,E=t.propagateSelect,O=void 0!==E&&E,A=t.propagateSelectUpwards,x=void 0!==A&&A,W=t.propagateCollapse,j=void 0!==W&&W,T=t.expandOnKeyboardSelect,D=void 0!==T&&T,N=t.togglableSelect,C=void 0!==N&&N,k=t.defaultExpandedIds,M=void 0===k?[]:k,U=t.defaultSelectedIds,_=void 0===U?[]:U,z=t.defaultDisabledIds,K=void 0===z?[]:z,H=t.clickAction,P=void 0===H?re.select:H,G=t.nodeAction,V=void 0===G?"select":G,Y=t.expandedIds,q=t.onBlur,X=h(t,["data","selectedIds","nodeRenderer","onSelect","onNodeSelect","onExpand","onLoadData","className","multiSelect","propagateSelect","propagateSelectUpwards","propagateCollapse","expandOnKeyboardSelect","togglableSelect","defaultExpandedIds","defaultSelectedIds","defaultDisabledIds","clickAction","nodeAction","expandedIds","onBlur"]);!function(e){if(B(e.map((function(e){return e.id}))))throw Error("Multiple TreeView nodes have the same ID. IDs must be unique.");if(e.forEach((function(e){if(e.id===e.parent)throw Error("Node with id=".concat(e.id," has parent reference to itself."));if(B(e.children))throw Error("Node with id=".concat(e.id," contains duplicate ids in its children."))})),1!==e.filter((function(e){return null===e.parent})).length)throw Error("TreeView can have only one root node.")}(r);var $=a({}),J=a({}),Z=s(oe({data:r,controlledSelectedIds:i,controlledExpandedIds:Y,defaultExpandedIds:M,defaultSelectedIds:_,defaultDisabledIds:K,nodeRefs:$,leafRefs:J,onSelect:u,onNodeSelect:v,onExpand:y,onLoadData:b,togglableSelect:C,multiSelect:w,propagateSelect:O,propagateSelectUpwards:x}),2),ee=Z[0],te=Z[1];O=O&&w;var ne=a(null);return null!=l&&(ne=l),n.createElement("ul",Object.assign({className:e(le.root,g),role:"tree","aria-multiselectable":"select"===V?w:void 0,ref:ne,onBlur:function(e){L(e,ne.current,(function(){q&&q({treeState:ee,dispatch:te}),te({type:Q})}))},onKeyDown:fe({data:r,tabbableId:ee.tabbableId,expandedIds:ee.expandedIds,selectedIds:ee.selectedIds,disabledIds:ee.disabledIds,halfSelectedIds:ee.halfSelectedIds,clickAction:P,dispatch:te,propagateCollapse:j,propagateSelect:O,multiSelect:w,expandOnKeyboardSelect:D,togglableSelect:C})},X),R(r).children.map((function(e,t){return n.createElement(se,Object.assign({key:"".concat(e,"-").concat(d(e)),data:r,element:F(r,e),setsize:R(r).children.length,posinset:t+1,level:1},ee,{state:ee,dispatch:te,nodeRefs:$,leafRefs:J,baseClassNames:le,nodeRenderer:c,propagateCollapse:j,propagateSelect:O,propagateSelectUpwards:x,multiSelect:w,togglableSelect:C,clickAction:P,nodeAction:V}))})))})),fe=function(e){var t=e.data,n=e.expandedIds,a=e.selectedIds,l=e.disabledIds,r=e.tabbableId,d=e.dispatch,i=e.propagateCollapse,s=e.propagateSelect,o=e.multiSelect,u=e.expandOnKeyboardSelect,f=e.togglableSelect,h=e.clickAction;return function(e){var p=F(t,r),v=p.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();var S=t.filter((function(e){return null!==e.parent})).map((function(e){return e.id})).filter((function(e){return!l.has(e)}));d({type:X,multiSelect:o,select:Array.from(a).filter((function(e){return!l.has(e)})).length!==S.length,ids:S,lastInteractedWith:p.id})}else if(e.shiftKey&&("Home"===e.key||"End"===e.key)){var y="Home"===e.key?R(t).children[0]:A(t,v,n),b=j({data:t,expandedIds:n,from:v,to:y}).filter((function(e){return!l.has(e)}));d({type:X,multiSelect:o,select:!0,ids:s?C(t,b,l):b}),d({type:J,id:y,lastInteractedWith:y})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var m=x(t,v,n);return void(null==m||l.has(m)||(d({type:X,ids:s?C(t,[m],l):[m],select:!0,multiSelect:o,lastInteractedWith:m,lastManuallyToggled:m}),d({type:J,id:m,lastInteractedWith:m})));case"ArrowDown":e.preventDefault();var E=W(t,v,n);return void(null==E||l.has(E)||(d({type:X,ids:s?C(t,[E],l):[E],multiSelect:o,select:!0,lastInteractedWith:E,lastManuallyToggled:E}),d({type:J,id:E,lastInteractedWith:E})))}switch(e.key){case"ArrowDown":e.preventDefault();var O=W(t,v,n);return void(null!=O&&d({type:J,id:O,lastInteractedWith:O}));case"ArrowUp":e.preventDefault();var T=x(t,v,n);return void(null!=T&&d({type:J,id:T,lastInteractedWith:T}));case"ArrowLeft":if(e.preventDefault(),(I(t,v)||p.isBranch)&&n.has(r))if(i){var D=[v].concat(c(w(t,v,new Set)));d({type:z,ids:D,lastInteractedWith:p.id})}else d({type:_,id:v,lastInteractedWith:v});else if(!R(t).children.includes(v)){var N=g(t,v);if(null==N)throw new Error("parentId of root element is null");d({type:J,id:N,lastInteractedWith:N})}return;case"ArrowRight":return e.preventDefault(),void((I(t,v)||p.isBranch)&&(n.has(r)?d({type:J,id:p.children[0],lastInteractedWith:p.children[0]}):d({type:K,id:v,lastInteractedWith:v})));case"Home":e.preventDefault(),d({type:J,id:R(t).children[0],lastInteractedWith:R(t).children[0]});break;case"End":e.preventDefault();var L=A(t,R(t).id,n);return void d({type:J,id:L,lastInteractedWith:L});case"*":e.preventDefault();var M=g(t,v);if(null==M)throw new Error("parentId of element is null");var B=F(t,M).children.filter((function(e){return I(t,e)||F(t,e).isBranch}));return void d({type:H,ids:B,lastInteractedWith:v});case"Enter":case" ":case"Spacebar":if(e.preventDefault(),h===re.focus)return;var V=k(t,p.id,a),$=U(t,p.id,a);return d({type:f?V&&!$?P:q:G,id:v,multiSelect:o,lastInteractedWith:v,lastManuallyToggled:v}),s&&!l.has(p.id)&&d({type:X,ids:C(t,[v],l),select:!f||!a.has(v),multiSelect:o,lastInteractedWith:v,lastManuallyToggled:v}),void(u&&d({type:Y,id:v,lastInteractedWith:v}));default:if(1===e.key.length)for(var Q=W(t,v,n);Q!==v;)if(null!=Q){if(F(t,Q).name[0].toLowerCase()===e.key.toLowerCase())return void d({type:J,id:Q,lastInteractedWith:v});Q=W(t,Q,n)}else Q=R(t).children[0];return}}}};ue.propTypes={data:t.array.isRequired,onSelect:t.func,onNodeSelect:t.func,onExpand:t.func,className:t.string,nodeRenderer:t.func.isRequired,defaultExpandedIds:t.array,defaultSelectedIds:t.array,expandedIds: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(ie),clickAction:t.oneOf(de),onBlur:t.func,onLoadData:t.func};export default ue;export{de as CLICK_ACTIONS,T as flattenTree}; |
@@ -14,2 +14,3 @@ import { EventCallback, INode, INodeRef, NodeId } from "./types"; | ||
export declare const getDescendants: (data: INode[], id: NodeId, disabledIds: Set<NodeId>) => NodeId[]; | ||
export declare const getChildren: (data: INode[], id: NodeId) => NodeId[]; | ||
export declare const getSibling: (data: INode[], id: NodeId, diff: number) => NodeId | null; | ||
@@ -51,3 +52,4 @@ export declare const getLastAccessible: (data: INode[], id: NodeId, expandedIds: Set<NodeId>) => NodeId; | ||
export declare const isBranchNotSelectedAndHasAllSelectedDescendants: (data: INode[], elementId: NodeId, selectedIds: Set<NodeId>) => boolean; | ||
export declare const isBranchSelectedAndHasAllSelectedDescendants: (data: INode[], elementId: NodeId, selectedIds: Set<NodeId>) => boolean; | ||
export declare const isBranchNotSelectedAndHasOnlySelectedChild: (data: INode[], elementId: NodeId, selectedIds: Set<NodeId>) => boolean; | ||
export declare const isBranchSelectedAndHasOnlySelectedChild: (data: INode[], elementId: NodeId, selectedIds: Set<NodeId>) => boolean; | ||
export declare const getTreeParent: (data: INode[]) => INode; | ||
@@ -54,0 +56,0 @@ export declare const getTreeNode: (data: INode[], id: NodeId) => INode; |
{ | ||
"name": "react-accessible-treeview", | ||
"description": "A react component that implements the treeview pattern as described by the WAI-ARIA Authoring Practices.", | ||
"version": "2.5.3", | ||
"version": "2.5.4", | ||
"author": "lissitz (https://github.com/lissitz)", | ||
@@ -6,0 +6,0 @@ "main": "dist/react-accessible-treeview.cjs.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94788
667