@tangle-network/sandbox-ui 0.10.9 → 0.12.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/chunk-LQNEZDRM.js +109 -0
- package/dist/{chunk-Z5PSS3VD.js → chunk-NKUPJC34.js} +453 -80
- package/dist/dashboard.d.ts +1 -1
- package/dist/dashboard.js +13 -1
- package/dist/files.d.ts +64 -4
- package/dist/files.js +4 -0
- package/dist/globals.css +24 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +17 -1
- package/dist/styles.css +24 -0
- package/dist/{variant-list-DAhiR-7S.d.ts → variant-list-BrHYcBCk.d.ts} +120 -1
- package/package.json +2 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// src/files/rich-file-tree.tsx
|
|
2
|
+
import {
|
|
3
|
+
FileTree as PierreFileTree,
|
|
4
|
+
useFileTree as usePierreFileTree
|
|
5
|
+
} from "@pierre/trees/react";
|
|
6
|
+
import { useEffect, useMemo } from "react";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
function cssVarFromToken(name) {
|
|
9
|
+
return `var(${name})`;
|
|
10
|
+
}
|
|
11
|
+
var DEFAULT_THEME = {
|
|
12
|
+
selectedBg: cssVarFromToken("--accent-surface-soft"),
|
|
13
|
+
selectedFg: cssVarFromToken("--accent-text"),
|
|
14
|
+
fg: cssVarFromToken("--foreground"),
|
|
15
|
+
hoverBg: cssVarFromToken("--muted"),
|
|
16
|
+
border: cssVarFromToken("--border"),
|
|
17
|
+
mutedFg: cssVarFromToken("--muted-foreground")
|
|
18
|
+
};
|
|
19
|
+
function flattenFileNode(node, out = []) {
|
|
20
|
+
if (node.type === "file" && node.path) {
|
|
21
|
+
out.push(node.path);
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
if (node.type === "directory") {
|
|
25
|
+
if (node.children?.length) {
|
|
26
|
+
for (const child of node.children) {
|
|
27
|
+
flattenFileNode(child, out);
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
if (node.path) out.push(`${node.path}/`);
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
function RichFileTree({
|
|
36
|
+
root,
|
|
37
|
+
paths,
|
|
38
|
+
selectedPath,
|
|
39
|
+
onSelect,
|
|
40
|
+
search = true,
|
|
41
|
+
initialExpansion = "open",
|
|
42
|
+
gitStatus,
|
|
43
|
+
renderContextMenu,
|
|
44
|
+
header,
|
|
45
|
+
themeOverrides,
|
|
46
|
+
className,
|
|
47
|
+
style,
|
|
48
|
+
height
|
|
49
|
+
}) {
|
|
50
|
+
if (root && paths) {
|
|
51
|
+
throw new Error("RichFileTree: pass `root` or `paths`, not both");
|
|
52
|
+
}
|
|
53
|
+
const flatPaths = useMemo(() => {
|
|
54
|
+
if (paths) return Array.from(paths);
|
|
55
|
+
if (root) return flattenFileNode(root);
|
|
56
|
+
return [];
|
|
57
|
+
}, [paths, root]);
|
|
58
|
+
const { model } = usePierreFileTree({
|
|
59
|
+
paths: flatPaths,
|
|
60
|
+
search,
|
|
61
|
+
initialExpansion,
|
|
62
|
+
onSelectionChange: (selected) => {
|
|
63
|
+
const next = selected[0];
|
|
64
|
+
if (next && next !== selectedPath) onSelect?.(next);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!gitStatus) return;
|
|
69
|
+
model.setGitStatus(gitStatus);
|
|
70
|
+
}, [model, gitStatus]);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
model.resetPaths(flatPaths);
|
|
73
|
+
}, [model, flatPaths]);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (!selectedPath) return;
|
|
76
|
+
const current = model.getSelectedPaths();
|
|
77
|
+
if (current.length === 1 && current[0] === selectedPath) return;
|
|
78
|
+
const m = model;
|
|
79
|
+
m.setSelectedPaths?.([selectedPath]);
|
|
80
|
+
}, [model, selectedPath]);
|
|
81
|
+
const theme = { ...DEFAULT_THEME, ...themeOverrides };
|
|
82
|
+
const themeStyle = useMemo(
|
|
83
|
+
() => ({
|
|
84
|
+
["--trees-selected-bg-override"]: theme.selectedBg,
|
|
85
|
+
["--trees-selected-fg-override"]: theme.selectedFg,
|
|
86
|
+
["--trees-fg-override"]: theme.fg,
|
|
87
|
+
["--trees-hover-bg-override"]: theme.hoverBg,
|
|
88
|
+
["--trees-border-color-override"]: theme.border,
|
|
89
|
+
["--trees-muted-fg-override"]: theme.mutedFg,
|
|
90
|
+
height: height ?? "100%",
|
|
91
|
+
...style
|
|
92
|
+
}),
|
|
93
|
+
[theme, height, style]
|
|
94
|
+
);
|
|
95
|
+
return /* @__PURE__ */ jsx(
|
|
96
|
+
PierreFileTree,
|
|
97
|
+
{
|
|
98
|
+
model,
|
|
99
|
+
header,
|
|
100
|
+
renderContextMenu,
|
|
101
|
+
className,
|
|
102
|
+
style: themeStyle
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
RichFileTree
|
|
109
|
+
};
|