@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,299 +0,0 @@
1
- /**
2
- * @module entryRendering
3
- * @description Shared constants, class names and icon-resolution helpers used by both the classic
4
- * label row (DirectoryEntryItem) and the TreeGrid row (DirectoryTreeGridRow).
5
- * Extracted from DirectoryTree.tsx so the two row renderers can share them without a
6
- * circular import.
7
- * 従来行と TreeGrid 行が共有する定数・クラス・アイコン解決ヘルパ。循環 import 回避のため分離。
8
- */
9
- import ChevronDownIcon from "@heroicons/react/24/solid/ChevronDownIcon.js"
10
- import ChevronRightIcon from "@heroicons/react/24/solid/ChevronRightIcon.js"
11
- import FolderIcon from "@heroicons/react/24/solid/FolderIcon.js"
12
- import { FileAudio, FileCode, FileCsv, FileDoc, FileIcon, FileImage, FileMd, FilePdf, FilePpt, FileText, FileVideo, FileXls, FileZip } from "@phosphor-icons/react"
13
- import type { ReactNode } from "react"
14
- import { twMerge } from "tailwind-merge"
15
- import type { DirectoryTreeIconOverrides, DirectoryTreeIconRenderContext, DirectoryTreeIconRenderer } from "./types.ts"
16
-
17
- /** Default row height in px. / 各行の高さの既定値 (px)。 FHD環境に最適化されたコンパクト設計 (18px) */
18
- export const DEFAULT_ITEM_HEIGHT = 18
19
- /** Indentation per depth level in px. / 1 階層あたりのインデント幅 (px)。 FHD環境に最適化されたコンパクト設計 (12px) */
20
- export const INDENT_SIZE = 12
21
- /** Standard expand glyph size. / 展開アイコンの標準サイズ (8px)。 */
22
- export const EXPAND_GLYPH_SIZE = 8
23
-
24
- /**
25
- * TailwindCSS v4 class names for DirectoryTree component.
26
- * DirectoryTreeコンポーネント用の TailwindCSS v4 クラス名。
27
- */
28
- export const directoryTreeClasses = {
29
- container: "directory-tree-container relative h-full transition-opacity duration-300 overflow-y-hidden pb-[3px] pr-[2px]",
30
- containerPending: "opacity-70",
31
-
32
- entry: "directory-tree-entry flex items-center cursor-pointer relative select-none text-xs leading-tight py-0.5",
33
-
34
- // ホバー時のスタイル(ライト/ダークモード対応)
35
- entryHover: twMerge("directory-tree-entry--hover hover:bg-gray-400/15", "dark:hover:bg-gray-200/10"),
36
-
37
- // 選択時のスタイル(ライト/ダークモード対応)
38
- entrySelected: twMerge("directory-tree-entry--selected bg-blue-400/10", "dark:bg-blue-400/15"),
39
-
40
- // アイテム選択時のスタイル(ライト/ダークモード対応)
41
- entryItemSelected: 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)]"),
42
-
43
- // アイコンのスタイル
44
- expandIcon: twMerge("directory-tree-expand-icon w-3.5 h-3.5 flex-shrink-0 flex items-center justify-center", "text-gray-500", "dark:text-gray-400"),
45
-
46
- expandIconSelected: twMerge("directory-tree-expand-icon--selected text-blue-700", "dark:text-blue-400"),
47
-
48
- typeIcon: twMerge("directory-tree-type-icon w-3.5 h-3.5 flex-shrink-0 flex items-center justify-center", "text-gray-500", "dark:text-gray-400"),
49
-
50
- typeIconSelected: twMerge("directory-tree-type-icon--selected text-blue-700", "dark:text-blue-400"),
51
-
52
- // テキストのスタイル
53
- name: twMerge("directory-tree-name overflow-hidden text-ellipsis whitespace-nowrap ml-1 text-xs font-normal", "text-gray-700", "dark:text-gray-200"),
54
-
55
- nameDirectory: "directory-tree-name--directory font-medium",
56
-
57
- nameSelected: twMerge("directory-tree-name--selected text-blue-800 font-semibold", "dark:text-blue-300"),
58
- }
59
-
60
- /**
61
- * @function getFileExtension
62
- * @description Extracts the extension from a filename. / ファイル名から拡張子を抽出する。
63
- */
64
- export const getFileExtension = (filename: string): string => {
65
- if (!filename) return ""
66
- const cleanName = filename.split("?")[0].split("#")[0].split("/").pop() || filename
67
- const lastDot = cleanName.lastIndexOf(".")
68
- if (lastDot <= 0) return ""
69
- return cleanName.slice(lastDot + 1).toLowerCase()
70
- }
71
-
72
- export type ExpandIconParams = {
73
- isDirectory: boolean
74
- isExpanded: boolean
75
- showExpandIcons: boolean
76
- useCanvasExpandIcons: boolean
77
- expandIconSize?: number
78
- }
79
-
80
- /**
81
- * @function resolveExpandIcon
82
- * @description Determines the expand icon node for a directory entry. / 展開アイコンノードを決定する。
83
- */
84
- export const resolveExpandIcon = ({ isDirectory, isExpanded, showExpandIcons, useCanvasExpandIcons, expandIconSize }: ExpandIconParams): ReactNode => {
85
- const style = expandIconSize ? { width: expandIconSize, height: expandIconSize } : undefined
86
- const className = expandIconSize ? "" : "h-4 w-4"
87
-
88
- if (!(showExpandIcons && isDirectory) || useCanvasExpandIcons) {
89
- return <span className={className} style={style} aria-hidden="true" />
90
- }
91
- return isExpanded ? <ChevronDownIcon className={className} style={style} /> : <ChevronRightIcon className={className} style={style} />
92
- }
93
-
94
- /**
95
- * Resolves a directory tree icon renderer into a ReactNode.
96
- * ディレクトリツリーのアイコン描画設定を ReactNode に解決する関数。
97
- */
98
- const sanitizeIcon = (node: unknown, path: string): ReactNode | null => {
99
- if (node === null || node === undefined || typeof node === "boolean") return null
100
- if (typeof node === "function") {
101
- console.warn(`[DirectoryTree] Function returned by renderer for "${path}". Return a node.`)
102
- return null
103
- }
104
- if (typeof node === "object") {
105
- if ("then" in node) {
106
- console.warn(`[DirectoryTree] Promise returned for "${path}". Not supported.`)
107
- return null
108
- }
109
- if (Array.isArray(node)) {
110
- const kids = node.map((c) => sanitizeIcon(c, path)).filter(Boolean)
111
- return kids.length ? kids : null
112
- }
113
- const type = (node as { type?: { $$typeof?: symbol } }).type
114
- if (type && type.$$typeof === Symbol.for("react.lazy")) {
115
- console.warn(`[DirectoryTree] Lazy component for "${path}". Not supported.`)
116
- return null
117
- }
118
- }
119
- return node as ReactNode
120
- }
121
-
122
- /**
123
- * Resolves a file icon based on mimeType (primary) > extension (fallback).
124
- * mimeType (最優先) > 拡張子 (フォールバック) の順序でファイルアイコンを解決する。
125
- */
126
- export const getFileIconByMimeOrExtension = (mimeType?: string, extension?: string, filename?: string): ReactNode => {
127
- const cleanExt = (extension || (filename ? getFileExtension(filename) : "")).toLowerCase()
128
- const cleanMime = (mimeType || "").toLowerCase()
129
-
130
- // 1. MimeType 判断 (最優先、汎用 octet-stream 以外)
131
- if (cleanMime && cleanMime !== "application/octet-stream") {
132
- // Markdown
133
- if (cleanMime === "text/markdown" || cleanMime === "text/x-markdown") {
134
- return <FileMd className="h-4 w-4 text-sky-500 dark:text-sky-400" />
135
- }
136
- // PDF
137
- if (cleanMime === "application/pdf") {
138
- return <FilePdf className="h-4 w-4 text-red-500 dark:text-red-400" />
139
- }
140
- // Excel / 表計算 / CSV / Google Sheets (google-apps.spreadsheet)
141
- if (cleanMime.includes("excel") || cleanMime.includes("spreadsheet") || cleanMime.includes("google-apps.spreadsheet")) {
142
- return <FileXls className="h-4 w-4 text-emerald-600 dark:text-emerald-400" />
143
- }
144
- if (cleanMime === "text/csv" || cleanMime === "text/tab-separated-values") {
145
- return <FileCsv className="h-4 w-4 text-emerald-600 dark:text-emerald-400" />
146
- }
147
- // Word / ドキュメント / Google Docs (google-apps.document)
148
- if (cleanMime.includes("word") || cleanMime.includes("msword") || cleanMime.includes("wordprocessingml") || cleanMime.includes("google-apps.document") || cleanMime === "application/rtf") {
149
- return <FileDoc className="h-4 w-4 text-blue-600 dark:text-blue-400" />
150
- }
151
- // PowerPoint / プレゼンテーション / Google Slides (google-apps.presentation)
152
- if (cleanMime.includes("powerpoint") || cleanMime.includes("presentation") || cleanMime.includes("google-apps.presentation")) {
153
- return <FilePpt className="h-4 w-4 text-orange-500 dark:text-orange-400" />
154
- }
155
- // 画像
156
- if (cleanMime.startsWith("image/")) {
157
- return <FileImage className="h-4 w-4 text-teal-500 dark:text-teal-400" />
158
- }
159
- // 音声
160
- if (cleanMime.startsWith("audio/")) {
161
- return <FileAudio className="h-4 w-4 text-pink-500 dark:text-pink-400" />
162
- }
163
- // 動画
164
- if (cleanMime.startsWith("video/")) {
165
- return <FileVideo className="h-4 w-4 text-violet-500 dark:text-violet-400" />
166
- }
167
- // アーカイブ / 圧縮
168
- if (cleanMime.includes("zip") || cleanMime.includes("tar") || cleanMime.includes("compressed") || cleanMime.includes("archive")) {
169
- return <FileZip className="h-4 w-4 text-amber-500 dark:text-amber-400" />
170
- }
171
- // ソースコード / JSON / HTML / CSS
172
- if (
173
- cleanMime === "application/json" ||
174
- cleanMime.includes("javascript") ||
175
- cleanMime.includes("typescript") ||
176
- cleanMime.includes("xml") ||
177
- cleanMime.startsWith("text/html") ||
178
- cleanMime.startsWith("text/css") ||
179
- cleanMime.includes("x-python") ||
180
- cleanMime.includes("x-sh") ||
181
- cleanMime.includes("x-go") ||
182
- cleanMime.includes("x-rust")
183
- ) {
184
- return <FileCode className="h-4 w-4 text-purple-500 dark:text-purple-400" />
185
- }
186
- // テキスト
187
- if (cleanMime.startsWith("text/")) {
188
- return <FileText className="h-4 w-4 text-gray-500 dark:text-gray-400" />
189
- }
190
- }
191
-
192
- // 2. 拡張子判断 (MimeType が汎用または不在時のフォールバック)
193
- if (cleanExt) {
194
- if (cleanExt === "md" || cleanExt === "markdown" || cleanExt === "mdx") {
195
- return <FileMd className="h-4 w-4 text-sky-500 dark:text-sky-400" />
196
- }
197
- if (cleanExt === "pdf") {
198
- return <FilePdf className="h-4 w-4 text-red-500 dark:text-red-400" />
199
- }
200
- if (["xls", "xlsx", "xlsm", "xlsb", "ods"].includes(cleanExt)) {
201
- return <FileXls className="h-4 w-4 text-emerald-600 dark:text-emerald-400" />
202
- }
203
- if (["csv", "tsv"].includes(cleanExt)) {
204
- return <FileCsv className="h-4 w-4 text-emerald-600 dark:text-emerald-400" />
205
- }
206
- if (["doc", "docx", "rtf", "odt"].includes(cleanExt)) {
207
- return <FileDoc className="h-4 w-4 text-blue-600 dark:text-blue-400" />
208
- }
209
- if (["ppt", "pptx", "odp"].includes(cleanExt)) {
210
- return <FilePpt className="h-4 w-4 text-orange-500 dark:text-orange-400" />
211
- }
212
- if (["png", "jpg", "jpeg", "gif", "svg", "webp", "ico", "bmp", "tiff", "avif"].includes(cleanExt)) {
213
- return <FileImage className="h-4 w-4 text-teal-500 dark:text-teal-400" />
214
- }
215
- if (["js", "mjs", "cjs", "ts", "tsx", "jsx", "json", "html", "htm", "css", "scss", "py", "go", "rs", "c", "cpp", "h", "hpp", "sh", "bash", "yaml", "yml", "sql", "xml", "toml"].includes(cleanExt)) {
216
- return <FileCode className="h-4 w-4 text-purple-500 dark:text-purple-400" />
217
- }
218
- if (["mp3", "wav", "ogg", "m4a", "flac", "aac", "wma"].includes(cleanExt)) {
219
- return <FileAudio className="h-4 w-4 text-pink-500 dark:text-pink-400" />
220
- }
221
- if (["mp4", "webm", "mov", "avi", "mkv", "wmv", "flv"].includes(cleanExt)) {
222
- return <FileVideo className="h-4 w-4 text-violet-500 dark:text-violet-400" />
223
- }
224
- if (["zip", "tar", "gz", "7z", "rar", "tgz", "bz2"].includes(cleanExt)) {
225
- return <FileZip className="h-4 w-4 text-amber-500 dark:text-amber-400" />
226
- }
227
- if (["txt", "log"].includes(cleanExt)) {
228
- return <FileText className="h-4 w-4 text-gray-500 dark:text-gray-400" />
229
- }
230
- }
231
-
232
- // 3. デフォルトファイルアイコン
233
- return <FileIcon className="h-4 w-4 text-gray-400 dark:text-gray-400" />
234
- }
235
-
236
- /**
237
- * Determines the icon to render for a directory entry.
238
- * ディレクトリエントリに表示するアイコンを決定する関数。
239
- */
240
- export const resolveEntryIcon = (ctx: DirectoryTreeIconRenderContext, overrides?: DirectoryTreeIconOverrides): ReactNode => {
241
- const { entry, isDirectory, isExpanded, extension, mimeType } = ctx
242
- let target: ReactNode | DirectoryTreeIconRenderer | undefined
243
-
244
- const effectiveMime = mimeType || entry.mimeType
245
-
246
- if (entry.icon !== undefined) target = entry.icon
247
- else if (isDirectory) target = (isExpanded && overrides?.directoryExpanded) || overrides?.directory || <FolderIcon className="h-4 w-4" />
248
- else if (extension && overrides?.fileByExtension?.[extension]) target = overrides.fileByExtension[extension]
249
- else target = overrides?.file || getFileIconByMimeOrExtension(effectiveMime, extension, entry.name)
250
-
251
- if (typeof target === "function") return sanitizeIcon(target(ctx), entry.absolutePath)
252
- return sanitizeIcon(target, entry.absolutePath)
253
- }
254
-
255
- /**
256
- * @function toKebabCase
257
- * @description Lowercases a key and inserts a dash before each capital that follows a lowercase
258
- * letter or digit, producing the form HTML `data-*` attributes require.
259
- * キーを小文字化し、小文字または数字に続く大文字の前へダッシュを挿入して、
260
- * HTML の `data-*` 属性が要求する形へ変換する。
261
- *
262
- * @remarks これは DOM の `dataset` 逆変換と**同一ではない**。`dataset` は連続する大文字をそれぞれ
263
- * 区切るが、ここでは `aBC` は `a-bc` になる。またこの変換は単射ではなく、`panelCount` と
264
- * `panel-count` は同じ属性名へ落ちる (同一オブジェクト内に両方を書いた場合は後者が勝つ)。
265
- * 実務上のキーは単語境界が明確なため問題にならないが、契約として明記しておく。
266
- *
267
- * @param key - 変換前のキー。
268
- * @returns 属性名として使える小文字ダッシュ区切りのキー。
269
- */
270
- const toKebabCase = (key: string): string => key.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase()
271
-
272
- /**
273
- * @function toDataAttributes
274
- * @description Converts an entry's `data` map into React `data-*` props.
275
- * エントリの `data` マップを React の `data-*` props へ変換する。
276
- *
277
- * キーは `data-` を含めずに受け取り、ここで接頭辞を付ける。値は属性として出力するため文字列化する。
278
- * camelCase のキーは HTML の `dataset` と同じ規約で kebab-case へ変換する
279
- * (`panelCount` → `data-panel-count`)。変換しないと React が属性を落として警告を出すだけで、
280
- * 利用側からは「指定したのに出ない」という無言の失敗に見える。
281
- *
282
- * 呼び出し側はこの結果をコンポーネント自身の `data-entry-*` より**前**に展開すること
283
- * (後勝ちで自前の属性を守るため)。
284
- *
285
- * @param data - エントリの `data` マップ (未指定可)。
286
- * @returns `data-*` をキーとするオブジェクト。`data` が空なら undefined。
287
- */
288
- export const toDataAttributes = (data?: Record<string, string | number | boolean>): Record<string, string> | undefined => {
289
- if (!data) {
290
- return undefined
291
- }
292
- // null / undefined は「属性を出さない」意図として扱う。String() に通すと data-x="undefined" という
293
- // 実在しない状態を DOM へ書き込んでしまい、属性の有無で判定する利用側が誤検知する
294
- const entries = Object.entries(data).filter(([, value]) => value !== null && value !== undefined)
295
- if (entries.length === 0) {
296
- return undefined
297
- }
298
- return Object.fromEntries(entries.map(([key, value]) => [`data-${toKebabCase(key)}`, String(value)]))
299
- }
package/src/gridUtils.ts DELETED
@@ -1,88 +0,0 @@
1
- /**
2
- * @module gridUtils
3
- * @description Pure helpers for the DirectoryTree TreeGrid (columns) mode. Kept free of DOM/React
4
- * so the layout math can be unit-tested in isolation.
5
- * TreeGrid(列)モード用の純粋ヘルパ。DOM/React 非依存で単体テスト可能に保つ。
6
- */
7
- import type { DirectoryEntry, DirectoryTreeColumn } from "./types.ts"
8
-
9
- /** Default frozen width of the name (tree) column in px. / 名前列の既定凍結幅 (px)。 */
10
- export const DEFAULT_NAME_COLUMN_WIDTH = 240
11
- /** Default width of a numeric column in px. / 数値列の既定幅 (px)。 */
12
- export const DEFAULT_NUMERIC_COLUMN_WIDTH = 96
13
- /** Default vertical scrollbar width used to align header/footer with the body. / ヘッダ/フッタ整合用の既定縦バー幅。 */
14
- export const DEFAULT_GRID_SCROLLBAR_WIDTH = 12
15
-
16
- /** Resolves the effective width of a column, applying defaults. / 列の実効幅を既定込みで解決する。 */
17
- const resolveColumnWidth = (column: DirectoryTreeColumn | undefined, fallback: number): number => {
18
- const width = column?.width
19
- return typeof width === "number" && Number.isFinite(width) && width > 0 ? width : fallback
20
- }
21
-
22
- /**
23
- * Builds the `grid-template-columns` string for the numeric (non-name) columns.
24
- * 数値列(columns[1..])の `grid-template-columns` 文字列を構築する。
25
- *
26
- * @returns e.g. `"96px 96px 120px"`. Empty string when there is no numeric column.
27
- */
28
- export const buildNumericTemplate = (columns: DirectoryTreeColumn[]): string =>
29
- columns
30
- .slice(1)
31
- .map((column) => `${resolveColumnWidth(column, DEFAULT_NUMERIC_COLUMN_WIDTH)}px`)
32
- .join(" ")
33
-
34
- /** Metrics describing the frozen/scrollable split of a TreeGrid. / TreeGrid の凍結/可動分割を表す寸法。 */
35
- export type GridMetrics = {
36
- /** Frozen width of the name column. / 名前列の凍結幅。 */
37
- nameWidth: number
38
- /** Total width of all numeric columns (the scrollable content width). / 数値列合計幅(可動コンテンツ幅)。 */
39
- numericTotal: number
40
- /** Visible width of the numeric region (viewport). / 数値領域の可視幅(ビューポート)。 */
41
- numericVisible: number
42
- /** Maximum horizontal scroll offset (>= 0). / 横スクロールの最大オフセット (>= 0)。 */
43
- maxHScroll: number
44
- }
45
-
46
- /**
47
- * Computes the frozen/scrollable layout metrics from the measured container width.
48
- * 計測済みコンテナ幅から凍結/可動レイアウトの寸法を算出する。
49
- *
50
- * `numericVisible = measuredWidth - nameWidth - scrollBarWidth`, clamped to >= 0. This single
51
- * source of truth keeps the body (reduced by the vertical scrollbar) aligned with the
52
- * header/footer (which reserve an equal right-side spacer).
53
- */
54
- export const computeGridMetrics = ({ measuredWidth, columns, scrollBarWidth = DEFAULT_GRID_SCROLLBAR_WIDTH }: { measuredWidth: number; columns: DirectoryTreeColumn[]; scrollBarWidth?: number }): GridMetrics => {
55
- const nameWidth = resolveColumnWidth(columns[0], DEFAULT_NAME_COLUMN_WIDTH)
56
- const numericTotal = columns.slice(1).reduce((sum, column) => sum + resolveColumnWidth(column, DEFAULT_NUMERIC_COLUMN_WIDTH), 0)
57
- const safeWidth = Number.isFinite(measuredWidth) && measuredWidth > 0 ? measuredWidth : 0
58
- const numericVisible = Math.max(0, safeWidth - nameWidth - Math.max(0, scrollBarWidth))
59
- const maxHScroll = Math.max(0, numericTotal - numericVisible)
60
- return { nameWidth, numericTotal, numericVisible, maxHScroll }
61
- }
62
-
63
- /** Clamps a horizontal scroll offset into `[0, maxHScroll]`. / 横スクロール量を [0, maxHScroll] に丸める。 */
64
- export const clampHScroll = (value: number, maxHScroll: number): number => {
65
- if (!Number.isFinite(value)) return 0
66
- if (value < 0) return 0
67
- if (value > maxHScroll) return maxHScroll
68
- return value
69
- }
70
-
71
- /**
72
- * Depth-first flattens every node of the tree **regardless of expansion state** — used to feed
73
- * column footers that total over all entries (including collapsed subtrees).
74
- * 展開状態に依存せず全ノードを DFS で平坦化する。列フッタの全 entries 合計に使用。
75
- */
76
- export const flattenAllEntries = (entries: DirectoryEntry[]): DirectoryEntry[] => {
77
- const result: DirectoryEntry[] = []
78
- const walk = (nodes: DirectoryEntry[]): void => {
79
- for (const node of nodes) {
80
- result.push(node)
81
- if (node.children && node.children.length > 0) {
82
- walk(node.children)
83
- }
84
- }
85
- }
86
- walk(entries)
87
- return result
88
- }
package/src/index.ts DELETED
@@ -1,32 +0,0 @@
1
- /**
2
- * @fileoverview Directory Tree Component Library
3
- * @package @aiquants/directory-tree
4
- *
5
- * This module provides a comprehensive directory tree component for React applications.
6
- * The component supports virtualization for performance, file selection, and theming.
7
- *
8
- * このモジュールは React アプリケーション用の包括的なディレクトリツリーコンポーネントを提供します。
9
- * このコンポーネントはパフォーマンス向上のための仮想化、ファイル選択、およびテーマ設定をサポートしています。
10
- */
11
-
12
- export { DirectoryTree, directoryTreeClasses } from "./DirectoryTree.tsx"
13
- export type {
14
- DirectoryEntry,
15
- DirectoryEntryComparator,
16
- DirectoryEntryItemProps,
17
- DirectoryTreeClickEvent,
18
- DirectoryTreeColumn,
19
- DirectoryTreeGrid,
20
- DirectoryTreeIconOverrides,
21
- DirectoryTreeIconRenderContext,
22
- DirectoryTreeIconRenderer,
23
- DirectoryTreeProps,
24
- DirectoryTreeState,
25
- DirectoryTreeVirtualScrollOptions,
26
- HighlightStyles,
27
- ItemHeight,
28
- TreeLineItemInfo,
29
- TreeLineProps,
30
- UseDirectoryTreeStateProps,
31
- } from "./types.ts"
32
- export { useDirectoryTreeState } from "./useDirectoryTreeState.ts"
package/src/logger.ts DELETED
@@ -1,162 +0,0 @@
1
- /**
2
- * @module utils/logger
3
- * @description Logger utility for consistent log management across the library.
4
- * @description ライブラリ全体で一貫したログ管理を行うためのロガーユーティリティ。
5
- */
6
-
7
- /**
8
- * @enum LogLevel
9
- * @description Log levels for filtering output.
10
- * @description 出力をフィルタリングするためのログレベル。
11
- */
12
- export enum LogLevel {
13
- DEBUG = 0,
14
- INFO = 1,
15
- WARN = 2,
16
- ERROR = 3,
17
- NONE = 4,
18
- }
19
-
20
- /**
21
- * @interface ILogger
22
- * @description Interface for a logger object compatible with Console.
23
- * @description Console と互換性のあるロガーオブジェクトのインターフェース。
24
- */
25
- export interface ILogger {
26
- debug(message?: unknown, ...optionalParams: unknown[]): void
27
- info(message?: unknown, ...optionalParams: unknown[]): void
28
- warn(message?: unknown, ...optionalParams: unknown[]): void
29
- error(message?: unknown, ...optionalParams: unknown[]): void
30
- }
31
-
32
- /**
33
- * @class Logger
34
- * @description A wrapper class for handling logging with levels and prefixes.
35
- * @description レベルとプレフィックスを使用したログ記録を処理するためのラッパークラス。
36
- */
37
- export class Logger implements ILogger {
38
- private level: LogLevel
39
- private prefix: string
40
- private impl: ILogger
41
-
42
- /**
43
- * @constructor
44
- * @param {LogLevel} [level=LogLevel.WARN] - The minimum log level to output.
45
- * @param {string} [prefix="[fuzzy-search]"] - The prefix to add to all log messages.
46
- * @param {ILogger} [impl=console] - The implementation to use for logging.
47
- */
48
- constructor(level: LogLevel = LogLevel.WARN, prefix: string = "[fuzzy-search]", impl: ILogger = console) {
49
- this.level = level
50
- this.prefix = prefix
51
- this.impl = impl
52
- }
53
-
54
- private static instance: Logger = new Logger(LogLevel.WARN, "[fuzzy-search]")
55
-
56
- /**
57
- * @method setLevel
58
- * @description Updates the current log level for the static instance.
59
- * @description 静的インスタンスの現在のログレベルを更新します。
60
- * @param {LogLevel} level - The new log level.
61
- */
62
- static setLevel(level: LogLevel): void {
63
- Logger.instance.setLevel(level)
64
- }
65
-
66
- /**
67
- * @method setLevel
68
- * @description Updates the current log level.
69
- * @description 現在のログレベルを更新します。
70
- * @param {LogLevel} level - The new log level.
71
- */
72
- setLevel(level: LogLevel): void {
73
- this.level = level
74
- }
75
-
76
- /**
77
- * @method setImplementation
78
- * @description Updates the logger implementation for the static instance.
79
- * @description 静的インスタンスのロガーの実装を更新します。
80
- * @param {ILogger} impl - The new logger implementation.
81
- */
82
- static setImplementation(impl: ILogger): void {
83
- Logger.instance.setImplementation(impl)
84
- }
85
-
86
- /**
87
- * @method setImplementation
88
- * @description Updates the logger implementation.
89
- * @description ロガーの実装を更新します。
90
- * @param {ILogger} impl - The new logger implementation.
91
- */
92
- setImplementation(impl: ILogger): void {
93
- this.impl = impl
94
- }
95
-
96
- /**
97
- * @method setPrefix
98
- * @description Updates the log prefix for the static instance.
99
- * @description 静的インスタンスのログのプレフィックスを更新します。
100
- * @param {string} prefix - The new prefix.
101
- */
102
- static setPrefix(prefix: string): void {
103
- Logger.instance.setPrefix(prefix)
104
- }
105
-
106
- /**
107
- * @method setPrefix
108
- * @description Updates the log prefix.
109
- * @description ログのプレフィックスを更新します。
110
- * @param {string} prefix - The new prefix.
111
- */
112
- setPrefix(prefix: string): void {
113
- this.prefix = prefix
114
- }
115
-
116
- private formatMessage(message: unknown): unknown[] {
117
- if (typeof message === "string") {
118
- return [`${this.prefix} ${message}`]
119
- }
120
- return [this.prefix, message]
121
- }
122
-
123
- static debug(message?: unknown, ...optionalParams: unknown[]): void {
124
- Logger.instance.debug(message, ...optionalParams)
125
- }
126
-
127
- debug(message?: unknown, ...optionalParams: unknown[]): void {
128
- if (this.level <= LogLevel.DEBUG) {
129
- this.impl.debug(...this.formatMessage(message), ...optionalParams)
130
- }
131
- }
132
-
133
- static info(message?: unknown, ...optionalParams: unknown[]): void {
134
- Logger.instance.info(message, ...optionalParams)
135
- }
136
-
137
- info(message?: unknown, ...optionalParams: unknown[]): void {
138
- if (this.level <= LogLevel.INFO) {
139
- this.impl.info(...this.formatMessage(message), ...optionalParams)
140
- }
141
- }
142
-
143
- static warn(message?: unknown, ...optionalParams: unknown[]): void {
144
- Logger.instance.warn(message, ...optionalParams)
145
- }
146
-
147
- warn(message?: unknown, ...optionalParams: unknown[]): void {
148
- if (this.level <= LogLevel.WARN) {
149
- this.impl.warn(...this.formatMessage(message), ...optionalParams)
150
- }
151
- }
152
-
153
- static error(message?: unknown, ...optionalParams: unknown[]): void {
154
- Logger.instance.error(message, ...optionalParams)
155
- }
156
-
157
- error(message?: unknown, ...optionalParams: unknown[]): void {
158
- if (this.level <= LogLevel.ERROR) {
159
- this.impl.error(...this.formatMessage(message), ...optionalParams)
160
- }
161
- }
162
- }