@aiquants/directory-tree 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -32,6 +32,15 @@ export type DirectoryEntry = {
32
32
  */
33
33
  style?: CSSProperties;
34
34
  };
35
+ /**
36
+ * Comparator applied to a sibling group before the tree is flattened into rows.
37
+ * Receives two entries that share the same parent and returns the usual
38
+ * `Array.prototype.sort` ordering number.
39
+ *
40
+ * ツリーを行へフラット化する前に、同一の親を持つ兄弟グループへ適用する比較関数。
41
+ * 戻り値は `Array.prototype.sort` と同じ順序数値。
42
+ */
43
+ export type DirectoryEntryComparator = (a: DirectoryEntry, b: DirectoryEntry) => number;
35
44
  /**
36
45
  * Row height for directory tree entries.
37
46
  * Either a fixed pixel value applied to every row, or a function computing the
@@ -481,6 +490,22 @@ export type DirectoryTreeProps = {
481
490
  * `grid.columns` と各 `render` / `footer` は参照安定必須(`itemHeight` と同じ制約)。
482
491
  */
483
492
  grid?: DirectoryTreeGrid;
493
+ /**
494
+ * Optional comparator applied to every sibling group before the tree is flattened
495
+ * into rows. Only a shallow copy of each sibling array is sorted, so every
496
+ * `DirectoryEntry` object and every `children` array keeps its identity and
497
+ * consumer-side memoization (row memo, reference-preserving decorators, hydration
498
+ * caches) continues to work. Omit it to render the entries in their given order.
499
+ *
500
+ * 各兄弟グループへフラット化前に適用する任意の比較関数。並べ替えは兄弟配列の浅いコピーに
501
+ * 対してのみ行うため、`DirectoryEntry` と `children` 配列の identity は保持され、利用側の
502
+ * メモ化 (行メモ・参照保持デコレータ・ハイドレーションキャッシュ) はそのまま機能する。
503
+ * 省略時は与えられた順序のまま描画。
504
+ *
505
+ * @remarks 参照を安定させること (`useMemo` / `useCallback`)。identity が毎レンダー変わると
506
+ * ツリー走査が都度再計算され、パフォーマンスが劣化する (`itemHeight` と同じ制約)。
507
+ */
508
+ sort?: DirectoryEntryComparator;
484
509
  };
485
510
  /**
486
511
  * Props for the useDirectoryTreeState hook.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAErE;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,cAAc,GAAG;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,IAAI,EAAE,MAAM,GAAG,WAAW,CAAA;IAC1B,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAA;IAC3B,IAAI,CAAC,EAAE,yBAAyB,CAAA;IAChC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,KAAK,CAAC,EAAE,aAAa,CAAA;CACxB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,CAAA;AAEpF;;;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG;IACzC,KAAK,EAAE,cAAc,CAAA;IACrB,WAAW,EAAE,OAAO,CAAA;IACpB,UAAU,EAAE,OAAO,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,cAAc,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG,SAAS,GAAG,CAAC,CAAC,OAAO,EAAE,8B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AE,MAAM,CAAA;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,eAAe,CAAC,EAAE,MAAM,CAAA;CAC3B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiquants/directory-tree",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "High-performance directory tree component for React with virtual scrolling and file selection",
5
5
  "sideEffects": [
6
6
  "**/*.css"
@@ -33,7 +33,7 @@
33
33
  "peerDependencies": {
34
34
  "react": "^19.2.7",
35
35
  "react-dom": "^19.2.7",
36
- "@aiquants/virtualscroll": "^1.22.0"
36
+ "@aiquants/virtualscroll": "^1.23.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@tailwindcss/cli": "^4.1.18",
@@ -54,7 +54,7 @@
54
54
  "vite": "^7.2.7",
55
55
  "vite-plugin-dts": "^4.5.4",
56
56
  "vitest": "^3.2.4",
57
- "@aiquants/virtualscroll": "1.22.0"
57
+ "@aiquants/virtualscroll": "1.23.0"
58
58
  },
