@aiquants/directory-tree 0.1.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/index.js ADDED
@@ -0,0 +1,694 @@
1
+ import he, { memo as me, useRef as ne, useState as H, useEffect as ee, useCallback as D, Fragment as be, useMemo as Z, useTransition as ve } from "react";
2
+ import { VirtualScroll as ye } from "@aiquants/virtualscroll";
3
+ import { ChevronDownIcon as pe, ChevronRightIcon as Ee, FolderIcon as xe, DocumentTextIcon as ge } from "@heroicons/react/24/solid";
4
+ import { FileIcon as we } from "@phosphor-icons/react";
5
+ import { twMerge as L } from "tailwind-merge";
6
+ var Q = { exports: {} }, G = {};
7
+ /**
8
+ * @license React
9
+ * react-jsx-runtime.production.js
10
+ *
11
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
12
+ *
13
+ * This source code is licensed under the MIT license found in the
14
+ * LICENSE file in the root directory of this source tree.
15
+ */
16
+ var se;
17
+ function _e() {
18
+ if (se) return G;
19
+ se = 1;
20
+ var t = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
21
+ function u(c, s, i) {
22
+ var f = null;
23
+ if (i !== void 0 && (f = "" + i), s.key !== void 0 && (f = "" + s.key), "key" in s) {
24
+ i = {};
25
+ for (var p in s)
26
+ p !== "key" && (i[p] = s[p]);
27
+ } else i = s;
28
+ return s = i.ref, {
29
+ $$typeof: t,
30
+ type: c,
31
+ key: f,
32
+ ref: s !== void 0 ? s : null,
33
+ props: i
34
+ };
35
+ }
36
+ return G.Fragment = r, G.jsx = u, G.jsxs = u, G;
37
+ }
38
+ var X = {};
39
+ /**
40
+ * @license React
41
+ * react-jsx-runtime.development.js
42
+ *
43
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
44
+ *
45
+ * This source code is licensed under the MIT license found in the
46
+ * LICENSE file in the root directory of this source tree.
47
+ */
48
+ var le;
49
+ function Ie() {
50
+ return le || (le = 1, process.env.NODE_ENV !== "production" && (function() {
51
+ function t(e) {
52
+ if (e == null) return null;
53
+ if (typeof e == "function")
54
+ return e.$$typeof === Y ? null : e.displayName || e.name || null;
55
+ if (typeof e == "string") return e;
56
+ switch (e) {
57
+ case h:
58
+ return "Fragment";
59
+ case x:
60
+ return "Profiler";
61
+ case _:
62
+ return "StrictMode";
63
+ case $:
64
+ return "Suspense";
65
+ case N:
66
+ return "SuspenseList";
67
+ case I:
68
+ return "Activity";
69
+ }
70
+ if (typeof e == "object")
71
+ switch (typeof e.tag == "number" && console.error(
72
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
73
+ ), e.$$typeof) {
74
+ case n:
75
+ return "Portal";
76
+ case P:
77
+ return e.displayName || "Context";
78
+ case v:
79
+ return (e._context.displayName || "Context") + ".Consumer";
80
+ case M:
81
+ var o = e.render;
82
+ return e = e.displayName, e || (e = o.displayName || o.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
83
+ case U:
84
+ return o = e.displayName || null, o !== null ? o : t(e.type) || "Memo";
85
+ case z:
86
+ o = e._payload, e = e._init;
87
+ try {
88
+ return t(e(o));
89
+ } catch {
90
+ }
91
+ }
92
+ return null;
93
+ }
94
+ function r(e) {
95
+ return "" + e;
96
+ }
97
+ function u(e) {
98
+ try {
99
+ r(e);
100
+ var o = !1;
101
+ } catch {
102
+ o = !0;
103
+ }
104
+ if (o) {
105
+ o = console;
106
+ var d = o.error, y = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
107
+ return d.call(
108
+ o,
109
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
110
+ y
111
+ ), r(e);
112
+ }
113
+ }
114
+ function c(e) {
115
+ if (e === h) return "<>";
116
+ if (typeof e == "object" && e !== null && e.$$typeof === z)
117
+ return "<...>";
118
+ try {
119
+ var o = t(e);
120
+ return o ? "<" + o + ">" : "<...>";
121
+ } catch {
122
+ return "<...>";
123
+ }
124
+ }
125
+ function s() {
126
+ var e = W.A;
127
+ return e === null ? null : e.getOwner();
128
+ }
129
+ function i() {
130
+ return Error("react-stack-top-frame");
131
+ }
132
+ function f(e) {
133
+ if (q.call(e, "key")) {
134
+ var o = Object.getOwnPropertyDescriptor(e, "key").get;
135
+ if (o && o.isReactWarning) return !1;
136
+ }
137
+ return e.key !== void 0;
138
+ }
139
+ function p(e, o) {
140
+ function d() {
141
+ C || (C = !0, console.error(
142
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
143
+ o
144
+ ));
145
+ }
146
+ d.isReactWarning = !0, Object.defineProperty(e, "key", {
147
+ get: d,
148
+ configurable: !0
149
+ });
150
+ }
151
+ function E() {
152
+ var e = t(this.type);
153
+ return S[e] || (S[e] = !0, console.error(
154
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
155
+ )), e = this.props.ref, e !== void 0 ? e : null;
156
+ }
157
+ function k(e, o, d, y, B, te) {
158
+ var g = d.ref;
159
+ return e = {
160
+ $$typeof: l,
161
+ type: e,
162
+ key: o,
163
+ props: d,
164
+ _owner: y
165
+ }, (g !== void 0 ? g : null) !== null ? Object.defineProperty(e, "ref", {
166
+ enumerable: !1,
167
+ get: E
168
+ }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
169
+ configurable: !1,
170
+ enumerable: !1,
171
+ writable: !0,
172
+ value: 0
173
+ }), Object.defineProperty(e, "_debugInfo", {
174
+ configurable: !1,
175
+ enumerable: !1,
176
+ writable: !0,
177
+ value: null
178
+ }), Object.defineProperty(e, "_debugStack", {
179
+ configurable: !1,
180
+ enumerable: !1,
181
+ writable: !0,
182
+ value: B
183
+ }), Object.defineProperty(e, "_debugTask", {
184
+ configurable: !1,
185
+ enumerable: !1,
186
+ writable: !0,
187
+ value: te
188
+ }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
189
+ }
190
+ function O(e, o, d, y, B, te) {
191
+ var g = o.children;
192
+ if (g !== void 0)
193
+ if (y)
194
+ if (m(g)) {
195
+ for (y = 0; y < g.length; y++)
196
+ j(g[y]);
197
+ Object.freeze && Object.freeze(g);
198
+ } else
199
+ console.error(
200
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
201
+ );
202
+ else j(g);
203
+ if (q.call(o, "key")) {
204
+ g = t(e);
205
+ var J = Object.keys(o).filter(function(fe) {
206
+ return fe !== "key";
207
+ });
208
+ y = 0 < J.length ? "{key: someKey, " + J.join(": ..., ") + ": ...}" : "{key: someKey}", V[g + y] || (J = 0 < J.length ? "{" + J.join(": ..., ") + ": ...}" : "{}", console.error(
209
+ `A props object containing a "key" prop is being spread into JSX:
210
+ let props = %s;
211
+ <%s {...props} />
212
+ React keys must be passed directly to JSX without using spread:
213
+ let props = %s;
214
+ <%s key={someKey} {...props} />`,
215
+ y,
216
+ g,
217
+ J,
218
+ g
219
+ ), V[g + y] = !0);
220
+ }
221
+ if (g = null, d !== void 0 && (u(d), g = "" + d), f(o) && (u(o.key), g = "" + o.key), "key" in o) {
222
+ d = {};
223
+ for (var re in o)
224
+ re !== "key" && (d[re] = o[re]);
225
+ } else d = o;
226
+ return g && p(
227
+ d,
228
+ typeof e == "function" ? e.displayName || e.name || "Unknown" : e
229
+ ), k(
230
+ e,
231
+ g,
232
+ d,
233
+ s(),
234
+ B,
235
+ te
236
+ );
237
+ }
238
+ function j(e) {
239
+ w(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === z && (e._payload.status === "fulfilled" ? w(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
240
+ }
241
+ function w(e) {
242
+ return typeof e == "object" && e !== null && e.$$typeof === l;
243
+ }
244
+ var a = he, l = Symbol.for("react.transitional.element"), n = Symbol.for("react.portal"), h = Symbol.for("react.fragment"), _ = Symbol.for("react.strict_mode"), x = Symbol.for("react.profiler"), v = Symbol.for("react.consumer"), P = Symbol.for("react.context"), M = Symbol.for("react.forward_ref"), $ = Symbol.for("react.suspense"), N = Symbol.for("react.suspense_list"), U = Symbol.for("react.memo"), z = Symbol.for("react.lazy"), I = Symbol.for("react.activity"), Y = Symbol.for("react.client.reference"), W = a.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, q = Object.prototype.hasOwnProperty, m = Array.isArray, T = console.createTask ? console.createTask : function() {
245
+ return null;
246
+ };
247
+ a = {
248
+ react_stack_bottom_frame: function(e) {
249
+ return e();
250
+ }
251
+ };
252
+ var C, S = {}, A = a.react_stack_bottom_frame.bind(
253
+ a,
254
+ i
255
+ )(), F = T(c(i)), V = {};
256
+ X.Fragment = h, X.jsx = function(e, o, d) {
257
+ var y = 1e4 > W.recentlyCreatedOwnerStacks++;
258
+ return O(
259
+ e,
260
+ o,
261
+ d,
262
+ !1,
263
+ y ? Error("react-stack-top-frame") : A,
264
+ y ? T(c(e)) : F
265
+ );
266
+ }, X.jsxs = function(e, o, d) {
267
+ var y = 1e4 > W.recentlyCreatedOwnerStacks++;
268
+ return O(
269
+ e,
270
+ o,
271
+ d,
272
+ !0,
273
+ y ? Error("react-stack-top-frame") : A,
274
+ y ? T(c(e)) : F
275
+ );
276
+ };
277
+ })()), X;
278
+ }
279
+ var ce;
280
+ function Te() {
281
+ return ce || (ce = 1, process.env.NODE_ENV === "production" ? Q.exports = _e() : Q.exports = Ie()), Q.exports;
282
+ }
283
+ var b = Te();
284
+ const Se = ({ items: t, itemHeight: r, width: u, segmentWidth: c, color: s = "#a0aec0", strokeWidth: i = 1, renderFromY: f = 0, renderHeight: p }) => {
285
+ const E = [], k = Math.max(0, Math.floor(f / r)), O = p ?? t.length * r, j = Math.min(t.length, Math.ceil((f + O) / r));
286
+ for (let a = k; a < j; a++) {
287
+ const l = t[a], n = a * r, h = n + r / 2;
288
+ for (let v = 0; v < l.indentLevel; v++) {
289
+ const P = v * c + c / 2;
290
+ let M = !1;
291
+ for (let $ = a; $ < t.length; $++) {
292
+ if (t[$].indentLevel > v && t[$].ancestorIsLast.length > v && !t[$].ancestorIsLast[v]) {
293
+ M = !0;
294
+ break;
295
+ }
296
+ if (t[$].indentLevel === v && $ > a)
297
+ break;
298
+ }
299
+ M && l.ancestorIsLast.length > v && !l.ancestorIsLast[v] && E.push(`M ${P},${n} L ${P},${n + r}`);
300
+ }
301
+ const _ = l.indentLevel * c, x = _ + c / 2;
302
+ if (l.isDirectory) {
303
+ const v = c / 1.5;
304
+ E.push(`M ${x},${n} L ${x},${h - v}`);
305
+ } else
306
+ E.push(`M ${x},${n} L ${x},${h}`);
307
+ if (l.isDirectory || l.isLastChild && E.push(`M ${x},${h} L ${_ + c},${h}`), !l.isLastChild)
308
+ if (l.isDirectory) {
309
+ const v = c / 1.5;
310
+ E.push(`M ${x},${h + v} L ${x},${n + r}`);
311
+ } else
312
+ E.push(`M ${x},${h} L ${x},${n + r}`);
313
+ }
314
+ const w = t.length * r;
315
+ return /* @__PURE__ */ b.jsxs(
316
+ "svg",
317
+ {
318
+ width: u,
319
+ height: p ?? w,
320
+ viewBox: `0 ${f} ${u} ${p ?? w}`,
321
+ fill: "none",
322
+ xmlns: "http://www.w3.org/2000/svg",
323
+ className: "pointer-events-none absolute top-0 left-0 z-0 opacity-75",
324
+ children: [
325
+ /* @__PURE__ */ b.jsx("title", { children: "Tree Lines" }),
326
+ E.map((a, l) => /* @__PURE__ */ b.jsx("path", { d: a, stroke: s, strokeWidth: i, strokeLinecap: "round", strokeLinejoin: "round" }, `path-${t[k + l]?.id || l}-${k + l}`))
327
+ ]
328
+ }
329
+ );
330
+ }, R = {
331
+ container: "directory-tree-container relative h-full transition-opacity duration-300 overflow-y-hidden",
332
+ containerPending: "opacity-70",
333
+ entry: "flex items-center cursor-pointer relative select-none",
334
+ // ホバー時のスタイル(ライト/ダークモード対応)
335
+ entryHover: L(
336
+ "hover:bg-gray-400/15",
337
+ "dark:hover:bg-gray-200/10"
338
+ ),
339
+ // 選択時のスタイル(ライト/ダークモード対応)
340
+ entrySelected: L(
341
+ "bg-blue-400/10",
342
+ "dark:bg-blue-400/15"
343
+ ),
344
+ // アイテム選択時のスタイル(ライト/ダークモード対応)
345
+ entryItemSelected: L(
346
+ "bg-blue-400/20 shadow-[0_0_0_1px_rgba(59,130,246,0.3)]",
347
+ "dark:bg-blue-400/25 dark:shadow-[0_0_0_1px_rgba(96,165,250,0.4)]"
348
+ ),
349
+ // アイコンのスタイル
350
+ expandIcon: L(
351
+ "w-5 h-5 flex-shrink-0 flex items-center justify-center",
352
+ "text-gray-500",
353
+ "dark:text-gray-400"
354
+ ),
355
+ expandIconSelected: L(
356
+ "text-blue-700",
357
+ "dark:text-blue-400"
358
+ ),
359
+ typeIcon: L(
360
+ "w-5 h-5 flex-shrink-0 flex items-center justify-center",
361
+ "text-gray-500",
362
+ "dark:text-gray-400"
363
+ ),
364
+ typeIconSelected: L(
365
+ "text-blue-700",
366
+ "dark:text-blue-400"
367
+ ),
368
+ // テキストのスタイル
369
+ name: L(
370
+ "overflow-hidden text-ellipsis whitespace-nowrap ml-1",
371
+ "text-gray-700",
372
+ "dark:text-gray-200"
373
+ ),
374
+ nameDirectory: "font-bold",
375
+ nameSelected: L(
376
+ "text-blue-800 font-medium",
377
+ "dark:text-blue-300"
378
+ )
379
+ }, ie = {
380
+ msOverflowStyle: "none",
381
+ /* IE and Edge */
382
+ scrollbarWidth: "none"
383
+ /* Firefox */
384
+ }, Re = () => {
385
+ let t = document.getElementById("directory-tree-webkit-scrollbar-hide");
386
+ t || (t = document.createElement("style"), t.id = "directory-tree-webkit-scrollbar-hide", t.textContent = ".directory-tree-container::-webkit-scrollbar { display: none; }", document.head.appendChild(t));
387
+ }, ke = (t = !1, r = !1, u = !1) => L(
388
+ R.entry,
389
+ t && R.entryHover,
390
+ r && R.entrySelected,
391
+ u && R.entryItemSelected
392
+ ), je = (t = !1) => L(
393
+ R.expandIcon,
394
+ t && R.expandIconSelected
395
+ ), $e = (t = !1) => L(
396
+ R.typeIcon,
397
+ t && R.typeIconSelected
398
+ ), Ce = (t = !1, r = !1) => L(
399
+ R.name,
400
+ t && R.nameDirectory,
401
+ r && R.nameSelected
402
+ ), Le = (t) => t.slice((t.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase(), oe = me(
403
+ ({
404
+ entry: t,
405
+ indentLevel: r,
406
+ isDirOpen: u,
407
+ onFileSelect: c,
408
+ toggleDirectory: s,
409
+ onToggleDirectoryRecursive: i,
410
+ selectedPath: f,
411
+ parentIsLast: p,
412
+ renderChildren: E = !0,
413
+ selectionMode: k = "none",
414
+ selectedItems: O,
415
+ onSelectionChange: j
416
+ }) => {
417
+ const w = ne(null), [a, l] = H(null);
418
+ ee(() => () => {
419
+ w.current && window.clearTimeout(w.current);
420
+ }, []);
421
+ const n = t.children !== void 0, h = n && u(t.absolutePath, t.relativePath), _ = t.absolutePath === f, x = !n && (O?.has(t.absolutePath) || !1);
422
+ ee(() => {
423
+ h && t.children ? Promise.resolve().then(() => {
424
+ l(t.children ?? []);
425
+ }) : l(null);
426
+ }, [h, t.children]);
427
+ const v = D(
428
+ (I) => {
429
+ I.stopPropagation(), k !== "none" && !n && j && j(t.absolutePath, !x), n ? w.current ? (window.clearTimeout(w.current), w.current = null, i(t)) : w.current = window.setTimeout(() => {
430
+ s(t.absolutePath, t.relativePath), w.current = null;
431
+ }, 500) : c(t.absolutePath, t.relativePath);
432
+ },
433
+ [n, t, i, s, c, k, j, x]
434
+ ), [P, M] = H(!1), $ = ke(P, _, x), N = je(_ || x), U = $e(_ || x), z = Ce(n, _ || x);
435
+ return /* @__PURE__ */ b.jsxs(be, { children: [
436
+ /* @__PURE__ */ b.jsxs(
437
+ "div",
438
+ {
439
+ className: $,
440
+ style: {
441
+ paddingLeft: `${r * ae}px`,
442
+ height: `${K}px`
443
+ },
444
+ onClick: v,
445
+ onMouseEnter: () => M(!0),
446
+ onMouseLeave: () => M(!1),
447
+ onKeyDown: (I) => {
448
+ I.key === "Enter" && v(I);
449
+ },
450
+ tabIndex: 0,
451
+ role: "treeitem",
452
+ "aria-expanded": n ? h : void 0,
453
+ "aria-label": `${t.name} (${n ? "directory" : "file"})`,
454
+ children: [
455
+ /* @__PURE__ */ b.jsx("span", { className: N, children: n ? h ? /* @__PURE__ */ b.jsx(pe, { className: "h-4 w-4" }) : /* @__PURE__ */ b.jsx(Ee, { className: "h-4 w-4" }) : /* @__PURE__ */ b.jsx("span", { className: "w-4" }) }),
456
+ /* @__PURE__ */ b.jsx("span", { className: U, children: n ? /* @__PURE__ */ b.jsx(xe, { className: "h-4 w-4" }) : (() => {
457
+ switch (Le(t.name)) {
458
+ case "md":
459
+ return /* @__PURE__ */ b.jsx(ge, { className: "h-4 w-4" });
460
+ default:
461
+ return /* @__PURE__ */ b.jsx(we, { className: "h-4 w-4" });
462
+ }
463
+ })() }),
464
+ /* @__PURE__ */ b.jsx("span", { className: z, children: t.name })
465
+ ]
466
+ }
467
+ ),
468
+ h && a && E && /* @__PURE__ */ b.jsx("fieldset", { children: a.map((I, Y) => /* @__PURE__ */ b.jsx(
469
+ oe,
470
+ {
471
+ entry: I,
472
+ indentLevel: r + 1,
473
+ isDirOpen: u,
474
+ onFileSelect: c,
475
+ toggleDirectory: s,
476
+ onToggleDirectoryRecursive: i,
477
+ selectedPath: f,
478
+ parentIsLast: [...p, Y === (a || []).length - 1],
479
+ selectionMode: k,
480
+ selectedItems: O,
481
+ onSelectionChange: j
482
+ },
483
+ I.absolutePath
484
+ )) })
485
+ ] }, t.absolutePath);
486
+ },
487
+ (t, r) => {
488
+ if (t.entry.absolutePath !== r.entry.absolutePath || t.entry.relativePath !== r.entry.relativePath || t.entry.name !== r.entry.name || t.entry.type !== r.entry.type || t.entry.children === void 0 != (r.entry.children === void 0))
489
+ return !1;
490
+ const u = t.entry.children !== void 0, c = r.entry.children !== void 0, s = u && t.isDirOpen(t.entry.absolutePath, t.entry.relativePath), i = c && r.isDirOpen(r.entry.absolutePath, r.entry.relativePath);
491
+ if (t.indentLevel !== r.indentLevel || s !== i || t.selectedPath !== r.selectedPath || t.onFileSelect !== r.onFileSelect || // onFileSelect はメモ化されていることを期待
492
+ t.toggleDirectory !== r.toggleDirectory || // toggleDirectory はメモ化されていることを期待
493
+ t.onToggleDirectoryRecursive !== r.onToggleDirectoryRecursive || t.selectionMode !== r.selectionMode || t.selectedItems !== r.selectedItems || t.onSelectionChange !== r.onSelectionChange || t.parentIsLast.length !== r.parentIsLast.length)
494
+ return !1;
495
+ for (let f = 0; f < t.parentIsLast.length; f++)
496
+ if (t.parentIsLast[f] !== r.parentIsLast[f])
497
+ return !1;
498
+ return !0;
499
+ }
500
+ );
501
+ oe.displayName = "DirectoryEntryItem";
502
+ const K = 20, ae = 16, ue = (t) => {
503
+ const r = [];
504
+ if (t.children)
505
+ for (const u of t.children)
506
+ u.type === "directory" && (r.push(u.absolutePath), r.push(...ue(u)));
507
+ return r;
508
+ }, de = (t, r, u = [], c = 0) => t.flatMap((s, i) => {
509
+ const f = i === t.length - 1, p = [...u, f], E = { entry: s, indentLevel: c, parentIsLast: p };
510
+ return s.children && s.children.length > 0 && r(s.absolutePath, s.relativePath) ? [E, ...de(s.children, r, p, c + 1)] : [E];
511
+ }), Me = ({
512
+ entries: t,
513
+ onFileSelect: r,
514
+ className: u,
515
+ style: c,
516
+ selectedPath: s,
517
+ toggle: i,
518
+ isExpanded: f,
519
+ expandMultiple: p,
520
+ collapseMultiple: E,
521
+ isPending: k,
522
+ doubleClickAction: O = "recursive",
523
+ selectionMode: j = "none",
524
+ selectedItems: w,
525
+ onSelectionChange: a,
526
+ lineColor: l = "#A0AEC0"
527
+ }) => {
528
+ const [n, h] = H(!1), _ = ne(null), x = ne(null), [v, P] = H(0), [M, $] = H(0);
529
+ ee(() => {
530
+ if (h(!0), Re(), _.current) {
531
+ P(_.current.clientHeight);
532
+ const m = new ResizeObserver((T) => {
533
+ for (const C of T)
534
+ P(C.contentRect.height);
535
+ });
536
+ return m.observe(_.current), () => m.disconnect();
537
+ }
538
+ }, []);
539
+ const N = D(
540
+ (m) => n ? f(m) : !1,
541
+ [n, f]
542
+ ), U = k ? `${R.container} ${R.containerPending}` : R.container, z = D(
543
+ (m, T) => {
544
+ const C = ue(m), S = [m.absolutePath, ...C], A = T || O;
545
+ S.every((V) => N(V)) ? E(S) : S.every((e) => !N(e)) || A === "recursive" ? p(S) : A === "toggle" ? E(S) : console.warn(`[DirectoryTree] Unknown double click action: ${A}. No action taken.`);
546
+ },
547
+ [N, p, E, O]
548
+ ), I = Z(() => {
549
+ if (t.length === 0)
550
+ return [];
551
+ const m = [];
552
+ function T(C, S, A) {
553
+ C.forEach((F, V) => {
554
+ const e = F.children !== void 0, o = F.absolutePath, d = e && N(o), y = {
555
+ id: o,
556
+ name: F.name,
557
+ absolutePath: o,
558
+ indentLevel: S,
559
+ isLastChild: V === C.length - 1,
560
+ isDirectory: e,
561
+ isExpanded: d,
562
+ ancestorIsLast: [...A]
563
+ // 祖先の状態をコピーして渡す
564
+ };
565
+ m.push(y), e && d && F.children && T(F.children, S + 1, [...A, V === C.length - 1]);
566
+ });
567
+ }
568
+ return T(t, 0, []), m;
569
+ }, [t, N]), Y = Z(() => de(t, N), [t, N]), W = Z(() => Y.length * K, [Y]), q = Z(() => {
570
+ if (t.length === 0)
571
+ return 0;
572
+ let m = 0;
573
+ for (const T of I)
574
+ T.indentLevel > m && (m = T.indentLevel);
575
+ return (m + 2) * ae;
576
+ }, [I, t]);
577
+ return t.length === 0 ? /* @__PURE__ */ b.jsx("div", { className: `${U} ${u || ""}`, style: { ...c, ...ie } }) : /* @__PURE__ */ b.jsx("div", { ref: _, className: `${U} ${u || ""}`, style: { ...c, ...ie }, role: "tree", children: /* @__PURE__ */ b.jsxs("div", { className: "w-full", style: { position: "relative", height: `${W}px` }, children: [
578
+ /* @__PURE__ */ b.jsx("div", { style: { position: "absolute", top: 0, left: 0, width: q, height: `${v}px`, overflow: "hidden" }, children: /* @__PURE__ */ b.jsx(Se, { items: I, itemHeight: K, width: q, segmentWidth: ae, color: l, "aria-hidden": "true", role: "presentation", renderFromY: M, renderHeight: v }) }),
579
+ /* @__PURE__ */ b.jsx(ye, { ref: x, itemCount: Y.length, getItem: (m) => Y[m], getItemHeight: () => K, viewportSize: v, overscanCount: 10, onScroll: (m) => $(m), children: (m, T) => {
580
+ if (!m)
581
+ return null;
582
+ const { entry: C, indentLevel: S, parentIsLast: A } = m;
583
+ return /* @__PURE__ */ b.jsx(
584
+ oe,
585
+ {
586
+ entry: C,
587
+ indentLevel: S,
588
+ isDirOpen: N,
589
+ onFileSelect: r,
590
+ toggleDirectory: i,
591
+ onToggleDirectoryRecursive: z,
592
+ selectedPath: s,
593
+ parentIsLast: A,
594
+ renderChildren: !1,
595
+ selectionMode: j,
596
+ selectedItems: w,
597
+ onSelectionChange: a
598
+ },
599
+ C.absolutePath
600
+ );
601
+ } })
602
+ ] }) });
603
+ }, Fe = ({
604
+ initialExpanded: t = /* @__PURE__ */ new Set(),
605
+ storageKey: r
606
+ } = {}) => {
607
+ const [u, c] = ve(), [s, i] = H(() => {
608
+ if (typeof window < "u" && r)
609
+ try {
610
+ const a = window.localStorage.getItem(r);
611
+ if (a) {
612
+ const l = JSON.parse(a);
613
+ return new Set(l);
614
+ }
615
+ } catch (a) {
616
+ console.error("[useDirectoryTreeState] Error reading from localStorage", a);
617
+ }
618
+ return t;
619
+ });
620
+ ee(() => {
621
+ if (r && typeof window < "u")
622
+ try {
623
+ window.localStorage.setItem(r, JSON.stringify(Array.from(s)));
624
+ } catch (a) {
625
+ console.warn(`Error setting localStorage key "${r}":`, a);
626
+ }
627
+ }, [s, r]);
628
+ const f = D((a) => {
629
+ c(() => {
630
+ i((l) => {
631
+ const n = new Set(l);
632
+ return n.has(a) ? n.delete(a) : n.add(a), n;
633
+ });
634
+ });
635
+ }, []), p = D((a) => {
636
+ c(() => {
637
+ i((l) => {
638
+ const n = new Set(l);
639
+ return n.has(a) || n.add(a), n;
640
+ });
641
+ });
642
+ }, []), E = D((a) => {
643
+ c(() => {
644
+ i((l) => {
645
+ const n = new Set(l);
646
+ return n.has(a) && n.delete(a), n;
647
+ });
648
+ });
649
+ }, []), k = D((a) => {
650
+ c(() => {
651
+ i((l) => {
652
+ const n = new Set(l);
653
+ for (const h of a)
654
+ n.has(h) && n.delete(h);
655
+ return n;
656
+ });
657
+ });
658
+ }, []), O = D((a) => {
659
+ c(() => {
660
+ i((l) => {
661
+ const n = new Set(l);
662
+ for (const h of a)
663
+ n.has(h) || n.add(h);
664
+ return n;
665
+ });
666
+ });
667
+ }, []), j = D(() => {
668
+ c(() => {
669
+ i(/* @__PURE__ */ new Set());
670
+ });
671
+ }, []), w = D((a) => s.has(a), [s]);
672
+ return {
673
+ expanded: s,
674
+ toggle: f,
675
+ expand: p,
676
+ collapse: E,
677
+ collapseMultiple: k,
678
+ expandMultiple: O,
679
+ collapseAll: j,
680
+ isExpanded: w,
681
+ isPending: u
682
+ };
683
+ };
684
+ export {
685
+ Me as DirectoryTree,
686
+ Se as TreeLine,
687
+ R as directoryTreeClasses,
688
+ ke as getEntryClasses,
689
+ je as getExpandIconClasses,
690
+ Ce as getNameClasses,
691
+ $e as getTypeIconClasses,
692
+ Fe as useDirectoryTreeState
693
+ };
694
+ //# sourceMappingURL=index.js.map