react-accessible-treeview
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -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,c=e[Symbol.iterator]();!(r=(d=c.next()).done)&&(a.push(d.value),!t||a.length!==t);r=!0);}catch(e){n=!0,l=e}finally{try{r||null==c.return||c.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,c=e[Symbol.iterator]();!(r=(d=c.next()).done);r=!0){var s=d.value;t.has(s)||a.add(s)}}catch(e){n=!0,l=e}finally{try{r||null==c.return||c.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){var a=[];return function e(t,r){var n=t[r],l=!0,d=!1,c=void 0;try{for(var s,i=(n.children||[])[Symbol.iterator]();!(l=(s=i.next()).done);l=!0){var o=s.value;a.push(o),e(t,o)}}catch(e){d=!0,c=e}finally{try{l||null==i.return||i.return()}finally{if(d)throw c}}}(e,t),a},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){var r={every:new Set,some:new Set,none:new Set},n=!0,l=!1,d=void 0;try{for(var c,s=t[Symbol.iterator]();!(n=(c=s.next()).done);n=!0)for(var i=c.value,o=!1;;){var u=getParent(e,i);if(0===u)break;if(o)r.some.add(u),i=u;else{var p=e[u].children;p.some(function(e){return a.has(e)})?p.every(function(e){return a.has(e)})?r.every.add(u):(o=!0,r.some.add(u)):r.none.add(u),i=u}}}catch(e){l=!0,d=e}finally{try{n||null==s.return||s.return()}finally{if(l)throw d}}return r},getAccesibleRange=function(e){var t=e.data,a=e.expandedIds,r=e.from,n=e.to,l=[],d=Object.keys(t).length,c=0,s=r;if(l.push(r),r<n)for(;c<d&&(s=getNextAccessible(t,s,a),l.push(s),null!=s&&s!==n);)c+=1;else if(r>n)for(;c<d&&(s=getPreviousAccessible(t,s,a),l.push(s),null!=s&&s!==n);)c+=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,c=void 0;try{for(var s,i=r.children[Symbol.iterator]();!(l=(s=i.next()).done);l=!0){e(s.value,r.id)}}catch(e){d=!0,c=e}finally{try{l||null==i.return||i.return()}finally{if(d)throw c}}r.children=r.children.map(function(e){return e.id})}}(e,null),a},getAriaSelected=function(e,t){return t?e:!!e||void 0},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"},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 c,s=t.ids[Symbol.iterator]();!(n=(c=s.next()).done);n=!0){var i=c.value;r.delete(i)}}catch(e){l=!0,d=e}finally{try{n||null==s.return||s.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:return _objectSpread2({},e,{expandedIds:new Set([].concat(_toConsumableArray(e.expandedIds),_toConsumableArray(t.ids))),lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.toggle:var u=new Set(e.expandedIds);return e.expandedIds.has(t.id)?u.delete(t.id):u.add(t.id),_objectSpread2({},e,{expandedIds:u,tabbableId:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.halfSelect:var p=new Set(e.halfSelectedIds),f=new Set(e.selectedIds);return p.add(t.id),f.delete(t.id),_objectSpread2({},e,{selectedIds:f,halfSelectedIds:p,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.select:var y;t.multiSelect?(y=new Set(e.selectedIds)).add(t.id):(y=new Set).add(t.id);var h=new Set(e.halfSelectedIds);return h.delete(t.id),_objectSpread2({},e,{selectedIds:y,halfSelectedIds:h,tabbableId:t.keepFocus?e.tabbableId:t.id,lastStandardSelect:t.NotUserAction?e.lastStandardSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.deselect:var S;t.multiSelect?(S=new Set(e.selectedIds)).delete(t.id):S=new Set;var b=new Set(e.halfSelectedIds);return b.delete(t.id),_objectSpread2({},e,{selectedIds:S,halfSelectedIds:b,tabbableId:t.keepFocus?e.tabbableId:t.id,lastStandardSelect:t.NotUserAction?e.lastStandardSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.toggleSelect:var v,I=e.selectedIds.has(t.id);t.multiSelect?(v=new Set(e.selectedIds),I?v.delete(t.id):v.add(t.id)):(v=new Set,I||v.add(t.id));var g=new Set(e.halfSelectedIds);return g.delete(t.id),_objectSpread2({},e,{selectedIds:v,halfSelectedIds:g,tabbableId:t.id,lastStandardSelect:t.NotUserAction?e.lastStandardSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case treeTypes.changeSelectMany:var m;return t.multiSelect?_objectSpread2({},e,{selectedIds:m=t.select?new Set([].concat(_toConsumableArray(e.selectedIds),_toConsumableArray(t.ids))):difference(e.selectedIds,new Set(t.ids)),halfSelectedIds:difference(e.halfSelectedIds,m),lastAction:t.type,lastInteractedWith:t.lastInteractedWith}):e;case treeTypes.exclusiveChangeSelectMany:var x;return t.multiSelect?_objectSpread2({},e,{selectedIds:x=t.select?new Set(t.ids):difference(e.selectedIds,new Set(t.ids)),halfSelectedIds:difference(e.halfSelectedIds,x),lastAction:t.type,lastInteractedWith:t.lastInteractedWith}):e;case treeTypes.focus:return _objectSpread2({},e,{tabbableId:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});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.nodeRefs,l=e.onSelect,d=e.onExpand,c=e.multiSelect,s=e.propagateSelectUpwards,i=_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}),2),o=i[0],u=i[1],p=o.selectedIds,f=o.expandedIds,y=o.tabbableId,h=o.halfSelectedIds,S=o.lastAction,b=o.lastInteractedWith,v=usePrevious(p)||new Set,I=symmetricDifference(p,v);React.useEffect(function(){if(l!==noop){var e=!0,a=!1,r=void 0;try{for(var n,d=I[Symbol.iterator]();!(e=(n=d.next()).done);e=!0){var c=n.value,s=isBranchNode(t,c);l({element:t[c],isBranch:s,isExpanded:s?f.has(c):void 0,selectedIds:p,expandedIds:f,tabbableId:y,halfSelectedIds:h,lastInteractedWith:b})}}catch(e){a=!0,r=e}finally{try{e||null==d.return||d.return()}finally{if(a)throw r}}}},[t,p,f,y,h,I,l,b]);var g=usePrevious(f)||new Set;React.useEffect(function(){var e=difference(f,g);if(d!==noop){var a=!0,r=!1,n=void 0;try{for(var l,c=e[Symbol.iterator]();!(a=(l=c.next()).done);a=!0){var s=l.value;d({element:t[s],isBranch:!0,isExpanded:!0,selectedIds:p,expandedIds:f,tabbableId:y,halfSelectedIds:h,lastInteractedWith:b})}}catch(e){r=!0,n=e}finally{try{a||null==c.return||c.return()}finally{if(r)throw n}}}},[t,p,f,y,h,l,d,g,b]),React.useEffect(function(){if(s&&c){var e=new Set(I);b&&e.add(b);var a=propagateSelectChange(t,e,p),r=a.every,n=a.some,l=a.none,d=!0,i=!1,o=void 0;try{for(var f,y=r[Symbol.iterator]();!(d=(f=y.next()).done);d=!0){var S=f.value;p.has(S)||u({type:treeTypes.select,id:S,multiSelect:c,keepFocus:!0,userInput:!1,NotUserAction:!0,lastInteractedWith:b})}}catch(e){i=!0,o=e}finally{try{d||null==y.return||y.return()}finally{if(i)throw o}}var v=!0,g=!1,m=void 0;try{for(var x,w=n[Symbol.iterator]();!(v=(x=w.next()).done);v=!0){var A=x.value;h.has(A)||u({type:treeTypes.halfSelect,id:A,multiSelect:c,keepFocus:!0,NotUserAction:!0,lastInteractedWith:b})}}catch(e){g=!0,m=e}finally{try{v||null==w.return||w.return()}finally{if(g)throw m}}var T=!0,_=!1,W=void 0;try{for(var E,P=l[Symbol.iterator]();!(T=(E=P.next()).done);T=!0){var C=E.value;(p.has(C)||h.has(C))&&u({type:treeTypes.deselect,id:C,multiSelect:c,keepFocus:!0,NotUserAction:!0,lastInteractedWith:b})}}catch(e){_=!0,W=e}finally{try{T||null==P.return||P.return()}finally{if(_)throw W}}}},[t,c,s,p,f,h,S,v,I,b]);var m=React.useRef(!1);return React.useEffect(function(){if(m.current){if(null!=y){var e=n.current[y];focusRef(e)}}else m.current=!0},[y,n,m]),[o,u]},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,c=void 0===d?noop:d,s=e.className,i=void 0===s?"":s,o=e.multiSelect,u=void 0!==o&&o,p=e.propagateSelect,f=void 0!==p&&p,y=e.propagateSelectUpwards,h=void 0!==y&&y,S=e.propagateCollapse,b=void 0!==S&&S,v=e.expandOnKeyboardSelect,I=void 0!==v&&v,g=e.togglableSelect,m=void 0!==g&&g,x=e.defaultExpandedIds,w=void 0===x?[]:x,A=e.defaultSelectedIds,T=void 0===A?[]:A,_=e.clickAction,W=void 0===_?clickActions.select:_,E=_objectWithoutProperties(e,["data","nodeRenderer","onSelect","onExpand","className","multiSelect","propagateSelect","propagateSelectUpwards","propagateCollapse","expandOnKeyboardSelect","togglableSelect","defaultExpandedIds","defaultSelectedIds","clickAction"]),P=React.useRef({}),C=_slicedToArray(useTree({data:a,defaultExpandedIds:w,defaultSelectedIds:T,nodeRefs:P,onSelect:l,onExpand:c,multiSelect:u,propagateSelectUpwards:h}),2),N=C[0],O=C[1];return f=f&&u,React__default.createElement("ul",_extends({className:cx(baseClassNames.root,i),role:"tree","aria-multiselectable":u,ref:t,onKeyDown:handleKeyDown({data:a,tabbableId:N.tabbableId,expandedIds:N.expandedIds,selectedIds:N.selectedIds,halfSelectedIds:N.halfSelectedIds,dispatch:O,propagateCollapse:b,propagateSelect:f,multiSelect:u,expandOnKeyboardSelect:I,togglableSelect:m})},E),a[0].children.map(function(e,t){return React__default.createElement(Node,{key:e,selectedIds:N.selectedIds,tabbableId:N.tabbableId,expandedIds:N.expandedIds,halfSelectedIds:N.halfSelectedIds,lastStandardSelect:N.lastStandardSelect,lastInteractedWith:N.lastInteractedWith,dispatch:O,data:a,element:a[e],nodeRefs:P,baseClassNames:baseClassNames,nodeRenderer:r,setsize:a[0].children.length,posinset:t+1,level:1,propagateCollapse:b,propagateSelect:f,multiSelect:u,togglableSelect:m,clickAction:W})}))}),Node=function e(t){var a=t.element,r=t.dispatch,n=t.data,l=t.selectedIds,d=t.tabbableId,c=t.expandedIds,s=t.halfSelectedIds,i=t.lastStandardSelect,o=t.nodeRefs,u=t.baseClassNames,p=t.nodeRenderer,f=t.setsize,y=t.posinset,h=t.level,S=t.propagateCollapse,b=t.propagateSelect,v=t.multiSelect,I=t.togglableSelect,g=t.clickAction,m=t.lastInteractedWith,x=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(c.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})},w=function(e){if(e.shiftKey){var t=getAccesibleRange({data:n,expandedIds:c,from:i,to:a.id,lastInteractedWith:a.id});t=new Set(t.concat(t.filter(function(e){return isBranchNode(n,e)}).flatMap(function(e){return getDescendants(n,e)}))),r({type:treeTypes.exclusiveChangeSelectMany,select:!0,multiSelect:v,ids:t,lastInteractedWith:a.id})}else e.ctrlKey||g===clickActions.select?(r(I?{type:treeTypes.toggleSelect,id:a.id,multiSelect:v}:{type:treeTypes.select,id:a.id,multiSelect:v}),b&&r({type:treeTypes.changeSelectMany,ids:getDescendants(n,a.id),select:!l.has(a.id),multiSelect:v,lastInteractedWith:a.id})):g===clickActions.exclusiveSelect?r(I?{type:treeTypes.toggleSelect,id:a.id,multiSelect:!1,lastInteractedWith:a.id}:{type:treeTypes.select,id:a.id,multiSelect:!1,lastInteractedWith:a.id}):g===clickActions.focus&&r({type:treeTypes.focus,id:a.id,lastInteractedWith:a.id})},A=function(e){var t;return cx(e,(_defineProperty(t={},"".concat(e,"--expanded"),c.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":c.has(a.id),"aria-selected":getAriaSelected(l.has(a.id),v),"aria-setsize":f,"aria-posinset":y,"aria-level":h,tabIndex:d===a.id?0:-1,ref:function(e){return o.current[a.id]=e},className:cx(A(u.node),u.branch)},p({element:a,isBranch:isBranchNode(n,a.id),isSelected:l.has(a.id),isHalfSelected:s.has(a.id),isExpanded:c.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),className:A(u.branchWrapper)}},setsize:f,posinset:y,level:h,handleSelect:w,handleExpand:x}),c.has(a.id)&&React__default.createElement("ul",{role:"group",className:A(u.nodeGroup)},a.children.map(function(t,f){return React__default.createElement(e,{key:t,selectedIds:l,tabbableId:d,expandedIds:c,halfSelectedIds:s,lastStandardSelect:i,dispatch:r,data:n,element:n[t],nodeRefs:o,baseClassNames:u,nodeRenderer:p,setsize:a.children.length,posinset:f+1,level:h+1,propagateCollapse:S,propagateSelect:b,multiSelect:v,togglableSelect:I,clickAction:g,lastInteractedWith:m})}))):React__default.createElement("li",{role:"none",className:A(u.leafListItem)},p({element:a,isBranch:isBranchNode(n,a.id),isSelected:l.has(a.id),isHalfSelected:s.has(a.id),isExpanded:c.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),ref:function(e){return o.current[a.id]=e},className:cx(A(u.node),u.leaf),"aria-setsize":f,"aria-posinset":y,"aria-level":h,"aria-selected":getAriaSelected(l.has(a.id),v)}},setsize:f,posinset:y,level:h,handleSelect:w,handleExpand:x}))},handleKeyDown=function(e){var t=e.data,a=e.expandedIds,r=e.selectedIds,n=e.tabbableId,l=e.dispatch,d=e.propagateCollapse,c=e.propagateSelect,s=e.multiSelect,i=e.expandOnKeyboardSelect,o=e.togglableSelect;return function(e){var u=t[n],p=u.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();t[0];var f=_objectWithoutProperties(t,["0"]),y=Object.values(f);l({type:treeTypes.changeSelectMany,multiSelect:s,select:r.size!==y.length,ids:new Set(Object.values(f).map(function(e){return e.id})),lastInteractedWith:u.id})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var h=getPreviousAccessible(t,p,a);return void(null!=h&&l({type:treeTypes.select,id:h,multiSelect:s,lastInteractedWith:h}));case"ArrowDown":e.preventDefault();var S=getNextAccessible(t,p,a);return void(null!=S&&l({type:treeTypes.select,id:S,multiSelect:s,lastInteractedWith:S}))}switch(e.key){case"ArrowDown":e.preventDefault();var b=getNextAccessible(t,p,a);return void(null!=b&&l({type:treeTypes.focus,id:b,lastInteractedWith:b}));case"ArrowUp":e.preventDefault();var v=getPreviousAccessible(t,p,a);return void(null!=v&&l({type:treeTypes.focus,id:v,lastInteractedWith:v}));case"ArrowLeft":if(e.preventDefault(),isBranchNode(t,p)&&a.has(n))if(d){var I=[p].concat(_toConsumableArray(getDescendants(t,p)));l({type:treeTypes.collapseMany,ids:I,lastInteractedWith:u.id})}else l({type:treeTypes.collapse,id:p,lastInteractedWith:p});else if(!t[0].children.includes(p)){var g=getParent(t,p);l({type:treeTypes.focus,id:g,lastInteractedWith:g})}return;case"ArrowRight":return e.preventDefault(),void(isBranchNode(t,p)&&(a.has(n)?l({type:treeTypes.focus,id:u.children[0],lastInteractedWith:u.children[0]}):l({type:treeTypes.expand,id:p,lastInteractedWith:p})));case"Home":e.preventDefault(),l({type:treeTypes.focus,id:t[0].children[0]});break;case"End":e.preventDefault();var m=getLastAccessible(t,t[0].id,a);return void l({type:treeTypes.focus,id:m,lastInteractedWith:m});case"*":e.preventDefault();var x=t[getParent(t,p)].children.filter(function(e){return isBranchNode(t,e)});return void l({type:treeTypes.expandMany,ids:x,lastInteractedWith:p});case"Enter":case" ":case"Spacebar":return e.preventDefault(),l(o?{type:treeTypes.toggleSelect,id:p,multiSelect:s,lastInteractedWith:p}:{type:treeTypes.select,id:p,multiSelect:s,lastInteractedWith:p}),i&&l({type:treeTypes.toggle,id:p,lastInteractedWith:p}),void(c&&l({type:treeTypes.changeSelectMany,ids:getDescendants(t,p),select:!r.has(p),multiSelect:s,lastInteractedWith:p}));default:if(1===e.key.length)for(var w=getNextAccessible(t,p,a);w!==p;)if(null!=w){if(t[w].name[0].toLowerCase()===e.key.toLowerCase())return void l({type:treeTypes.focus,id:w,lastInteractedWith:p});w=getNextAccessible(t,w,a)}else w=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,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){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; |
@@ -1,1 +0,1 @@ | ||
import e,{useRef as t,useEffect as a,useReducer as r}from"react";import n from"classnames";import l from"prop-types";function d(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(){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 c(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 s(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?c(a,!0).forEach(function(t){d(e,t,a[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):c(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={},l=Object.keys(e);for(r=0;r<l.length;r++)a=l[r],t.indexOf(a)>=0||(n[a]=e[a]);return n}(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 u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var a=[],r=!0,n=!1,l=void 0;try{for(var d,i=e[Symbol.iterator]();!(r=(d=i.next()).done)&&(a.push(d.value),!t||a.length!==t);r=!0);}catch(e){n=!0,l=e}finally{try{r||null==i.return||i.return()}finally{if(n)throw l}}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 n=r[a];if(n&&n(e),e.defaultPrevented)break}}},h=function(e,t){var a=new Set,r=!0,n=!1,l=void 0;try{for(var d,i=e[Symbol.iterator]();!(r=(d=i.next()).done);r=!0){var c=d.value;t.has(c)||a.add(c)}}catch(e){n=!0,l=e}finally{try{r||null==i.return||i.return()}finally{if(n)throw l}}return a},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},I=function(e,t){return e[t].parent},y=function(e,t){var a=[];return function e(t,r){var n=t[r],l=!0,d=!1,i=void 0;try{for(var c,s=(n.children||[])[Symbol.iterator]();!(l=(c=s.next()).done);l=!0){var o=c.value;a.push(o),e(t,o)}}catch(e){d=!0,i=e}finally{try{l||null==s.return||s.return()}finally{if(d)throw i}}}(e,t),a},b=function(e,t,a){var r=I(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},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)&&v(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=b(e,t,-1);return null==r?I(e,t):m(e,r,a)},g=function(e,t,a){var r=e[t].id;if(v(e,r)&&a.has(r))return e[r].children[0];for(;;){var n=b(e,r,1);if(null!=n)return n;if(null==(r=I(e,r)))return null}},x=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,i=void 0;try{for(var c,s=r.children[Symbol.iterator]();!(l=(c=s.next()).done);l=!0){e(c.value,r.id)}}catch(e){d=!0,i=e}finally{try{l||null==s.return||s.return()}finally{if(d)throw i}}r.children=r.children.map(function(e){return e.id})}}(e,null),a},W=function(e,t){return t?e:!!e||void 0},E={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"},A="COLLAPSE",O="COLLAPSE_MANY",C="EXPAND",k="EXPAND_MANY",N="HALF_SELECT",j="SELECT",L="DESELECT",D="TOGGLE",P="TOGGLE_SELECT",U="SELECT_MANY",R="EXCLUSIVE_CHANGE_SELECT_MANY",K="FOCUS",T=function(e,t){switch(t.type){case A:var a=new Set(e.expandedIds);return a.delete(t.id),s({},e,{expandedIds:a,tabbableId:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case O:var r=new Set(e.expandedIds),n=!0,l=!1,d=void 0;try{for(var i,c=t.ids[Symbol.iterator]();!(n=(i=c.next()).done);n=!0){var o=i.value;r.delete(o)}}catch(e){l=!0,d=e}finally{try{n||null==c.return||c.return()}finally{if(l)throw d}}return s({},e,{expandedIds:r,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case C:var u=new Set(e.expandedIds);return u.add(t.id),s({},e,{expandedIds:u,tabbableId:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case k:return s({},e,{expandedIds:new Set([].concat(f(e.expandedIds),f(t.ids))),lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case D:var p=new Set(e.expandedIds);return e.expandedIds.has(t.id)?p.delete(t.id):p.add(t.id),s({},e,{expandedIds:p,tabbableId:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case N:var S=new Set(e.halfSelectedIds),v=new Set(e.selectedIds);return S.add(t.id),v.delete(t.id),s({},e,{selectedIds:v,halfSelectedIds:S,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case j:var I;t.multiSelect?(I=new Set(e.selectedIds)).add(t.id):(I=new Set).add(t.id);var y=new Set(e.halfSelectedIds);return y.delete(t.id),s({},e,{selectedIds:I,halfSelectedIds:y,tabbableId:t.keepFocus?e.tabbableId:t.id,lastStandardSelect:t.NotUserAction?e.lastStandardSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case L:var b;t.multiSelect?(b=new Set(e.selectedIds)).delete(t.id):b=new Set;var m=new Set(e.halfSelectedIds);return m.delete(t.id),s({},e,{selectedIds:b,halfSelectedIds:m,tabbableId:t.keepFocus?e.tabbableId:t.id,lastStandardSelect:t.NotUserAction?e.lastStandardSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case P:var w,g=e.selectedIds.has(t.id);t.multiSelect?(w=new Set(e.selectedIds),g?w.delete(t.id):w.add(t.id)):(w=new Set,g||w.add(t.id));var x=new Set(e.halfSelectedIds);return x.delete(t.id),s({},e,{selectedIds:w,halfSelectedIds:x,tabbableId:t.id,lastStandardSelect:t.NotUserAction?e.lastStandardSelect:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case U:var W;return t.multiSelect?s({},e,{selectedIds:W=t.select?new Set([].concat(f(e.selectedIds),f(t.ids))):h(e.selectedIds,new Set(t.ids)),halfSelectedIds:h(e.halfSelectedIds,W),lastAction:t.type,lastInteractedWith:t.lastInteractedWith}):e;case R:var E;return t.multiSelect?s({},e,{selectedIds:E=t.select?new Set(t.ids):h(e.selectedIds,new Set(t.ids)),halfSelectedIds:h(e.halfSelectedIds,E),lastAction:t.type,lastInteractedWith:t.lastInteractedWith}):e;case K:return s({},e,{tabbableId:t.id,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});default:throw new Error("Invalid action passed to the reducer")}},_=function(e){var n,l,d=e.data,i=e.defaultExpandedIds,c=e.defaultSelectedIds,s=e.nodeRefs,o=e.onSelect,p=e.onExpand,y=e.multiSelect,b=e.propagateSelectUpwards,m=u(r(T,{selectedIds:new Set(c),tabbableId:d[0].children[0],expandedIds:new Set(i),halfSelectedIds:new Set,lastStandardSelect:d[0].children[0],lastInteractedWith:null}),2),w=m[0],g=m[1],x=w.selectedIds,W=w.expandedIds,E=w.tabbableId,A=w.halfSelectedIds,O=w.lastAction,C=w.lastInteractedWith,k=S(x)||new Set,D=(n=x,l=k,new Set([].concat(f(h(n,l)),f(h(l,n)))));a(function(){if(o!==F){var e=!0,t=!1,a=void 0;try{for(var r,n=D[Symbol.iterator]();!(e=(r=n.next()).done);e=!0){var l=r.value,i=v(d,l);o({element:d[l],isBranch:i,isExpanded:i?W.has(l):void 0,selectedIds:x,expandedIds:W,tabbableId:E,halfSelectedIds:A,lastInteractedWith:C})}}catch(e){t=!0,a=e}finally{try{e||null==n.return||n.return()}finally{if(t)throw a}}}},[d,x,W,E,A,D,o,C]);var P=S(W)||new Set;a(function(){var e=h(W,P);if(p!==F){var t=!0,a=!1,r=void 0;try{for(var n,l=e[Symbol.iterator]();!(t=(n=l.next()).done);t=!0){var i=n.value;p({element:d[i],isBranch:!0,isExpanded:!0,selectedIds:x,expandedIds:W,tabbableId:E,halfSelectedIds:A,lastInteractedWith:C})}}catch(e){a=!0,r=e}finally{try{t||null==l.return||l.return()}finally{if(a)throw r}}}},[d,x,W,E,A,o,p,P,C]),a(function(){if(b&&y){var e=new Set(D);C&&e.add(C);var t=function(e,t,a){var r={every:new Set,some:new Set,none:new Set},n=!0,l=!1,d=void 0;try{for(var i,c=t[Symbol.iterator]();!(n=(i=c.next()).done);n=!0)for(var s=i.value,o=!1;;){var u=I(e,s);if(0===u)break;if(o)r.some.add(u),s=u;else{var f=e[u].children;f.some(function(e){return a.has(e)})?f.every(function(e){return a.has(e)})?r.every.add(u):(o=!0,r.some.add(u)):r.none.add(u),s=u}}}catch(e){l=!0,d=e}finally{try{n||null==c.return||c.return()}finally{if(l)throw d}}return r}(d,e,x),a=t.every,r=t.some,n=t.none,l=!0,i=!1,c=void 0;try{for(var s,o=a[Symbol.iterator]();!(l=(s=o.next()).done);l=!0){var u=s.value;x.has(u)||g({type:j,id:u,multiSelect:y,keepFocus:!0,userInput:!1,NotUserAction:!0,lastInteractedWith:C})}}catch(e){i=!0,c=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw c}}var f=!0,p=!1,h=void 0;try{for(var S,v=r[Symbol.iterator]();!(f=(S=v.next()).done);f=!0){var m=S.value;A.has(m)||g({type:N,id:m,multiSelect:y,keepFocus:!0,NotUserAction:!0,lastInteractedWith:C})}}catch(e){p=!0,h=e}finally{try{f||null==v.return||v.return()}finally{if(p)throw h}}var w=!0,W=!1,E=void 0;try{for(var O,k=n[Symbol.iterator]();!(w=(O=k.next()).done);w=!0){var P=O.value;(x.has(P)||A.has(P))&&g({type:L,id:P,multiSelect:y,keepFocus:!0,NotUserAction:!0,lastInteractedWith:C})}}catch(e){W=!0,E=e}finally{try{w||null==k.return||k.return()}finally{if(W)throw E}}}},[d,y,b,x,W,A,O,k,D,C]);var U=t(!1);return a(function(){if(U.current){if(null!=E){var e=s.current[E];null!=(t=e)&&t.focus&&t.focus()}}else U.current=!0;var t},[E,s,U]),[w,g]},z={select:"SELECT",focus:"FOCUS",exclusiveSelect:"EXCLUSIVE_SELECT"},F=function(){},G=e.forwardRef(function(a,r){var l=a.data,d=a.nodeRenderer,c=a.onSelect,s=void 0===c?F:c,f=a.onExpand,p=void 0===f?F:f,h=a.className,S=void 0===h?"":h,v=a.multiSelect,I=void 0!==v&&v,y=a.propagateSelect,b=void 0!==y&&y,m=a.propagateSelectUpwards,w=void 0!==m&&m,g=a.propagateCollapse,x=void 0!==g&&g,W=a.expandOnKeyboardSelect,A=void 0!==W&&W,O=a.togglableSelect,C=void 0!==O&&O,k=a.defaultExpandedIds,N=void 0===k?[]:k,j=a.defaultSelectedIds,L=void 0===j?[]:j,D=a.clickAction,P=void 0===D?z.select:D,U=o(a,["data","nodeRenderer","onSelect","onExpand","className","multiSelect","propagateSelect","propagateSelectUpwards","propagateCollapse","expandOnKeyboardSelect","togglableSelect","defaultExpandedIds","defaultSelectedIds","clickAction"]),R=t({}),K=u(_({data:l,defaultExpandedIds:N,defaultSelectedIds:L,nodeRefs:R,onSelect:s,onExpand:p,multiSelect:I,propagateSelectUpwards:w}),2),T=K[0],G=K[1];return b=b&&I,e.createElement("ul",i({className:n(E.root,S),role:"tree","aria-multiselectable":I,ref:r,onKeyDown:M({data:l,tabbableId:T.tabbableId,expandedIds:T.expandedIds,selectedIds:T.selectedIds,halfSelectedIds:T.halfSelectedIds,dispatch:G,propagateCollapse:x,propagateSelect:b,multiSelect:I,expandOnKeyboardSelect:A,togglableSelect:C})},U),l[0].children.map(function(t,a){return e.createElement(H,{key:t,selectedIds:T.selectedIds,tabbableId:T.tabbableId,expandedIds:T.expandedIds,halfSelectedIds:T.halfSelectedIds,lastStandardSelect:T.lastStandardSelect,lastInteractedWith:T.lastInteractedWith,dispatch:G,data:l,element:l[t],nodeRefs:R,baseClassNames:E,nodeRenderer:d,setsize:l[0].children.length,posinset:a+1,level:1,propagateCollapse:x,propagateSelect:b,multiSelect:I,togglableSelect:C,clickAction:P})}))}),H=function t(a){var r=a.element,l=a.dispatch,i=a.data,c=a.selectedIds,s=a.tabbableId,o=a.expandedIds,u=a.halfSelectedIds,h=a.lastStandardSelect,S=a.nodeRefs,I=a.baseClassNames,b=a.nodeRenderer,m=a.setsize,x=a.posinset,E=a.level,A=a.propagateCollapse,C=a.propagateSelect,k=a.multiSelect,N=a.togglableSelect,L=a.clickAction,T=a.lastInteractedWith,_=function(e){if(!(e.ctrlKey||e.altKey||e.shiftKey))if(o.has(r.id)&&A){var t=[r.id].concat(f(y(i,r.id)));l({type:O,ids:t,lastInteractedWith:r.id})}else l({type:D,id:r.id,lastInteractedWith:r.id})},F=function(e){if(e.shiftKey){var t=function(e){var t=e.data,a=e.expandedIds,r=e.from,n=e.to,l=[],d=Object.keys(t).length,i=0,c=r;if(l.push(r),r<n)for(;i<d&&(c=g(t,c,a),l.push(c),null!=c&&c!==n);)i+=1;else if(r>n)for(;i<d&&(c=w(t,c,a),l.push(c),null!=c&&c!==n);)i+=1;return l}({data:i,expandedIds:o,from:h,to:r.id,lastInteractedWith:r.id});t=new Set(t.concat(t.filter(function(e){return v(i,e)}).flatMap(function(e){return y(i,e)}))),l({type:R,select:!0,multiSelect:k,ids:t,lastInteractedWith:r.id})}else e.ctrlKey||L===z.select?(l(N?{type:P,id:r.id,multiSelect:k}:{type:j,id:r.id,multiSelect:k}),C&&l({type:U,ids:y(i,r.id),select:!c.has(r.id),multiSelect:k,lastInteractedWith:r.id})):L===z.exclusiveSelect?l(N?{type:P,id:r.id,multiSelect:!1,lastInteractedWith:r.id}:{type:j,id:r.id,multiSelect:!1,lastInteractedWith:r.id}):L===z.focus&&l({type:K,id:r.id,lastInteractedWith:r.id})},G=function(e){var t;return n(e,(d(t={},"".concat(e,"--expanded"),o.has(r.id)),d(t,"".concat(e,"--selected"),c.has(r.id)),t))};return v(i,r.id)?e.createElement("li",{role:"treeitem","aria-expanded":o.has(r.id),"aria-selected":W(c.has(r.id),k),"aria-setsize":m,"aria-posinset":x,"aria-level":E,tabIndex:s===r.id?0:-1,ref:function(e){return S.current[r.id]=e},className:n(G(I.node),I.branch)},b({element:r,isBranch:v(i,r.id),isSelected:c.has(r.id),isHalfSelected:u.has(r.id),isExpanded:o.has(r.id),tabbableId:s,dispatch:l,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onClick;return{onClick:p(t,_),className:G(I.branchWrapper)}},setsize:m,posinset:x,level:E,handleSelect:F,handleExpand:_}),o.has(r.id)&&e.createElement("ul",{role:"group",className:G(I.nodeGroup)},r.children.map(function(a,n){return e.createElement(t,{key:a,selectedIds:c,tabbableId:s,expandedIds:o,halfSelectedIds:u,lastStandardSelect:h,dispatch:l,data:i,element:i[a],nodeRefs:S,baseClassNames:I,nodeRenderer:b,setsize:r.children.length,posinset:n+1,level:E+1,propagateCollapse:A,propagateSelect:C,multiSelect:k,togglableSelect:N,clickAction:L,lastInteractedWith:T})}))):e.createElement("li",{role:"none",className:G(I.leafListItem)},b({element:r,isBranch:v(i,r.id),isSelected:c.has(r.id),isHalfSelected:u.has(r.id),isExpanded:o.has(r.id),tabbableId:s,dispatch:l,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onClick;return{role:"treeitem",tabIndex:s===r.id?0:-1,onClick:p(t),ref:function(e){return S.current[r.id]=e},className:n(G(I.node),I.leaf),"aria-setsize":m,"aria-posinset":x,"aria-level":E,"aria-selected":W(c.has(r.id),k)}},setsize:m,posinset:x,level:E,handleSelect:F,handleExpand:_}))},M=function(e){var t=e.data,a=e.expandedIds,r=e.selectedIds,n=e.tabbableId,l=e.dispatch,d=e.propagateCollapse,i=e.propagateSelect,c=e.multiSelect,s=e.expandOnKeyboardSelect,u=e.togglableSelect;return function(e){var p=t[n],h=p.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();t[0];var S=o(t,["0"]),b=Object.values(S);l({type:U,multiSelect:c,select:r.size!==b.length,ids:new Set(Object.values(S).map(function(e){return e.id})),lastInteractedWith:p.id})}}else{if(e.shiftKey)switch(e.key){case"ArrowUp":e.preventDefault();var x=w(t,h,a);return void(null!=x&&l({type:j,id:x,multiSelect:c,lastInteractedWith:x}));case"ArrowDown":e.preventDefault();var W=g(t,h,a);return void(null!=W&&l({type:j,id:W,multiSelect:c,lastInteractedWith:W}))}switch(e.key){case"ArrowDown":e.preventDefault();var E=g(t,h,a);return void(null!=E&&l({type:K,id:E,lastInteractedWith:E}));case"ArrowUp":e.preventDefault();var N=w(t,h,a);return void(null!=N&&l({type:K,id:N,lastInteractedWith:N}));case"ArrowLeft":if(e.preventDefault(),v(t,h)&&a.has(n))if(d){var L=[h].concat(f(y(t,h)));l({type:O,ids:L,lastInteractedWith:p.id})}else l({type:A,id:h,lastInteractedWith:h});else if(!t[0].children.includes(h)){var R=I(t,h);l({type:K,id:R,lastInteractedWith:R})}return;case"ArrowRight":return e.preventDefault(),void(v(t,h)&&(a.has(n)?l({type:K,id:p.children[0],lastInteractedWith:p.children[0]}):l({type:C,id:h,lastInteractedWith:h})));case"Home":e.preventDefault(),l({type:K,id:t[0].children[0]});break;case"End":e.preventDefault();var T=m(t,t[0].id,a);return void l({type:K,id:T,lastInteractedWith:T});case"*":e.preventDefault();var _=t[I(t,h)].children.filter(function(e){return v(t,e)});return void l({type:k,ids:_,lastInteractedWith:h});case"Enter":case" ":case"Spacebar":return e.preventDefault(),l(u?{type:P,id:h,multiSelect:c,lastInteractedWith:h}:{type:j,id:h,multiSelect:c,lastInteractedWith:h}),s&&l({type:D,id:h,lastInteractedWith:h}),void(i&&l({type:U,ids:y(t,h),select:!r.has(h),multiSelect:c,lastInteractedWith:h}));default:if(1===e.key.length)for(var z=g(t,h,a);z!==h;)if(null!=z){if(t[z].name[0].toLowerCase()===e.key.toLowerCase())return void l({type:K,id:z,lastInteractedWith:h});z=g(t,z,a)}else z=t[0].children[0];return}}}};G.propTypes={data:l.array.isRequired,onSelect:l.func,onExpand:l.func,className:l.string,nodeRenderer:l.func.isRequired,defaultExpandedIds:l.array,defaultSelectedIds:l.array,propagateCollapse:l.bool,propagateSelect:l.bool,propagateSelectUpwards:l.bool,multiSelect:l.bool,expandOnKeyboardSelect:l.bool,togglableSelect:l.bool,clickAction:l.oneOf(Object.values(z))};export default G;export{x as flattenTree}; | ||
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}; |
{ | ||
"name": "react-accessible-treeview", | ||
"description": "A react component that implements the treeview pattern as described by the WAI-ARIA Authoring Practices.", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"author": "lissitz (https://github.com/lissitz)", | ||
@@ -11,3 +11,3 @@ "main": "dist/react-accessible-treeview.cjs.js", | ||
"prop-types": "^15.7.2", | ||
"react": "^16.8.6" | ||
"react": "^16.8.0" | ||
}, | ||
@@ -32,3 +32,3 @@ "devDependencies": { | ||
"prettier": "^1.18.2", | ||
"react": "^16.8.6", | ||
"react": "^16.8.0", | ||
"react-docgen": "^4.1.1", | ||
@@ -35,0 +35,0 @@ "react-dom": "^16.8.6", |
@@ -25,2 +25,3 @@ # react-accessible-treeview | ||
| `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 | | ||
@@ -84,2 +85,3 @@ | ||
| `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 | | ||
@@ -86,0 +88,0 @@ <br/> <br/> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59628
162
140
1