@aiquants/directory-tree 3.11.0 → 3.11.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.
Files changed (45) hide show
  1. package/dist/DirectoryTree.d.ts +2 -21
  2. package/dist/DirectoryTreeGrid.d.ts +3 -17
  3. package/dist/TreeLine.d.ts +2 -8
  4. package/dist/cli.server.d.ts +0 -1
  5. package/dist/entryRendering.d.ts +2 -42
  6. package/dist/gridUtils.d.ts +1 -30
  7. package/dist/index.cjs +2 -2
  8. package/dist/index.d.ts +3 -14
  9. package/dist/index.js +101 -101
  10. package/dist/logger.d.ts +0 -63
  11. package/dist/scrollAnchor.d.ts +0 -28
  12. package/dist/styles/directory-tree.standalone.css +1 -1
  13. package/dist/types.d.ts +3 -497
  14. package/dist/useDirectoryTreeState.d.ts +1 -14
  15. package/dist/useEntryInteraction.d.ts +2 -8
  16. package/package.json +6 -7
  17. package/dist/DirectoryTree.d.ts.map +0 -1
  18. package/dist/DirectoryTreeGrid.d.ts.map +0 -1
  19. package/dist/TreeLine.d.ts.map +0 -1
  20. package/dist/cli.server.d.ts.map +0 -1
  21. package/dist/entryRendering.d.ts.map +0 -1
  22. package/dist/gridUtils.d.ts.map +0 -1
  23. package/dist/index.d.ts.map +0 -1
  24. package/dist/logger.d.ts.map +0 -1
  25. package/dist/scrollAnchor.d.ts.map +0 -1
  26. package/dist/types.d.ts.map +0 -1
  27. package/dist/useDirectoryTreeState.d.ts.map +0 -1
  28. package/dist/useEntryInteraction.d.ts.map +0 -1
  29. package/src/DirectoryTree.tsx +0 -1257
  30. package/src/DirectoryTreeGrid.tsx +0 -285
  31. package/src/TreeLine.tsx +0 -300
  32. package/src/cli.server.ts +0 -38
  33. package/src/entryRendering.tsx +0 -299
  34. package/src/gridUtils.ts +0 -88
  35. package/src/index.ts +0 -32
  36. package/src/logger.ts +0 -162
  37. package/src/scrollAnchor.spec.ts +0 -105
  38. package/src/scrollAnchor.ts +0 -86
  39. package/src/styles/components.entry.css +0 -10
  40. package/src/styles/directory-tree.css +0 -87
  41. package/src/styles/standalone.entry.css +0 -12
  42. package/src/types.ts +0 -761
  43. package/src/useDirectoryTreeState.ts +0 -133
  44. package/src/useEntryInteraction.ts +0 -74
  45. package/src/virtualScrollOptionsSeal.spec.ts +0 -43
