@aiquants/directory-tree 3.3.0 → 3.5.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
@@ -31,7 +31,32 @@ export type DirectoryEntry = {
31
31
  * エントリ用のオプションのインラインスタイル。
32
32
  */
33
33
  style?: CSSProperties;
34
+ /**
35
+ * Extra `data-*` attributes rendered on this entry's row. Keys are given **without** the
36
+ * `data-` prefix (`{ open: true }` renders `data-open="true"`); values are stringified.
37
+ * camelCase keys are converted to kebab-case exactly as the DOM `dataset` API does
38
+ * (`{ panelCount: 2 }` renders `data-panel-count="2"`).
39
+ *
40
+ * この行へ付与する追加の `data-*` 属性。キーは `data-` を**含めずに**渡し
41
+ * (`{ open: true }` は `data-open="true"` になる)、値は文字列化される。
42
+ * camelCase のキーは DOM の `dataset` と同じ規約で kebab-case へ変換される
43
+ * (`{ panelCount: 2 }` は `data-panel-count="2"`)。
44
+ *
45
+ * @remarks 用途は、状態を CSS クラスではなく属性として公開し、テストやスタイルが
46
+ * クラス名に依存しないようにすること。クラス名は整形や prefix 変更で無言に壊れる。
47
+ * このコンポーネント自身が出力する `data-entry-*` は上書きできない (常に後勝ち)。
48
+ */
49
+ data?: Record<string, string | number | boolean>;
34
50
  };
51
+ /**
52
+ * Comparator applied to a sibling group before the tree is flattened into rows.
53
+ * Receives two entries that share the same parent and returns the usual
54
+ * `Array.prototype.sort` ordering number.
55
+ *
56
+ * ツリーを行へフラット化する前に、同一の親を持つ兄弟グループへ適用する比較関数。
57
+ * 戻り値は `Array.prototype.sort` と同じ順序数値。
58
+ */
59
+ export type DirectoryEntryComparator = (a: DirectoryEntry, b: DirectoryEntry) => number;
35
60
  /**
36
61
  * Row height for directory tree entries.
37
62
  * Either a fixed pixel value applied to every row, or a function computing the
@@ -481,6 +506,22 @@ export type DirectoryTreeProps = {
481
506
  * `grid.columns` と各 `render` / `footer` は参照安定必須(`itemHeight` と同じ制約)。
482
507
  */
483
508
  grid?: DirectoryTreeGrid;
509
+ /**
510
+ * Optional comparator applied to every sibling group before the tree is flattened
511
+ * into rows. Only a shallow copy of each sibling array is sorted, so every
512
+ * `DirectoryEntry` object and every `children` array keeps its identity and
513
+ * consumer-side memoization (row memo, reference-preserving decorators, hydration
514
+ * caches) continues to work. Omit it to render the entries in their given order.
515
+ *
516
+ * 各兄弟グループへフラット化前に適用する任意の比較関数。並べ替えは兄弟配列の浅いコピーに
517
+ * 対してのみ行うため、`DirectoryEntry` と `children` 配列の identity は保持され、利用側の
518
+ * メモ化 (行メモ・参照保持デコレータ・ハイドレーションキャッシュ) はそのまま機能する。
519
+ * 省略時は与えられた順序のまま描画。
520
+ *
521
+ * @remarks 参照を安定させること (`useMemo` / `useCallback`)。identity が毎レンダー変わると
522
+ * ツリー走査が都度再計算され、パフォーマンスが劣化する (`itemHeight` と同じ制約)。
523
+ */
524
+ sort?: DirectoryEntryComparator;
484
525
  };
485
526
  /**
486
527
  * Props for the useDirectoryTreeState hook.
@@ -506,6 +547,18 @@ export type UseDirectoryTreeStateProps = {
506
547
  export type DirectoryEntryItemProps = {
507
548
  entry: DirectoryEntry;
508
549
  indentLevel: number;
550
+ /**
551
+ * Logical depth from the roots, 0-based, independent of the visual indent.
552
+ * ルートからの論理的な深さ (0 始まり)。視覚的インデントとは独立。
553
+ *
554
+ * `visual.removeRootIndent` は `indentLevel` を負方向へずらすため、`aria-level` の算出には
555
+ * こちらを用いる (支援技術へ伝えるのは見た目のずれではなく実際の階層)。
556
+ */
557
+ depth: number;
558
+ /** 1-based position among its siblings (`aria-posinset`). / 兄弟内の位置 (1 始まり)。 */
559
+ positionInSet: number;
560
+ /** Number of siblings in the same group (`aria-setsize`). / 同一グループの兄弟数。 */
561
+ setSize: number;
509
562
  /** Resolved height of this row in px. / この行の解決済み高さ (px)。 */
