react-accessible-treeview
Advanced tools
Comparing version 2.0.0 to 2.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,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; | ||
"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 s,d=e[Symbol.iterator]();!(r=(s=d.next()).done)&&(a.push(s.value),!t||a.length!==t);r=!0);}catch(e){n=!0,l=e}finally{try{r||null==d.return||d.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 s,d=e[Symbol.iterator]();!(r=(s=d.next()).done);r=!0){var i=s.value;t.has(i)||a.add(i)}}catch(e){n=!0,l=e}finally{try{r||null==d.return||d.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 s=!0,d=!1,i=void 0;try{for(var c,o=l.children.filter(function(e){return!a.has(e)})[Symbol.iterator]();!(s=(c=o.next()).done);s=!0){var u=c.value;r.push(u),e(t,u)}}catch(e){d=!0,i=e}finally{try{s||null==o.return||o.return()}finally{if(d)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,s=!1,d=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){s=!0,d=e}finally{try{l||null==c.return||c.return()}finally{if(s)throw d}}return n},getAccessibleRange=function(e){var t=e.data,a=e.expandedIds,r=e.from,n=e.to,l=[],s=Object.keys(t).length,d=0,i=r;if(l.push(r),r<n)for(;d<s&&(i=getNextAccessible(t,i,a),l.push(i),null!=i&&i!==n);)d+=1;else if(r>n)for(;d<s&&(i=getPreviousAccessible(t,i,a),l.push(i),null!=i&&i!==n);)d+=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,s=!1,d=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){s=!0,d=e}finally{try{l||null==c.return||c.return()}finally{if(s)throw d}}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,s=void 0;try{for(var d,i=t.ids[Symbol.iterator]();!(n=(d=i.next()).done);n=!0){var c=d.value;r.delete(c)}}catch(e){l=!0,s=e}finally{try{n||null==i.return||i.return()}finally{if(l)throw s}}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,lastUserSelect:t.NotUserAction?e.lastUserSelect: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,lastUserSelect:t.NotUserAction?e.lastUserSelect: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,lastUserSelect:t.NotUserAction?e.lastUserSelect: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,s=e.onSelect,d=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,lastUserSelect: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(s!==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 d=n.value,i=isBranchNode(t,d);s({element:t[d],isBranch:i,isExpanded:i?h.has(d):void 0,isSelected:f.has(d),isDisabled:y.has(d),isHalfSelected:i?S.has(d):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,s,u]);var T=usePrevious(h)||new Set;return React.useEffect(function(){var e=symmetricDifference(h,T);if(d!==noop){var a=!0,r=!1,n=void 0;try{for(var l,s=e[Symbol.iterator]();!(a=(l=s.next()).done);a=!0){var i=l.value;d({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==s.return||s.return()}finally{if(r)throw n}}}},[t,f,h,y,S,T,d,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,s=!0,d=!1,o=void 0;try{for(var u,h=r[Symbol.iterator]();!(s=(u=h.next()).done);s=!0){var b=u.value;f.has(b)||p({type:treeTypes.select,id:b,multiSelect:i,keepFocus:!0,NotUserAction:!0,lastInteractedWith:v})}}catch(e){d=!0,o=e}finally{try{s||null==h.return||h.return()}finally{if(d)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,s=e.onExpand,d=void 0===s?noop:s,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=e.onBlur,N=_objectWithoutProperties(e,["data","nodeRenderer","onSelect","onExpand","className","multiSelect","propagateSelect","propagateSelectUpwards","propagateCollapse","expandOnKeyboardSelect","togglableSelect","defaultExpandedIds","defaultSelectedIds","defaultDisabledIds","clickAction","onBlur"]),R=React.useRef({}),O=_slicedToArray(useTree({data:a,defaultExpandedIds:A,defaultSelectedIds:x,defaultDisabledIds:E,nodeRefs:R,onSelect:l,onExpand:d,multiSelect:u,propagateSelect:f,propagateSelectUpwards:y}),2),j=O[0],D=O[1];f=f&&u;var k=React.useRef();return null!=t&&(k=t),React__default.createElement("ul",_extends({className:cx(baseClassNames.root,c),role:"tree","aria-multiselectable":u,ref:k,onBlur:function(e){return onComponentBlur(e,k.current,function(){C&&C({treeState:j,dispatch:D}),D({type:treeTypes.blur})})},onKeyDown:handleKeyDown({data:a,tabbableId:j.tabbableId,expandedIds:j.expandedIds,selectedIds:j.selectedIds,disabledIds:j.disabledIds,halfSelectedIds:j.halfSelectedIds,dispatch:D,propagateCollapse:S,propagateSelect:f,multiSelect:u,expandOnKeyboardSelect:v,togglableSelect:m})},N),a[0].children.map(function(e,t){return React__default.createElement(Node,{key:e,selectedIds:j.selectedIds,tabbableId:j.tabbableId,isFocused:j.isFocused,expandedIds:j.expandedIds,disabledIds:j.disabledIds,halfSelectedIds:j.halfSelectedIds,lastUserSelect:j.lastUserSelect,lastInteractedWith:j.lastInteractedWith,dispatch:D,data:a,element:a[e],nodeRefs:R,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:j})}))}),Node=function e(t){var a=t.element,r=t.dispatch,n=t.data,l=t.selectedIds,s=t.tabbableId,d=t.isFocused,i=t.expandedIds,c=t.disabledIds,o=t.halfSelectedIds,u=t.lastUserSelect,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,new Set)));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"),s===a.id&&d),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:s===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:s,isFocused:d,expandedIds:i,halfSelectedIds:o,disabledIds:c,lastUserSelect: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:s===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,s=e.dispatch,d=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)});s({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)});s({type:treeTypes.changeSelectMany,multiSelect:c,select:!0,ids:i?propagatedIds(t,S,n):S}),s({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)||(s({type:treeTypes.changeSelectMany,ids:i?propagatedIds(t,[I],n):[I],select:!0,multiSelect:c,lastInteractedWith:I}),s({type:treeTypes.focus,id:I,lastInteractedWith:I})));case"ArrowDown":e.preventDefault();var v=getNextAccessible(t,f,a);return void(null==v&&n.has(v)||(s({type:treeTypes.changeSelectMany,ids:i?propagatedIds(t,[v],n):[v],multiSelect:c,select:!0,lastInteractedWith:v}),s({type:treeTypes.focus,id:v,lastInteractedWith:v})))}switch(e.key){case"ArrowDown":e.preventDefault();var g=getNextAccessible(t,f,a);return void(null!=g&&s({type:treeTypes.focus,id:g,lastInteractedWith:g}));case"ArrowUp":e.preventDefault();var m=getPreviousAccessible(t,f,a);return void(null!=m&&s({type:treeTypes.focus,id:m,lastInteractedWith:m}));case"ArrowLeft":if(e.preventDefault(),isBranchNode(t,f)&&a.has(l))if(d){var T=[f].concat(_toConsumableArray(getDescendants(t,f,new Set)));s({type:treeTypes.collapseMany,ids:T,lastInteractedWith:p.id})}else s({type:treeTypes.collapse,id:f,lastInteractedWith:f});else if(!t[0].children.includes(f)){var A=getParent(t,f);s({type:treeTypes.focus,id:A,lastInteractedWith:A})}return;case"ArrowRight":return e.preventDefault(),void(isBranchNode(t,f)&&(a.has(l)?s({type:treeTypes.focus,id:p.children[0],lastInteractedWith:p.children[0]}):s({type:treeTypes.expand,id:f,lastInteractedWith:f})));case"Home":e.preventDefault(),s({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 s({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 s({type:treeTypes.expandMany,ids:x,lastInteractedWith:f});case"Enter":case" ":case"Spacebar":return e.preventDefault(),!n.has(f)&&s({type:treeTypes.changeSelectMany,ids:i?propagatedIds(t,[f],n):[f],select:!u||!r.has(f),multiSelect:c,lastInteractedWith:f}),void(o&&s({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 s({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 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}; | ||
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 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){d(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={},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 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,l=void 0;try{for(var d,i=e[Symbol.iterator]();!(r=(d=i.next()).done);r=!0){var s=d.value;t.has(s)||a.add(s)}}catch(e){n=!0,l=e}finally{try{r||null==i.return||i.return()}finally{if(n)throw l}}return a},I=function(e,t){return new Set([].concat(f(p(e,t)),f(p(t,e))))},v=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},y=function(e,t){return e[t].parent},b=function(e,t,a){var r=[];return function e(t,n){var l=t[n];if(null!=l.children){var d=!0,i=!1,s=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){i=!0,s=e}finally{try{d||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],l=n.children.indexOf(t)+a;if(n.children[l])return n.children[l]}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)&&S(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(S(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,l=[],d=Object.keys(t).length,i=0,s=r;if(l.push(r),r<n)for(;i<d&&(s=x(t,s,a),l.push(s),null!=s&&s!==n);)i+=1;else if(r>n)for(;i<d&&(s=g(t,s,a),l.push(s),null!=s&&s!==n);)i+=1;return l},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 l=!0,d=!1,i=void 0;try{for(var s,c=r.children[Symbol.iterator]();!(l=(s=c.next()).done);l=!0){e(s.value,r.id)}}catch(e){d=!0,i=e}finally{try{l||null==c.return||c.return()}finally{if(d)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 S(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",U="COLLAPSE_MANY",N="EXPAND",L="EXPAND_MANY",j="HALF_SELECT",F="SELECT",P="DESELECT",R="TOGGLE",T="TOGGLE_SELECT",K="SELECT_MANY",_="EXCLUSIVE_CHANGE_SELECT_MANY",B="FOCUS",H="BLUR",z="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 U:var r=new Set(e.expandedIds),n=!0,l=!1,d=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){l=!0,d=e}finally{try{n||null==s.return||s.return()}finally{if(l)throw d}}return c({},e,{expandedIds:r,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case N: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 L: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 j:if(e.disabledIds.has(t.id))return e;var v=new Set(e.halfSelectedIds),S=new Set(e.selectedIds);return v.add(t.id),S.delete(t.id),c({},e,{selectedIds:S,halfSelectedIds:v,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case F: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,lastUserSelect:t.NotUserAction?e.lastUserSelect: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,isFocused:!0,lastUserSelect:t.NotUserAction?e.lastUserSelect: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,lastUserSelect:t.NotUserAction?e.lastUserSelect: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 B:return c({},e,{tabbableId:t.id,isFocused:!0,lastAction:t.type,lastInteractedWith:t.lastInteractedWith});case H:return c({},e,{isFocused:!1});case z: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,l=e.defaultSelectedIds,d=e.defaultDisabledIds,i=e.nodeRefs,s=e.onSelect,c=e.onExpand,o=e.multiSelect,f=e.propagateSelectUpwards,h=u(r(M,{selectedIds:new Set(l),tabbableId:t[0].children[0],isFocused:!1,expandedIds:new Set(n),halfSelectedIds:new Set,lastUserSelect:t[0].children[0],lastInteractedWith:null,disabledIds:new Set(d)}),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=v(m)||new Set,k=I(m,O);a(function(){if(s!==q){var e=!0,a=!1,r=void 0;try{for(var n,l=k[Symbol.iterator]();!(e=(n=l.next()).done);e=!0){var d=n.value,i=S(t,d);s({element:t[d],isBranch:i,isExpanded:i?w.has(d):void 0,isSelected:m.has(d),isDisabled:g.has(d),isHalfSelected:i?E.has(d):void 0,treeState:p})}}catch(e){a=!0,r=e}finally{try{e||null==l.return||l.return()}finally{if(a)throw r}}}},[t,m,w,g,E,k,s,p]);var C=v(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 l,d=e[Symbol.iterator]();!(a=(l=d.next()).done);a=!0){var i=l.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==d.return||d.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},l=!0,d=!1,i=void 0;try{for(var s,c=t[Symbol.iterator]();!(l=(s=c.next()).done);l=!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){d=!0,i=e}finally{try{l||null==c.return||c.return()}finally{if(d)throw i}}return n}(t,e,m,g),r=a.every,n=a.some,l=a.none,d=!0,i=!1,s=void 0;try{for(var c,u=r[Symbol.iterator]();!(d=(c=u.next()).done);d=!0){var h=c.value;m.has(h)||b({type:F,id:h,multiSelect:o,keepFocus:!0,NotUserAction:!0,lastInteractedWith:A})}}catch(e){i=!0,s=e}finally{try{d||null==u.return||u.return()}finally{if(i)throw s}}var p=!0,I=!1,v=void 0;try{for(var S,w=n[Symbol.iterator]();!(p=(S=w.next()).done);p=!0){var x=S.value;E.has(x)||b({type:j,id:x,multiSelect:o,keepFocus:!0,NotUserAction:!0,lastInteractedWith:A})}}catch(e){I=!0,v=e}finally{try{p||null==w.return||w.return()}finally{if(I)throw v}}var W=!0,O=!1,C=void 0;try{for(var D,U=l[Symbol.iterator]();!(W=(D=U.next()).done);W=!0){var N=D.value;(m.has(N)||E.has(N))&&b({type:P,id:N,multiSelect:o,keepFocus:!0,NotUserAction:!0,lastInteractedWith:A})}}catch(e){O=!0,C=e}finally{try{W||null==U.return||U.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 l=a.data,d=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,v=a.multiSelect,S=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,E=a.expandOnKeyboardSelect,W=void 0!==E&&E,A=a.togglableSelect,O=void 0!==A&&A,D=a.defaultExpandedIds,U=void 0===D?[]:D,N=a.defaultSelectedIds,L=void 0===N?[]:N,j=a.defaultDisabledIds,F=void 0===j?[]:j,P=a.clickAction,R=void 0===P?Y.select:P,T=a.onBlur,K=o(a,["data","nodeRenderer","onSelect","onExpand","className","multiSelect","propagateSelect","propagateSelectUpwards","propagateCollapse","expandOnKeyboardSelect","togglableSelect","defaultExpandedIds","defaultSelectedIds","defaultDisabledIds","clickAction","onBlur"]),_=t({}),B=u(X({data:l,defaultExpandedIds:U,defaultSelectedIds:L,defaultDisabledIds:F,nodeRefs:_,onSelect:c,onExpand:h,multiSelect:S,propagateSelect:b,propagateSelectUpwards:w}),2),z=B[0],G=B[1];b=b&&S;var M=t();return null!=r&&(M=r),e.createElement("ul",i({className:n(C.root,I),role:"tree","aria-multiselectable":S,ref:M,onBlur:function(e){return k(e,M.current,function(){T&&T({treeState:z,dispatch:G}),G({type:H})})},onKeyDown:Q({data:l,tabbableId:z.tabbableId,expandedIds:z.expandedIds,selectedIds:z.selectedIds,disabledIds:z.disabledIds,halfSelectedIds:z.halfSelectedIds,dispatch:G,propagateCollapse:x,propagateSelect:b,multiSelect:S,expandOnKeyboardSelect:W,togglableSelect:O})},K),l[0].children.map(function(t,a){return e.createElement(J,{key:t,selectedIds:z.selectedIds,tabbableId:z.tabbableId,isFocused:z.isFocused,expandedIds:z.expandedIds,disabledIds:z.disabledIds,halfSelectedIds:z.halfSelectedIds,lastUserSelect:z.lastUserSelect,lastInteractedWith:z.lastInteractedWith,dispatch:G,data:l,element:l[t],nodeRefs:_,baseClassNames:C,nodeRenderer:d,setsize:l[0].children.length,posinset:a+1,level:1,propagateCollapse:x,propagateSelect:b,multiSelect:S,togglableSelect:O,clickAction:R,state:z})}))}),J=function t(a){var r=a.element,l=a.dispatch,i=a.data,s=a.selectedIds,c=a.tabbableId,o=a.isFocused,u=a.expandedIds,p=a.disabledIds,I=a.halfSelectedIds,v=a.lastUserSelect,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,N=a.togglableSelect,L=a.clickAction,j=a.lastInteractedWith,P=a.state,H=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,new Set)));l({type:U,ids:t,lastInteractedWith:r.id})}else l({type:R,id:r.id,lastInteractedWith:r.id})},z=function(){l({type:B,id:r.id,lastInteractedWith:r.id})},G=function(e){if(e.shiftKey){var t=E({data:i,expandedIds:u,from:v,to:r.id,lastInteractedWith:r.id}).filter(function(e){return!p.has(e)});t=C?O(i,t,p):t,l({type:_,select:!0,multiSelect:D,ids:t,lastInteractedWith:r.id})}else e.ctrlKey||L===Y.select?(l({type:N?T:F,id:r.id,multiSelect:D,lastInteractedWith:r.id}),C&&!p.has(r.id)&&l({type:K,ids:O(i,[r.id],p),select:!N||!s.has(r.id),multiSelect:D,lastInteractedWith:r.id})):L===Y.exclusiveSelect?l({type:N?T:F,id:r.id,multiSelect:!1,lastInteractedWith:r.id}):L===Y.focus&&l({type:B,id:r.id,lastInteractedWith:r.id})},M=function(e){var t;return n(e,(d(t={},"".concat(e,"--expanded"),u.has(r.id)),d(t,"".concat(e,"--selected"),s.has(r.id)),d(t,"".concat(e,"--focused"),c===r.id&&o),t))};return S(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:l,getNodeProps:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.onClick;return{onClick:null==t?h(G,H,z):h(t,z),className:n(M(m.node),m.branch)}},setsize:g,posinset:x,level:W,handleSelect:G,handleExpand:H,treeState:P}),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,lastUserSelect:v,dispatch:l,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:N,clickAction:L,lastInteractedWith:j,state:P})}))):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:l,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,z),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:P}))},Q=function(e){var t=e.data,a=e.expandedIds,r=e.selectedIds,n=e.disabledIds,l=e.tabbableId,d=e.dispatch,i=e.propagateCollapse,s=e.propagateSelect,c=e.multiSelect,u=e.expandOnKeyboardSelect,h=e.togglableSelect;return function(e){var p=t[l],I=p.id;if(e.ctrlKey){if("a"===e.key){e.preventDefault();t[0];var v=o(t,["0"]),m=Object.values(v).map(function(e){return e.id}).filter(function(e){return!n.has(e)});d({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)});d({type:K,multiSelect:c,select:!0,ids:s?O(t,A,n):A}),d({type:B,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)||(d({type:K,ids:s?O(t,[k],n):[k],select:!0,multiSelect:c,lastInteractedWith:k}),d({type:B,id:k,lastInteractedWith:k})));case"ArrowDown":e.preventDefault();var C=x(t,I,a);return void(null==C&&n.has(C)||(d({type:K,ids:s?O(t,[C],n):[C],multiSelect:c,select:!0,lastInteractedWith:C}),d({type:B,id:C,lastInteractedWith:C})))}switch(e.key){case"ArrowDown":e.preventDefault();var j=x(t,I,a);return void(null!=j&&d({type:B,id:j,lastInteractedWith:j}));case"ArrowUp":e.preventDefault();var F=g(t,I,a);return void(null!=F&&d({type:B,id:F,lastInteractedWith:F}));case"ArrowLeft":if(e.preventDefault(),S(t,I)&&a.has(l))if(i){var P=[I].concat(f(b(t,I,new Set)));d({type:U,ids:P,lastInteractedWith:p.id})}else d({type:D,id:I,lastInteractedWith:I});else if(!t[0].children.includes(I)){var T=y(t,I);d({type:B,id:T,lastInteractedWith:T})}return;case"ArrowRight":return e.preventDefault(),void(S(t,I)&&(a.has(l)?d({type:B,id:p.children[0],lastInteractedWith:p.children[0]}):d({type:N,id:I,lastInteractedWith:I})));case"Home":e.preventDefault(),d({type:B,id:t[0].children[0],lastInteractedWith:t[0].children[0]});break;case"End":e.preventDefault();var _=w(t,t[0].id,a);return void d({type:B,id:_,lastInteractedWith:_});case"*":e.preventDefault();var H=t[y(t,I)].children.filter(function(e){return S(t,e)});return void d({type:L,ids:H,lastInteractedWith:I});case"Enter":case" ":case"Spacebar":return e.preventDefault(),!n.has(I)&&d({type:K,ids:s?O(t,[I],n):[I],select:!h||!r.has(I),multiSelect:c,lastInteractedWith:I}),void(u&&d({type:R,id:I,lastInteractedWith:I}));default:if(1===e.key.length)for(var z=x(t,I,a);z!==I;)if(null!=z){if(t[z].name[0].toLowerCase()===e.key.toLowerCase())return void d({type:B,id:z,lastInteractedWith:I});z=x(t,z,a)}else z=t[0].children[0];return}}}};V.propTypes={data:l.array.isRequired,onSelect:l.func,onExpand:l.func,className:l.string,nodeRenderer:l.func.isRequired,defaultExpandedIds:l.array,defaultSelectedIds:l.array,defaultDisabledIds: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(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": "2.0.0", | ||
"version": "2.1.0", | ||
"author": "lissitz (https://github.com/lissitz)", | ||
@@ -18,6 +18,8 @@ "main": "dist/react-accessible-treeview.cjs.js", | ||
"@babel/preset-react": "^7.0.0", | ||
"babel-eslint": "^10.0.2", | ||
"@storybook/addon-actions": "^5.1.11", | ||
"@storybook/addon-links": "^5.1.11", | ||
"@storybook/addons": "^5.1.11", | ||
"@storybook/react": "^5.1.11", | ||
"babel-loader": "^8.0.6", | ||
"classnames": "^2.2.6", | ||
"css-loader": "^3.1.0", | ||
"eslint": "^6.1.0", | ||
@@ -30,9 +32,6 @@ "eslint-config-react-app": "^5.0.0", | ||
"eslint-plugin-react-hooks": "^1.5.0", | ||
"lint-staged": "^9.2.1", | ||
"lint-staged": "^9.2.2", | ||
"prettier": "^1.18.2", | ||
"react": "^16.8.0", | ||
"react-docgen": "^4.1.1", | ||
"react-dom": "^16.8.6", | ||
"react-icons": "^3.7.0", | ||
"react-styleguidist": "^9.1.13", | ||
"rollup": "^1.16.7", | ||
@@ -42,9 +41,10 @@ "rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-node-resolve": "^5.1.0", | ||
"rollup-plugin-terser": "^5.1.1", | ||
"style-loader": "^1.0.0", | ||
"webpack": "^4.38.0" | ||
"rollup-plugin-terser": "^5.1.1" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"dev": "rollup -c -w" | ||
"dev": "rollup -c -w", | ||
"storybook": "start-storybook -p 6006", | ||
"build-storybook": "build-storybook", | ||
"prepare": "npm run build" | ||
}, | ||
@@ -61,3 +61,3 @@ "files": [ | ||
}, | ||
"homepage": "https://github.com/lissitz/react-accessible-treeview", | ||
"homepage": "https://react-accessible-treeview.netlify.com", | ||
"husky": { | ||
@@ -82,3 +82,4 @@ "hooks": { | ||
"tree" | ||
] | ||
], | ||
"dependencies": {} | ||
} |
@@ -13,6 +13,5 @@ # 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) | ||
**Documentation and demo** | ||
https://react-accessible-treeview.netlify.com/ | ||
[Documentation and demo](https://react-accessible-treeview.netlify.com) | ||
### Prop Types | ||
## Prop Types | ||
@@ -36,6 +35,7 @@ | Prop name | Type | Default value | Description | | ||
| `clickAction` | `enum` | `SELECT` | Action to perform on click. One of: EXCLUSIVE_SELECT, FOCUS, SELECT | | ||
| `onBlur` | `func` | `noop` | Custom onBlur event that is triggered when focusing out of the component as a whole (moving focus between the nodes won't trigger it). | | ||
<br/> <br/> | ||
### data | ||
## data | ||
@@ -72,7 +72,7 @@ An array of nodes. Nodes are objects with the following structure: | ||
The array can also be generated from a nested object using the <code>flattenTree</code> helper (see the examples below). | ||
The array can also be generated from a nested object using the `flattenTree` helper (see the examples below). | ||
<br/> <br/> | ||
### nodeRenderer | ||
## nodeRenderer | ||
@@ -100,3 +100,3 @@ - _Arguments_: An object containing the following properties: | ||
### onSelect | ||
## onSelect | ||
@@ -106,3 +106,3 @@ - _Arguments_: `onSelect({element, isBranch, isExpanded, isSelected, isHalfSelected, isDisabled, treeState })` | ||
### onExpand | ||
## onExpand | ||
@@ -114,28 +114,28 @@ - _Arguments_: `onExpand({element, isExpanded, isSelected, isHalfSelected, isDisabled, treeState})` | ||
### Keyboard Navigation | ||
## Keyboard Navigation | ||
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. | ||
| Key | Function | | ||
| -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `Enter` or `Space` | Updates the selected node to the current node and triggers `onSelect` | | ||
| <code>Down Arrow </code> | <ul><li>Moves focus to the next node that is tabbable without opening or closing a node.</li> <li>If focus is on the last node, does nothing.</li></ul> | | ||
| <code> Up arrow </code> | <ul><li> Moves focus to the previous node that is tabbable without opening or closing a node. </li><li> If focus is on the first node, does nothing.</li></ul> | | ||
| <code>Right Arrow </code> | <ul><li>When focus is on a closed node, opens the node; focus does not move.</li> <li> When focus is on an end node, does nothing.</li><li> When focus is on a open node, moves focus to the first child node. </li></ul> | | ||
| <code>Left Arrow </code> | <ul> <li>When focus is on an open node, closes the node.</li> <li>When focus is on a child node that is also either an end node or a closed node, moves focus to its parent node.</li> <li> When focus is on a root node that is also either an end node or a closed node, does nothing.</li> </ul> | | ||
| <code>Home</code> | Moves focus to first node without opening or closing a node. | | ||
| <code>End</code> | Moves focus to the last node that can be focused without expanding any nodes that are closed. | | ||
| <code>a-z, A-Z</code> | <ul> <li>Focus moves to the next node with a name that starts with the typed character.</li> <li>Search wraps to first node if a matching name is not found among the nodes that follow the focused node.</li> <li>Search ignores nodes that are descendants of closed nodes.</li> </ul> | | ||
| <code>\*</code> (asterisk) | <ul><li> Expands all closed sibling nodes that are at the same level as the focused node.</li><li> Focus does not move.</li></ul> | | ||
| <code>Shift + Down Arrow </code> | Moves focus to and toggles the selection state of the next node. | | ||
| <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, unselects all nodes. | | ||
| Key | Function | | ||
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `Enter` or `Space` | Updates the selected node to the current node and triggers `onSelect` | | ||
| `Down Arrow` | <ul><li>Moves focus to the next node that is tabbable without opening or closing a node.</li> <li>If focus is on the last node, does nothing.</li></ul> | | ||
| `Up arrow` | <ul><li> Moves focus to the previous node that is tabbable without opening or closing a node. </li><li> If focus is on the first node, does nothing.</li></ul> | | ||
| `Right Arrow` | <ul><li>When focus is on a closed node, opens the node; focus does not move.</li> <li> When focus is on an end node, does nothing.</li><li> When focus is on a open node, moves focus to the first child node. </li></ul> | | ||
| `Left Arrow` | <ul> <li>When focus is on an open node, closes the node.</li> <li>When focus is on a child node that is also either an end node or a closed node, moves focus to its parent node.</li> <li> When focus is on a root node that is also either an end node or a closed node, does nothing.</li> </ul> | | ||
| `Home` | Moves focus to first node without opening or closing a node. | | ||
| `End` | Moves focus to the last node that can be focused without expanding any nodes that are closed. | | ||
| `a-z, A-Z` | <ul> <li>Focus moves to the next node with a name that starts with the typed character.</li> <li>Search wraps to first node if a matching name is not found among the nodes that follow the focused node.</li> <li>Search ignores nodes that are descendants of closed nodes.</li> </ul> | | ||
| `*` (asterisk) | <ul><li> Expands all closed sibling nodes that are at the same level as the focused node.</li><li> Focus does not move.</li></ul> | | ||
| `Shift + Down Arrow` | Moves focus to and toggles the selection state of the next node. | | ||
| `Shift + Up Arrow` | Moves focus to and toggles the selection state of the previous node. | | ||
| `Ctrl + A` | Selects all nodes in the tree. If all nodes are selected, unselects all nodes. | | ||
<br/> <br/> | ||
### Mouse Navigation | ||
## Mouse Navigation | ||
| Key | Function | | ||
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `Click` | Toggles parent nodes and also performs one of clickActions = SELECT, EXCLUSIVE_SELECT, FOCUS | | ||
| `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. | | ||
@@ -146,3 +146,3 @@ | `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. | | ||
### Click actions | ||
## Click actions | ||
@@ -156,1 +156,16 @@ | Variant | Function | | ||
<br/> <br/> | ||
## treeState | ||
The internal state of the component. | ||
| Property | Type | Default | Description | | ||
| ------------------ | ---------------- | ----------------------------- | ---------------------------------------- | | ||
| selectedIds | `Set` | `new Set(defaultSelectedIds)` | Set of the ids of the selected nodes | | ||
| tabbableId | `number` | `data[0].children[0]` | if of the node with tabindex = 0 | | ||
| isFocused | `bool` | `false` | wether the tree has focus | | ||
| expandedIds | `Set` | `new Set(defaultExpandedIds)` | Set of the ids of the expanded nodes | | ||
| halfSelectedIds | `Set` | `new Set()` | Set of the ids of the selected nodes | | ||
| lastUserSelect | `number` | `data[0].children[0]` | Last selection made directly by the user | | ||
| lastInteractedWith | `number or null` | `null` | Last node interacted with | | ||
| disabledIds | `Set` | `new Set(defaultDisabledIds)` | Set of the ids of the selected nodes | |
@@ -145,5 +145,3 @@ import React, { useReducer, useRef, useEffect } from "react"; | ||
isFocused: true, | ||
lastStandardSelect: action.NotUserAction | ||
? state.lastStandardSelect | ||
: action.id, | ||
lastUserSelect: action.NotUserAction ? state.lastUserSelect : action.id, | ||
lastAction: action.type, | ||
@@ -170,5 +168,3 @@ lastInteractedWith: action.lastInteractedWith | ||
isFocused: true, | ||
lastStandardSelect: action.NotUserAction | ||
? state.lastStandardSelect | ||
: action.id, | ||
lastUserSelect: action.NotUserAction ? state.lastUserSelect : action.id, | ||
lastAction: action.type, | ||
@@ -199,5 +195,3 @@ lastInteractedWith: action.lastInteractedWith | ||
isFocused: true, | ||
lastStandardSelect: action.NotUserAction | ||
? state.lastStandardSelect | ||
: action.id, | ||
lastUserSelect: action.NotUserAction ? state.lastUserSelect : action.id, | ||
lastAction: action.type, | ||
@@ -298,3 +292,3 @@ lastInteractedWith: action.lastInteractedWith | ||
halfSelectedIds: new Set(), | ||
lastStandardSelect: data[0].children[0], | ||
lastUserSelect: data[0].children[0], | ||
lastInteractedWith: null, | ||
@@ -466,2 +460,3 @@ disabledIds: new Set(defaultDisabledIds) | ||
clickAction = clickActions.select, | ||
onBlur, | ||
...other | ||
@@ -497,2 +492,7 @@ }, | ||
onComponentBlur(event, innerRef.current, () => { | ||
onBlur && | ||
onBlur({ | ||
treeState: state, | ||
dispatch | ||
}); | ||
dispatch({ type: treeTypes.blur }); | ||
@@ -526,3 +526,3 @@ }) | ||
halfSelectedIds={state.halfSelectedIds} | ||
lastStandardSelect={state.lastStandardSelect} | ||
lastUserSelect={state.lastUserSelect} | ||
lastInteractedWith={state.lastInteractedWith} | ||
@@ -560,3 +560,3 @@ dispatch={dispatch} | ||
halfSelectedIds, | ||
lastStandardSelect, | ||
lastUserSelect, | ||
nodeRefs, | ||
@@ -579,3 +579,3 @@ baseClassNames, | ||
if (expandedIds.has(element.id) && propagateCollapse) { | ||
const ids = [element.id, ...getDescendants(data, element.id, [])]; | ||
const ids = [element.id, ...getDescendants(data, element.id, new Set())]; | ||
dispatch({ | ||
@@ -608,3 +608,3 @@ type: treeTypes.collapseMany, | ||
expandedIds, | ||
from: lastStandardSelect, | ||
from: lastUserSelect, | ||
to: element.id, | ||
@@ -738,3 +738,3 @@ lastInteractedWith: element.id | ||
disabledIds={disabledIds} | ||
lastStandardSelect={lastStandardSelect} | ||
lastUserSelect={lastUserSelect} | ||
dispatch={dispatch} | ||
@@ -920,3 +920,3 @@ data={data} | ||
if (propagateCollapse) { | ||
const ids = [id, ...getDescendants(data, id, [])]; | ||
const ids = [id, ...getDescendants(data, id, new Set())]; | ||
dispatch({ | ||
@@ -923,0 +923,0 @@ type: treeTypes.collapseMany, |
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
No website
QualityPackage does not have a website.
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
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
113921
26
1387
164
0
2