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