reifyui 0.18.5 → 0.19.1
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/README.md +43 -0
- package/dist/index.cjs +128 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +122 -8
- package/dist/index.js.map +1 -1
- package/dist/tree.cjs +1159 -0
- package/dist/tree.cjs.map +1 -0
- package/dist/tree.d.ts +178 -0
- package/dist/tree.js +1129 -0
- package/dist/tree.js.map +1 -0
- package/package.json +9 -1
- package/src/auth/AuthForm.jsx +2 -0
- package/src/auth/client.js +34 -4
- package/src/auth/personCheck.js +98 -0
- package/src/index.d.ts +7 -1
- package/src/index.js +2 -1
- package/src/tree/FileTree.jsx +668 -0
- package/src/tree/index.d.ts +178 -0
- package/src/tree/index.js +14 -0
- package/src/tree/model.js +220 -0
- package/styles/tree.css +199 -0
package/dist/tree.cjs
ADDED
|
@@ -0,0 +1,1159 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/tree/index.js
|
|
30
|
+
var tree_exports = {};
|
|
31
|
+
__export(tree_exports, {
|
|
32
|
+
DEFAULT_TREE_LABELS: () => DEFAULT_TREE_LABELS,
|
|
33
|
+
FileTree: () => FileTree,
|
|
34
|
+
baseName: () => baseName,
|
|
35
|
+
buildFileTree: () => buildFileTree,
|
|
36
|
+
canMove: () => canMove,
|
|
37
|
+
folderPaths: () => folderPaths,
|
|
38
|
+
isWithin: () => isWithin,
|
|
39
|
+
joinPath: () => joinPath,
|
|
40
|
+
movedPath: () => movedPath,
|
|
41
|
+
nameProblem: () => nameProblem,
|
|
42
|
+
normalizePath: () => normalizePath,
|
|
43
|
+
parentOf: () => parentOf,
|
|
44
|
+
splitExt: () => splitExt,
|
|
45
|
+
treeKeyAction: () => treeKeyAction,
|
|
46
|
+
visibleRows: () => visibleRows
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(tree_exports);
|
|
49
|
+
|
|
50
|
+
// src/tree/FileTree.jsx
|
|
51
|
+
var import_react = __toESM(require("react"), 1);
|
|
52
|
+
var import_react_dom = require("react-dom");
|
|
53
|
+
|
|
54
|
+
// src/tree/model.js
|
|
55
|
+
var parentOf = (p) => {
|
|
56
|
+
const i = p.lastIndexOf("/");
|
|
57
|
+
return i < 0 ? "" : p.slice(0, i);
|
|
58
|
+
};
|
|
59
|
+
var baseName = (p) => p.slice(p.lastIndexOf("/") + 1);
|
|
60
|
+
var joinPath = (dir, name) => dir ? `${dir}/${name}` : name;
|
|
61
|
+
var isWithin = (p, dir) => p === dir || p.startsWith(dir + "/");
|
|
62
|
+
function normalizePath(raw) {
|
|
63
|
+
return String(raw ?? "").replace(/\\/g, "/").replace(/\/{2,}/g, "/").replace(/^\/+|\/+$/g, "");
|
|
64
|
+
}
|
|
65
|
+
function splitExt(name) {
|
|
66
|
+
const i = name.lastIndexOf(".");
|
|
67
|
+
return i <= 0 ? [name, ""] : [name.slice(0, i), name.slice(i)];
|
|
68
|
+
}
|
|
69
|
+
var byName = (a, b) => a.kind !== b.kind ? a.kind === "dir" ? -1 : 1 : a.name.localeCompare(b.name, void 0, { numeric: true, sensitivity: "base" }) || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
70
|
+
function buildFileTree(entries) {
|
|
71
|
+
const root = { path: "", name: "", kind: "dir", depth: 0, children: [], files: 0 };
|
|
72
|
+
const byPath = /* @__PURE__ */ new Map([["", root]]);
|
|
73
|
+
const ensureDir = (path) => {
|
|
74
|
+
const hit = byPath.get(path);
|
|
75
|
+
if (hit) {
|
|
76
|
+
if (hit.kind === "dir") return hit;
|
|
77
|
+
hit.kind = "dir";
|
|
78
|
+
hit.children = [];
|
|
79
|
+
hit.files = 0;
|
|
80
|
+
delete hit.note;
|
|
81
|
+
return hit;
|
|
82
|
+
}
|
|
83
|
+
const parent = ensureDir(parentOf(path));
|
|
84
|
+
const node = { path, name: baseName(path), kind: "dir", depth: parent.depth + 1, children: [], files: 0 };
|
|
85
|
+
parent.children.push(node);
|
|
86
|
+
byPath.set(path, node);
|
|
87
|
+
return node;
|
|
88
|
+
};
|
|
89
|
+
for (const e of entries || []) {
|
|
90
|
+
const path = normalizePath(e && e.path);
|
|
91
|
+
if (!path) continue;
|
|
92
|
+
if (e.kind === "dir") {
|
|
93
|
+
const d = ensureDir(path);
|
|
94
|
+
if (e.note) d.note = String(e.note);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (byPath.has(path)) continue;
|
|
98
|
+
const parent = ensureDir(parentOf(path));
|
|
99
|
+
const node = { path, name: baseName(path), kind: "file", depth: parent.depth + 1, children: [], files: 0 };
|
|
100
|
+
if (e.note) node.note = String(e.note);
|
|
101
|
+
parent.children.push(node);
|
|
102
|
+
byPath.set(path, node);
|
|
103
|
+
}
|
|
104
|
+
const finish = (n) => {
|
|
105
|
+
n.children.sort(byName);
|
|
106
|
+
n.files = 0;
|
|
107
|
+
for (const c of n.children) {
|
|
108
|
+
if (c.kind === "dir") {
|
|
109
|
+
finish(c);
|
|
110
|
+
n.files += c.files;
|
|
111
|
+
} else n.files += 1;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
finish(root);
|
|
115
|
+
return { root, nodes: root.children, byPath };
|
|
116
|
+
}
|
|
117
|
+
function folderPaths(tree) {
|
|
118
|
+
const out = [];
|
|
119
|
+
for (const [p, n] of tree.byPath) if (p && n.kind === "dir") out.push(p);
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
function visibleRows(nodes, isOpen) {
|
|
123
|
+
const open = typeof isOpen === "function" ? isOpen : (p) => !!(isOpen && isOpen.has && isOpen.has(p));
|
|
124
|
+
const rows = [];
|
|
125
|
+
const walk = (list) => {
|
|
126
|
+
for (const n of list) {
|
|
127
|
+
const o = n.kind === "dir" && open(n.path);
|
|
128
|
+
rows.push({
|
|
129
|
+
path: n.path,
|
|
130
|
+
name: n.name,
|
|
131
|
+
kind: n.kind,
|
|
132
|
+
depth: n.depth,
|
|
133
|
+
parent: parentOf(n.path),
|
|
134
|
+
open: o,
|
|
135
|
+
hasChildren: n.children.length > 0,
|
|
136
|
+
files: n.files,
|
|
137
|
+
note: n.note
|
|
138
|
+
});
|
|
139
|
+
if (o) walk(n.children);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
walk(nodes || []);
|
|
143
|
+
return rows;
|
|
144
|
+
}
|
|
145
|
+
function treeKeyAction(rows, active, ev, opts = {}) {
|
|
146
|
+
const key = typeof ev === "string" ? ev : ev.key;
|
|
147
|
+
const shift = typeof ev === "object" && !!ev.shiftKey;
|
|
148
|
+
const mod = typeof ev === "object" && !!(ev.ctrlKey || ev.metaKey || ev.altKey);
|
|
149
|
+
if (!rows.length) return null;
|
|
150
|
+
let i = rows.findIndex((r) => r.path === active);
|
|
151
|
+
if (i < 0) i = 0;
|
|
152
|
+
const row = rows[i];
|
|
153
|
+
const editable = opts.editable !== false;
|
|
154
|
+
if (mod && key !== "F10") return null;
|
|
155
|
+
switch (key) {
|
|
156
|
+
case "ArrowDown":
|
|
157
|
+
return i < rows.length - 1 ? { type: "focus", path: rows[i + 1].path } : { type: "focus", path: row.path };
|
|
158
|
+
case "ArrowUp":
|
|
159
|
+
return i > 0 ? { type: "focus", path: rows[i - 1].path } : { type: "focus", path: row.path };
|
|
160
|
+
case "Home":
|
|
161
|
+
return { type: "focus", path: rows[0].path };
|
|
162
|
+
case "End":
|
|
163
|
+
return { type: "focus", path: rows[rows.length - 1].path };
|
|
164
|
+
case "ArrowRight":
|
|
165
|
+
if (row.kind !== "dir") return { type: "none" };
|
|
166
|
+
if (!row.open) return { type: "open", path: row.path };
|
|
167
|
+
return row.hasChildren && rows[i + 1] ? { type: "focus", path: rows[i + 1].path } : { type: "none" };
|
|
168
|
+
case "ArrowLeft":
|
|
169
|
+
if (row.kind === "dir" && row.open) return { type: "close", path: row.path };
|
|
170
|
+
return row.parent ? { type: "focus", path: row.parent } : { type: "none" };
|
|
171
|
+
case "Enter":
|
|
172
|
+
case " ":
|
|
173
|
+
case "Spacebar":
|
|
174
|
+
return { type: "activate", path: row.path, kind: row.kind };
|
|
175
|
+
case "F2":
|
|
176
|
+
return editable ? { type: "rename", path: row.path } : null;
|
|
177
|
+
case "Delete":
|
|
178
|
+
case "Backspace":
|
|
179
|
+
return editable ? { type: "delete", path: row.path } : null;
|
|
180
|
+
case "ContextMenu":
|
|
181
|
+
return editable ? { type: "menu", path: row.path } : null;
|
|
182
|
+
case "F10":
|
|
183
|
+
return shift && editable ? { type: "menu", path: row.path } : null;
|
|
184
|
+
default:
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
var invisible = (s) => Array.from(s).some((c) => {
|
|
189
|
+
const n = c.charCodeAt(0);
|
|
190
|
+
return n < 32 || n === 127;
|
|
191
|
+
});
|
|
192
|
+
var say = (v, ...a) => typeof v === "function" ? v(...a) : v;
|
|
193
|
+
function nameProblem(name, { kind = "file", dir = "", siblings = [], labels = {}, validate } = {}) {
|
|
194
|
+
const L = { ...NAME_LABELS, ...labels };
|
|
195
|
+
const n = String(name ?? "").trim();
|
|
196
|
+
if (!n) return say(L.nameEmpty, kind);
|
|
197
|
+
if (n === "." || n === "..") return say(L.nameDots, kind);
|
|
198
|
+
if (/[\\/]/.test(n)) return say(L.nameSlash, kind);
|
|
199
|
+
if (invisible(n)) return say(L.nameInvisible, kind);
|
|
200
|
+
const lower = n.toLowerCase();
|
|
201
|
+
const sib = Array.from(siblings || []);
|
|
202
|
+
if (sib.some((s) => s === n)) return say(L.nameTaken, n, kind);
|
|
203
|
+
if (sib.some((s) => s.toLowerCase() === lower)) return say(L.nameTaken, sib.find((s) => s.toLowerCase() === lower), kind);
|
|
204
|
+
if (typeof validate === "function") return validate(n, dir, kind) || "";
|
|
205
|
+
return "";
|
|
206
|
+
}
|
|
207
|
+
function canMove(tree, from, toDir) {
|
|
208
|
+
const node = tree.byPath.get(from);
|
|
209
|
+
if (!node || !from) return false;
|
|
210
|
+
const dest = tree.byPath.get(toDir);
|
|
211
|
+
if (!dest || dest.kind !== "dir") return false;
|
|
212
|
+
if (parentOf(from) === toDir) return false;
|
|
213
|
+
if (node.kind === "dir" && isWithin(toDir, from)) return false;
|
|
214
|
+
return !dest.children.some((c) => c.name.toLowerCase() === node.name.toLowerCase());
|
|
215
|
+
}
|
|
216
|
+
var movedPath = (p, from, to) => isWithin(p, from) ? to + p.slice(from.length) : p;
|
|
217
|
+
var NAME_LABELS = {
|
|
218
|
+
nameEmpty: (kind) => kind === "dir" ? "Type a folder name." : "Type a file name.",
|
|
219
|
+
nameDots: "Choose a name other than . or ..",
|
|
220
|
+
nameSlash: "Use a name without a slash.",
|
|
221
|
+
nameInvisible: "Use visible characters only.",
|
|
222
|
+
nameTaken: (name) => `${name} is already here.`
|
|
223
|
+
};
|
|
224
|
+
var DEFAULT_TREE_LABELS = Object.freeze({
|
|
225
|
+
tree: "Files",
|
|
226
|
+
newFile: "New file",
|
|
227
|
+
newFolder: "New folder",
|
|
228
|
+
upload: "Upload files",
|
|
229
|
+
collapseAll: "Collapse all",
|
|
230
|
+
rename: "Rename",
|
|
231
|
+
delete: "Delete",
|
|
232
|
+
keep: "Keep",
|
|
233
|
+
renameKey: "F2",
|
|
234
|
+
deleteKey: "\u232B",
|
|
235
|
+
empty: "No files yet.",
|
|
236
|
+
emptyFolder: "empty",
|
|
237
|
+
loading: "Loading",
|
|
238
|
+
saving: "Saving",
|
|
239
|
+
failed: "That didn\u2019t work. Try again.",
|
|
240
|
+
newFileInput: "Name of the new file",
|
|
241
|
+
newFolderInput: "Name of the new folder",
|
|
242
|
+
renameInput: (name) => `New name for ${name}`,
|
|
243
|
+
confirmFile: (name) => `Delete ${name}?`,
|
|
244
|
+
confirmFolder: (name, files) => files ? `Delete ${name} and the ${files === 1 ? "file" : `${files} files`} in it?` : `Delete ${name}?`,
|
|
245
|
+
menu: (name) => name,
|
|
246
|
+
...NAME_LABELS
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// src/tree/FileTree.jsx
|
|
250
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
251
|
+
var useIsoLayoutEffect = typeof window === "undefined" ? import_react.useEffect : import_react.useLayoutEffect;
|
|
252
|
+
var DRAG_TYPE = "application/x-reifyui-tree-path";
|
|
253
|
+
var OPEN_ON_HOVER_MS = 600;
|
|
254
|
+
var FOCUS_WAIT_MS = 4e3;
|
|
255
|
+
var HEADER_ACTIONS = ["newFile", "newFolder", "upload", "collapseAll"];
|
|
256
|
+
var MENU_VARS = [
|
|
257
|
+
"--_surface",
|
|
258
|
+
"--_ink",
|
|
259
|
+
"--_mute",
|
|
260
|
+
"--_faint",
|
|
261
|
+
"--_line",
|
|
262
|
+
"--_brand",
|
|
263
|
+
"--_hover",
|
|
264
|
+
"--_fail",
|
|
265
|
+
"--_shadow",
|
|
266
|
+
"--_r-menu",
|
|
267
|
+
"--_r-row",
|
|
268
|
+
"--_z",
|
|
269
|
+
"--_fs-md"
|
|
270
|
+
];
|
|
271
|
+
var say2 = (v, ...a) => typeof v === "function" ? v(...a) : v;
|
|
272
|
+
function Svg({ s = 14, children }) {
|
|
273
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
274
|
+
"svg",
|
|
275
|
+
{
|
|
276
|
+
width: s,
|
|
277
|
+
height: s,
|
|
278
|
+
viewBox: "0 0 24 24",
|
|
279
|
+
fill: "none",
|
|
280
|
+
stroke: "currentColor",
|
|
281
|
+
strokeWidth: "1.8",
|
|
282
|
+
strokeLinecap: "round",
|
|
283
|
+
strokeLinejoin: "round",
|
|
284
|
+
"aria-hidden": "true",
|
|
285
|
+
focusable: "false",
|
|
286
|
+
children
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
var I = {
|
|
291
|
+
file: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { children: [
|
|
292
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z" }),
|
|
293
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14 3v5h5" })
|
|
294
|
+
] }),
|
|
295
|
+
folder: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Svg, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" }) }),
|
|
296
|
+
chevron: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Svg, { s: 12, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9 6l6 6-6 6" }) }),
|
|
297
|
+
newFile: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { children: [
|
|
298
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z" }),
|
|
299
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14 3v5h5" }),
|
|
300
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 11v6M9 14h6" })
|
|
301
|
+
] }),
|
|
302
|
+
newFolder: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { children: [
|
|
303
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" }),
|
|
304
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 10.5v5M9.5 13h5" })
|
|
305
|
+
] }),
|
|
306
|
+
upload: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { children: [
|
|
307
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 16V4M7 9l5-5 5 5" }),
|
|
308
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3" })
|
|
309
|
+
] }),
|
|
310
|
+
collapseAll: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Svg, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M7 10l5-5 5 5M7 19l5-5 5 5" }) }),
|
|
311
|
+
pencil: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { children: [
|
|
312
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 20h9" }),
|
|
313
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z" })
|
|
314
|
+
] }),
|
|
315
|
+
trash: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Svg, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4 7h16M9 7V4.5h6V7M18 7l-1 13H7L6 7M10 11v5M14 11v5" }) })
|
|
316
|
+
};
|
|
317
|
+
async function answer(fn, failed) {
|
|
318
|
+
try {
|
|
319
|
+
const r = await fn();
|
|
320
|
+
return typeof r === "string" ? r : "";
|
|
321
|
+
} catch {
|
|
322
|
+
return failed;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function Name({ name }) {
|
|
326
|
+
const [base, ext] = splitExt(name);
|
|
327
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "rui-tree-name", children: [
|
|
328
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-base", children: base }),
|
|
329
|
+
ext ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-ext", children: ext }) : null
|
|
330
|
+
] });
|
|
331
|
+
}
|
|
332
|
+
function TreeMenu({ menu, items, label, tokensFrom, onClose, menuRef }) {
|
|
333
|
+
const [pos, setPos] = (0, import_react.useState)(null);
|
|
334
|
+
const btns = (0, import_react.useRef)([]);
|
|
335
|
+
const style = (0, import_react.useMemo)(() => {
|
|
336
|
+
const s = {};
|
|
337
|
+
const src = tokensFrom.current;
|
|
338
|
+
if (src && typeof getComputedStyle === "function") {
|
|
339
|
+
const cs = getComputedStyle(src);
|
|
340
|
+
for (const v of MENU_VARS) {
|
|
341
|
+
const val = cs.getPropertyValue(v);
|
|
342
|
+
if (val) s[v] = val.trim();
|
|
343
|
+
}
|
|
344
|
+
s.fontFamily = cs.fontFamily;
|
|
345
|
+
}
|
|
346
|
+
return s;
|
|
347
|
+
}, [tokensFrom, menu]);
|
|
348
|
+
useIsoLayoutEffect(() => {
|
|
349
|
+
const el = menuRef.current;
|
|
350
|
+
if (!el) return;
|
|
351
|
+
const r = el.getBoundingClientRect();
|
|
352
|
+
const vw = window.innerWidth, vh = window.innerHeight, m = 8;
|
|
353
|
+
const left = Math.max(m, Math.min(menu.x, vw - r.width - m));
|
|
354
|
+
const top = menu.y + r.height > vh - m ? Math.max(m, menu.y - r.height) : menu.y;
|
|
355
|
+
setPos({ left, top });
|
|
356
|
+
}, [menu]);
|
|
357
|
+
(0, import_react.useEffect)(() => {
|
|
358
|
+
if (pos) btns.current.find((b) => b && !b.disabled)?.focus();
|
|
359
|
+
}, [pos]);
|
|
360
|
+
(0, import_react.useEffect)(() => {
|
|
361
|
+
const down = (e) => {
|
|
362
|
+
if (!menuRef.current?.contains(e.target)) onClose(false);
|
|
363
|
+
};
|
|
364
|
+
const scroll = (e) => {
|
|
365
|
+
if (!menuRef.current?.contains(e.target)) onClose(false);
|
|
366
|
+
};
|
|
367
|
+
const resize = () => onClose(false);
|
|
368
|
+
document.addEventListener("pointerdown", down, true);
|
|
369
|
+
window.addEventListener("scroll", scroll, true);
|
|
370
|
+
window.addEventListener("resize", resize);
|
|
371
|
+
return () => {
|
|
372
|
+
document.removeEventListener("pointerdown", down, true);
|
|
373
|
+
window.removeEventListener("scroll", scroll, true);
|
|
374
|
+
window.removeEventListener("resize", resize);
|
|
375
|
+
};
|
|
376
|
+
}, [onClose, menuRef]);
|
|
377
|
+
const onKeyDown = (e) => {
|
|
378
|
+
const list = btns.current.filter((b) => b && !b.disabled);
|
|
379
|
+
const at = list.indexOf(document.activeElement);
|
|
380
|
+
const go = (i) => {
|
|
381
|
+
e.preventDefault();
|
|
382
|
+
list[(i + list.length) % list.length]?.focus();
|
|
383
|
+
};
|
|
384
|
+
if (e.key === "ArrowDown") go(at + 1);
|
|
385
|
+
else if (e.key === "ArrowUp") go(at < 0 ? list.length - 1 : at - 1);
|
|
386
|
+
else if (e.key === "Home") go(0);
|
|
387
|
+
else if (e.key === "End") go(list.length - 1);
|
|
388
|
+
else if (e.key === "Tab" || e.key === "Escape") {
|
|
389
|
+
e.preventDefault();
|
|
390
|
+
onClose(true);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
btns.current = [];
|
|
394
|
+
let k = 0;
|
|
395
|
+
return (0, import_react_dom.createPortal)(
|
|
396
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
397
|
+
"div",
|
|
398
|
+
{
|
|
399
|
+
ref: menuRef,
|
|
400
|
+
className: "rui-tree-menu",
|
|
401
|
+
role: "menu",
|
|
402
|
+
"aria-label": label,
|
|
403
|
+
onKeyDown,
|
|
404
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
405
|
+
style: { ...style, left: pos ? pos.left : menu.x, top: pos ? pos.top : menu.y, visibility: pos ? "visible" : "hidden" },
|
|
406
|
+
children: items.map((it, i) => it.sep ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "rui-tree-menu-sep", role: "separator" }, `s${i}`) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
407
|
+
"button",
|
|
408
|
+
{
|
|
409
|
+
type: "button",
|
|
410
|
+
role: "menuitem",
|
|
411
|
+
tabIndex: -1,
|
|
412
|
+
ref: (el) => {
|
|
413
|
+
btns.current[k++] = el;
|
|
414
|
+
},
|
|
415
|
+
className: `rui-tree-menu-item${it.danger ? " is-danger" : ""}`,
|
|
416
|
+
disabled: it.disabled,
|
|
417
|
+
"aria-keyshortcuts": it.keys || void 0,
|
|
418
|
+
onClick: () => {
|
|
419
|
+
onClose(false);
|
|
420
|
+
it.run();
|
|
421
|
+
},
|
|
422
|
+
children: [
|
|
423
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-menu-label", children: it.label }),
|
|
424
|
+
it.hint ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kbd", { className: "rui-tree-menu-hint", "aria-hidden": "true", children: it.hint }) : null
|
|
425
|
+
]
|
|
426
|
+
},
|
|
427
|
+
it.id
|
|
428
|
+
))
|
|
429
|
+
}
|
|
430
|
+
),
|
|
431
|
+
document.body
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
function FileTree(props) {
|
|
435
|
+
const {
|
|
436
|
+
entries,
|
|
437
|
+
selected = null,
|
|
438
|
+
onSelect,
|
|
439
|
+
open: openProp,
|
|
440
|
+
defaultOpen = true,
|
|
441
|
+
onOpenChange,
|
|
442
|
+
title,
|
|
443
|
+
label,
|
|
444
|
+
actions,
|
|
445
|
+
labels: labelsProp,
|
|
446
|
+
onCreate,
|
|
447
|
+
onRename,
|
|
448
|
+
onDelete,
|
|
449
|
+
onMove,
|
|
450
|
+
onUpload,
|
|
451
|
+
validateName,
|
|
452
|
+
menuItems,
|
|
453
|
+
readOnly = false,
|
|
454
|
+
busy = false,
|
|
455
|
+
pending,
|
|
456
|
+
rowErrors,
|
|
457
|
+
error,
|
|
458
|
+
className,
|
|
459
|
+
style
|
|
460
|
+
} = props;
|
|
461
|
+
const L = (0, import_react.useMemo)(() => ({ ...DEFAULT_TREE_LABELS, ...labelsProp || {} }), [labelsProp]);
|
|
462
|
+
const uid = (0, import_react.useId)().replace(/:/g, "");
|
|
463
|
+
const rootRef = (0, import_react.useRef)(null);
|
|
464
|
+
const menuRef = (0, import_react.useRef)(null);
|
|
465
|
+
const inputRef = (0, import_react.useRef)(null);
|
|
466
|
+
const askRef = (0, import_react.useRef)(null);
|
|
467
|
+
const tree = (0, import_react.useMemo)(() => buildFileTree(entries), [entries]);
|
|
468
|
+
const editable = !readOnly;
|
|
469
|
+
const controlled = Array.isArray(openProp);
|
|
470
|
+
const [kept, setKept] = (0, import_react.useState)(() => defaultOpen === true ? { all: true, set: /* @__PURE__ */ new Set() } : { all: false, set: new Set(Array.isArray(defaultOpen) ? defaultOpen : []) });
|
|
471
|
+
const keptRef = (0, import_react.useRef)(kept);
|
|
472
|
+
const ctlRef = (0, import_react.useRef)(openProp);
|
|
473
|
+
if (controlled) ctlRef.current = openProp;
|
|
474
|
+
const openSet = (0, import_react.useMemo)(() => controlled ? new Set(openProp) : null, [controlled, openProp]);
|
|
475
|
+
const isOpen = (0, import_react.useCallback)(
|
|
476
|
+
(p) => controlled ? openSet.has(p) : kept.all ? !kept.set.has(p) : kept.set.has(p),
|
|
477
|
+
[controlled, openSet, kept]
|
|
478
|
+
);
|
|
479
|
+
const readOpen = () => controlled ? { all: false, set: new Set(ctlRef.current || []) } : keptRef.current;
|
|
480
|
+
const writeOpen = (next) => {
|
|
481
|
+
if (controlled) {
|
|
482
|
+
const list = Array.from(next.set);
|
|
483
|
+
ctlRef.current = list;
|
|
484
|
+
onOpenChange?.(list);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
keptRef.current = next;
|
|
488
|
+
setKept(next);
|
|
489
|
+
onOpenChange?.(next.all ? folderPaths(tree).filter((p) => !next.set.has(p)) : Array.from(next.set));
|
|
490
|
+
};
|
|
491
|
+
const setOpen = (paths, value) => {
|
|
492
|
+
const cur = readOpen();
|
|
493
|
+
const set = new Set(cur.set);
|
|
494
|
+
let changed = false;
|
|
495
|
+
for (const p of paths) {
|
|
496
|
+
if (!p) continue;
|
|
497
|
+
const inSet = cur.all ? !value : value;
|
|
498
|
+
if (set.has(p) !== inSet) {
|
|
499
|
+
if (inSet) set.add(p);
|
|
500
|
+
else set.delete(p);
|
|
501
|
+
changed = true;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
if (changed) writeOpen({ all: cur.all, set });
|
|
505
|
+
};
|
|
506
|
+
const remapOpen = (from, to) => {
|
|
507
|
+
const cur = readOpen();
|
|
508
|
+
if (!Array.from(cur.set).some((p) => isWithin(p, from))) return;
|
|
509
|
+
writeOpen({ all: cur.all, set: new Set(Array.from(cur.set).map((p) => movedPath(p, from, to))) });
|
|
510
|
+
};
|
|
511
|
+
const collapseAll = () => {
|
|
512
|
+
writeOpen({ all: false, set: /* @__PURE__ */ new Set() });
|
|
513
|
+
if (active) setActive(active.split("/")[0]);
|
|
514
|
+
};
|
|
515
|
+
const rows = (0, import_react.useMemo)(() => visibleRows(tree.nodes, isOpen), [tree, isOpen]);
|
|
516
|
+
const [active, setActive] = (0, import_react.useState)(null);
|
|
517
|
+
const pendingFocus = (0, import_react.useRef)(null);
|
|
518
|
+
const focusSoon = (path) => {
|
|
519
|
+
pendingFocus.current = { path, at: Date.now() };
|
|
520
|
+
setActive(path);
|
|
521
|
+
};
|
|
522
|
+
const tabPath = (0, import_react.useMemo)(() => {
|
|
523
|
+
const has = (p) => rows.some((r) => r.path === p);
|
|
524
|
+
for (let p = active; p; p = parentOf(p)) if (has(p)) return p;
|
|
525
|
+
if (selected && has(selected)) return selected;
|
|
526
|
+
return rows[0]?.path ?? null;
|
|
527
|
+
}, [rows, active, selected]);
|
|
528
|
+
const tabPathRef = (0, import_react.useRef)(tabPath);
|
|
529
|
+
tabPathRef.current = tabPath;
|
|
530
|
+
(0, import_react.useEffect)(() => {
|
|
531
|
+
const want = pendingFocus.current;
|
|
532
|
+
if (!want) return;
|
|
533
|
+
if (Date.now() - want.at > FOCUS_WAIT_MS) {
|
|
534
|
+
pendingFocus.current = null;
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
const root = rootRef.current;
|
|
538
|
+
if (!root) return;
|
|
539
|
+
const here = document.activeElement;
|
|
540
|
+
if (here && here !== document.body && !root.contains(here)) {
|
|
541
|
+
pendingFocus.current = null;
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
const el = Array.from(root.querySelectorAll('[role="treeitem"][data-path]')).find((x) => x.dataset.path === want.path);
|
|
545
|
+
if (el) {
|
|
546
|
+
pendingFocus.current = null;
|
|
547
|
+
el.focus();
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
(0, import_react.useEffect)(() => {
|
|
551
|
+
if (!selected) return;
|
|
552
|
+
const up = [];
|
|
553
|
+
for (let p = parentOf(selected); p; p = parentOf(p)) if (tree.byPath.get(p)?.kind === "dir" && !isOpen(p)) up.push(p);
|
|
554
|
+
if (up.length) setOpen(up, true);
|
|
555
|
+
}, [selected]);
|
|
556
|
+
const [edit, setEditState] = (0, import_react.useState)(null);
|
|
557
|
+
const editRef = (0, import_react.useRef)(null);
|
|
558
|
+
const setEdit = (x) => {
|
|
559
|
+
editRef.current = x;
|
|
560
|
+
setEditState(x);
|
|
561
|
+
};
|
|
562
|
+
const returnTo = (0, import_react.useRef)(null);
|
|
563
|
+
const [ask, setAsk] = (0, import_react.useState)(null);
|
|
564
|
+
const [menu, setMenu] = (0, import_react.useState)(null);
|
|
565
|
+
const [notes, setNotes] = (0, import_react.useState)({});
|
|
566
|
+
const note = (path, msg) => setNotes((n) => {
|
|
567
|
+
const x = { ...n };
|
|
568
|
+
if (msg) x[path] = msg;
|
|
569
|
+
else delete x[path];
|
|
570
|
+
return x;
|
|
571
|
+
});
|
|
572
|
+
const nodeKind = (p) => tree.byPath.get(p)?.kind;
|
|
573
|
+
const existingDir = (d) => {
|
|
574
|
+
let x = d || "";
|
|
575
|
+
while (x && nodeKind(x) !== "dir") x = parentOf(x);
|
|
576
|
+
return x;
|
|
577
|
+
};
|
|
578
|
+
const targetDir = () => {
|
|
579
|
+
const from = active !== null ? active : selected;
|
|
580
|
+
if (!from) return "";
|
|
581
|
+
return existingDir(nodeKind(from) === "dir" ? from : parentOf(from));
|
|
582
|
+
};
|
|
583
|
+
const childNames = (dir) => (tree.byPath.get(dir)?.children || []).map((c) => c.name);
|
|
584
|
+
const hold = busy;
|
|
585
|
+
function dropEdit() {
|
|
586
|
+
if (!editRef.current?.busy) setEdit(null);
|
|
587
|
+
}
|
|
588
|
+
function closeAll() {
|
|
589
|
+
dropEdit();
|
|
590
|
+
setAsk(null);
|
|
591
|
+
setMenu(null);
|
|
592
|
+
}
|
|
593
|
+
function startCreate(kind, dir) {
|
|
594
|
+
if (!editable || !onCreate || hold || editRef.current?.busy) return;
|
|
595
|
+
setAsk(null);
|
|
596
|
+
setMenu(null);
|
|
597
|
+
returnTo.current = typeof document !== "undefined" ? document.activeElement : null;
|
|
598
|
+
dir = existingDir(dir);
|
|
599
|
+
if (dir) setOpen([...ancestorsOf(dir), dir], true);
|
|
600
|
+
setEdit({ mode: "create", kind, dir, value: "", err: "", busy: false });
|
|
601
|
+
}
|
|
602
|
+
function startRename(path) {
|
|
603
|
+
if (!editable || !onRename || hold || editRef.current?.busy || !tree.byPath.has(path)) return;
|
|
604
|
+
setAsk(null);
|
|
605
|
+
setMenu(null);
|
|
606
|
+
setEdit({ mode: "rename", path, kind: nodeKind(path), value: baseName(path), err: "", busy: false });
|
|
607
|
+
setActive(path);
|
|
608
|
+
}
|
|
609
|
+
function askDelete(path) {
|
|
610
|
+
if (!editable || !onDelete || hold) return;
|
|
611
|
+
const n = tree.byPath.get(path);
|
|
612
|
+
if (!n) return;
|
|
613
|
+
dropEdit();
|
|
614
|
+
setMenu(null);
|
|
615
|
+
setAsk({ path, kind: n.kind, files: n.files, busy: false });
|
|
616
|
+
setActive(path);
|
|
617
|
+
}
|
|
618
|
+
async function commitEdit(fromBlur) {
|
|
619
|
+
const ed = editRef.current;
|
|
620
|
+
if (!ed || ed.busy) return;
|
|
621
|
+
const value = ed.value.trim();
|
|
622
|
+
const same = ed.mode === "rename" && value === baseName(ed.path);
|
|
623
|
+
if (same || fromBlur && !value) {
|
|
624
|
+
setEdit(null);
|
|
625
|
+
if (!fromBlur) {
|
|
626
|
+
if (ed.mode === "rename") focusSoon(ed.path);
|
|
627
|
+
else restoreFocus();
|
|
628
|
+
}
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
const dir = ed.mode === "create" ? ed.dir : parentOf(ed.path);
|
|
632
|
+
const siblings = childNames(dir).filter((n) => ed.mode !== "rename" || n !== baseName(ed.path));
|
|
633
|
+
const err = nameProblem(value, { kind: ed.kind, dir, siblings, labels: L, validate: validateName });
|
|
634
|
+
if (err) {
|
|
635
|
+
setEdit({ ...ed, err });
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
const to = joinPath(dir, value);
|
|
639
|
+
const going = { ...ed, err: "", busy: true };
|
|
640
|
+
setEdit(going);
|
|
641
|
+
const refused = await answer(() => ed.mode === "create" ? onCreate({ path: to, kind: ed.kind }) : onRename({ from: ed.path, to, kind: ed.kind }), L.failed);
|
|
642
|
+
if (editRef.current !== going) return;
|
|
643
|
+
if (refused) {
|
|
644
|
+
setEdit({ ...going, busy: false, err: refused });
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
setEdit(null);
|
|
648
|
+
if (ed.mode === "rename" && ed.kind === "dir") remapOpen(ed.path, to);
|
|
649
|
+
if (ed.mode === "create" && ed.kind === "dir") setOpen([to], true);
|
|
650
|
+
if (fromBlur) setActive(to);
|
|
651
|
+
else focusSoon(to);
|
|
652
|
+
}
|
|
653
|
+
async function confirmDelete() {
|
|
654
|
+
const a = ask;
|
|
655
|
+
if (!a || a.busy) return;
|
|
656
|
+
const i = rows.findIndex((r) => r.path === a.path);
|
|
657
|
+
const after = rows.slice(i + 1).find((r) => !isWithin(r.path, a.path));
|
|
658
|
+
const next = after && parentOf(after.path) === parentOf(a.path) ? after.path : rows[i - 1]?.path ?? after?.path ?? null;
|
|
659
|
+
const going = { ...a, busy: true };
|
|
660
|
+
setAsk(going);
|
|
661
|
+
const refused = await answer(() => onDelete({ path: a.path, kind: a.kind }), L.failed);
|
|
662
|
+
setAsk((cur) => cur && cur.path === a.path ? null : cur);
|
|
663
|
+
if (refused) {
|
|
664
|
+
note(a.path, refused);
|
|
665
|
+
focusSoon(a.path);
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
note(a.path, "");
|
|
669
|
+
if (next !== null) focusSoon(next);
|
|
670
|
+
else setActive(null);
|
|
671
|
+
}
|
|
672
|
+
async function doMove(from, kind, toDir) {
|
|
673
|
+
const to = joinPath(toDir, baseName(from));
|
|
674
|
+
note(from, "");
|
|
675
|
+
const refused = await answer(() => onMove({ from, toDir, kind }), L.failed);
|
|
676
|
+
if (refused) {
|
|
677
|
+
note(from, refused);
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
if (kind === "dir") remapOpen(from, to);
|
|
681
|
+
if (toDir) setOpen([...ancestorsOf(toDir), toDir], true);
|
|
682
|
+
setActive(to);
|
|
683
|
+
}
|
|
684
|
+
function restoreFocus() {
|
|
685
|
+
const el = returnTo.current;
|
|
686
|
+
returnTo.current = null;
|
|
687
|
+
if (el && el.isConnected && rootRef.current?.contains(el)) el.focus();
|
|
688
|
+
else if (tabPath) focusSoon(tabPath);
|
|
689
|
+
}
|
|
690
|
+
(0, import_react.useEffect)(() => {
|
|
691
|
+
if (!edit && !ask && !menu) return void 0;
|
|
692
|
+
const onKey = (e) => {
|
|
693
|
+
if (e.key !== "Escape") return;
|
|
694
|
+
const t = e.target;
|
|
695
|
+
if (!(rootRef.current?.contains(t) || menuRef.current?.contains(t))) return;
|
|
696
|
+
e.stopPropagation();
|
|
697
|
+
e.preventDefault();
|
|
698
|
+
if (menu) {
|
|
699
|
+
setMenu(null);
|
|
700
|
+
focusSoon(menu.path || tabPath);
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
if (editRef.current) {
|
|
704
|
+
const ed = editRef.current;
|
|
705
|
+
if (ed.busy) return;
|
|
706
|
+
setEdit(null);
|
|
707
|
+
if (ed.mode === "rename") focusSoon(ed.path);
|
|
708
|
+
else restoreFocus();
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
if (ask) {
|
|
712
|
+
setAsk(null);
|
|
713
|
+
focusSoon(ask.path);
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
window.addEventListener("keydown", onKey, true);
|
|
717
|
+
return () => window.removeEventListener("keydown", onKey, true);
|
|
718
|
+
});
|
|
719
|
+
(0, import_react.useEffect)(() => {
|
|
720
|
+
const el = inputRef.current;
|
|
721
|
+
if (!el || !edit) return;
|
|
722
|
+
el.focus();
|
|
723
|
+
const v = el.value;
|
|
724
|
+
const dot = edit.mode === "rename" && edit.kind === "file" ? splitExt(v)[0].length : v.length;
|
|
725
|
+
el.setSelectionRange(edit.mode === "rename" ? 0 : v.length, dot);
|
|
726
|
+
}, [edit?.mode, edit?.path, edit?.dir, edit?.kind]);
|
|
727
|
+
(0, import_react.useEffect)(() => {
|
|
728
|
+
if (ask && !ask.busy) askRef.current?.focus();
|
|
729
|
+
}, [ask?.path]);
|
|
730
|
+
const itemsFor = (path, kind) => {
|
|
731
|
+
const at = kind === "dir" ? path : parentOf(path);
|
|
732
|
+
const groups = [[], [], []];
|
|
733
|
+
if (onCreate) {
|
|
734
|
+
groups[0].push({ id: "new-file", label: L.newFile, run: () => startCreate("file", at) });
|
|
735
|
+
groups[0].push({ id: "new-folder", label: L.newFolder, run: () => startCreate("dir", at) });
|
|
736
|
+
}
|
|
737
|
+
if (path) {
|
|
738
|
+
if (onRename) groups[1].push({ id: "rename", label: L.rename, hint: L.renameKey, keys: "F2", run: () => startRename(path) });
|
|
739
|
+
for (const m of menuItems || []) {
|
|
740
|
+
if (m.when && !m.when(path, kind)) continue;
|
|
741
|
+
groups[1].push({ id: `x-${m.id}`, label: m.label, disabled: !!m.disabled, run: () => {
|
|
742
|
+
focusSoon(path);
|
|
743
|
+
m.onSelect(path, kind);
|
|
744
|
+
} });
|
|
745
|
+
}
|
|
746
|
+
if (onDelete) groups[2].push({ id: "delete", label: L.delete, hint: L.deleteKey, keys: "Delete", danger: true, run: () => askDelete(path) });
|
|
747
|
+
}
|
|
748
|
+
const out = [];
|
|
749
|
+
for (const g of groups) {
|
|
750
|
+
if (!g.length) continue;
|
|
751
|
+
if (out.length) out.push({ sep: true });
|
|
752
|
+
out.push(...g);
|
|
753
|
+
}
|
|
754
|
+
return out;
|
|
755
|
+
};
|
|
756
|
+
function openMenu(path, kind, x, y) {
|
|
757
|
+
if (!editable || hold) return false;
|
|
758
|
+
if (!itemsFor(path, kind).length) return false;
|
|
759
|
+
dropEdit();
|
|
760
|
+
setAsk(null);
|
|
761
|
+
setMenu({ path, kind, x, y });
|
|
762
|
+
if (path) setActive(path);
|
|
763
|
+
return true;
|
|
764
|
+
}
|
|
765
|
+
const menuNow = (0, import_react.useRef)(null);
|
|
766
|
+
menuNow.current = menu;
|
|
767
|
+
const closeMenu = (0, import_react.useCallback)((refocus) => {
|
|
768
|
+
const m = menuNow.current;
|
|
769
|
+
if (!m) return;
|
|
770
|
+
if (refocus) pendingFocus.current = { path: m.path || tabPathRef.current, at: Date.now() };
|
|
771
|
+
setMenu(null);
|
|
772
|
+
}, []);
|
|
773
|
+
function menuFromKeyboard(path) {
|
|
774
|
+
const el = rowEl(path);
|
|
775
|
+
const r = el ? el.getBoundingClientRect() : { left: 0, bottom: 0 };
|
|
776
|
+
openMenu(path, nodeKind(path), Math.round(r.left + 24), Math.round(r.bottom));
|
|
777
|
+
}
|
|
778
|
+
const rowEl = (path) => Array.from(rootRef.current?.querySelectorAll("[data-row]") || []).find((x) => x.dataset.row === path);
|
|
779
|
+
function onTreeKeyDown(e) {
|
|
780
|
+
const t = e.target;
|
|
781
|
+
if (t.closest("input, button, .rui-tree-ask")) return;
|
|
782
|
+
const item = t.closest('[role="treeitem"]');
|
|
783
|
+
if (!item || item.dataset.path === void 0) return;
|
|
784
|
+
const act = treeKeyAction(rows, item.dataset.path, e, { editable });
|
|
785
|
+
if (!act) return;
|
|
786
|
+
e.preventDefault();
|
|
787
|
+
switch (act.type) {
|
|
788
|
+
case "focus":
|
|
789
|
+
focusSoon(act.path);
|
|
790
|
+
break;
|
|
791
|
+
case "open":
|
|
792
|
+
setOpen([act.path], true);
|
|
793
|
+
break;
|
|
794
|
+
case "close":
|
|
795
|
+
setOpen([act.path], false);
|
|
796
|
+
break;
|
|
797
|
+
case "activate":
|
|
798
|
+
closeAll();
|
|
799
|
+
onSelect?.(act.path, act.kind);
|
|
800
|
+
if (act.kind === "dir") setOpen([act.path], !isOpen(act.path));
|
|
801
|
+
break;
|
|
802
|
+
case "rename":
|
|
803
|
+
startRename(act.path);
|
|
804
|
+
break;
|
|
805
|
+
case "delete":
|
|
806
|
+
askDelete(act.path);
|
|
807
|
+
break;
|
|
808
|
+
case "menu":
|
|
809
|
+
menuFromKeyboard(act.path);
|
|
810
|
+
break;
|
|
811
|
+
default:
|
|
812
|
+
break;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
function onRowClick(r) {
|
|
816
|
+
if (editRef.current?.mode === "rename" && editRef.current.path === r.path) return;
|
|
817
|
+
dropEdit();
|
|
818
|
+
setAsk(null);
|
|
819
|
+
setActive(r.path);
|
|
820
|
+
onSelect?.(r.path, r.kind);
|
|
821
|
+
if (r.kind === "dir") setOpen([r.path], !isOpen(r.path));
|
|
822
|
+
}
|
|
823
|
+
const dragRef = (0, import_react.useRef)(null);
|
|
824
|
+
const [dragging, setDragging] = (0, import_react.useState)(null);
|
|
825
|
+
const [dropDir, setDropDirState] = (0, import_react.useState)(null);
|
|
826
|
+
const dropRef = (0, import_react.useRef)(null);
|
|
827
|
+
const hoverTimer = (0, import_react.useRef)(null);
|
|
828
|
+
const setDropDir = (d) => {
|
|
829
|
+
if (dropRef.current === d) return;
|
|
830
|
+
dropRef.current = d;
|
|
831
|
+
setDropDirState(d);
|
|
832
|
+
clearTimeout(hoverTimer.current);
|
|
833
|
+
if (d && !isOpen(d)) hoverTimer.current = setTimeout(() => {
|
|
834
|
+
if (dropRef.current === d) setOpen([d], true);
|
|
835
|
+
}, OPEN_ON_HOVER_MS);
|
|
836
|
+
};
|
|
837
|
+
(0, import_react.useEffect)(() => () => clearTimeout(hoverTimer.current), []);
|
|
838
|
+
const canDrag = editable && !!onMove && !hold;
|
|
839
|
+
const overDir = (e, dir) => {
|
|
840
|
+
const d = dragRef.current;
|
|
841
|
+
if (!d) return;
|
|
842
|
+
e.stopPropagation();
|
|
843
|
+
if (canMove(tree, d.path, dir)) {
|
|
844
|
+
e.preventDefault();
|
|
845
|
+
e.dataTransfer.dropEffect = "move";
|
|
846
|
+
setDropDir(dir);
|
|
847
|
+
} else {
|
|
848
|
+
e.dataTransfer.dropEffect = "none";
|
|
849
|
+
setDropDir(null);
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
const dropOn = (e, dir) => {
|
|
853
|
+
const d = dragRef.current;
|
|
854
|
+
if (!d) return;
|
|
855
|
+
e.preventDefault();
|
|
856
|
+
e.stopPropagation();
|
|
857
|
+
dragRef.current = null;
|
|
858
|
+
setDragging(null);
|
|
859
|
+
setDropDir(null);
|
|
860
|
+
if (canMove(tree, d.path, dir)) void doMove(d.path, d.kind, dir);
|
|
861
|
+
};
|
|
862
|
+
const endDrag = () => {
|
|
863
|
+
dragRef.current = null;
|
|
864
|
+
setDragging(null);
|
|
865
|
+
setDropDir(null);
|
|
866
|
+
};
|
|
867
|
+
const wanted = Array.isArray(actions) ? actions : HEADER_ACTIONS;
|
|
868
|
+
const offered = wanted.filter((a) => a === "collapseAll" ? true : !editable ? false : a === "upload" ? !!onUpload : a === "newFile" || a === "newFolder" ? !!onCreate : false);
|
|
869
|
+
const headerAction = {
|
|
870
|
+
newFile: { label: L.newFile, icon: I.newFile, run: () => startCreate("file", targetDir()), mutates: true },
|
|
871
|
+
newFolder: { label: L.newFolder, icon: I.newFolder, run: () => startCreate("dir", targetDir()), mutates: true },
|
|
872
|
+
upload: { label: L.upload, icon: I.upload, run: () => onUpload(targetDir()), mutates: true },
|
|
873
|
+
collapseAll: { label: L.collapseAll, icon: I.collapseAll, run: collapseAll, mutates: false }
|
|
874
|
+
};
|
|
875
|
+
const pendingSet = (0, import_react.useMemo)(() => new Set(pending || []), [pending]);
|
|
876
|
+
const errs = rowErrors || {};
|
|
877
|
+
const depthStyle = (depth) => ({ "--rui-tree-d": depth });
|
|
878
|
+
let msgN = 0;
|
|
879
|
+
const entryRow = (dir, depth) => {
|
|
880
|
+
const ed = edit;
|
|
881
|
+
const errId = `${uid}-new-err`;
|
|
882
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
883
|
+
"li",
|
|
884
|
+
{
|
|
885
|
+
role: "treeitem",
|
|
886
|
+
"aria-level": depth,
|
|
887
|
+
"aria-selected": false,
|
|
888
|
+
className: "rui-tree-item is-new",
|
|
889
|
+
"aria-label": ed.kind === "dir" ? L.newFolderInput : L.newFileInput,
|
|
890
|
+
children: [
|
|
891
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "rui-tree-row is-editing", style: depthStyle(depth - 1), children: [
|
|
892
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-twisty", "aria-hidden": "true" }),
|
|
893
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-icon", "aria-hidden": "true", children: ed.kind === "dir" ? I.folder : I.file }),
|
|
894
|
+
nameInput(ed, ed.kind === "dir" ? L.newFolderInput : L.newFileInput, errId)
|
|
895
|
+
] }),
|
|
896
|
+
ed.err ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "rui-tree-msg is-error", id: errId, role: "alert", style: depthStyle(depth - 1), children: ed.err }) : null
|
|
897
|
+
]
|
|
898
|
+
},
|
|
899
|
+
"__rui-tree-new"
|
|
900
|
+
);
|
|
901
|
+
};
|
|
902
|
+
function nameInput(ed, aria, errId) {
|
|
903
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
904
|
+
"input",
|
|
905
|
+
{
|
|
906
|
+
ref: inputRef,
|
|
907
|
+
className: "rui-tree-input",
|
|
908
|
+
value: ed.value,
|
|
909
|
+
"aria-label": aria,
|
|
910
|
+
autoComplete: "off",
|
|
911
|
+
spellCheck: false,
|
|
912
|
+
readOnly: ed.busy,
|
|
913
|
+
"aria-busy": ed.busy || void 0,
|
|
914
|
+
"aria-invalid": !!ed.err,
|
|
915
|
+
"aria-describedby": ed.err ? errId : void 0,
|
|
916
|
+
onClick: (e) => e.stopPropagation(),
|
|
917
|
+
onDoubleClick: (e) => e.stopPropagation(),
|
|
918
|
+
onChange: (e) => setEdit({ ...ed, value: e.target.value, err: "" }),
|
|
919
|
+
onKeyDown: (e) => {
|
|
920
|
+
if (e.key === "Enter") {
|
|
921
|
+
e.preventDefault();
|
|
922
|
+
void commitEdit(false);
|
|
923
|
+
}
|
|
924
|
+
},
|
|
925
|
+
onBlur: () => {
|
|
926
|
+
if (editRef.current) void commitEdit(true);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
);
|
|
930
|
+
}
|
|
931
|
+
function renderNode(n) {
|
|
932
|
+
const r = { path: n.path, kind: n.kind, depth: n.depth };
|
|
933
|
+
const isDir = n.kind === "dir";
|
|
934
|
+
const open = isDir && isOpen(n.path);
|
|
935
|
+
const renaming = edit && edit.mode === "rename" && edit.path === n.path;
|
|
936
|
+
const asking = ask && ask.path === n.path;
|
|
937
|
+
const sel = selected === n.path;
|
|
938
|
+
const busyRow = pendingSet.has(n.path);
|
|
939
|
+
const msg = errs[n.path] || notes[n.path] || "";
|
|
940
|
+
const msgId = msg ? `${uid}-m${msgN++}` : void 0;
|
|
941
|
+
const errId = `${uid}-ren-err`;
|
|
942
|
+
const creatingHere = edit && edit.mode === "create" && isDir && edit.dir === n.path;
|
|
943
|
+
const kids = open ? n.children : [];
|
|
944
|
+
const cls = [
|
|
945
|
+
"rui-tree-row",
|
|
946
|
+
sel ? "is-selected" : "",
|
|
947
|
+
isDir && active === n.path ? "is-target" : "",
|
|
948
|
+
menu && menu.path === n.path ? "is-menu" : "",
|
|
949
|
+
busyRow ? "is-pending" : "",
|
|
950
|
+
renaming ? "is-editing" : "",
|
|
951
|
+
dragging === n.path ? "is-dragging" : ""
|
|
952
|
+
].filter(Boolean).join(" ");
|
|
953
|
+
const showActs = editable && !renaming && !busyRow && (onRename || onDelete);
|
|
954
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
955
|
+
"li",
|
|
956
|
+
{
|
|
957
|
+
role: "treeitem",
|
|
958
|
+
"data-path": n.path,
|
|
959
|
+
"aria-level": n.depth,
|
|
960
|
+
"aria-expanded": isDir ? open : void 0,
|
|
961
|
+
"aria-selected": sel,
|
|
962
|
+
"aria-busy": busyRow || void 0,
|
|
963
|
+
"aria-describedby": msgId,
|
|
964
|
+
tabIndex: tabPath === n.path ? 0 : -1,
|
|
965
|
+
className: `rui-tree-item${dropDir === n.path ? " is-drop" : ""}`,
|
|
966
|
+
children: [
|
|
967
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
968
|
+
"div",
|
|
969
|
+
{
|
|
970
|
+
className: cls,
|
|
971
|
+
"data-row": n.path,
|
|
972
|
+
style: depthStyle(n.depth - 1),
|
|
973
|
+
title: n.path,
|
|
974
|
+
draggable: canDrag && !renaming ? true : void 0,
|
|
975
|
+
onClick: () => onRowClick(r),
|
|
976
|
+
onContextMenu: (e) => {
|
|
977
|
+
if (openMenu(n.path, n.kind, e.clientX, e.clientY)) e.preventDefault();
|
|
978
|
+
e.stopPropagation();
|
|
979
|
+
},
|
|
980
|
+
onDragStart: canDrag ? (e) => {
|
|
981
|
+
closeAll();
|
|
982
|
+
dragRef.current = { path: n.path, kind: n.kind };
|
|
983
|
+
setDragging(n.path);
|
|
984
|
+
e.dataTransfer.effectAllowed = "move";
|
|
985
|
+
try {
|
|
986
|
+
e.dataTransfer.setData(DRAG_TYPE, n.path);
|
|
987
|
+
e.dataTransfer.setData("text/plain", n.path);
|
|
988
|
+
} catch {
|
|
989
|
+
}
|
|
990
|
+
} : void 0,
|
|
991
|
+
onDragEnd: canDrag ? endDrag : void 0,
|
|
992
|
+
onDragEnter: (e) => overDir(e, isDir ? n.path : parentOf(n.path)),
|
|
993
|
+
onDragOver: (e) => overDir(e, isDir ? n.path : parentOf(n.path)),
|
|
994
|
+
onDrop: (e) => dropOn(e, isDir ? n.path : parentOf(n.path)),
|
|
995
|
+
children: [
|
|
996
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `rui-tree-twisty${open ? " is-open" : ""}`, "aria-hidden": "true", children: isDir ? I.chevron : null }),
|
|
997
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-icon", "aria-hidden": "true", children: isDir ? I.folder : I.file }),
|
|
998
|
+
renaming ? nameInput(edit, say2(L.renameInput, n.name), errId) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Name, { name: n.name }),
|
|
999
|
+
!renaming && n.note ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-note", children: n.note }) : null,
|
|
1000
|
+
!renaming && isDir && !n.children.length ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-tag", children: L.emptyFolder }) : null,
|
|
1001
|
+
busyRow ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-spin", role: "status", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-sr", children: L.saving }) }) : null,
|
|
1002
|
+
showActs ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "rui-tree-acts", "aria-hidden": "true", children: [
|
|
1003
|
+
onRename ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1004
|
+
"button",
|
|
1005
|
+
{
|
|
1006
|
+
type: "button",
|
|
1007
|
+
className: "rui-tree-ib",
|
|
1008
|
+
tabIndex: -1,
|
|
1009
|
+
title: L.rename,
|
|
1010
|
+
disabled: hold,
|
|
1011
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
1012
|
+
onClick: (e) => {
|
|
1013
|
+
e.stopPropagation();
|
|
1014
|
+
startRename(n.path);
|
|
1015
|
+
},
|
|
1016
|
+
children: I.pencil
|
|
1017
|
+
}
|
|
1018
|
+
) : null,
|
|
1019
|
+
onDelete ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1020
|
+
"button",
|
|
1021
|
+
{
|
|
1022
|
+
type: "button",
|
|
1023
|
+
className: "rui-tree-ib",
|
|
1024
|
+
tabIndex: -1,
|
|
1025
|
+
title: L.delete,
|
|
1026
|
+
disabled: hold,
|
|
1027
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
1028
|
+
onClick: (e) => {
|
|
1029
|
+
e.stopPropagation();
|
|
1030
|
+
askDelete(n.path);
|
|
1031
|
+
},
|
|
1032
|
+
children: I.trash
|
|
1033
|
+
}
|
|
1034
|
+
) : null
|
|
1035
|
+
] }) : null
|
|
1036
|
+
]
|
|
1037
|
+
}
|
|
1038
|
+
),
|
|
1039
|
+
renaming && edit.err ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "rui-tree-msg is-error", id: errId, role: "alert", style: depthStyle(n.depth - 1), children: edit.err }) : null,
|
|
1040
|
+
msg ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "rui-tree-msg is-error", id: msgId, style: depthStyle(n.depth - 1), children: msg }) : null,
|
|
1041
|
+
asking ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1042
|
+
"div",
|
|
1043
|
+
{
|
|
1044
|
+
className: "rui-tree-ask",
|
|
1045
|
+
role: "group",
|
|
1046
|
+
"aria-label": isDir ? say2(L.confirmFolder, n.name, n.files) : say2(L.confirmFile, n.name),
|
|
1047
|
+
style: depthStyle(n.depth - 1),
|
|
1048
|
+
children: [
|
|
1049
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-ask-q", children: isDir ? say2(L.confirmFolder, n.name, n.files) : say2(L.confirmFile, n.name) }),
|
|
1050
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "rui-tree-ask-b", children: [
|
|
1051
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "rui-tree-link", disabled: ask.busy, onClick: () => {
|
|
1052
|
+
setAsk(null);
|
|
1053
|
+
focusSoon(n.path);
|
|
1054
|
+
}, children: L.keep }),
|
|
1055
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "rui-tree-link is-danger", ref: askRef, disabled: ask.busy, onClick: () => void confirmDelete(), children: L.delete })
|
|
1056
|
+
] })
|
|
1057
|
+
]
|
|
1058
|
+
}
|
|
1059
|
+
) : null,
|
|
1060
|
+
open && kids.length || creatingHere ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("ul", { role: "group", className: "rui-tree-group", children: [
|
|
1061
|
+
kids.map(renderNode),
|
|
1062
|
+
creatingHere ? entryRow(n.path, n.depth + 1) : null
|
|
1063
|
+
] }) : null
|
|
1064
|
+
]
|
|
1065
|
+
},
|
|
1066
|
+
n.path
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
const empty = !tree.nodes.length;
|
|
1070
|
+
const creatingAtTop = edit && edit.mode === "create" && edit.dir === "";
|
|
1071
|
+
const treeLabel = label || title || L.tree;
|
|
1072
|
+
const rootClass = ["rui-tree", readOnly ? "is-readonly" : "", className || ""].filter(Boolean).join(" ");
|
|
1073
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ref: rootRef, className: rootClass, style, children: [
|
|
1074
|
+
title || offered.length ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "rui-tree-head", children: [
|
|
1075
|
+
title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-title", children: title }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-title" }),
|
|
1076
|
+
offered.length ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-tools", children: offered.map((a) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1077
|
+
"button",
|
|
1078
|
+
{
|
|
1079
|
+
type: "button",
|
|
1080
|
+
className: "rui-tree-tool",
|
|
1081
|
+
"aria-label": headerAction[a].label,
|
|
1082
|
+
title: headerAction[a].label,
|
|
1083
|
+
disabled: headerAction[a].mutates && hold,
|
|
1084
|
+
onClick: headerAction[a].run,
|
|
1085
|
+
children: headerAction[a].icon
|
|
1086
|
+
},
|
|
1087
|
+
a
|
|
1088
|
+
)) }) : null
|
|
1089
|
+
] }) : null,
|
|
1090
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "rui-tree-msg is-error is-tree", role: "alert", children: error }) : null,
|
|
1091
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1092
|
+
"div",
|
|
1093
|
+
{
|
|
1094
|
+
className: `rui-tree-body${dropDir === "" ? " is-drop" : ""}`,
|
|
1095
|
+
onClick: (e) => {
|
|
1096
|
+
if (e.target === e.currentTarget || e.target.classList?.contains("rui-tree-list")) {
|
|
1097
|
+
dropEdit();
|
|
1098
|
+
setAsk(null);
|
|
1099
|
+
setActive("");
|
|
1100
|
+
}
|
|
1101
|
+
},
|
|
1102
|
+
onContextMenu: (e) => {
|
|
1103
|
+
if (e.target.closest("[data-row]")) return;
|
|
1104
|
+
if (openMenu("", "dir", e.clientX, e.clientY)) e.preventDefault();
|
|
1105
|
+
},
|
|
1106
|
+
onDragEnter: (e) => overDir(e, ""),
|
|
1107
|
+
onDragOver: (e) => overDir(e, ""),
|
|
1108
|
+
onDrop: (e) => dropOn(e, ""),
|
|
1109
|
+
onDragLeave: (e) => {
|
|
1110
|
+
const b = e.currentTarget.getBoundingClientRect();
|
|
1111
|
+
const out = e.relatedTarget ? !e.currentTarget.contains(e.relatedTarget) : e.clientX < b.left || e.clientX >= b.right || e.clientY < b.top || e.clientY >= b.bottom;
|
|
1112
|
+
if (out) setDropDir(null);
|
|
1113
|
+
},
|
|
1114
|
+
children: [
|
|
1115
|
+
busy && empty ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "rui-tree-skel", role: "status", children: [
|
|
1116
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-sr", children: L.loading }),
|
|
1117
|
+
[64, 48, 56].map((w, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "rui-tree-skel-line", style: { width: `${w}%` }, "aria-hidden": "true" }, i))
|
|
1118
|
+
] }) : null,
|
|
1119
|
+
!busy && empty && !creatingAtTop ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "rui-tree-empty", children: L.empty }) : null,
|
|
1120
|
+
!empty || creatingAtTop ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1121
|
+
"ul",
|
|
1122
|
+
{
|
|
1123
|
+
role: "tree",
|
|
1124
|
+
className: "rui-tree-list",
|
|
1125
|
+
"aria-label": treeLabel,
|
|
1126
|
+
"aria-busy": busy || void 0,
|
|
1127
|
+
onKeyDown: onTreeKeyDown,
|
|
1128
|
+
onFocus: (e) => {
|
|
1129
|
+
const p = e.target.getAttribute?.("data-path");
|
|
1130
|
+
if (e.target.getAttribute?.("role") === "treeitem" && p !== null && p !== active) setActive(p);
|
|
1131
|
+
},
|
|
1132
|
+
children: [
|
|
1133
|
+
tree.nodes.map(renderNode),
|
|
1134
|
+
creatingAtTop ? entryRow("", 1) : null
|
|
1135
|
+
]
|
|
1136
|
+
}
|
|
1137
|
+
) : null
|
|
1138
|
+
]
|
|
1139
|
+
}
|
|
1140
|
+
),
|
|
1141
|
+
menu && typeof document !== "undefined" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1142
|
+
TreeMenu,
|
|
1143
|
+
{
|
|
1144
|
+
menu,
|
|
1145
|
+
items: itemsFor(menu.path, menu.kind),
|
|
1146
|
+
label: say2(L.menu, menu.path ? baseName(menu.path) : treeLabel),
|
|
1147
|
+
tokensFrom: rootRef,
|
|
1148
|
+
menuRef,
|
|
1149
|
+
onClose: closeMenu
|
|
1150
|
+
}
|
|
1151
|
+
) : null
|
|
1152
|
+
] });
|
|
1153
|
+
}
|
|
1154
|
+
function ancestorsOf(dir) {
|
|
1155
|
+
const out = [];
|
|
1156
|
+
for (let p = parentOf(dir); p; p = parentOf(p)) out.unshift(p);
|
|
1157
|
+
return out;
|
|
1158
|
+
}
|
|
1159
|
+
//# sourceMappingURL=tree.cjs.map
|