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

react-accessible-treeview

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-accessible-treeview - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

src/index.js

2

dist/react-accessible-treeview.cjs.js

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

"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),React__default=_interopDefault(React),cx=_interopDefault(require("classnames")),PropTypes=_interopDefault(require("prop-types"));function _defineProperty(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(e[r]=a[r])}return e}).apply(this,arguments)}function ownKeys(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),a.push.apply(a,r)}return a}function _objectSpread2(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(a,!0).forEach(function(t){_defineProperty(e,t,a[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):ownKeys(a).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))})}return e}function _objectWithoutPropertiesLoose(e,t){if(null==e)return{};var a,r,n={},l=Object.keys(e);for(r=0;r<l.length;r++)a=l[r],t.indexOf(a)>=0||(n[a]=e[a]);return n}function _objectWithoutProperties(e,t){if(null==e)return{};var a,r,n=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r<l.length;r++)a=l[r],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_nonIterableRest()}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,a=new Array(e.length);t<e.length;t++)a[t]=e[t];return a}}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function _iterableToArrayLimit(e,t){var a=[],r=!0,n=!1,l=void 0;try{for(var d,s=e[Symbol.iterator]();!(r=(d=s.next()).done)&&(a.push(d.value),!t||a.length!==t);r=!0);}catch(e){n=!0,l=e}finally{try{r||null==s.return||s.return()}finally{if(n)throw l}}return a}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}var composeHandlers=function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return function(e){for(var a=0,r=t;a<r.length;a++){var n=r[a];if(n&&n(e),e.defaultPrevented)break}}},difference=function(e,t){var a=new Set,r=!0,n=!1,l=void 0;try{for(var d,s=e[Symbol.iterator]();!(r=(d=s.next()).done);r=!0){var i=d.value;t.has(i)||a.add(i)}}catch(e){n=!0,l=e}finally{try{r||null==s.return||s.return()}finally{if(n)throw l}}return a},symmetricDifference=function(e,t){return new Set([].concat(_toConsumableArray(difference(e,t)),_toConsumableArray(difference(t,e))))},usePrevious=function(e){var t=React.useRef();return React.useEffect(function(){t.current=e},[e]),t.current},isBranchNode=function(e,t){return null!=e[t].children&&e[t].children.length>0},focusRef=function(e){null!=e&&e.focus&&e.focus()},getParent=function(e,t){return e[t].parent},getDescendants=function(e,t,a){var r=[];return function e(t,n){var l=t[n];if(null!=l.children){var d=!0,s=!1,i=void 0;try{for(var c,o=l.children.filter(function(e){return!a.has(e)})[Symbol.iterator]();!(d=(c=o.next()).done);d=!0){var u=c.value;r.push(u),e(t,u)}}catch(e){s=!0,i=e}finally{try{d||null==o.return||o.return()}finally{if(s)throw i}}}}(e,t),r},getSibling=function(e,t,a){var r=getParent(e,t);if(null!=r){var n=e[r],l=n.children.indexOf(t)+a;if(n.children[l])return n.children[l]}return null},getLastAccessible=function(e,t,a){var r=e[t];for(e[0].id===t&&(r=e[e[t].children[e[t].children.length-1]]);a.has(r.id)&&isBranchNode(e,r.id);)r=e[r.children[r.children.length-1]];return r.id},getPreviousAccessible=function(e,t,a){if(t===e[0].children[0])return null;var r=getSibling(e,t,-1);return null==r?getParent(e,t):getLastAccessible(e,r,a)},getNextAccessible=function(e,t,a){var r=e[t].id;if(isBranchNode(e,r)&&a.has(r))return e[r].children[0];for(;;){var n=getSibling(e,r,1);if(null!=n)return n;if(null==(r=getParent(e,r)))return null}},propagateSelectChange=function(e,t,a,r){var n={every:new Set,some:new Set,none:new Set},l=!0,d=!1,s=void 0;try{for(var i,c=t[Symbol.iterator]();!(l=(i=c.next()).done);l=!0)for(var o=i.value;;){var u=getParent(e,o);if(0===u||r.has(u))break;var p=e[u].children.filter(function(e){return!r.has(e)});if(0===p.length)break;p.some(function(e){return a.has(e)})?p.every(function(e){return a.has(e)})?n.every.add(u):n.some.add(u):n.none.add(u),o=u}}catch(e){d=!0,s=e}finally{try{l||null==c.return||c.return()}finally{if(d)throw s}}return n},getAccessibleRange=function(e){var t=e.data,a=e.expandedIds,r=e.from,n=e.to,l=[],d=Object.keys(t).length,s=0,i=r;if(l.push(r),r<n)for(;s<d&&(i=getNextAccessible(t,i,a),l.push(i),null!=i&&i!==n);)s+=1;else if(r>n)for(;s<d&&(i=getPreviousAccessible(t,i,a),l.push(i),null!=i&&i!==n);)s+=1;return l},flattenTree=function(e){var t=0,a=[];return function e(r,n){if(r.id=t,r.parent=n,a[t]=r,t+=1,null!=r.children&&0!==r.children.length){var l=!0,d=!1,s=void 0;try{for(var i,c=r.children[Symbol.iterator]();!(l=(i=c.next()).done);l=!0){e(i.value,r.id)}}catch(e){d=!0,s=e}finally{try{l||null==c.return||c.return()}finally{if(d)throw s}}r.children=r.children.map(function(e){return e.id})}}(e,null),a},getAriaSelected=function(e,t){return t?e:!!e||void 0},propagatedIds=function(e,t,a){return t.concat.apply(t,_toConsumableArray(t.filter(function(t){return isBranchNode(e,t)}).map(function(t){return getDescendants(e,t,a)})))},baseClassNames={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"},treeTypes={collapse:"COLLAPSE",collapseMany:"COLLAPSE_MANY",expand:"EXPAND",expandMany:"EXPAND_MANY",halfSelect:"HALF_SELECT",select:"SELECT",deselect:"DESELECT",toggle:"TOGGLE",toggleSelect:"TOGGLE_SELECT",changeSelectMany:"SELECT_MANY",exclusiveSelectMany:"EXCLUSIVE_SELECT_MANY",exclusiveChangeSelectMany:"EXCLUSIVE_CHANGE_SELECT_MANY",focus:"FOCUS",disable:"DISABLE",enable:"ENABLE"},treeReducer=function(e,t){switch(t.type){case treeTypes.collapse:var a=new Set(e.expandedIds);return a.delete(t.id),_objectSpread2({},e,{expandedIds:a,tabbableId:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.collapseMany:var r=new Set(e.expandedIds),n=!0,l=!1,d=void 0;try{for(var s,i=t.ids[Symbol.iterator]();!(n=(s=i.next()).done);n=!0){var c=s.value;r.delete(c)}}catch(e){l=!0,d=e}finally{try{n||null==i.return||i.return()}finally{if(l)throw d}}return _objectSpread2({},e,{expandedIds:r,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.expand:var o=new Set(e.expandedIds);return o.add(t.id),_objectSpread2({},e,{expandedIds:o,tabbableId:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.expandMany:var u=new Set([].concat(_toConsumableArray(e.expandedIds),_toConsumableArray(t.ids)));return _objectSpread2({},e,{expandedIds:u,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.toggle:var p=new Set(e.expandedIds);return e.expandedIds.has(t.id)?p.delete(t.id):p.add(t.id),_objectSpread2({},e,{expandedIds:p,tabbableId:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.halfSelect: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),_objectSpread2({},e,{selectedIds:h,halfSelectedIds:f,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.select:if(e.disabledIds.has(t.id))return e;var y;t.multiSelect?(y=new Set(e.selectedIds)).add(t.id):(y=new Set).add(t.id);var b=new Set(e.halfSelectedIds);return b.delete(t.id),_objectSpread2({},e,{selectedIds:y,halfSelectedIds:b,tabbableId:t.keepFocus?e.tabbableId:t.id,lastStandardSelect:t.NotUserAction?e.lastStandardSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.deselect:if(e.disabledIds.has(t.id))return e;var S;t.multiSelect?(S=new Set(e.selectedIds)).delete(t.id):S=new Set;var I=new Set(e.halfSelectedIds);return I.delete(t.id),_objectSpread2({},e,{selectedIds:S,halfSelectedIds:I,tabbableId:t.keepFocus?e.tabbableId:t.id,lastStandardSelect:t.NotUserAction?e.lastStandardSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.toggleSelect:if(e.disabledIds.has(t.id))return e;var v,g=e.selectedIds.has(t.id);t.multiSelect?(v=new Set(e.selectedIds),g?v.delete(t.id):v.add(t.id)):(v=new Set,g||v.add(t.id));var m=new Set(e.halfSelectedIds);return m.delete(t.id),_objectSpread2({},e,{selectedIds:v,halfSelectedIds:m,tabbableId:t.id,lastStandardSelect:t.NotUserAction?e.lastStandardSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.changeSelectMany:var A,x=t.ids.filter(function(t){return!e.disabledIds.has(t)});if(t.multiSelect){A=t.select?new Set([].concat(_toConsumableArray(e.selectedIds),_toConsumableArray(x))):difference(e.selectedIds,new Set(x));var T=difference(e.halfSelectedIds,A);return _objectSpread2({},e,{selectedIds:A,halfSelectedIds:T,lastAction:t.type,lastInteractedWith:t.lastInteractedWith})}return e;case treeTypes.exclusiveChangeSelectMany:var w,_=t.ids.filter(function(t){return!e.disabledIds.has(t)});if(t.multiSelect){w=t.select?new Set(_):difference(e.selectedIds,new Set(_));var W=difference(e.halfSelectedIds,w);return _objectSpread2({},e,{selectedIds:w,halfSelectedIds:W,lastAction:t.type,lastInteractedWith:t.lastInteractedWith})}return e;case treeTypes.focus:return _objectSpread2({},e,{tabbableId:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.disable:var E=new Set(e.disabledIds);return E.add(t.id),_objectSpread2({},e,{disabledIds:E});case treeTypes.enable:var P=new Set(e.disabledIds);return P.delete(t.id),_objectSpread2({},e,{disabledIds:P});default:throw new Error("Invalid action passed to the reducer")}},useTree=function(e){var t=e.data,a=e.defaultExpandedIds,r=e.defaultSelectedIds,n=e.defaultDisabledIds,l=e.nodeRefs,d=e.onSelect,s=e.onExpand,i=e.multiSelect,c=e.propagateSelectUpwards,o=_slicedToArray(React.useReducer(treeReducer,{selectedIds:new Set(r),tabbableId:t[0].children[0],expandedIds:new Set(a),halfSelectedIds:new Set,lastStandardSelect:t[0].children[0],lastInteractedWith:null,disabledIds:new Set(n)}),2),u=o[0],p=o[1],f=u.selectedIds,h=u.expandedIds,y=u.disabledIds,b=u.tabbableId,S=u.halfSelectedIds,I=u.lastAction,v=u.lastInteractedWith,g=usePrevious(f)||new Set,m=symmetricDifference(f,g);React.useEffect(function(){if(d!==noop){var e=!0,a=!1,r=void 0;try{for(var n,l=m[Symbol.iterator]();!(e=(n=l.next()).done);e=!0){var s=n.value,i=isBranchNode(t,s);d({element:t[s],isBranch:i,isExpanded:i?h.has(s):void 0,selectedIds:f,expandedIds:h,disabledIds:y,tabbableId:b,halfSelectedIds:S})}}catch(e){a=!0,r=e}finally{try{e||null==l.return||l.return()}finally{if(a)throw r}}}},[t,f,h,b,S,m,d,v]);var A=usePrevious(h)||new Set;React.useEffect(function(){var e=difference(h,A);if(s!==noop){var a=!0,r=!1,n=void 0;try{for(var l,d=e[Symbol.iterator]();!(a=(l=d.next()).done);a=!0){var i=l.value;s({element:t[i],isBranch:!0,isExpanded:!0,selectedIds:f,disabledIds:y,expandedIds:h,tabbableId:b,halfSelectedIds:S})}}catch(e){r=!0,n=e}finally{try{a||null==d.return||d.return()}finally{if(r)throw n}}}},[t,f,h,b,S,d,s,A,v]),React.useEffect(function(){if(c&&i){var e=new Set(m);v&&e.add(v);var a=propagateSelectChange(t,e,f,y),r=a.every,n=a.some,l=a.none,d=!0,s=!1,o=void 0;try{for(var u,h=r[Symbol.iterator]();!(d=(u=h.next()).done);d=!0){var b=u.value;f.has(b)||p({type:treeTypes.select,id:b,multiSelect:i,keepFocus:!0,NotUserAction:!0,lastInteractedWith:v})}}catch(e){s=!0,o=e}finally{try{d||null==h.return||h.return()}finally{if(s)throw o}}var I=!0,g=!1,A=void 0;try{for(var x,T=n[Symbol.iterator]();!(I=(x=T.next()).done);I=!0){var w=x.value;S.has(w)||p({type:treeTypes.halfSelect,id:w,multiSelect:i,keepFocus:!0,NotUserAction:!0,lastInteractedWith:v})}}catch(e){g=!0,A=e}finally{try{I||null==T.return||T.return()}finally{if(g)throw A}}var _=!0,W=!1,E=void 0;try{for(var P,C=l[Symbol.iterator]();!(_=(P=C.next()).done);_=!0){var N=P.value;(f.has(N)||S.has(N))&&p({type:treeTypes.deselect,id:N,multiSelect:i,keepFocus:!0,NotUserAction:!0,lastInteractedWith:v})}}catch(e){W=!0,E=e}finally{try{_||null==C.return||C.return()}finally{if(W)throw E}}}},[t,i,c,f,h,y,S,I,g,m,v]);var x=React.useRef(!1);return React.useEffect(function(){if(x.current){if(null!=b){var e=l.current[b];focusRef(e)}}else x.current=!0},[b,l,x]),[u,p]},clickActions={select:"SELECT",focus:"FOCUS",exclusiveSelect:"EXCLUSIVE_SELECT"},noop=function(){},TreeView=React__default.forwardRef(function(e,t){var a=e.data,r=e.nodeRenderer,n=e.onSelect,l=void 0===n?noop:n,d=e.onExpand,s=void 0===d?noop:d,i=e.className,c=void 0===i?"":i,o=e.multiSelect,u=void 0!==o&&o,p=e.propagateSelect,f=void 0!==p&&p,h=e.propagateSelectUpwards,y=void 0!==h&&h,b=e.propagateCollapse,S=void 0!==b&&b,I=e.expandOnKeyboardSelect,v=void 0!==I&&I,g=e.togglableSelect,m=void 0!==g&&g,A=e.defaultExpandedIds,x=void 0===A?[]:A,T=e.defaultSelectedIds,w=void 0===T?[]:T,_=e.defaultDisabledIds,W=void 0===_?[]:_,E=e.clickAction,P=void 0===E?clickActions.select:E,C=_objectWithoutProperties(e,["data","nodeRenderer","onSelect","onExpand","className","multiSelect","propagateSelect","propagateSelectUpwards","propagateCollapse","expandOnKeyboardSelect","togglableSelect","defaultExpandedIds","defaultSelectedIds","defaultDisabledIds","clickAction"]),N=React.useRef({}),R=_slicedToArray(useTree({data:a,defaultExpandedIds:x,defaultSelectedIds:w,defaultDisabledIds:W,nodeRefs:N,onSelect:l,onExpand:s,multiSelect:u,propagateSelect:f,propagateSelectUpwards:y}),2),O=R[0],j=R[1];return f=f&&u,React__default.createElement("ul",_extends({className:cx(baseClassNames.root,c),role:"tree","aria-multiselectable":u,ref:t,onKeyDown:handleKeyDown({data:a,tabbableId:O.tabbableId,expandedIds:O.expandedIds,selectedIds:O.selectedIds,disabledIds:O.disabledIds,halfSelectedIds:O.halfSelectedIds,dispatch:j,propagateCollapse:S,propagateSelect:f,multiSelect:u,expandOnKeyboardSelect:v,togglableSelect:m})},C),a[0].children.map(function(e,t){return React__default.createElement(Node,{key:e,selectedIds:O.selectedIds,tabbableId:O.tabbableId,expandedIds:O.expandedIds,disabledIds:O.disabledIds,halfSelectedIds:O.halfSelectedIds,lastStandardSelect:O.lastStandardSelect,lastInteractedWith:O.lastInteractedWith,dispatch:j,data:a,element:a[e],nodeRefs:N,baseClassNames:baseClassNames,nodeRenderer:r,setsize:a[0].children.length,posinset:t+1,level:1,propagateCollapse:S,propagateSelect:f,multiSelect:u,togglableSelect:m,clickAction:P})}))}),Node=function e(t){var a=t.element,r=t.dispatch,n=t.data,l=t.selectedIds,d=t.tabbableId,s=t.expandedIds,i=t.disabledIds,c=t.halfSelectedIds,o=t.lastStandardSelect,u=t.nodeRefs,p=t.baseClassNames,f=t.nodeRenderer,h=t.setsize,y=t.posinset,b=t.level,S=t.propagateCollapse,I=t.propagateSelect,v=t.multiSelect,g=t.togglableSelect,m=t.clickAction,A=t.lastInteractedWith,x=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(s.has(a.id)&&S){var t=[a.id].concat(_toConsumableArray(getDescendants(n,a.id,[])));r({type:treeTypes.collapseMany,ids:t,lastInteractedWith:a.id})}else r({type:treeTypes.toggle,id:a.id,lastInteractedWith:a.id})},T=function(){r({type:treeTypes.focus,id:a.id,lastInteractedWith:a.id})},w=function(e){if(e.shiftKey){var t=getAccessibleRange({data:n,expandedIds:s,from:o,to:a.id,lastInteractedWith:a.id}).filter(function(e){return!i.has(e)});t=I?propagatedIds(n,t,i):t,r({type:treeTypes.exclusiveChangeSelectMany,select:!0,multiSelect:v,ids:t,lastInteractedWith:a.id})}else e.ctrlKey||m===clickActions.select?(r({type:g?treeTypes.toggleSelect:treeTypes.select,id:a.id,multiSelect:v,lastInteractedWith:a.id}),I&&!i.has(a.id)&&r({type:treeTypes.changeSelectMany,ids:propagatedIds(n,[a.id],i),select:!g||!l.has(a.id),multiSelect:v,lastInteractedWith:a.id})):m===clickActions.exclusiveSelect?r({type:g?treeTypes.toggleSelect:treeTypes.select,id:a.id,multiSelect:!1,lastInteractedWith:a.id}):m===clickActions.focus&&r({type:treeTypes.focus,id:a.id,lastInteractedWith:a.id})},_=function(e){var t;return cx(e,(_defineProperty(t={},"".concat(e,"--expanded"),s.has(a.id)),_defineProperty(t,"".concat(e,"--selected"),l.has(a.id)),t))};return isBranchNode(n,a.id)?React__default.createElement("li",{role:"treeitem","aria-expanded":s.has(a.id),"aria-selected":getAriaSelected(l.has(a.id),v),"aria-setsize":h,"aria-posinset":y,"aria-level":b,tabIndex:d===a.id?0:-1,ref:function(e){return u.current[a.id]=e},className:cx(_(p.node),p.branch)},f({element:a,isBranch:isBranchNode(n,a.id),isSelected:l.has(a.id),isHalfSelected:c.has(a.id),isExpanded:s.has(a.id),isDisabled:i.has(a.id),tabbableId:d,dispatch:r,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onClick;return{onClick:composeHandlers(t,x,T),className:_(p.branchWrapper)}},setsize:h,posinset:y,level:b,handleSelect:w,handleExpand:x}),s.has(a.id)&&React__default.createElement("ul",{role:"group",className:_(p.nodeGroup)},a.children.map(function(t,h){return React__default.createElement(e,{key:t,selectedIds:l,tabbableId:d,expandedIds:s,halfSelectedIds:c,disabledIds:i,lastStandardSelect:o,dispatch:r,data:n,element:n[t],nodeRefs:u,baseClassNames:p,nodeRenderer:f,setsize:a.children.length,posinset:h+1,level:b+1,propagateCollapse:S,propagateSelect:I,multiSelect:v,togglableSelect:g,clickAction:m,lastInteractedWith:A})}))):React__default.createElement("li",{role:"none",className:_(p.leafListItem)},f({element:a,isBranch:isBranchNode(n,a.id),isSelected:l.has(a.id),isHalfSelected:c.has(a.id),isExpanded:s.has(a.id),isDisabled:i.has(a.id),tabbableId:d,dispatch:r,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onClick;return{role:"treeitem",tabIndex:d===a.id?0:-1,onClick:composeHandlers(t,T),ref:function(e){return u.current[a.id]=e},className:cx(_(p.node),p.leaf),"aria-setsize":h,"aria-posinset":y,"aria-level":b,"aria-selected":getAriaSelected(l.has(a.id),v)}},setsize:h,posinset:y,level:b,handleSelect:w,handleExpand:x}))},handleKeyDown=function(e){var t=e.data,a=e.expandedIds,r=e.selectedIds,n=e.disabledIds,l=e.tabbableId,d=e.dispatch,s=e.propagateCollapse,i=e.propagateSelect,c=e.multiSelect,o=e.expandOnKeyboardSelect,u=e.togglableSelect;return function(e){var p=t[l],f=p.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();t[0];var h=_objectWithoutProperties(t,["0"]),y=Object.values(h).map(function(e){return e.id}).filter(function(e){return!n.has(e)});d({type:treeTypes.changeSelectMany,multiSelect:c,select:Array.from(r).filter(function(e){return!n.has(e)}).length!==y.length,ids:y,lastInteractedWith:p.id})}else if(e.shiftKey&&("Home"===e.key||"End"===e.key)){var b="Home"===e.key?t[0].children[0]:getLastAccessible(t,f,a),S=getAccessibleRange({data:t,expandedIds:a,from:f,to:b}).filter(function(e){return!n.has(e)});d({type:treeTypes.changeSelectMany,multiSelect:c,select:!0,ids:i?propagatedIds(t,S,n):S}),d({type:treeTypes.focus,id:b,lastInteractedWith:b})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var I=getPreviousAccessible(t,f,a);return void(null==I&&n.has(I)||(d({type:treeTypes.changeSelectMany,ids:i?propagatedIds(t,[I],n):[I],select:!0,multiSelect:c,lastInteractedWith:I}),d({type:treeTypes.focus,id:I,lastInteractedWith:I})));case"ArrowDown":e.preventDefault();var v=getNextAccessible(t,f,a);return void(null==v&&n.has(v)||(d({type:treeTypes.changeSelectMany,ids:i?propagatedIds(t,[v],n):[v],multiSelect:c,select:!0,lastInteractedWith:v}),d({type:treeTypes.focus,id:v,lastInteractedWith:v})))}switch(e.key){case"ArrowDown":e.preventDefault();var g=getNextAccessible(t,f,a);return void(null!=g&&d({type:treeTypes.focus,id:g,lastInteractedWith:g}));case"ArrowUp":e.preventDefault();var m=getPreviousAccessible(t,f,a);return void(null!=m&&d({type:treeTypes.focus,id:m,lastInteractedWith:m}));case"ArrowLeft":if(e.preventDefault(),isBranchNode(t,f)&&a.has(l))if(s){var A=[f].concat(_toConsumableArray(getDescendants(t,f,[])));d({type:treeTypes.collapseMany,ids:A,lastInteractedWith:p.id})}else d({type:treeTypes.collapse,id:f,lastInteractedWith:f});else if(!t[0].children.includes(f)){var x=getParent(t,f);d({type:treeTypes.focus,id:x,lastInteractedWith:x})}return;case"ArrowRight":return e.preventDefault(),void(isBranchNode(t,f)&&(a.has(l)?d({type:treeTypes.focus,id:p.children[0],lastInteractedWith:p.children[0]}):d({type:treeTypes.expand,id:f,lastInteractedWith:f})));case"Home":e.preventDefault(),d({type:treeTypes.focus,id:t[0].children[0],lastInteractedWith:t[0].children[0]});break;case"End":e.preventDefault();var T=getLastAccessible(t,t[0].id,a);return void d({type:treeTypes.focus,id:T,lastInteractedWith:T});case"*":e.preventDefault();var w=t[getParent(t,f)].children.filter(function(e){return isBranchNode(t,e)});return void d({type:treeTypes.expandMany,ids:w,lastInteractedWith:f});case"Enter":case" ":case"Spacebar":return e.preventDefault(),!n.has(f)&&d({type:treeTypes.changeSelectMany,ids:i?propagatedIds(t,[f],n):[f],select:!u||!r.has(f),multiSelect:c,lastInteractedWith:f}),void(o&&d({type:treeTypes.toggle,id:f,lastInteractedWith:f}));default:if(1===e.key.length)for(var _=getNextAccessible(t,f,a);_!==f;)if(null!=_){if(t[_].name[0].toLowerCase()===e.key.toLowerCase())return void d({type:treeTypes.focus,id:_,lastInteractedWith:f});_=getNextAccessible(t,_,a)}else _=t[0].children[0];return}}}};TreeView.propTypes={data:PropTypes.array.isRequired,onSelect:PropTypes.func,onExpand:PropTypes.func,className:PropTypes.string,nodeRenderer:PropTypes.func.isRequired,defaultExpandedIds:PropTypes.array,defaultSelectedIds:PropTypes.array,defaultDisabledIds:PropTypes.array,propagateCollapse:PropTypes.bool,propagateSelect:PropTypes.bool,propagateSelectUpwards:PropTypes.bool,multiSelect:PropTypes.bool,expandOnKeyboardSelect:PropTypes.bool,togglableSelect:PropTypes.bool,clickAction:PropTypes.oneOf(Object.values(clickActions))},exports.default=TreeView,exports.flattenTree=flattenTree;
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),React__default=_interopDefault(React),cx=_interopDefault(require("classnames")),PropTypes=_interopDefault(require("prop-types"));function _defineProperty(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(e[r]=a[r])}return e}).apply(this,arguments)}function ownKeys(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),a.push.apply(a,r)}return a}function _objectSpread2(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(a,!0).forEach(function(t){_defineProperty(e,t,a[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):ownKeys(a).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))})}return e}function _objectWithoutPropertiesLoose(e,t){if(null==e)return{};var a,r,n={},l=Object.keys(e);for(r=0;r<l.length;r++)a=l[r],t.indexOf(a)>=0||(n[a]=e[a]);return n}function _objectWithoutProperties(e,t){if(null==e)return{};var a,r,n=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r<l.length;r++)a=l[r],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(n[a]=e[a])}return n}function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_nonIterableRest()}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,a=new Array(e.length);t<e.length;t++)a[t]=e[t];return a}}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function _iterableToArrayLimit(e,t){var a=[],r=!0,n=!1,l=void 0;try{for(var d,s=e[Symbol.iterator]();!(r=(d=s.next()).done)&&(a.push(d.value),!t||a.length!==t);r=!0);}catch(e){n=!0,l=e}finally{try{r||null==s.return||s.return()}finally{if(n)throw l}}return a}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}var composeHandlers=function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return function(e){for(var a=0,r=t;a<r.length;a++){var n=r[a];if(n&&n(e),e.defaultPrevented)break}}},difference=function(e,t){var a=new Set,r=!0,n=!1,l=void 0;try{for(var d,s=e[Symbol.iterator]();!(r=(d=s.next()).done);r=!0){var i=d.value;t.has(i)||a.add(i)}}catch(e){n=!0,l=e}finally{try{r||null==s.return||s.return()}finally{if(n)throw l}}return a},symmetricDifference=function(e,t){return new Set([].concat(_toConsumableArray(difference(e,t)),_toConsumableArray(difference(t,e))))},usePrevious=function(e){var t=React.useRef();return React.useEffect(function(){t.current=e},[e]),t.current},isBranchNode=function(e,t){return null!=e[t].children&&e[t].children.length>0},focusRef=function(e){null!=e&&e.focus&&e.focus()},getParent=function(e,t){return e[t].parent},getDescendants=function(e,t,a){var r=[];return function e(t,n){var l=t[n];if(null!=l.children){var d=!0,s=!1,i=void 0;try{for(var c,o=l.children.filter(function(e){return!a.has(e)})[Symbol.iterator]();!(d=(c=o.next()).done);d=!0){var u=c.value;r.push(u),e(t,u)}}catch(e){s=!0,i=e}finally{try{d||null==o.return||o.return()}finally{if(s)throw i}}}}(e,t),r},getSibling=function(e,t,a){var r=getParent(e,t);if(null!=r){var n=e[r],l=n.children.indexOf(t)+a;if(n.children[l])return n.children[l]}return null},getLastAccessible=function(e,t,a){var r=e[t];for(e[0].id===t&&(r=e[e[t].children[e[t].children.length-1]]);a.has(r.id)&&isBranchNode(e,r.id);)r=e[r.children[r.children.length-1]];return r.id},getPreviousAccessible=function(e,t,a){if(t===e[0].children[0])return null;var r=getSibling(e,t,-1);return null==r?getParent(e,t):getLastAccessible(e,r,a)},getNextAccessible=function(e,t,a){var r=e[t].id;if(isBranchNode(e,r)&&a.has(r))return e[r].children[0];for(;;){var n=getSibling(e,r,1);if(null!=n)return n;if(null==(r=getParent(e,r)))return null}},propagateSelectChange=function(e,t,a,r){var n={every:new Set,some:new Set,none:new Set},l=!0,d=!1,s=void 0;try{for(var i,c=t[Symbol.iterator]();!(l=(i=c.next()).done);l=!0)for(var o=i.value;;){var u=getParent(e,o);if(0===u||r.has(u))break;var p=e[u].children.filter(function(e){return!r.has(e)});if(0===p.length)break;p.some(function(e){return a.has(e)})?p.every(function(e){return a.has(e)})?n.every.add(u):n.some.add(u):n.none.add(u),o=u}}catch(e){d=!0,s=e}finally{try{l||null==c.return||c.return()}finally{if(d)throw s}}return n},getAccessibleRange=function(e){var t=e.data,a=e.expandedIds,r=e.from,n=e.to,l=[],d=Object.keys(t).length,s=0,i=r;if(l.push(r),r<n)for(;s<d&&(i=getNextAccessible(t,i,a),l.push(i),null!=i&&i!==n);)s+=1;else if(r>n)for(;s<d&&(i=getPreviousAccessible(t,i,a),l.push(i),null!=i&&i!==n);)s+=1;return l},flattenTree=function(e){var t=0,a=[];return function e(r,n){if(r.id=t,r.parent=n,a[t]=r,t+=1,null!=r.children&&0!==r.children.length){var l=!0,d=!1,s=void 0;try{for(var i,c=r.children[Symbol.iterator]();!(l=(i=c.next()).done);l=!0){e(i.value,r.id)}}catch(e){d=!0,s=e}finally{try{l||null==c.return||c.return()}finally{if(d)throw s}}r.children=r.children.map(function(e){return e.id})}}(e,null),a},getAriaSelected=function(e,t,a){if(!t)return a?e:!!e||void 0},propagatedIds=function(e,t,a){return t.concat.apply(t,_toConsumableArray(t.filter(function(t){return isBranchNode(e,t)}).map(function(t){return getDescendants(e,t,a)})))},isIE=function(){return window.navigator.userAgent.match(/Trident/)},onComponentBlur=function(e,t,a){isIE()?setTimeout(function(){return!t.contains(document.activeElement)&&a()},0):!t.contains(e.nativeEvent.relatedTarget)&&a()},baseClassNames={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"},treeTypes={collapse:"COLLAPSE",collapseMany:"COLLAPSE_MANY",expand:"EXPAND",expandMany:"EXPAND_MANY",halfSelect:"HALF_SELECT",select:"SELECT",deselect:"DESELECT",toggle:"TOGGLE",toggleSelect:"TOGGLE_SELECT",changeSelectMany:"SELECT_MANY",exclusiveSelectMany:"EXCLUSIVE_SELECT_MANY",exclusiveChangeSelectMany:"EXCLUSIVE_CHANGE_SELECT_MANY",focus:"FOCUS",blur:"BLUR",disable:"DISABLE",enable:"ENABLE"},treeReducer=function(e,t){switch(t.type){case treeTypes.collapse:var a=new Set(e.expandedIds);return a.delete(t.id),_objectSpread2({},e,{expandedIds:a,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.collapseMany:var r=new Set(e.expandedIds),n=!0,l=!1,d=void 0;try{for(var s,i=t.ids[Symbol.iterator]();!(n=(s=i.next()).done);n=!0){var c=s.value;r.delete(c)}}catch(e){l=!0,d=e}finally{try{n||null==i.return||i.return()}finally{if(l)throw d}}return _objectSpread2({},e,{expandedIds:r,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.expand:var o=new Set(e.expandedIds);return o.add(t.id),_objectSpread2({},e,{expandedIds:o,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.expandMany:var u=new Set([].concat(_toConsumableArray(e.expandedIds),_toConsumableArray(t.ids)));return _objectSpread2({},e,{expandedIds:u,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.toggle:var p=new Set(e.expandedIds);return e.expandedIds.has(t.id)?p.delete(t.id):p.add(t.id),_objectSpread2({},e,{expandedIds:p,tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.halfSelect: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),_objectSpread2({},e,{selectedIds:h,halfSelectedIds:f,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.select:if(e.disabledIds.has(t.id))return e;var y;t.multiSelect?(y=new Set(e.selectedIds)).add(t.id):(y=new Set).add(t.id);var b=new Set(e.halfSelectedIds);return b.delete(t.id),_objectSpread2({},e,{selectedIds:y,halfSelectedIds:b,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastStandardSelect:t.NotUserAction?e.lastStandardSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.deselect:if(e.disabledIds.has(t.id))return e;var S;t.multiSelect?(S=new Set(e.selectedIds)).delete(t.id):S=new Set;var I=new Set(e.halfSelectedIds);return I.delete(t.id),_objectSpread2({},e,{selectedIds:S,halfSelectedIds:I,tabbableId:t.keepFocus?e.tabbableId:t.id,isFocused:!0,lastStandardSelect:t.NotUserAction?e.lastStandardSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.toggleSelect:if(e.disabledIds.has(t.id))return e;var v,g=e.selectedIds.has(t.id);t.multiSelect?(v=new Set(e.selectedIds),g?v.delete(t.id):v.add(t.id)):(v=new Set,g||v.add(t.id));var m=new Set(e.halfSelectedIds);return m.delete(t.id),_objectSpread2({},e,{selectedIds:v,halfSelectedIds:m,tabbableId:t.id,isFocused:!0,lastStandardSelect:t.NotUserAction?e.lastStandardSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.changeSelectMany:var T,A=t.ids.filter(function(t){return!e.disabledIds.has(t)});if(t.multiSelect){T=t.select?new Set([].concat(_toConsumableArray(e.selectedIds),_toConsumableArray(A))):difference(e.selectedIds,new Set(A));var w=difference(e.halfSelectedIds,T);return _objectSpread2({},e,{selectedIds:T,halfSelectedIds:w,lastAction:t.type,lastInteractedWith:t.lastInteractedWith})}return e;case treeTypes.exclusiveChangeSelectMany:var x,_=t.ids.filter(function(t){return!e.disabledIds.has(t)});if(t.multiSelect){x=t.select?new Set(_):difference(e.selectedIds,new Set(_));var E=difference(e.halfSelectedIds,x);return _objectSpread2({},e,{selectedIds:x,halfSelectedIds:E,lastAction:t.type,lastInteractedWith:t.lastInteractedWith})}return e;case treeTypes.focus:return _objectSpread2({},e,{tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.blur:return _objectSpread2({},e,{isFocused:!1});case treeTypes.disable:var W=new Set(e.disabledIds);return W.add(t.id),_objectSpread2({},e,{disabledIds:W});case treeTypes.enable:var P=new Set(e.disabledIds);return P.delete(t.id),_objectSpread2({},e,{disabledIds:P});default:throw new Error("Invalid action passed to the reducer")}},useTree=function(e){var t=e.data,a=e.defaultExpandedIds,r=e.defaultSelectedIds,n=e.defaultDisabledIds,l=e.nodeRefs,d=e.onSelect,s=e.onExpand,i=e.multiSelect,c=e.propagateSelectUpwards,o=_slicedToArray(React.useReducer(treeReducer,{selectedIds:new Set(r),tabbableId:t[0].children[0],isFocused:!1,expandedIds:new Set(a),halfSelectedIds:new Set,lastStandardSelect:t[0].children[0],lastInteractedWith:null,disabledIds:new Set(n)}),2),u=o[0],p=o[1],f=u.selectedIds,h=u.expandedIds,y=u.disabledIds,b=u.tabbableId,S=u.halfSelectedIds,I=u.lastAction,v=u.lastInteractedWith,g=usePrevious(f)||new Set,m=symmetricDifference(f,g);React.useEffect(function(){if(d!==noop){var e=!0,a=!1,r=void 0;try{for(var n,l=m[Symbol.iterator]();!(e=(n=l.next()).done);e=!0){var s=n.value,i=isBranchNode(t,s);d({element:t[s],isBranch:i,isExpanded:i?h.has(s):void 0,isSelected:f.has(s),isDisabled:y.has(s),isHalfSelected:i?S.has(s):void 0,treeState:u})}}catch(e){a=!0,r=e}finally{try{e||null==l.return||l.return()}finally{if(a)throw r}}}},[t,f,h,y,S,m,d,u]);var T=usePrevious(h)||new Set;return React.useEffect(function(){var e=symmetricDifference(h,T);if(s!==noop){var a=!0,r=!1,n=void 0;try{for(var l,d=e[Symbol.iterator]();!(a=(l=d.next()).done);a=!0){var i=l.value;s({element:t[i],isExpanded:h.has(i),isSelected:f.has(i),isDisabled:y.has(i),isHalfSelected:S.has(i),treeState:u})}}catch(e){r=!0,n=e}finally{try{a||null==d.return||d.return()}finally{if(r)throw n}}}},[t,f,h,y,S,T,s,u]),React.useEffect(function(){if(c&&i){var e=new Set(m);v&&e.add(v);var a=propagateSelectChange(t,e,f,y),r=a.every,n=a.some,l=a.none,d=!0,s=!1,o=void 0;try{for(var u,h=r[Symbol.iterator]();!(d=(u=h.next()).done);d=!0){var b=u.value;f.has(b)||p({type:treeTypes.select,id:b,multiSelect:i,keepFocus:!0,NotUserAction:!0,lastInteractedWith:v})}}catch(e){s=!0,o=e}finally{try{d||null==h.return||h.return()}finally{if(s)throw o}}var I=!0,g=!1,T=void 0;try{for(var A,w=n[Symbol.iterator]();!(I=(A=w.next()).done);I=!0){var x=A.value;S.has(x)||p({type:treeTypes.halfSelect,id:x,multiSelect:i,keepFocus:!0,NotUserAction:!0,lastInteractedWith:v})}}catch(e){g=!0,T=e}finally{try{I||null==w.return||w.return()}finally{if(g)throw T}}var _=!0,E=!1,W=void 0;try{for(var P,C=l[Symbol.iterator]();!(_=(P=C.next()).done);_=!0){var N=P.value;(f.has(N)||S.has(N))&&p({type:treeTypes.deselect,id:N,multiSelect:i,keepFocus:!0,NotUserAction:!0,lastInteractedWith:v})}}catch(e){E=!0,W=e}finally{try{_||null==C.return||C.return()}finally{if(E)throw W}}}},[t,i,c,f,h,y,S,I,g,m,v]),React.useEffect(function(){if(null!=v&&null!=b){var e=l.current[b];focusRef(e)}},[b,l,v]),[u,p]},clickActions={select:"SELECT",focus:"FOCUS",exclusiveSelect:"EXCLUSIVE_SELECT"},noop=function(){},TreeView=React__default.forwardRef(function(e,t){var a=e.data,r=e.nodeRenderer,n=e.onSelect,l=void 0===n?noop:n,d=e.onExpand,s=void 0===d?noop:d,i=e.className,c=void 0===i?"":i,o=e.multiSelect,u=void 0!==o&&o,p=e.propagateSelect,f=void 0!==p&&p,h=e.propagateSelectUpwards,y=void 0!==h&&h,b=e.propagateCollapse,S=void 0!==b&&b,I=e.expandOnKeyboardSelect,v=void 0!==I&&I,g=e.togglableSelect,m=void 0!==g&&g,T=e.defaultExpandedIds,A=void 0===T?[]:T,w=e.defaultSelectedIds,x=void 0===w?[]:w,_=e.defaultDisabledIds,E=void 0===_?[]:_,W=e.clickAction,P=void 0===W?clickActions.select:W,C=_objectWithoutProperties(e,["data","nodeRenderer","onSelect","onExpand","className","multiSelect","propagateSelect","propagateSelectUpwards","propagateCollapse","expandOnKeyboardSelect","togglableSelect","defaultExpandedIds","defaultSelectedIds","defaultDisabledIds","clickAction"]),N=React.useRef({}),R=_slicedToArray(useTree({data:a,defaultExpandedIds:A,defaultSelectedIds:x,defaultDisabledIds:E,nodeRefs:N,onSelect:l,onExpand:s,multiSelect:u,propagateSelect:f,propagateSelectUpwards:y}),2),O=R[0],j=R[1];f=f&&u;var D=React.useRef();return null!=t&&(D=t),React__default.createElement("ul",_extends({className:cx(baseClassNames.root,c),role:"tree","aria-multiselectable":u,ref:D,onBlur:function(e){return onComponentBlur(e,D.current,function(){j({type:treeTypes.blur})})},onKeyDown:handleKeyDown({data:a,tabbableId:O.tabbableId,expandedIds:O.expandedIds,selectedIds:O.selectedIds,disabledIds:O.disabledIds,halfSelectedIds:O.halfSelectedIds,dispatch:j,propagateCollapse:S,propagateSelect:f,multiSelect:u,expandOnKeyboardSelect:v,togglableSelect:m})},C),a[0].children.map(function(e,t){return React__default.createElement(Node,{key:e,selectedIds:O.selectedIds,tabbableId:O.tabbableId,isFocused:O.isFocused,expandedIds:O.expandedIds,disabledIds:O.disabledIds,halfSelectedIds:O.halfSelectedIds,lastStandardSelect:O.lastStandardSelect,lastInteractedWith:O.lastInteractedWith,dispatch:j,data:a,element:a[e],nodeRefs:N,baseClassNames:baseClassNames,nodeRenderer:r,setsize:a[0].children.length,posinset:t+1,level:1,propagateCollapse:S,propagateSelect:f,multiSelect:u,togglableSelect:m,clickAction:P,state:O})}))}),Node=function e(t){var a=t.element,r=t.dispatch,n=t.data,l=t.selectedIds,d=t.tabbableId,s=t.isFocused,i=t.expandedIds,c=t.disabledIds,o=t.halfSelectedIds,u=t.lastStandardSelect,p=t.nodeRefs,f=t.baseClassNames,h=t.nodeRenderer,y=t.setsize,b=t.posinset,S=t.level,I=t.propagateCollapse,v=t.propagateSelect,g=t.multiSelect,m=t.togglableSelect,T=t.clickAction,A=t.lastInteractedWith,w=t.state,x=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(i.has(a.id)&&I){var t=[a.id].concat(_toConsumableArray(getDescendants(n,a.id,[])));r({type:treeTypes.collapseMany,ids:t,lastInteractedWith:a.id})}else r({type:treeTypes.toggle,id:a.id,lastInteractedWith:a.id})},_=function(){r({type:treeTypes.focus,id:a.id,lastInteractedWith:a.id})},E=function(e){if(e.shiftKey){var t=getAccessibleRange({data:n,expandedIds:i,from:u,to:a.id,lastInteractedWith:a.id}).filter(function(e){return!c.has(e)});t=v?propagatedIds(n,t,c):t,r({type:treeTypes.exclusiveChangeSelectMany,select:!0,multiSelect:g,ids:t,lastInteractedWith:a.id})}else e.ctrlKey||T===clickActions.select?(r({type:m?treeTypes.toggleSelect:treeTypes.select,id:a.id,multiSelect:g,lastInteractedWith:a.id}),v&&!c.has(a.id)&&r({type:treeTypes.changeSelectMany,ids:propagatedIds(n,[a.id],c),select:!m||!l.has(a.id),multiSelect:g,lastInteractedWith:a.id})):T===clickActions.exclusiveSelect?r({type:m?treeTypes.toggleSelect:treeTypes.select,id:a.id,multiSelect:!1,lastInteractedWith:a.id}):T===clickActions.focus&&r({type:treeTypes.focus,id:a.id,lastInteractedWith:a.id})},W=function(e){var t;return cx(e,(_defineProperty(t={},"".concat(e,"--expanded"),i.has(a.id)),_defineProperty(t,"".concat(e,"--selected"),l.has(a.id)),_defineProperty(t,"".concat(e,"--focused"),d===a.id&&s),t))};return isBranchNode(n,a.id)?React__default.createElement("li",{role:"treeitem","aria-expanded":i.has(a.id),"aria-selected":getAriaSelected(l.has(a.id),c.has(a.id),g),"aria-setsize":y,"aria-posinset":b,"aria-level":S,disabled:c.has(a.id),tabIndex:d===a.id?0:-1,ref:function(e){return p.current[a.id]=e},className:f.branchWrapper},h({element:a,isBranch:!0,isSelected:l.has(a.id),isHalfSelected:o.has(a.id),isExpanded:i.has(a.id),isDisabled:c.has(a.id),dispatch:r,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onClick;return{onClick:null==t?composeHandlers(E,x,_):composeHandlers(t,_),className:cx(W(f.node),f.branch)}},setsize:y,posinset:b,level:S,handleSelect:E,handleExpand:x,treeState:w}),i.has(a.id)&&React__default.createElement("ul",{role:"group",className:W(f.nodeGroup)},a.children.map(function(t,y){return React__default.createElement(e,{key:t,selectedIds:l,tabbableId:d,isFocused:s,expandedIds:i,halfSelectedIds:o,disabledIds:c,lastStandardSelect:u,dispatch:r,data:n,element:n[t],nodeRefs:p,baseClassNames:f,nodeRenderer:h,setsize:a.children.length,posinset:y+1,level:S+1,propagateCollapse:I,propagateSelect:v,multiSelect:g,togglableSelect:m,clickAction:T,lastInteractedWith:A,state:w})}))):React__default.createElement("li",{role:"none",className:W(f.leafListItem)},h({element:a,isBranch:!1,isSelected:l.has(a.id),isHalfSelected:void 0,isExpanded:!1,isDisabled:c.has(a.id),dispatch:r,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onClick;return{role:"treeitem",tabIndex:d===a.id?0:-1,onClick:composeHandlers(null==t?E:t,_),ref:function(e){return p.current[a.id]=e},className:cx(W(f.node),f.leaf),"aria-setsize":y,"aria-posinset":b,"aria-level":S,"aria-selected":getAriaSelected(l.has(a.id),c.has(a.id),g),disabled:c.has(a.id)}},setsize:y,posinset:b,level:S,handleSelect:E,handleExpand:noop,treeState:w}))},handleKeyDown=function(e){var t=e.data,a=e.expandedIds,r=e.selectedIds,n=e.disabledIds,l=e.tabbableId,d=e.dispatch,s=e.propagateCollapse,i=e.propagateSelect,c=e.multiSelect,o=e.expandOnKeyboardSelect,u=e.togglableSelect;return function(e){var p=t[l],f=p.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();t[0];var h=_objectWithoutProperties(t,["0"]),y=Object.values(h).map(function(e){return e.id}).filter(function(e){return!n.has(e)});d({type:treeTypes.changeSelectMany,multiSelect:c,select:Array.from(r).filter(function(e){return!n.has(e)}).length!==y.length,ids:y,lastInteractedWith:p.id})}else if(e.shiftKey&&("Home"===e.key||"End"===e.key)){var b="Home"===e.key?t[0].children[0]:getLastAccessible(t,f,a),S=getAccessibleRange({data:t,expandedIds:a,from:f,to:b}).filter(function(e){return!n.has(e)});d({type:treeTypes.changeSelectMany,multiSelect:c,select:!0,ids:i?propagatedIds(t,S,n):S}),d({type:treeTypes.focus,id:b,lastInteractedWith:b})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var I=getPreviousAccessible(t,f,a);return void(null==I&&n.has(I)||(d({type:treeTypes.changeSelectMany,ids:i?propagatedIds(t,[I],n):[I],select:!0,multiSelect:c,lastInteractedWith:I}),d({type:treeTypes.focus,id:I,lastInteractedWith:I})));case"ArrowDown":e.preventDefault();var v=getNextAccessible(t,f,a);return void(null==v&&n.has(v)||(d({type:treeTypes.changeSelectMany,ids:i?propagatedIds(t,[v],n):[v],multiSelect:c,select:!0,lastInteractedWith:v}),d({type:treeTypes.focus,id:v,lastInteractedWith:v})))}switch(e.key){case"ArrowDown":e.preventDefault();var g=getNextAccessible(t,f,a);return void(null!=g&&d({type:treeTypes.focus,id:g,lastInteractedWith:g}));case"ArrowUp":e.preventDefault();var m=getPreviousAccessible(t,f,a);return void(null!=m&&d({type:treeTypes.focus,id:m,lastInteractedWith:m}));case"ArrowLeft":if(e.preventDefault(),isBranchNode(t,f)&&a.has(l))if(s){var T=[f].concat(_toConsumableArray(getDescendants(t,f,[])));d({type:treeTypes.collapseMany,ids:T,lastInteractedWith:p.id})}else d({type:treeTypes.collapse,id:f,lastInteractedWith:f});else if(!t[0].children.includes(f)){var A=getParent(t,f);d({type:treeTypes.focus,id:A,lastInteractedWith:A})}return;case"ArrowRight":return e.preventDefault(),void(isBranchNode(t,f)&&(a.has(l)?d({type:treeTypes.focus,id:p.children[0],lastInteractedWith:p.children[0]}):d({type:treeTypes.expand,id:f,lastInteractedWith:f})));case"Home":e.preventDefault(),d({type:treeTypes.focus,id:t[0].children[0],lastInteractedWith:t[0].children[0]});break;case"End":e.preventDefault();var w=getLastAccessible(t,t[0].id,a);return void d({type:treeTypes.focus,id:w,lastInteractedWith:w});case"*":e.preventDefault();var x=t[getParent(t,f)].children.filter(function(e){return isBranchNode(t,e)});return void d({type:treeTypes.expandMany,ids:x,lastInteractedWith:f});case"Enter":case" ":case"Spacebar":return e.preventDefault(),!n.has(f)&&d({type:treeTypes.changeSelectMany,ids:i?propagatedIds(t,[f],n):[f],select:!u||!r.has(f),multiSelect:c,lastInteractedWith:f}),void(o&&d({type:treeTypes.toggle,id:f,lastInteractedWith:f}));default:if(1===e.key.length)for(var _=getNextAccessible(t,f,a);_!==f;)if(null!=_){if(t[_].name[0].toLowerCase()===e.key.toLowerCase())return void d({type:treeTypes.focus,id:_,lastInteractedWith:f});_=getNextAccessible(t,_,a)}else _=t[0].children[0];return}}}};TreeView.propTypes={data:PropTypes.array.isRequired,onSelect:PropTypes.func,onExpand:PropTypes.func,className:PropTypes.string,nodeRenderer:PropTypes.func.isRequired,defaultExpandedIds:PropTypes.array,defaultSelectedIds:PropTypes.array,defaultDisabledIds:PropTypes.array,propagateCollapse:PropTypes.bool,propagateSelect:PropTypes.bool,propagateSelectUpwards:PropTypes.bool,multiSelect:PropTypes.bool,expandOnKeyboardSelect:PropTypes.bool,togglableSelect:PropTypes.bool,clickAction:PropTypes.oneOf(Object.values(clickActions))},exports.default=TreeView,exports.flattenTree=flattenTree;

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

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

@@ -18,9 +18,9 @@ "main": "dist/react-accessible-treeview.cjs.js",

"@babel/preset-react": "^7.0.0",
"babel-eslint": "^9.0.0",
"babel-eslint": "^10.0.2",
"babel-loader": "^8.0.6",
"classnames": "^2.2.6",
"css-loader": "^3.1.0",
"eslint": "^5.16.0",
"eslint-config-react-app": "^4.0.1",
"eslint-plugin-flowtype": "^2.50.3",
"eslint": "^6.1.0",
"eslint-config-react-app": "^5.0.0",
"eslint-plugin-flowtype": "^4.2.0",
"eslint-plugin-import": "^2.18.2",

@@ -42,3 +42,3 @@ "eslint-plugin-jsx-a11y": "^6.2.3",

"rollup-plugin-terser": "^5.1.1",
"style-loader": "^0.23.1",
"style-loader": "^1.0.0",
"webpack": "^4.38.0"

@@ -51,3 +51,5 @@ },

