@sensilla-cloud/react-file-tree
Version:
Virtualized tree for displaying hierarchy in a traditional file-tree format
25 lines (24 loc) • 27.9 kB
JavaScript
import e,{useRef as t,useEffect as n,useMemo as r}from"react";import{jsxs as o,jsx as i,Fragment as s}from"react/jsx-runtime";var a,c={},l={get exports(){return c},set exports(e){c=e}},u={},f={get exports(){return u},set exports(e){u=e}},d={};var p,h,y,m,v,b,g,O,S,E,w,_,x,T,N={};
/** @license React v16.13.1
* react-is.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/function j(){return h||(h=1,e=f,"production"===process.env.NODE_ENV?e.exports=function(){if(a)return d;a=1;var e="function"==typeof Symbol&&Symbol.for,t=e?Symbol.for("react.element"):60103,n=e?Symbol.for("react.portal"):60106,r=e?Symbol.for("react.fragment"):60107,o=e?Symbol.for("react.strict_mode"):60108,i=e?Symbol.for("react.profiler"):60114,s=e?Symbol.for("react.provider"):60109,c=e?Symbol.for("react.context"):60110,l=e?Symbol.for("react.async_mode"):60111,u=e?Symbol.for("react.concurrent_mode"):60111,f=e?Symbol.for("react.forward_ref"):60112,p=e?Symbol.for("react.suspense"):60113,h=e?Symbol.for("react.suspense_list"):60120,y=e?Symbol.for("react.memo"):60115,m=e?Symbol.for("react.lazy"):60116,v=e?Symbol.for("react.block"):60121,b=e?Symbol.for("react.fundamental"):60117,g=e?Symbol.for("react.responder"):60118,O=e?Symbol.for("react.scope"):60119;function S(e){if("object"==typeof e&&null!==e){var a=e.$$typeof;switch(a){case t:switch(e=e.type){case l:case u:case r:case i:case o:case p:return e;default:switch(e=e&&e.$$typeof){case c:case f:case m:case y:case s:return e;default:return a}}case n:return a}}}function E(e){return S(e)===u}return d.AsyncMode=l,d.ConcurrentMode=u,d.ContextConsumer=c,d.ContextProvider=s,d.Element=t,d.ForwardRef=f,d.Fragment=r,d.Lazy=m,d.Memo=y,d.Portal=n,d.Profiler=i,d.StrictMode=o,d.Suspense=p,d.isAsyncMode=function(e){return E(e)||S(e)===l},d.isConcurrentMode=E,d.isContextConsumer=function(e){return S(e)===c},d.isContextProvider=function(e){return S(e)===s},d.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===t},d.isForwardRef=function(e){return S(e)===f},d.isFragment=function(e){return S(e)===r},d.isLazy=function(e){return S(e)===m},d.isMemo=function(e){return S(e)===y},d.isPortal=function(e){return S(e)===n},d.isProfiler=function(e){return S(e)===i},d.isStrictMode=function(e){return S(e)===o},d.isSuspense=function(e){return S(e)===p},d.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===r||e===u||e===i||e===o||e===p||e===h||"object"==typeof e&&null!==e&&(e.$$typeof===m||e.$$typeof===y||e.$$typeof===s||e.$$typeof===c||e.$$typeof===f||e.$$typeof===b||e.$$typeof===g||e.$$typeof===O||e.$$typeof===v)},d.typeOf=S,d}():e.exports=(p||(p=1,"production"!==process.env.NODE_ENV&&function(){var e="function"==typeof Symbol&&Symbol.for,t=e?Symbol.for("react.element"):60103,n=e?Symbol.for("react.portal"):60106,r=e?Symbol.for("react.fragment"):60107,o=e?Symbol.for("react.strict_mode"):60108,i=e?Symbol.for("react.profiler"):60114,s=e?Symbol.for("react.provider"):60109,a=e?Symbol.for("react.context"):60110,c=e?Symbol.for("react.async_mode"):60111,l=e?Symbol.for("react.concurrent_mode"):60111,u=e?Symbol.for("react.forward_ref"):60112,f=e?Symbol.for("react.suspense"):60113,d=e?Symbol.for("react.suspense_list"):60120,p=e?Symbol.for("react.memo"):60115,h=e?Symbol.for("react.lazy"):60116,y=e?Symbol.for("react.block"):60121,m=e?Symbol.for("react.fundamental"):60117,v=e?Symbol.for("react.responder"):60118,b=e?Symbol.for("react.scope"):60119;function g(e){if("object"==typeof e&&null!==e){var d=e.$$typeof;switch(d){case t:var y=e.type;switch(y){case c:case l:case r:case i:case o:case f:return y;default:var m=y&&y.$$typeof;switch(m){case a:case u:case h:case p:case s:return m;default:return d}}case n:return d}}}var O=c,S=l,E=a,w=s,_=t,x=u,T=r,j=h,$=p,C=n,R=i,I=o,M=f,k=!1;function A(e){return g(e)===l}N.AsyncMode=O,N.ConcurrentMode=S,N.ContextConsumer=E,N.ContextProvider=w,N.Element=_,N.ForwardRef=x,N.Fragment=T,N.Lazy=j,N.Memo=$,N.Portal=C,N.Profiler=R,N.StrictMode=I,N.Suspense=M,N.isAsyncMode=function(e){return k||(k=!0,console.warn("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.")),A(e)||g(e)===c},N.isConcurrentMode=A,N.isContextConsumer=function(e){return g(e)===a},N.isContextProvider=function(e){return g(e)===s},N.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===t},N.isForwardRef=function(e){return g(e)===u},N.isFragment=function(e){return g(e)===r},N.isLazy=function(e){return g(e)===h},N.isMemo=function(e){return g(e)===p},N.isPortal=function(e){return g(e)===n},N.isProfiler=function(e){return g(e)===i},N.isStrictMode=function(e){return g(e)===o},N.isSuspense=function(e){return g(e)===f},N.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===r||e===l||e===i||e===o||e===f||e===d||"object"==typeof e&&null!==e&&(e.$$typeof===h||e.$$typeof===p||e.$$typeof===s||e.$$typeof===a||e.$$typeof===u||e.$$typeof===m||e.$$typeof===v||e.$$typeof===b||e.$$typeof===y)},N.typeOf=g}()),N)),u;var e}
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/function $(){if(b)return v;b=1;return v="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"}function C(){return O?g:(O=1,g=Function.call.bind(Object.prototype.hasOwnProperty))}if("production"!==process.env.NODE_ENV){var R=j();l.exports=function(){if(_)return w;_=1;var e=j(),t=function(){if(m)return y;m=1;var e=Object.getOwnPropertySymbols,t=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;function r(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}return y=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;var r=Object.getOwnPropertyNames(t).map((function(e){return t[e]}));if("0123456789"!==r.join(""))return!1;var o={};return"abcdefghijklmnopqrst".split("").forEach((function(e){o[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},o)).join("")}catch(e){return!1}}()?Object.assign:function(o,i){for(var s,a,c=r(o),l=1;l<arguments.length;l++){for(var u in s=Object(arguments[l]))t.call(s,u)&&(c[u]=s[u]);if(e){a=e(s);for(var f=0;f<a.length;f++)n.call(s,a[f])&&(c[a[f]]=s[a[f]])}}return c},y}(),n=$(),r=C(),o=function(){if(E)return S;E=1;var e=function(){};if("production"!==process.env.NODE_ENV){var t=$(),n={},r=C();e=function(e){var t="Warning: "+e;"undefined"!=typeof console&&console.error(t);try{throw new Error(t)}catch(e){}}}function o(o,i,s,a,c){if("production"!==process.env.NODE_ENV)for(var l in o)if(r(o,l)){var u;try{if("function"!=typeof o[l]){var f=Error((a||"React class")+": "+s+" type `"+l+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof o[l]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw f.name="Invariant Violation",f}u=o[l](i,l,a,s,null,t)}catch(e){u=e}if(!u||u instanceof Error||e((a||"React class")+": type specification of "+s+" `"+l+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof u+". 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 instanceof Error&&!(u.message in n)){n[u.message]=!0;var d=c?c():"";e("Failed "+s+" type: "+u.message+(null!=d?d:""))}}}return o.resetWarningCache=function(){"production"!==process.env.NODE_ENV&&(n={})},S=o}(),i=function(){};function s(){return null}return"production"!==process.env.NODE_ENV&&(i=function(e){var t="Warning: "+e;"undefined"!=typeof console&&console.error(t);try{throw new Error(t)}catch(e){}}),w=function(a,c){var l="function"==typeof Symbol&&Symbol.iterator,u="<<anonymous>>",f={array:y("array"),bigint:y("bigint"),bool:y("boolean"),func:y("function"),number:y("number"),object:y("object"),string:y("string"),symbol:y("symbol"),any:h(s),arrayOf:function(e){return h((function(t,r,o,i,s){if("function"!=typeof e)return new p("Property `"+s+"` of component `"+o+"` has invalid PropType notation inside arrayOf.");var a=t[r];if(!Array.isArray(a))return new p("Invalid "+i+" `"+s+"` of type `"+b(a)+"` supplied to `"+o+"`, expected an array.");for(var c=0;c<a.length;c++){var l=e(a,c,o,i,s+"["+c+"]",n);if(l instanceof Error)return l}return null}))},element:h((function(e,t,n,r,o){var i=e[t];return a(i)?null:new p("Invalid "+r+" `"+o+"` of type `"+b(i)+"` supplied to `"+n+"`, expected a single ReactElement.")})),elementType:h((function(t,n,r,o,i){var s=t[n];return e.isValidElementType(s)?null:new p("Invalid "+o+" `"+i+"` of type `"+b(s)+"` supplied to `"+r+"`, expected a single ReactElement type.")})),instanceOf:function(e){return h((function(t,n,r,o,i){if(!(t[n]instanceof e)){var s=e.name||u;return new p("Invalid "+o+" `"+i+"` of type `"+((a=t[n]).constructor&&a.constructor.name?a.constructor.name:u)+"` supplied to `"+r+"`, expected instance of `"+s+"`.")}var a;return null}))},node:h((function(e,t,n,r,o){return v(e[t])?null:new p("Invalid "+r+" `"+o+"` supplied to `"+n+"`, expected a ReactNode.")})),objectOf:function(e){return h((function(t,o,i,s,a){if("function"!=typeof e)return new p("Property `"+a+"` of component `"+i+"` has invalid PropType notation inside objectOf.");var c=t[o],l=b(c);if("object"!==l)return new p("Invalid "+s+" `"+a+"` of type `"+l+"` supplied to `"+i+"`, expected an object.");for(var u in c)if(r(c,u)){var f=e(c,u,i,s,a+"."+u,n);if(f instanceof Error)return f}return null}))},oneOf:function(e){if(!Array.isArray(e))return"production"!==process.env.NODE_ENV&&i(arguments.length>1?"Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).":"Invalid argument supplied to oneOf, expected an array."),s;function t(t,n,r,o,i){for(var s=t[n],a=0;a<e.length;a++)if(d(s,e[a]))return null;var c=JSON.stringify(e,(function(e,t){return"symbol"===g(t)?String(t):t}));return new p("Invalid "+o+" `"+i+"` of value `"+String(s)+"` supplied to `"+r+"`, expected one of "+c+".")}return h(t)},oneOfType:function(e){if(!Array.isArray(e))return"production"!==process.env.NODE_ENV&&i("Invalid argument supplied to oneOfType, expected an instance of array."),s;for(var t=0;t<e.length;t++){var o=e[t];if("function"!=typeof o)return i("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+O(o)+" at index "+t+"."),s}return h((function(t,o,i,s,a){for(var c=[],l=0;l<e.length;l++){var u=(0,e[l])(t,o,i,s,a,n);if(null==u)return null;u.data&&r(u.data,"expectedType")&&c.push(u.data.expectedType)}return new p("Invalid "+s+" `"+a+"` supplied to `"+i+"`"+(c.length>0?", expected one of type ["+c.join(", ")+"]":"")+".")}))},shape:function(e){return h((function(t,r,o,i,s){var a=t[r],c=b(a);if("object"!==c)return new p("Invalid "+i+" `"+s+"` of type `"+c+"` supplied to `"+o+"`, expected `object`.");for(var l in e){var u=e[l];if("function"!=typeof u)return m(o,i,s,l,g(u));var f=u(a,l,o,i,s+"."+l,n);if(f)return f}return null}))},exact:function(e){return h((function(o,i,s,a,c){var l=o[i],u=b(l);if("object"!==u)return new p("Invalid "+a+" `"+c+"` of type `"+u+"` supplied to `"+s+"`, expected `object`.");var f=t({},o[i],e);for(var d in f){var h=e[d];if(r(e,d)&&"function"!=typeof h)return m(s,a,c,d,g(h));if(!h)return new p("Invalid "+a+" `"+c+"` key `"+d+"` supplied to `"+s+"`.\nBad object: "+JSON.stringify(o[i],null," ")+"\nValid keys: "+JSON.stringify(Object.keys(e),null," "));var y=h(l,d,s,a,c+"."+d,n);if(y)return y}return null}))}};function d(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function p(e,t){this.message=e,this.data=t&&"object"==typeof t?t:{},this.stack=""}function h(e){if("production"!==process.env.NODE_ENV)var t={},r=0;function o(o,s,a,l,f,d,h){if(l=l||u,d=d||a,h!==n){if(c){var y=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types");throw y.name="Invariant Violation",y}if("production"!==process.env.NODE_ENV&&"undefined"!=typeof console){var m=l+":"+a;!t[m]&&r<3&&(i("You are manually calling a React.PropTypes validation function for the `"+d+"` prop on `"+l+"`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details."),t[m]=!0,r++)}}return null==s[a]?o?null===s[a]?new p("The "+f+" `"+d+"` is marked as required in `"+l+"`, but its value is `null`."):new p("The "+f+" `"+d+"` is marked as required in `"+l+"`, but its value is `undefined`."):null:e(s,a,l,f,d)}var s=o.bind(null,!1);return s.isRequired=o.bind(null,!0),s}function y(e){return h((function(t,n,r,o,i,s){var a=t[n];return b(a)!==e?new p("Invalid "+o+" `"+i+"` of type `"+g(a)+"` supplied to `"+r+"`, expected `"+e+"`.",{expectedType:e}):null}))}function m(e,t,n,r,o){return new p((e||"React class")+": "+t+" type `"+n+"."+r+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+o+"`.")}function v(e){switch(typeof e){case"number":case"string":case"undefined":return!0;case"boolean":return!e;case"object":if(Array.isArray(e))return e.every(v);if(null===e||a(e))return!0;var t=function(e){var t=e&&(l&&e[l]||e["@@iterator"]);if("function"==typeof t)return t}(e);if(!t)return!1;var n,r=t.call(e);if(t!==e.entries){for(;!(n=r.next()).done;)if(!v(n.value))return!1}else for(;!(n=r.next()).done;){var o=n.value;if(o&&!v(o[1]))return!1}return!0;default:return!1}}function b(e){var t=typeof e;return Array.isArray(e)?"array":e instanceof RegExp?"object":function(e,t){return"symbol"===e||!!t&&("Symbol"===t["@@toStringTag"]||"function"==typeof Symbol&&t instanceof Symbol)}(t,e)?"symbol":t}function g(e){if(null==e)return""+e;var t=b(e);if("object"===t){if(e instanceof Date)return"date";if(e instanceof RegExp)return"regexp"}return t}function O(e){var t=g(e);switch(t){case"array":case"object":return"an "+t;case"boolean":case"date":case"regexp":return"a "+t;default:return t}}return p.prototype=Error.prototype,f.checkPropTypes=o,f.resetWarningCache=o.resetWarningCache,f.PropTypes=f,f},w}()(R.isElement,!0)}else l.exports=function(){if(T)return x;T=1;var e=$();function t(){}function n(){}return n.resetWarningCache=t,x=function(){function r(t,n,r,o,i,s){if(s!==e){var a=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw a.name="Invariant Violation",a}}function o(){return r}r.isRequired=r;var i={array:r,bigint:r,bool:r,func:r,number:r,object:r,string:r,symbol:r,any:r,arrayOf:o,element:r,elementType:r,instanceOf:o,node:r,objectOf:o,oneOf:o,oneOfType:o,shape:o,exact:o,checkPropTypes:n,resetWarningCache:t};return i.PropTypes=i,i},x}()();var I,M={},k={get exports(){return M},set exports(e){M=e}},A={};var L,D,P={};
/**
* @license React
* use-sync-external-store-shim.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/D=k,"production"===process.env.NODE_ENV?D.exports=function(){if(I)return A;I=1;var t=e,n="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},r=t.useState,o=t.useEffect,i=t.useLayoutEffect,s=t.useDebugValue;function a(e){var t=e.getSnapshot;e=e.value;try{var r=t();return!n(e,r)}catch(e){return!0}}var c="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(e,t){var n=t(),c=r({inst:{value:n,getSnapshot:t}}),l=c[0].inst,u=c[1];return i((function(){l.value=n,l.getSnapshot=t,a(l)&&u({inst:l})}),[e,n,t]),o((function(){return a(l)&&u({inst:l}),e((function(){a(l)&&u({inst:l})}))}),[e]),s(n),n};return A.useSyncExternalStore=void 0!==t.useSyncExternalStore?t.useSyncExternalStore:c,A}():D.exports=(L||(L=1,"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var t=e,n=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function r(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];o("error",e,n)}function o(e,t,r){var o=n.ReactDebugCurrentFrame.getStackAddendum();""!==o&&(t+="%s",r=r.concat([o]));var i=r.map((function(e){return String(e)}));i.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,i)}var i="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},s=t.useState,a=t.useEffect,c=t.useLayoutEffect,l=t.useDebugValue,u=!1,f=!1;function d(e){var t=e.getSnapshot,n=e.value;try{var r=t();return!i(n,r)}catch(e){return!0}}var p="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t,n){return t()}:function(e,n,o){u||void 0!==t.startTransition&&(u=!0,r("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var p=n();if(!f){var h=n();i(p,h)||(r("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var y=s({inst:{value:p,getSnapshot:n}}),m=y[0].inst,v=y[1];return c((function(){m.value=p,m.getSnapshot=n,d(m)&&v({inst:m})}),[e,p,n]),a((function(){return d(m)&&v({inst:m}),e((function(){d(m)&&v({inst:m})}))}),[e]),l(p),p},h=void 0!==t.useSyncExternalStore?t.useSyncExternalStore:p;P.useSyncExternalStore=h,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),P);const V=(e,t,n)=>{const r=[];let{from:o,to:i}=e;if(n)for(let n=e.getOffset(o);i>o;)r.push(t(o,n)),n+=e.getSize(o++);else for(;i>o;)r.push(t(o++,0));return r},z=[0,1,2],F=class{observe(){}unobserve(){}disconnect(){}},W=e=>e(),H=(e,t)=>{const n=e.length+1,r=new t(n);r.set(e,1);for(let e,t=1;n>t;t++)e=t+(t&-t),n>e&&(r[e]+=r[t]);return r},B=(e,t,n,r)=>{for(;r>t;t+=t&-t)e[t]+=n},U=(e,t,n)=>{for(;n>t;t+=t&-t);return Math.min(t,e.length)},q=new Set,G={t:0,i(){this.t++},h(){0==--this.t&&(q.forEach(W),q.clear())},o:e=>q.add(e)},K=Uint32Array,J=new K(0);const Y=e=>t().current||=new class{l(e){e&&(G.i(),this.u+=e,this.m-=e,this.scrollSize+=e,this.p(1),this.g(),G.h())}constructor(e){this.horizontal=!1,this.v="top",this.M="scrollTop",this._="offsetHeight",this.S=0,this.u=0,this.T=0,this.C=0,this.k=0,this.F=0,this.H=3,this.I=40,this.O=null,this.R=J,this.j=J,this.q=0,this.scrollSize=0,this.from=0,this.to=0,this.sizesHash=0,this.A=new Map,this.G=new Map,this.L=[null,null],this.U=[0,0],this.W=new F((e=>{let t=0,n=0,r=0;for(const{target:o}of e)t=this.L.indexOf(o),-1!==t&&(n=o[this._]-this.U[t],n&&(this.U[t]+=n,r+=n));this.l(r)})),this.$=new F((e=>{let t=0,n=0,r=0,o=!1,i=U(this.j,this.from+1,this.to);for(const{target:s}of e)t=this.A.get(s),i>t&&(n=s[this._]-this.R[t],n&&(o=!0,this.R[t]+=n,r+=n,B(this.j,t+1,n,i)));o&&(G.i(),0!==r&&(B(this.j,i,r,this.j.length),this.S+=r,this.scrollSize+=r,this.p(1),0>r&&this.g()),this.sizesHash=this.sizesHash+1&1023,this.p(2),G.h())})),this.B=z.map((()=>[])),this.D=()=>{const e=this.O[this._]-this.u;e!==this.m&&(this.m=e,this.g())},this.J=new F(this.D),this.setOuterNode=e=>{this.O&&(this.J.unobserve(this.O),this.O.removeEventListener("scroll",this)),(this.O=e)?(this.J.observe(e),e.addEventListener("scroll",this,{passive:!0})):(this.$.disconnect(),this.W.disconnect(),clearTimeout(this.k))},this.m=e.estimatedWidgetSize??200,this.set(e)}on(e,t){return t.forEach((t=>this.B[t].push(e))),()=>t.forEach((t=>this.B[t].splice(this.B[t].indexOf(e),1)))}p(e){this.B[e].forEach(0===G.t?W:G.o)}getIndex(e){let t=0;e=Math.min(e,this.S);for(let n=this.q,r=0;n>0;n>>=1)(r=t+n)<=this.T&&e>this.j[r]&&(t=r,e-=this.j[r]);return t}getOffset(e){if("production"!==process.env.NODE_ENV&&e>this.T)throw Error("index must not be > itemCount");let t=0;for(;e>0;e-=e&-e)t+=this.j[e];return t}getSize(e){if("production"!==process.env.NODE_ENV&&e>=this.R.length)throw Error("itemIndex must be < itemCount in getSize");return this.R[e]}get visibleFrom(){const e=this.getIndex(this.F);return e+(this.F-this.getOffset(e))/this.R[e]}handleEvent(e){const t=this.F,n=this.O[this.M];n!==t&&(this.F=n,this.C=e.timeStamp,n>t?this.g():this.K())}el(e,t){const n=this.G.get(e);n&&(this.G.delete(e),this.A.delete(n),this.$.unobserve(n)),t&&(this.A.set(t,e),this.G.set(e,t),this.$.observe(t))}N(e,t){const n=this.L[e];n&&(this.W.unobserve(n),this.l(-this.U[e]),this.L[e]=null,this.U[e]=0),t&&this.W.observe(this.L[e]=t)}setStickyHeader(e){this.N(0,e)}setStickyFooter(e){this.N(1,e)}g(){const e=1+this.getIndex(this.F+this.m);e>this.to&&(this.to=Math.min(this.T,e+this.H),this.from=this.getIndex(this.F),this.p(0))}K(){const e=this.getIndex(this.F);e<this.from&&(this.from=Math.max(0,e-this.H),this.to=this.T&&1+this.getIndex(this.F+this.m),this.p(0))}scrollTo(e,t,n){if(clearTimeout(this.k),this.O){const r=0|e,o=Math.min(this.scrollSize-this.m,this.getOffset(r)+Math.round(this.R[r]*(e-r)));o!==this.F&&(n||=5,t&&128>=performance.now()-this.C||(this.O.scroll({[this.v]:o,behavior:t?"smooth":"instant"}),n--),n&&(this.k=setTimeout((()=>this.scrollTo(e,t,n)),t?512:32)))}}set(e){let{overscanCount:t,horizontal:n,itemCount:r,estimatedItemSize:o}=e;if(G.i(),o&&(this.I=o),void 0!==t&&(this.H=t),void 0!==r&&this.T!==r){if(r>2147483647)throw Error(`itemCount must be <= 2147483647. Got: ${r}.`);this.q=(this.T=r)&&1<<31-Math.clz32(r);const e=this.R,t=e.length;r>t&&(this.R=new K(Math.min(r+32,2147483647)),this.R.set(e),this.j=H(this.R.fill(this.I||40,t),K)),this.scrollSize=(this.S=this.getOffset(r))+this.u,this.p(1),this.to>r&&(this.to=-1),this.g()}void 0!==n&&this.horizontal!==n&&(this.v=(this.horizontal=n)?"left":"top",this.M=n?"scrollLeft":"scrollTop",this._=n?"offsetWidth":"offsetHeight",this.O&&this.D(),this.scrollTo(0)),G.h()}}(e),Q=n,X=e=>(((e,t)=>{t||=z;const[n,o]=r((()=>[n=>e.on(n,t),()=>t.reduce(((t,n)=>t+"_"+(0===n?e.to**2+e.from:1===n?e.scrollSize:e.sizesHash)),"")]),[t]);M.useSyncExternalStore(n,o,o)})(e.model,e.events),e.children()),Z=new Map,ee=e=>{const t=e.trim().replace(/(\s)+/g,"$1").replace(/\s?:\s?/,":");let n=Z.get(t);return n||(n="af-styled_"+t.replace(/\W+/g,"_"),Z.set(t,n)),n};function te(e){let t=ee(e);for(let e=1;e<arguments.length;e++)t+=" "+ee(arguments[e]);return t}function ne(e){for(let t=1,n="";t<arguments.length;t++)n=arguments[t],n&&(e+=" "+n);return e}const re=te("overflow: auto","position: relative"),oe=te("visibility: hidden"),ie=te("position: absolute"),se=te("height: 1px"),ae=te("width: 1px"),ce=ne(re,te("display: flex")),le=ne(ie,oe,ae,te("top: 0")),ue=ne(ie,oe,se,te("left: 0")),fe=ne(oe,ae),de=ne(oe,se,te("flex-shrink: 0")),pe=["height",re,le,fe],he=["width",ce,ue,de],ye=[0],me=[1],ve=e=>{let{model:t,children:n,className:r,itemData:a,header:c=null,footer:l=null,component:u="div",getKey:f=(e=>e),tabIndex:d=-1,...p}=e;const[h,y,m,v]=t.horizontal?he:pe;return o(u,{className:ne(y,r),ref:t.setOuterNode,tabIndex:d,...p,children:[i(X,{model:t,events:me,children:()=>i("div",{className:m,style:{[h]:t.scrollSize}})}),c,i(X,{model:t,events:ye,children:()=>o(s,{children:[i("div",{className:v,style:{[h]:t.getOffset(t.from)}}),V(t,((e,r)=>i(n,{i:e,data:a,offset:r,model:t},f(e,a))))]})}),l]})};"production"!==process.env.NODE_ENV&&(ve.propTypes={model:c.object.isRequired,children:c.elementType.isRequired,getKey:c.func,component:c.elementType,header:c.element,footer:c.element,className:c.string,itemData:c.any,tabIndex:c.number});const be={childClassName:"react-file-tree-child",expandTool:e.createElement("div",{className:"react-file-tree-child-button"},"+"),collapseTool:e.createElement("div",{className:"react-file-tree-child-button"},"-"),indentWidth:16},ge={className:"react-file-tree",renderOptions:be,filterFn:(e,t)=>e.name.toLowerCase().includes(t.toLowerCase())},Oe=t=>{const n=Object.assign({},ge,t);n.renderOptions=Object.assign({},be,n.renderOptions);const[r,o]=e.useState(new Map),[i,s]=e.useState(new Map),[a,c]=e.useState([]),[l,u]=e.useState(),f={expand:e=>{n.onExpand&&n.onExpand(e),o(new Map(r.set(e.id,Object.assign(Object.assign({},r.get(e.id)),{expanded:!0}))))},collapse:e=>{n.onCollapse&&n.onCollapse(e),o(new Map(r.set(e.id,Object.assign(Object.assign({},r.get(e.id)),{expanded:!1}))))},select:e=>{if(n.selectable){n.onSelect&&n.onSelect(e);const t=new Map(r.set(e.id,Object.assign(Object.assign({},r.get(e.id)),{selected:!0})));n.multiSelect||(void 0!==l&&t.set(l,Object.assign(Object.assign({},t.get(l)),{selected:!1})),u(e.id)),o(t)}},deselect:e=>{n.selectable&&(n.onDeselect&&n.onDeselect(e),o(new Map(r.set(e.id,Object.assign(Object.assign({},r.get(e.id)),{selected:!1})))),n.multiSelect||u(void 0))}},d=e.useCallback(((e,o)=>void 0===e||n.filterable&&!a.includes(e.id)?[]:["function"==typeof t.childRenderer?t.childRenderer(e,o,n,f):h(e,o,n.renderOptions),...e.children&&o.expanded?Array.from(e.children.map((e=>d(e,r.get(e.id))))).flat(9999999):[]]),[r,n.renderOptions,t.childRenderer]),p=e.useCallback((({i:t,model:o})=>n.data[t]&&r.has(n.data[t].id)?e.createElement("div",{ref:e=>o.el(t,e),className:n.className+"-virtual-child-wrapper"},d(n.data[t],r.get(n.data[t].id))):null),[n.data,r,a]),h=(t,r,o)=>{var i,s;return e.createElement("div",{key:t.id,className:`${o.childClassName}${r.expanded?` ${o.childClassName}-expanded`:""}${r.selected?` ${o.childClassName}-selected`:""}${r.disabled?` ${o.childClassName}-disabled`:""}`},e.createElement("div",{className:o.childClassName+"-row"},e.createElement("div",{style:{width:o.indentWidth*r.depth}}),(null!==(s=null===(i=t.children)||void 0===i?void 0:i.length)&&void 0!==s?s:0)>0&&e.createElement("div",{className:o.childClassName+"-fold-button",onClick:()=>{if(n.disabled)return;const e=!r.expanded;e?f.expand(t):e||f.collapse(t)}},r.expanded?o.collapseTool:o.expandTool),e.createElement("div",{className:o.childClassName+"-label",style:{cursor:n.disabled?"not-allowed":n.selectable&&r.selectable?"pointer":"default"},onClick:()=>{if(n.selectable&&r.selectable&&!n.disabled){const e=!r.selected;e?f.select(t):e||f.deselect(t)}}},t.name)))};e.useEffect((()=>{const e=new Map,t=new Map,r=(n,o,i)=>{var s,a,c,l,u;e.set(n.id,{expanded:null!==(s=n.expanded)&&void 0!==s&&s,depth:o,selected:null!==(a=n.selected)&&void 0!==a&&a,disabled:null!==(c=n.disabled)&&void 0!==c&&c,selectable:null===(l=n.selectable)||void 0===l||l,parent:i}),t.set(n.id,n),null===(u=n.children)||void 0===u||u.forEach((e=>{r(e,o+1,n)}))};n.data.forEach((e=>{r(e,0,null)})),o(e),s(t)}),[t.data]),e.useEffect((()=>{if(n.filterable&&n.filter){const e=[],t=[];i.forEach((e=>{n.filterFn(e,n.filter||"")&&t.push(e)}));const o=t=>{var n,i;e.push(t.id),null!==(null===(n=r.get(t.id))||void 0===n?void 0:n.parent)&&o(null===(i=r.get(t.id))||void 0===i?void 0:i.parent)};t.forEach((e=>{o(e)})),c(e)}else n.filterable&&c([...i.keys()])}),[n.filter,n.filterable,i]);const y=(e=>{const t=Y(e);return Q((()=>t.set(e))),t})({itemCount:n.data.length});return e.createElement("div",{className:`${n.className}${n.disabled?` ${n.className}-disabled`:""}`},n.virtual?e.createElement(ve,{className:n.className+"-virtual",model:y},p):n.data.map((e=>r.has(e.id)?d(e,r.get(e.id)):null)))};export{Oe as default};
//# sourceMappingURL=index.js.map