510
563
  rowHeight: number;
511
564
  isDirOpen: (path: string) => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","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C/B,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,cAAc,EAAE,MAAM,CAAA;IACtB,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,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.5.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,8 @@
4
4
 
5
5
  | Version | Date | Author | Reviewer | Approver | Summary of Changes |
6
6
  | :--- | :--- | :--- | :--- | :--- | :--- |
7
+ | 3.5.0 | 2026-08-08 | Claude Opus 5 | | | Rows now declare their position in the tree: `aria-level` (1-based **logical** depth, so `visual.removeRootIndent` no longer misreports the hierarchy it only shifts visually), `aria-posinset` and `aria-setsize`, taken from the **post-sort** sibling order so the announced position always matches the rendered one. Grid rows gain `aria-posinset` / `aria-setsize` alongside the `aria-level` they already had. New `DirectoryEntry.data` renders extra `data-*` attributes on the row so consumers can expose state as attributes instead of CSS classes (class names are a styling contract and break silently under utility refactors); keys are given without the `data-` prefix and camelCase is converted to kebab-case exactly as the DOM `dataset` API does, since React otherwise drops the attribute with only a warning. The component's own `data-entry-*` attributes cannot be overridden. Also completes the pass-through audit started in 3.4.0: `virtualScroll.testId` and `virtualScroll.contentProps` were accepted by the type but never forwarded, and are now forwarded (they target the scroll pane, a different element from the `role="tree"` container this component owns, so there is no ARIA conflict). |
8
+ | 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
9
  | 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
10
  | 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
11
  | 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). |
@@ -120,6 +122,13 @@ The fundamental data structure for representing a file or directory.
120
122
  | `absolutePath` | `string` | The absolute path of the entry. エントリの絶対パス。 |
121
123
  | `relativePath` | `string` | The path of the entry relative to the root. ルートからの相対パス。 |
122
124
  | `children` | `DirectoryEntry[] \| null` | An array of child entries if it's a directory, otherwise `null`. ディレクトリの場合は子エントリの配列、それ以外の場合は `null`。 |
125
+ | `data` | `Record<string, string \| number \| boolean>` | Extra `data-*` attributes rendered on this entry's row. Keys omit the `data-` prefix; camelCase becomes kebab-case as with the DOM `dataset` API (`{ panelCount: 2 }` → `data-panel-count="2"`). Values are stringified. The component's own `data-entry-*` attributes always win. この行へ付与する追加の `data-*` 属性。キーは `data-` を含めず、camelCase は `dataset` と同じ規約で kebab-case になる。自前の `data-entry-*` は上書き不可。 |
126
+
127
+ **Why `data` exists**: it lets a consumer expose row state as an *attribute* rather than as a CSS class, so
128
+ styling and test locators never depend on class names — those are a styling contract that changes freely under
129
+ utility refactors, prefix migrations and class sorting, and break silently when they do.
130
+ `data` は行の状態を CSS クラスではなく属性として公開するための口。クラス名はスタイリング契約であり、
131
+ 整形や prefix 変更で無言に壊れるため、スタイルやテストの依存先にしない。
123
132
 
124
133
  ### 3.2. Props
125
134
 
@@ -134,6 +143,7 @@ The `DirectoryTree` component accepts the following props:
134
143
  | `visual` | `object` | No | - | Visual customization options. 表示のカスタマイズオプション。 |
135
144
  | `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
145
  | `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)。 |