59
59
  "keywords": [
60
60
  "react",
@@ -4,6 +4,7 @@
4
4
 
5
5
  | Version | Date | Author | Reviewer | Approver | Summary of Changes |
6
6
  | :--- | :--- | :--- | :--- | :--- | :--- |
7
+ | 3.4.0 | 2026-08-08 | Claude Opus 5 | | | Add the optional top-level `sort` prop (`DirectoryEntryComparator`), applied to every sibling group inside `collectTreeData` immediately before flattening. Only a shallow copy of each sibling array is sorted, so every `DirectoryEntry` object and every `children` array keeps its identity and consumer-side memoization (row memo, reference-preserving decorators, hydration caches) survives a re-sort; the caller's `entries` arrays are never mutated. `isLastChild` and the ancestor chain derive from the loop index, so connector geometry follows the sorted order automatically, in grid mode too. Ordering is deliberately a top-level prop rather than a `visual` member because it changes row semantics rather than presentation. Also fixes a latent defect exposed by any reordering: `virtualScroll.getItemKey` was accepted by the type but never destructured or forwarded, so `VirtualScroll` fell back to index keying and every row whose index-to-entry mapping changed was unmounted and remounted; it is now forwarded, defaulting to `entry.absolutePath`. |
7
8
  | 3.1.0 | 2026-07-31 | Claude Opus 5 | | | Add opt-in `virtualScroll.preserveScrollAnchor`: when the row list mutates (e.g. streaming insertions above the viewport), the first visible row is kept visually stationary via a pre-paint (`useLayoutEffect`) scroll correction. Pure helpers `captureScrollAnchor` / `resolveAnchorScroll` live in `scrollAnchor.ts` (unit-tested). The anchor is captured from the **live pane position** (`getScrollPosition()`, inset-adjusted) rather than the RAF-throttled `onScroll` mirror, so corrections landing mid-scroll do not rubber-band by the notification lag; the handle's clamped return value is adopted, and the component's own `scrollPosition` state is updated **in the same pre-paint flush** so the tree-line canvas / expand glyphs never misalign from the rows. No correction at the top of the list (scroll 0) and pixel-position fallback when the anchored row vanished. Known trade-off: the programmatic correction goes through the ScrollPane handle, which stops an in-progress pointer-drag inertia fling (same as the pre-existing compensation path). Also removed a leftover dead `isEmpty` local. |
8
9
  | 3.0.1 | 2026-07-07 | Antigravity | | | Fix: `columns[0].className` is now correctly applied to the name column cells in the header and footer (TreeGrid mode), ensuring consistency with body rows and data columns. |
9
10
  | 3.0.0 | 2026-07-07 | Claude Opus 4.8 | | | Add TreeGrid (columns) mode via the optional `grid` prop (`DirectoryTreeGrid` / `DirectoryTreeColumn`). The name/tree column is frozen on the left (indent + connector lines confined there); the remaining columns render as a vertically-aligned grid with an aligned column header, an optional footer that aggregates over **all** entries (collapsed subtrees included), and a horizontally scrollable numeric region (the name column stays frozen). Grid mode uses `role="treegrid"` / `row` / `gridcell` / `columnheader`. Enabled by a new opt-in `onWheelHorizontal` prop on `@aiquants/virtualscroll` (axis-aware wheel). `grid` and each `render` / `footer` must be stable references. Note: connector lines are rendered on a `<canvas>` (this document previously described them as a single SVG component — corrected here). |
@@ -134,6 +135,7 @@ The `DirectoryTree` component accepts the following props:
134
135
  | `visual` | `object` | No | - | Visual customization options. 表示のカスタマイズオプション。 |
135
136
  | `virtualScroll` | `DirectoryTreeVirtualScrollOptions` | No | - | Additional options for VirtualScroll integration. Includes `viewportHeightOverride` and `preserveScrollAnchor` (opt-in, default `false`: keeps the first visible row visually stationary across row-list mutations such as streaming insertions above the viewport; inactive at scroll 0; falls back to pixel-position when the anchored row vanished). VirtualScroll の設定を上書きするオプション。`preserveScrollAnchor` (既定 `false`) を有効化すると、行リスト変異時に先頭可視行を画面上で静止させる (最上部では不作動、アンカー行消失時はピクセル位置維持へフォールバック)。 |
136
137
  | `grid` | `DirectoryTreeGrid` | No | - | TreeGrid (columns) mode. When present, renders a frozen name column + aligned data columns with header/footer and a horizontally scrollable numeric region. See §3.2.4. TreeGrid(列)モード。指定時は凍結名前列+整列データ列を描画する(§3.2.4)。 |
138
+ | `sort` | `DirectoryEntryComparator` | No | - | Comparator applied to every sibling group before flattening. Only a shallow copy of each sibling array is sorted, so entry objects and their `children` arrays keep identity. Omit to render in the given order. **Stable reference required.** See §3.2.5. フラット化前に各兄弟グループへ適用する比較関数。兄弟配列の浅いコピーのみを並べ替えるため、エントリと `children` の identity は保持される。省略時は与えられた順序のまま。**参照安定必須**(§3.2.5)。 |
137
139
 
138
140
  #### 3.2.1. `expansion` Configuration
139
141
 
@@ -225,6 +227,44 @@ entries, and a horizontally scrollable numeric region. When omitted, the classic
225
227
  7. With empty `entries`, grid mode still renders the header and footer (footer aggregates over 0 entries) with the `treegrid` role; only the body has no rows.
226
228
  8. Horizontal scrolling only updates the shared CSS variable — the virtualized body is **not** re-rendered (the `VirtualScroll` element is memoized and the rows are `React.memo`-skipped).
227
229
 
230
+ #### 3.2.5. `sort` (sibling ordering)
231
+
232
+ `sort` is a plain comparator over two entries that share the same parent. It is applied inside the single
233
+ traversal that turns sibling order into row order, immediately before flattening, at **every** depth.
234
+ `sort` は同一の親を持つ 2 エントリを比較する関数で、兄弟順序が行順序へ変換される唯一の走査内で、フラット化直前に全階層へ適用される。
235
+
236
+ ```typescript
237
+ export type DirectoryEntryComparator = (a: DirectoryEntry, b: DirectoryEntry) => number
238
+ ```
239
+
240
+ **Guarantees / behavior:**
241
+
242
+ 1. **Entry identity is preserved.** Only a shallow copy of each sibling array is sorted (`[...siblings].sort(sort)`);
243
+ no `DirectoryEntry` object and no `children` array is cloned or mutated. Consumer-side memoization that keys on
244
+ entry identity — the internal row memo, reference-preserving decorators, hydration caches — therefore keeps working.
245
+ エントリ本体と `children` 配列は複製も変更もされないため、identity に依存する利用側のメモ化はそのまま機能する。
246
+ 2. **The `entries` prop is never mutated.** The caller's arrays are left in their original order.
247
+ 3. **Connector geometry follows the sorted order.** `isLastChild` and the ancestor chain derive from the loop index,
248
+ so the last *rendered* sibling receives the stub connector.
249
+ 4. Ordering is not a presentation concern (it changes row semantics and connector geometry, and applies identically in
250
+ grid mode), which is why `sort` is a top-level prop rather than a member of `visual`.
251
+ 5. **Stable reference required** (memoize with `useMemo` / `useCallback`) — a new identity each render re-runs the
252
+ whole traversal, the same constraint as `visual.itemHeight` and `grid.columns`.
253
+ 6. Omitting `sort` skips the copy entirely: entries render in exactly the order given.
254
+ 7. Sorting is applied to rows only; `grid.columns[].footer` still aggregates over all entries in input order, which is
255
+ order-insensitive by construction.
256
+
257
+ **Row keying.** `virtualScroll.getItemKey` is forwarded to `VirtualScroll`, and when it is omitted rows are keyed by
258
+ `entry.absolutePath` instead of by index. This is what lets a re-sort *move* existing rows rather than unmount and
259
+ remount every row whose index-to-entry mapping changed.
260
+ `virtualScroll.getItemKey` は `VirtualScroll` へ転送され、未指定時の既定行キーは `entry.absolutePath`。これにより並べ替え時に既存行は移動するだけで再生成されない。
261
+
262
+ ```typescript
263
+ const compare = useMemo<DirectoryEntryComparator>(() => (a, b) => a.name.localeCompare(b.name, "en", { numeric: true }), [])
264
+
265
+ <DirectoryTree entries={entries} expansion={...} selection={...} sort={compare} />
266
+ ```
267
+
228
268
  ### 3.3. Usage
229
269
 
230
270
  Here is a basic example of how to use the `DirectoryTree` component with the `useDirectoryTreeState` hook.
@@ -462,13 +502,22 @@ guards). Run `pnpm run test:coverage`.
462
502
  * **Memo comparator** (`isEntryExpanded`, entry-reference change, directory expansion change).