"files": [
"dist"
"dist",
"src/index.js",
"src/TreeView/*.js"
],

@@ -54,0 +56,0 @@ "license": "MIT",

@@ -1,5 +0,13 @@

# react-accessible-treeview
# react-accessible-treeview [![Build Status](https://travis-ci.org/lissitz/react-accessible-treeview.svg?branch=master)](https://travis-ci.org/lissitz/react-accessible-treeview) [![Greenkeeper badge](https://badges.greenkeeper.io/lissitz/react-accessible-treeview.svg)](https://greenkeeper.io/) [![npm version](https://badge.fury.io/js/react-accessible-treeview.svg)](https://badge.fury.io/js/react-accessible-treeview) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
A react component that implements the treeview pattern as described by the [WAI-ARIA Authoring Practices](https://www.w3.org/TR/wai-aria-practices/#TreeView).
### Features
- Single and multiple selection.
- Disabled nodes.
- Extensive key bindings.
- Highly customizable through the use of the render prop and prop getter patterns.
- WAI-ARIA compliant.
**Documentation and demo**

@@ -10,19 +18,19 @@ https://react-accessible-treeview.netlify.com/

| Prop name | Type | Default value | Description |
| ------------------------ | ------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `data` | `array[node]` | `required` | Tree data |
| `nodeRenderer` | `func` | `required` | Render prop for the node (see below for more details) |
| `onSelect` | `func` | `noop` | Function called when a node changes its selected state |
| `onExpand` | `func` | `noop` | Function called when a node changes its expanded state |
| `className` | `string` | `""` | className to add to the outermost dom element, al `ul` with `role = "tree"` |
| `multiSelect` | `bool` | `false` | Allows multiple nodes to be selected |
| `propagateSelect` | `bool` | `false` | If true, selecting a node will also select its descendants |
| `propagateSelectUpwards` | `bool` | `false` | If true, selecting a node will update the state of its parent (e.g. a parent node in a checkbox will be automatically selected if all of its children are selected |
| `propagateCollapse` | `bool` | `false` | If true, collapsing a node will also collapse its descendants |
| `expandOnKeyboardSelect` | `bool` | `false` | Selecting a node with a keyboard (using Space or Enter) will also toggle its expanded state |
| `togglableSelect` | `bool` | `false` | Wether the selected state is togglable |
| `defaultSelectedIds` | `array` | `[]` | Array with the ids of the default selected nodes |
| `defaultExpandedIds` | `array` | `[]` | Array with the ids of the default expanded nodes |
| `defaultDisabledIds` | `array` | `[]` | Array with the ids of the default disabled nodes |
| `clickAction` | `enum` | `SELECT` | Action to perform on click. One of: EXCLUSIVE_SELECT, FOCUS, SELECT |
| Prop name | Type | Default value | Description |
| ------------------------ | ------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `data` | `array[node]` | `required` | Tree data |
| `nodeRenderer` | `func` | `required` | Render prop for the node (see below for more details) |
| `onSelect` | `func` | `noop` | Function called when a node changes its selected state |
| `onExpand` | `func` | `noop` | Function called when a node changes its expanded state |
| `className` | `string` | `""` | className to add to the outermost dom element, al `ul` with `role = "tree"` |
| `multiSelect` | `bool` | `false` | Allows multiple nodes to be selected |
| `propagateSelect` | `bool` | `false` | If set to true, selecting a node will also select its descendants |
| `propagateSelectUpwards` | `bool` | `false` | If set to true, selecting a node will update the state of its parent (e.g. a parent node in a checkbox will be automatically selected if all of its children are selected |
| `propagateCollapse` | `bool` | `false` | If set to true, collapsing a node will also collapse its descendants |
| `expandOnKeyboardSelect` | `bool` | `false` | Selecting a node with a keyboard (using Space or Enter) will also toggle its expanded state |
| `togglableSelect` | `bool` | `false` | Wether the selected state is togglable |
| `defaultSelectedIds` | `array` | `[]` | Array with the ids of the default selected nodes |
| `defaultExpandedIds` | `array` | `[]` | Array with the ids of the default expanded nodes |
| `defaultDisabledIds` | `array` | `[]` | Array with the ids of the default disabled nodes |
| `clickAction` | `enum` | `SELECT` | Action to perform on click. One of: EXCLUSIVE_SELECT, FOCUS, SELECT |

@@ -71,17 +79,18 @@ <br/> <br/>

| Property | Type | Description |
| -------------- | --------------------- | ----------------------------------------------------------------------------------------------------- |
| `element` | `object` | The object that represents the rendered node |
| `getNodeProps` | `function` | A function which gives back the props to pass to the node |
| `isBranch` | `bool` | Whether the rendered node is a branch node |
| `isSelected` | `bool` | Whether the rendered node is selected |
| `isExpanded` | `bool` or `undefined` | If the node is a branch node, whether it is expanded, else undefined |
| `tabbableId` | `integer` | Id of the currently tabbable (tabindex = 0) node |
| `expandedIds` | `array` | An array formed of the ids of the expanded nodes |
| `level` | `number` | A positive integer that corresponds to the aria-level attribute |
| `setsize` | `number` | A positive integer that corresponds to the aria-setsize attribute |
| `posinset` | `number` | A positive integer that corresponds to the aria-posinset attribute |
| `handleSelect` | `function` | Function to assign to the onClick event handler of the element(s) that will toggle the selected state |
| `handleExpand` | `function` | Function to assign to the onClick event handler of the element(s) that will toggle the expanded state |
| `dispatch` | `function` | Function to dispatch actions |
| Property | Type | Description |
| ---------------- | --------------------- | ----------------------------------------------------------------------------------------------------- |
| `element` | `object` | The object that represents the rendered node |
| `getNodeProps` | `function` | A function which gives back the props to pass to the node |
| `isBranch` | `bool` | Whether the rendered node is a branch node |
| `isSelected` | `bool` | Whether the rendered node is selected |
| `isHalfSelected` | `bool` or `undefined` | If the node is a branch node, whether it is half-selected, else undefined |
| `isExpanded` | `bool` or `undefined` | If the node is a branch node, whether it is expanded, else undefined |
| `isDisabled` | `bool` | Wheter the rendered node is disabled |
| `level` | `number` | A positive integer that corresponds to the aria-level attribute |
| `setsize` | `number` | A positive integer that corresponds to the aria-setsize attribute |
| `posinset` | `number` | A positive integer that corresponds to the aria-posinset attribute |
| `handleSelect` | `function` | Function to assign to the onClick event handler of the element(s) that will toggle the selected state |
| `handleExpand` | `function` | Function to assign to the onClick event handler of the element(s) that will toggle the expanded state |
| `dispatch` | `function` | Function to dispatch actions |
| `treeState` | `function` | state of the treeview |

@@ -92,3 +101,3 @@ <br/> <br/>

- _Arguments_: `onSelect({element, isBranch, isExpanded, selectedIds, expandedIds, tabbableId, halfSelectedIds, lastInteractedWith})`
- _Arguments_: `onSelect({element, isBranch, isExpanded, isSelected, isHalfSelected, isDisabled, treeState })`
Note: the function uses the state _after_ the selection.

@@ -98,4 +107,4 @@

- _Arguments_: `onExpand({element, isBranch, isExpanded, selectedIds, expandedIds, tabbableId, halfSelectedIds, lastInteractedWith})`
Note: the function uses the state \_after the expansion.
- _Arguments_: `onExpand({element, isExpanded, isSelected, isHalfSelected, isDisabled, treeState})`
Note: the function uses the state _after_ the expansion.

@@ -106,3 +115,3 @@ <br/> <br/>

Follows the same convention described in https://www.w3.org/TR/wai-aria-practices/examples/treeview/treeview-1/treeview-1b.html.
Follows the same conventions described in https://www.w3.org/TR/wai-aria-practices/examples/treeview/treeview-1/treeview-1b.html and https://www.w3.org/TR/wai-aria-practices/#keyboard-interaction-22.

@@ -122,3 +131,3 @@ | Key | Function |

| <code>Shift + Up Arrow</code> | Moves focus to and toggles the selection state of the previous node. |
| <code>Ctrl + A </code> | Selects all nodes in the tree. If all nodes are selected, it unselects all nodes. |
| <code>Ctrl + A </code> | Selects all nodes in the tree. If all nodes are selected, unselects all nodes. |

@@ -129,7 +138,7 @@ <br/> <br/>

| Key | Function |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Click` | toggle parent nodes and also performs one of clickActions = SELECT, EXCLUSIVE_SELECT, FOCUS |
| `Ctrl+Click` | If `multiselect` is `true`, selects the node without dropping the current selected ones. If false, it selects the clicked node. Doesn't toggle parents. |
| `Shift+Click` | If `multiselect` is `true`, selects from the node without dropping the current selected ones. If false, it focus the clicked node. Doesn't toggle parents. |
| Key | Function |
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Click` | Toggles parent nodes and also performs one of clickActions = SELECT, EXCLUSIVE_SELECT, FOCUS |
| `Ctrl+Click` | If `multiselect` is set to `true`, selects the node without dropping the current selected ones. If false, it selects the clicked node. Doesn't toggle parents. |
| `Shift+Click` | If `multiselect` is set to `true`, selects from the node without dropping the current selected ones. If false, it focus the clicked node. Doesn't toggle parents. |

@@ -140,8 +149,8 @@ <br/> <br/>

| Variant | Function |
| ------------------ | ----------------------------------------------- |
| `SELECT` | Select the clicked node (default). |
| `EXCLUSIVE_SELECT` | Select the clicked node and deselects the rest. |
| `FOCUS` | Focus the clicked node |
| Variant | Function |
| ------------------ | ------------------------------------------------ |
| `SELECT` | Selects the clicked node (default). |
| `EXCLUSIVE_SELECT` | Selects the clicked node and deselects the rest. |
| `FOCUS` | Focuses the clicked node |
<br/> <br/>
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc