react-accessible-treeview
Advanced tools
Comparing version 2.6.2 to 2.6.3
@@ -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")),a=e(require("prop-types")),n=require("react"),l=e(n);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,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==a)return;var n,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)||c(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e){return function(e){if(Array.isArray(e))return o(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||c(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e,t){if(e){if("string"==typeof e)return o(e,t);var a=Object.prototype.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?o(e,t):void 0}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var a=0,n=new Array(t);a<t;a++)n[a]=e[a];return n}function u(e,t){var a="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!a){if(Array.isArray(e)||(a=c(e))||t&&e&&"number"==typeof e.length){a&&(e=a);var n=0,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 f(e,t){var a={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(a[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var 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 h=function(){},p=function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return function(e){var a,n=u(t);try{for(n.s();!(a=n.n()).done;){var l=a.value;if(l&&l(e),e.defaultPrevented)break}}catch(e){n.e(e)}finally{n.f()}}},v=function(e,t){var a,n=new Set,l=u(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},b=function(e,t){return new Set([].concat(s(v(e,t)),s(v(t,e))))},S=function(e){var t=n.useRef();return n.useEffect((function(){t.current=e}),[e]),t.current},y=function(e,t){var a;return!!(null===(a=U(e,t).children)||void 0===a?void 0:a.length)},I=function(e,t){return U(e,t).parent},g=function(e,t,a){for(var n=t,l=[];;){var r=I(e,n);if(0===r||null==r||null!=r&&a.has(r))break;l.push(r),n=r}return l},m=function(e,t,a){var n=[];return function e(t,l){var r=U(t,l);if(null!=r.children){var d,i=u(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},w=function(e,t){var a=U(e,t);return null==a.children?[]:a.children},E=function(e,t,a){var n=I(e,t);if(null!=n){var l=U(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=U(e,t);for(M(e).id===t&&(n=U(e,U(e,t).children[U(e,t).children.length-1]));a.has(n.id)&&y(e,n.id);)n=U(e,n.children[n.children.length-1]);return n.id},A=function(e,t,a){if(t===M(e).children[0])return null;var n=E(e,t,-1);return null==n?I(e,t):O(e,n,a)},x=function(e,t,a){var n=U(e,t).id;if(y(e,n)&&a.has(n))return U(e,n).children[0];for(;;){var l=E(e,n,1);if(null!=l)return l;if(null==(n=I(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=e.isSelected,a=e.isDisabled,n=e.multiSelect;return a||n?t:!!t||void 0},T=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,s(t.filter((function(t){return y(e,t)})).map((function(t){return m(e,t,a)}))))},C=function(e,t,a){null!=t?window.navigator.userAgent.match(/Trident/)?setTimeout((function(){return!t.contains(document.activeElement)&&a()}),0):!t.contains(e.nativeEvent.relatedTarget)&&a():console.warn("ref not set on <ul>")},D=function(e,t,a){return y(e,t)&&a.has(t)&&m(e,t,new Set).some((function(e){return a.has(e)}))},L=function(e,t,a){var n=w(e,t);return y(e,t)&&!a.has(t)&&1===n.length&&n.every((function(e){return a.has(e)}))},k=function(e,t,a){var n=w(e,t);return y(e,t)&&a.has(t)&&1===n.length&&n.every((function(e){return a.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 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},R=function(e){var t=Array.from(new Set(e));return e.length!==t.length},F="COLLAPSE",_="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 F: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=u(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 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,tabbableId:t.keepFocus?e.tabbableId:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id});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 b=new Set(e.halfSelectedIds);return b.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:p,halfSelectedIds:b,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 S,y=new Set(e.selectedIds);return y.delete(t.id),t.multiSelect?(S=new Set(e.halfSelectedIds)).delete(t.id):S=new Set,Object.assign(Object.assign({},e),{selectedIds:y,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 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,T=e.lastInteractedWith,N=e.tabbableId;if(t.multiSelect)j=new Set(t.ids),t.ids.length&&(T=t.ids[t.ids.length-1],N=t.ids[t.ids.length-1]);else{j=new Set,t.ids.length>1&&console.warn("Tree in singleSelect mode, only the first item from selectedIds will be selected.");var C=t.ids[0];C&&j.add(C),T=null!=C?C:T,N=null!=C?C:T}var D=new Set(e.halfSelectedIds);t.ids.every((function(e){return D.delete(e)}));var L=new Set(t.ids);return Object.assign(Object.assign({},e),{selectedIds:j,halfSelectedIds:D,controlledIds:L,isFocused:!0,lastAction:t.type,tabbableId:N,lastInteractedWith:T});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 k=new Set(e.disabledIds);return k.add(t.id),Object.assign(Object.assign({},e),{disabledIds:k});case Q:var M=new Set(e.disabledIds);return M.delete(t.id),Object.assign(Object.assign({},e),{disabledIds:M});case Z:return Object.assign(Object.assign({},e),{lastManuallyToggled:null});default:throw new Error("Invalid action passed to the reducer")}},ae={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"},le=Object.freeze(Object.values(ne)),re=Object.freeze(Object.values({check:"check",select:"select"})),de=function(e){var a=e.element,n=e.dispatch,r=e.data,i=e.selectedIds,c=e.tabbableId,o=e.isFocused,u=e.expandedIds,v=e.disabledIds,b=e.halfSelectedIds,S=e.lastUserSelect,I=e.nodeRefs,g=e.leafRefs,w=e.baseClassNames,E=e.nodeRenderer,O=e.nodeAction,A=e.setsize,x=e.posinset,C=e.level,L=e.propagateCollapse,M=e.propagateSelect,U=e.multiSelect,R=e.togglableSelect,F=e.clickAction,B=e.state,z=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(u.has(a.id)&&L){var t=[a.id].concat(s(m(r,a.id,new Set)));n({type:_,ids:t,lastInteractedWith:a.id})}else n({type:G,id:a.id,lastInteractedWith:a.id})},P=function(){return n({type:X,id:a.id,lastInteractedWith:a.id})},$=function(e){if(e.shiftKey){var t=W({data:r,expandedIds:u,from:S,to:a.id}).filter((function(e){return!v.has(e)}));t=M?N(r,t,v):t,n({type:Y,select:!0,multiSelect:U,ids:t,lastInteractedWith:a.id,lastManuallyToggled:a.id})}else if(e.ctrlKey||F===ne.select){var l=D(r,a.id,i),d=k(r,a.id,i);n({type:R?l&&!d?K:V:H,id:a.id,multiSelect:U,lastInteractedWith:a.id,lastManuallyToggled:a.id}),M&&!v.has(a.id)&&n({type:q,ids:N(r,[a.id],v),select:!R||!i.has(a.id),multiSelect:U,lastInteractedWith:a.id,lastManuallyToggled:a.id})}else F===ne.exclusiveSelect?n({type:R?V:H,id:a.id,multiSelect:!1,lastInteractedWith:a.id,lastManuallyToggled:a.id}):F===ne.focus&&n({type:X,id:a.id,lastInteractedWith:a.id})},J=function(e){var n;return t(e,(d(n={},"".concat(e,"--expanded"),u.has(a.id)),d(n,"".concat(e,"--selected"),i.has(a.id)),d(n,"".concat(e,"--focused"),c===a.id&&o),n))},Q="select"===O?{"aria-selected":j({isSelected:i.has(a.id),isDisabled:v.has(a.id),multiSelect:U})}:{"aria-checked":T({isSelected:i.has(a.id),isDisabled:v.has(a.id),isHalfSelected:b.has(a.id),multiSelect:U})};return y(r,a.id)||a.isBranch?l.createElement("li",Object.assign({role:"treeitem","aria-expanded":u.has(a.id),"aria-setsize":A,"aria-posinset":x,"aria-level":C,"aria-disabled":v.has(a.id),tabIndex:c===a.id?0:-1,ref:function(e){null!=(null==I?void 0:I.current)&&null!=e&&(I.current[a.id]=e)},className:w.branchWrapper},Q),l.createElement(l.Fragment,null,E({element:a,isBranch:!0,isSelected:i.has(a.id),isHalfSelected:b.has(a.id),isExpanded:u.has(a.id),isDisabled:v.has(a.id),dispatch:n,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.onClick;return{onClick:null==n?p($,z,P):p(n,P),className:t(J(w.node),w.branch),ref:function(e){null!=(null==g?void 0:g.current)&&(g.current[a.id]=e)}}},setsize:A,posinset:x,level:C,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:a,isBranch:!1,isSelected:i.has(a.id),isHalfSelected:!1,isExpanded:!1,isDisabled:v.has(a.id),dispatch:n,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.onClick;return Object.assign({role:"treeitem",tabIndex:c===a.id?0:-1,onClick:p(null==n?$:n,P),ref:function(e){null!=(null==I?void 0:I.current)&&null!=(null==g?void 0:g.current)&&(I.current[a.id]=e,g.current[a.id]=e)},className:t(J(w.node),w.leaf),"aria-setsize":A,"aria-posinset":x,"aria-level":C,disabled:v.has(a.id),"aria-disabled":v.has(a.id)},Q)},setsize:A,posinset:x,level:C,handleSelect:$,handleExpand:h,treeState:B}))},ie=function(e){var t=e.data,a=e.element,n=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)},n.has(a.id)&&a.children.length>0&&a.children.map((function(e,d){return l.createElement(de,Object.assign({data:t,expandedIds:n,baseClassNames:i,key:"".concat(e,"-").concat(r(e)),element:U(t,e),setsize:a.children.length,posinset:d+1,level:s+1},c))})))},se=function(e){var t=e.data,a=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),C=i(n.useReducer(te,{selectedIds:new Set(a||d),controlledIds:new Set(a),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),D=C[0],k=C[1],R=D.selectedIds,V=D.controlledIds,Y=D.expandedIds,$=D.disabledIds,J=D.tabbableId,Q=D.halfSelectedIds,ae=D.lastAction,ne=D.lastInteractedWith,le=D.lastManuallyToggled,re=S(R)||new Set,de=b(R,re);n.useEffect((function(){var e;if(null!=p&&p!==h){var a,n=u(de);try{for(n.s();!(a=n.n()).done;){var l=a.value,r=y(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:D})}}catch(e){n.e(e)}finally{n.f()}}}),[t,R,Y,$,Q,de,p,D]),n.useEffect((function(){null!=w&&w!==h&&null!=le&&de.size&&(w({element:U(t,le),isSelected:R.has(le),isBranch:y(t,le),treeState:D}),k({type:Z}))}),[le,R,de]);var ie=S(Y)||new Set;n.useEffect((function(){var e=b(Y,ie);if(null!=E&&E!==h){var a,n=u(e);try{for(n.s();!(a=n.n()).done;){var l=a.value;E({element:U(t,l),isExpanded:Y.has(l),isSelected:R.has(l),isDisabled:$.has(l),isHalfSelected:Q.has(l),treeState:D})}}catch(e){n.e(e)}finally{n.f()}}}),[t,R,Y,$,Q,ie,E,D]);var se,ce,oe=(se=t,ce=n.useRef(),n.useEffect((function(){ce.current=se})),ce.current||new Map);n.useEffect((function(){var e=b(Y,ie);if(O){var a,n=u(e);try{for(n.s();!(a=n.n()).done;){var l=a.value;O({element:U(t,l),isExpanded:Y.has(l),isSelected:R.has(l),isDisabled:$.has(l),isHalfSelected:Q.has(l),treeState:D})}}catch(e){n.e(e)}finally{n.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:N(t,[i],$),select:!0,multiSelect:x,lastInteractedWith:i})}}catch(e){d.e(e)}finally{d.f()}}}}),[t,R,Y,$,Q,ie,O,D]);var ue=b(new Set(a),V);return n.useEffect((function(){if(a){ue.size&&k({type:ee,ids:a,multiSelect:x});var e,n=u(a);try{for(n.s();!(e=n.n()).done;){var l=e.value;W&&!$.has(l)&&k({type:q,ids:N(t,[l],$),select:!0,multiSelect:x,lastInteractedWith:l})}}catch(e){n.e(e)}finally{n.f()}}}),[a]),n.useEffect((function(){var e=new Set(l),a=v(e,ie),n=v(ie,e);if(n.size){var r,d=u(n);try{for(d.s();!(r=d.n()).done;){var i=r.value;if(y(t,i)||U(t,i).isBranch){var c=[i].concat(s(m(t,i,new Set)));k({type:_,ids:c,lastInteractedWith:i})}}}catch(e){d.e(e)}finally{d.f()}}if(a.size){var o,f=u(a);try{for(f.s();!(o=f.n()).done;){var h=o.value;if(y(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]),n.useEffect((function(){if(j){var e=new Set([].concat(s(de),s(V)));ne&&ae!==X&&ae!==F&&ae!==B&&ae!==G&&e.add(ne);var a=[];e.forEach((function(e){t.find((function(t){return t.id===e}))||a.push(e)})),a.forEach((function(t){return e.delete(t)}));var n,l=function(e,t,a,n,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&&n.has(o))break;var f=U(e,o).children.filter((function(e){return!n.has(e)}));if(0===f.length)break;if(f.some((function(e){return a.has(e)||i.some.has(e)||l.has(e)})))f.every((function(e){return a.has(e)}))?i.every.add(o):i.some.add(o);else{var h=g(e,c,n).find((function(e){return a.has(e)}));if(!r&&h){m(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,R,$,Q,x),r=l.every,d=l.some,i=l.none,c=u(r);try{for(c.s();!(n=c.n()).done;){var o=n.value;R.has(o)||k({type:H,id:o,multiSelect:x||L(t,o,R),keepFocus:!0,NotUserAction:!0,lastInteractedWith:ne})}}catch(e){c.e(e)}finally{c.f()}var f,h=u(d);try{for(h.s();!(f=h.n()).done;){var p=f.value;Q.has(p)||k({type:K,id:p,lastInteractedWith:ne,keepFocus:!0,NotUserAction:!0})}}catch(e){h.e(e)}finally{h.f()}var v,b=u(i);try{for(b.s();!(v=b.n()).done;){var S=v.value;(R.has(S)||Q.has(S))&&k({type:P,id:S,multiSelect:x,keepFocus:!0,NotUserAction:!0,lastInteractedWith:ne,lastManuallyToggled:le})}}catch(e){b.e(e)}finally{b.f()}}}),[t,x,j,R,Y,$,Q,ae,re,de,ne,ue]),n.useEffect((function(){if(null!=ne&&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[ne]),function(e){null!=e&&e.focus&&e.focus({preventScroll:!0})}(e)}}),[J,o,f,ne]),[D,k]},ce=l.forwardRef((function(e,a){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,b=e.onExpand,S=void 0===b?h:b,y=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,N=void 0!==T&&T,D=e.togglableSelect,L=void 0!==D&&D,k=e.defaultExpandedIds,F=void 0===k?[]:k,_=e.defaultSelectedIds,B=void 0===_?[]:_,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,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=n.useRef({}),Q=n.useRef({}),Z=i(se({data:d,controlledSelectedIds:s,controlledExpandedIds:q,defaultExpandedIds:F,defaultSelectedIds:B,defaultDisabledIds:K,nodeRefs:J,leafRefs:Q,onSelect:u,onNodeSelect:v,onExpand:S,onLoadData:y,togglableSelect:L,multiSelect:w,propagateSelect:O,propagateSelectUpwards:x}),2),ee=Z[0],te=Z[1];O=O&&w;var le=n.useRef(null);return null!=a&&(le=a),l.createElement("ul",Object.assign({className:t(ae.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: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:N,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:ae,nodeRenderer:c,propagateCollapse:j,propagateSelect:O,propagateSelectUpwards:x,multiSelect:w,togglableSelect:L,clickAction:P,nodeAction:V}))})))})),oe=function(e){var t=e.data,a=e.expandedIds,n=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 b=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!==b.length,ids:b,lastInteractedWith:p.id})}else if(e.shiftKey&&("Home"===e.key||"End"===e.key)){var S="Home"===e.key?M(t).children[0]:O(t,v,a),g=W({data:t,expandedIds:a,from:v,to:S}).filter((function(e){return!l.has(e)}));d({type:q,multiSelect:o,select:!0,ids:c?N(t,g,l):g}),d({type:X,id:S,lastInteractedWith:S})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var w=A(t,v,a);return void(null==w||l.has(w)||(d({type:q,ids:c?N(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,a);return void(null==E||l.has(E)||(d({type:q,ids:c?N(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,a);return void(null!=j&&d({type:X,id:j,lastInteractedWith:j}));case"ArrowUp":e.preventDefault();var T=A(t,v,a);return void(null!=T&&d({type:X,id:T,lastInteractedWith:T}));case"ArrowLeft":if(e.preventDefault(),(y(t,v)||p.isBranch)&&a.has(r))if(i){var C=[v].concat(s(m(t,v,new Set)));d({type:_,ids:C,lastInteractedWith:p.id})}else d({type:F,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((y(t,v)||p.isBranch)&&(a.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,a);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 y(t,e)||U(t,e).isBranch}));return void d({type:z,ids:Y,lastInteractedWith:v});case"Enter":case" ":case"Spacebar":if(e.preventDefault(),h===ne.focus)return;var $=D(t,p.id,n),J=k(t,p.id,n);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:N(t,[v],l),select:!f||!n.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,a);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,a)}else Q=M(t).children[0];return}}}};ce.propTypes={data:a.array.isRequired,onSelect:a.func,onNodeSelect:a.func,onExpand:a.func,className:a.string,nodeRenderer:a.func.isRequired,defaultExpandedIds:a.array,defaultSelectedIds:a.array,expandedIds:a.array,selectedIds:a.array,defaultDisabledIds:a.array,propagateCollapse:a.bool,propagateSelect:a.bool,propagateSelectUpwards:a.bool,multiSelect:a.bool,expandOnKeyboardSelect:a.bool,togglableSelect:a.bool,nodeAction:a.oneOf(re),clickAction:a.oneOf(le),onBlur:a.func,onLoadData:a.func},exports.CLICK_ACTIONS=le,exports.default=ce,exports.flattenTree=function(e){var t=0,a=[];return function e(n,l){var r,d={id:n.id||t,name:n.name,children:[],parent:l,metadata:n.metadata?Object.assign({},n.metadata):void 0};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=u(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=u(a.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),a}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("classnames")),a=e(require("prop-types")),n=require("react"),l=e(n);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,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==a)return;var n,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)||c(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e){return function(e){if(Array.isArray(e))return o(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||c(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e,t){if(e){if("string"==typeof e)return o(e,t);var a=Object.prototype.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?o(e,t):void 0}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var a=0,n=new Array(t);a<t;a++)n[a]=e[a];return n}function u(e,t){var a="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!a){if(Array.isArray(e)||(a=c(e))||t&&e&&"number"==typeof e.length){a&&(e=a);var n=0,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 f(e,t){var a={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(a[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var 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 h=function(){},p=function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return function(e){var a,n=u(t);try{for(n.s();!(a=n.n()).done;){var l=a.value;if(l&&l(e),e.defaultPrevented)break}}catch(e){n.e(e)}finally{n.f()}}},v=function(e,t){var a,n=new Set,l=u(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},b=function(e,t){return new Set([].concat(s(v(e,t)),s(v(t,e))))},I=function(e){var t=n.useRef();return n.useEffect((function(){t.current=e}),[e]),t.current},S=function(e,t){var a;return!!(null===(a=k(e,t).children)||void 0===a?void 0:a.length)},y=function(e,t){return k(e,t).parent},g=function(e,t,a){for(var n=t,l=[];;){var r=y(e,n);if(0===r||null==r||null!=r&&a.has(r))break;l.push(r),n=r}return l},m=function(e,t,a){var n=[];return function e(t,l){var r=k(t,l);if(null!=r.children){var d,i=u(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},w=function(e,t){var a=k(e,t);return null==a.children?[]:a.children},E=function(e,t,a){var n=y(e,t);if(null!=n){var l=k(e,n),r=l.children.indexOf(t)+a;if(l.children[r])return l.children[r]}return null},A=function(e,t,a){var n=k(e,t);for(L(e).id===t&&(n=k(e,k(e,t).children[k(e,t).children.length-1]));a.has(n.id)&&S(e,n.id);)n=k(e,n.children[n.children.length-1]);return n.id},O=function(e,t,a){if(t===L(e).children[0])return null;var n=E(e,t,-1);return null==n?y(e,t):A(e,n,a)},W=function(e,t,a){var n=k(e,t).id;if(S(e,n)&&a.has(n))return k(e,n).children[0];for(;;){var l=E(e,n,1);if(null!=l)return l;if(null==(n=y(e,n)))return null}},x=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=W(t,s,a))&&r.push(s),null!=s&&s!==l);)i+=1;else if(n>l)for(;i<d&&(null!=(s=O(t,s,a))&&r.push(s),null!=s&&s!==l);)i+=1;return r},T=function(e){var t=e.isSelected,a=e.isDisabled,n=e.multiSelect;return a||n?t:!!t||void 0},j=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,s(t.filter((function(t){return S(e,t)})).map((function(t){return m(e,t,a)}))))},D=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>")},C=function(e,t,a){return S(e,t)&&a.has(t)&&m(e,t,new Set).some((function(e){return a.has(e)}))},U=function(e,t,a){var n=w(e,t);return S(e,t)&&!a.has(t)&&1===n.length&&n.every((function(e){return a.has(e)}))},M=function(e,t,a){var n=w(e,t);return S(e,t)&&a.has(t)&&1===n.length&&n.every((function(e){return a.has(e)}))},L=function(e){var t=e.find((function(e){return null===e.parent}));if(!t)throw Error("TreeView data must contain parent node.");return t},k=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},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="UPDATE_TREE_STATE_WHEN_DATA_CHANGED",ae=function(e,t){switch(t.type){case _: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 F:var n,l=new Set(e.expandedIds),r=u(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 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,tabbableId:t.keepFocus?e.tabbableId:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id});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 b=new Set(e.halfSelectedIds);return b.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:p,halfSelectedIds:b,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0!==t.NotUserAction,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 I,S=new Set(e.selectedIds);return S.delete(t.id),t.multiSelect?(I=new Set(e.halfSelectedIds)).delete(t.id):I=new Set,Object.assign(Object.assign({},e),{selectedIds:S,halfSelectedIds:I,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled});case V:if(e.disabledIds.has(t.id))return e;var y,g=e.selectedIds.has(t.id);t.multiSelect?(y=new Set(e.selectedIds),g?y.delete(t.id):y.add(t.id)):(y=new Set,g||y.add(t.id));var m=new Set(e.halfSelectedIds);return m.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:y,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 A=v(e.halfSelectedIds,w);return Object.assign(Object.assign({},e),{selectedIds:w,halfSelectedIds:A,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled})}return e;case Y:var O,W=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){O=t.select?new Set(W):v(e.selectedIds,new Set(W));var x=v(e.halfSelectedIds,O);return Object.assign(Object.assign({},e),{selectedIds:O,halfSelectedIds:x,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled})}return e;case ee:var T,j=e.lastInteractedWith,N=e.tabbableId;if(t.multiSelect)T=new Set(t.ids),t.ids.length&&(j=t.ids[t.ids.length-1],N=t.ids[t.ids.length-1]);else{T=new Set,t.ids.length>1&&console.warn("Tree in singleSelect mode, only the first item from selectedIds will be selected.");var D=t.ids[0];D&&T.add(D),j=null!=D?D:j,N=null!=D?D:j}var C=new Set(e.halfSelectedIds);t.ids.every((function(e){return C.delete(e)}));var U=new Set(t.ids);return Object.assign(Object.assign({},e),{selectedIds:T,halfSelectedIds:C,controlledIds:U,isFocused:!0,lastAction:t.type,tabbableId:N,lastInteractedWith:j});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 M=new Set(e.disabledIds);return M.add(t.id),Object.assign(Object.assign({},e),{disabledIds:M});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});case te:return Object.assign(Object.assign({},e),{tabbableId:t.tabbableId,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled,lastUserSelect:t.lastUserSelect});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(e){var a=e.element,n=e.dispatch,r=e.data,i=e.selectedIds,c=e.tabbableId,o=e.isFocused,u=e.expandedIds,v=e.disabledIds,b=e.halfSelectedIds,I=e.lastUserSelect,y=e.nodeRefs,g=e.leafRefs,w=e.baseClassNames,E=e.nodeRenderer,A=e.nodeAction,O=e.setsize,W=e.posinset,D=e.level,U=e.propagateCollapse,L=e.propagateSelect,k=e.multiSelect,R=e.togglableSelect,_=e.clickAction,B=e.state,z=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(u.has(a.id)&&U){var t=[a.id].concat(s(m(r,a.id,new Set)));n({type:F,ids:t,lastInteractedWith:a.id})}else n({type:G,id:a.id,lastInteractedWith:a.id})},P=function(){return n({type:X,id:a.id,lastInteractedWith:a.id})},$=function(e){if(e.shiftKey){var t=x({data:r,expandedIds:u,from:I,to:a.id}).filter((function(e){return!v.has(e)}));t=L?N(r,t,v):t,n({type:Y,select:!0,multiSelect:k,ids:t,lastInteractedWith:a.id,lastManuallyToggled:a.id})}else if(e.ctrlKey||_===le.select){var l=C(r,a.id,i),d=M(r,a.id,i);n({type:R?l&&!d?K:V:H,id:a.id,multiSelect:k,lastInteractedWith:a.id,lastManuallyToggled:a.id}),L&&!v.has(a.id)&&n({type:q,ids:N(r,[a.id],v),select:!R||!i.has(a.id),multiSelect:k,lastInteractedWith:a.id,lastManuallyToggled:a.id})}else _===le.exclusiveSelect?n({type:R?V:H,id:a.id,multiSelect:!1,lastInteractedWith:a.id,lastManuallyToggled:a.id}):_===le.focus&&n({type:X,id:a.id,lastInteractedWith:a.id})},J=function(e){var n;return t(e,(d(n={},"".concat(e,"--expanded"),u.has(a.id)),d(n,"".concat(e,"--selected"),i.has(a.id)),d(n,"".concat(e,"--focused"),c===a.id&&o),n))},Q="select"===A?{"aria-selected":T({isSelected:i.has(a.id),isDisabled:v.has(a.id),multiSelect:k})}:{"aria-checked":j({isSelected:i.has(a.id),isDisabled:v.has(a.id),isHalfSelected:b.has(a.id),multiSelect:k})};return S(r,a.id)||a.isBranch?l.createElement("li",Object.assign({role:"treeitem","aria-expanded":u.has(a.id),"aria-setsize":O,"aria-posinset":W,"aria-level":D,"aria-disabled":v.has(a.id),tabIndex:c===a.id?0:-1,ref:function(e){null!=(null==y?void 0:y.current)&&null!=e&&(y.current[a.id]=e)},className:w.branchWrapper},Q),l.createElement(l.Fragment,null,E({element:a,isBranch:!0,isSelected:i.has(a.id),isHalfSelected:b.has(a.id),isExpanded:u.has(a.id),isDisabled:v.has(a.id),dispatch:n,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.onClick;return{onClick:null==n?p($,z,P):p(n,P),className:t(J(w.node),w.branch),ref:function(e){null!=(null==g?void 0:g.current)&&(g.current[a.id]=e)}}},setsize:O,posinset:W,level:D,handleSelect:$,handleExpand:z,treeState:B}),l.createElement(se,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:a,isBranch:!1,isSelected:i.has(a.id),isHalfSelected:!1,isExpanded:!1,isDisabled:v.has(a.id),dispatch:n,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.onClick;return Object.assign({role:"treeitem",tabIndex:c===a.id?0:-1,onClick:p(null==n?$:n,P),ref:function(e){null!=(null==y?void 0:y.current)&&null!=(null==g?void 0:g.current)&&(y.current[a.id]=e,g.current[a.id]=e)},className:t(J(w.node),w.leaf),"aria-setsize":O,"aria-posinset":W,"aria-level":D,disabled:v.has(a.id),"aria-disabled":v.has(a.id)},Q)},setsize:O,posinset:W,level:D,handleSelect:$,handleExpand:h,treeState:B}))},se=function(e){var t=e.data,a=e.element,n=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)},n.has(a.id)&&a.children.length>0&&a.children.map((function(e,d){return l.createElement(ie,Object.assign({data:t,expandedIds:n,baseClassNames:i,key:"".concat(e,"-").concat(r(e)),element:k(t,e),setsize:a.children.length,posinset:d+1,level:s+1},c))})))},ce=function(e){var t=e.data,a=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,A=e.onLoadData,O=e.togglableSelect,W=e.multiSelect,x=e.propagateSelect,T=e.propagateSelectUpwards,j=L(t),D=i(n.useReducer(ae,{selectedIds:new Set(a||d),controlledIds:new Set(a),tabbableId:j.children[0],isFocused:!1,expandedIds:new Set(l||r),halfSelectedIds:new Set,lastUserSelect:j.children[0],lastInteractedWith:null,lastManuallyToggled:null,disabledIds:new Set(c)}),2),C=D[0],M=D[1],R=C.selectedIds,V=C.controlledIds,Y=C.expandedIds,$=C.disabledIds,J=C.tabbableId,Q=C.halfSelectedIds,ne=C.lastAction,le=C.lastInteractedWith,re=C.lastManuallyToggled,de=I(R)||new Set,ie=b(R,de);n.useEffect((function(){var e;if(null!=p&&p!==h){var a,n=u(ie);try{for(n.s();!(a=n.n()).done;){var l=a.value,r=S(t,l)||!!(null===(e=k(t,J))||void 0===e?void 0:e.isBranch);p({element:k(t,l),isBranch:r,isExpanded:!!r&&Y.has(l),isSelected:R.has(l),isDisabled:$.has(l),isHalfSelected:!!r&&Q.has(l),treeState:C})}}catch(e){n.e(e)}finally{n.f()}}}),[t,R,Y,$,Q,ie,p,C]),n.useEffect((function(){null!=w&&w!==h&&null!=re&&ie.size&&(w({element:k(t,re),isSelected:R.has(re),isBranch:S(t,re),treeState:C}),M({type:Z}))}),[re,R,ie]);var se=I(Y)||new Set;n.useEffect((function(){var e=b(Y,se);if(null!=E&&E!==h){var a,n=u(e);try{for(n.s();!(a=n.n()).done;){var l=a.value;E({element:k(t,l),isExpanded:Y.has(l),isSelected:R.has(l),isDisabled:$.has(l),isHalfSelected:Q.has(l),treeState:C})}}catch(e){n.e(e)}finally{n.f()}}}),[t,R,Y,$,Q,se,E,C]);var ce,oe,ue=(ce=t,oe=n.useRef(),n.useEffect((function(){oe.current=ce})),oe.current||new Map);n.useEffect((function(){var e=b(Y,se);if(A){var a,n=u(e);try{for(n.s();!(a=n.n()).done;){var l=a.value;A({element:k(t,l),isExpanded:Y.has(l),isSelected:R.has(l),isDisabled:$.has(l),isHalfSelected:Q.has(l),treeState:C})}}catch(e){n.e(e)}finally{n.f()}if(ue!==t&&O&&x){var r,d=u(Y);try{for(d.s();!(r=d.n()).done;){var i=r.value;R.has(i)&&M({type:q,ids:N(t,[i],$),select:!0,multiSelect:W,lastInteractedWith:i})}}catch(e){d.e(e)}finally{d.f()}}}}),[t,R,Y,$,Q,se,A,C]),n.useEffect((function(){if(ue!==t){var e=L(t);e.children.length&&M({type:te,tabbableId:t.find((function(e){return e.id===C.tabbableId}))?C.tabbableId:e.children[0],lastInteractedWith:t.find((function(e){return e.id===C.lastInteractedWith}))?C.lastInteractedWith:null,lastManuallyToggled:t.find((function(e){return e.id===C.lastManuallyToggled}))?C.lastManuallyToggled:null,lastUserSelect:t.find((function(e){return e.id===C.lastUserSelect}))?C.lastUserSelect:e.children[0]})}}),[t]);var fe=b(new Set(a),V);return n.useEffect((function(){if(a){fe.size&&M({type:ee,ids:a,multiSelect:W});var e,n=u(a);try{for(n.s();!(e=n.n()).done;){var l=e.value;x&&!$.has(l)&&M({type:q,ids:N(t,[l],$),select:!0,multiSelect:W,lastInteractedWith:l})}}catch(e){n.e(e)}finally{n.f()}}}),[a]),n.useEffect((function(){var e=new Set(l),a=v(e,se),n=v(se,e);if(n.size){var r,d=u(n);try{for(d.s();!(r=d.n()).done;){var i=r.value;if(S(t,i)||k(t,i).isBranch){var c=[i].concat(s(m(t,i,new Set)));M({type:F,ids:c,lastInteractedWith:i})}}}catch(e){d.e(e)}finally{d.f()}}if(a.size){var o,f=u(a);try{for(f.s();!(o=f.n()).done;){var h=o.value;if(S(t,h)||k(t,h).isBranch){var p=y(t,h);M(p?{type:z,ids:[h,p],lastInteractedWith:h}:{type:B,id:h,lastInteractedWith:h})}}}catch(e){f.e(e)}finally{f.f()}}}),[l]),n.useEffect((function(){if(T){var e=new Set([].concat(s(ie),s(V)));le&&ne!==X&&ne!==_&&ne!==B&&ne!==G&&e.add(le);var a=[];e.forEach((function(e){t.find((function(t){return t.id===e}))||a.push(e)})),a.forEach((function(t){return e.delete(t)}));var n,l=function(e,t,a,n,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=y(e,c);if(0===o||null==o||null!=o&&n.has(o))break;var f=k(e,o).children.filter((function(e){return!n.has(e)}));if(0===f.length)break;if(f.some((function(e){return a.has(e)||i.some.has(e)||l.has(e)})))f.every((function(e){return a.has(e)}))?i.every.add(o):i.some.add(o);else{var h=g(e,c,n).find((function(e){return a.has(e)}));if(!r&&h){m(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,R,$,Q,W),r=l.every,d=l.some,i=l.none,c=u(r);try{for(c.s();!(n=c.n()).done;){var o=n.value;R.has(o)||M({type:H,id:o,multiSelect:W||U(t,o,R),keepFocus:!0,NotUserAction:!0,lastInteractedWith:le})}}catch(e){c.e(e)}finally{c.f()}var f,h=u(d);try{for(h.s();!(f=h.n()).done;){var p=f.value;Q.has(p)||M({type:K,id:p,lastInteractedWith:le,keepFocus:!0,NotUserAction:!0})}}catch(e){h.e(e)}finally{h.f()}var v,b=u(i);try{for(b.s();!(v=b.n()).done;){var I=v.value;(R.has(I)||Q.has(I))&&M({type:P,id:I,multiSelect:W,keepFocus:!0,NotUserAction:!0,lastInteractedWith:le,lastManuallyToggled:re})}}catch(e){b.e(e)}finally{b.f()}}}),[t,W,T,R,Y,$,Q,ne,de,ie,le,fe]),n.useEffect((function(){if(null!=le&&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[le]),function(e){null!=e&&e.focus&&e.focus({preventScroll:!0})}(e)}}),[J,o,f,le]),[C,M]},oe=l.forwardRef((function(e,a){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,b=e.onExpand,I=void 0===b?h:b,S=e.onLoadData,y=e.className,g=void 0===y?"":y,m=e.multiSelect,w=void 0!==m&&m,E=e.propagateSelect,A=void 0!==E&&E,O=e.propagateSelectUpwards,W=void 0!==O&&O,x=e.propagateCollapse,T=void 0!==x&&x,j=e.expandOnKeyboardSelect,N=void 0!==j&&j,C=e.togglableSelect,U=void 0!==C&&C,M=e.defaultExpandedIds,_=void 0===M?[]:M,F=e.defaultSelectedIds,B=void 0===F?[]:F,z=e.defaultDisabledIds,K=void 0===z?[]:z,H=e.clickAction,P=void 0===H?le.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."))})),0===e.filter((function(e){return null===e.parent})).length)throw Error("TreeView must have one root node.");if(e.filter((function(e){return null===e.parent})).length>1)throw Error("TreeView can have only one root node.");L(e).children.length||console.warn("TreeView have no nodes to display.")}(d);var J=n.useRef({}),Q=n.useRef({}),Z=i(ce({data:d,controlledSelectedIds:s,controlledExpandedIds:q,defaultExpandedIds:_,defaultSelectedIds:B,defaultDisabledIds:K,nodeRefs:J,leafRefs:Q,onSelect:u,onNodeSelect:v,onExpand:I,onLoadData:S,togglableSelect:U,multiSelect:w,propagateSelect:A,propagateSelectUpwards:W}),2),ee=Z[0],te=Z[1];A=A&&w;var ae=n.useRef(null);return null!=a&&(ae=a),l.createElement("ul",Object.assign({className:t(ne.root,g),role:"tree","aria-multiselectable":"select"===V?w:void 0,ref:ae,onBlur:function(e){D(e,ae.current,(function(){Y&&Y({treeState:ee,dispatch:te}),te({type:$})}))},onKeyDown:ue({data:d,tabbableId:ee.tabbableId,expandedIds:ee.expandedIds,selectedIds:ee.selectedIds,disabledIds:ee.disabledIds,halfSelectedIds:ee.halfSelectedIds,clickAction:P,dispatch:te,propagateCollapse:T,propagateSelect:A,multiSelect:w,expandOnKeyboardSelect:N,togglableSelect:U})},X),L(d).children.map((function(e,t){return l.createElement(ie,Object.assign({key:"".concat(e,"-").concat(r(e)),data:d,element:k(d,e),setsize:L(d).children.length,posinset:t+1,level:1},ee,{state:ee,dispatch:te,nodeRefs:J,leafRefs:Q,baseClassNames:ne,nodeRenderer:c,propagateCollapse:T,propagateSelect:A,propagateSelectUpwards:W,multiSelect:w,togglableSelect:U,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,c=e.propagateSelect,o=e.multiSelect,u=e.expandOnKeyboardSelect,f=e.togglableSelect,h=e.clickAction;return function(e){var p=k(t,r),v=p.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();var b=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!==b.length,ids:b,lastInteractedWith:p.id})}else if(e.shiftKey&&("Home"===e.key||"End"===e.key)){var I="Home"===e.key?L(t).children[0]:A(t,v,a),g=x({data:t,expandedIds:a,from:v,to:I}).filter((function(e){return!l.has(e)}));d({type:q,multiSelect:o,select:!0,ids:c?N(t,g,l):g}),d({type:X,id:I,lastInteractedWith:I})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var w=O(t,v,a);return void(null==w||l.has(w)||(d({type:q,ids:c?N(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=W(t,v,a);return void(null==E||l.has(E)||(d({type:q,ids:c?N(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 T=W(t,v,a);return void(null!=T&&d({type:X,id:T,lastInteractedWith:T}));case"ArrowUp":e.preventDefault();var j=O(t,v,a);return void(null!=j&&d({type:X,id:j,lastInteractedWith:j}));case"ArrowLeft":if(e.preventDefault(),(S(t,v)||p.isBranch)&&a.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(!L(t).children.includes(v)){var U=y(t,v);if(null==U)throw new Error("parentId of root element is null");d({type:X,id:U,lastInteractedWith:U})}return;case"ArrowRight":return e.preventDefault(),void((S(t,v)||p.isBranch)&&(a.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:L(t).children[0],lastInteractedWith:L(t).children[0]});break;case"End":e.preventDefault();var R=A(t,L(t).id,a);return void d({type:X,id:R,lastInteractedWith:R});case"*":e.preventDefault();var P=y(t,v);if(null==P)throw new Error("parentId of element is null");var Y=k(t,P).children.filter((function(e){return S(t,e)||k(t,e).isBranch}));return void d({type:z,ids:Y,lastInteractedWith:v});case"Enter":case" ":case"Spacebar":if(e.preventDefault(),h===le.focus)return;var $=C(t,p.id,n),J=M(t,p.id,n);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:N(t,[v],l),select:!f||!n.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=W(t,v,a);Q!==v;)if(null!=Q){if(k(t,Q).name[0].toLowerCase()===e.key.toLowerCase())return void d({type:X,id:Q,lastInteractedWith:v});Q=W(t,Q,a)}else Q=L(t).children[0];return}}}};oe.propTypes={data:a.array.isRequired,onSelect:a.func,onNodeSelect:a.func,onExpand:a.func,className:a.string,nodeRenderer:a.func.isRequired,defaultExpandedIds:a.array,defaultSelectedIds:a.array,expandedIds:a.array,selectedIds:a.array,defaultDisabledIds:a.array,propagateCollapse:a.bool,propagateSelect:a.bool,propagateSelectUpwards:a.bool,multiSelect:a.bool,expandOnKeyboardSelect:a.bool,togglableSelect:a.bool,nodeAction:a.oneOf(de),clickAction:a.oneOf(re),onBlur:a.func,onLoadData:a.func},exports.CLICK_ACTIONS=re,exports.default=oe,exports.flattenTree=function(e){var t=0,a=[];return function e(n,l){var r,d={id:n.id||t,name:n.name,children:[],parent:l,metadata:n.metadata?Object.assign({},n.metadata):void 0};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=u(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=u(a.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),a}; |
@@ -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()}}},b=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},S=function(e,t){return new Set([].concat(c(b(e,t)),c(b(t,e))))},y=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){var a=R(e,t);return null==a.children?[]:a.children},O=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},A=function(e,t,a){var n=R(e,t);for(F(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},W=function(e,t,a){if(t===F(e).children[0])return null;var n=O(e,t,-1);return null==n?g(e,t):A(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=O(e,n,1);if(null!=l)return l;if(null==(n=g(e,n)))return null}},j=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=W(t,s,a))&&r.push(s),null!=s&&s!==l);)i+=1;return r},T=function(e){var t=0,a=[];return function e(n,l){var r,d={id:n.id||t,name:n.name,children:[],parent:l,metadata:n.metadata?Object.assign({},n.metadata):void 0};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},N=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},C=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)}))))},k=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)}))},M=function(e,t,a){var n=E(e,t);return I(e,t)&&!a.has(t)&&1===n.length&&n.every((function(e){return a.has(e)}))},U=function(e,t,a){var n=E(e,t);return I(e,t)&&a.has(t)&&1===n.length&&n.every((function(e){return a.has(e)}))},F=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},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",ae="CONTROLLED_SELECT_MANY",ne=function(e,t){switch(t.type){case _: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 z: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 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,tabbableId:t.keepFocus?e.tabbableId:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id});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 S,y=new Set(e.selectedIds);return y.delete(t.id),t.multiSelect?(S=new Set(e.halfSelectedIds)).delete(t.id):S=new Set,Object.assign(Object.assign({},e),{selectedIds:y,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 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))):b(e.selectedIds,new Set(E));var O=b(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,W=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){A=t.select?new Set(W):b(e.selectedIds,new Set(W));var x=b(e.halfSelectedIds,A);return Object.assign(Object.assign({},e),{selectedIds:A,halfSelectedIds:x,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled})}return e;case ae:var j,T=e.lastInteractedWith,N=e.tabbableId;if(t.multiSelect)j=new Set(t.ids),t.ids.length&&(T=t.ids[t.ids.length-1],N=t.ids[t.ids.length-1]);else{j=new Set,t.ids.length>1&&console.warn("Tree in singleSelect mode, only the first item from selectedIds will be selected.");var D=t.ids[0];D&&j.add(D),T=null!=D?D:T,N=null!=D?D:T}var C=new Set(e.halfSelectedIds);t.ids.every((function(e){return C.delete(e)}));var k=new Set(t.ids);return Object.assign(Object.assign({},e),{selectedIds:j,halfSelectedIds:C,controlledIds:k,isFocused:!0,lastAction:t.type,tabbableId:N,lastInteractedWith:T});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 L=new Set(e.disabledIds);return L.add(t.id),Object.assign(Object.assign({},e),{disabledIds:L});case ee:var M=new Set(e.disabledIds);return M.delete(t.id),Object.assign(Object.assign({},e),{disabledIds:M});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 n=t.element,l=t.dispatch,r=t.data,d=t.selectedIds,s=t.tabbableId,o=t.isFocused,u=t.expandedIds,f=t.disabledIds,b=t.halfSelectedIds,S=t.lastUserSelect,y=t.nodeRefs,g=t.leafRefs,m=t.baseClassNames,E=t.nodeRenderer,O=t.nodeAction,A=t.setsize,W=t.posinset,x=t.level,T=t.propagateCollapse,k=t.propagateSelect,M=t.multiSelect,F=t.togglableSelect,R=t.clickAction,B=t.state,_=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(u.has(n.id)&&T){var t=[n.id].concat(c(w(r,n.id,new Set)));l({type:z,ids:t,lastInteractedWith:n.id})}else l({type:Y,id:n.id,lastInteractedWith:n.id})},K=function(){return l({type:J,id:n.id,lastInteractedWith:n.id})},H=function(e){if(e.shiftKey){var t=j({data:r,expandedIds:u,from:S,to:n.id}).filter((function(e){return!f.has(e)}));t=k?C(r,t,f):t,l({type:$,select:!0,multiSelect:M,ids:t,lastInteractedWith:n.id,lastManuallyToggled:n.id})}else if(e.ctrlKey||R===re.select){var a=L(r,n.id,d),i=U(r,n.id,d);l({type:F?a&&!i?P:q:G,id:n.id,multiSelect:M,lastInteractedWith:n.id,lastManuallyToggled:n.id}),k&&!f.has(n.id)&&l({type:X,ids:C(r,[n.id],f),select:!F||!d.has(n.id),multiSelect:M,lastInteractedWith:n.id,lastManuallyToggled:n.id})}else R===re.exclusiveSelect?l({type:F?q:G,id:n.id,multiSelect:!1,lastInteractedWith:n.id,lastManuallyToggled:n.id}):R===re.focus&&l({type:J,id:n.id,lastInteractedWith:n.id})},V=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":N({isSelected:d.has(n.id),isDisabled:f.has(n.id),multiSelect:M})}:{"aria-checked":D({isSelected:d.has(n.id),isDisabled:f.has(n.id),isHalfSelected:b.has(n.id),multiSelect:M})};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":W,"aria-level":x,"aria-disabled":f.has(n.id),tabIndex:s===n.id?0:-1,ref:function(e){null!=(null==y?void 0:y.current)&&null!=e&&(y.current[n.id]=e)},className:m.branchWrapper},Q),a.createElement(a.Fragment,null,E({element:n,isBranch:!0,isSelected:d.has(n.id),isHalfSelected:b.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(H,_,K):v(a,K),className:e(V(m.node),m.branch),ref:function(e){null!=(null==g?void 0:g.current)&&(g.current[n.id]=e)}}},setsize:A,posinset:W,level:x,handleSelect:H,handleExpand:_,treeState:B}),a.createElement(ce,Object.assign({getClasses:V},function(e){e.setsize,e.posinset;return h(e,["setsize","posinset"])}(t))))):a.createElement("li",{role:"none",className:V(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?H:a,K),ref:function(e){null!=(null==y?void 0:y.current)&&null!=(null==g?void 0:g.current)&&(y.current[n.id]=e,g.current[n.id]=e)},className:e(V(m.node),m.leaf),"aria-setsize":A,"aria-posinset":W,"aria-level":x,disabled:f.has(n.id),"aria-disabled":f.has(n.id)},Q)},setsize:A,posinset:W,level:x,handleSelect:H,handleExpand:p,treeState:B}))},ce=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(se,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))})))},oe=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,W=e.onLoadData,x=e.togglableSelect,j=e.multiSelect,T=e.propagateSelect,N=e.propagateSelectUpwards,D=F(t),k=s(r(ne,{selectedIds:new Set(a||o),controlledIds:new Set(a),tabbableId:D.children[0],isFocused:!1,expandedIds:new Set(d||i),halfSelectedIds:new Set,lastUserSelect:D.children[0],lastInteractedWith:null,lastManuallyToggled:null,disabledIds:new Set(u)}),2),L=k[0],U=k[1],B=L.selectedIds,q=L.controlledIds,$=L.expandedIds,Q=L.disabledIds,Z=L.tabbableId,ee=L.halfSelectedIds,le=L.lastAction,re=L.lastInteractedWith,de=L.lastManuallyToggled,ie=y(B)||new Set,se=S(B,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&&$.has(l),isSelected:B.has(l),isDisabled:Q.has(l),isHalfSelected:!!r&&ee.has(l),treeState:L})}}catch(e){n.e(e)}finally{n.f()}}}),[t,B,$,Q,ee,se,E,L]),l((function(){null!=O&&O!==p&&null!=de&&se.size&&(O({element:R(t,de),isSelected:B.has(de),isBranch:I(t,de),treeState:L}),U({type:te}))}),[de,B,se]);var ce=y($)||new Set;l((function(){var e=S($,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:$.has(l),isSelected:B.has(l),isDisabled:Q.has(l),isHalfSelected:ee.has(l),treeState:L})}}catch(e){n.e(e)}finally{n.f()}}}),[t,B,$,Q,ee,ce,A,L]);var oe,ue,fe=(oe=t,ue=n(),l((function(){ue.current=oe})),ue.current||new Map);l((function(){var e=S($,ce);if(W){var a,n=f(e);try{for(n.s();!(a=n.n()).done;){var l=a.value;W({element:R(t,l),isExpanded:$.has(l),isSelected:B.has(l),isDisabled:Q.has(l),isHalfSelected:ee.has(l),treeState:L})}}catch(e){n.e(e)}finally{n.f()}if(fe!==t&&x&&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,W,L]);var he=S(new Set(a),q);return l((function(){if(a){he.size&&U({type:ae,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)&&U({type:X,ids:C(t,[l],Q),select:!0,multiSelect:j,lastInteractedWith:l})}}catch(e){n.e(e)}finally{n.f()}}}),[a]),l((function(){var e=new Set(d),a=b(e,ce),n=b(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)));U({type:z,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);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(N){var e=new Set([].concat(c(se),c(q)));re&&le!==J&&le!==_&&le!==K&&le!==Y&&e.add(re);var a=[];e.forEach((function(e){t.find((function(t){return t.id===e}))||a.push(e)})),a.forEach((function(t){return e.delete(t)}));var n,l=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,B,Q,ee,j),r=l.every,d=l.some,i=l.none,s=f(r);try{for(s.s();!(n=s.n()).done;){var o=n.value;B.has(o)||U({type:G,id:o,multiSelect:j||M(t,o,B),keepFocus:!0,NotUserAction:!0,lastInteractedWith:re})}}catch(e){s.e(e)}finally{s.f()}var u,h=f(d);try{for(h.s();!(u=h.n()).done;){var p=u.value;ee.has(p)||U({type:P,id:p,lastInteractedWith:re,keepFocus:!0,NotUserAction:!0})}}catch(e){h.e(e)}finally{h.f()}var v,b=f(i);try{for(b.s();!(v=b.n()).done;){var S=v.value;(B.has(S)||ee.has(S))&&U({type:V,id:S,multiSelect:j,keepFocus:!0,NotUserAction:!0,lastInteractedWith:re,lastManuallyToggled:de})}}catch(e){b.e(e)}finally{b.f()}}}),[t,j,N,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]),[L,U]},ue=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,b=t.onExpand,S=void 0===b?p:b,y=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,W=void 0!==A&&A,x=t.propagateCollapse,j=void 0!==x&&x,T=t.expandOnKeyboardSelect,N=void 0!==T&&T,D=t.togglableSelect,C=void 0!==D&&D,L=t.defaultExpandedIds,M=void 0===L?[]:L,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 $=n({}),J=n({}),Z=s(oe({data:r,controlledSelectedIds:i,controlledExpandedIds:Y,defaultExpandedIds:M,defaultSelectedIds:_,defaultDisabledIds:K,nodeRefs:$,leafRefs:J,onSelect:u,onNodeSelect:v,onExpand:S,onLoadData:y,togglableSelect:C,multiSelect:w,propagateSelect:O,propagateSelectUpwards:W}),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(le.root,g),role:"tree","aria-multiselectable":"select"===V?w:void 0,ref:ae,onBlur:function(e){k(e,ae.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:N,togglableSelect:C})},X),F(r).children.map((function(e,t){return a.createElement(se,Object.assign({key:"".concat(e,"-").concat(d(e)),data:r,element:R(r,e),setsize:F(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:W,multiSelect:w,togglableSelect:C,clickAction:P,nodeAction:V}))})))})),fe=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 b=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(n).filter((function(e){return!l.has(e)})).length!==b.length,ids:b,lastInteractedWith:p.id})}else if(e.shiftKey&&("Home"===e.key||"End"===e.key)){var S="Home"===e.key?F(t).children[0]:A(t,v,a),y=j({data:t,expandedIds:a,from:v,to:S}).filter((function(e){return!l.has(e)}));d({type:X,multiSelect:o,select:!0,ids:s?C(t,y,l):y}),d({type:J,id:S,lastInteractedWith:S})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var m=W(t,v,a);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=x(t,v,a);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=x(t,v,a);return void(null!=O&&d({type:J,id:O,lastInteractedWith:O}));case"ArrowUp":e.preventDefault();var T=W(t,v,a);return void(null!=T&&d({type:J,id:T,lastInteractedWith:T}));case"ArrowLeft":if(e.preventDefault(),(I(t,v)||p.isBranch)&&a.has(r))if(i){var N=[v].concat(c(w(t,v,new Set)));d({type:z,ids:N,lastInteractedWith:p.id})}else d({type:_,id:v,lastInteractedWith:v});else if(!F(t).children.includes(v)){var D=g(t,v);if(null==D)throw new Error("parentId of root element is null");d({type:J,id:D,lastInteractedWith:D})}return;case"ArrowRight":return e.preventDefault(),void((I(t,v)||p.isBranch)&&(a.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:F(t).children[0],lastInteractedWith:F(t).children[0]});break;case"End":e.preventDefault();var k=A(t,F(t).id,a);return void d({type:J,id:k,lastInteractedWith:k});case"*":e.preventDefault();var M=g(t,v);if(null==M)throw new Error("parentId of element is null");var B=R(t,M).children.filter((function(e){return I(t,e)||R(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=L(t,p.id,n),$=U(t,p.id,n);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||!n.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=x(t,v,a);Q!==v;)if(null!=Q){if(R(t,Q).name[0].toLowerCase()===e.key.toLowerCase())return void d({type:J,id:Q,lastInteractedWith:v});Q=x(t,Q,a)}else Q=F(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}; | ||
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()}}},b=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},S=function(e,t){return new Set([].concat(c(b(e,t)),c(b(t,e))))},I=function(e){var t=n();return l((function(){t.current=e}),[e]),t.current},y=function(e,t){var a;return!!(null===(a=F(e,t).children)||void 0===a?void 0:a.length)},g=function(e,t){return F(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=F(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){var a=F(e,t);return null==a.children?[]:a.children},A=function(e,t,a){var n=g(e,t);if(null!=n){var l=F(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=F(e,t);for(_(e).id===t&&(n=F(e,F(e,t).children[F(e,t).children.length-1]));a.has(n.id)&&y(e,n.id);)n=F(e,n.children[n.children.length-1]);return n.id},W=function(e,t,a){if(t===_(e).children[0])return null;var n=A(e,t,-1);return null==n?g(e,t):O(e,n,a)},x=function(e,t,a){var n=F(e,t).id;if(y(e,n)&&a.has(n))return F(e,n).children[0];for(;;){var l=A(e,n,1);if(null!=l)return l;if(null==(n=g(e,n)))return null}},T=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=W(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,metadata:n.metadata?Object.assign({},n.metadata):void 0};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},N=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},C=function(e,t,a){return t.concat.apply(t,c(t.filter((function(t){return y(e,t)})).map((function(t){return w(e,t,a)}))))},U=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>")},M=function(e,t,a){return y(e,t)&&a.has(t)&&w(e,t,new Set).some((function(e){return a.has(e)}))},k=function(e,t,a){var n=E(e,t);return y(e,t)&&!a.has(t)&&1===n.length&&n.every((function(e){return a.has(e)}))},L=function(e,t,a){var n=E(e,t);return y(e,t)&&a.has(t)&&1===n.length&&n.every((function(e){return a.has(e)}))},_=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 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},R=function(e){var t=Array.from(new Set(e));return e.length!==t.length},B="COLLAPSE",z="COLLAPSE_MANY",H="EXPAND",K="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",ae="CONTROLLED_SELECT_MANY",ne="UPDATE_TREE_STATE_WHEN_DATA_CHANGED",le=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 z: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 H: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 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,tabbableId:t.keepFocus?e.tabbableId:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id});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!==t.NotUserAction,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 S,I=new Set(e.selectedIds);return I.delete(t.id),t.multiSelect?(S=new Set(e.halfSelectedIds)).delete(t.id):S=new Set,Object.assign(Object.assign({},e),{selectedIds:I,halfSelectedIds:S,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled});case q:if(e.disabledIds.has(t.id))return e;var y,g=e.selectedIds.has(t.id);t.multiSelect?(y=new Set(e.selectedIds),g?y.delete(t.id):y.add(t.id)):(y=new Set,g||y.add(t.id));var m=new Set(e.halfSelectedIds);return m.delete(t.id),Object.assign(Object.assign({},e),{selectedIds:y,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))):b(e.selectedIds,new Set(E));var A=b(e.halfSelectedIds,w);return Object.assign(Object.assign({},e),{selectedIds:w,halfSelectedIds:A,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled})}return e;case $:var O,W=t.ids.filter((function(t){return!e.disabledIds.has(t)}));if(t.multiSelect){O=t.select?new Set(W):b(e.selectedIds,new Set(W));var x=b(e.halfSelectedIds,O);return Object.assign(Object.assign({},e),{selectedIds:O,halfSelectedIds:x,lastAction:t.type,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled})}return e;case ae:var T,j=e.lastInteractedWith,N=e.tabbableId;if(t.multiSelect)T=new Set(t.ids),t.ids.length&&(j=t.ids[t.ids.length-1],N=t.ids[t.ids.length-1]);else{T=new Set,t.ids.length>1&&console.warn("Tree in singleSelect mode, only the first item from selectedIds will be selected.");var D=t.ids[0];D&&T.add(D),j=null!=D?D:j,N=null!=D?D:j}var C=new Set(e.halfSelectedIds);t.ids.every((function(e){return C.delete(e)}));var U=new Set(t.ids);return Object.assign(Object.assign({},e),{selectedIds:T,halfSelectedIds:C,controlledIds:U,isFocused:!0,lastAction:t.type,tabbableId:N,lastInteractedWith:j});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 M=new Set(e.disabledIds);return M.add(t.id),Object.assign(Object.assign({},e),{disabledIds:M});case ee:var k=new Set(e.disabledIds);return k.delete(t.id),Object.assign(Object.assign({},e),{disabledIds:k});case te:return Object.assign(Object.assign({},e),{lastManuallyToggled:null});case ne:return Object.assign(Object.assign({},e),{tabbableId:t.tabbableId,lastInteractedWith:t.lastInteractedWith,lastManuallyToggled:t.lastManuallyToggled,lastUserSelect:t.lastUserSelect});default:throw new Error("Invalid action passed to the reducer")}},re={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"},de={select:"SELECT",focus:"FOCUS",exclusiveSelect:"EXCLUSIVE_SELECT"},ie=Object.freeze(Object.values(de)),se=Object.freeze(Object.values({check:"check",select:"select"})),ce=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,b=t.halfSelectedIds,S=t.lastUserSelect,I=t.nodeRefs,g=t.leafRefs,m=t.baseClassNames,E=t.nodeRenderer,A=t.nodeAction,O=t.setsize,W=t.posinset,x=t.level,j=t.propagateCollapse,U=t.propagateSelect,k=t.multiSelect,_=t.togglableSelect,F=t.clickAction,R=t.state,B=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(u.has(n.id)&&j){var t=[n.id].concat(c(w(r,n.id,new Set)));l({type:z,ids:t,lastInteractedWith:n.id})}else l({type:Y,id:n.id,lastInteractedWith:n.id})},H=function(){return l({type:J,id:n.id,lastInteractedWith:n.id})},K=function(e){if(e.shiftKey){var t=T({data:r,expandedIds:u,from:S,to:n.id}).filter((function(e){return!f.has(e)}));t=U?C(r,t,f):t,l({type:$,select:!0,multiSelect:k,ids:t,lastInteractedWith:n.id,lastManuallyToggled:n.id})}else if(e.ctrlKey||F===de.select){var a=M(r,n.id,d),i=L(r,n.id,d);l({type:_?a&&!i?P:q:G,id:n.id,multiSelect:k,lastInteractedWith:n.id,lastManuallyToggled:n.id}),U&&!f.has(n.id)&&l({type:X,ids:C(r,[n.id],f),select:!_||!d.has(n.id),multiSelect:k,lastInteractedWith:n.id,lastManuallyToggled:n.id})}else F===de.exclusiveSelect?l({type:_?q:G,id:n.id,multiSelect:!1,lastInteractedWith:n.id,lastManuallyToggled:n.id}):F===de.focus&&l({type:J,id:n.id,lastInteractedWith:n.id})},V=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"===A?{"aria-selected":N({isSelected:d.has(n.id),isDisabled:f.has(n.id),multiSelect:k})}:{"aria-checked":D({isSelected:d.has(n.id),isDisabled:f.has(n.id),isHalfSelected:b.has(n.id),multiSelect:k})};return y(r,n.id)||n.isBranch?a.createElement("li",Object.assign({role:"treeitem","aria-expanded":u.has(n.id),"aria-setsize":O,"aria-posinset":W,"aria-level":x,"aria-disabled":f.has(n.id),tabIndex:s===n.id?0:-1,ref:function(e){null!=(null==I?void 0:I.current)&&null!=e&&(I.current[n.id]=e)},className:m.branchWrapper},Q),a.createElement(a.Fragment,null,E({element:n,isBranch:!0,isSelected:d.has(n.id),isHalfSelected:b.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(K,B,H):v(a,H),className:e(V(m.node),m.branch),ref:function(e){null!=(null==g?void 0:g.current)&&(g.current[n.id]=e)}}},setsize:O,posinset:W,level:x,handleSelect:K,handleExpand:B,treeState:R}),a.createElement(oe,Object.assign({getClasses:V},function(e){e.setsize,e.posinset;return h(e,["setsize","posinset"])}(t))))):a.createElement("li",{role:"none",className:V(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?K:a,H),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:e(V(m.node),m.leaf),"aria-setsize":O,"aria-posinset":W,"aria-level":x,disabled:f.has(n.id),"aria-disabled":f.has(n.id)},Q)},setsize:O,posinset:W,level:x,handleSelect:K,handleExpand:p,treeState:R}))},oe=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(ce,Object.assign({data:t,expandedIds:l,baseClassNames:i,key:"".concat(e,"-").concat(d(e)),element:F(t,e),setsize:n.children.length,posinset:r+1,level:s+1},c))})))},ue=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,A=e.onNodeSelect,O=e.onExpand,W=e.onLoadData,x=e.togglableSelect,T=e.multiSelect,j=e.propagateSelect,N=e.propagateSelectUpwards,D=_(t),U=s(r(le,{selectedIds:new Set(a||o),controlledIds:new Set(a),tabbableId:D.children[0],isFocused:!1,expandedIds:new Set(d||i),halfSelectedIds:new Set,lastUserSelect:D.children[0],lastInteractedWith:null,lastManuallyToggled:null,disabledIds:new Set(u)}),2),M=U[0],L=U[1],R=M.selectedIds,q=M.controlledIds,$=M.expandedIds,Q=M.disabledIds,Z=M.tabbableId,ee=M.halfSelectedIds,re=M.lastAction,de=M.lastInteractedWith,ie=M.lastManuallyToggled,se=I(R)||new Set,ce=S(R,se);l((function(){var e;if(null!=E&&E!==p){var a,n=f(ce);try{for(n.s();!(a=n.n()).done;){var l=a.value,r=y(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:R.has(l),isDisabled:Q.has(l),isHalfSelected:!!r&&ee.has(l),treeState:M})}}catch(e){n.e(e)}finally{n.f()}}}),[t,R,$,Q,ee,ce,E,M]),l((function(){null!=A&&A!==p&&null!=ie&&ce.size&&(A({element:F(t,ie),isSelected:R.has(ie),isBranch:y(t,ie),treeState:M}),L({type:te}))}),[ie,R,ce]);var oe=I($)||new Set;l((function(){var e=S($,oe);if(null!=O&&O!==p){var a,n=f(e);try{for(n.s();!(a=n.n()).done;){var l=a.value;O({element:F(t,l),isExpanded:$.has(l),isSelected:R.has(l),isDisabled:Q.has(l),isHalfSelected:ee.has(l),treeState:M})}}catch(e){n.e(e)}finally{n.f()}}}),[t,R,$,Q,ee,oe,O,M]);var ue,fe,he=(ue=t,fe=n(),l((function(){fe.current=ue})),fe.current||new Map);l((function(){var e=S($,oe);if(W){var a,n=f(e);try{for(n.s();!(a=n.n()).done;){var l=a.value;W({element:F(t,l),isExpanded:$.has(l),isSelected:R.has(l),isDisabled:Q.has(l),isHalfSelected:ee.has(l),treeState:M})}}catch(e){n.e(e)}finally{n.f()}if(he!==t&&x&&j){var r,d=f($);try{for(d.s();!(r=d.n()).done;){var i=r.value;R.has(i)&&L({type:X,ids:C(t,[i],Q),select:!0,multiSelect:T,lastInteractedWith:i})}}catch(e){d.e(e)}finally{d.f()}}}}),[t,R,$,Q,ee,oe,W,M]),l((function(){if(he!==t){var e=_(t);e.children.length&&L({type:ne,tabbableId:t.find((function(e){return e.id===M.tabbableId}))?M.tabbableId:e.children[0],lastInteractedWith:t.find((function(e){return e.id===M.lastInteractedWith}))?M.lastInteractedWith:null,lastManuallyToggled:t.find((function(e){return e.id===M.lastManuallyToggled}))?M.lastManuallyToggled:null,lastUserSelect:t.find((function(e){return e.id===M.lastUserSelect}))?M.lastUserSelect:e.children[0]})}}),[t]);var pe=S(new Set(a),q);return l((function(){if(a){pe.size&&L({type:ae,ids:a,multiSelect:T});var e,n=f(a);try{for(n.s();!(e=n.n()).done;){var l=e.value;j&&!Q.has(l)&&L({type:X,ids:C(t,[l],Q),select:!0,multiSelect:T,lastInteractedWith:l})}}catch(e){n.e(e)}finally{n.f()}}}),[a]),l((function(){var e=new Set(d),a=b(e,oe),n=b(oe,e);if(n.size){var l,r=f(n);try{for(r.s();!(l=r.n()).done;){var i=l.value;if(y(t,i)||F(t,i).isBranch){var s=[i].concat(c(w(t,i,new Set)));L({type:z,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(y(t,h)||F(t,h).isBranch){var p=g(t,h);L(p?{type:K,ids:[h,p],lastInteractedWith:h}:{type:H,id:h,lastInteractedWith:h})}}}catch(e){u.e(e)}finally{u.f()}}}),[d]),l((function(){if(N){var e=new Set([].concat(c(ce),c(q)));de&&re!==J&&re!==B&&re!==H&&re!==Y&&e.add(de);var a=[];e.forEach((function(e){t.find((function(t){return t.id===e}))||a.push(e)})),a.forEach((function(t){return e.delete(t)}));var n,l=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=F(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,R,Q,ee,T),r=l.every,d=l.some,i=l.none,s=f(r);try{for(s.s();!(n=s.n()).done;){var o=n.value;R.has(o)||L({type:G,id:o,multiSelect:T||k(t,o,R),keepFocus:!0,NotUserAction:!0,lastInteractedWith:de})}}catch(e){s.e(e)}finally{s.f()}var u,h=f(d);try{for(h.s();!(u=h.n()).done;){var p=u.value;ee.has(p)||L({type:P,id:p,lastInteractedWith:de,keepFocus:!0,NotUserAction:!0})}}catch(e){h.e(e)}finally{h.f()}var v,b=f(i);try{for(b.s();!(v=b.n()).done;){var S=v.value;(R.has(S)||ee.has(S))&&L({type:V,id:S,multiSelect:T,keepFocus:!0,NotUserAction:!0,lastInteractedWith:de,lastManuallyToggled:ie})}}catch(e){b.e(e)}finally{b.f()}}}),[t,T,N,R,$,Q,ee,re,se,ce,de,pe]),l((function(){if(null!=de&&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[de]),function(e){null!=e&&e.focus&&e.focus({preventScroll:!0})}(e)}}),[Z,h,v,de]),[M,L]},fe=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,b=t.onExpand,S=void 0===b?p:b,I=t.onLoadData,y=t.className,g=void 0===y?"":y,m=t.multiSelect,w=void 0!==m&&m,E=t.propagateSelect,A=void 0!==E&&E,O=t.propagateSelectUpwards,W=void 0!==O&&O,x=t.propagateCollapse,T=void 0!==x&&x,j=t.expandOnKeyboardSelect,N=void 0!==j&&j,D=t.togglableSelect,C=void 0!==D&&D,M=t.defaultExpandedIds,k=void 0===M?[]:M,L=t.defaultSelectedIds,B=void 0===L?[]:L,z=t.defaultDisabledIds,H=void 0===z?[]:z,K=t.clickAction,P=void 0===K?de.select:K,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(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."))})),0===e.filter((function(e){return null===e.parent})).length)throw Error("TreeView must have one root node.");if(e.filter((function(e){return null===e.parent})).length>1)throw Error("TreeView can have only one root node.");_(e).children.length||console.warn("TreeView have no nodes to display.")}(r);var $=n({}),J=n({}),Z=s(ue({data:r,controlledSelectedIds:i,controlledExpandedIds:Y,defaultExpandedIds:k,defaultSelectedIds:B,defaultDisabledIds:H,nodeRefs:$,leafRefs:J,onSelect:u,onNodeSelect:v,onExpand:S,onLoadData:I,togglableSelect:C,multiSelect:w,propagateSelect:A,propagateSelectUpwards:W}),2),ee=Z[0],te=Z[1];A=A&&w;var ae=n(null);return null!=l&&(ae=l),a.createElement("ul",Object.assign({className:e(re.root,g),role:"tree","aria-multiselectable":"select"===V?w:void 0,ref:ae,onBlur:function(e){U(e,ae.current,(function(){q&&q({treeState:ee,dispatch:te}),te({type:Q})}))},onKeyDown:he({data:r,tabbableId:ee.tabbableId,expandedIds:ee.expandedIds,selectedIds:ee.selectedIds,disabledIds:ee.disabledIds,halfSelectedIds:ee.halfSelectedIds,clickAction:P,dispatch:te,propagateCollapse:T,propagateSelect:A,multiSelect:w,expandOnKeyboardSelect:N,togglableSelect:C})},X),_(r).children.map((function(e,t){return a.createElement(ce,Object.assign({key:"".concat(e,"-").concat(d(e)),data:r,element:F(r,e),setsize:_(r).children.length,posinset:t+1,level:1},ee,{state:ee,dispatch:te,nodeRefs:$,leafRefs:J,baseClassNames:re,nodeRenderer:c,propagateCollapse:T,propagateSelect:A,propagateSelectUpwards:W,multiSelect:w,togglableSelect:C,clickAction:P,nodeAction:V}))})))})),he=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=F(t,r),v=p.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();var b=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(n).filter((function(e){return!l.has(e)})).length!==b.length,ids:b,lastInteractedWith:p.id})}else if(e.shiftKey&&("Home"===e.key||"End"===e.key)){var S="Home"===e.key?_(t).children[0]:O(t,v,a),I=T({data:t,expandedIds:a,from:v,to:S}).filter((function(e){return!l.has(e)}));d({type:X,multiSelect:o,select:!0,ids:s?C(t,I,l):I}),d({type:J,id:S,lastInteractedWith:S})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var m=W(t,v,a);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=x(t,v,a);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 A=x(t,v,a);return void(null!=A&&d({type:J,id:A,lastInteractedWith:A}));case"ArrowUp":e.preventDefault();var j=W(t,v,a);return void(null!=j&&d({type:J,id:j,lastInteractedWith:j}));case"ArrowLeft":if(e.preventDefault(),(y(t,v)||p.isBranch)&&a.has(r))if(i){var N=[v].concat(c(w(t,v,new Set)));d({type:z,ids:N,lastInteractedWith:p.id})}else d({type:B,id:v,lastInteractedWith:v});else if(!_(t).children.includes(v)){var D=g(t,v);if(null==D)throw new Error("parentId of root element is null");d({type:J,id:D,lastInteractedWith:D})}return;case"ArrowRight":return e.preventDefault(),void((y(t,v)||p.isBranch)&&(a.has(r)?d({type:J,id:p.children[0],lastInteractedWith:p.children[0]}):d({type:H,id:v,lastInteractedWith:v})));case"Home":e.preventDefault(),d({type:J,id:_(t).children[0],lastInteractedWith:_(t).children[0]});break;case"End":e.preventDefault();var U=O(t,_(t).id,a);return void d({type:J,id:U,lastInteractedWith:U});case"*":e.preventDefault();var k=g(t,v);if(null==k)throw new Error("parentId of element is null");var R=F(t,k).children.filter((function(e){return y(t,e)||F(t,e).isBranch}));return void d({type:K,ids:R,lastInteractedWith:v});case"Enter":case" ":case"Spacebar":if(e.preventDefault(),h===de.focus)return;var V=M(t,p.id,n),$=L(t,p.id,n);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||!n.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=x(t,v,a);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=x(t,Q,a)}else Q=_(t).children[0];return}}}};fe.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(se),clickAction:t.oneOf(ie),onBlur:t.func,onLoadData:t.func};export default fe;export{ie as CLICK_ACTIONS,j as flattenTree}; |
@@ -20,2 +20,3 @@ import { NodeId } from "./types"; | ||
readonly controlledSelectMany: "CONTROLLED_SELECT_MANY"; | ||
readonly updateTreeStateWhenDataChanged: "UPDATE_TREE_STATE_WHEN_DATA_CHANGED"; | ||
}; | ||
@@ -106,2 +107,8 @@ export type TreeViewAction = { | ||
multiSelect?: boolean; | ||
} | { | ||
type: "UPDATE_TREE_STATE_WHEN_DATA_CHANGED"; | ||
tabbableId: NodeId; | ||
lastInteractedWith?: NodeId | null; | ||
lastManuallyToggled?: NodeId | null; | ||
lastUserSelect: NodeId; | ||
}; | ||
@@ -108,0 +115,0 @@ export interface ITreeViewState { |
@@ -60,3 +60,12 @@ import { EventCallback, INode, INodeRef, NodeId } from "./types"; | ||
export declare const getTreeNode: (data: INode[], id: NodeId) => INode; | ||
/** | ||
* We need to validate a tree data for | ||
* - duplicates | ||
* - node references to itself | ||
* - node has duplicated children | ||
* - no root node in a tree | ||
* - more then one root node in a tree | ||
* - to have nodes to display | ||
* */ | ||
export declare const validateTreeViewData: (data: INode[]) => void; | ||
export {}; |
{ | ||
"name": "react-accessible-treeview", | ||
"description": "A react component that implements the treeview pattern as described by the WAI-ARIA Authoring Practices.", | ||
"version": "2.6.2", | ||
"version": "2.6.3", | ||
"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
99027
707