463
503
  * **`isEntryExpanded`** helper: directory expanded/collapsed, file short-circuit.
464
504
 
465
- ### 9.4. Pure helpers
505
+ ### 9.4. Sibling ordering & row keying ([DirectoryTree.sort.test.tsx](../tests/DirectoryTree.sort.test.tsx))
506
+
507
+ * **Default order**: without `sort`, rows appear in exactly the input order.
508
+ * **Ordering**: the comparator orders root siblings and, with the same comparator, the siblings of every expanded subtree; a descending comparator produces the exact inverse of the ascending one.
509
+ * **Identity preservation**: after sorting, the entry object handed to a row is `Object.is`-identical to the one in the input tree, and so is its `children` array.
510
+ * **Non-mutation**: the caller's `entries` arrays keep their original order.
511
+ * **Row stability**: re-rendering with a different comparator *moves* the DOM node of an unchanged entry rather than recreating it.
512
+ * **`getItemKey` forwarding**: a caller-supplied `virtualScroll.getItemKey` is actually invoked, and the default keys rows by `absolutePath` (proven by reordering `entries` and asserting DOM-node identity).
513
+
514
+ ### 9.5. Pure helpers
466
515
 
467
516
  * **[gridUtils.test.ts](../tests/gridUtils.test.ts)**: `buildNumericTemplate`, `computeGridMetrics`, `clampHScroll`, `flattenAllEntries` (incl. default/invalid widths, zero-width viewport, NaN clamp).
