@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,133 +0,0 @@
1
- import { useCallback, useEffect, useState, useTransition } from "react"
2
- import type { DirectoryTreeState, UseDirectoryTreeStateProps } from "./types"
3
-
4
- /**
5
- * A React hook for managing the state of a directory tree.
6
- * ディレクトリツリーの状態を管理するための React フック。
7
- *
8
- * This hook is designed to work with Server-Side Rendering (SSR) by allowing
9
- * the initial expansion state to be passed in as a prop.
10
- * このフックは、初期の展開状態をプロパティとして渡すことで、
11
- * サーバーサイドレンダリング (SSR) と連携するように設計されています。
12
- *
13
- * @param props - The properties for the hook.
14
- * @returns The state and actions for the directory tree.
15
- */
16
- export const useDirectoryTreeState = ({ initialExpanded = new Set<string>(), storageKey }: UseDirectoryTreeStateProps = {}): DirectoryTreeState => {
17
- const [isPending, startTransition] = useTransition()
18
- const [expanded, setExpanded] = useState(() => {
19
- if (typeof window !== "undefined" && storageKey) {
20
- try {
21
- const item = window.localStorage.getItem(storageKey)
22
- if (item) {
23
- const parsedItem = JSON.parse(item)
24
- return new Set<string>(parsedItem)
25
- }
26
- } catch (error) {
27
- console.error("[useDirectoryTreeState] Error reading from localStorage", error)
28
- }
29
- }
30
- return initialExpanded
31
- })
32
-
33
- const runTransition = useCallback((update: (next: Set<string>) => void) => {
34
- startTransition(() => {
35
- setExpanded((prev) => {
36
- const next = new Set(prev)
37
- update(next)
38
- return next
39
- })
40
- })
41
- }, [])
42
-
43
- const mutatePaths = useCallback(
44
- (paths: Iterable<string>, modifier: (next: Set<string>, path: string) => void) => {
45
- runTransition((next) => {
46
- for (const path of paths) {
47
- modifier(next, path)
48
- }
49
- })
50
- },
51
- [runTransition],
52
- )
53
-
54
- // 展開状態を localStorage に同期する副作用。expanded と storageKey の変化時に発火。
55
- useEffect(() => {
56
- if (storageKey && typeof window !== "undefined") {
57
- try {
58
- window.localStorage.setItem(storageKey, JSON.stringify(Array.from(expanded)))
59
- } catch (error) {
60
- console.warn(`Error setting localStorage key "${storageKey}":`, error)
61
- }
62
- }
63
- }, [expanded, storageKey])
64
-
65
- const toggle = useCallback(
66
- (path: string) => {
67
- mutatePaths([path], (next, current) => {
68
- if (next.has(current)) {
69
- next.delete(current)
70
- } else {
71
- next.add(current)
72
- }
73
- })
74
- },
75
- [mutatePaths],
76
- )
77
-
78
- const expand = useCallback(
79
- (path: string) => {
80
- mutatePaths([path], (next, current) => {
81
- next.add(current)
82
- })
83
- },
84
- [mutatePaths],
85
- )
86
-
87
- const collapse = useCallback(
88
- (path: string) => {
89
- mutatePaths([path], (next, current) => {
90
- next.delete(current)
91
- })
92
- },
93
- [mutatePaths],
94
- )
95
-
96
- const collapseMultiple = useCallback(
97
- (paths: string[]) => {
98
- mutatePaths(paths, (next, current) => {
99
- next.delete(current)
100
- })
101
- },
102
- [mutatePaths],
103
- )
104
-
105
- const expandMultiple = useCallback(
106
- (paths: string[]) => {
107
- mutatePaths(paths, (next, current) => {
108
- next.add(current)
109
- })
110
- },
111
- [mutatePaths],
112
- )
113
-
114
- const collapseAll = useCallback(() => {
115
- runTransition((next) => {
116
- next.clear()
117
- })
118
- }, [runTransition])
119
-
120
- const isExpanded = useCallback((path: string) => expanded.has(path), [expanded])
121
-
122
- return {
123
- expanded,
124
- toggle,
125
- expand,
126
- collapse,
127
- collapseMultiple,
128
- expandMultiple,
129
- collapseAll,
130
- isExpanded,
131
- isPending,
132
- }
133
- }
@@ -1,74 +0,0 @@
1
- /**
2
- * @module useEntryInteraction
3
- * @description Shared click / double-click / selection handling for a directory entry row.
4
- * Used by both the classic label row (DirectoryEntryItem) and the TreeGrid row
5
- * (DirectoryTreeGridRow) so the interaction semantics stay identical.
6
- * 単一クリック/ダブルクリック/選択の共通ハンドラ。従来行と TreeGrid 行で共有する。
7
- */
8
- import type { MouseEvent } from "react"
9
- import { useCallback, useEffect, useRef } from "react"
10
- import type { DirectoryEntry, DirectoryTreeClickEvent } from "./types.ts"
11
-
12
- /** Delay (ms) distinguishing a single click (toggle) from a double click (recursive). / 単/ダブルクリック判定の遅延。 */
13
- const DOUBLE_CLICK_DELAY_MS = 500
14
-
15
- export type UseEntryInteractionArgs = {
16
- entry: DirectoryEntry
17
- isDirectory: boolean
18
- isExpanded: boolean
19
- isItemSelected: boolean
20
- selectionMode: "none" | "single" | "multiple"
21
- onSelectionChange?: (entry: DirectoryEntry, isSelected: boolean) => void
22
- onEntryClick: (event: DirectoryTreeClickEvent) => void
23
- toggleDirectory: (path: string) => void
24
- onToggleDirectoryRecursive: (entry: DirectoryEntry) => void
25
- }
26
-
27
- /**
28
- * Returns a click handler implementing: fire onEntryClick immediately; for files toggle
29
- * selection; for directories, single click toggles (after a delay) and double click expands
30
- * recursively — unless the consumer calls preventDefault() on the click event.
31
- */
32
- export const useEntryInteraction = ({ entry, isDirectory, isExpanded, isItemSelected, selectionMode, onSelectionChange, onEntryClick, toggleDirectory, onToggleDirectoryRecursive }: UseEntryInteractionArgs) => {
33
- const clickTimer = useRef<number | null>(null)
34
-
35
- useEffect(
36
- () => () => {
37
- if (clickTimer.current) window.clearTimeout(clickTimer.current)
38
- },
39
- [],
40
- )
41
-
42
- return useCallback(
43
- (e: MouseEvent<HTMLDivElement>) => {
44
- e.stopPropagation()
45
- if (selectionMode !== "none" && !isDirectory && onSelectionChange) {
46
- onSelectionChange(entry, !isItemSelected)
47
- }
48
-
49
- let defaultPrevented = false
50
- onEntryClick({
51
- entry,
52
- isDirectory,
53
- isExpanded,
54
- preventDefault: () => {
55
- defaultPrevented = true
56
- },
57
- })
58
-
59
- if (!isDirectory || defaultPrevented) return
60
-
61
- if (clickTimer.current) {
62
- window.clearTimeout(clickTimer.current)
63
- clickTimer.current = null
64
- onToggleDirectoryRecursive(entry)
65
- } else {
66
- clickTimer.current = window.setTimeout(() => {
67
- toggleDirectory(entry.absolutePath)
68
- clickTimer.current = null
69
- }, DOUBLE_CLICK_DELAY_MS)
70
- }
71
- },
72
- [isDirectory, entry, isExpanded, onToggleDirectoryRecursive, toggleDirectory, onEntryClick, selectionMode, onSelectionChange, isItemSelected],
73
- )
74
- }
@@ -1,43 +0,0 @@
1
- /**
2
- * @fileoverview Consumer-perspective seal test for `DirectoryTreeVirtualScrollOptions`.
3
- * DirectoryTree owns the horizontal axis internally, so the ENTIRE horizontal seam of
4
- * VirtualScroll (`onWheelHorizontal` + the keyboard pair `horizontalKeyInputs` /
5
- * `horizontalKeyStep` added at the top level in virtualscroll 2.5.0) must be sealed by
6
- * the `Omit<>`. These assignments compile-fail on purpose: if a seal is ever dropped, the
7
- * `@ts-expect-error` itself errors ("unused directive", TS2578) and `tsc --noEmit` goes
8
- * red. This only works because `tsconfig.json` includes spec/test files in type checking
9
- * (the former exclusion of spec/test file patterns made in-test type guards vacuous —
10
- * proven by mutation, and removed in 3.10.0). The definition-adjacent counterpart is
11
- * `HorizontalSeamSealGuard` in `types.ts`, which pins the `Omit<>` list itself.
12
- *
13
- * `DirectoryTreeVirtualScrollOptions` の封印の消費者視点テスト。DirectoryTree は横軸を
14
- * 自前で所有するため、VirtualScroll の横軸シーム全体 (`onWheelHorizontal` + 2.5.0 で
15
- * トップレベルに追加されたキーボード対 `horizontalKeyInputs` / `horizontalKeyStep`) を
16
- * `Omit<>` が封じていなければならない。封印が外れると `@ts-expect-error` が「未使用
17
- * ディレクティブ」(TS2578) になり `tsc --noEmit` が赤くなる仕組み。これが機能するのは
18
- * `tsconfig.json` が spec / test ファイルを型検査対象に含めているからであり (3.10.0 で
19
- * exclude を撤去)、定義側の対は `types.ts` の `HorizontalSeamSealGuard` が受け持つ。
20
- */
21
-
22
- import { describe, expect, it } from "vitest"
23
- import type { DirectoryTreeVirtualScrollOptions } from "./types.ts"
24
-
25
- describe("DirectoryTreeVirtualScrollOptions - 横軸シームの封印 (型レベル)", () => {
26
- it("封じた 3 props は型エラーになり、封じていない props は通る", () => {
27
- // @ts-expect-error onWheelHorizontal は封印済み (横軸は DirectoryTree が所有する)
28
- const sealedWheel: DirectoryTreeVirtualScrollOptions = { onWheelHorizontal: () => {} }
29
- // @ts-expect-error horizontalKeyInputs は封印済み (キーボード経由の横軸到達と Arrow 競合を防ぐ)
30
- const sealedInputs: DirectoryTreeVirtualScrollOptions = { horizontalKeyInputs: ["arrow"] }
31
- // @ts-expect-error horizontalKeyStep は封印済み (同上)
32
- const sealedStep: DirectoryTreeVirtualScrollOptions = { horizontalKeyStep: 40 }
33
-
34
- // 封じていない props は従来どおり受け付ける (封印が広すぎないことの陽性コントロール)
35
- const open: DirectoryTreeVirtualScrollOptions = {
36
- overscanCount: 10,
37
- behaviorOptions: { wheelSpeedMultiplier: 2, overscrollBehavior: "contain" },
38
- }
39
-
40
- // ランタイム assert は形式上のもの (実体は tsc --noEmit の型検査が担う)
41
- expect([sealedWheel, sealedInputs, sealedStep, open].length).toBe(4)
42
- })
43
- })