@aiquants/directory-tree 3.2.0 → 3.3.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEntryInteraction.d.ts","sourceRoot":"","sources":["../src/useEntryInteraction.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAEvC,OAAO,KAAK,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAKzE,MAAM,MAAM,uBAAuB,GAAG;IAClC,KAAK,EAAE,cAAc,CAAA;IACrB,WAAW,EAAE,OAAO,CAAA;IACpB,UAAU,EAAE,OAAO,CAAA;IACnB,cAAc,EAAE,OAAO,CAAA;IACvB,aAAa,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC7C,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,OAAO,KAAK,IAAI,CAAA;IACxE,YAAY,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAA;IACtD,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACvC,0BAA0B,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAA;CAC9D,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,iJAAiJ,uBAAuB,SAWhM,UAAU,CAAC,cAAc,CAAC,SA+BrC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiquants/directory-tree",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "High-performance directory tree component for React with virtual scrolling and file selection",
5
5
  "sideEffects": [
6
6
  "**/*.css"
@@ -332,6 +332,9 @@ const DirectoryEntryItem = memo<DirectoryEntryItemProps>(
332
332
  showFileIcons = true,
333
333
  useCanvasExpandIcons = false,
334
334
  expandIconSize,
335
+ typeIconSize,
336
+ fontSize,
337
+ indentSize = INDENT_SIZE,
335
338
  highlightStyles,
336
339
  entryClassName,
337
340
  entryStyle,
@@ -350,7 +353,7 @@ const DirectoryEntryItem = memo<DirectoryEntryItemProps>(
350
353
  const isExpanded = isDirectory && isDirOpen(entry.absolutePath)
351
354
  const isSelected = entry.absolutePath === selectedPath
352
355
  const isItemSelected = !isDirectory && selectedItems?.has(entry.absolutePath)
353
- const extension = isDirectory ? undefined : (getFileExtension(entry.name) || getFileExtension(entry.relativePath) || getFileExtension(entry.absolutePath))
356
+ const extension = isDirectory ? undefined : getFileExtension(entry.name) || getFileExtension(entry.relativePath) || getFileExtension(entry.absolutePath)
354
357
 
355
358
  /**
356
359
  * @effect Lazy Children Loading
@@ -395,15 +398,19 @@ const DirectoryEntryItem = memo<DirectoryEntryItemProps>(
395
398
  ...(!isDirectory && (isSelected || isItemSelected) ? highlightStyles?.itemSelectedStyle : {}),
396
399
  }
397
400
 
401
+ const typeIconStyle = typeIconSize ? { width: typeIconSize, height: typeIconSize } : undefined
402
+ const fontSizeStyle = fontSize ? { fontSize: typeof fontSize === "number" ? `${fontSize}px` : fontSize } : undefined
403
+
398
404
  return (
399
405
  <Fragment key={entry.absolutePath}>
400
406
  <div
401
407
  className={entryClasses}
402
408
  style={{
403
- paddingLeft: `${Math.max(0, indentLevel * INDENT_SIZE)}px`,
404
- transform: indentLevel < 0 ? `translateX(${indentLevel * INDENT_SIZE}px)` : undefined,
405
- width: indentLevel < 0 ? `calc(100% + ${Math.abs(indentLevel * INDENT_SIZE)}px)` : undefined,
409
+ paddingLeft: `${Math.max(0, indentLevel * indentSize)}px`,
410
+ transform: indentLevel < 0 ? `translateX(${indentLevel * indentSize}px)` : undefined,
411
+ width: indentLevel < 0 ? `calc(100% + ${Math.abs(indentLevel * indentSize)}px)` : undefined,
406
412
  height: `${rowHeight}px`,
413
+ ...fontSizeStyle,
407
414
  ...customHighlightStyle,
408
415
  ...entryStyle,
409
416
  ...entry.style,
@@ -421,10 +428,15 @@ const DirectoryEntryItem = memo<DirectoryEntryItemProps>(
421
428
  aria-expanded={isDirectory ? isExpanded : undefined}
422
429
  aria-label={`${entry.name} (${isDirectory ? "directory" : "file"})`}>
423
430
  {(showExpandIcons || useCanvasExpandIcons) && <span className={expandIconClasses}>{expandIconContent}</span>}
424
- {(isDirectory ? showDirectoryIcons : showFileIcons) && <span className={typeIconClasses}>{resolvedIcon}</span>}
431
+ {(isDirectory ? showDirectoryIcons : showFileIcons) && (
432
+ <span className={typeIconClasses} style={typeIconStyle}>
433
+ {resolvedIcon}
434
+ </span>
435
+ )}
425
436
  <span
426
437
  className={nameClasses}
427
438
  style={{
439
+ ...fontSizeStyle,
428
440
  ...nameStyle,
429
441
  ...(isDirectory ? directoryNameStyle : fileNameStyle),
430
442
  }}
@@ -23,6 +23,9 @@ export type GridRowVisual = {
23
23
  showFileIcons?: boolean
24
24
  useCanvasExpandIcons?: boolean
25
25
  expandIconSize?: number
26
+ typeIconSize?: number
27
+ fontSize?: number | string
28
+ indentSize?: number
26
29
  highlightStyles?: HighlightStyles
27
30
  }
28
31
 
@@ -81,7 +84,7 @@ export const DirectoryTreeGridRow = memo<DirectoryTreeGridRowProps>(
81
84
  rowClassName,
82
85
  selection: { onEntryClick, selectedPath, mode: selectionMode = "none", selectedItems, onSelectionChange },
83
86
  expansion: { toggleDirectory, onToggleDirectoryRecursive },
84
- visual: { iconOverrides, showExpandIcons = true, showDirectoryIcons = true, showFileIcons = true, useCanvasExpandIcons = false, expandIconSize, highlightStyles },
87
+ visual: { iconOverrides, showExpandIcons = true, showDirectoryIcons = true, showFileIcons = true, useCanvasExpandIcons = false, expandIconSize, indentSize = INDENT_SIZE, highlightStyles },
85
88
  }) => {
86
89
  const [isHovered, setIsHovered] = useState(false)
87
90
 
@@ -89,7 +92,7 @@ export const DirectoryTreeGridRow = memo<DirectoryTreeGridRowProps>(
89
92
  const isExpanded = isDirectory && isDirOpen(entry.absolutePath)
90
93
  const isSelected = entry.absolutePath === selectedPath
91
94
  const isItemSelected = !isDirectory && Boolean(selectedItems?.has(entry.absolutePath))
92
- const extension = isDirectory ? undefined : (getFileExtension(entry.name) || getFileExtension(entry.relativePath) || getFileExtension(entry.absolutePath))
95
+ const extension = isDirectory ? undefined : getFileExtension(entry.name) || getFileExtension(entry.relativePath) || getFileExtension(entry.absolutePath)
93
96
 
94
97
  const handleInteraction = useEntryInteraction({ entry, isDirectory, isExpanded, isItemSelected, selectionMode, onSelectionChange, onEntryClick, toggleDirectory, onToggleDirectoryRecursive })
95
98
 
@@ -141,7 +144,7 @@ export const DirectoryTreeGridRow = memo<DirectoryTreeGridRowProps>(
141
144
  onKeyDown={(e) => e.key === "Enter" && handleInteraction(e as unknown as MouseEvent<HTMLDivElement>)}
142
145
  tabIndex={0}>
143
146
  {/* Frozen name/tree cell — indent applied here only. / 凍結名前セル(インデントはここだけ)。 */}
144
- <div className={twMerge("dt-grid-name-cell", nameColumn?.className)} role="gridcell" style={{ width: nameWidth, paddingLeft: Math.max(0, indentLevel * INDENT_SIZE) }}>
147
+ <div className={twMerge("dt-grid-name-cell", nameColumn?.className)} role="gridcell" style={{ width: nameWidth, paddingLeft: Math.max(0, indentLevel * indentSize) }}>
145
148
  {(showExpandIcons || useCanvasExpandIcons) && <span className={expandIconClasses}>{expandIconContent}</span>}
146
149
  {(isDirectory ? showDirectoryIcons : showFileIcons) && <span className={typeIconClasses}>{resolvedIcon}</span>}
147
150
  <span className={nameLabelClasses}>{nameContent}</span>
@@ -7,41 +7,27 @@
7
7
  * 従来行と TreeGrid 行が共有する定数・クラス・アイコン解決ヘルパ。循環 import 回避のため分離。
8
8
  */
9
9
  import { ChevronDownIcon, ChevronRightIcon, FolderIcon } from "@heroicons/react/24/solid"
10
- import {
11
- FileAudio,
12
- FileCode,
13
- FileCsv,
14
- FileDoc,
15
- FileIcon,
16
- FileImage,
17
- FileMd,
18
- FilePdf,
19
- FilePpt,
20
- FileText,
21
- FileVideo,
22
- FileXls,
23
- FileZip,
24
- } from "@phosphor-icons/react"
10
+ import { FileAudio, FileCode, FileCsv, FileDoc, FileIcon, FileImage, FileMd, FilePdf, FilePpt, FileText, FileVideo, FileXls, FileZip } from "@phosphor-icons/react"
25
11
  import type { ReactNode } from "react"
26
12
  import { twMerge } from "tailwind-merge"
27
13
  import type { DirectoryTreeIconOverrides, DirectoryTreeIconRenderContext, DirectoryTreeIconRenderer } from "./types.ts"
28
14
 
29
- /** Default row height in px. / 各行の高さの既定値 (px)。 */
30
- export const DEFAULT_ITEM_HEIGHT = 20
31
- /** Indentation per depth level in px. / 1 階層あたりのインデント幅 (px)。 */
32
- export const INDENT_SIZE = 16
33
- /** Standard expand glyph size. / 展開アイコンの標準サイズ。 */
34
- export const EXPAND_GLYPH_SIZE = 12
15
+ /** Default row height in px. / 各行の高さの既定値 (px)。 FHD環境に最適化されたコンパクト設計 (18px) */
16
+ export const DEFAULT_ITEM_HEIGHT = 18
17
+ /** Indentation per depth level in px. / 1 階層あたりのインデント幅 (px)。 FHD環境に最適化されたコンパクト設計 (12px) */
18
+ export const INDENT_SIZE = 12
19
+ /** Standard expand glyph size. / 展開アイコンの標準サイズ (10px)。 */
20
+ export const EXPAND_GLYPH_SIZE = 10
35
21
 
36
22
  /**
37
23
  * TailwindCSS v4 class names for DirectoryTree component.
38
24
  * DirectoryTreeコンポーネント用の TailwindCSS v4 クラス名。
39
25
  */
40
26
  export const directoryTreeClasses = {
41
- container: "directory-tree-container relative h-full transition-opacity duration-300 overflow-y-hidden pb-[5px] pr-[3px]",
27
+ container: "directory-tree-container relative h-full transition-opacity duration-300 overflow-y-hidden pb-[3px] pr-[2px]",
42
28
  containerPending: "opacity-70",
43
29
 
44
- entry: "directory-tree-entry flex items-center cursor-pointer relative select-none",
30
+ entry: "directory-tree-entry flex items-center cursor-pointer relative select-none text-xs leading-tight py-0.5",
45
31
 
46
32
  // ホバー時のスタイル(ライト/ダークモード対応)
47
33
  entryHover: twMerge("directory-tree-entry--hover hover:bg-gray-400/15", "dark:hover:bg-gray-200/10"),
@@ -53,20 +39,20 @@ export const directoryTreeClasses = {
53
39
  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)]"),
54
40
 
55
41
  // アイコンのスタイル
56
- expandIcon: twMerge("directory-tree-expand-icon w-5 h-5 flex-shrink-0 flex items-center justify-center", "text-gray-500", "dark:text-gray-400"),
42
+ 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"),
57
43
 
58
44
  expandIconSelected: twMerge("directory-tree-expand-icon--selected text-blue-700", "dark:text-blue-400"),
59
45
 
60
- typeIcon: twMerge("directory-tree-type-icon w-5 h-5 flex-shrink-0 flex items-center justify-center", "text-gray-500", "dark:text-gray-400"),
46
+ 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"),
61
47
 
62
48
  typeIconSelected: twMerge("directory-tree-type-icon--selected text-blue-700", "dark:text-blue-400"),
63
49
 
64
50
  // テキストのスタイル
65
- name: twMerge("directory-tree-name overflow-hidden text-ellipsis whitespace-nowrap ml-1", "text-gray-700", "dark:text-gray-200"),
51
+ name: twMerge("directory-tree-name overflow-hidden text-ellipsis whitespace-nowrap ml-1 text-xs font-normal", "text-gray-700", "dark:text-gray-200"),
66
52
 
67
- nameDirectory: "directory-tree-name--directory",
53
+ nameDirectory: "directory-tree-name--directory font-medium",
68
54
 
69
- nameSelected: twMerge("directory-tree-name--selected text-blue-800 font-medium", "dark:text-blue-300"),
55
+ nameSelected: twMerge("directory-tree-name--selected text-blue-800 font-semibold", "dark:text-blue-300"),
70
56
  }
71
57
 
72
58
  /**
@@ -135,11 +121,7 @@ const sanitizeIcon = (node: unknown, path: string): ReactNode | null => {
135
121
  * Resolves a file icon based on mimeType (primary) > extension (fallback).
136
122
  * mimeType (最優先) > 拡張子 (フォールバック) の順序でファイルアイコンを解決する。
137
123
  */
138
- export const getFileIconByMimeOrExtension = (
139
- mimeType?: string,
140
- extension?: string,
141
- filename?: string,
142
- ): ReactNode => {
124
+ export const getFileIconByMimeOrExtension = (mimeType?: string, extension?: string, filename?: string): ReactNode => {
143
125
  const cleanExt = (extension || (filename ? getFileExtension(filename) : "")).toLowerCase()
144
126
  const cleanMime = (mimeType || "").toLowerCase()
145
127
 
@@ -154,32 +136,18 @@ export const getFileIconByMimeOrExtension = (
154
136
  return <FilePdf className="h-4 w-4 text-red-500 dark:text-red-400" />
155
137
  }
156
138
  // Excel / 表計算 / CSV / Google Sheets (google-apps.spreadsheet)
157
- if (
158
- cleanMime.includes("excel") ||
159
- cleanMime.includes("spreadsheet") ||
160
- cleanMime.includes("google-apps.spreadsheet")
161
- ) {
139
+ if (cleanMime.includes("excel") || cleanMime.includes("spreadsheet") || cleanMime.includes("google-apps.spreadsheet")) {
162
140
  return <FileXls className="h-4 w-4 text-emerald-600 dark:text-emerald-400" />
163
141
  }
164
142
  if (cleanMime === "text/csv" || cleanMime === "text/tab-separated-values") {
165
143
  return <FileCsv className="h-4 w-4 text-emerald-600 dark:text-emerald-400" />
166
144
  }
167
145
  // Word / ドキュメント / Google Docs (google-apps.document)
168
- if (
169
- cleanMime.includes("word") ||
170
- cleanMime.includes("msword") ||
171
- cleanMime.includes("wordprocessingml") ||
172
- cleanMime.includes("google-apps.document") ||
173
- cleanMime === "application/rtf"
174
- ) {
146
+ if (cleanMime.includes("word") || cleanMime.includes("msword") || cleanMime.includes("wordprocessingml") || cleanMime.includes("google-apps.document") || cleanMime === "application/rtf") {
175
147
  return <FileDoc className="h-4 w-4 text-blue-600 dark:text-blue-400" />
176
148
  }
177
149
  // PowerPoint / プレゼンテーション / Google Slides (google-apps.presentation)
178
- if (
179
- cleanMime.includes("powerpoint") ||
180
- cleanMime.includes("presentation") ||
181
- cleanMime.includes("google-apps.presentation")
182
- ) {
150
+ if (cleanMime.includes("powerpoint") || cleanMime.includes("presentation") || cleanMime.includes("google-apps.presentation")) {
183
151
  return <FilePpt className="h-4 w-4 text-orange-500 dark:text-orange-400" />
184
152
  }
185
153
  // 画像
@@ -195,12 +163,7 @@ export const getFileIconByMimeOrExtension = (
195
163
  return <FileVideo className="h-4 w-4 text-violet-500 dark:text-violet-400" />
196
164
  }
197
165
  // アーカイブ / 圧縮
198
- if (
199
- cleanMime.includes("zip") ||
200
- cleanMime.includes("tar") ||
201
- cleanMime.includes("compressed") ||
202
- cleanMime.includes("archive")
203
- ) {
166
+ if (cleanMime.includes("zip") || cleanMime.includes("tar") || cleanMime.includes("compressed") || cleanMime.includes("archive")) {
204
167
  return <FileZip className="h-4 w-4 text-amber-500 dark:text-amber-400" />
205
168
  }
206
169
  // ソースコード / JSON / HTML / CSS
@@ -247,11 +210,7 @@ export const getFileIconByMimeOrExtension = (
247
210
  if (["png", "jpg", "jpeg", "gif", "svg", "webp", "ico", "bmp", "tiff", "avif"].includes(cleanExt)) {
248
211
  return <FileImage className="h-4 w-4 text-teal-500 dark:text-teal-400" />
249
212
  }
250
- if (
251
- ["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(
252
- cleanExt,
253
- )
254
- ) {
213
+ 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)) {
255
214
  return <FileCode className="h-4 w-4 text-purple-500 dark:text-purple-400" />
256
215
  }
257
216
  if (["mp3", "wav", "ogg", "m4a", "flac", "aac", "wma"].includes(cleanExt)) {
package/src/types.ts CHANGED
@@ -427,16 +427,31 @@ export type DirectoryTreeProps = {
427
427
  */
428
428
  iconOverrides?: DirectoryTreeIconOverrides
429
429
  /**
430
- * Size of the expand icon.
431
- * 展開アイコンのサイズ。
430
+ * Size of the expand icon in px.
431
+ * 展開アイコンのサイズ (px)。
432
432
  */
433
433
  expandIconSize?: number
434
434
  /**
435
- * Row height in px, or a function computing the height per entry. Default 20.
435
+ * Size of the file/directory type icon in px.
436
+ * ファイル/ディレクトリアイコンのサイズ (px)。
437
+ */
438
+ typeIconSize?: number
439
+ /**
440
+ * Font size of entry labels in px or CSS string (e.g. 12 or "0.75rem").
441
+ * ラベル文字のフォントサイズ (px または CSS 文字列)。
442
+ */
443
+ fontSize?: number | string
444
+ /**
445
+ * Indentation width per depth level in px.
446
+ * 1 階層あたりのインデント幅 (px)。
447
+ */
448
+ indentSize?: number
449
+ /**
450
+ * Row height in px, or a function computing the height per entry. Default 20 (or 18 in compact mode).
436
451
  * When a function is supplied, rows may have different heights and the tree
437
452
  * connector lines follow each row's cumulative offset.
438
453
  *
439
- * 各行の高さ (px)、またはエントリごとに高さを算出する関数。既定 20。
454
+ * 各行の高さ (px)、またはエントリごとに高さを算出する関数。既定 20 (コンパクトモード時 18)。
440
455
  * 関数を渡すと行ごとに高さを変えられ、ツリー接続線は各行の累積オフセットに追従する。
441
456
  */
442
457
  itemHeight?: ItemHeight
@@ -535,6 +550,9 @@ export type DirectoryEntryItemProps = {
535
550
  showFileIcons?: boolean
536
551
  iconOverrides?: DirectoryTreeIconOverrides
537
552
  expandIconSize?: number
553
+ typeIconSize?: number
554
+ fontSize?: number | string
555
+ indentSize?: number
538
556
  useCanvasExpandIcons?: boolean
539
557
  highlightStyles?: HighlightStyles
540
558
  entryClassName?: string