468
517
  * **[treeLineGeometry.test.ts](../tests/treeLineGeometry.test.ts)**: `buildTreeLineGeometry` — every connector variant (directory/file, last-child, ancestor lines, glyphs), `hideLines` skip, empty input, glyph-size fallback, and defensive out-of-bounds fallbacks.
469
518
  * **[useEntryInteraction.test.tsx](../tests/useEntryInteraction.test.tsx)**: file select, directory single-click (delayed toggle), double-click (recursive), `preventDefault`, unmount timer cleanup.
470
519
  * **[entryRendering.test.tsx](../tests/entryRendering.test.tsx)**: `resolveExpandIcon`, `resolveEntryIcon` (all icon paths + sanitizer edge cases), `getFileExtension`.
471
520
 
472
- ### 9.5. VirtualScroll horizontal wheel (`@aiquants/virtualscroll`)
521
+ ### 9.6. VirtualScroll horizontal wheel (`@aiquants/virtualscroll`)
473
522
 
474
523
  * **[wheel-horizontal.spec.tsx](../../virtualscroll/tests/integration/wheel-horizontal.spec.tsx)**: `onWheelHorizontal` fires on horizontal-dominant / shift+wheel gestures, not on vertical-dominant; `deltaMode` LINE/PAGE scaling; a no-op (backward-compatible) when the handler is absent.
@@ -12,7 +12,7 @@ import { DEFAULT_ITEM_HEIGHT, directoryTreeClasses, EXPAND_GLYPH_SIZE, getFileEx
12
12
  import { buildNumericTemplate, clampHScroll, computeGridMetrics, DEFAULT_GRID_SCROLLBAR_WIDTH, flattenAllEntries } from "./gridUtils.ts"
13
13
  import { captureScrollAnchor, resolveAnchorScroll } from "./scrollAnchor.ts"
14
14
  import { TreeLine } from "./TreeLine.tsx"
15
- import type { DirectoryEntry, DirectoryEntryItemProps, DirectoryTreeProps, DirectoryTreeVirtualScrollOptions, TreeLineGeometry, TreeLineGlyph, TreeLineItemInfo, TreeLineSegment } from "./types.ts"
15
+ import type { DirectoryEntry, DirectoryEntryComparator, DirectoryEntryItemProps, DirectoryTreeProps, DirectoryTreeVirtualScrollOptions, TreeLineGeometry, TreeLineGlyph, TreeLineItemInfo, TreeLineSegment } from "./types.ts"
16
16
  import { useEntryInteraction } from "./useEntryInteraction.ts"
17
17
 
18
18
  /**
@@ -54,17 +54,21 @@ type TreeTraversalResult = {
54
54
  /**
55
55
  * @function collectTreeData
56
56
  * @description Traverses directory entries to build flattened items and tree line metadata.
57
+ * Sibling groups are ordered by the optional comparator before flattening.
57
58
  * ディレクトリエントリを走査してフラットなアイテムとツリーライン用メタデータを構築する。
59
+ * フラット化の前に、任意の比較関数で兄弟グループを並べ替える。
58
60
  */
59
- const collectTreeData = (entries: DirectoryEntry[], resolver: (absolutePath: string, relativePath?: string) => boolean, includeTreeLines: boolean, removeRootIndent: boolean): TreeTraversalResult => {
61
+ const collectTreeData = (entries: DirectoryEntry[], resolver: (absolutePath: string, relativePath?: string) => boolean, includeTreeLines: boolean, removeRootIndent: boolean, sort?: DirectoryEntryComparator): TreeTraversalResult => {
60
62
  const flatItems: FlattenedEntry[] = []
61
63
  const lineItems: TreeLineItemInfo[] = []
62
64
  let maxIndent = 0
63
65
 
64
66
  const walk = (currentEntries: DirectoryEntry[], indentLevel: number, ancestorChain: boolean[]): void => {
65
- for (let index = 0; index < currentEntries.length; index++) {
66
- const entry = currentEntries[index]
67
- const isLastChild = index === currentEntries.length - 1
67
+ // 並べ替えは兄弟配列の浅いコピーに対してのみ行い、エントリと children の identity を保持する
68
+ const ordered = sort ? [...currentEntries].sort(sort) : currentEntries
69
+ for (let index = 0; index < ordered.length; index++) {
70
+ const entry = ordered[index]
71
+ const isLastChild = index === ordered.length - 1
68
72
  const nextAncestorChain = [...ancestorChain, isLastChild]
69
73
  const isDirectory = entry.children !== undefined
70
74
  const isExpanded = isDirectory && resolver(entry.absolutePath, entry.relativePath)
@@ -575,6 +579,7 @@ export const DirectoryTree = ({
575
579
  } = {},
576
580
  virtualScroll: virtualScrollOptions,
577
581
  grid,
582
+ sort,
578
583
  }: DirectoryTreeProps) => {
579
584
  const isGrid = grid !== undefined
580
585
  const [isClient, setIsClient] = useState(false)
@@ -601,6 +606,7 @@ export const DirectoryTree = ({
601
606
  scrollBarOptions,
602
607
  behaviorOptions,
603
608
  preserveScrollAnchor = false,
609
+ getItemKey: userGetItemKey,
604
610
  }: DirectoryTreeVirtualScrollOptions = virtualScrollOptions ?? {}
605
611
 
606
612
  const [scrollPosition, setScrollPosition] = useState(typeof initialScrollOffset === "number" ? initialScrollOffset : 0)
@@ -719,7 +725,7 @@ export const DirectoryTree = ({
719
725
  // frozen name column (which must start at x=0), so it is intentionally ignored in grid mode.
720
726
  // grid モードでは名前列を x=0 に凍結するため、負インデントに依存する removeRootIndent は無効化する。
721
727
  const effectiveRemoveRootIndent = isGrid ? false : removeRootIndent
722
- const { flatItems, lineItems, maxIndent } = useMemo(() => collectTreeData(entries, safeIsExpanded, showTreeLines, effectiveRemoveRootIndent), [entries, safeIsExpanded, showTreeLines, effectiveRemoveRootIndent])
728
+ const { flatItems, lineItems, maxIndent } = useMemo(() => collectTreeData(entries, safeIsExpanded, showTreeLines, effectiveRemoveRootIndent, sort), [entries, safeIsExpanded, showTreeLines, effectiveRemoveRootIndent, sort])
723
729
 
724
730
  // 各行の高さを解決する。number ならそのまま、関数なら (entry, flatIndex) で算出する。
725
731
  // 不正値 (NaN / Infinity / 0 / 負値) は既定高さにフォールバックし、オフセット表の単調性と CSS 高さの妥当性を保証する。
@@ -746,6 +752,11 @@ export const DirectoryTree = ({
746
752
  // VirtualScroll に渡す高さ取得関数。identity は itemHeights が変わったときだけ更新される。
747
753
  const getItemHeight = useCallback((index: number) => virtualItems[index]?.rowHeight ?? DEFAULT_ITEM_HEIGHT, [virtualItems])
748
754
 
755
+ // 行キーは既定で絶対パス。index キーのままだと並べ替えや挿入で index→entry の対応が変わるたびに
756
+ // 可視行が unmount/remount され、行メモも DOM 状態 (hover 等) も失われる。
757
+ const defaultGetItemKey = useCallback((index: number) => virtualItems[index]?.entry.absolutePath ?? index, [virtualItems])
758
+ const resolvedGetItemKey = userGetItemKey ?? defaultGetItemKey
759
+
749
760
  const treeLineGeometry = useMemo(
750
761
  () => (!showTreeLines || lineItems.length === 0 ? { segmentsByItem: [], glyphsByItem: [] } : buildTreeLineGeometry(lineItems, itemHeights, itemOffsets, INDENT_SIZE, showTreeLines, expandIconSize ?? EXPAND_GLYPH_SIZE)),
751
762
  [lineItems, itemHeights, itemOffsets, showTreeLines, expandIconSize],
@@ -867,6 +878,7 @@ export const DirectoryTree = ({
867
878
  itemCount={virtualItems.length}
868
879
  getItem={getItem}
869
880
  getItemHeight={getItemHeight}
881
+ getItemKey={resolvedGetItemKey}
870
882
  viewportSize={viewportHeight}
871
883
  overscanCount={userOverscanCount}
872
884
  onScroll={handleVirtualScroll}
@@ -951,6 +963,7 @@ export const DirectoryTree = ({
951
963
  virtualItems.length,
952
964
  getItem,
953
965
  getItemHeight,
966
+ resolvedGetItemKey,
954
967
  viewportHeight,
955
968
  userOverscanCount,
956
969
  handleVirtualScroll,
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@
12
12
  export { DirectoryTree, directoryTreeClasses } from "./DirectoryTree.tsx"
13
13
  export type {
14
14
  DirectoryEntry,
15
+ DirectoryEntryComparator,
15
16
  DirectoryEntryItemProps,
16
17
  DirectoryTreeClickEvent,
17
18
  DirectoryTreeColumn,
package/src/types.ts CHANGED
@@ -39,6 +39,16 @@ export type DirectoryEntry = {
39
39
  style?: CSSProperties
40
40
  }
41
41
 
42
+ /**
43
+ * Comparator applied to a sibling group before the tree is flattened into rows.
44
+ * Receives two entries that share the same parent and returns the usual
45
+ * `Array.prototype.sort` ordering number.
46
+ *
47
+ * ツリーを行へフラット化する前に、同一の親を持つ兄弟グループへ適用する比較関数。
48
+ * 戻り値は `Array.prototype.sort` と同じ順序数値。
49
+ */
50
+ export type DirectoryEntryComparator = (a: DirectoryEntry, b: DirectoryEntry) => number
51
+
42
52
  /**
43
53
  * Row height for directory tree entries.
44
54
  * Either a fixed pixel value applied to every row, or a function computing the
@@ -499,6 +509,23 @@ export type DirectoryTreeProps = {
499
509
  * `grid.columns` と各 `render` / `footer` は参照安定必須(`itemHeight` と同じ制約)。
500
510
  */
501
511
  grid?: DirectoryTreeGrid
512
+
513
+ /**
514
+ * Optional comparator applied to every sibling group before the tree is flattened
515
+ * into rows. Only a shallow copy of each sibling array is sorted, so every
516
+ * `DirectoryEntry` object and every `children` array keeps its identity and
517
+ * consumer-side memoization (row memo, reference-preserving decorators, hydration
518
+ * caches) continues to work. Omit it to render the entries in their given order.
519
+ *
520
+ * 各兄弟グループへフラット化前に適用する任意の比較関数。並べ替えは兄弟配列の浅いコピーに
521
+ * 対してのみ行うため、`DirectoryEntry` と `children` 配列の identity は保持され、利用側の
522
+ * メモ化 (行メモ・参照保持デコレータ・ハイドレーションキャッシュ) はそのまま機能する。
523
+ * 省略時は与えられた順序のまま描画。
524
+ *
525
+ * @remarks 参照を安定させること (`useMemo` / `useCallback`)。identity が毎レンダー変わると
526
+ * ツリー走査が都度再計算され、パフォーマンスが劣化する (`itemHeight` と同じ制約)。
527
+ */
528
+ sort?: DirectoryEntryComparator
502
529
  }
503
530
 
504
531
  /**