@@ -1,105 +0,0 @@
1
- /**
2
- * Unit tests for the scroll-anchor pure helpers.
3
- * スクロールアンカー純関数ヘルパーの単体テスト。
4
- */
5
- import { describe, expect, it } from "vitest"
6
- import { type AnchorableItem, captureScrollAnchor, resolveAnchorScroll } from "./scrollAnchor.ts"
7
-
8
- /** 均一 28px 行のテストデータを生成する */
9
- const buildItems = (paths: string[]): { items: AnchorableItem[]; offsets: number[] } => {
10
- const items = paths.map((path) => ({ entry: { absolutePath: path } }))
11
- const offsets = new Array<number>(paths.length + 1)
12
- offsets[0] = 0
13
- for (let index = 0; index < paths.length; index++) {
14
- offsets[index + 1] = offsets[index] + 28
15
- }
16
- return { items, offsets }
17
- }
18
-
19
- describe("captureScrollAnchor", () => {
20
- it("should return null at the top of the list (natural streaming view)", () => {
21
- const { items, offsets } = buildItems(["/a", "/b", "/c"])
22
- expect(captureScrollAnchor(items, offsets, 0)).toBeNull()
23
- expect(captureScrollAnchor(items, offsets, -5)).toBeNull()
24
- })
25
-
26
- it("should return null for an empty list or mismatched offsets", () => {
27
- expect(captureScrollAnchor([], [0], 100)).toBeNull()
28
- const { items } = buildItems(["/a"])
29
- expect(captureScrollAnchor(items, [0], 100)).toBeNull()
30
- })
31
-
32
- it("should capture the first visible row with its in-viewport offset", () => {
33
- const { items, offsets } = buildItems(["/a", "/b", "/c", "/d"])
34
- // 60px = 行 2 (/c, 上端 56px) の途中 4px まで見えている
35
- const anchor = captureScrollAnchor(items, offsets, 60)
36
- expect(anchor).toEqual({ path: "/c", offsetInViewport: 4 })
37
- })
38
-
39
- it("should capture a row boundary exactly at its top", () => {
40
- const { items, offsets } = buildItems(["/a", "/b", "/c"])
41
- const anchor = captureScrollAnchor(items, offsets, 28)
42
- expect(anchor).toEqual({ path: "/b", offsetInViewport: 0 })
43
- })
44
-
45
- it("should clamp to the last row when scrolled past the end", () => {
46
- const { items, offsets } = buildItems(["/a", "/b"])
47
- const anchor = captureScrollAnchor(items, offsets, 999)
48
- expect(anchor?.path).toBe("/b")
49
- })
50
- })
51
-
52
- describe("resolveAnchorScroll", () => {
53
- it("should keep the anchored row stationary when rows are inserted above it", () => {
54
- const before = buildItems(["/a", "/b", "/c", "/d"])
55
- const anchor = captureScrollAnchor(before.items, before.offsets, 60)
56
- expect(anchor?.path).toBe("/c")
57
-
58
- // /c の上に 2 行挿入される (ストリーミング追記を模擬)
59
- const after = buildItems(["/a", "/x", "/y", "/b", "/c", "/d"])
60
- const nextScroll = resolveAnchorScroll(anchor as NonNullable<typeof anchor>, after.items, after.offsets)
61
-
62
- // /c の新しい上端 (4 * 28 = 112) + viewport 内オフセット 4
63
- expect(nextScroll).toBe(116)
64
- })
65
-
66
- it("should return the same position when nothing changed above the anchor", () => {
67
- const { items, offsets } = buildItems(["/a", "/b", "/c", "/d"])
68
- const anchor = captureScrollAnchor(items, offsets, 60)
69
- const nextScroll = resolveAnchorScroll(anchor as NonNullable<typeof anchor>, items, offsets)
70
- expect(nextScroll).toBe(60)
71
- })
72
-
73
- it("should return null when the anchored row no longer exists", () => {
74
- const before = buildItems(["/a", "/b", "/c"])
75
- const anchor = captureScrollAnchor(before.items, before.offsets, 60)
76
- const after = buildItems(["/a", "/b"])
77
- expect(resolveAnchorScroll(anchor as NonNullable<typeof anchor>, after.items, after.offsets)).toBeNull()
78
- })
79
-
80
- it("should never return a negative scroll position", () => {
81
- const anchor = { path: "/a", offsetInViewport: -10 }
82
- const after = buildItems(["/a", "/b"])
83
- expect(resolveAnchorScroll(anchor, after.items, after.offsets)).toBe(0)
84
- })
85
-
86
- it("should return null for an empty or mismatched new list", () => {
87
- const anchor = { path: "/a", offsetInViewport: 0 }
88
- expect(resolveAnchorScroll(anchor, [], [0])).toBeNull()
89
- const { items } = buildItems(["/a"])
90
- expect(resolveAnchorScroll(anchor, items, [0])).toBeNull()
91
- })
92
-
93
- it("should keep variable-height rows stationary (non-uniform offsets)", () => {
94
- // 可変高さ: /a=40, /b=20, /c=60
95
- const beforeItems: AnchorableItem[] = [{ entry: { absolutePath: "/a" } }, { entry: { absolutePath: "/b" } }, { entry: { absolutePath: "/c" } }]
96
- const beforeOffsets = [0, 40, 60, 120]
97
- const anchor = captureScrollAnchor(beforeItems, beforeOffsets, 65)
98
- expect(anchor).toEqual({ path: "/c", offsetInViewport: 5 })
99
-
100
- // /c の上に高さ 100 の行が入る
101
- const afterItems: AnchorableItem[] = [{ entry: { absolutePath: "/a" } }, { entry: { absolutePath: "/x" } }, { entry: { absolutePath: "/b" } }, { entry: { absolutePath: "/c" } }]
102
- const afterOffsets = [0, 40, 140, 160, 220]
103
- expect(resolveAnchorScroll(anchor as NonNullable<typeof anchor>, afterItems, afterOffsets)).toBe(165)
104
- })
105
- })
@@ -1,86 +0,0 @@
1
- /**
2
- * Pure helpers for preserving the visual scroll anchor across row-list mutations.
3
- * 行リストの変異を跨いで視覚的スクロールアンカーを保持するための純関数ヘルパーモジュール。
4
- *
5
- * ストリーミング追記などで viewport より上に行が挿入されると、ピクセル位置を維持する
6
- * 通常のスクロールでは表示内容が下へずれる。本モジュールは「変更前の先頭可視行」を
7
- * アンカーとして捕捉し、変更後の行リスト内で同じ行が同じ画面位置に来るスクロール量を
8
- * 算出する。副作用を持たないため単体テストで全経路を検証できる。
9
- */
10
-
11
- /** アンカー捕捉に必要な最小の行形状 (構造的部分型) */
12
- export type AnchorableItem = {
13
- entry: { absolutePath: string }
14
- }
15
-
16
- /** 捕捉されたスクロールアンカー */
17
- export type ScrollAnchor = {
18
- /** 変更前の先頭可視行のパス */
19
- path: string
20
- /** 行上端から viewport 上端までのピクセル差 (行の途中まで見えている量) */
21
- offsetInViewport: number
22
- }
23
-
24
- /**
25
- * Binary-searches a cumulative offset table for the item covering a pixel position.
26
- * 累積オフセット表を二分探索し、指定ピクセル位置を含むアイテムのインデックスを返す処理。
27
- */
28
- const findItemIndexAtOffset = (offsets: number[], position: number): number => {
29
- const itemCount = offsets.length - 1
30
- if (itemCount <= 0) return 0
31
- let low = 0
32
- let high = itemCount - 1
33
- let result = 0
34
- while (low <= high) {
35
- const mid = (low + high) >>> 1
36
- if (offsets[mid] <= position) {
37
- result = mid
38
- low = mid + 1
39
- } else {
40
- high = mid - 1
41
- }
42
- }
43
- return result
44
- }
45
-
46
- /**
47
- * Captures the first visible row as a scroll anchor (null when anchoring is unnecessary).
48
- * 先頭可視行をスクロールアンカーとして捕捉する処理 (アンカー不要時は null)。
49
- *
50
- * scrollPosition が 0 以下 (最上部) の場合は「先頭に張り付いて新着を眺める」挙動が
51
- * 自然なため、意図的にアンカーしない。
52
- */
53
- export const captureScrollAnchor = (items: ReadonlyArray<AnchorableItem>, offsets: number[], scrollPosition: number): ScrollAnchor | null => {
54
- if (scrollPosition <= 0 || items.length === 0 || offsets.length !== items.length + 1) {
55
- return null
56
- }
57
- const index = findItemIndexAtOffset(offsets, scrollPosition)
58
- const item = items[index]
59
- if (!item) {
60
- return null
61
- }
62
- return {
63
- path: item.entry.absolutePath,
64
- offsetInViewport: scrollPosition - offsets[index],
65
- }
66
- }
67
-
68
- /**
69
- * Resolves the scroll position that keeps the anchored row visually stationary in the new list.
70
- * 新しい行リスト内でアンカー行を同じ画面位置に保つスクロール量を解決する処理。
71
- *
72
- * アンカー行が新リストに存在しない場合 (折りたたみ・フィルタで消えた等) は null を返し、
73
- * 呼び出し側は補正を行わない (ピクセル位置維持のフォールバック)。
74
- */
75
- export const resolveAnchorScroll = (anchor: ScrollAnchor, items: ReadonlyArray<AnchorableItem>, offsets: number[]): number | null => {
76
- if (items.length === 0 || offsets.length !== items.length + 1) {
77
- return null
78
- }
79
- // パス一致検索は O(n) だが、呼び出し頻度はスナップショット到達時のみ (スロットル済) のため許容
80
- for (let index = 0; index < items.length; index++) {
81
- if (items[index].entry.absolutePath === anchor.path) {
82
- return Math.max(0, offsets[index] + anchor.offsetInViewport)
83
- }
84
- }
85
- return null
86
- }
@@ -1,10 +0,0 @@
1
- /*
2
- * Artifact A: components-only CSS (Tailwind ホスト向け).
3
- * 手書き .dt-* コンポーネントクラスのみ。virtualscroll CSS は埋め込まない
4
- * (ホストが @aiquants/virtualscroll の Artifact A を別途 import するため。二重同梱を回避)。
5
- * :root テーマ変数・ユーティリティ・preflight を含まない。
6
- */
7
- @import "tailwindcss/theme.css" theme(reference);
8
- @layer components {
9
- @import "./directory-tree.css";
10
- }
@@ -1,87 +0,0 @@
1
- /* ===== TreeGrid (columns) mode ===== */
2
- /* Frozen name column on the left; numeric columns scroll horizontally via the shared
3
- --dt-hscroll custom property. Header / body rows / footer all read the same variable so
4
- they stay perfectly aligned without any per-row React re-render.
5
- 左に凍結した名前列、数値列は共有変数 --dt-hscroll で横スクロール。ヘッダ/本体/フッタが同一変数を
6
- 参照するため、行の再レンダー無しで整列を保つ。 */
7
-
8
- .dt-grid {
9
- position: relative;
10
- display: flex;
11
- flex-direction: column;
12
- }
13
-
14
- /* The virtualized body region. Its height (not the whole container's) is what the viewport
15
- measurement must use, so header/footer are excluded. / 計測対象はこの本体領域の高さ。 */
16
- .dt-grid-body {
17
- position: relative;
18
- flex: 1 1 0%;
19
- min-height: 0;
20
- }
21
-
22
- .dt-grid-header,
23
- .dt-grid-footer,
24
- .dt-grid-row,
25
- .dt-grid-hscrollbar-row {
26
- display: flex;
27
- align-items: stretch;
28
- }
29
-
30
- /* Frozen name cell/header/footer: fixed width, above the numeric track (z-index), clips its
31
- own overflow. / 凍結名前セル: 固定幅・数値トラックより前面・自身をクリップ。 */
32
- .dt-grid-name-cell,
33
- .dt-grid-name-header,
34
- .dt-grid-name-footer {
35
- position: relative;
36
- z-index: 1;
37
- flex-shrink: 0;
38
- display: flex;
39
- align-items: center;
40
- overflow: hidden;
41
- }
42
-
43
- /* Scrollable numeric region: a per-element viewport clips the translated track's overflow on
44
- both sides (so it never slides under the frozen name cell). / 行ごとのビューポートで両端クリップ。 */
45
- .dt-grid-numeric-viewport {
46
- position: relative;
47
- flex: 1 1 0%;
48
- overflow: hidden;
49
- }
50
-
51
- .dt-grid-numeric-track {
52
- display: grid;
53
- transform: translateX(calc(-1 * var(--dt-hscroll, 0px)));
54
- will-change: transform;
55
- }
56
-
57
- .dt-grid-cell {
58
- display: flex;
59
- align-items: center;
60
- padding: 0 8px;
61
- overflow: hidden;
62
- white-space: nowrap;
63
- text-overflow: ellipsis;
64
- }
65
-
66
- /* Right-aligned / centered numeric cells. / 右寄せ・中央寄せセル。 */
67
- .dt-grid-cell--right {
68
- justify-content: flex-end;
69
- text-align: right;
70
- }
71
-
72
- .dt-grid-cell--center {
73
- justify-content: center;
74
- text-align: center;
75
- }
76
-
77
- .dt-grid-name-label {
78
- overflow: hidden;
79
- white-space: nowrap;
80
- text-overflow: ellipsis;
81
- }
82
-
83
- /* Fixed-width spacers used to keep the horizontal scrollbar aligned with the numeric viewport
84
- (left = name width, right = vertical scrollbar width). / 横バー整合用スペーサ。 */
85
- .dt-grid-scrollbar-spacer {
86
- flex-shrink: 0;
87
- }
@@ -1,12 +0,0 @@
1
- /*! @aiquants/directory-tree standalone CSS — 非 Tailwind ホスト専用。ホストの Tailwind ビルドと混在させないこと */
2
- /*
3
- * Artifact B: 自己完結スタンドアロン. 非 Tailwind ホストの利便のため peer の
4
- * @aiquants/virtualscroll CSS も同梱する (Tailwind ホストは Artifact A を使うので二重にならない)。
5
- */
6
- @layer theme, base, components, utilities;
7
- @import "tailwindcss/theme.css" layer(theme);
8
- @import "tailwindcss/utilities.css" layer(utilities) source(none);
9
- @import "@aiquants/virtualscroll/styles/virtualscroll.css" layer(components);
10
- @import "./directory-tree.css" layer(components);
11
- @source "../**/*.{ts,tsx}";
12
- @custom-variant dark (&:where(.dark, .dark *));