146
+ | `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
147
 
138
148
  #### 3.2.1. `expansion` Configuration
139
149
 
@@ -225,6 +235,46 @@ entries, and a horizontally scrollable numeric region. When omitted, the classic
225
235
  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
236
  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
237
 
238
+ #### 3.2.5. `sort` (sibling ordering)
239
+
240
+ `sort` is a plain comparator over two entries that share the same parent. It is applied inside the single
241
+ traversal that turns sibling order into row order, immediately before flattening, at **every** depth.
242
+ `sort` は同一の親を持つ 2 エントリを比較する関数で、兄弟順序が行順序へ変換される唯一の走査内で、フラット化直前に全階層へ適用される。
243
+
244
+ ```typescript
245
+ export type DirectoryEntryComparator = (a: DirectoryEntry, b: DirectoryEntry) => number
246
+ ```
247
+
248
+ **Guarantees / behavior:**
249
+
250
+ 1. **Entry identity is preserved.** Only a shallow copy of each sibling array is sorted (`[...siblings].sort(sort)`);
251
+ no `DirectoryEntry` object and no `children` array is cloned or mutated. Consumer-side memoization that keys on
252
+ entry identity — the internal row memo, reference-preserving decorators, hydration caches — therefore keeps working.
253
+ エントリ本体と `children` 配列は複製も変更もされないため、identity に依存する利用側のメモ化はそのまま機能する。
254
+ 2. **The `entries` prop is never mutated.** The caller's arrays are left in their original order.
255
+ 3. **Connector geometry follows the sorted order.** `isLastChild` and the ancestor chain derive from the loop index,
256
+ so the last *rendered* sibling receives the stub connector.
257
+ 4. Ordering is not a presentation concern (it changes row semantics and connector geometry, and applies identically in
258
+ grid mode), which is why `sort` is a top-level prop rather than a member of `visual`.
259
+ 5. **Stable reference required** (memoize with `useMemo` / `useCallback`) — a new identity each render re-runs the
260
+ whole traversal, the same constraint as `visual.itemHeight` and `grid.columns`.
261
+ 6. Omitting `sort` skips the copy entirely: entries render in exactly the order given.
262
+ 7. Sorting is applied to **rows only**. `grid.columns[].footer` still receives every node of the `entries` prop in the
263
+ **prop's** order, not the rendered order. Most footers aggregate (sum / count) and are unaffected, but a footer whose
264
+ output depends on order (e.g. "first item", a running sequence) must apply the same comparator itself.
265
+ フッタは描画順ではなく `entries` の順序で全ノードを受け取る。順序に依存するフッタは同じ比較関数を自前で適用すること。
266
+
267
+ **Row keying.** `virtualScroll.getItemKey` is forwarded to `VirtualScroll`, and when it is omitted rows are keyed by
268
+ `entry.absolutePath` instead of by index. This is what lets a re-sort *move* existing rows rather than unmount and
269
+ remount every row whose index-to-entry mapping changed.
270
+ `virtualScroll.getItemKey` は `VirtualScroll` へ転送され、未指定時の既定行キーは `entry.absolutePath`。これにより並べ替え時に既存行は移動するだけで再生成されない。
271
+
272
+ ```typescript
273
+ const compare = useMemo<DirectoryEntryComparator>(() => (a, b) => a.name.localeCompare(b.name, "en", { numeric: true }), [])
274
+
275
+ <DirectoryTree entries={entries} expansion={...} selection={...} sort={compare} />
276
+ ```
277
+
228
278
  ### 3.3. Usage
229
279
 
230
280
  Here is a basic example of how to use the `DirectoryTree` component with the `useDirectoryTreeState` hook.
@@ -462,13 +512,30 @@ guards). Run `pnpm run test:coverage`.
462
512
  * **Memo comparator** (`isEntryExpanded`, entry-reference change, directory expansion change).
463
513
  * **`isEntryExpanded`** helper: directory expanded/collapsed, file short-circuit.
464
514
 
465
- ### 9.4. Pure helpers
515
+ ### 9.4. Sibling ordering & row keying ([DirectoryTree.sort.test.tsx](../tests/DirectoryTree.sort.test.tsx))
516
+
517
+ * **Default order**: without `sort`, rows appear in exactly the input order.
518
+ * **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.
519
+ * **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.
520
+ * **Non-mutation**: the caller's `entries` arrays keep their original order.
521
+ * **Row stability**: re-rendering with a different comparator *moves* the DOM node of an unchanged entry rather than recreating it.
522
+ * **`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).
523
+
524
+ ### 9.5. Row position semantics, `data-*` and pass-through ([DirectoryTree.a11y-and-passthrough.test.tsx](../tests/DirectoryTree.a11y-and-passthrough.test.tsx))
525
+
526
+ * **`aria-level`**: 1-based logical depth for roots and nested rows, and **unchanged by `visual.removeRootIndent`** (which shifts only the visual indent).
527
+ * **`aria-posinset` / `aria-setsize`**: position and sibling count per group, independent between a parent's group and its children's.
528
+ * **Post-sort position**: with a comparator applied, the announced position matches the rendered order at every depth — the announcement can never contradict what is drawn.
529
+ * **`entry.data`**: rendered as `data-*`; camelCase converted to kebab-case; absent/empty `data` adds no attributes; the component's own `data-entry-*` cannot be overridden.
530
+ * **Pass-through**: `virtualScroll.testId` and `virtualScroll.contentProps` actually reach `VirtualScroll` (regression gate for the typed-but-dropped class of defect).
531
+
532
+ ### 9.6. Pure helpers
466
533
 
