react-composable-treeview 1.0.16 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/dist/contexts/treeViewContext.d.ts +2 -1
- package/dist/hooks/useNodeMap.d.ts +3 -2
- package/dist/index.cjs +9 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +440 -417
- package/dist/index.js.map +1 -1
- package/dist/treeView.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,12 +53,13 @@ The `focus` state keep track of the curent focused item or group. This state is
|
|
|
53
53
|
|
|
54
54
|
Contains all the parts of an tree view
|
|
55
55
|
|
|
56
|
-
| Prop
|
|
57
|
-
|
|
|
58
|
-
| value
|
|
59
|
-
| defaultValue
|
|
60
|
-
|
|
|
61
|
-
|
|
|
56
|
+
| Prop | Type | Default |
|
|
57
|
+
| ----------------- | ----------------------- | ----------- |
|
|
58
|
+
| value | `Set<string>` | `new Set()` |
|
|
59
|
+
| defaultValue | `Set<string>` | `new Set()` |
|
|
60
|
+
| defaultSelection | `string` | - |
|
|
61
|
+
| onValueChange | `(Set<string>) => void` | - |
|
|
62
|
+
| draggable | `boolean` | `false` |
|
|
62
63
|
|
|
63
64
|
### Group
|
|
64
65
|
|
|
@@ -8,6 +8,7 @@ export interface TreeViewContextType {
|
|
|
8
8
|
setSelection: React.Dispatch<React.SetStateAction<string>>;
|
|
9
9
|
focus: React.MutableRefObject<string>;
|
|
10
10
|
nodeMap: useNodeMapHook[0];
|
|
11
|
-
|
|
11
|
+
registerNode: useNodeMapHook[1];
|
|
12
|
+
removeNode: useNodeMapHook[2];
|
|
12
13
|
}
|
|
13
14
|
export declare const TreeViewContext: React.Context<TreeViewContextType>;
|
|
@@ -10,7 +10,8 @@ export interface TreeNode {
|
|
|
10
10
|
ref: React.RefObject<HTMLLIElement>;
|
|
11
11
|
}
|
|
12
12
|
export type useNodeMapHook = [
|
|
13
|
-
Record<string, TreeNode
|
|
14
|
-
(value: string, parent: string, index: number, isGroup: boolean, ref: React.RefObject<HTMLLIElement>) => void
|
|
13
|
+
React.RefObject<Record<string, TreeNode>>,
|
|
14
|
+
(value: string, parent: string, index: number, isGroup: boolean, ref: React.RefObject<HTMLLIElement>) => void,
|
|
15
|
+
(value: string) => void
|
|
15
16
|
];
|
|
16
17
|
export declare function useNodeMap(): useNodeMapHook;
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const h=require("react");var se={exports:{}},B={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var Ie;function lr(){if(Ie)return B;Ie=1;var n=h,i=Symbol.for("react.element"),o=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,s=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function R(u,f,P){var w,b={},x=null,j=null;P!==void 0&&(x=""+P),f.key!==void 0&&(x=""+f.key),f.ref!==void 0&&(j=f.ref);for(w in f)a.call(f,w)&&!l.hasOwnProperty(w)&&(b[w]=f[w]);if(u&&u.defaultProps)for(w in f=u.defaultProps,f)b[w]===void 0&&(b[w]=f[w]);return{$$typeof:i,type:u,key:x,ref:j,props:b,_owner:s.current}}return B.Fragment=o,B.jsx=R,B.jsxs=R,B}var K={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
`+
|
|
19
|
-
`),S=
|
|
20
|
-
`),E=
|
|
21
|
-
`+
|
|
17
|
+
*/var Ve;function dr(){return Ve||(Ve=1,process.env.NODE_ENV!=="production"&&function(){var n=h,i=Symbol.for("react.element"),o=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),l=Symbol.for("react.profiler"),R=Symbol.for("react.provider"),u=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),P=Symbol.for("react.suspense"),w=Symbol.for("react.suspense_list"),b=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),j=Symbol.for("react.offscreen"),O=Symbol.iterator,V="@@iterator";function N(e){if(e===null||typeof e!="object")return null;var r=O&&e[O]||e[V];return typeof r=="function"?r:null}var g=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function m(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),c=1;c<r;c++)t[c-1]=arguments[c];L("error",e,t)}}function L(e,r,t){{var c=g.ReactDebugCurrentFrame,v=c.getStackAddendum();v!==""&&(r+="%s",t=t.concat([v]));var _=t.map(function(p){return String(p)});_.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,_)}}var C=!1,A=!1,T=!1,D=!1,H=!1,G;G=Symbol.for("react.module.reference");function Le(e){return!!(typeof e=="string"||typeof e=="function"||e===a||e===l||H||e===s||e===P||e===w||D||e===j||C||A||T||typeof e=="object"&&e!==null&&(e.$$typeof===x||e.$$typeof===b||e.$$typeof===R||e.$$typeof===u||e.$$typeof===f||e.$$typeof===G||e.getModuleId!==void 0))}function $e(e,r,t){var c=e.displayName;if(c)return c;var v=r.displayName||r.name||"";return v!==""?t+"("+v+")":t}function le(e){return e.displayName||"Context"}function $(e){if(e==null)return null;if(typeof e.tag=="number"&&m("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case a:return"Fragment";case o:return"Portal";case l:return"Profiler";case s:return"StrictMode";case P:return"Suspense";case w:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case u:var r=e;return le(r)+".Consumer";case R:var t=e;return le(t._context)+".Provider";case f:return $e(e,e.render,"ForwardRef");case b:var c=e.displayName||null;return c!==null?c:$(e.type)||"Memo";case x:{var v=e,_=v._payload,p=v._init;try{return $(p(_))}catch{return null}}}return null}var Y=Object.assign,q=0,de,pe,ve,he,_e,ge,Re;function be(){}be.__reactDisabledLog=!0;function Ye(){{if(q===0){de=console.log,pe=console.info,ve=console.warn,he=console.error,_e=console.group,ge=console.groupCollapsed,Re=console.groupEnd;var e={configurable:!0,enumerable:!0,value:be,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}q++}}function Me(){{if(q--,q===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:Y({},e,{value:de}),info:Y({},e,{value:pe}),warn:Y({},e,{value:ve}),error:Y({},e,{value:he}),group:Y({},e,{value:_e}),groupCollapsed:Y({},e,{value:ge}),groupEnd:Y({},e,{value:Re})})}q<0&&m("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var te=g.ReactCurrentDispatcher,ne;function X(e,r,t){{if(ne===void 0)try{throw Error()}catch(v){var c=v.stack.trim().match(/\n( *(at )?)/);ne=c&&c[1]||""}return`
|
|
18
|
+
`+ne+e}}var oe=!1,Z;{var We=typeof WeakMap=="function"?WeakMap:Map;Z=new We}function me(e,r){if(!e||oe)return"";{var t=Z.get(e);if(t!==void 0)return t}var c;oe=!0;var v=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var _;_=te.current,te.current=null,Ye();try{if(r){var p=function(){throw Error()};if(Object.defineProperty(p.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(p,[])}catch(F){c=F}Reflect.construct(e,[],p)}else{try{p.call()}catch(F){c=F}e.call(p.prototype)}}else{try{throw Error()}catch(F){c=F}e()}}catch(F){if(F&&c&&typeof F.stack=="string"){for(var d=F.stack.split(`
|
|
19
|
+
`),S=c.stack.split(`
|
|
20
|
+
`),E=d.length-1,y=S.length-1;E>=1&&y>=0&&d[E]!==S[y];)y--;for(;E>=1&&y>=0;E--,y--)if(d[E]!==S[y]){if(E!==1||y!==1)do if(E--,y--,y<0||d[E]!==S[y]){var k=`
|
|
21
|
+
`+d[E].replace(" at new "," at ");return e.displayName&&k.includes("<anonymous>")&&(k=k.replace("<anonymous>",e.displayName)),typeof e=="function"&&Z.set(e,k),k}while(E>=1&&y>=0);break}}}finally{oe=!1,te.current=_,Me(),Error.prepareStackTrace=v}var W=e?e.displayName||e.name:"",Fe=W?X(W):"";return typeof e=="function"&&Z.set(e,Fe),Fe}function Ue(e,r,t){return me(e,!1)}function Ge(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function Q(e,r,t){if(e==null)return"";if(typeof e=="function")return me(e,Ge(e));if(typeof e=="string")return X(e);switch(e){case P:return X("Suspense");case w:return X("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case f:return Ue(e.render);case b:return Q(e.type,r,t);case x:{var c=e,v=c._payload,_=c._init;try{return Q(_(v),r,t)}catch{}}}return""}var ee=Object.prototype.hasOwnProperty,Ee={},ye=g.ReactDebugCurrentFrame;function re(e){if(e){var r=e._owner,t=Q(e.type,e._source,r?r.type:null);ye.setExtraStackFrame(t)}else ye.setExtraStackFrame(null)}function qe(e,r,t,c,v){{var _=Function.call.bind(ee);for(var p in e)if(_(e,p)){var d=void 0;try{if(typeof e[p]!="function"){var S=Error((c||"React class")+": "+t+" type `"+p+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[p]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw S.name="Invariant Violation",S}d=e[p](r,p,c,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(E){d=E}d&&!(d instanceof Error)&&(re(v),m("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",c||"React class",t,p,typeof d),re(null)),d instanceof Error&&!(d.message in Ee)&&(Ee[d.message]=!0,re(v),m("Failed %s type: %s",t,d.message),re(null))}}}var Be=Array.isArray;function ae(e){return Be(e)}function Ke(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function Je(e){try{return we(e),!1}catch{return!0}}function we(e){return""+e}function xe(e){if(Je(e))return m("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ke(e)),we(e)}var Ce=g.ReactCurrentOwner,ze={key:!0,ref:!0,__self:!0,__source:!0},Te,Se;function He(e){if(ee.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function Xe(e){if(ee.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function Ze(e,r){typeof e.ref=="string"&&Ce.current}function Qe(e,r){{var t=function(){Te||(Te=!0,m("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function er(e,r){{var t=function(){Se||(Se=!0,m("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var rr=function(e,r,t,c,v,_,p){var d={$$typeof:i,type:e,key:r,ref:t,props:p,_owner:_};return d._store={},Object.defineProperty(d._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(d,"_self",{configurable:!1,enumerable:!1,writable:!1,value:c}),Object.defineProperty(d,"_source",{configurable:!1,enumerable:!1,writable:!1,value:v}),Object.freeze&&(Object.freeze(d.props),Object.freeze(d)),d};function tr(e,r,t,c,v){{var _,p={},d=null,S=null;t!==void 0&&(xe(t),d=""+t),Xe(r)&&(xe(r.key),d=""+r.key),He(r)&&(S=r.ref,Ze(r,v));for(_ in r)ee.call(r,_)&&!ze.hasOwnProperty(_)&&(p[_]=r[_]);if(e&&e.defaultProps){var E=e.defaultProps;for(_ in E)p[_]===void 0&&(p[_]=E[_])}if(d||S){var y=typeof e=="function"?e.displayName||e.name||"Unknown":e;d&&Qe(p,y),S&&er(p,y)}return rr(e,d,S,v,c,Ce.current,p)}}var ie=g.ReactCurrentOwner,Pe=g.ReactDebugCurrentFrame;function M(e){if(e){var r=e._owner,t=Q(e.type,e._source,r?r.type:null);Pe.setExtraStackFrame(t)}else Pe.setExtraStackFrame(null)}var ue;ue=!1;function ce(e){return typeof e=="object"&&e!==null&&e.$$typeof===i}function Oe(){{if(ie.current){var e=$(ie.current.type);if(e)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+e+"`."}return""}}function nr(e){return""}var
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function nr(e){return""}var ke={};function or(e){{var r=Oe();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+
|
|
25
|
+
Check the top-level render call using <`+t+">.")}return r}}function je(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=or(r);if(ke[t])return;ke[t]=!0;var c="";e&&e._owner&&e._owner!==ie.current&&(c=" It was passed a child from "+$(e._owner.type)+"."),M(e),m('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,c),M(null)}}function De(e,r){{if(typeof e!="object")return;if(ae(e))for(var t=0;t<e.length;t++){var c=e[t];ce(c)&&je(c,r)}else if(ce(e))e._store&&(e._store.validated=!0);else if(e){var v=N(e);if(typeof v=="function"&&v!==e.entries)for(var _=v.call(e),p;!(p=_.next()).done;)ce(p.value)&&je(p.value,r)}}}function ar(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===f||r.$$typeof===b))t=r.propTypes;else return;if(t){var c=$(r);qe(t,e.props,"prop",c,e)}else if(r.PropTypes!==void 0&&!ue){ue=!0;var v=$(r);m("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",v||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&m("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ir(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var c=r[t];if(c!=="children"&&c!=="key"){M(e),m("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",c),M(null);break}}e.ref!==null&&(M(e),m("Invalid attribute `ref` supplied to `React.Fragment`."),M(null))}}function Ae(e,r,t,c,v,_){{var p=Le(e);if(!p){var d="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(d+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var S=nr();S?d+=S:d+=Oe();var E;e===null?E="null":ae(e)?E="array":e!==void 0&&e.$$typeof===i?(E="<"+($(e.type)||"Unknown")+" />",d=" Did you accidentally export a JSX literal instead of a component?"):E=typeof e,m("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",E,d)}var y=tr(e,r,t,v,_);if(y==null)return y;if(p){var k=r.children;if(k!==void 0)if(c)if(ae(k)){for(var W=0;W<k.length;W++)De(k[W],e);Object.freeze&&Object.freeze(k)}else m("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else De(k,e)}return e===a?ir(y):ar(y),y}}function ur(e,r,t){return Ae(e,r,t,!0)}function cr(e,r,t){return Ae(e,r,t,!1)}var sr=cr,fr=ur;K.Fragment=a,K.jsx=sr,K.jsxs=fr}()),K}process.env.NODE_ENV==="production"?se.exports=lr():se.exports=dr();var I=se.exports;const z=h.createContext({rootValue:new Set,setRootValue:()=>{},selection:null,setSelection:()=>{},focus:{current:""},nodeMap:{current:{}},registerNode:()=>{},removeNode:()=>{}});function pr(){const n=h.useRef({__root__:{value:"__root__",parent:"",children:{},index:0,childrenLength:0,isGroup:!0,ref:{current:null}}});return[n,(a,s,l,R,u)=>{if(n.current==null)return;const f=n.current;f[a]={value:a,parent:s,children:{},childrenLength:0,index:l,isGroup:R,ref:u},f[s].children[l]=a,(l+1>f[s].childrenLength||f[f[s].childrenLength-1]==null)&&(f[s].childrenLength=l+1)},a=>{if(n.current==null)return;const s=n.current[a],l=n.current[s.parent];for(delete l.children[s.index];l.childrenLength>0&&l.children[l.childrenLength-1]==null;)l.childrenLength-=1;delete n.current[a]}]}const U=h.createContext({parent:"",getIndex:()=>-1,depth:-1});function vr(n,i,o){const[a,s]=h.useState(o),l=n!==void 0?n:a;return[l,u=>{const f=typeof u=="function"?u(l):u;i&&i(f),s(f)}]}function J(n,i){return function(a){const s=a.defaultPrevented;s&&(a.defaultPrevented=!1),n==null||n(a);let l;return a.defaultPrevented||(l=i==null?void 0:i(a),s&&(a.defaultPrevented=!0)),l}}function fe(...n){return h.useCallback(i=>{for(const o of n)typeof o=="function"?o(i):o!=null&&(o.current=i)},[n])}function Ne(){let n=-1;const i={};function o(a){return i[a]==null&&(i[a]=++n),i[a]}return o}const hr=["ArrowRight","ArrowUp","ArrowLeft","ArrowDown","Home","End","Enter"];function _r(n,i){var s;const o=n.current;if(!o)return;const a=o[i].children[0];a!=null&&((s=o[a].ref.current)==null||s.focus())}function gr(n,i){var s;const o=n.current;if(!o)return;const a=o[i].parent;a!="__root__"&&((s=o[a].ref.current)==null||s.focus())}function Rr(n,i){var l,R;const o=n.current;if(!o)return;const a=o[i].parent,s=o[i].index;if(s!=0){let u=o[a].children[s-1],f;for(;o[u].isGroup&&(f=o[u].children[o[u].childrenLength-1],!(f==null||o[f].ref.current==null));)u=f;(l=o[u].ref.current)==null||l.focus();return}a!="__root__"&&((R=o[a].ref.current)==null||R.focus())}function br(n,i){var l,R;const o=n.current;if(!o)return;if(o[i].isGroup){const u=(l=o[o[i].children[0]])==null?void 0:l.ref.current;if(u){u.focus();return}}let a,s;for(;a=o[i].parent,s=o[a].children[o[i].index+1],s==null;){if(a=="__root__")return;i=a}(R=o[s].ref.current)==null||R.focus()}function mr(n){var a;const i=n.current;if(!i)return;const o=i.__root__.children[0];(a=i[o].ref.current)==null||a.focus()}function Er(n){var s;const i=n.current;if(!i)return;let o="__root__",a;for(;i[o].isGroup&&(a=i[o].children[i[o].childrenLength-1],!(a==null||i[a].ref.current==null));)o=a;(s=i[o].ref.current)==null||s.focus()}const yr=h.forwardRef(({value:n,onValueChange:i,defaultValue:o,defaultSelection:a,onKeyDown:s,...l},R)=>{const[u,f,P]=pr(),w=Ne(),[b,x]=vr(n,i,o??new Set),[j,O]=h.useState(""),V=h.useRef(null),N=fe(V,R),g=h.useRef(""),m=h.useCallback(C=>{var A;if(!(!hr.includes(C.key)||!u))switch(C.key){case"ArrowRight":if(!((A=u.current)!=null&&A[g.current].isGroup))break;C.preventDefault(),b.has(g.current)?_r(u,g.current):x(T=>new Set([...T,g.current]));break;case"ArrowLeft":C.preventDefault(),b.has(g.current)?x(T=>new Set([...T].filter(D=>D!==g.current))):gr(u,g.current);break;case"ArrowUp":C.preventDefault(),Rr(u,g.current);break;case"ArrowDown":C.preventDefault(),br(u,g.current);break;case"Home":C.preventDefault(),mr(u);break;case"End":C.preventDefault(),Er(u);break;case"Enter":C.preventDefault(),O(g.current),b.has(g.current)?x(T=>new Set([...T].filter(D=>D!==g.current))):x(T=>new Set([...T,g.current]));break}},[b]),L=J(s,m);return I.jsx(z.Provider,{value:{rootValue:b,setRootValue:x,selection:j,setSelection:O,focus:g,nodeMap:u,registerNode:f,removeNode:P},children:I.jsx(U.Provider,{value:{parent:"__root__",getIndex:w,depth:0},children:I.jsx("ul",{ref:N,role:"tree","aria-multiselectable":"false",onKeyDown:L,...l})})})}),wr=h.forwardRef(({value:n,onFocus:i,onClick:o,...a},s)=>{const{selection:l,setSelection:R,focus:u,nodeMap:f,registerNode:P,removeNode:w}=h.useContext(z),{parent:b,getIndex:x,depth:j}=h.useContext(U),O=h.useRef(null),V=fe(O,s),N=J(i,m),g=J(o,L);function m(A){var T,D,H,G;(H=(D=(T=f.current)==null?void 0:T[u.current])==null?void 0:D.ref.current)==null||H.setAttribute("tabindex","-1"),(G=O.current)==null||G.setAttribute("tabindex","0"),u.current=n,A.stopPropagation()}function L(){R(n)}const C=x(n);return u.current==""&&b=="__root__"&&C==0&&(u.current=n),h.useEffect(()=>(P(n,b,C,!1,O),()=>w(n)),[]),h.useEffect(()=>()=>{u.current==n&&(u.current="")},[]),I.jsx("li",{ref:V,role:"treeitem","aria-selected":l==n,tabIndex:u.current==n?0:-1,onFocus:N,onClick:g,"data-depth":j,...a})}),xr=h.forwardRef(({value:n,onFocus:i,...o},a)=>{const s=Ne(),{rootValue:l,selection:R,focus:u,nodeMap:f,registerNode:P,removeNode:w}=h.useContext(z),{parent:b,getIndex:x,depth:j}=h.useContext(U),O=h.useRef(null),V=fe(O,a),N=J(i,g);function g(L){var C,A,T,D;(T=(A=(C=f.current)==null?void 0:C[u.current])==null?void 0:A.ref.current)==null||T.setAttribute("tabindex","-1"),(D=O.current)==null||D.setAttribute("tabindex","0"),u.current=n,L.stopPropagation()}const m=x(n);return u.current==""&&b=="__root__"&&m==0&&(u.current=n),h.useEffect(()=>(P(n,b,m,!0,O),()=>w(n)),[]),h.useEffect(()=>()=>{u.current==n&&(u.current="")},[]),I.jsx(U.Provider,{value:{parent:n,getIndex:s,depth:j+1},children:I.jsx("li",{ref:V,role:"treeitem","data-state":l.has(n)?"open":"closed","data-depth":j,"aria-expanded":l.has(n),"aria-selected":R==n,tabIndex:u.current==n?0:-1,onFocus:N,...o})})}),Cr=h.forwardRef(({onClick:n,...i},o)=>{const{setRootValue:a,setSelection:s}=h.useContext(z),{parent:l}=h.useContext(U),R=J(n,u);function u(){s(l),a(f=>f.has(l)?new Set([...f].filter(P=>P!==l)):new Set([...f,l]))}return I.jsx("div",{ref:o,onClick:R,...i})}),Tr=h.forwardRef(({...n},i)=>{const{rootValue:o}=h.useContext(z),{parent:a}=h.useContext(U);if(o.has(a))return I.jsx("ul",{ref:i,role:"group",...n})}),Sr={Root:yr,Group:xr,Trigger:Cr,Content:Tr,Item:wr};module.exports=Sr;
|
|
26
26
|
//# sourceMappingURL=index.cjs.map
|