react-composable-treeview 1.0.19 → 1.0.20
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/dist/hooks/useNodeMap.d.ts +6 -3
- package/dist/index.cjs +9 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +508 -446
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,15 +3,18 @@ import { default as React } from 'react';
|
|
|
3
3
|
export interface TreeNode {
|
|
4
4
|
value: string;
|
|
5
5
|
parent: string;
|
|
6
|
-
children: Record<string, string>;
|
|
7
|
-
childrenLength: number;
|
|
8
6
|
index: number;
|
|
9
7
|
isGroup: boolean;
|
|
10
8
|
ref: React.RefObject<HTMLLIElement>;
|
|
11
9
|
}
|
|
12
10
|
export type useNodeMapHook = [
|
|
13
|
-
React.RefObject<
|
|
11
|
+
React.RefObject<Map<string, TreeNode>>,
|
|
14
12
|
(value: string, parent: string, index: number, isGroup: boolean, ref: React.RefObject<HTMLLIElement>) => void,
|
|
15
13
|
(value: string) => void
|
|
16
14
|
];
|
|
17
15
|
export declare function useNodeMap(): useNodeMapHook;
|
|
16
|
+
export declare function getFirstChild(nodeMap: useNodeMapHook[0], value: string): string;
|
|
17
|
+
export declare function getPreviousNode(nodeMap: useNodeMapHook[0], value: string): string;
|
|
18
|
+
export declare function getNextNode(nodeMap: useNodeMapHook[0], value: string): string;
|
|
19
|
+
export declare function getFirstNode(nodeMap: useNodeMapHook[0]): string;
|
|
20
|
+
export declare function getLastNode(nodeMap: useNodeMapHook[0]): string;
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const _=require("react");var ce={exports:{}},J={};/**
|
|
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 Ie;function
|
|
9
|
+
*/var Ie;function vr(){if(Ie)return J;Ie=1;var r=_,u=Symbol.for("react.element"),n=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,i=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,f={key:!0,ref:!0,__self:!0,__source:!0};function x(c,v,P){var y,R={},w=null,j=null;P!==void 0&&(w=""+P),v.key!==void 0&&(w=""+v.key),v.ref!==void 0&&(j=v.ref);for(y in v)o.call(v,y)&&!f.hasOwnProperty(y)&&(R[y]=v[y]);if(c&&c.defaultProps)for(y in v=c.defaultProps,v)R[y]===void 0&&(R[y]=v[y]);return{$$typeof:u,type:c,key:w,ref:j,props:R,_owner:i.current}}return J.Fragment=n,J.jsx=x,J.jsxs=x,J}var z={};/**
|
|
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
|
-
`+ne+e}}var oe=!1,
|
|
19
|
-
`),S=
|
|
20
|
-
`),E=
|
|
21
|
-
`+
|
|
17
|
+
*/var Ne;function pr(){return Ne||(Ne=1,process.env.NODE_ENV!=="production"&&function(){var r=_,u=Symbol.for("react.element"),n=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),f=Symbol.for("react.profiler"),x=Symbol.for("react.provider"),c=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),P=Symbol.for("react.suspense"),y=Symbol.for("react.suspense_list"),R=Symbol.for("react.memo"),w=Symbol.for("react.lazy"),j=Symbol.for("react.offscreen"),O=Symbol.iterator,V="@@iterator";function $(e){if(e===null||typeof e!="object")return null;var t=O&&e[O]||e[V];return typeof t=="function"?t:null}var h=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(e){{for(var t=arguments.length,a=new Array(t>1?t-1:0),s=1;s<t;s++)a[s-1]=arguments[s];Y("error",e,a)}}function Y(e,t,a){{var s=h.ReactDebugCurrentFrame,p=s.getStackAddendum();p!==""&&(t+="%s",a=a.concat([p]));var g=a.map(function(d){return String(d)});g.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,g)}}var C=!1,F=!1,D=!1,T=!1,I=!1,B;B=Symbol.for("react.module.reference");function Le(e){return!!(typeof e=="string"||typeof e=="function"||e===o||e===f||I||e===i||e===P||e===y||T||e===j||C||F||D||typeof e=="object"&&e!==null&&(e.$$typeof===w||e.$$typeof===R||e.$$typeof===x||e.$$typeof===c||e.$$typeof===v||e.$$typeof===B||e.getModuleId!==void 0))}function We(e,t,a){var s=e.displayName;if(s)return s;var p=t.displayName||t.name||"";return p!==""?a+"("+p+")":a}function le(e){return e.displayName||"Context"}function L(e){if(e==null)return null;if(typeof e.tag=="number"&&b("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 o:return"Fragment";case n:return"Portal";case f:return"Profiler";case i:return"StrictMode";case P:return"Suspense";case y:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case c:var t=e;return le(t)+".Consumer";case x:var a=e;return le(a._context)+".Provider";case v:return We(e,e.render,"ForwardRef");case R:var s=e.displayName||null;return s!==null?s:L(e.type)||"Memo";case w:{var p=e,g=p._payload,d=p._init;try{return L(d(g))}catch{return null}}}return null}var W=Object.assign,K=0,de,ve,pe,_e,ge,he,Re;function be(){}be.__reactDisabledLog=!0;function Ue(){{if(K===0){de=console.log,ve=console.info,pe=console.warn,_e=console.error,ge=console.group,he=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})}K++}}function Ge(){{if(K--,K===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:W({},e,{value:de}),info:W({},e,{value:ve}),warn:W({},e,{value:pe}),error:W({},e,{value:_e}),group:W({},e,{value:ge}),groupCollapsed:W({},e,{value:he}),groupEnd:W({},e,{value:Re})})}K<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var te=h.ReactCurrentDispatcher,ne;function Z(e,t,a){{if(ne===void 0)try{throw Error()}catch(p){var s=p.stack.trim().match(/\n( *(at )?)/);ne=s&&s[1]||""}return`
|
|
18
|
+
`+ne+e}}var oe=!1,M;{var qe=typeof WeakMap=="function"?WeakMap:Map;M=new qe}function Ee(e,t){if(!e||oe)return"";{var a=M.get(e);if(a!==void 0)return a}var s;oe=!0;var p=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var g;g=te.current,te.current=null,Ue();try{if(t){var d=function(){throw Error()};if(Object.defineProperty(d.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(d,[])}catch(A){s=A}Reflect.construct(e,[],d)}else{try{d.call()}catch(A){s=A}e.call(d.prototype)}}else{try{throw Error()}catch(A){s=A}e()}}catch(A){if(A&&s&&typeof A.stack=="string"){for(var l=A.stack.split(`
|
|
19
|
+
`),S=s.stack.split(`
|
|
20
|
+
`),E=l.length-1,m=S.length-1;E>=1&&m>=0&&l[E]!==S[m];)m--;for(;E>=1&&m>=0;E--,m--)if(l[E]!==S[m]){if(E!==1||m!==1)do if(E--,m--,m<0||l[E]!==S[m]){var k=`
|
|
21
|
+
`+l[E].replace(" at new "," at ");return e.displayName&&k.includes("<anonymous>")&&(k=k.replace("<anonymous>",e.displayName)),typeof e=="function"&&M.set(e,k),k}while(E>=1&&m>=0);break}}}finally{oe=!1,te.current=g,Ge(),Error.prepareStackTrace=p}var G=e?e.displayName||e.name:"",Ae=G?Z(G):"";return typeof e=="function"&&M.set(e,Ae),Ae}function Be(e,t,a){return Ee(e,!1)}function Ke(e){var t=e.prototype;return!!(t&&t.isReactComponent)}function Q(e,t,a){if(e==null)return"";if(typeof e=="function")return Ee(e,Ke(e));if(typeof e=="string")return Z(e);switch(e){case P:return Z("Suspense");case y:return Z("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case v:return Be(e.render);case R:return Q(e.type,t,a);case w:{var s=e,p=s._payload,g=s._init;try{return Q(g(p),t,a)}catch{}}}return""}var ee=Object.prototype.hasOwnProperty,me={},xe=h.ReactDebugCurrentFrame;function re(e){if(e){var t=e._owner,a=Q(e.type,e._source,t?t.type:null);xe.setExtraStackFrame(a)}else xe.setExtraStackFrame(null)}function Je(e,t,a,s,p){{var g=Function.call.bind(ee);for(var d in e)if(g(e,d)){var l=void 0;try{if(typeof e[d]!="function"){var S=Error((s||"React class")+": "+a+" type `"+d+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[d]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw S.name="Invariant Violation",S}l=e[d](t,d,s,a,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(E){l=E}l&&!(l instanceof Error)&&(re(p),b("%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).",s||"React class",a,d,typeof l),re(null)),l instanceof Error&&!(l.message in me)&&(me[l.message]=!0,re(p),b("Failed %s type: %s",a,l.message),re(null))}}}var ze=Array.isArray;function ue(e){return ze(e)}function He(e){{var t=typeof Symbol=="function"&&Symbol.toStringTag,a=t&&e[Symbol.toStringTag]||e.constructor.name||"Object";return a}}function Xe(e){try{return ye(e),!1}catch{return!0}}function ye(e){return""+e}function we(e){if(Xe(e))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",He(e)),ye(e)}var Ce=h.ReactCurrentOwner,Ze={key:!0,ref:!0,__self:!0,__source:!0},Te,Se;function Me(e){if(ee.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return e.ref!==void 0}function Qe(e){if(ee.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function er(e,t){typeof e.ref=="string"&&Ce.current}function rr(e,t){{var a=function(){Te||(Te=!0,b("%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)",t))};a.isReactWarning=!0,Object.defineProperty(e,"key",{get:a,configurable:!0})}}function tr(e,t){{var a=function(){Se||(Se=!0,b("%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)",t))};a.isReactWarning=!0,Object.defineProperty(e,"ref",{get:a,configurable:!0})}}var nr=function(e,t,a,s,p,g,d){var l={$$typeof:u,type:e,key:t,ref:a,props:d,_owner:g};return l._store={},Object.defineProperty(l._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(l,"_self",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.defineProperty(l,"_source",{configurable:!1,enumerable:!1,writable:!1,value:p}),Object.freeze&&(Object.freeze(l.props),Object.freeze(l)),l};function or(e,t,a,s,p){{var g,d={},l=null,S=null;a!==void 0&&(we(a),l=""+a),Qe(t)&&(we(t.key),l=""+t.key),Me(t)&&(S=t.ref,er(t,p));for(g in t)ee.call(t,g)&&!Ze.hasOwnProperty(g)&&(d[g]=t[g]);if(e&&e.defaultProps){var E=e.defaultProps;for(g in E)d[g]===void 0&&(d[g]=E[g])}if(l||S){var m=typeof e=="function"?e.displayName||e.name||"Unknown":e;l&&rr(d,m),S&&tr(d,m)}return nr(e,l,S,p,s,Ce.current,d)}}var ae=h.ReactCurrentOwner,Pe=h.ReactDebugCurrentFrame;function U(e){if(e){var t=e._owner,a=Q(e.type,e._source,t?t.type:null);Pe.setExtraStackFrame(a)}else Pe.setExtraStackFrame(null)}var ie;ie=!1;function se(e){return typeof e=="object"&&e!==null&&e.$$typeof===u}function Oe(){{if(ae.current){var e=L(ae.current.type);if(e)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+e+"`."}return""}}function
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function ur(e){return""}var ke={};function ar(e){{var t=Oe();if(!t){var a=typeof e=="string"?e:e.displayName||e.name;a&&(t=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+
|
|
25
|
+
Check the top-level render call using <`+a+">.")}return t}}function je(e,t){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var a=ar(t);if(ke[a])return;ke[a]=!0;var s="";e&&e._owner&&e._owner!==ae.current&&(s=" It was passed a child from "+L(e._owner.type)+"."),U(e),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',a,s),U(null)}}function De(e,t){{if(typeof e!="object")return;if(ue(e))for(var a=0;a<e.length;a++){var s=e[a];se(s)&&je(s,t)}else if(se(e))e._store&&(e._store.validated=!0);else if(e){var p=$(e);if(typeof p=="function"&&p!==e.entries)for(var g=p.call(e),d;!(d=g.next()).done;)se(d.value)&&je(d.value,t)}}}function ir(e){{var t=e.type;if(t==null||typeof t=="string")return;var a;if(typeof t=="function")a=t.propTypes;else if(typeof t=="object"&&(t.$$typeof===v||t.$$typeof===R))a=t.propTypes;else return;if(a){var s=L(t);Je(a,e.props,"prop",s,e)}else if(t.PropTypes!==void 0&&!ie){ie=!0;var p=L(t);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",p||"Unknown")}typeof t.getDefaultProps=="function"&&!t.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function sr(e){{for(var t=Object.keys(e.props),a=0;a<t.length;a++){var s=t[a];if(s!=="children"&&s!=="key"){U(e),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",s),U(null);break}}e.ref!==null&&(U(e),b("Invalid attribute `ref` supplied to `React.Fragment`."),U(null))}}function Fe(e,t,a,s,p,g){{var d=Le(e);if(!d){var l="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(l+=" 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=ur();S?l+=S:l+=Oe();var E;e===null?E="null":ue(e)?E="array":e!==void 0&&e.$$typeof===u?(E="<"+(L(e.type)||"Unknown")+" />",l=" Did you accidentally export a JSX literal instead of a component?"):E=typeof e,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",E,l)}var m=or(e,t,a,p,g);if(m==null)return m;if(d){var k=t.children;if(k!==void 0)if(s)if(ue(k)){for(var G=0;G<k.length;G++)De(k[G],e);Object.freeze&&Object.freeze(k)}else b("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===o?sr(m):ir(m),m}}function cr(e,t,a){return Fe(e,t,a,!0)}function fr(e,t,a){return Fe(e,t,a,!1)}var lr=fr,dr=cr;z.Fragment=o,z.jsx=lr,z.jsxs=dr}()),z}process.env.NODE_ENV==="production"?ce.exports=vr():ce.exports=pr();var N=ce.exports;const X=_.createContext({rootValue:new Set,setRootValue:()=>{},selection:null,setSelection:()=>{},focus:{current:""},nodeMap:{current:new Map},registerNode:()=>{},removeNode:()=>{}});function _r(){const r=_.useRef(new Map([["__root__",{value:"__root__",parent:"",index:0,isGroup:!0,ref:{current:null}}]]));return[r,(o,i,f,x,c)=>{var v;(v=r.current)==null||v.set(o,{value:o,parent:i,index:f,isGroup:x,ref:c})},o=>{var i;(i=r.current)==null||i.delete(o)}]}function Ve(r,u){if(!r.current)return"";for(const[n,o]of r.current)if(o.parent==u&&o.index==0)return o.value;return""}function gr(r,u){if(!r.current)return"";const n=r.current.get(u);if(n){for(const[o,i]of r.current)if(i.parent==n.parent&&i.index==n.index-1)return i.value;return""}else return""}function hr(r,u){if(!r.current)return"";const n=r.current.get(u);if(n){if(n.index==0)return n.parent;{let o=r.current.get(gr(r,n.value));for(;o&&o.isGroup;){const i=r.current.get($e(r,o.value));if(!i)return o.value;o=i}return o?o.value:""}}else return""}function Rr(r,u){if(!r.current)return"";const n=r.current.get(u);if(n){for(const[o,i]of r.current)if(i.parent==n.parent&&i.index==n.index+1)return i.value;return""}else return""}function br(r,u){if(!r.current)return"";const n=r.current.get(u);if(n){if(n.isGroup){const i=Ve(r,u);if(i)return i}let o=n;for(;;){const i=Rr(r,o.value);if(i)return i;{const f=r.current.get(o.parent);if(!f||o.value=="__root__")return"";o=f}}}else return""}function Er(r){if(!r.current)return"";for(const[u,n]of r.current)if(n.parent=="__root__"&&n.index==0)return n.value;return""}function $e(r,u){if(!r.current)return"";let n=null;for(const[o,i]of r.current)i.parent==u&&(!n||i.index>n.index)&&(n=i);return n?n.value:""}function mr(r){if(!r.current)return"";let u=r.current.get("__root__");for(;u&&u.isGroup;){const n=r.current.get($e(r,u.value));if(!n)return u.value;u=n}return u?u.value:""}const q=_.createContext({parent:"",getIndex:()=>-1,depth:-1});function xr(r,u,n){const[o,i]=_.useState(n),f=r!==void 0?r:o;return[f,c=>{const v=typeof c=="function"?c(f):c;u&&u(v),i(v)}]}function H(r,u){return function(o){const i=o.defaultPrevented;i&&(o.defaultPrevented=!1),r==null||r(o);let f;return o.defaultPrevented||(f=u==null?void 0:u(o),i&&(o.defaultPrevented=!0)),f}}function fe(...r){return _.useCallback(u=>{for(const n of r)typeof n=="function"?n(u):n!=null&&(n.current=u)},[r])}function Ye(){let r=-1;const u={};function n(o){return u[o]==null&&(u[o]=++r),u[o]}return n}const yr=["ArrowRight","ArrowUp","ArrowLeft","ArrowDown","Home","End","Enter"];function wr(r,u){var o,i,f;const n=Ve(r,u);n&&((f=(i=(o=r.current)==null?void 0:o.get(n))==null?void 0:i.ref.current)==null||f.focus())}function Cr(r,u){var o,i,f,x,c;const n=(i=(o=r.current)==null?void 0:o.get(u))==null?void 0:i.parent;n&&n!="__root__"&&((c=(x=(f=r.current)==null?void 0:f.get(n))==null?void 0:x.ref.current)==null||c.focus())}function Tr(r,u){var o,i,f;const n=hr(r,u);n&&n!="__root__"&&((f=(i=(o=r.current)==null?void 0:o.get(n))==null?void 0:i.ref.current)==null||f.focus())}function Sr(r,u){var o,i,f;const n=br(r,u);n&&n!="__root__"&&((f=(i=(o=r.current)==null?void 0:o.get(n))==null?void 0:i.ref.current)==null||f.focus())}function Pr(r){var n,o,i;const u=Er(r);u&&u!="__root__"&&((i=(o=(n=r.current)==null?void 0:n.get(u))==null?void 0:o.ref.current)==null||i.focus())}function Or(r){var n,o,i;const u=mr(r);u&&u!="__root__"&&((i=(o=(n=r.current)==null?void 0:n.get(u))==null?void 0:o.ref.current)==null||i.focus())}const kr=_.forwardRef(({value:r,onValueChange:u,defaultValue:n,defaultSelection:o,onKeyDown:i,...f},x)=>{const[c,v,P]=_r(),y=Ye(),[R,w]=xr(r,u,n??new Set),[j,O]=_.useState(""),V=_.useRef(null),$=fe(V,x),h=_.useRef(""),b=_.useCallback(C=>{var F;if(!(!yr.includes(C.key)||!c))switch(C.key){case"ArrowRight":const D=(F=c.current)==null?void 0:F.get(h.current);if(!D||!D.isGroup)break;C.preventDefault(),R.has(h.current)?wr(c,h.current):w(T=>new Set([...T,h.current]));break;case"ArrowLeft":C.preventDefault(),R.has(h.current)?w(T=>new Set([...T].filter(I=>I!==h.current))):Cr(c,h.current);break;case"ArrowUp":C.preventDefault(),Tr(c,h.current);break;case"ArrowDown":C.preventDefault(),Sr(c,h.current);break;case"Home":C.preventDefault(),Pr(c);break;case"End":C.preventDefault(),Or(c);break;case"Enter":C.preventDefault(),O(h.current),R.has(h.current)?w(T=>new Set([...T].filter(I=>I!==h.current))):w(T=>new Set([...T,h.current]));break}},[R]),Y=H(i,b);return N.jsx(X.Provider,{value:{rootValue:R,setRootValue:w,selection:j,setSelection:O,focus:h,nodeMap:c,registerNode:v,removeNode:P},children:N.jsx(q.Provider,{value:{parent:"__root__",getIndex:y,depth:0},children:N.jsx("ul",{ref:$,role:"tree","aria-multiselectable":"false",onKeyDown:Y,...f})})})}),jr=_.forwardRef(({value:r,onFocus:u,onClick:n,...o},i)=>{const{selection:f,setSelection:x,focus:c,nodeMap:v,registerNode:P,removeNode:y}=_.useContext(X),{parent:R,getIndex:w,depth:j}=_.useContext(q),O=_.useRef(null),V=fe(O,i),$=H(u,b),h=H(n,Y);function b(F){var D,T,I,B;(I=(T=(D=v.current)==null?void 0:D.get(c.current))==null?void 0:T.ref.current)==null||I.setAttribute("tabindex","-1"),(B=O.current)==null||B.setAttribute("tabindex","0"),c.current=r,F.stopPropagation()}function Y(){x(r)}const C=w(r);return P(r,R,C,!1,O),c.current==""&&R=="__root__"&&C==0&&(c.current=r),_.useEffect(()=>()=>y(r),[]),_.useEffect(()=>()=>{c.current==r&&(c.current="")},[]),N.jsx("li",{ref:V,role:"treeitem","aria-selected":f==r,tabIndex:c.current==r?0:-1,onFocus:$,onClick:h,"data-depth":j,...o})}),Dr=_.forwardRef(({value:r,onFocus:u,...n},o)=>{const i=Ye(),{rootValue:f,selection:x,focus:c,nodeMap:v,registerNode:P,removeNode:y}=_.useContext(X),{parent:R,getIndex:w,depth:j}=_.useContext(q),O=_.useRef(null),V=fe(O,o),$=H(u,h);function h(Y){var C,F,D,T;(D=(F=(C=v.current)==null?void 0:C.get(c.current))==null?void 0:F.ref.current)==null||D.setAttribute("tabindex","-1"),(T=O.current)==null||T.setAttribute("tabindex","0"),c.current=r,Y.stopPropagation()}const b=w(r);return c.current==""&&R=="__root__"&&b==0&&(c.current=r),_.useEffect(()=>(P(r,R,b,!0,O),()=>y(r)),[]),_.useEffect(()=>()=>{c.current==r&&(c.current="")},[]),N.jsx(q.Provider,{value:{parent:r,getIndex:i,depth:j+1},children:N.jsx("li",{ref:V,role:"treeitem","data-state":f.has(r)?"open":"closed","data-depth":j,"aria-expanded":f.has(r),"aria-selected":x==r,tabIndex:c.current==r?0:-1,onFocus:$,...n})})}),Fr=_.forwardRef(({onClick:r,...u},n)=>{const{setRootValue:o,setSelection:i}=_.useContext(X),{parent:f}=_.useContext(q),x=H(r,c);function c(){i(f),o(v=>v.has(f)?new Set([...v].filter(P=>P!==f)):new Set([...v,f]))}return N.jsx("div",{ref:n,onClick:x,...u})}),Ar=_.forwardRef(({...r},u)=>{const{rootValue:n}=_.useContext(X),{parent:o}=_.useContext(q);if(n.has(o))return N.jsx("ul",{ref:u,role:"group",...r})}),Ir={Root:kr,Group:Dr,Trigger:Fr,Content:Ar,Item:jr};module.exports=Ir;
|
|
26
26
|
//# sourceMappingURL=index.cjs.map
|