467
534
  * **[gridUtils.test.ts](../tests/gridUtils.test.ts)**: `buildNumericTemplate`, `computeGridMetrics`, `clampHScroll`, `flattenAllEntries` (incl. default/invalid widths, zero-width viewport, NaN clamp).
468
535
  * **[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
536
  * **[useEntryInteraction.test.tsx](../tests/useEntryInteraction.test.tsx)**: file select, directory single-click (delayed toggle), double-click (recursive), `preventDefault`, unmount timer cleanup.
470
537
  * **[entryRendering.test.tsx](../tests/entryRendering.test.tsx)**: `resolveExpandIcon`, `resolveEntryIcon` (all icon paths + sanitizer edge cases), `getFileExtension`.
471
538
 
472
- ### 9.5. VirtualScroll horizontal wheel (`@aiquants/virtualscroll`)
539
+ ### 9.7. VirtualScroll horizontal wheel (`@aiquants/virtualscroll`)
473
540
 
474
541
  * **[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.
@@ -8,11 +8,11 @@ import type { CSSProperties, MouseEvent } from "react"
8
8
  import { Fragment, memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"
9
9
  import { twMerge } from "tailwind-merge"
10
10
  import { DirectoryTreeGridFooterRow, DirectoryTreeGridHeaderRow, DirectoryTreeGridRow } from "./DirectoryTreeGrid.tsx"
11
- import { DEFAULT_ITEM_HEIGHT, directoryTreeClasses, EXPAND_GLYPH_SIZE, getFileExtension, INDENT_SIZE, resolveEntryIcon, resolveExpandIcon } from "./entryRendering.tsx"
11
+ import { DEFAULT_ITEM_HEIGHT, directoryTreeClasses, EXPAND_GLYPH_SIZE, getFileExtension, INDENT_SIZE, resolveEntryIcon, resolveExpandIcon, toDataAttributes } from "./entryRendering.tsx"
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
  /**
@@ -40,7 +40,18 @@ const applyWebkitScrollbarHide = () => {
40
40
  }
41
41
  }
42
42
 
43
- type FlattenedEntry = { entry: DirectoryEntry; indentLevel: number; parentIsLast: boolean[] }
43
+ type FlattenedEntry = {
44
+ entry: DirectoryEntry
45
+ /** 視覚的インデント段数 (removeRootIndent で負になり得る)。 */
46
+ indentLevel: number
47
+ /** ルートからの論理的な深さ (0 始まり)。`aria-level` の算出に使う。 */
48
+ depth: number
49
+ /** 兄弟内の位置 (1 始まり)。 */
50
+ positionInSet: number
51
+ /** 同一グループの兄弟数。 */
52
+ setSize: number
53
+ parentIsLast: boolean[]
54
+ }
44
55
 
45
56
  /** A flattened entry with its resolved row height. / 解決済みの行高を持つフラット化エントリ。 */
46
57
  type VirtualItem = FlattenedEntry & { rowHeight: number }
@@ -54,17 +65,21 @@ type TreeTraversalResult = {
54
65
  /**
55
66
  * @function collectTreeData
56
67
  * @description Traverses directory entries to build flattened items and tree line metadata.
68
+ * Sibling groups are ordered by the optional comparator before flattening.
57
69
  * ディレクトリエントリを走査してフラットなアイテムとツリーライン用メタデータを構築する。
70
+ * フラット化の前に、任意の比較関数で兄弟グループを並べ替える。
58
71
  */
59
- const collectTreeData = (entries: DirectoryEntry[], resolver: (absolutePath: string, relativePath?: string) => boolean, includeTreeLines: boolean, removeRootIndent: boolean): TreeTraversalResult => {
72
+ const collectTreeData = (entries: DirectoryEntry[], resolver: (absolutePath: string, relativePath?: string) => boolean, includeTreeLines: boolean, removeRootIndent: boolean, sort?: DirectoryEntryComparator): TreeTraversalResult => {
60
73
  const flatItems: FlattenedEntry[] = []
61
74
  const lineItems: TreeLineItemInfo[] = []
62
75
  let maxIndent = 0
63
76
 
64
77
  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
78
+ // 並べ替えは兄弟配列の浅いコピーに対してのみ行い、エントリと children の identity を保持する
79
+ const ordered = sort ? [...currentEntries].sort(sort) : currentEntries
80
+ for (let index = 0; index < ordered.length; index++) {
81
+ const entry = ordered[index]
82
+ const isLastChild = index === ordered.length - 1
68
83
  const nextAncestorChain = [...ancestorChain, isLastChild]
69
84
  const isDirectory = entry.children !== undefined
70
85
  const isExpanded = isDirectory && resolver(entry.absolutePath, entry.relativePath)
@@ -79,7 +94,8 @@ const collectTreeData = (entries: DirectoryEntry[], resolver: (absolutePath: str
79
94
  effectiveAncestorChain = ancestorChain.slice(1)
80
95
  }
81
96
 
82
- flatItems.push({ entry, indentLevel: effectiveIndentLevel, parentIsLast: effectiveNextAncestorChain })
97
+ // 位置情報は並べ替え後の ordered から採るため、aria の申告は実際の描画順と常に一致する
98
+ flatItems.push({ entry, indentLevel: effectiveIndentLevel, depth: indentLevel, positionInSet: index + 1, setSize: ordered.length, parentIsLast: effectiveNextAncestorChain })
83
99
 
84
100
  if (includeTreeLines) {
85
101
  if (effectiveIndentLevel > maxIndent) {
@@ -319,6 +335,9 @@ const DirectoryEntryItem = memo<DirectoryEntryItemProps>(
319
335
  ({
320
336
  entry,
321
337
  indentLevel,
338
+ depth,
339
+ positionInSet,
340
+ setSize,
322
341
  rowHeight,
323
342
  isDirOpen,
324
343
  parentIsLast,
@@ -398,6 +417,9 @@ const DirectoryEntryItem = memo<DirectoryEntryItemProps>(
398
417
  ...(!isDirectory && (isSelected || isItemSelected) ? highlightStyles?.itemSelectedStyle : {}),
399
418
  }
400
419
 
420
+ // 利用側が渡した data-* 属性。自身が出力する data-entry-* より前に展開し、後勝ちで守る
421
+ const customDataAttributes = toDataAttributes(entry.data)
422
+
401
423
  const typeIconStyle = typeIconSize ? { width: typeIconSize, height: typeIconSize } : undefined
402
424
  const fontSizeStyle = fontSize ? { fontSize: typeof fontSize === "number" ? `${fontSize}px` : fontSize } : undefined
403
425
 
@@ -415,6 +437,7 @@ const DirectoryEntryItem = memo<DirectoryEntryItemProps>(
415
437
  ...entryStyle,
416
438
  ...entry.style,
417
439
  }}
440
+ {...customDataAttributes}
418
441
  data-entry-type={isDirectory ? "directory" : "file"}
419
442
  data-entry-expanded={isDirectory ? String(isExpanded) : undefined}
420
443
  data-entry-selected={isSelected ? "true" : undefined}
@@ -426,6 +449,9 @@ const DirectoryEntryItem = memo<DirectoryEntryItemProps>(
426
449
  tabIndex={0}
427
450
  role="treeitem"
428
451
  aria-expanded={isDirectory ? isExpanded : undefined}
452
+ aria-level={depth + 1}
453
+ aria-posinset={positionInSet}
454
+ aria-setsize={setSize}
429
455
  aria-label={`${entry.name} (${isDirectory ? "directory" : "file"})`}>
430
456
  {(showExpandIcons || useCanvasExpandIcons) && <span className={expandIconClasses}>{expandIconContent}</span>}
431
457
  {(isDirectory ? showDirectoryIcons : showFileIcons) && (
@@ -453,6 +479,9 @@ const DirectoryEntryItem = memo<DirectoryEntryItemProps>(
453
479
  key={child.absolutePath}
454
480
  entry={child}
455
481
  indentLevel={indentLevel + 1}
482
+ depth={depth + 1}
483
+ positionInSet={index + 1}
484
+ setSize={childrenToRender.length}
456
485
  // 非仮想化の再帰描画では親行の高さを一様に流用する (DirectoryTree は renderChildren=false のため通常この経路は通らない)。
457
486
  rowHeight={rowHeight}
458
487
  isDirOpen={isDirOpen}
@@ -493,6 +522,10 @@ const DirectoryEntryItem = memo<DirectoryEntryItemProps>(
493
522
 
494
523
  return (
495
524
  prev.indentLevel === next.indentLevel &&
525
+ // 位置情報は aria として描画されるため、変化したら再描画が必要
526
+ prev.depth === next.depth &&
527
+ prev.positionInSet === next.positionInSet &&
528
+ prev.setSize === next.setSize &&
496
529
  prev.rowHeight === next.rowHeight &&
497
530
  prevExpanded === nextExpanded &&
498
531
  prev.selection.selectedPath === next.selection.selectedPath &&
@@ -575,6 +608,7 @@ export const DirectoryTree = ({
575
608
  } = {},
576
609
  virtualScroll: virtualScrollOptions,
577
610
  grid,
611
+ sort,
578
612
  }: DirectoryTreeProps) => {
579
613
  const isGrid = grid !== undefined
580
614
  const [isClient, setIsClient] = useState(false)
@@ -601,6 +635,11 @@ export const DirectoryTree = ({
601
635
  scrollBarOptions,
602
636
  behaviorOptions,
603
637
  preserveScrollAnchor = false,
638
+ getItemKey: userGetItemKey,
639
+ // 素通しの pass-through。型で受け付けているものは実際に転送する
640
+ // (`role="tree"` は本コンポーネント自身のコンテナに付くため contentProps とは別要素で衝突しない)
641
+ testId,
642
+ contentProps,
604
643
  }: DirectoryTreeVirtualScrollOptions = virtualScrollOptions ?? {}
605
644
 
606
645
  const [scrollPosition, setScrollPosition] = useState(typeof initialScrollOffset === "number" ? initialScrollOffset : 0)
@@ -719,7 +758,7 @@ export const DirectoryTree = ({
719
758
  // frozen name column (which must start at x=0), so it is intentionally ignored in grid mode.
720
759
  // grid モードでは名前列を x=0 に凍結するため、負インデントに依存する removeRootIndent は無効化する。
721
760
  const effectiveRemoveRootIndent = isGrid ? false : removeRootIndent
722
- const { flatItems, lineItems, maxIndent } = useMemo(() => collectTreeData(entries, safeIsExpanded, showTreeLines, effectiveRemoveRootIndent), [entries, safeIsExpanded, showTreeLines, effectiveRemoveRootIndent])
761
+ const { flatItems, lineItems, maxIndent } = useMemo(() => collectTreeData(entries, safeIsExpanded, showTreeLines, effectiveRemoveRootIndent, sort), [entries, safeIsExpanded, showTreeLines, effectiveRemoveRootIndent, sort])
723
762
 
724
763
  // 各行の高さを解決する。number ならそのまま、関数なら (entry, flatIndex) で算出する。
725
764
  // 不正値 (NaN / Infinity / 0 / 負値) は既定高さにフォールバックし、オフセット表の単調性と CSS 高さの妥当性を保証する。
@@ -746,6 +785,11 @@ export const DirectoryTree = ({
746
785
  // VirtualScroll に渡す高さ取得関数。identity は itemHeights が変わったときだけ更新される。
747
786
  const getItemHeight = useCallback((index: number) => virtualItems[index]?.rowHeight ?? DEFAULT_ITEM_HEIGHT, [virtualItems])
748
787
 
788
+ // 行キーは既定で絶対パス。index キーのままだと並べ替えや挿入で index→entry の対応が変わるたびに
789
+ // 可視行が unmount/remount され、行メモも DOM 状態 (hover 等) も失われる。
790
+ const defaultGetItemKey = useCallback((index: number) => virtualItems[index]?.entry.absolutePath ?? index, [virtualItems])
791
+ const resolvedGetItemKey = userGetItemKey ?? defaultGetItemKey
792
+
749
793
  const treeLineGeometry = useMemo(
750
794
  () => (!showTreeLines || lineItems.length === 0 ? { segmentsByItem: [], glyphsByItem: [] } : buildTreeLineGeometry(lineItems, itemHeights, itemOffsets, INDENT_SIZE, showTreeLines, expandIconSize ?? EXPAND_GLYPH_SIZE)),
751
795
  [lineItems, itemHeights, itemOffsets, showTreeLines, expandIconSize],
@@ -867,6 +911,9 @@ export const DirectoryTree = ({
867
911
  itemCount={virtualItems.length}
868
912
  getItem={getItem}
869
913
  getItemHeight={getItemHeight}
914
+ getItemKey={resolvedGetItemKey}
915
+ testId={testId}
916
+ contentProps={contentProps}
870
917
  viewportSize={viewportHeight}
871
918
  overscanCount={userOverscanCount}
872
919
  onScroll={handleVirtualScroll}
@@ -901,6 +948,8 @@ export const DirectoryTree = ({
901
948
  key={item.entry.absolutePath}
902
949
  entry={item.entry}
903
950
  indentLevel={item.indentLevel}
951
+ positionInSet={item.positionInSet}
952
+ setSize={item.setSize}
904
953
  rowHeight={item.rowHeight}
905
954
  isDirOpen={safeIsExpanded}
906
955
  columns={grid.columns}
@@ -919,6 +968,9 @@ export const DirectoryTree = ({
919
968
  key={item.entry.absolutePath}
920
969
  entry={item.entry}
921
970
  indentLevel={item.indentLevel}
971
+ depth={item.depth}
972
+ positionInSet={item.positionInSet}
973
+ setSize={item.setSize}
922
974
  rowHeight={item.rowHeight}
923
975
  isDirOpen={safeIsExpanded}
924
976
  parentIsLast={item.parentIsLast}
@@ -951,6 +1003,9 @@ export const DirectoryTree = ({
951
1003
  virtualItems.length,
952
1004
  getItem,
953
1005
  getItemHeight,
1006
+ resolvedGetItemKey,
1007
+ testId,
1008
+ contentProps,
954
1009
  viewportHeight,
955
1010
  userOverscanCount,
956
1011
  handleVirtualScroll,
@@ -11,7 +11,7 @@
11
11
  import type { CSSProperties, MouseEvent, ReactNode } from "react"
12
12
  import { memo, useState } from "react"
13
13
  import { twMerge } from "tailwind-merge"
14
- import { directoryTreeClasses, getFileExtension, INDENT_SIZE, resolveEntryIcon, resolveExpandIcon } from "./entryRendering.tsx"
14
+ import { directoryTreeClasses, getFileExtension, INDENT_SIZE, resolveEntryIcon, resolveExpandIcon, toDataAttributes } from "./entryRendering.tsx"
15
15
  import type { DirectoryEntry, DirectoryTreeColumn, DirectoryTreeIconOverrides, HighlightStyles } from "./types.ts"
16
16
  import { useEntryInteraction } from "./useEntryInteraction.ts"
17
17
 
@@ -44,6 +44,10 @@ const numericTrackStyle = (numericTotal: number, numericTemplate: string): CSSPr
44
44
  export type DirectoryTreeGridRowProps = {
45
45
  entry: DirectoryEntry
46
46
  indentLevel: number
47
+ /** 兄弟内の位置 (1 始まり)。`aria-posinset` として出力する。 */
48
+ positionInSet: number
49
+ /** 同一グループの兄弟数。`aria-setsize` として出力する。 */
50
+ setSize: number
47
51
  rowHeight: number
48
52
  isDirOpen: (path: string) => boolean
49
53
  columns: DirectoryTreeColumn[]
@@ -75,6 +79,8 @@ export const DirectoryTreeGridRow = memo<DirectoryTreeGridRowProps>(
75
79
  ({
76
80
  entry,
77
81
  indentLevel,
82
+ positionInSet,
83
+ setSize,
78
84
  rowHeight,
79
85
  isDirOpen,
80
86
  columns,
@@ -134,6 +140,9 @@ export const DirectoryTreeGridRow = memo<DirectoryTreeGridRowProps>(
134
140
  role="row"
135
141
  aria-expanded={isDirectory ? isExpanded : undefined}
136
142
  aria-level={indentLevel + 1}
143
+ aria-posinset={positionInSet}
144
+ aria-setsize={setSize}
145
+ {...toDataAttributes(entry.data)}
137
146
  data-entry-type={isDirectory ? "directory" : "file"}
138
147
  data-entry-expanded={isDirectory ? String(isExpanded) : undefined}
139
148
  data-entry-selected={isSelected ? "true" : undefined}
@@ -170,6 +179,8 @@ export const DirectoryTreeGridRow = memo<DirectoryTreeGridRowProps>(
170
179
  const nextExpanded = isEntryExpanded(next.entry, next.isDirOpen)
171
180
  return (
172
181
  prev.indentLevel === next.indentLevel &&
182
+ prev.positionInSet === next.positionInSet &&
183
+ prev.setSize === next.setSize &&
173
184
  prev.rowHeight === next.rowHeight &&
174
185
  prevExpanded === nextExpanded &&
175
186
  prev.columns === next.columns &&
@@ -249,3 +249,40 @@ export const resolveEntryIcon = (ctx: DirectoryTreeIconRenderContext, overrides?
249
249
  if (typeof target === "function") return sanitizeIcon(target(ctx), entry.absolutePath)
250
250
  return sanitizeIcon(target, entry.absolutePath)
251
251
  }
252
+
253
+ /**
254
+ * @function toKebabCase
255
+ * @description Converts a camelCase key to the kebab-case form HTML `data-*` attributes require.
256
+ * camelCase のキーを、HTML の `data-*` 属性が要求する kebab-case へ変換する。
257
+ *
258
+ * @param key - 変換前のキー。
259
+ * @returns kebab-case のキー。
260
+ */
261
+ const toKebabCase = (key: string): string => key.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase()
262
+
263
+ /**
264
+ * @function toDataAttributes
265
+ * @description Converts an entry's `data` map into React `data-*` props.
266
+ * エントリの `data` マップを React の `data-*` props へ変換する。
267
+ *
268
+ * キーは `data-` を含めずに受け取り、ここで接頭辞を付ける。値は属性として出力するため文字列化する。
269
+ * camelCase のキーは HTML の `dataset` と同じ規約で kebab-case へ変換する
270
+ * (`panelCount` → `data-panel-count`)。変換しないと React が属性を落として警告を出すだけで、
271
+ * 利用側からは「指定したのに出ない」という無言の失敗に見える。
272
+ *
273
+ * 呼び出し側はこの結果をコンポーネント自身の `data-entry-*` より**前**に展開すること
274
+ * (後勝ちで自前の属性を守るため)。
275
+ *
276
+ * @param data - エントリの `data` マップ (未指定可)。
277
+ * @returns `data-*` をキーとするオブジェクト。`data` が空なら undefined。
278
+ */
279
+ export const toDataAttributes = (data?: Record<string, string | number | boolean>): Record<string, string> | undefined => {
280
+ if (!data) {
281
+ return undefined
282
+ }
283
+ const entries = Object.entries(data)
284
+ if (entries.length === 0) {
285
+ return undefined
286
+ }
287
+ return Object.fromEntries(entries.map(([key, value]) => [`data-${toKebabCase(key)}`, String(value)]))
288
+ }
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,