@aiquants/directory-tree 3.0.0 → 3.0.2
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 -7
- package/dist/index.cjs +1 -1
- package/dist/index.js +60 -60
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ The main component for rendering the directory tree.
|
|
|
116
116
|
#### Props
|
|
117
117
|
|
|
118
118
|
| Prop | Type | Required | Description |
|
|
119
|
-
|
|
|
119
|
+
| --- | --- | --- | --- |
|
|
120
120
|
| `entries` | `DirectoryEntry[]` | Yes | Array of root directory entries to display |
|
|
121
121
|
| `expansion` | `object` | Yes | Configuration for tree expansion state and behavior |
|
|
122
122
|
| `selection` | `object` | Yes | Configuration for item selection |
|
|
@@ -126,7 +126,7 @@ The main component for rendering the directory tree.
|
|
|
126
126
|
#### Expansion Options (`expansion`)
|
|
127
127
|
|
|
128
128
|
| Prop | Type | Required | Default | Description |
|
|
129
|
-
|
|
|
129
|
+
| --- | --- | --- | --- | --- |
|
|
130
130
|
| `toggle` | `(path: string) => void` | Yes | - | Function to toggle directory expansion state |
|
|
131
131
|
| `isExpanded` | `(path: string) => boolean` | Yes | - | Function to check if a directory is expanded |
|
|
132
132
|
| `expandMultiple` | `(paths: string[]) => void` | Yes | - | Function to expand multiple directories |
|
|
@@ -138,7 +138,7 @@ The main component for rendering the directory tree.
|
|
|
138
138
|
#### Selection Options (`selection`)
|
|
139
139
|
|
|
140
140
|
| Prop | Type | Required | Default | Description |
|
|
141
|
-
|
|
|
141
|
+
| --- | --- | --- | --- | --- |
|
|
142
142
|
| `onEntryClick` | `(event: DirectoryTreeClickEvent) => void` | Yes | - | Callback function triggered when an entry is clicked |
|
|
143
143
|
| `selectedPath` | `string \| null` | No | - | The currently selected file path |
|
|
144
144
|
| `mode` | `'none' \| 'single' \| 'multiple'` | No | `'none'` | Selection mode for items |
|
|
@@ -148,7 +148,7 @@ The main component for rendering the directory tree.
|
|
|
148
148
|
#### Visual Options (`visual`)
|
|
149
149
|
|
|
150
150
|
| Prop | Type | Required | Default | Description |
|
|
151
|
-
|
|
|
151
|
+
| --- | --- | --- | --- | --- |
|
|
152
152
|
| `className` | `string` | No | - | Optional CSS class name for the container |
|
|
153
153
|
| `style` | `React.CSSProperties` | No | - | Optional inline styles for the container |
|
|
154
154
|
| `lineColor` | `string` | No | `'#A0AEC0'` | The color of the tree lines |
|
|
@@ -206,20 +206,20 @@ A hook for managing directory tree state with localStorage persistence.
|
|
|
206
206
|
#### Parameters
|
|
207
207
|
|
|
208
208
|
| Parameter | Type | Description |
|
|
209
|
-
|
|
|
209
|
+
| --- | --- | --- |
|
|
210
210
|
| `options` | `UseDirectoryTreeStateProps` | Configuration options |
|
|
211
211
|
|
|
212
212
|
#### Options
|
|
213
213
|
|
|
214
214
|
| Option | Type | Description |
|
|
215
|
-
|
|
|
215
|
+
| --- | --- | --- |
|
|
216
216
|
| `initialExpanded` | `Set<string>` | Initially expanded directories |
|
|
217
217
|
| `storageKey` | `string` | localStorage key for persistence (default: 'directory-tree-state') |
|
|
218
218
|
|
|
219
219
|
#### Returns
|
|
220
220
|
|
|
221
221
|
| Property | Type | Description |
|
|
222
|
-
|
|
|
222
|
+
| --- | --- | --- |
|
|
223
223
|
| `expanded` | `Set<string>` | Currently expanded directories |
|
|
224
224
|
| `toggle` | `(path: string) => void` | Toggle directory expansion |
|
|
225
225
|
| `isExpanded` | `(path: string) => boolean` | Check if directory is expanded |
|
package/dist/index.cjs
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,_,j,Z,j),re[j+_]=!0)}if(j=null,R!==void 0&&(a(R),j=""+R),o(b)&&(a(b.key),j=""+b.key),"key"in b){R={};for(var B in b)B!=="key"&&(R[B]=b[B])}else R=b;return j&&m(R,typeof r=="function"?r.displayName||r.name||"Unknown":r),v(r,j,R,s(),q,J)}function h(r){x(r)?r._store&&(r._store.validated=1):typeof r=="object"&&r!==null&&r.$$typeof===I&&(r._payload.status==="fulfilled"?x(r._payload.value)&&r._payload.value._store&&(r._payload.value._store.validated=1):r._store&&(r._store.validated=1))}function x(r){return typeof r=="object"&&r!==null&&r.$$typeof===N}var S=c,N=Symbol.for("react.transitional.element"),d=Symbol.for("react.portal"),u=Symbol.for("react.fragment"),g=Symbol.for("react.strict_mode"),D=Symbol.for("react.profiler"),w=Symbol.for("react.consumer"),k=Symbol.for("react.context"),y=Symbol.for("react.forward_ref"),T=Symbol.for("react.suspense"),W=Symbol.for("react.suspense_list"),L=Symbol.for("react.memo"),I=Symbol.for("react.lazy"),G=Symbol.for("react.activity"),F=Symbol.for("react.client.reference"),H=S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,K=Object.prototype.hasOwnProperty,z=Array.isArray,X=console.createTask?console.createTask:function(){return null};S={react_stack_bottom_frame:function(r){return r()}};var M,U={},C=S.react_stack_bottom_frame.bind(S,l)(),$=X(n(l)),re={};pe.Fragment=u,pe.jsx=function(r,b,R){var _=1e4>H.recentlyCreatedOwnerStacks++;return i(r,b,R,!1,_?Error("react-stack-top-frame"):C,_?X(n(r)):$)},pe.jsxs=function(r,b,R){var _=1e4>H.recentlyCreatedOwnerStacks++;return i(r,b,R,!0,_?Error("react-stack-top-frame"):C,_?X(n(r)):$)}})()),pe}var ut;function Ot(){return ut||(ut=1,process.env.NODE_ENV==="production"?Se.exports=Pt():Se.exports=At()),Se.exports}var p=Ot();const ke=20,he=16,ft=12,O={container:"directory-tree-container relative h-full transition-opacity duration-300 overflow-y-hidden pb-[5px] pr-[3px]",containerPending:"opacity-70",entry:"directory-tree-entry flex items-center cursor-pointer relative select-none",entryHover:P.twMerge("directory-tree-entry--hover hover:bg-gray-400/15","dark:hover:bg-gray-200/10"),entrySelected:P.twMerge("directory-tree-entry--selected bg-blue-400/10","dark:bg-blue-400/15"),entryItemSelected:P.twMerge("directory-tree-entry--item-selected bg-blue-400/20 shadow-[0_0_0_1px_rgba(59,130,246,0.3)]","dark:bg-blue-400/25 dark:shadow-[0_0_0_1px_rgba(96,165,250,0.4)]"),expandIcon:P.twMerge("directory-tree-expand-icon w-5 h-5 flex-shrink-0 flex items-center justify-center","text-gray-500","dark:text-gray-400"),expandIconSelected:P.twMerge("directory-tree-expand-icon--selected text-blue-700","dark:text-blue-400"),typeIcon:P.twMerge("directory-tree-type-icon w-5 h-5 flex-shrink-0 flex items-center justify-center","text-gray-500","dark:text-gray-400"),typeIconSelected:P.twMerge("directory-tree-type-icon--selected text-blue-700","dark:text-blue-400"),name:P.twMerge("directory-tree-name overflow-hidden text-ellipsis whitespace-nowrap ml-1","text-gray-700","dark:text-gray-200"),nameDirectory:"directory-tree-name--directory",nameSelected:P.twMerge("directory-tree-name--selected text-blue-800 font-medium","dark:text-blue-300")},pt=e=>e.slice((e.lastIndexOf(".")-1>>>0)+2).toLowerCase(),bt=({isDirectory:e,isExpanded:t,showExpandIcons:a,useCanvasExpandIcons:n,expandIconSize:s})=>{const l=s?{width:s,height:s}:void 0,o=s?"":"h-4 w-4";return!(a&&e)||n?p.jsx("span",{className:o,style:l,"aria-hidden":"true"}):t?p.jsx(Ce.ChevronDownIcon,{className:o,style:l}):p.jsx(Ce.ChevronRightIcon,{className:o,style:l})},Oe=(e,t)=>{if(e==null||typeof e=="boolean")return null;if(typeof e=="function")return console.warn(`[DirectoryTree] Function returned by renderer for "${t}". Return a node.`),null;if(typeof e=="object"){if("then"in e)return console.warn(`[DirectoryTree] Promise returned for "${t}". Not supported.`),null;if(Array.isArray(e)){const n=e.map(s=>Oe(s,t)).filter(Boolean);return n.length?n:null}const a=e.type;if(a&&a.$$typeof===Symbol.for("react.lazy"))return console.warn(`[DirectoryTree] Lazy component for "${t}". Not supported.`),null}return e},vt=(e,t)=>{const{entry:a,isDirectory:n,isExpanded:s,extension:l}=e;let o;return a.icon!==void 0?o=a.icon:n?o=s&&t?.directoryExpanded||t?.directory||p.jsx(Ce.FolderIcon,{className:"h-4 w-4"}):l&&t?.fileByExtension?.[l]?o=t.fileByExtension[l]:o=t?.file||(l==="md"?p.jsx(Ce.DocumentTextIcon,{className:"h-4 w-4"}):p.jsx(jt.FileIcon,{className:"h-4 w-4"})),Oe(typeof o=="function"?o(e):o,a.absolutePath)},Dt=500,gt=({entry:e,isDirectory:t,isExpanded:a,isItemSelected:n,selectionMode:s,onSelectionChange:l,onEntryClick:o,toggleDirectory:m,onToggleDirectoryRecursive:E})=>{const v=c.useRef(null);return c.useEffect(()=>()=>{v.current&&window.clearTimeout(v.current)},[]),c.useCallback(i=>{i.stopPropagation(),s!=="none"&&!t&&l&&l(e,!n);let h=!1;o({entry:e,isDirectory:t,isExpanded:a,preventDefault:()=>{h=!0}}),!(!t||h)&&(v.current?(window.clearTimeout(v.current),v.current=null,E(e)):v.current=window.setTimeout(()=>{m(e.absolutePath),v.current=null},Dt))},[t,e,a,E,m,o,s,l,n])},xt=e=>e==="right"?"dt-grid-cell--right":e==="center"?"dt-grid-cell--center":"",mt=(e,t)=>e.children!==void 0&&t(e.absolutePath),wt=(e,t)=>({width:e,gridTemplateColumns:t}),Et=c.memo(({entry:e,indentLevel:t,rowHeight:a,isDirOpen:n,columns:s,numericTemplate:l,numericTotal:o,nameWidth:m,rowClassName:E,selection:{onEntryClick:v,selectedPath:i,mode:h="none",selectedItems:x,onSelectionChange:S},expansion:{toggleDirectory:N,onToggleDirectoryRecursive:d},visual:{iconOverrides:u,showExpandIcons:g=!0,showDirectoryIcons:D=!0,showFileIcons:w=!0,useCanvasExpandIcons:k=!1,expandIconSize:y,highlightStyles:T}})=>{const[W,L]=c.useState(!1),I=e.children!==void 0,G=I&&n(e.absolutePath),F=e.absolutePath===i,H=!I&&!!x?.has(e.absolutePath),K=I?void 0:pt(e.name),z=gt({entry:e,isDirectory:I,isExpanded:G,isItemSelected:H,selectionMode:h,onSelectionChange:S,onEntryClick:v,toggleDirectory:N,onToggleDirectoryRecursive:d}),X=W?T?.hoverClassName!==void 0?T.hoverClassName:O.entryHover:"",M=(()=>{if(I){if(F)return T?.directorySelectedClassName!==void 0?T.directorySelectedClassName:O.entrySelected}else if(F||H)return T?.itemSelectedClassName!==void 0?T.itemSelectedClassName:P.twMerge(F&&O.entrySelected,H&&O.entryItemSelected);return""})(),U=typeof E=="function"?E(e):E,C=P.twMerge("dt-grid-row cursor-pointer select-none",X,M,U,e.className),$=P.twMerge(O.expandIcon,(F||H)&&O.expandIconSelected),re=P.twMerge(O.typeIcon,(F||H)&&O.typeIconSelected),r=P.twMerge("dt-grid-name-label ml-1","text-gray-700 dark:text-gray-200",I&&O.nameDirectory,(F||H)&&O.nameSelected),b=bt({isDirectory:I,isExpanded:G,showExpandIcons:g,useCanvasExpandIcons:k,expandIconSize:y}),R=(I?D:w)?vt({entry:e,isDirectory:I,isExpanded:G,isSelected:F,isItemSelected:H,extension:K},u):null,_={indentLevel:t,isDirectory:I,isExpanded:G},[q,...J]=s,j=q?.render?q.render(e,_):e.label??e.name,Z={...W?T?.hoverStyle:{},...I&&F?T?.directorySelectedStyle:{},...!I&&(F||H)?T?.itemSelectedStyle:{}};return p.jsxs("div",{className:C,style:{height:a,...Z,...e.style},role:"row","aria-expanded":I?G:void 0,"aria-level":t+1,"data-entry-type":I?"directory":"file","data-entry-expanded":I?String(G):void 0,"data-entry-selected":F?"true":void 0,"data-entry-item-selected":H?"true":void 0,onClick:z,onMouseEnter:()=>L(!0),onMouseLeave:()=>L(!1),onKeyDown:B=>B.key==="Enter"&&z(B),tabIndex:0,children:[p.jsxs("div",{className:P.twMerge("dt-grid-name-cell",q?.className),role:"gridcell",style:{width:m,paddingLeft:Math.max(0,t*he)},children:[(g||k)&&p.jsx("span",{className:$,children:b}),(I?D:w)&&p.jsx("span",{className:re,children:R}),p.jsx("span",{className:r,children:j})]}),J.length>0&&p.jsx("div",{className:"dt-grid-numeric-viewport",children:p.jsx("div",{className:"dt-grid-numeric-track",style:wt(o,l),children:J.map(B=>p.jsx("div",{className:P.twMerge("dt-grid-cell",xt(B.align),B.className),role:"gridcell",children:B.render?B.render(e,_):null},B.key))})})]})},(e,t)=>{if(e.entry!==t.entry)return!1;const a=mt(e.entry,e.isDirOpen),n=mt(t.entry,t.isDirOpen);return e.indentLevel===t.indentLevel&&e.rowHeight===t.rowHeight&&a===n&&e.columns===t.columns&&e.numericTemplate===t.numericTemplate&&e.numericTotal===t.numericTotal&&e.nameWidth===t.nameWidth&&e.rowClassName===t.rowClassName&&e.selection.selectedPath===t.selection.selectedPath&&e.selection.mode===t.selection.mode&&e.selection.selectedItems===t.selection.selectedItems&&e.visual===t.visual});Et.displayName="DirectoryTreeGridRow";const St=({kind:e,columns:t,numericTemplate:a,numericTotal:n,nameWidth:s,scrollBarWidth:l,className:o,nameContent:m,renderCell:E})=>{const[,...v]=t,i=e==="header"?"dt-grid-name-header":"dt-grid-name-footer",h=e==="header"?"dt-grid-header":"dt-grid-footer",x=e==="header"?"columnheader":"gridcell";return p.jsxs("div",{className:P.twMerge(h,"text-gray-600 dark:text-gray-300",o),role:"row",children:[p.jsx("div",{className:P.twMerge(i,"px-1"),role:x,style:{width:s},children:m}),v.length>0&&p.jsx("div",{className:"dt-grid-numeric-viewport",children:p.jsx("div",{className:"dt-grid-numeric-track",style:wt(n,a),children:v.map(S=>p.jsx("div",{className:P.twMerge("dt-grid-cell",xt(S.align),S.className),role:x,children:E(S)},S.key))})}),p.jsx("div",{className:"dt-grid-scrollbar-spacer",style:{width:l},"aria-hidden":"true"})]})},Lt=({columns:e,className:t,...a})=>p.jsx(St,{kind:"header",columns:e,className:t,nameContent:e[0]?.header??null,renderCell:n=>n.header??null,...a}),ht=(e,t)=>typeof e=="function"?e(t):e??null,Ht=({columns:e,allEntries:t,className:a,...n})=>p.jsx(St,{kind:"footer",columns:e,className:a,nameContent:ht(e[0]?.footer,t),renderCell:s=>ht(s.footer,t),...n}),$t=240,kt=96,Ct=12,De=(e,t)=>{const a=e?.width;return typeof a=="number"&&Number.isFinite(a)&&a>0?a:t},Wt=e=>e.slice(1).map(t=>`${De(t,kt)}px`).join(" "),Ft=({measuredWidth:e,columns:t,scrollBarWidth:a=Ct})=>{const n=De(t[0],$t),s=t.slice(1).reduce((E,v)=>E+De(v,kt),0),l=Number.isFinite(e)&&e>0?e:0,o=Math.max(0,l-n-Math.max(0,a)),m=Math.max(0,s-o);return{nameWidth:n,numericTotal:s,numericVisible:o,maxHScroll:m}},Ae=(e,t)=>!Number.isFinite(e)||e<0?0:e>t?t:e,Bt=e=>{const t=[],a=n=>{for(const s of n)t.push(s),s.children&&s.children.length>0&&a(s.children)};return a(e),t},Yt=(e,t,a)=>{const n=[];for(let s=t;s<a;s++){const l=e[s];if(!(!l||l.length===0))for(const o of l)n.push(o)}return n},Gt=(e,t,a)=>{const n=[];for(let s=t;s<a;s++){const l=e[s];if(!(!l||l.length===0))for(const o of l)n.push(o)}return n},Ut=(e,t,a,n)=>{const s=Math.max(1,Math.floor(t*n)),l=Math.max(1,Math.floor(a*n));(e.width!==s||e.height!==l)&&(e.width=s,e.height=l);const o=e.style;o.width!==`${t}px`&&(o.width=`${t}px`),o.height!==`${a}px`&&(o.height=`${a}px`)},Vt=(e,t,a)=>{e.lineWidth=a,e.beginPath();for(const n of t)e.moveTo(n.x1,n.y1),e.lineTo(n.x2,n.y2);e.stroke()},zt=(e,t)=>{const a=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(!a)return null;let n=a[1];n.length===3&&(n=n.split("").map(m=>m+m).join(""));const s=Number.parseInt(n.slice(0,2),16),l=Number.parseInt(n.slice(2,4),16),o=Number.parseInt(n.slice(4,6),16);return`rgba(${s}, ${l}, ${o}, ${t})`},Xt=(e,t,a,n)=>{if(t.length===0)return;const s=zt(a,.14),l=e.strokeStyle,o=e.fillStyle,m=e.lineWidth,E=e.lineCap,v=e.lineJoin;e.strokeStyle=a,e.lineCap="round",e.lineJoin="round";for(const i of t){const h=n??i.size,x=Math.max(0,h/2),S=Math.max(1,Math.round(h*.08)),N=Math.max(1,Math.round(h*.14)),d=Math.max(0,x-S*.8),u=Math.max(0,d*.55);s&&(e.fillStyle=s,e.beginPath(),e.arc(i.centerX,i.centerY,d,0,Math.PI*2),e.fill()),e.lineWidth=S,e.beginPath(),e.arc(i.centerX,i.centerY,Math.max(0,x-S*.3),0,Math.PI*2),e.stroke(),e.lineWidth=N,e.beginPath(),e.moveTo(i.centerX-u,i.centerY),e.lineTo(i.centerX+u,i.centerY),e.stroke(),i.isExpanded||(e.beginPath(),e.moveTo(i.centerX,i.centerY-u),e.lineTo(i.centerX,i.centerY+u),e.stroke())}e.strokeStyle=l,e.fillStyle=o,e.lineWidth=m,e.lineCap=E,e.lineJoin=v},Nt=c.memo(({segmentsByItem:e,glyphsByItem:t,itemHeight:a,width:n,viewportHeight:s,scrollPosition:l,color:o="#a0aec0",strokeWidth:m=1,renderStartIndex:E,renderEndIndex:v,lookaheadEndIndex:i,devicePixelRatio:h,expandGlyphColor:x,expandGlyphSize:S})=>{const N=c.useRef(null),d=c.useRef(null),u=c.useRef({segmentsByItem:e,glyphsByItem:t,itemHeight:a,width:n,viewportHeight:s,scrollPosition:l,color:o,strokeWidth:m,renderStartIndex:E,renderEndIndex:v,lookaheadEndIndex:i,devicePixelRatio:h,expandGlyphColor:x,expandGlyphSize:S}),g=c.useCallback(()=>{d.current=null;const w=N.current;if(!w)return;const k=w.getContext("2d");if(!k)return;const y=u.current;if(y.width<=0||y.viewportHeight<=0){k.clearRect(0,0,w.width,w.height);return}const T=Number.isFinite(y.devicePixelRatio??NaN)?y.devicePixelRatio:typeof window<"u"&&window.devicePixelRatio||1;Ut(w,y.width,y.viewportHeight,T);const W=y.segmentsByItem.length,L=typeof y.renderStartIndex=="number"&&Number.isFinite(y.renderStartIndex)?Math.max(0,Math.floor(y.renderStartIndex)):Math.max(0,Math.floor(y.scrollPosition/y.itemHeight)),I=Math.min(W,Math.ceil((y.scrollPosition+y.viewportHeight)/y.itemHeight)),G=(()=>{if(typeof y.renderEndIndex=="number"&&Number.isFinite(y.renderEndIndex)){const z=Math.floor(y.renderEndIndex);return Math.max(Math.min(W,z+1),L)}return Math.max(I,L)})(),F=(()=>{if(typeof y.lookaheadEndIndex=="number"&&Number.isFinite(y.lookaheadEndIndex)){const z=Math.floor(y.lookaheadEndIndex),X=Math.min(W,z+1);return Math.max(X,G)}return Math.max(I,G)})(),H=Yt(y.segmentsByItem,L,F),K=Gt(y.glyphsByItem,L,F);k.save(),k.scale(T,T),k.clearRect(0,0,y.width,y.viewportHeight),k.translate(0,-y.scrollPosition),k.strokeStyle=y.color,Vt(k,H,y.strokeWidth),Xt(k,K,y.expandGlyphColor??y.color,y.expandGlyphSize),k.restore()},[]),D=c.useCallback(()=>{d.current===null&&(d.current=window.requestAnimationFrame(g))},[g]);return c.useEffect(()=>{u.current={segmentsByItem:e,glyphsByItem:t,itemHeight:a,width:n,viewportHeight:s,scrollPosition:l,color:o,strokeWidth:m,renderStartIndex:E,renderEndIndex:v,lookaheadEndIndex:i,devicePixelRatio:h,expandGlyphColor:x,expandGlyphSize:S},D()},[e,t,a,n,s,l,o,m,E,v,i,h,x,S,D]),c.useEffect(()=>()=>{d.current!==null&&(window.cancelAnimationFrame(d.current),d.current=null)},[]),p.jsx("canvas",{ref:N,className:"pointer-events-none absolute top-0 left-0 z-0"})});Nt.displayName="TreeLineCanvas";const qt={msOverflowStyle:"none",scrollbarWidth:"none"},Jt=()=>{let e=document.getElementById("directory-tree-webkit-scrollbar-hide");e||(e=document.createElement("style"),e.id="directory-tree-webkit-scrollbar-hide",e.textContent=".directory-tree-container::-webkit-scrollbar { display: none; }",document.head.appendChild(e))},Zt=(e,t,a,n)=>{const s=[],l=[];let o=0;const m=(E,v,i)=>{for(let h=0;h<E.length;h++){const x=E[h],S=h===E.length-1,N=[...i,S],d=x.children!==void 0,u=d&&t(x.absolutePath,x.relativePath);let g=v,D=N,w=i;n&&(g=v-1,D=N.slice(1),w=i.slice(1)),s.push({entry:x,indentLevel:g,parentIsLast:D}),a&&(g>o&&(o=g),l.push({id:x.absolutePath,name:x.name,absolutePath:x.absolutePath,indentLevel:g,isLastChild:S,isDirectory:d,isExpanded:u,ancestorIsLast:[...w],hideLines:n&&v===0})),d&&u&&x.children&&m(x.children,v+1,N)}};return m(e,0,[]),{flatItems:s,lineItems:l,maxIndent:o}},yt=(e,t)=>{const a=e.length-1;if(a<=0)return 0;let n=0,s=a-1,l=0;for(;n<=s;){const o=n+s>>>1;e[o]<=t?(l=o,n=o+1):s=o-1}return l},Qt=(e,t,a,n,s,l)=>{const o=n?.renderStart??Math.max(0,yt(l,s)),m=t>0?yt(l,s+t)+a:o+a,E=e>0?Math.min(e-1,Math.max(o,m)):o,v=n?.renderEnd??E,i=e>0?Math.min(e-1,v+a):v;return{renderStart:o,renderEnd:v,lookaheadEnd:i}},Kt=(e,t,a,n,s,l)=>{if(e.length===0)return{segmentsByItem:[],glyphsByItem:[]};const o=Array.from({length:e.length},()=>[]),m=Array.from({length:e.length},()=>[]),E=i=>s?typeof l=="number"&&Number.isFinite(l)&&l>0?l:Math.max(8,Math.min(n*.9,i*.7)):0,v=3;for(let i=0;i<e.length;i++){const h=e[i];if(h.hideLines)continue;const x=[],S=t[i]??0,N=a[i]??0,d=N+S/2,u=E(S),g=u>0?u/2+2:n/1.5;for(let k=0;k<h.indentLevel;k++){if(h.ancestorIsLast[k]??!1)continue;let T=!1;for(let W=i;W<e.length;W++){const L=e[W];if(L.indentLevel>k&&L.ancestorIsLast.length>k&&!L.ancestorIsLast[k]){T=!0;break}if(W>i&&L.indentLevel===k)break}if(T){const W=k*n+n/2+v;x.push({key:`${h.id}-ancestor-${k}`,x1:W,y1:N,x2:W,y2:N+S,itemIndex:i})}}const D=h.indentLevel*n,w=D+n/2+v;if(h.isDirectory?x.push({key:`${h.id}-connector-top`,x1:w,y1:N,x2:w,y2:d-g,itemIndex:i}):x.push({key:`${h.id}-connector-top`,x1:w,y1:N,x2:w,y2:d,itemIndex:i}),!h.isDirectory&&h.isLastChild&&x.push({key:`${h.id}-connector-horizontal`,x1:w,y1:d,x2:D+n+v,y2:d,itemIndex:i}),h.isLastChild||(h.isDirectory?x.push({key:`${h.id}-connector-bottom`,x1:w,y1:d+g,x2:w,y2:N+S,itemIndex:i}):x.push({key:`${h.id}-connector-bottom`,x1:w,y1:d,x2:w,y2:N+S,itemIndex:i})),o[i]=x,s&&h.isDirectory){const k=u,y=w,T=d;m[i]=[{key:`${h.id}-glyph`,itemIndex:i,centerX:y,centerY:T,size:k,isExpanded:h.isExpanded}]}}return{segmentsByItem:o,glyphsByItem:m}},Le=c.memo(({entry:e,indentLevel:t,rowHeight:a,isDirOpen:n,parentIsLast:s,renderChildren:l=!0,expansion:{toggleDirectory:o,onToggleDirectoryRecursive:m},selection:{onEntryClick:E,selectedPath:v,mode:i="none",selectedItems:h,onSelectionChange:x},visual:{iconOverrides:S,showExpandIcons:N=!0,showDirectoryIcons:d=!0,showFileIcons:u=!0,useCanvasExpandIcons:g=!1,expandIconSize:D,highlightStyles:w,entryClassName:k,entryStyle:y,nameClassName:T,nameStyle:W,directoryNameClassName:L,directoryNameStyle:I,fileNameClassName:G,fileNameStyle:F}})=>{const[H,K]=c.useState(null),[z,X]=c.useState(!1),M=e.children!==void 0,U=M&&n(e.absolutePath),C=e.absolutePath===v,$=!M&&h?.has(e.absolutePath),re=M?void 0:pt(e.name);c.useEffect(()=>{K(U&&e.children?e.children:null)},[U,e.children]);const r=gt({entry:e,isDirectory:M,isExpanded:U,isItemSelected:!!$,selectionMode:i,onSelectionChange:x,onEntryClick:E,toggleDirectory:o,onToggleDirectoryRecursive:m}),b=z?w?.hoverClassName!==void 0?w.hoverClassName:O.entryHover:"",R=(()=>{if(M){if(C)return w?.directorySelectedClassName!==void 0?w.directorySelectedClassName:O.entrySelected}else if(C||$)return w?.itemSelectedClassName!==void 0?w.itemSelectedClassName:P.twMerge(C&&O.entrySelected,$&&O.entryItemSelected);return""})(),_=P.twMerge(O.entry,b,R,k,e.className),q=P.twMerge(O.expandIcon,(C||$)&&O.expandIconSelected),J=P.twMerge(O.typeIcon,(C||$)&&O.typeIconSelected),j=P.twMerge(O.name,T,M&&O.nameDirectory,M&&L,!M&&G,(C||$)&&O.nameSelected),Z=bt({isDirectory:M,isExpanded:U,showExpandIcons:N,useCanvasExpandIcons:g,expandIconSize:D}),B=(M?d:u)?vt({entry:e,isDirectory:M,isExpanded:U,isSelected:C,isItemSelected:!!$,extension:re},S):null,ie={...z?w?.hoverStyle:{},...M&&C?w?.directorySelectedStyle:{},...!M&&(C||$)?w?.itemSelectedStyle:{}};return p.jsxs(c.Fragment,{children:[p.jsxs("div",{className:_,style:{paddingLeft:`${Math.max(0,t*he)}px`,transform:t<0?`translateX(${t*he}px)`:void 0,width:t<0?`calc(100% + ${Math.abs(t*he)}px)`:void 0,height:`${a}px`,...ie,...y,...e.style},"data-entry-type":M?"directory":"file","data-entry-expanded":M?String(U):void 0,"data-entry-selected":C?"true":void 0,"data-entry-item-selected":$?"true":void 0,onClick:r,onMouseEnter:()=>X(!0),onMouseLeave:()=>X(!1),onKeyDown:se=>se.key==="Enter"&&r(se),tabIndex:0,role:"treeitem","aria-expanded":M?U:void 0,"aria-label":`${e.name} (${M?"directory":"file"})`,children:[(N||g)&&p.jsx("span",{className:q,children:Z}),(M?d:u)&&p.jsx("span",{className:J,children:B}),p.jsx("span",{className:j,style:{...W,...M?I:F},"data-entry-type":M?"directory":"file","data-entry-role":"name",children:e.label??e.name})]}),U&&H&&l&&p.jsx("fieldset",{children:H.map((se,Ne)=>p.jsx(Le,{entry:se,indentLevel:t+1,rowHeight:a,isDirOpen:n,parentIsLast:[...s,Ne===H.length-1],expansion:{toggleDirectory:o,onToggleDirectoryRecursive:m},selection:{onEntryClick:E,selectedPath:v,mode:i,selectedItems:h,onSelectionChange:x},visual:{iconOverrides:S,showExpandIcons:N,showDirectoryIcons:d,showFileIcons:u,useCanvasExpandIcons:g,expandIconSize:D,highlightStyles:w,entryClassName:k,entryStyle:y,nameClassName:T,nameStyle:W,directoryNameClassName:L,directoryNameStyle:I,fileNameClassName:G,fileNameStyle:F}},se.absolutePath))})]},e.absolutePath)},(e,t)=>{if(e.entry!==t.entry)return!1;const a=e.entry.children!==void 0,n=t.entry.children!==void 0,s=a&&e.isDirOpen(e.entry.absolutePath),l=n&&t.isDirOpen(t.entry.absolutePath);return e.indentLevel===t.indentLevel&&e.rowHeight===t.rowHeight&&s===l&&e.selection.selectedPath===t.selection.selectedPath&&e.selection.mode===t.selection.mode&&e.selection.selectedItems===t.selection.selectedItems&&e.visual.iconOverrides===t.visual.iconOverrides&&e.visual.showExpandIcons===t.visual.showExpandIcons&&e.visual.showDirectoryIcons===t.visual.showDirectoryIcons&&e.visual.showFileIcons===t.visual.showFileIcons&&e.visual.useCanvasExpandIcons===t.visual.useCanvasExpandIcons&&e.visual.expandIconSize===t.visual.expandIconSize&&e.visual.highlightStyles===t.visual.highlightStyles&&e.visual.entryClassName===t.visual.entryClassName&&e.visual.entryStyle===t.visual.entryStyle&&e.visual.nameClassName===t.visual.nameClassName&&e.visual.nameStyle===t.visual.nameStyle&&e.visual.directoryNameClassName===t.visual.directoryNameClassName&&e.visual.directoryNameStyle===t.visual.directoryNameStyle&&e.visual.fileNameClassName===t.visual.fileNameClassName&&e.visual.fileNameStyle===t.visual.fileNameStyle&&e.parentIsLast.length===t.parentIsLast.length&&e.parentIsLast.every((o,m)=>o===t.parentIsLast[m])});Le.displayName="DirectoryEntryItem";const It=e=>{const t=[];if(e.children)for(const a of e.children)a.type==="directory"&&(t.push(a.absolutePath),t.push(...It(a)));return t},er=({entries:e,expansion:{toggle:t,isExpanded:a,expandMultiple:n,collapseMultiple:s,isPending:l,alwaysExpanded:o=!1,doubleClickAction:m="recursive"},selection:{onEntryClick:E,selectedPath:v,mode:i="none",selectedItems:h,onSelectionChange:x},visual:{className:S,style:N,lineColor:d="#A0AEC0",showTreeLines:u=!0,showExpandIcons:g=!0,showDirectoryIcons:D=!0,showFileIcons:w=!0,iconOverrides:k,expandIconSize:y,itemHeight:T=ke,removeRootIndent:W=!1,highlightStyles:L,entryClassName:I,entryStyle:G,nameClassName:F,nameStyle:H,directoryNameClassName:K,directoryNameStyle:z,fileNameClassName:X,fileNameStyle:M}={},virtualScroll:U,grid:C})=>{const $=C!==void 0,[re,r]=c.useState(!1),b=c.useRef(null),R=c.useRef(null),_=c.useRef(null),[q,J]=c.useState(0),[j,Z]=c.useState(0),[B,ie]=c.useState(0),[se,Ne]=c.useState(null),{overscanCount:be=15,className:He,background:$e,onScroll:We,onRangeChange:Fe,initialScrollIndex:Be,initialScrollOffset:de,callbackThrottleMs:Ye=5,contentInsets:Ge,onItemFocus:Ue,viewportHeightOverride:ee,scrollBarOptions:Ie,behaviorOptions:Ve}=U??{},[ve,ze]=c.useState(typeof de=="number"?de:0),Xe=c.useCallback((f,A)=>{ze(f),We?.(f,A)},[We]),qe=c.useCallback(f=>{const{renderingStartIndex:A,renderingEndIndex:Y}=f;Ne(Q=>Q&&Q.renderStart===A&&Q.renderEnd===Y?Q:{renderStart:A,renderEnd:Y}),Fe?.(f)},[Fe]);c.useEffect(()=>{typeof de=="number"&&ze(de)},[de]),c.useEffect(()=>{r(!0),Jt()},[]),c.useEffect(()=>{const f=b.current,A=$?R.current:f,Y=()=>{if(f){const ne=f.clientWidth;Z(me=>Math.abs(me-ne)>1?ne:me)}if(typeof ee=="number")J(ne=>Math.abs(ne-ee)>1?ee:ne);else if(A){const ne=A.clientHeight;J(me=>Math.abs(me-ne)>1?ne:me)}};if(!(f||A))return J(0);Y();const Q=new ResizeObserver(Y);return f&&Q.observe(f),A&&A!==f&&Q.observe(A),()=>Q.disconnect()},[ee,$]);const ae=typeof ee=="number"?ee:q,oe=c.useCallback(f=>o||(re?a(f):!1),[re,a,o]),Re=P.twMerge(O.container,l&&O.containerPending,S),Te=c.useMemo(()=>({...qt,...N??{},...typeof ee=="number"?{height:ee,minHeight:ee}:{}}),[N,ee]),Me=c.useCallback((f,A)=>{const Y=[f.absolutePath,...It(f)],Q=A||m;if(Y.every(Pe=>oe(Pe)))return s(Y);if(Y.every(Pe=>!oe(Pe))||Q==="recursive")return n(Y);if(Q==="toggle")return s(Y);console.warn(`[DirectoryTree] Unknown double click action: ${Q}. No action taken.`)},[oe,n,s,m]),Je=$?!1:W,{flatItems:Ze,lineItems:_e,maxIndent:Qe}=c.useMemo(()=>Zt(e,oe,u,Je),[e,oe,u,Je]),te=c.useMemo(()=>Ze.map((f,A)=>{const Y=typeof T=="function"?T(f.entry,A):T;return{...f,rowHeight:Number.isFinite(Y)&&Y>0?Y:ke}}),[Ze,T]),le=c.useMemo(()=>te.map(f=>f.rowHeight),[te]),ge=c.useMemo(()=>{const f=new Array(le.length+1);f[0]=0;for(let A=0;A<le.length;A++)f[A+1]=f[A]+le[A];return f},[le]),Ke=c.useCallback(f=>te[f]?.rowHeight??ke,[te]),xe=c.useMemo(()=>!u||_e.length===0?{segmentsByItem:[],glyphsByItem:[]}:Kt(_e,le,ge,he,u,y??ft),[_e,le,ge,u,y]),we=c.useMemo(()=>!u||e.length===0?0:(Qe+2)*he,[e.length,Qe,u]),{renderStart:et,renderEnd:tt,lookaheadEnd:rt}=c.useMemo(()=>Qt(te.length,ae,be,se,ve,ge),[te.length,ae,be,se,ve,ge]),je=c.useMemo(()=>!u||we<=0||ae<=0||xe.segmentsByItem.length===0?null:p.jsx("div",{className:"pointer-events-none absolute inset-0 z-0","aria-hidden":"true",children:p.jsx("div",{className:"absolute top-0 left-0",style:{width:we,height:ae},children:p.jsx(Nt,{segmentsByItem:xe.segmentsByItem,glyphsByItem:xe.glyphsByItem,itemHeight:le[0]??ke,width:we,viewportHeight:ae,scrollPosition:ve,color:d,expandGlyphColor:d,expandGlyphSize:y??ft,renderStartIndex:et,renderEndIndex:tt,lookaheadEndIndex:rt})})}),[we,ae,et,tt,rt,ve,xe,d,u,y,le]),nt=c.useCallback(f=>te[f],[te]),ce=C?.columns,ue=C?.scrollBarWidth??Ie?.width??Ct,V=c.useMemo(()=>ce?Ft({measuredWidth:j,columns:ce,scrollBarWidth:ue}):null,[ce,j,ue]),Ee=c.useMemo(()=>ce?Wt(ce):"",[ce]),Rt=c.useMemo(()=>C?.showFooter&&ce?Bt(e):[],[C?.showFooter,ce,e]),fe=V?.maxHScroll??0;c.useEffect(()=>{ie(f=>Ae(f,fe))},[fe]);const st=c.useCallback(f=>ie(A=>Ae(A+f,fe)),[fe]),at=c.useMemo(()=>({iconOverrides:k,showExpandIcons:g,showDirectoryIcons:D,showFileIcons:w,useCanvasExpandIcons:u,expandIconSize:y,highlightStyles:L}),[k,g,D,w,u,y,L]),ot=e.length===0,lt=c.useMemo(()=>p.jsx(ct.VirtualScroll,{ref:_,itemCount:te.length,getItem:nt,getItemHeight:Ke,viewportSize:ae,overscanCount:be,onScroll:Xe,onRangeChange:qe,className:He,onWheelHorizontal:$?st:void 0,background:p.jsxs(p.Fragment,{children:[$&&V?p.jsx("div",{className:"pointer-events-none absolute top-0 left-0 z-0 h-full overflow-hidden",style:{width:V.nameWidth},"aria-hidden":"true",children:je}):je,$e]}),initialScrollIndex:Be,initialScrollOffset:de,onItemFocus:Ue,callbackThrottleMs:Ye,contentInsets:Ge,scrollBarOptions:Ie,behaviorOptions:Ve,children:f=>f?$&&C&&V?p.jsx(Et,{entry:f.entry,indentLevel:f.indentLevel,rowHeight:f.rowHeight,isDirOpen:oe,columns:C.columns,numericTemplate:Ee,numericTotal:V.numericTotal,nameWidth:V.nameWidth,rowClassName:C.rowClassName,selection:{onEntryClick:E,selectedPath:v??null,mode:i,selectedItems:h,onSelectionChange:x},expansion:{toggleDirectory:t,onToggleDirectoryRecursive:Me},visual:at},f.entry.absolutePath):p.jsx(Le,{entry:f.entry,indentLevel:f.indentLevel,rowHeight:f.rowHeight,isDirOpen:oe,parentIsLast:f.parentIsLast,renderChildren:!1,expansion:{toggleDirectory:t,onToggleDirectoryRecursive:Me},selection:{onEntryClick:E,selectedPath:v??null,mode:i,selectedItems:h,onSelectionChange:x},visual:{iconOverrides:k,showExpandIcons:g,showDirectoryIcons:D,showFileIcons:w,useCanvasExpandIcons:u,expandIconSize:y,highlightStyles:L,entryClassName:I,entryStyle:G,nameClassName:F,nameStyle:H,directoryNameClassName:K,directoryNameStyle:z,fileNameClassName:X,fileNameStyle:M}},f.entry.absolutePath):null}),[te.length,nt,Ke,ae,be,Xe,qe,He,$,st,V,je,$e,Be,de,Ue,Ye,Ge,Ie,Ve,C,Ee,oe,E,v,i,h,x,t,Me,at,k,g,D,w,u,y,L,I,G,F,H,K,z,X,M]);if(!(C&&V))return ot?p.jsx("div",{className:Re,style:Te}):p.jsx("div",{ref:b,className:Re,style:Te,role:"tree",children:lt});const Tt=C.showHeader??!0,Mt=C.showFooter??!1,_t={...Te,"--dt-hscroll":`${B}px`};return p.jsxs("div",{ref:b,className:P.twMerge(Re,"dt-grid"),style:_t,role:"treegrid",children:[Tt&&p.jsx(Lt,{columns:C.columns,numericTemplate:Ee,numericTotal:V.numericTotal,nameWidth:V.nameWidth,scrollBarWidth:ue,className:C.headerClassName}),p.jsx("div",{ref:R,className:"dt-grid-body",children:!ot&<}),fe>0&&p.jsxs("div",{className:"dt-grid-hscrollbar-row",children:[p.jsx("div",{className:"dt-grid-scrollbar-spacer",style:{width:V.nameWidth},"aria-hidden":"true"}),p.jsx(ct.ScrollBar,{horizontal:!0,contentSize:V.numericTotal,viewportSize:V.numericVisible,scrollPosition:B,scrollBarWidth:ue,onScroll:f=>{const A=typeof f=="function"?f(B):f,Y=Ae(A,fe);return ie(Y),Y}}),p.jsx("div",{className:"dt-grid-scrollbar-spacer",style:{width:ue},"aria-hidden":"true"})]}),Mt&&p.jsx(Ht,{columns:C.columns,numericTemplate:Ee,numericTotal:V.numericTotal,nameWidth:V.nameWidth,scrollBarWidth:ue,allEntries:Rt,className:C.footerClassName})]})},tr=({initialExpanded:e=new Set,storageKey:t}={})=>{const[a,n]=c.useTransition(),[s,l]=c.useState(()=>{if(typeof window<"u"&&t)try{const d=window.localStorage.getItem(t);if(d){const u=JSON.parse(d);return new Set(u)}}catch(d){console.error("[useDirectoryTreeState] Error reading from localStorage",d)}return e}),o=c.useCallback(d=>{n(()=>{l(u=>{const g=new Set(u);return d(g),g})})},[]),m=c.useCallback((d,u)=>{o(g=>{for(const D of d)u(g,D)})},[o]);c.useEffect(()=>{if(t&&typeof window<"u")try{window.localStorage.setItem(t,JSON.stringify(Array.from(s)))}catch(d){console.warn(`Error setting localStorage key "${t}":`,d)}},[s,t]);const E=c.useCallback(d=>{m([d],(u,g)=>{u.has(g)?u.delete(g):u.add(g)})},[m]),v=c.useCallback(d=>{m([d],(u,g)=>{u.add(g)})},[m]),i=c.useCallback(d=>{m([d],(u,g)=>{u.delete(g)})},[m]),h=c.useCallback(d=>{m(d,(u,g)=>{u.delete(g)})},[m]),x=c.useCallback(d=>{m(d,(u,g)=>{u.add(g)})},[m]),S=c.useCallback(()=>{o(d=>{d.clear()})},[o]),N=c.useCallback(d=>s.has(d),[s]);return{expanded:s,toggle:E,expand:v,collapse:i,collapseMultiple:h,expandMultiple:x,collapseAll:S,isExpanded:N,isPending:a}};exports.DirectoryTree=er;exports.directoryTreeClasses=O;exports.useDirectoryTreeState=tr;
|
|
6
|
+
<%s key={someKey} {...props} />`,_,j,Z,j),re[j+_]=!0)}if(j=null,R!==void 0&&(a(R),j=""+R),o(b)&&(a(b.key),j=""+b.key),"key"in b){R={};for(var B in b)B!=="key"&&(R[B]=b[B])}else R=b;return j&&m(R,typeof r=="function"?r.displayName||r.name||"Unknown":r),v(r,j,R,s(),q,J)}function h(r){x(r)?r._store&&(r._store.validated=1):typeof r=="object"&&r!==null&&r.$$typeof===I&&(r._payload.status==="fulfilled"?x(r._payload.value)&&r._payload.value._store&&(r._payload.value._store.validated=1):r._store&&(r._store.validated=1))}function x(r){return typeof r=="object"&&r!==null&&r.$$typeof===N}var S=c,N=Symbol.for("react.transitional.element"),d=Symbol.for("react.portal"),u=Symbol.for("react.fragment"),g=Symbol.for("react.strict_mode"),D=Symbol.for("react.profiler"),w=Symbol.for("react.consumer"),k=Symbol.for("react.context"),y=Symbol.for("react.forward_ref"),T=Symbol.for("react.suspense"),W=Symbol.for("react.suspense_list"),L=Symbol.for("react.memo"),I=Symbol.for("react.lazy"),G=Symbol.for("react.activity"),F=Symbol.for("react.client.reference"),H=S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,K=Object.prototype.hasOwnProperty,z=Array.isArray,X=console.createTask?console.createTask:function(){return null};S={react_stack_bottom_frame:function(r){return r()}};var M,U={},C=S.react_stack_bottom_frame.bind(S,l)(),$=X(n(l)),re={};pe.Fragment=u,pe.jsx=function(r,b,R){var _=1e4>H.recentlyCreatedOwnerStacks++;return i(r,b,R,!1,_?Error("react-stack-top-frame"):C,_?X(n(r)):$)},pe.jsxs=function(r,b,R){var _=1e4>H.recentlyCreatedOwnerStacks++;return i(r,b,R,!0,_?Error("react-stack-top-frame"):C,_?X(n(r)):$)}})()),pe}var ut;function Ot(){return ut||(ut=1,process.env.NODE_ENV==="production"?Se.exports=Pt():Se.exports=At()),Se.exports}var p=Ot();const ke=20,he=16,ft=12,O={container:"directory-tree-container relative h-full transition-opacity duration-300 overflow-y-hidden pb-[5px] pr-[3px]",containerPending:"opacity-70",entry:"directory-tree-entry flex items-center cursor-pointer relative select-none",entryHover:P.twMerge("directory-tree-entry--hover hover:bg-gray-400/15","dark:hover:bg-gray-200/10"),entrySelected:P.twMerge("directory-tree-entry--selected bg-blue-400/10","dark:bg-blue-400/15"),entryItemSelected:P.twMerge("directory-tree-entry--item-selected bg-blue-400/20 shadow-[0_0_0_1px_rgba(59,130,246,0.3)]","dark:bg-blue-400/25 dark:shadow-[0_0_0_1px_rgba(96,165,250,0.4)]"),expandIcon:P.twMerge("directory-tree-expand-icon w-5 h-5 flex-shrink-0 flex items-center justify-center","text-gray-500","dark:text-gray-400"),expandIconSelected:P.twMerge("directory-tree-expand-icon--selected text-blue-700","dark:text-blue-400"),typeIcon:P.twMerge("directory-tree-type-icon w-5 h-5 flex-shrink-0 flex items-center justify-center","text-gray-500","dark:text-gray-400"),typeIconSelected:P.twMerge("directory-tree-type-icon--selected text-blue-700","dark:text-blue-400"),name:P.twMerge("directory-tree-name overflow-hidden text-ellipsis whitespace-nowrap ml-1","text-gray-700","dark:text-gray-200"),nameDirectory:"directory-tree-name--directory",nameSelected:P.twMerge("directory-tree-name--selected text-blue-800 font-medium","dark:text-blue-300")},pt=e=>e.slice((e.lastIndexOf(".")-1>>>0)+2).toLowerCase(),bt=({isDirectory:e,isExpanded:t,showExpandIcons:a,useCanvasExpandIcons:n,expandIconSize:s})=>{const l=s?{width:s,height:s}:void 0,o=s?"":"h-4 w-4";return!(a&&e)||n?p.jsx("span",{className:o,style:l,"aria-hidden":"true"}):t?p.jsx(Ce.ChevronDownIcon,{className:o,style:l}):p.jsx(Ce.ChevronRightIcon,{className:o,style:l})},Oe=(e,t)=>{if(e==null||typeof e=="boolean")return null;if(typeof e=="function")return console.warn(`[DirectoryTree] Function returned by renderer for "${t}". Return a node.`),null;if(typeof e=="object"){if("then"in e)return console.warn(`[DirectoryTree] Promise returned for "${t}". Not supported.`),null;if(Array.isArray(e)){const n=e.map(s=>Oe(s,t)).filter(Boolean);return n.length?n:null}const a=e.type;if(a&&a.$$typeof===Symbol.for("react.lazy"))return console.warn(`[DirectoryTree] Lazy component for "${t}". Not supported.`),null}return e},vt=(e,t)=>{const{entry:a,isDirectory:n,isExpanded:s,extension:l}=e;let o;return a.icon!==void 0?o=a.icon:n?o=s&&t?.directoryExpanded||t?.directory||p.jsx(Ce.FolderIcon,{className:"h-4 w-4"}):l&&t?.fileByExtension?.[l]?o=t.fileByExtension[l]:o=t?.file||(l==="md"?p.jsx(Ce.DocumentTextIcon,{className:"h-4 w-4"}):p.jsx(jt.FileIcon,{className:"h-4 w-4"})),Oe(typeof o=="function"?o(e):o,a.absolutePath)},Dt=500,gt=({entry:e,isDirectory:t,isExpanded:a,isItemSelected:n,selectionMode:s,onSelectionChange:l,onEntryClick:o,toggleDirectory:m,onToggleDirectoryRecursive:E})=>{const v=c.useRef(null);return c.useEffect(()=>()=>{v.current&&window.clearTimeout(v.current)},[]),c.useCallback(i=>{i.stopPropagation(),s!=="none"&&!t&&l&&l(e,!n);let h=!1;o({entry:e,isDirectory:t,isExpanded:a,preventDefault:()=>{h=!0}}),!(!t||h)&&(v.current?(window.clearTimeout(v.current),v.current=null,E(e)):v.current=window.setTimeout(()=>{m(e.absolutePath),v.current=null},Dt))},[t,e,a,E,m,o,s,l,n])},xt=e=>e==="right"?"dt-grid-cell--right":e==="center"?"dt-grid-cell--center":"",mt=(e,t)=>e.children!==void 0&&t(e.absolutePath),wt=(e,t)=>({width:e,gridTemplateColumns:t}),Et=c.memo(({entry:e,indentLevel:t,rowHeight:a,isDirOpen:n,columns:s,numericTemplate:l,numericTotal:o,nameWidth:m,rowClassName:E,selection:{onEntryClick:v,selectedPath:i,mode:h="none",selectedItems:x,onSelectionChange:S},expansion:{toggleDirectory:N,onToggleDirectoryRecursive:d},visual:{iconOverrides:u,showExpandIcons:g=!0,showDirectoryIcons:D=!0,showFileIcons:w=!0,useCanvasExpandIcons:k=!1,expandIconSize:y,highlightStyles:T}})=>{const[W,L]=c.useState(!1),I=e.children!==void 0,G=I&&n(e.absolutePath),F=e.absolutePath===i,H=!I&&!!x?.has(e.absolutePath),K=I?void 0:pt(e.name),z=gt({entry:e,isDirectory:I,isExpanded:G,isItemSelected:H,selectionMode:h,onSelectionChange:S,onEntryClick:v,toggleDirectory:N,onToggleDirectoryRecursive:d}),X=W?T?.hoverClassName!==void 0?T.hoverClassName:O.entryHover:"",M=(()=>{if(I){if(F)return T?.directorySelectedClassName!==void 0?T.directorySelectedClassName:O.entrySelected}else if(F||H)return T?.itemSelectedClassName!==void 0?T.itemSelectedClassName:P.twMerge(F&&O.entrySelected,H&&O.entryItemSelected);return""})(),U=typeof E=="function"?E(e):E,C=P.twMerge("dt-grid-row cursor-pointer select-none",X,M,U,e.className),$=P.twMerge(O.expandIcon,(F||H)&&O.expandIconSelected),re=P.twMerge(O.typeIcon,(F||H)&&O.typeIconSelected),r=P.twMerge("dt-grid-name-label ml-1","text-gray-700 dark:text-gray-200",I&&O.nameDirectory,(F||H)&&O.nameSelected),b=bt({isDirectory:I,isExpanded:G,showExpandIcons:g,useCanvasExpandIcons:k,expandIconSize:y}),R=(I?D:w)?vt({entry:e,isDirectory:I,isExpanded:G,isSelected:F,isItemSelected:H,extension:K},u):null,_={indentLevel:t,isDirectory:I,isExpanded:G},[q,...J]=s,j=q?.render?q.render(e,_):e.label??e.name,Z={...W?T?.hoverStyle:{},...I&&F?T?.directorySelectedStyle:{},...!I&&(F||H)?T?.itemSelectedStyle:{}};return p.jsxs("div",{className:C,style:{height:a,...Z,...e.style},role:"row","aria-expanded":I?G:void 0,"aria-level":t+1,"data-entry-type":I?"directory":"file","data-entry-expanded":I?String(G):void 0,"data-entry-selected":F?"true":void 0,"data-entry-item-selected":H?"true":void 0,onClick:z,onMouseEnter:()=>L(!0),onMouseLeave:()=>L(!1),onKeyDown:B=>B.key==="Enter"&&z(B),tabIndex:0,children:[p.jsxs("div",{className:P.twMerge("dt-grid-name-cell",q?.className),role:"gridcell",style:{width:m,paddingLeft:Math.max(0,t*he)},children:[(g||k)&&p.jsx("span",{className:$,children:b}),(I?D:w)&&p.jsx("span",{className:re,children:R}),p.jsx("span",{className:r,children:j})]}),J.length>0&&p.jsx("div",{className:"dt-grid-numeric-viewport",children:p.jsx("div",{className:"dt-grid-numeric-track",style:wt(o,l),children:J.map(B=>p.jsx("div",{className:P.twMerge("dt-grid-cell",xt(B.align),B.className),role:"gridcell",children:B.render?B.render(e,_):null},B.key))})})]})},(e,t)=>{if(e.entry!==t.entry)return!1;const a=mt(e.entry,e.isDirOpen),n=mt(t.entry,t.isDirOpen);return e.indentLevel===t.indentLevel&&e.rowHeight===t.rowHeight&&a===n&&e.columns===t.columns&&e.numericTemplate===t.numericTemplate&&e.numericTotal===t.numericTotal&&e.nameWidth===t.nameWidth&&e.rowClassName===t.rowClassName&&e.selection.selectedPath===t.selection.selectedPath&&e.selection.mode===t.selection.mode&&e.selection.selectedItems===t.selection.selectedItems&&e.visual===t.visual});Et.displayName="DirectoryTreeGridRow";const St=({kind:e,columns:t,numericTemplate:a,numericTotal:n,nameWidth:s,scrollBarWidth:l,className:o,nameContent:m,renderCell:E})=>{const[,...v]=t,i=e==="header"?"dt-grid-name-header":"dt-grid-name-footer",h=e==="header"?"dt-grid-header":"dt-grid-footer",x=e==="header"?"columnheader":"gridcell";return p.jsxs("div",{className:P.twMerge(h,"text-gray-600 dark:text-gray-300",o),role:"row",children:[p.jsx("div",{className:P.twMerge(i,"px-1",t[0]?.className),role:x,style:{width:s},children:m}),v.length>0&&p.jsx("div",{className:"dt-grid-numeric-viewport",children:p.jsx("div",{className:"dt-grid-numeric-track",style:wt(n,a),children:v.map(S=>p.jsx("div",{className:P.twMerge("dt-grid-cell",xt(S.align),S.className),role:x,children:E(S)},S.key))})}),p.jsx("div",{className:"dt-grid-scrollbar-spacer",style:{width:l},"aria-hidden":"true"})]})},Lt=({columns:e,className:t,...a})=>p.jsx(St,{kind:"header",columns:e,className:t,nameContent:e[0]?.header??null,renderCell:n=>n.header??null,...a}),ht=(e,t)=>typeof e=="function"?e(t):e??null,Ht=({columns:e,allEntries:t,className:a,...n})=>p.jsx(St,{kind:"footer",columns:e,className:a,nameContent:ht(e[0]?.footer,t),renderCell:s=>ht(s.footer,t),...n}),$t=240,kt=96,Ct=12,De=(e,t)=>{const a=e?.width;return typeof a=="number"&&Number.isFinite(a)&&a>0?a:t},Wt=e=>e.slice(1).map(t=>`${De(t,kt)}px`).join(" "),Ft=({measuredWidth:e,columns:t,scrollBarWidth:a=Ct})=>{const n=De(t[0],$t),s=t.slice(1).reduce((E,v)=>E+De(v,kt),0),l=Number.isFinite(e)&&e>0?e:0,o=Math.max(0,l-n-Math.max(0,a)),m=Math.max(0,s-o);return{nameWidth:n,numericTotal:s,numericVisible:o,maxHScroll:m}},Ae=(e,t)=>!Number.isFinite(e)||e<0?0:e>t?t:e,Bt=e=>{const t=[],a=n=>{for(const s of n)t.push(s),s.children&&s.children.length>0&&a(s.children)};return a(e),t},Yt=(e,t,a)=>{const n=[];for(let s=t;s<a;s++){const l=e[s];if(!(!l||l.length===0))for(const o of l)n.push(o)}return n},Gt=(e,t,a)=>{const n=[];for(let s=t;s<a;s++){const l=e[s];if(!(!l||l.length===0))for(const o of l)n.push(o)}return n},Ut=(e,t,a,n)=>{const s=Math.max(1,Math.floor(t*n)),l=Math.max(1,Math.floor(a*n));(e.width!==s||e.height!==l)&&(e.width=s,e.height=l);const o=e.style;o.width!==`${t}px`&&(o.width=`${t}px`),o.height!==`${a}px`&&(o.height=`${a}px`)},Vt=(e,t,a)=>{e.lineWidth=a,e.beginPath();for(const n of t)e.moveTo(n.x1,n.y1),e.lineTo(n.x2,n.y2);e.stroke()},zt=(e,t)=>{const a=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(!a)return null;let n=a[1];n.length===3&&(n=n.split("").map(m=>m+m).join(""));const s=Number.parseInt(n.slice(0,2),16),l=Number.parseInt(n.slice(2,4),16),o=Number.parseInt(n.slice(4,6),16);return`rgba(${s}, ${l}, ${o}, ${t})`},Xt=(e,t,a,n)=>{if(t.length===0)return;const s=zt(a,.14),l=e.strokeStyle,o=e.fillStyle,m=e.lineWidth,E=e.lineCap,v=e.lineJoin;e.strokeStyle=a,e.lineCap="round",e.lineJoin="round";for(const i of t){const h=n??i.size,x=Math.max(0,h/2),S=Math.max(1,Math.round(h*.08)),N=Math.max(1,Math.round(h*.14)),d=Math.max(0,x-S*.8),u=Math.max(0,d*.55);s&&(e.fillStyle=s,e.beginPath(),e.arc(i.centerX,i.centerY,d,0,Math.PI*2),e.fill()),e.lineWidth=S,e.beginPath(),e.arc(i.centerX,i.centerY,Math.max(0,x-S*.3),0,Math.PI*2),e.stroke(),e.lineWidth=N,e.beginPath(),e.moveTo(i.centerX-u,i.centerY),e.lineTo(i.centerX+u,i.centerY),e.stroke(),i.isExpanded||(e.beginPath(),e.moveTo(i.centerX,i.centerY-u),e.lineTo(i.centerX,i.centerY+u),e.stroke())}e.strokeStyle=l,e.fillStyle=o,e.lineWidth=m,e.lineCap=E,e.lineJoin=v},Nt=c.memo(({segmentsByItem:e,glyphsByItem:t,itemHeight:a,width:n,viewportHeight:s,scrollPosition:l,color:o="#a0aec0",strokeWidth:m=1,renderStartIndex:E,renderEndIndex:v,lookaheadEndIndex:i,devicePixelRatio:h,expandGlyphColor:x,expandGlyphSize:S})=>{const N=c.useRef(null),d=c.useRef(null),u=c.useRef({segmentsByItem:e,glyphsByItem:t,itemHeight:a,width:n,viewportHeight:s,scrollPosition:l,color:o,strokeWidth:m,renderStartIndex:E,renderEndIndex:v,lookaheadEndIndex:i,devicePixelRatio:h,expandGlyphColor:x,expandGlyphSize:S}),g=c.useCallback(()=>{d.current=null;const w=N.current;if(!w)return;const k=w.getContext("2d");if(!k)return;const y=u.current;if(y.width<=0||y.viewportHeight<=0){k.clearRect(0,0,w.width,w.height);return}const T=Number.isFinite(y.devicePixelRatio??NaN)?y.devicePixelRatio:typeof window<"u"&&window.devicePixelRatio||1;Ut(w,y.width,y.viewportHeight,T);const W=y.segmentsByItem.length,L=typeof y.renderStartIndex=="number"&&Number.isFinite(y.renderStartIndex)?Math.max(0,Math.floor(y.renderStartIndex)):Math.max(0,Math.floor(y.scrollPosition/y.itemHeight)),I=Math.min(W,Math.ceil((y.scrollPosition+y.viewportHeight)/y.itemHeight)),G=(()=>{if(typeof y.renderEndIndex=="number"&&Number.isFinite(y.renderEndIndex)){const z=Math.floor(y.renderEndIndex);return Math.max(Math.min(W,z+1),L)}return Math.max(I,L)})(),F=(()=>{if(typeof y.lookaheadEndIndex=="number"&&Number.isFinite(y.lookaheadEndIndex)){const z=Math.floor(y.lookaheadEndIndex),X=Math.min(W,z+1);return Math.max(X,G)}return Math.max(I,G)})(),H=Yt(y.segmentsByItem,L,F),K=Gt(y.glyphsByItem,L,F);k.save(),k.scale(T,T),k.clearRect(0,0,y.width,y.viewportHeight),k.translate(0,-y.scrollPosition),k.strokeStyle=y.color,Vt(k,H,y.strokeWidth),Xt(k,K,y.expandGlyphColor??y.color,y.expandGlyphSize),k.restore()},[]),D=c.useCallback(()=>{d.current===null&&(d.current=window.requestAnimationFrame(g))},[g]);return c.useEffect(()=>{u.current={segmentsByItem:e,glyphsByItem:t,itemHeight:a,width:n,viewportHeight:s,scrollPosition:l,color:o,strokeWidth:m,renderStartIndex:E,renderEndIndex:v,lookaheadEndIndex:i,devicePixelRatio:h,expandGlyphColor:x,expandGlyphSize:S},D()},[e,t,a,n,s,l,o,m,E,v,i,h,x,S,D]),c.useEffect(()=>()=>{d.current!==null&&(window.cancelAnimationFrame(d.current),d.current=null)},[]),p.jsx("canvas",{ref:N,className:"pointer-events-none absolute top-0 left-0 z-0"})});Nt.displayName="TreeLineCanvas";const qt={msOverflowStyle:"none",scrollbarWidth:"none"},Jt=()=>{let e=document.getElementById("directory-tree-webkit-scrollbar-hide");e||(e=document.createElement("style"),e.id="directory-tree-webkit-scrollbar-hide",e.textContent=".directory-tree-container::-webkit-scrollbar { display: none; }",document.head.appendChild(e))},Zt=(e,t,a,n)=>{const s=[],l=[];let o=0;const m=(E,v,i)=>{for(let h=0;h<E.length;h++){const x=E[h],S=h===E.length-1,N=[...i,S],d=x.children!==void 0,u=d&&t(x.absolutePath,x.relativePath);let g=v,D=N,w=i;n&&(g=v-1,D=N.slice(1),w=i.slice(1)),s.push({entry:x,indentLevel:g,parentIsLast:D}),a&&(g>o&&(o=g),l.push({id:x.absolutePath,name:x.name,absolutePath:x.absolutePath,indentLevel:g,isLastChild:S,isDirectory:d,isExpanded:u,ancestorIsLast:[...w],hideLines:n&&v===0})),d&&u&&x.children&&m(x.children,v+1,N)}};return m(e,0,[]),{flatItems:s,lineItems:l,maxIndent:o}},yt=(e,t)=>{const a=e.length-1;if(a<=0)return 0;let n=0,s=a-1,l=0;for(;n<=s;){const o=n+s>>>1;e[o]<=t?(l=o,n=o+1):s=o-1}return l},Qt=(e,t,a,n,s,l)=>{const o=n?.renderStart??Math.max(0,yt(l,s)),m=t>0?yt(l,s+t)+a:o+a,E=e>0?Math.min(e-1,Math.max(o,m)):o,v=n?.renderEnd??E,i=e>0?Math.min(e-1,v+a):v;return{renderStart:o,renderEnd:v,lookaheadEnd:i}},Kt=(e,t,a,n,s,l)=>{if(e.length===0)return{segmentsByItem:[],glyphsByItem:[]};const o=Array.from({length:e.length},()=>[]),m=Array.from({length:e.length},()=>[]),E=i=>s?typeof l=="number"&&Number.isFinite(l)&&l>0?l:Math.max(8,Math.min(n*.9,i*.7)):0,v=3;for(let i=0;i<e.length;i++){const h=e[i];if(h.hideLines)continue;const x=[],S=t[i]??0,N=a[i]??0,d=N+S/2,u=E(S),g=u>0?u/2+2:n/1.5;for(let k=0;k<h.indentLevel;k++){if(h.ancestorIsLast[k]??!1)continue;let T=!1;for(let W=i;W<e.length;W++){const L=e[W];if(L.indentLevel>k&&L.ancestorIsLast.length>k&&!L.ancestorIsLast[k]){T=!0;break}if(W>i&&L.indentLevel===k)break}if(T){const W=k*n+n/2+v;x.push({key:`${h.id}-ancestor-${k}`,x1:W,y1:N,x2:W,y2:N+S,itemIndex:i})}}const D=h.indentLevel*n,w=D+n/2+v;if(h.isDirectory?x.push({key:`${h.id}-connector-top`,x1:w,y1:N,x2:w,y2:d-g,itemIndex:i}):x.push({key:`${h.id}-connector-top`,x1:w,y1:N,x2:w,y2:d,itemIndex:i}),!h.isDirectory&&h.isLastChild&&x.push({key:`${h.id}-connector-horizontal`,x1:w,y1:d,x2:D+n+v,y2:d,itemIndex:i}),h.isLastChild||(h.isDirectory?x.push({key:`${h.id}-connector-bottom`,x1:w,y1:d+g,x2:w,y2:N+S,itemIndex:i}):x.push({key:`${h.id}-connector-bottom`,x1:w,y1:d,x2:w,y2:N+S,itemIndex:i})),o[i]=x,s&&h.isDirectory){const k=u,y=w,T=d;m[i]=[{key:`${h.id}-glyph`,itemIndex:i,centerX:y,centerY:T,size:k,isExpanded:h.isExpanded}]}}return{segmentsByItem:o,glyphsByItem:m}},Le=c.memo(({entry:e,indentLevel:t,rowHeight:a,isDirOpen:n,parentIsLast:s,renderChildren:l=!0,expansion:{toggleDirectory:o,onToggleDirectoryRecursive:m},selection:{onEntryClick:E,selectedPath:v,mode:i="none",selectedItems:h,onSelectionChange:x},visual:{iconOverrides:S,showExpandIcons:N=!0,showDirectoryIcons:d=!0,showFileIcons:u=!0,useCanvasExpandIcons:g=!1,expandIconSize:D,highlightStyles:w,entryClassName:k,entryStyle:y,nameClassName:T,nameStyle:W,directoryNameClassName:L,directoryNameStyle:I,fileNameClassName:G,fileNameStyle:F}})=>{const[H,K]=c.useState(null),[z,X]=c.useState(!1),M=e.children!==void 0,U=M&&n(e.absolutePath),C=e.absolutePath===v,$=!M&&h?.has(e.absolutePath),re=M?void 0:pt(e.name);c.useEffect(()=>{K(U&&e.children?e.children:null)},[U,e.children]);const r=gt({entry:e,isDirectory:M,isExpanded:U,isItemSelected:!!$,selectionMode:i,onSelectionChange:x,onEntryClick:E,toggleDirectory:o,onToggleDirectoryRecursive:m}),b=z?w?.hoverClassName!==void 0?w.hoverClassName:O.entryHover:"",R=(()=>{if(M){if(C)return w?.directorySelectedClassName!==void 0?w.directorySelectedClassName:O.entrySelected}else if(C||$)return w?.itemSelectedClassName!==void 0?w.itemSelectedClassName:P.twMerge(C&&O.entrySelected,$&&O.entryItemSelected);return""})(),_=P.twMerge(O.entry,b,R,k,e.className),q=P.twMerge(O.expandIcon,(C||$)&&O.expandIconSelected),J=P.twMerge(O.typeIcon,(C||$)&&O.typeIconSelected),j=P.twMerge(O.name,T,M&&O.nameDirectory,M&&L,!M&&G,(C||$)&&O.nameSelected),Z=bt({isDirectory:M,isExpanded:U,showExpandIcons:N,useCanvasExpandIcons:g,expandIconSize:D}),B=(M?d:u)?vt({entry:e,isDirectory:M,isExpanded:U,isSelected:C,isItemSelected:!!$,extension:re},S):null,ie={...z?w?.hoverStyle:{},...M&&C?w?.directorySelectedStyle:{},...!M&&(C||$)?w?.itemSelectedStyle:{}};return p.jsxs(c.Fragment,{children:[p.jsxs("div",{className:_,style:{paddingLeft:`${Math.max(0,t*he)}px`,transform:t<0?`translateX(${t*he}px)`:void 0,width:t<0?`calc(100% + ${Math.abs(t*he)}px)`:void 0,height:`${a}px`,...ie,...y,...e.style},"data-entry-type":M?"directory":"file","data-entry-expanded":M?String(U):void 0,"data-entry-selected":C?"true":void 0,"data-entry-item-selected":$?"true":void 0,onClick:r,onMouseEnter:()=>X(!0),onMouseLeave:()=>X(!1),onKeyDown:se=>se.key==="Enter"&&r(se),tabIndex:0,role:"treeitem","aria-expanded":M?U:void 0,"aria-label":`${e.name} (${M?"directory":"file"})`,children:[(N||g)&&p.jsx("span",{className:q,children:Z}),(M?d:u)&&p.jsx("span",{className:J,children:B}),p.jsx("span",{className:j,style:{...W,...M?I:F},"data-entry-type":M?"directory":"file","data-entry-role":"name",children:e.label??e.name})]}),U&&H&&l&&p.jsx("fieldset",{children:H.map((se,Ne)=>p.jsx(Le,{entry:se,indentLevel:t+1,rowHeight:a,isDirOpen:n,parentIsLast:[...s,Ne===H.length-1],expansion:{toggleDirectory:o,onToggleDirectoryRecursive:m},selection:{onEntryClick:E,selectedPath:v,mode:i,selectedItems:h,onSelectionChange:x},visual:{iconOverrides:S,showExpandIcons:N,showDirectoryIcons:d,showFileIcons:u,useCanvasExpandIcons:g,expandIconSize:D,highlightStyles:w,entryClassName:k,entryStyle:y,nameClassName:T,nameStyle:W,directoryNameClassName:L,directoryNameStyle:I,fileNameClassName:G,fileNameStyle:F}},se.absolutePath))})]},e.absolutePath)},(e,t)=>{if(e.entry!==t.entry)return!1;const a=e.entry.children!==void 0,n=t.entry.children!==void 0,s=a&&e.isDirOpen(e.entry.absolutePath),l=n&&t.isDirOpen(t.entry.absolutePath);return e.indentLevel===t.indentLevel&&e.rowHeight===t.rowHeight&&s===l&&e.selection.selectedPath===t.selection.selectedPath&&e.selection.mode===t.selection.mode&&e.selection.selectedItems===t.selection.selectedItems&&e.visual.iconOverrides===t.visual.iconOverrides&&e.visual.showExpandIcons===t.visual.showExpandIcons&&e.visual.showDirectoryIcons===t.visual.showDirectoryIcons&&e.visual.showFileIcons===t.visual.showFileIcons&&e.visual.useCanvasExpandIcons===t.visual.useCanvasExpandIcons&&e.visual.expandIconSize===t.visual.expandIconSize&&e.visual.highlightStyles===t.visual.highlightStyles&&e.visual.entryClassName===t.visual.entryClassName&&e.visual.entryStyle===t.visual.entryStyle&&e.visual.nameClassName===t.visual.nameClassName&&e.visual.nameStyle===t.visual.nameStyle&&e.visual.directoryNameClassName===t.visual.directoryNameClassName&&e.visual.directoryNameStyle===t.visual.directoryNameStyle&&e.visual.fileNameClassName===t.visual.fileNameClassName&&e.visual.fileNameStyle===t.visual.fileNameStyle&&e.parentIsLast.length===t.parentIsLast.length&&e.parentIsLast.every((o,m)=>o===t.parentIsLast[m])});Le.displayName="DirectoryEntryItem";const It=e=>{const t=[];if(e.children)for(const a of e.children)a.type==="directory"&&(t.push(a.absolutePath),t.push(...It(a)));return t},er=({entries:e,expansion:{toggle:t,isExpanded:a,expandMultiple:n,collapseMultiple:s,isPending:l,alwaysExpanded:o=!1,doubleClickAction:m="recursive"},selection:{onEntryClick:E,selectedPath:v,mode:i="none",selectedItems:h,onSelectionChange:x},visual:{className:S,style:N,lineColor:d="#A0AEC0",showTreeLines:u=!0,showExpandIcons:g=!0,showDirectoryIcons:D=!0,showFileIcons:w=!0,iconOverrides:k,expandIconSize:y,itemHeight:T=ke,removeRootIndent:W=!1,highlightStyles:L,entryClassName:I,entryStyle:G,nameClassName:F,nameStyle:H,directoryNameClassName:K,directoryNameStyle:z,fileNameClassName:X,fileNameStyle:M}={},virtualScroll:U,grid:C})=>{const $=C!==void 0,[re,r]=c.useState(!1),b=c.useRef(null),R=c.useRef(null),_=c.useRef(null),[q,J]=c.useState(0),[j,Z]=c.useState(0),[B,ie]=c.useState(0),[se,Ne]=c.useState(null),{overscanCount:be=15,className:He,background:$e,onScroll:We,onRangeChange:Fe,initialScrollIndex:Be,initialScrollOffset:de,callbackThrottleMs:Ye=5,contentInsets:Ge,onItemFocus:Ue,viewportHeightOverride:ee,scrollBarOptions:Ie,behaviorOptions:Ve}=U??{},[ve,ze]=c.useState(typeof de=="number"?de:0),Xe=c.useCallback((f,A)=>{ze(f),We?.(f,A)},[We]),qe=c.useCallback(f=>{const{renderingStartIndex:A,renderingEndIndex:Y}=f;Ne(Q=>Q&&Q.renderStart===A&&Q.renderEnd===Y?Q:{renderStart:A,renderEnd:Y}),Fe?.(f)},[Fe]);c.useEffect(()=>{typeof de=="number"&&ze(de)},[de]),c.useEffect(()=>{r(!0),Jt()},[]),c.useEffect(()=>{const f=b.current,A=$?R.current:f,Y=()=>{if(f){const ne=f.clientWidth;Z(me=>Math.abs(me-ne)>1?ne:me)}if(typeof ee=="number")J(ne=>Math.abs(ne-ee)>1?ee:ne);else if(A){const ne=A.clientHeight;J(me=>Math.abs(me-ne)>1?ne:me)}};if(!(f||A))return J(0);Y();const Q=new ResizeObserver(Y);return f&&Q.observe(f),A&&A!==f&&Q.observe(A),()=>Q.disconnect()},[ee,$]);const ae=typeof ee=="number"?ee:q,oe=c.useCallback(f=>o||(re?a(f):!1),[re,a,o]),Re=P.twMerge(O.container,l&&O.containerPending,S),Te=c.useMemo(()=>({...qt,...N??{},...typeof ee=="number"?{height:ee,minHeight:ee}:{}}),[N,ee]),Me=c.useCallback((f,A)=>{const Y=[f.absolutePath,...It(f)],Q=A||m;if(Y.every(Pe=>oe(Pe)))return s(Y);if(Y.every(Pe=>!oe(Pe))||Q==="recursive")return n(Y);if(Q==="toggle")return s(Y);console.warn(`[DirectoryTree] Unknown double click action: ${Q}. No action taken.`)},[oe,n,s,m]),Je=$?!1:W,{flatItems:Ze,lineItems:_e,maxIndent:Qe}=c.useMemo(()=>Zt(e,oe,u,Je),[e,oe,u,Je]),te=c.useMemo(()=>Ze.map((f,A)=>{const Y=typeof T=="function"?T(f.entry,A):T;return{...f,rowHeight:Number.isFinite(Y)&&Y>0?Y:ke}}),[Ze,T]),le=c.useMemo(()=>te.map(f=>f.rowHeight),[te]),ge=c.useMemo(()=>{const f=new Array(le.length+1);f[0]=0;for(let A=0;A<le.length;A++)f[A+1]=f[A]+le[A];return f},[le]),Ke=c.useCallback(f=>te[f]?.rowHeight??ke,[te]),xe=c.useMemo(()=>!u||_e.length===0?{segmentsByItem:[],glyphsByItem:[]}:Kt(_e,le,ge,he,u,y??ft),[_e,le,ge,u,y]),we=c.useMemo(()=>!u||e.length===0?0:(Qe+2)*he,[e.length,Qe,u]),{renderStart:et,renderEnd:tt,lookaheadEnd:rt}=c.useMemo(()=>Qt(te.length,ae,be,se,ve,ge),[te.length,ae,be,se,ve,ge]),je=c.useMemo(()=>!u||we<=0||ae<=0||xe.segmentsByItem.length===0?null:p.jsx("div",{className:"pointer-events-none absolute inset-0 z-0","aria-hidden":"true",children:p.jsx("div",{className:"absolute top-0 left-0",style:{width:we,height:ae},children:p.jsx(Nt,{segmentsByItem:xe.segmentsByItem,glyphsByItem:xe.glyphsByItem,itemHeight:le[0]??ke,width:we,viewportHeight:ae,scrollPosition:ve,color:d,expandGlyphColor:d,expandGlyphSize:y??ft,renderStartIndex:et,renderEndIndex:tt,lookaheadEndIndex:rt})})}),[we,ae,et,tt,rt,ve,xe,d,u,y,le]),nt=c.useCallback(f=>te[f],[te]),ce=C?.columns,ue=C?.scrollBarWidth??Ie?.width??Ct,V=c.useMemo(()=>ce?Ft({measuredWidth:j,columns:ce,scrollBarWidth:ue}):null,[ce,j,ue]),Ee=c.useMemo(()=>ce?Wt(ce):"",[ce]),Rt=c.useMemo(()=>C?.showFooter&&ce?Bt(e):[],[C?.showFooter,ce,e]),fe=V?.maxHScroll??0;c.useEffect(()=>{ie(f=>Ae(f,fe))},[fe]);const st=c.useCallback(f=>ie(A=>Ae(A+f,fe)),[fe]),at=c.useMemo(()=>({iconOverrides:k,showExpandIcons:g,showDirectoryIcons:D,showFileIcons:w,useCanvasExpandIcons:u,expandIconSize:y,highlightStyles:L}),[k,g,D,w,u,y,L]),ot=e.length===0,lt=c.useMemo(()=>p.jsx(ct.VirtualScroll,{ref:_,itemCount:te.length,getItem:nt,getItemHeight:Ke,viewportSize:ae,overscanCount:be,onScroll:Xe,onRangeChange:qe,className:He,onWheelHorizontal:$?st:void 0,background:p.jsxs(p.Fragment,{children:[$&&V?p.jsx("div",{className:"pointer-events-none absolute top-0 left-0 z-0 h-full overflow-hidden",style:{width:V.nameWidth},"aria-hidden":"true",children:je}):je,$e]}),initialScrollIndex:Be,initialScrollOffset:de,onItemFocus:Ue,callbackThrottleMs:Ye,contentInsets:Ge,scrollBarOptions:Ie,behaviorOptions:Ve,children:f=>f?$&&C&&V?p.jsx(Et,{entry:f.entry,indentLevel:f.indentLevel,rowHeight:f.rowHeight,isDirOpen:oe,columns:C.columns,numericTemplate:Ee,numericTotal:V.numericTotal,nameWidth:V.nameWidth,rowClassName:C.rowClassName,selection:{onEntryClick:E,selectedPath:v??null,mode:i,selectedItems:h,onSelectionChange:x},expansion:{toggleDirectory:t,onToggleDirectoryRecursive:Me},visual:at},f.entry.absolutePath):p.jsx(Le,{entry:f.entry,indentLevel:f.indentLevel,rowHeight:f.rowHeight,isDirOpen:oe,parentIsLast:f.parentIsLast,renderChildren:!1,expansion:{toggleDirectory:t,onToggleDirectoryRecursive:Me},selection:{onEntryClick:E,selectedPath:v??null,mode:i,selectedItems:h,onSelectionChange:x},visual:{iconOverrides:k,showExpandIcons:g,showDirectoryIcons:D,showFileIcons:w,useCanvasExpandIcons:u,expandIconSize:y,highlightStyles:L,entryClassName:I,entryStyle:G,nameClassName:F,nameStyle:H,directoryNameClassName:K,directoryNameStyle:z,fileNameClassName:X,fileNameStyle:M}},f.entry.absolutePath):null}),[te.length,nt,Ke,ae,be,Xe,qe,He,$,st,V,je,$e,Be,de,Ue,Ye,Ge,Ie,Ve,C,Ee,oe,E,v,i,h,x,t,Me,at,k,g,D,w,u,y,L,I,G,F,H,K,z,X,M]);if(!(C&&V))return ot?p.jsx("div",{className:Re,style:Te}):p.jsx("div",{ref:b,className:Re,style:Te,role:"tree",children:lt});const Tt=C.showHeader??!0,Mt=C.showFooter??!1,_t={...Te,"--dt-hscroll":`${B}px`};return p.jsxs("div",{ref:b,className:P.twMerge(Re,"dt-grid"),style:_t,role:"treegrid",children:[Tt&&p.jsx(Lt,{columns:C.columns,numericTemplate:Ee,numericTotal:V.numericTotal,nameWidth:V.nameWidth,scrollBarWidth:ue,className:C.headerClassName}),p.jsx("div",{ref:R,className:"dt-grid-body",children:!ot&<}),fe>0&&p.jsxs("div",{className:"dt-grid-hscrollbar-row",children:[p.jsx("div",{className:"dt-grid-scrollbar-spacer",style:{width:V.nameWidth},"aria-hidden":"true"}),p.jsx(ct.ScrollBar,{horizontal:!0,contentSize:V.numericTotal,viewportSize:V.numericVisible,scrollPosition:B,scrollBarWidth:ue,onScroll:f=>{const A=typeof f=="function"?f(B):f,Y=Ae(A,fe);return ie(Y),Y}}),p.jsx("div",{className:"dt-grid-scrollbar-spacer",style:{width:ue},"aria-hidden":"true"})]}),Mt&&p.jsx(Ht,{columns:C.columns,numericTemplate:Ee,numericTotal:V.numericTotal,nameWidth:V.nameWidth,scrollBarWidth:ue,allEntries:Rt,className:C.footerClassName})]})},tr=({initialExpanded:e=new Set,storageKey:t}={})=>{const[a,n]=c.useTransition(),[s,l]=c.useState(()=>{if(typeof window<"u"&&t)try{const d=window.localStorage.getItem(t);if(d){const u=JSON.parse(d);return new Set(u)}}catch(d){console.error("[useDirectoryTreeState] Error reading from localStorage",d)}return e}),o=c.useCallback(d=>{n(()=>{l(u=>{const g=new Set(u);return d(g),g})})},[]),m=c.useCallback((d,u)=>{o(g=>{for(const D of d)u(g,D)})},[o]);c.useEffect(()=>{if(t&&typeof window<"u")try{window.localStorage.setItem(t,JSON.stringify(Array.from(s)))}catch(d){console.warn(`Error setting localStorage key "${t}":`,d)}},[s,t]);const E=c.useCallback(d=>{m([d],(u,g)=>{u.has(g)?u.delete(g):u.add(g)})},[m]),v=c.useCallback(d=>{m([d],(u,g)=>{u.add(g)})},[m]),i=c.useCallback(d=>{m([d],(u,g)=>{u.delete(g)})},[m]),h=c.useCallback(d=>{m(d,(u,g)=>{u.delete(g)})},[m]),x=c.useCallback(d=>{m(d,(u,g)=>{u.add(g)})},[m]),S=c.useCallback(()=>{o(d=>{d.clear()})},[o]),N=c.useCallback(d=>s.has(d),[s]);return{expanded:s,toggle:E,expand:v,collapse:i,collapseMultiple:h,expandMultiple:x,collapseAll:S,isExpanded:N,isPending:a}};exports.DirectoryTree=er;exports.directoryTreeClasses=O;exports.useDirectoryTreeState=tr;
|
package/dist/index.js
CHANGED
|
@@ -55,7 +55,7 @@ function Vt() {
|
|
|
55
55
|
), r.$$typeof) {
|
|
56
56
|
case c:
|
|
57
57
|
return "Portal";
|
|
58
|
-
case
|
|
58
|
+
case N:
|
|
59
59
|
return r.displayName || "Context";
|
|
60
60
|
case x:
|
|
61
61
|
return (r._context.displayName || "Context") + ".Consumer";
|
|
@@ -223,7 +223,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
223
223
|
function g(r) {
|
|
224
224
|
return typeof r == "object" && r !== null && r.$$typeof === I;
|
|
225
225
|
}
|
|
226
|
-
var w = Ot, I = /* @__PURE__ */ Symbol.for("react.transitional.element"), c = /* @__PURE__ */ Symbol.for("react.portal"), d = /* @__PURE__ */ Symbol.for("react.fragment"), b = /* @__PURE__ */ Symbol.for("react.strict_mode"), O = /* @__PURE__ */ Symbol.for("react.profiler"), x = /* @__PURE__ */ Symbol.for("react.consumer"),
|
|
226
|
+
var w = Ot, I = /* @__PURE__ */ Symbol.for("react.transitional.element"), c = /* @__PURE__ */ Symbol.for("react.portal"), d = /* @__PURE__ */ Symbol.for("react.fragment"), b = /* @__PURE__ */ Symbol.for("react.strict_mode"), O = /* @__PURE__ */ Symbol.for("react.profiler"), x = /* @__PURE__ */ Symbol.for("react.consumer"), N = /* @__PURE__ */ Symbol.for("react.context"), h = /* @__PURE__ */ Symbol.for("react.forward_ref"), R = /* @__PURE__ */ Symbol.for("react.suspense"), $ = /* @__PURE__ */ Symbol.for("react.suspense_list"), D = /* @__PURE__ */ Symbol.for("react.memo"), k = /* @__PURE__ */ Symbol.for("react.lazy"), G = /* @__PURE__ */ Symbol.for("react.activity"), W = /* @__PURE__ */ Symbol.for("react.client.reference"), L = w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, ee = Object.prototype.hasOwnProperty, z = Array.isArray, J = console.createTask ? console.createTask : function() {
|
|
227
227
|
return null;
|
|
228
228
|
};
|
|
229
229
|
w = {
|
|
@@ -231,7 +231,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
231
231
|
return r();
|
|
232
232
|
}
|
|
233
233
|
};
|
|
234
|
-
var C, U = {},
|
|
234
|
+
var C, U = {}, S = w.react_stack_bottom_frame.bind(
|
|
235
235
|
w,
|
|
236
236
|
l
|
|
237
237
|
)(), H = J(n(l)), se = {};
|
|
@@ -242,7 +242,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
242
242
|
p,
|
|
243
243
|
T,
|
|
244
244
|
!1,
|
|
245
|
-
_ ? Error("react-stack-top-frame") :
|
|
245
|
+
_ ? Error("react-stack-top-frame") : S,
|
|
246
246
|
_ ? J(n(r)) : H
|
|
247
247
|
);
|
|
248
248
|
}, xe.jsxs = function(r, p, T) {
|
|
@@ -252,7 +252,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
252
252
|
p,
|
|
253
253
|
T,
|
|
254
254
|
!0,
|
|
255
|
-
_ ? Error("react-stack-top-frame") :
|
|
255
|
+
_ ? Error("react-stack-top-frame") : S,
|
|
256
256
|
_ ? J(n(r)) : H
|
|
257
257
|
);
|
|
258
258
|
};
|
|
@@ -329,7 +329,7 @@ const Re = 20, be = 16, yt = 12, A = {
|
|
|
329
329
|
},
|
|
330
330
|
[t, e, o, E, m, a, s, l, n]
|
|
331
331
|
);
|
|
332
|
-
},
|
|
332
|
+
}, Nt = (e) => e === "right" ? "dt-grid-cell--right" : e === "center" ? "dt-grid-cell--center" : "", pt = (e, t) => e.children !== void 0 && t(e.absolutePath), St = (e, t) => ({
|
|
333
333
|
width: e,
|
|
334
334
|
gridTemplateColumns: t
|
|
335
335
|
}), It = We(
|
|
@@ -345,7 +345,7 @@ const Re = 20, be = 16, yt = 12, A = {
|
|
|
345
345
|
rowClassName: E,
|
|
346
346
|
selection: { onEntryClick: v, selectedPath: i, mode: f = "none", selectedItems: g, onSelectionChange: w },
|
|
347
347
|
expansion: { toggleDirectory: I, onToggleDirectoryRecursive: c },
|
|
348
|
-
visual: { iconOverrides: d, showExpandIcons: b = !0, showDirectoryIcons: O = !0, showFileIcons: x = !0, useCanvasExpandIcons:
|
|
348
|
+
visual: { iconOverrides: d, showExpandIcons: b = !0, showDirectoryIcons: O = !0, showFileIcons: x = !0, useCanvasExpandIcons: N = !1, expandIconSize: h, highlightStyles: R }
|
|
349
349
|
}) => {
|
|
350
350
|
const [$, D] = ne(!1), k = e.children !== void 0, G = k && n(e.absolutePath), W = e.absolutePath === i, L = !k && !!g?.has(e.absolutePath), ee = k ? void 0 : gt(e.name), z = wt({ entry: e, isDirectory: k, isExpanded: G, isItemSelected: L, selectionMode: f, onSelectionChange: w, onEntryClick: v, toggleDirectory: I, onToggleDirectoryRecursive: c }), J = $ ? R?.hoverClassName !== void 0 ? R.hoverClassName : A.entryHover : "", C = (() => {
|
|
351
351
|
if (k) {
|
|
@@ -353,7 +353,7 @@ const Re = 20, be = 16, yt = 12, A = {
|
|
|
353
353
|
} else if (W || L)
|
|
354
354
|
return R?.itemSelectedClassName !== void 0 ? R.itemSelectedClassName : P(W && A.entrySelected, L && A.entryItemSelected);
|
|
355
355
|
return "";
|
|
356
|
-
})(), U = typeof E == "function" ? E(e) : E,
|
|
356
|
+
})(), U = typeof E == "function" ? E(e) : E, S = P("dt-grid-row cursor-pointer select-none", J, C, U, e.className), H = P(A.expandIcon, (W || L) && A.expandIconSelected), se = P(A.typeIcon, (W || L) && A.typeIconSelected), r = P("dt-grid-name-label ml-1", "text-gray-700 dark:text-gray-200", k && A.nameDirectory, (W || L) && A.nameSelected), p = xt({ isDirectory: k, isExpanded: G, showExpandIcons: b, useCanvasExpandIcons: N, expandIconSize: h }), T = (k ? O : x) ? Et({ entry: e, isDirectory: k, isExpanded: G, isSelected: W, isItemSelected: L, extension: ee }, d) : null, _ = { indentLevel: t, isDirectory: k, isExpanded: G }, [q, ...Z] = s, j = q?.render ? q.render(e, _) : e.label ?? e.name, Q = {
|
|
357
357
|
...$ ? R?.hoverStyle : {},
|
|
358
358
|
...k && W ? R?.directorySelectedStyle : {},
|
|
359
359
|
...!k && (W || L) ? R?.itemSelectedStyle : {}
|
|
@@ -361,7 +361,7 @@ const Re = 20, be = 16, yt = 12, A = {
|
|
|
361
361
|
return /* @__PURE__ */ y.jsxs(
|
|
362
362
|
"div",
|
|
363
363
|
{
|
|
364
|
-
className:
|
|
364
|
+
className: S,
|
|
365
365
|
style: { height: o, ...Q, ...e.style },
|
|
366
366
|
role: "row",
|
|
367
367
|
"aria-expanded": k ? G : void 0,
|
|
@@ -377,11 +377,11 @@ const Re = 20, be = 16, yt = 12, A = {
|
|
|
377
377
|
tabIndex: 0,
|
|
378
378
|
children: [
|
|
379
379
|
/* @__PURE__ */ y.jsxs("div", { className: P("dt-grid-name-cell", q?.className), role: "gridcell", style: { width: m, paddingLeft: Math.max(0, t * be) }, children: [
|
|
380
|
-
(b ||
|
|
380
|
+
(b || N) && /* @__PURE__ */ y.jsx("span", { className: H, children: p }),
|
|
381
381
|
(k ? O : x) && /* @__PURE__ */ y.jsx("span", { className: se, children: T }),
|
|
382
382
|
/* @__PURE__ */ y.jsx("span", { className: r, children: j })
|
|
383
383
|
] }),
|
|
384
|
-
Z.length > 0 && /* @__PURE__ */ y.jsx("div", { className: "dt-grid-numeric-viewport", children: /* @__PURE__ */ y.jsx("div", { className: "dt-grid-numeric-track", style:
|
|
384
|
+
Z.length > 0 && /* @__PURE__ */ y.jsx("div", { className: "dt-grid-numeric-viewport", children: /* @__PURE__ */ y.jsx("div", { className: "dt-grid-numeric-track", style: St(a, l), children: Z.map((B) => /* @__PURE__ */ y.jsx("div", { className: P("dt-grid-cell", Nt(B.align), B.className), role: "gridcell", children: B.render ? B.render(e, _) : null }, B.key)) }) })
|
|
385
385
|
]
|
|
386
386
|
}
|
|
387
387
|
);
|
|
@@ -406,8 +406,8 @@ const kt = ({
|
|
|
406
406
|
}) => {
|
|
407
407
|
const [, ...v] = t, i = e === "header" ? "dt-grid-name-header" : "dt-grid-name-footer", f = e === "header" ? "dt-grid-header" : "dt-grid-footer", g = e === "header" ? "columnheader" : "gridcell";
|
|
408
408
|
return /* @__PURE__ */ y.jsxs("div", { className: P(f, "text-gray-600 dark:text-gray-300", a), role: "row", children: [
|
|
409
|
-
/* @__PURE__ */ y.jsx("div", { className: P(i, "px-1"), role: g, style: { width: s }, children: m }),
|
|
410
|
-
v.length > 0 && /* @__PURE__ */ y.jsx("div", { className: "dt-grid-numeric-viewport", children: /* @__PURE__ */ y.jsx("div", { className: "dt-grid-numeric-track", style:
|
|
409
|
+
/* @__PURE__ */ y.jsx("div", { className: P(i, "px-1", t[0]?.className), role: g, style: { width: s }, children: m }),
|
|
410
|
+
v.length > 0 && /* @__PURE__ */ y.jsx("div", { className: "dt-grid-numeric-viewport", children: /* @__PURE__ */ y.jsx("div", { className: "dt-grid-numeric-track", style: St(n, o), children: v.map((w) => /* @__PURE__ */ y.jsx("div", { className: P("dt-grid-cell", Nt(w.align), w.className), role: g, children: E(w) }, w.key)) }) }),
|
|
411
411
|
/* @__PURE__ */ y.jsx("div", { className: "dt-grid-scrollbar-spacer", style: { width: l }, "aria-hidden": "true" })
|
|
412
412
|
] });
|
|
413
413
|
}, Jt = ({ columns: e, className: t, ...o }) => /* @__PURE__ */ y.jsx(kt, { kind: "header", columns: e, className: t, nameContent: e[0]?.header ?? null, renderCell: (n) => n.header ?? null, ...o }), vt = (e, t) => typeof e == "function" ? e(t) : e ?? null, qt = ({ columns: e, allEntries: t, className: o, ...n }) => /* @__PURE__ */ y.jsx(kt, { kind: "footer", columns: e, className: o, nameContent: vt(e[0]?.footer, t), renderCell: (s) => vt(s.footer, t), ...n }), Zt = 240, Tt = 96, Rt = 12, $e = (e, t) => {
|
|
@@ -489,12 +489,12 @@ const kt = ({
|
|
|
489
489
|
const x = I.current;
|
|
490
490
|
if (!x)
|
|
491
491
|
return;
|
|
492
|
-
const
|
|
493
|
-
if (!
|
|
492
|
+
const N = x.getContext("2d");
|
|
493
|
+
if (!N)
|
|
494
494
|
return;
|
|
495
495
|
const h = d.current;
|
|
496
496
|
if (h.width <= 0 || h.viewportHeight <= 0) {
|
|
497
|
-
|
|
497
|
+
N.clearRect(0, 0, x.width, x.height);
|
|
498
498
|
return;
|
|
499
499
|
}
|
|
500
500
|
const R = Number.isFinite(h.devicePixelRatio ?? NaN) ? h.devicePixelRatio : typeof window < "u" && window.devicePixelRatio || 1;
|
|
@@ -512,7 +512,7 @@ const kt = ({
|
|
|
512
512
|
}
|
|
513
513
|
return Math.max(k, G);
|
|
514
514
|
})(), L = tr(h.segmentsByItem, D, W), ee = rr(h.glyphsByItem, D, W);
|
|
515
|
-
|
|
515
|
+
N.save(), N.scale(R, R), N.clearRect(0, 0, h.width, h.viewportHeight), N.translate(0, -h.scrollPosition), N.strokeStyle = h.color, sr(N, L, h.strokeWidth), ar(N, ee, h.expandGlyphColor ?? h.color, h.expandGlyphSize), N.restore();
|
|
516
516
|
}, []), O = F(() => {
|
|
517
517
|
c.current === null && (c.current = window.requestAnimationFrame(b));
|
|
518
518
|
}, [b]);
|
|
@@ -586,23 +586,23 @@ const lr = {
|
|
|
586
586
|
if (f.hideLines)
|
|
587
587
|
continue;
|
|
588
588
|
const g = [], w = t[i] ?? 0, I = o[i] ?? 0, c = I + w / 2, d = E(w), b = d > 0 ? d / 2 + 2 : n / 1.5;
|
|
589
|
-
for (let
|
|
590
|
-
if (f.ancestorIsLast[
|
|
589
|
+
for (let N = 0; N < f.indentLevel; N++) {
|
|
590
|
+
if (f.ancestorIsLast[N] ?? !1)
|
|
591
591
|
continue;
|
|
592
592
|
let R = !1;
|
|
593
593
|
for (let $ = i; $ < e.length; $++) {
|
|
594
594
|
const D = e[$];
|
|
595
|
-
if (D.indentLevel >
|
|
595
|
+
if (D.indentLevel > N && D.ancestorIsLast.length > N && !D.ancestorIsLast[N]) {
|
|
596
596
|
R = !0;
|
|
597
597
|
break;
|
|
598
598
|
}
|
|
599
|
-
if ($ > i && D.indentLevel ===
|
|
599
|
+
if ($ > i && D.indentLevel === N)
|
|
600
600
|
break;
|
|
601
601
|
}
|
|
602
602
|
if (R) {
|
|
603
|
-
const $ =
|
|
603
|
+
const $ = N * n + n / 2 + v;
|
|
604
604
|
g.push({
|
|
605
|
-
key: `${f.id}-ancestor-${
|
|
605
|
+
key: `${f.id}-ancestor-${N}`,
|
|
606
606
|
x1: $,
|
|
607
607
|
y1: I,
|
|
608
608
|
x2: $,
|
|
@@ -648,14 +648,14 @@ const lr = {
|
|
|
648
648
|
y2: I + w,
|
|
649
649
|
itemIndex: i
|
|
650
650
|
})), a[i] = g, s && f.isDirectory) {
|
|
651
|
-
const
|
|
651
|
+
const N = d, h = x, R = c;
|
|
652
652
|
m[i] = [
|
|
653
653
|
{
|
|
654
654
|
key: `${f.id}-glyph`,
|
|
655
655
|
itemIndex: i,
|
|
656
656
|
centerX: h,
|
|
657
657
|
centerY: R,
|
|
658
|
-
size:
|
|
658
|
+
size: N,
|
|
659
659
|
isExpanded: f.isExpanded
|
|
660
660
|
}
|
|
661
661
|
];
|
|
@@ -680,7 +680,7 @@ const lr = {
|
|
|
680
680
|
useCanvasExpandIcons: b = !1,
|
|
681
681
|
expandIconSize: O,
|
|
682
682
|
highlightStyles: x,
|
|
683
|
-
entryClassName:
|
|
683
|
+
entryClassName: N,
|
|
684
684
|
entryStyle: h,
|
|
685
685
|
nameClassName: R,
|
|
686
686
|
nameStyle: $,
|
|
@@ -690,21 +690,21 @@ const lr = {
|
|
|
690
690
|
fileNameStyle: W
|
|
691
691
|
}
|
|
692
692
|
}) => {
|
|
693
|
-
const [L, ee] = ne(null), [z, J] = ne(!1), C = e.children !== void 0, U = C && n(e.absolutePath),
|
|
693
|
+
const [L, ee] = ne(null), [z, J] = ne(!1), C = e.children !== void 0, U = C && n(e.absolutePath), S = e.absolutePath === v, H = !C && f?.has(e.absolutePath), se = C ? void 0 : gt(e.name);
|
|
694
694
|
ae(() => {
|
|
695
695
|
ee(U && e.children ? e.children : null);
|
|
696
696
|
}, [U, e.children]);
|
|
697
697
|
const r = wt({ entry: e, isDirectory: C, isExpanded: U, isItemSelected: !!H, selectionMode: i, onSelectionChange: g, onEntryClick: E, toggleDirectory: a, onToggleDirectoryRecursive: m }), p = z ? x?.hoverClassName !== void 0 ? x.hoverClassName : A.entryHover : "", T = (() => {
|
|
698
698
|
if (C) {
|
|
699
|
-
if (
|
|
699
|
+
if (S)
|
|
700
700
|
return x?.directorySelectedClassName !== void 0 ? x.directorySelectedClassName : A.entrySelected;
|
|
701
|
-
} else if (
|
|
702
|
-
return x?.itemSelectedClassName !== void 0 ? x.itemSelectedClassName : P(
|
|
701
|
+
} else if (S || H)
|
|
702
|
+
return x?.itemSelectedClassName !== void 0 ? x.itemSelectedClassName : P(S && A.entrySelected, H && A.entryItemSelected);
|
|
703
703
|
return "";
|
|
704
|
-
})(), _ = P(A.entry, p, T,
|
|
704
|
+
})(), _ = P(A.entry, p, T, N, e.className), q = P(A.expandIcon, (S || H) && A.expandIconSelected), Z = P(A.typeIcon, (S || H) && A.typeIconSelected), j = P(A.name, R, C && A.nameDirectory, C && D, !C && G, (S || H) && A.nameSelected), Q = xt({ isDirectory: C, isExpanded: U, showExpandIcons: I, useCanvasExpandIcons: b, expandIconSize: O }), B = (C ? c : d) ? Et({ entry: e, isDirectory: C, isExpanded: U, isSelected: S, isItemSelected: !!H, extension: se }, w) : null, me = {
|
|
705
705
|
...z ? x?.hoverStyle : {},
|
|
706
|
-
...C &&
|
|
707
|
-
...!C && (
|
|
706
|
+
...C && S ? x?.directorySelectedStyle : {},
|
|
707
|
+
...!C && (S || H) ? x?.itemSelectedStyle : {}
|
|
708
708
|
};
|
|
709
709
|
return /* @__PURE__ */ y.jsxs(Dt, { children: [
|
|
710
710
|
/* @__PURE__ */ y.jsxs(
|
|
@@ -722,7 +722,7 @@ const lr = {
|
|
|
722
722
|
},
|
|
723
723
|
"data-entry-type": C ? "directory" : "file",
|
|
724
724
|
"data-entry-expanded": C ? String(U) : void 0,
|
|
725
|
-
"data-entry-selected":
|
|
725
|
+
"data-entry-selected": S ? "true" : void 0,
|
|
726
726
|
"data-entry-item-selected": H ? "true" : void 0,
|
|
727
727
|
onClick: r,
|
|
728
728
|
onMouseEnter: () => J(!0),
|
|
@@ -769,7 +769,7 @@ const lr = {
|
|
|
769
769
|
useCanvasExpandIcons: b,
|
|
770
770
|
expandIconSize: O,
|
|
771
771
|
highlightStyles: x,
|
|
772
|
-
entryClassName:
|
|
772
|
+
entryClassName: N,
|
|
773
773
|
entryStyle: h,
|
|
774
774
|
nameClassName: R,
|
|
775
775
|
nameStyle: $,
|
|
@@ -808,7 +808,7 @@ const _t = (e) => {
|
|
|
808
808
|
showExpandIcons: b = !0,
|
|
809
809
|
showDirectoryIcons: O = !0,
|
|
810
810
|
showFileIcons: x = !0,
|
|
811
|
-
iconOverrides:
|
|
811
|
+
iconOverrides: N,
|
|
812
812
|
expandIconSize: h,
|
|
813
813
|
itemHeight: R = Re,
|
|
814
814
|
removeRootIndent: $ = !1,
|
|
@@ -823,9 +823,9 @@ const _t = (e) => {
|
|
|
823
823
|
fileNameStyle: C
|
|
824
824
|
} = {},
|
|
825
825
|
virtualScroll: U,
|
|
826
|
-
grid:
|
|
826
|
+
grid: S
|
|
827
827
|
}) => {
|
|
828
|
-
const H =
|
|
828
|
+
const H = S !== void 0, [se, r] = ne(!1), p = he(null), T = he(null), _ = he(null), [q, Z] = ne(0), [j, Q] = ne(0), [B, me] = ne(0), [le, Ce] = ne(null), {
|
|
829
829
|
overscanCount: Ee = 15,
|
|
830
830
|
className: Be,
|
|
831
831
|
background: Ye,
|
|
@@ -895,23 +895,23 @@ const _t = (e) => {
|
|
|
895
895
|
return { ...u, rowHeight: Number.isFinite(Y) && Y > 0 ? Y : Re };
|
|
896
896
|
}),
|
|
897
897
|
[tt, R]
|
|
898
|
-
), de = X(() => re.map((u) => u.rowHeight), [re]),
|
|
898
|
+
), de = X(() => re.map((u) => u.rowHeight), [re]), Ne = X(() => {
|
|
899
899
|
const u = new Array(de.length + 1);
|
|
900
900
|
u[0] = 0;
|
|
901
901
|
for (let M = 0; M < de.length; M++)
|
|
902
902
|
u[M + 1] = u[M] + de[M];
|
|
903
903
|
return u;
|
|
904
|
-
}, [de]), nt = F((u) => re[u]?.rowHeight ?? Re, [re]),
|
|
905
|
-
() => !d || Ae.length === 0 ? { segmentsByItem: [], glyphsByItem: [] } : ur(Ae, de,
|
|
906
|
-
[Ae, de,
|
|
904
|
+
}, [de]), nt = F((u) => re[u]?.rowHeight ?? Re, [re]), Se = X(
|
|
905
|
+
() => !d || Ae.length === 0 ? { segmentsByItem: [], glyphsByItem: [] } : ur(Ae, de, Ne, be, d, h ?? yt),
|
|
906
|
+
[Ae, de, Ne, d, h]
|
|
907
907
|
), Ie = X(() => !d || e.length === 0 ? 0 : (rt + 2) * be, [e.length, rt, d]), { renderStart: st, renderEnd: ot, lookaheadEnd: at } = X(
|
|
908
|
-
() => dr(re.length, ie, Ee, le, we,
|
|
909
|
-
[re.length, ie, Ee, le, we,
|
|
910
|
-
), Oe = X(() => !d || Ie <= 0 || ie <= 0 ||
|
|
908
|
+
() => dr(re.length, ie, Ee, le, we, Ne),
|
|
909
|
+
[re.length, ie, Ee, le, we, Ne]
|
|
910
|
+
), Oe = X(() => !d || Ie <= 0 || ie <= 0 || Se.segmentsByItem.length === 0 ? null : /* @__PURE__ */ y.jsx("div", { className: "pointer-events-none absolute inset-0 z-0", "aria-hidden": "true", children: /* @__PURE__ */ y.jsx("div", { className: "absolute top-0 left-0", style: { width: Ie, height: ie }, children: /* @__PURE__ */ y.jsx(
|
|
911
911
|
Ct,
|
|
912
912
|
{
|
|
913
|
-
segmentsByItem:
|
|
914
|
-
glyphsByItem:
|
|
913
|
+
segmentsByItem: Se.segmentsByItem,
|
|
914
|
+
glyphsByItem: Se.glyphsByItem,
|
|
915
915
|
itemHeight: de[0] ?? Re,
|
|
916
916
|
width: Ie,
|
|
917
917
|
viewportHeight: ie,
|
|
@@ -923,13 +923,13 @@ const _t = (e) => {
|
|
|
923
923
|
renderEndIndex: ot,
|
|
924
924
|
lookaheadEndIndex: at
|
|
925
925
|
}
|
|
926
|
-
) }) }), [Ie, ie, st, ot, at, we,
|
|
926
|
+
) }) }), [Ie, ie, st, ot, at, we, Se, c, d, h, de]), lt = F((u) => re[u], [re]), ue = S?.columns, ye = S?.scrollBarWidth ?? _e?.width ?? Rt, V = X(() => ue ? Kt({ measuredWidth: j, columns: ue, scrollBarWidth: ye }) : null, [ue, j, ye]), ke = X(() => ue ? Qt(ue) : "", [ue]), jt = X(() => S?.showFooter && ue ? er(e) : [], [S?.showFooter, ue, e]), pe = V?.maxHScroll ?? 0;
|
|
927
927
|
ae(() => {
|
|
928
928
|
me((u) => Le(u, pe));
|
|
929
929
|
}, [pe]);
|
|
930
930
|
const it = F((u) => me((M) => Le(M + u, pe)), [pe]), ct = X(
|
|
931
|
-
() => ({ iconOverrides:
|
|
932
|
-
[
|
|
931
|
+
() => ({ iconOverrides: N, showExpandIcons: b, showDirectoryIcons: O, showFileIcons: x, useCanvasExpandIcons: d, expandIconSize: h, highlightStyles: D }),
|
|
932
|
+
[N, b, O, x, d, h, D]
|
|
933
933
|
), dt = e.length === 0, ut = X(
|
|
934
934
|
() => /* @__PURE__ */ y.jsx(
|
|
935
935
|
Ht,
|
|
@@ -958,18 +958,18 @@ const _t = (e) => {
|
|
|
958
958
|
contentInsets: Xe,
|
|
959
959
|
scrollBarOptions: _e,
|
|
960
960
|
behaviorOptions: qe,
|
|
961
|
-
children: (u) => u ? H &&
|
|
961
|
+
children: (u) => u ? H && S && V ? /* @__PURE__ */ y.jsx(
|
|
962
962
|
It,
|
|
963
963
|
{
|
|
964
964
|
entry: u.entry,
|
|
965
965
|
indentLevel: u.indentLevel,
|
|
966
966
|
rowHeight: u.rowHeight,
|
|
967
967
|
isDirOpen: ce,
|
|
968
|
-
columns:
|
|
968
|
+
columns: S.columns,
|
|
969
969
|
numericTemplate: ke,
|
|
970
970
|
numericTotal: V.numericTotal,
|
|
971
971
|
nameWidth: V.nameWidth,
|
|
972
|
-
rowClassName:
|
|
972
|
+
rowClassName: S.rowClassName,
|
|
973
973
|
selection: { onEntryClick: E, selectedPath: v ?? null, mode: i, selectedItems: f, onSelectionChange: g },
|
|
974
974
|
expansion: { toggleDirectory: t, onToggleDirectoryRecursive: Me },
|
|
975
975
|
visual: ct
|
|
@@ -987,7 +987,7 @@ const _t = (e) => {
|
|
|
987
987
|
expansion: { toggleDirectory: t, onToggleDirectoryRecursive: Me },
|
|
988
988
|
selection: { onEntryClick: E, selectedPath: v ?? null, mode: i, selectedItems: f, onSelectionChange: g },
|
|
989
989
|
visual: {
|
|
990
|
-
iconOverrides:
|
|
990
|
+
iconOverrides: N,
|
|
991
991
|
showExpandIcons: b,
|
|
992
992
|
showDirectoryIcons: O,
|
|
993
993
|
showFileIcons: x,
|
|
@@ -1029,7 +1029,7 @@ const _t = (e) => {
|
|
|
1029
1029
|
Xe,
|
|
1030
1030
|
_e,
|
|
1031
1031
|
qe,
|
|
1032
|
-
|
|
1032
|
+
S,
|
|
1033
1033
|
ke,
|
|
1034
1034
|
ce,
|
|
1035
1035
|
E,
|
|
@@ -1040,7 +1040,7 @@ const _t = (e) => {
|
|
|
1040
1040
|
t,
|
|
1041
1041
|
Me,
|
|
1042
1042
|
ct,
|
|
1043
|
-
|
|
1043
|
+
N,
|
|
1044
1044
|
b,
|
|
1045
1045
|
O,
|
|
1046
1046
|
x,
|
|
@@ -1057,11 +1057,11 @@ const _t = (e) => {
|
|
|
1057
1057
|
C
|
|
1058
1058
|
]
|
|
1059
1059
|
);
|
|
1060
|
-
if (!(
|
|
1060
|
+
if (!(S && V))
|
|
1061
1061
|
return dt ? /* @__PURE__ */ y.jsx("div", { className: je, style: Pe }) : /* @__PURE__ */ y.jsx("div", { ref: p, className: je, style: Pe, role: "tree", children: ut });
|
|
1062
|
-
const Pt =
|
|
1062
|
+
const Pt = S.showHeader ?? !0, Mt = S.showFooter ?? !1, At = { ...Pe, "--dt-hscroll": `${B}px` };
|
|
1063
1063
|
return /* @__PURE__ */ y.jsxs("div", { ref: p, className: P(je, "dt-grid"), style: At, role: "treegrid", children: [
|
|
1064
|
-
Pt && /* @__PURE__ */ y.jsx(Jt, { columns:
|
|
1064
|
+
Pt && /* @__PURE__ */ y.jsx(Jt, { columns: S.columns, numericTemplate: ke, numericTotal: V.numericTotal, nameWidth: V.nameWidth, scrollBarWidth: ye, className: S.headerClassName }),
|
|
1065
1065
|
/* @__PURE__ */ y.jsx("div", { ref: T, className: "dt-grid-body", children: !dt && ut }),
|
|
1066
1066
|
pe > 0 && /* @__PURE__ */ y.jsxs("div", { className: "dt-grid-hscrollbar-row", children: [
|
|
1067
1067
|
/* @__PURE__ */ y.jsx("div", { className: "dt-grid-scrollbar-spacer", style: { width: V.nameWidth }, "aria-hidden": "true" }),
|
|
@@ -1081,7 +1081,7 @@ const _t = (e) => {
|
|
|
1081
1081
|
),
|
|
1082
1082
|
/* @__PURE__ */ y.jsx("div", { className: "dt-grid-scrollbar-spacer", style: { width: ye }, "aria-hidden": "true" })
|
|
1083
1083
|
] }),
|
|
1084
|
-
Mt && /* @__PURE__ */ y.jsx(qt, { columns:
|
|
1084
|
+
Mt && /* @__PURE__ */ y.jsx(qt, { columns: S.columns, numericTemplate: ke, numericTotal: V.numericTotal, nameWidth: V.nameWidth, scrollBarWidth: ye, allEntries: jt, className: S.footerClassName })
|
|
1085
1085
|
] });
|
|
1086
1086
|
}, br = ({ initialExpanded: e = /* @__PURE__ */ new Set(), storageKey: t } = {}) => {
|
|
1087
1087
|
const [o, n] = Lt(), [s, l] = ne(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiquants/directory-tree",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "High-performance directory tree component for React with virtual scrolling and file selection",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"**/*.css"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@heroicons/react": "^2.2.0",
|
|
28
28
|
"@phosphor-icons/react": "^2.1.10",
|
|
29
29
|
"tailwind-merge": "^3.4.0",
|
|
30
|
-
"@aiquants/virtualscroll": "1.18.
|
|
30
|
+
"@aiquants/virtualscroll": "1.18.3"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": "^19.2.7",
|