@cocoar/vue-file-explorer-core 2.6.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/README.md +121 -0
- package/dist/asset-store.d.ts +284 -0
- package/dist/asset-store.d.ts.map +1 -0
- package/dist/create-asset-store.d.ts +60 -0
- package/dist/create-asset-store.d.ts.map +1 -0
- package/dist/describe-asset.d.ts +36 -0
- package/dist/describe-asset.d.ts.map +1 -0
- package/dist/file-meta.d.ts +21 -0
- package/dist/file-meta.d.ts.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +751 -0
- package/dist/use-file-explorer.d.ts +144 -0
- package/dist/use-file-explorer.d.ts.map +1 -0
- package/package.json +54 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,751 @@
|
|
|
1
|
+
import { computed as e, nextTick as t, onScopeDispose as n, ref as r, shallowRef as i, toValue as a, watch as o } from "vue";
|
|
2
|
+
//#region src/create-asset-store.ts
|
|
3
|
+
function s(e) {
|
|
4
|
+
let t = {
|
|
5
|
+
loadTree: e.loadTree,
|
|
6
|
+
loadContent: e.loadContent,
|
|
7
|
+
createFolder: e.createFolder,
|
|
8
|
+
createFile: e.createFile,
|
|
9
|
+
uploadFile: e.uploadFile,
|
|
10
|
+
save: e.save,
|
|
11
|
+
rename: e.rename,
|
|
12
|
+
delete: e.delete,
|
|
13
|
+
move: e.move
|
|
14
|
+
};
|
|
15
|
+
return e.loadChildren && (t.loadChildren = e.loadChildren), t;
|
|
16
|
+
}
|
|
17
|
+
function c(t = {}) {
|
|
18
|
+
let { initialTree: n = [], initialContent: i = {}, latencyMs: o = 0, failureRate: s = 0, idFactory: c = () => crypto.randomUUID(), lazy: l = !1, onConflict: u = "rename" } = t, d = r([...n]), f = r(new Set(l ? n.filter((e) => e.parentId === null).map((e) => e.id) : n.map((e) => e.id))), p = e(() => d.value.filter((e) => f.value.has(e.id))), m = new Map(Object.entries(i));
|
|
19
|
+
async function h(e, t) {
|
|
20
|
+
let n = a(o);
|
|
21
|
+
n > 0 && await new Promise((e) => setTimeout(e, n));
|
|
22
|
+
let r = a(s);
|
|
23
|
+
if (r > 0 && Math.random() < r) throw Error(`[InMemoryAssetStore] simulated failure in ${e}`);
|
|
24
|
+
return t();
|
|
25
|
+
}
|
|
26
|
+
function g(e) {
|
|
27
|
+
return d.value.findIndex((t) => t.id === e);
|
|
28
|
+
}
|
|
29
|
+
function _(e, t) {
|
|
30
|
+
let n = g(e);
|
|
31
|
+
if (n < 0) throw Error(`[InMemoryAssetStore] ${t}: asset ${e} not found`);
|
|
32
|
+
return d.value[n];
|
|
33
|
+
}
|
|
34
|
+
function v(e) {
|
|
35
|
+
return d.value.filter((t) => t.parentId === e);
|
|
36
|
+
}
|
|
37
|
+
function y(e, t) {
|
|
38
|
+
return new Set(d.value.filter((n) => n.parentId === e && n.id !== t).map((e) => e.name));
|
|
39
|
+
}
|
|
40
|
+
function b(e) {
|
|
41
|
+
let t = new Set([e]), n = !0;
|
|
42
|
+
for (; n;) {
|
|
43
|
+
n = !1;
|
|
44
|
+
for (let e of d.value) e.parentId && t.has(e.parentId) && !t.has(e.id) && (t.add(e.id), n = !0);
|
|
45
|
+
}
|
|
46
|
+
return t;
|
|
47
|
+
}
|
|
48
|
+
function x(e) {
|
|
49
|
+
return e.map((e) => e.kind === "folder" ? {
|
|
50
|
+
...e,
|
|
51
|
+
hasChildren: d.value.some((t) => t.parentId === e.id)
|
|
52
|
+
} : e);
|
|
53
|
+
}
|
|
54
|
+
function S(e) {
|
|
55
|
+
let t = new Set(f.value);
|
|
56
|
+
for (let n of e) t.add(n);
|
|
57
|
+
f.value = t;
|
|
58
|
+
}
|
|
59
|
+
function C(e) {
|
|
60
|
+
let t = new Set(f.value);
|
|
61
|
+
for (let n of e) t.delete(n);
|
|
62
|
+
f.value = t;
|
|
63
|
+
}
|
|
64
|
+
function w(e, t) {
|
|
65
|
+
let n = y(e);
|
|
66
|
+
if (!n.has(t)) return t;
|
|
67
|
+
let r = t.lastIndexOf("."), [i, a] = r > 0 ? [t.slice(0, r), t.slice(r)] : [t, ""];
|
|
68
|
+
for (let e = 2; e < 1e3; e++) {
|
|
69
|
+
let t = `${i} (${e})${a}`;
|
|
70
|
+
if (!n.has(t)) return t;
|
|
71
|
+
}
|
|
72
|
+
return `${i} (${crypto.randomUUID()})${a}`;
|
|
73
|
+
}
|
|
74
|
+
async function T(e, t, n) {
|
|
75
|
+
if (!y(e).has(t)) return t;
|
|
76
|
+
let r = a(u), i = d.value.find((n) => n.parentId === e && n.name === t), o = w(e, t), s;
|
|
77
|
+
if (r === "rename") s = {
|
|
78
|
+
action: "rename",
|
|
79
|
+
newName: o
|
|
80
|
+
};
|
|
81
|
+
else if (r === "overwrite") s = { action: "overwrite" };
|
|
82
|
+
else if (r === "prompt") {
|
|
83
|
+
let e = window.prompt(`"${t}" already exists. Use a different name?`, o);
|
|
84
|
+
s = e ? {
|
|
85
|
+
action: "rename",
|
|
86
|
+
newName: e.trim()
|
|
87
|
+
} : { action: "cancel" };
|
|
88
|
+
} else s = r === "error" ? { action: "cancel" } : await r({
|
|
89
|
+
existing: i,
|
|
90
|
+
incoming: {
|
|
91
|
+
name: t,
|
|
92
|
+
kind: n
|
|
93
|
+
},
|
|
94
|
+
parentId: e,
|
|
95
|
+
suggestedRename: o
|
|
96
|
+
});
|
|
97
|
+
if (s.action === "cancel") return null;
|
|
98
|
+
if (s.action === "overwrite") {
|
|
99
|
+
let e = b(i.id);
|
|
100
|
+
d.value = d.value.filter((t) => !e.has(t.id)), C(e);
|
|
101
|
+
for (let t of e) m.delete(t);
|
|
102
|
+
return t;
|
|
103
|
+
}
|
|
104
|
+
return T(e, s.newName, n);
|
|
105
|
+
}
|
|
106
|
+
let E = {
|
|
107
|
+
_assets: p,
|
|
108
|
+
_contents: m,
|
|
109
|
+
async loadTree() {
|
|
110
|
+
return h("loadTree", () => {
|
|
111
|
+
if (l) {
|
|
112
|
+
let e = d.value.filter((e) => e.parentId === null);
|
|
113
|
+
return S(e.map((e) => e.id)), x(e);
|
|
114
|
+
}
|
|
115
|
+
return x(d.value);
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
async loadContent(e) {
|
|
119
|
+
return h("loadContent", () => {
|
|
120
|
+
_(e, "loadContent");
|
|
121
|
+
let t = m.get(e);
|
|
122
|
+
if (t === void 0) throw Error(`[InMemoryAssetStore] loadContent: no content for ${e}`);
|
|
123
|
+
return t;
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
async createFolder(e, t) {
|
|
127
|
+
let n = await T(e, t, "folder");
|
|
128
|
+
if (n === null) throw Error(`[InMemoryAssetStore] createFolder: "${t}" already exists in this folder`);
|
|
129
|
+
return h("createFolder", () => {
|
|
130
|
+
let t = {
|
|
131
|
+
id: c(),
|
|
132
|
+
name: n,
|
|
133
|
+
kind: "folder",
|
|
134
|
+
parentId: e
|
|
135
|
+
};
|
|
136
|
+
return d.value.push(t), S([t.id]), t;
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
async createFile(e, t) {
|
|
140
|
+
let n = await T(e, t, "file");
|
|
141
|
+
if (n === null) throw Error(`[InMemoryAssetStore] createFile: "${t}" already exists in this folder`);
|
|
142
|
+
return h("createFile", () => {
|
|
143
|
+
let t = {
|
|
144
|
+
id: c(),
|
|
145
|
+
name: n,
|
|
146
|
+
kind: "file",
|
|
147
|
+
parentId: e
|
|
148
|
+
};
|
|
149
|
+
return d.value.push(t), S([t.id]), m.set(t.id, ""), t;
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
async uploadFile(e, t) {
|
|
153
|
+
let n = await T(e, t.name, "file");
|
|
154
|
+
if (n === null) throw Error(`[InMemoryAssetStore] uploadFile: "${t.name}" already exists in this folder`);
|
|
155
|
+
return h("uploadFile", () => {
|
|
156
|
+
let t = {
|
|
157
|
+
id: c(),
|
|
158
|
+
name: n,
|
|
159
|
+
kind: "file",
|
|
160
|
+
parentId: e
|
|
161
|
+
};
|
|
162
|
+
return d.value.push(t), S([t.id]), t;
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
async save(e, t) {
|
|
166
|
+
return h("save", () => {
|
|
167
|
+
_(e, "save"), m.set(e, t);
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
async rename(e, t) {
|
|
171
|
+
return h("rename", () => {
|
|
172
|
+
let n = _(e, "rename");
|
|
173
|
+
if (n.name !== t) {
|
|
174
|
+
if (y(n.parentId, e).has(t)) throw Error(`[InMemoryAssetStore] rename: "${t}" already exists in this folder`);
|
|
175
|
+
n.name = t;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
async delete(e) {
|
|
180
|
+
return h("delete", () => {
|
|
181
|
+
_(e, "delete");
|
|
182
|
+
let t = b(e);
|
|
183
|
+
d.value = d.value.filter((e) => !t.has(e.id)), C(t);
|
|
184
|
+
for (let e of t) m.delete(e);
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
async move(e, t, n) {
|
|
188
|
+
return h("move", () => {
|
|
189
|
+
let r = _(e, "move");
|
|
190
|
+
if (t !== null && b(e).has(t)) throw Error(`[InMemoryAssetStore] move: cannot move ${e} into its own descendant`);
|
|
191
|
+
if (r.parentId !== t && y(t).has(r.name)) throw Error(`[InMemoryAssetStore] move: "${r.name}" already exists in destination folder`);
|
|
192
|
+
r.parentId = t;
|
|
193
|
+
let i = g(e);
|
|
194
|
+
d.value.splice(i, 1);
|
|
195
|
+
let a = v(t), o = n ?? a.length;
|
|
196
|
+
if (o <= 0) {
|
|
197
|
+
let e = a.length ? d.value.indexOf(a[0]) : d.value.length;
|
|
198
|
+
d.value.splice(e, 0, r);
|
|
199
|
+
} else if (o >= a.length) {
|
|
200
|
+
let e = a[a.length - 1], t = e ? d.value.indexOf(e) : -1;
|
|
201
|
+
d.value.splice(t + 1, 0, r);
|
|
202
|
+
} else {
|
|
203
|
+
let e = a[o];
|
|
204
|
+
d.value.splice(d.value.indexOf(e), 0, r);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
return l && (E.loadChildren = async (e) => h("loadChildren", () => {
|
|
210
|
+
let t = d.value.filter((t) => t.parentId === e);
|
|
211
|
+
return S(t.map((e) => e.id)), x(t);
|
|
212
|
+
})), E;
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region src/file-meta.ts
|
|
216
|
+
function l(e) {
|
|
217
|
+
let t = e.toLowerCase(), n = t.split(".").pop() ?? "";
|
|
218
|
+
if (n === "md" || n === "markdown") return { editor: "markdown" };
|
|
219
|
+
if (n === "pdf") return { editor: "pdf" };
|
|
220
|
+
if ([
|
|
221
|
+
"png",
|
|
222
|
+
"jpg",
|
|
223
|
+
"jpeg",
|
|
224
|
+
"gif",
|
|
225
|
+
"svg",
|
|
226
|
+
"webp",
|
|
227
|
+
"bmp",
|
|
228
|
+
"avif"
|
|
229
|
+
].includes(n)) return { editor: "image" };
|
|
230
|
+
let r = (e) => ({
|
|
231
|
+
editor: "script",
|
|
232
|
+
language: e
|
|
233
|
+
});
|
|
234
|
+
return n === "ts" || n === "tsx" ? r("typescript") : n === "js" || n === "jsx" || n === "mjs" || n === "cjs" ? r("javascript") : n === "json" || n === "jsonc" ? r("json") : n === "yml" || n === "yaml" ? r("yaml") : n === "css" || n === "scss" || n === "less" ? r("css") : n === "html" || n === "htm" ? r("html") : n === "xml" ? r("xml") : n === "sql" ? r("sql") : n === "sh" || n === "bash" || n === "zsh" || n === "fish" ? r("shell") : n === "ini" || n === "toml" ? r("ini") : t === "dockerfile" || t.endsWith(".dockerfile") ? r("dockerfile") : n === "cs" ? r("csharp") : n === "cpp" || n === "cxx" || n === "cc" || n === "hpp" || n === "hxx" || n === "hh" ? r("cpp") : n === "c" || n === "h" ? r("c") : n === "java" ? r("java") : n === "py" || n === "pyw" ? r("python") : n === "go" ? r("go") : n === "rs" ? r("rust") : n === "rb" ? r("ruby") : n === "php" || n === "phtml" ? r("php") : n === "swift" ? r("swift") : n === "kt" || n === "kts" ? r("kotlin") : n === "scala" || n === "sc" ? r("scala") : n === "lua" ? r("lua") : n === "pl" || n === "pm" ? r("perl") : n === "dart" ? r("dart") : n === "fs" || n === "fsx" || n === "fsi" ? r("fsharp") : n === "vb" ? r("vb") : n === "r" ? r("r") : n === "ps1" || n === "psm1" ? r("powershell") : n === "m" || n === "mm" ? r("objective-c") : n === "sol" ? r("solidity") : n === "proto" ? r("protobuf") : n === "graphql" || n === "gql" ? r("graphql") : n === "cshtml" || n === "razor" ? r("razor") : n === "pug" || n === "jade" ? r("pug") : n === "hbs" || n === "handlebars" ? r("handlebars") : n === "twig" ? r("twig") : [
|
|
235
|
+
"txt",
|
|
236
|
+
"log",
|
|
237
|
+
"env",
|
|
238
|
+
"conf",
|
|
239
|
+
"cfg",
|
|
240
|
+
"gitignore",
|
|
241
|
+
"editorconfig",
|
|
242
|
+
"npmrc",
|
|
243
|
+
"nvmrc",
|
|
244
|
+
"csv",
|
|
245
|
+
"tsv"
|
|
246
|
+
].includes(n) || t.indexOf(".") === -1 ? r("plaintext") : null;
|
|
247
|
+
}
|
|
248
|
+
function u(e, t) {
|
|
249
|
+
let n = d(e, t);
|
|
250
|
+
return n ? n.editor === "script" && !n.language ? {
|
|
251
|
+
...n,
|
|
252
|
+
language: "plaintext"
|
|
253
|
+
} : n : null;
|
|
254
|
+
}
|
|
255
|
+
function d(e, t) {
|
|
256
|
+
return e.editor ? {
|
|
257
|
+
editor: e.editor,
|
|
258
|
+
language: e.language
|
|
259
|
+
} : t?.getFileMeta?.(e) || l(e.name);
|
|
260
|
+
}
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region src/describe-asset.ts
|
|
263
|
+
var f = {
|
|
264
|
+
script: "Script",
|
|
265
|
+
markdown: "Markdown",
|
|
266
|
+
pdf: "PDF",
|
|
267
|
+
image: "Image"
|
|
268
|
+
}, p = {
|
|
269
|
+
typescript: "TypeScript",
|
|
270
|
+
javascript: "JavaScript",
|
|
271
|
+
json: "JSON",
|
|
272
|
+
html: "HTML",
|
|
273
|
+
css: "CSS",
|
|
274
|
+
scss: "SCSS",
|
|
275
|
+
less: "Less",
|
|
276
|
+
yaml: "YAML",
|
|
277
|
+
xml: "XML",
|
|
278
|
+
sql: "SQL",
|
|
279
|
+
shell: "Shell",
|
|
280
|
+
python: "Python",
|
|
281
|
+
csharp: "C#",
|
|
282
|
+
cpp: "C++",
|
|
283
|
+
c: "C",
|
|
284
|
+
java: "Java",
|
|
285
|
+
go: "Go",
|
|
286
|
+
rust: "Rust",
|
|
287
|
+
ruby: "Ruby",
|
|
288
|
+
php: "PHP",
|
|
289
|
+
ini: "INI",
|
|
290
|
+
dockerfile: "Dockerfile",
|
|
291
|
+
plaintext: "Plain text"
|
|
292
|
+
};
|
|
293
|
+
function m(e) {
|
|
294
|
+
let t = e.lastIndexOf(".");
|
|
295
|
+
return t > 0 ? e.slice(t) : "";
|
|
296
|
+
}
|
|
297
|
+
function h(e, t) {
|
|
298
|
+
let n = [{
|
|
299
|
+
key: "name",
|
|
300
|
+
label: "Name",
|
|
301
|
+
value: e.name
|
|
302
|
+
}];
|
|
303
|
+
if (e.kind === "folder") n.push({
|
|
304
|
+
key: "type",
|
|
305
|
+
label: "Type",
|
|
306
|
+
value: "Folder"
|
|
307
|
+
});
|
|
308
|
+
else {
|
|
309
|
+
let r = t.meta?.editor;
|
|
310
|
+
if (n.push({
|
|
311
|
+
key: "type",
|
|
312
|
+
label: "Type",
|
|
313
|
+
value: r ? f[r] : "File"
|
|
314
|
+
}), r === "script" && t.meta?.language) {
|
|
315
|
+
let e = t.meta.language;
|
|
316
|
+
n.push({
|
|
317
|
+
key: "language",
|
|
318
|
+
label: "Language",
|
|
319
|
+
value: p[e] ?? e
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
let i = m(e.name);
|
|
323
|
+
i && n.push({
|
|
324
|
+
key: "extension",
|
|
325
|
+
label: "Extension",
|
|
326
|
+
value: i
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
return t.path.length > 1 && n.push({
|
|
330
|
+
key: "path",
|
|
331
|
+
label: "Path",
|
|
332
|
+
value: t.path.join(" / ")
|
|
333
|
+
}), n;
|
|
334
|
+
}
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/use-file-explorer.ts
|
|
337
|
+
function g(s) {
|
|
338
|
+
let { store: c, onError: l, getFileMeta: d, confirm: f = window.confirm.bind(window) } = s, p = (e, t, n = {}) => {
|
|
339
|
+
l?.(e, t, n);
|
|
340
|
+
}, m = r([]), g = c._assets, _ = g !== void 0, v = g ?? m, y = r(!1), b = (e) => {
|
|
341
|
+
if (_ || e.length === 0) return;
|
|
342
|
+
let t = /* @__PURE__ */ new Map();
|
|
343
|
+
for (let e of m.value) t.set(e.id, e);
|
|
344
|
+
for (let n of e) t.set(n.id, n);
|
|
345
|
+
m.value = Array.from(t.values());
|
|
346
|
+
}, x = (e) => {
|
|
347
|
+
_ || (m.value = [...e]);
|
|
348
|
+
}, S = (e) => {
|
|
349
|
+
_ || e.size === 0 || (m.value = m.value.filter((t) => !e.has(t.id)));
|
|
350
|
+
}, C = (e, t) => {
|
|
351
|
+
_ || (m.value = m.value.map((n) => n.id === e ? {
|
|
352
|
+
...n,
|
|
353
|
+
...t
|
|
354
|
+
} : n));
|
|
355
|
+
}, w = e(() => a(s.sortMode) ?? "folders-first"), T = e(() => w.value === "manual"), E = (e) => e === "manual" ? null : typeof e == "function" ? e : e === "alphabetical" ? (e, t) => e.name.localeCompare(t.name) : (e, t) => {
|
|
356
|
+
let n = Number(t.kind === "folder") - Number(e.kind === "folder");
|
|
357
|
+
return n === 0 ? e.name.localeCompare(t.name) : n;
|
|
358
|
+
}, D = (e) => {
|
|
359
|
+
let t = v.value.filter((t) => t.parentId === e), n = E(w.value);
|
|
360
|
+
return n ? t.sort(n) : t;
|
|
361
|
+
}, ee = e(() => D(null)), te = (e) => e.id, ne = (e) => e.kind === "folder" ? D(e.id) : void 0, O = (e) => e.name, re = (e) => e.kind === "folder" && e.hasChildren !== !1, k = "loadChildren" in c && typeof c.loadChildren == "function", ie = s.initialExpandedIds ?? (k ? [] : v.value.filter((e) => e.parentId === null && e.kind === "folder").map((e) => e.id)), A = r(new Set(ie)), j = r(null), M = r(/* @__PURE__ */ new Set()), N = r(/* @__PURE__ */ new Set()), P = (e, t, n) => {
|
|
362
|
+
let r = new Set(e.value);
|
|
363
|
+
n ? r.add(t) : r.delete(t), e.value = r;
|
|
364
|
+
}, F = i([]), I = r(null), ae = e(() => F.value.find((e) => e.id === I.value) ?? null), L = (e) => e.content !== e.savedContent, R = e(() => F.value.some(L)), z = (e) => v.value.find((t) => t.id === e) ?? null, oe = e(() => j.value ? z(j.value) : null), se = (e) => {
|
|
365
|
+
let t = new Set([e]), n = !0;
|
|
366
|
+
for (; n;) {
|
|
367
|
+
n = !1;
|
|
368
|
+
for (let e of v.value) e.parentId && t.has(e.parentId) && !t.has(e.id) && (t.add(e.id), n = !0);
|
|
369
|
+
}
|
|
370
|
+
return t;
|
|
371
|
+
}, B = (e) => u(e, { getFileMeta: d }), ce = (e) => h(e, {
|
|
372
|
+
meta: e.kind === "file" ? B(e) : null,
|
|
373
|
+
path: Y(e.id)
|
|
374
|
+
}), V = /* @__PURE__ */ new Set(), H = async (e) => {
|
|
375
|
+
let t = u({
|
|
376
|
+
id: "",
|
|
377
|
+
name: e.name,
|
|
378
|
+
kind: "file",
|
|
379
|
+
parentId: null
|
|
380
|
+
}, { getFileMeta: d });
|
|
381
|
+
if (!t) return console.warn(`[file-explorer] Unsupported file type: ${e.name}`), null;
|
|
382
|
+
if (t.editor === "pdf" || t.editor === "image") {
|
|
383
|
+
let n = URL.createObjectURL(e);
|
|
384
|
+
return V.add(n), {
|
|
385
|
+
content: n,
|
|
386
|
+
editor: t.editor
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
return {
|
|
390
|
+
content: await e.text(),
|
|
391
|
+
editor: t.editor
|
|
392
|
+
};
|
|
393
|
+
}, U = async (e, t) => {
|
|
394
|
+
try {
|
|
395
|
+
let n = await c.createFolder(e, t);
|
|
396
|
+
return b([n]), e && (A.value = new Set(A.value).add(e)), n;
|
|
397
|
+
} catch (n) {
|
|
398
|
+
return p("createFolder", n, {
|
|
399
|
+
parentId: e,
|
|
400
|
+
name: t
|
|
401
|
+
}), null;
|
|
402
|
+
}
|
|
403
|
+
}, W = async (e, t) => {
|
|
404
|
+
let n = Array.from(t), r = !1;
|
|
405
|
+
for (let t of n) {
|
|
406
|
+
let n = await H(t);
|
|
407
|
+
if (!n) continue;
|
|
408
|
+
let i;
|
|
409
|
+
try {
|
|
410
|
+
i = await c.uploadFile(e, t);
|
|
411
|
+
} catch (n) {
|
|
412
|
+
p("uploadFile", n, {
|
|
413
|
+
parentId: e,
|
|
414
|
+
file: t
|
|
415
|
+
});
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
b([i]), P(N, i.id, !0);
|
|
419
|
+
try {
|
|
420
|
+
await c.save(i.id, n.content), r = !0;
|
|
421
|
+
} catch (e) {
|
|
422
|
+
p("save", e, {
|
|
423
|
+
id: i.id,
|
|
424
|
+
name: i.name
|
|
425
|
+
});
|
|
426
|
+
} finally {
|
|
427
|
+
P(N, i.id, !1);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
r && e && (A.value = new Set(A.value).add(e));
|
|
431
|
+
}, le = async (e) => {
|
|
432
|
+
let t = se(e.id);
|
|
433
|
+
for (let e of t) {
|
|
434
|
+
let t = c._contents?.get(e);
|
|
435
|
+
typeof t == "string" && V.has(t) && (URL.revokeObjectURL(t), V.delete(t));
|
|
436
|
+
}
|
|
437
|
+
t.size > 0 && (F.value = F.value.filter((e) => !t.has(e.id)), I.value && t.has(I.value) && (I.value = F.value[0]?.id ?? null)), P(N, e.id, !0);
|
|
438
|
+
try {
|
|
439
|
+
await c.delete(e.id), S(t);
|
|
440
|
+
} catch (t) {
|
|
441
|
+
p("delete", t, {
|
|
442
|
+
id: e.id,
|
|
443
|
+
name: e.name
|
|
444
|
+
});
|
|
445
|
+
} finally {
|
|
446
|
+
P(N, e.id, !1);
|
|
447
|
+
}
|
|
448
|
+
}, G = async (e) => {
|
|
449
|
+
let { source: t, target: n, position: r } = e, i = T.value;
|
|
450
|
+
P(N, t.id, !0);
|
|
451
|
+
try {
|
|
452
|
+
if (!n) {
|
|
453
|
+
await c.move(t.id, null), C(t.id, { parentId: null });
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (r === "inside") {
|
|
457
|
+
if (n.kind !== "folder") return;
|
|
458
|
+
await c.move(t.id, n.id), C(t.id, { parentId: n.id }), A.value = new Set(A.value).add(n.id);
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
if (!i) {
|
|
462
|
+
await c.move(t.id, n.parentId), C(t.id, { parentId: n.parentId });
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
let e = v.value.filter((e) => e.parentId === n.parentId && e.id !== t.id).findIndex((e) => e.id === n.id), a = r === "before" ? e : e + 1;
|
|
466
|
+
await c.move(t.id, n.parentId, a), _ || await Q();
|
|
467
|
+
} catch (e) {
|
|
468
|
+
p("move", e, {
|
|
469
|
+
id: t.id,
|
|
470
|
+
name: t.name
|
|
471
|
+
});
|
|
472
|
+
} finally {
|
|
473
|
+
P(N, t.id, !1);
|
|
474
|
+
}
|
|
475
|
+
}, ue = async (e, t) => {
|
|
476
|
+
let n = z(e);
|
|
477
|
+
if (!(!n || n.name === t)) {
|
|
478
|
+
P(N, e, !0);
|
|
479
|
+
try {
|
|
480
|
+
await c.rename(e, t), C(e, { name: t });
|
|
481
|
+
} catch (n) {
|
|
482
|
+
p("rename", n, {
|
|
483
|
+
id: e,
|
|
484
|
+
name: t
|
|
485
|
+
});
|
|
486
|
+
return;
|
|
487
|
+
} finally {
|
|
488
|
+
P(N, e, !1);
|
|
489
|
+
}
|
|
490
|
+
if (n.kind === "file") {
|
|
491
|
+
let r = F.value.findIndex((t) => t.id === e);
|
|
492
|
+
if (r >= 0) {
|
|
493
|
+
let e = u(n, { getFileMeta: d }), i = F.value.slice();
|
|
494
|
+
i[r] = {
|
|
495
|
+
...i[r],
|
|
496
|
+
name: t,
|
|
497
|
+
editor: e?.editor ?? i[r].editor,
|
|
498
|
+
language: e?.language
|
|
499
|
+
}, F.value = i;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}, K = (e) => {
|
|
504
|
+
let t = F.value.findIndex((t) => t.id === e);
|
|
505
|
+
if (t < 0 || F.value[t].pinned) return;
|
|
506
|
+
let n = F.value.slice();
|
|
507
|
+
n[t] = {
|
|
508
|
+
...n[t],
|
|
509
|
+
pinned: !0
|
|
510
|
+
}, F.value = n;
|
|
511
|
+
}, de = (e, t, n) => {
|
|
512
|
+
if (e === t) return;
|
|
513
|
+
let r = F.value, i = r.findIndex((t) => t.id === e), a = r.findIndex((e) => e.id === t);
|
|
514
|
+
if (i < 0 || a < 0) return;
|
|
515
|
+
let o = r.slice(), [s] = o.splice(i, 1), c = i < a ? a - 1 : a, l = n === "before" ? c : c + 1;
|
|
516
|
+
o.splice(l, 0, s), F.value = o;
|
|
517
|
+
}, fe = (e) => {
|
|
518
|
+
let t = F.value.findIndex((t) => t.id === e);
|
|
519
|
+
if (t < 0 || !F.value[t].pinned) return;
|
|
520
|
+
let n = F.value.filter((t) => t.pinned || t.id === e), r = n.findIndex((t) => t.id === e);
|
|
521
|
+
n[r] = {
|
|
522
|
+
...n[r],
|
|
523
|
+
pinned: !1
|
|
524
|
+
}, F.value = n;
|
|
525
|
+
}, pe = (e, t) => {
|
|
526
|
+
let n = F.value.findIndex((t) => t.id === e);
|
|
527
|
+
if (n < 0) return;
|
|
528
|
+
let r = F.value.slice(), i = !r[n].pinned, a = t !== r[n].savedContent;
|
|
529
|
+
r[n] = {
|
|
530
|
+
...r[n],
|
|
531
|
+
content: t,
|
|
532
|
+
pinned: i && a ? !0 : r[n].pinned
|
|
533
|
+
}, F.value = r;
|
|
534
|
+
}, q = async (e, t = { pinned: !1 }) => {
|
|
535
|
+
let n = F.value.findIndex((t) => t.id === e.id);
|
|
536
|
+
if (n >= 0) {
|
|
537
|
+
t.pinned && !F.value[n].pinned && K(e.id), I.value = e.id;
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
let r = u(e, { getFileMeta: d });
|
|
541
|
+
if (!r) {
|
|
542
|
+
console.warn(`[file-explorer] No editor available for ${e.name}`);
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
let i = {
|
|
546
|
+
id: e.id,
|
|
547
|
+
name: e.name,
|
|
548
|
+
editor: r.editor,
|
|
549
|
+
language: r.language,
|
|
550
|
+
content: "",
|
|
551
|
+
savedContent: "",
|
|
552
|
+
pinned: t.pinned
|
|
553
|
+
};
|
|
554
|
+
if (t.pinned) F.value = [...F.value, i];
|
|
555
|
+
else {
|
|
556
|
+
let e = F.value.findIndex((e) => !e.pinned), t = F.value.slice();
|
|
557
|
+
e >= 0 ? t.splice(e, 1, i) : t.push(i), F.value = t;
|
|
558
|
+
}
|
|
559
|
+
I.value = e.id;
|
|
560
|
+
let a;
|
|
561
|
+
P(M, e.id, !0);
|
|
562
|
+
try {
|
|
563
|
+
a = await c.loadContent(e.id);
|
|
564
|
+
} catch (t) {
|
|
565
|
+
p("loadContent", t, {
|
|
566
|
+
id: e.id,
|
|
567
|
+
name: e.name
|
|
568
|
+
}), F.value = F.value.filter((t) => t.id !== e.id), I.value === e.id && (I.value = F.value[F.value.length - 1]?.id ?? null);
|
|
569
|
+
return;
|
|
570
|
+
} finally {
|
|
571
|
+
P(M, e.id, !1);
|
|
572
|
+
}
|
|
573
|
+
let o = typeof a == "string" ? a : "", s = F.value.findIndex((t) => t.id === e.id);
|
|
574
|
+
if (s >= 0) {
|
|
575
|
+
let e = F.value.slice();
|
|
576
|
+
e[s] = {
|
|
577
|
+
...e[s],
|
|
578
|
+
content: o,
|
|
579
|
+
savedContent: o
|
|
580
|
+
}, F.value = e;
|
|
581
|
+
}
|
|
582
|
+
}, me = (e) => {
|
|
583
|
+
e.kind === "file" && q(e, { pinned: !0 });
|
|
584
|
+
}, J = async (e) => {
|
|
585
|
+
let t = F.value.findIndex((t) => t.id === e);
|
|
586
|
+
if (t < 0) return !1;
|
|
587
|
+
let n = F.value[t];
|
|
588
|
+
if (!L(n)) return !0;
|
|
589
|
+
P(N, e, !0);
|
|
590
|
+
try {
|
|
591
|
+
await c.save(n.id, n.content);
|
|
592
|
+
} catch (t) {
|
|
593
|
+
return p("save", t, {
|
|
594
|
+
id: e,
|
|
595
|
+
name: n.name
|
|
596
|
+
}), !1;
|
|
597
|
+
} finally {
|
|
598
|
+
P(N, e, !1);
|
|
599
|
+
}
|
|
600
|
+
let r = F.value.slice();
|
|
601
|
+
return r[t] = {
|
|
602
|
+
...n,
|
|
603
|
+
savedContent: n.content
|
|
604
|
+
}, F.value = r, !0;
|
|
605
|
+
}, he = async () => {
|
|
606
|
+
I.value && await J(I.value);
|
|
607
|
+
}, ge = (e) => {
|
|
608
|
+
let t = F.value.findIndex((t) => t.id === e);
|
|
609
|
+
if (t < 0 || N.value.has(e)) return;
|
|
610
|
+
let n = F.value[t];
|
|
611
|
+
if (L(n) && !f(`Discard unsaved changes to "${n.name}"?`)) return;
|
|
612
|
+
let r = F.value.filter((t) => t.id !== e);
|
|
613
|
+
F.value = r, I.value === e && (I.value = r[t]?.id ?? r[t - 1]?.id ?? null);
|
|
614
|
+
}, _e = (e) => {
|
|
615
|
+
let t = F.value.filter((t) => t.id !== e && L(t));
|
|
616
|
+
if (t.length > 0 && !f(`Close ${F.value.length - 1 - t.length} other tabs? ${t.length} unsaved tab(s) will be kept open.`)) return;
|
|
617
|
+
let n = new Set([e, ...t.map((e) => e.id)]);
|
|
618
|
+
F.value = F.value.filter((e) => n.has(e.id)), I.value = e;
|
|
619
|
+
}, ve = (e) => {
|
|
620
|
+
let t = F.value.findIndex((t) => t.id === e);
|
|
621
|
+
if (t < 0) return;
|
|
622
|
+
let n = F.value.slice(t + 1), r = n.filter(L);
|
|
623
|
+
r.length > 0 && !f(`Close ${n.length} tab(s)? ${r.length} have unsaved changes.`) || (F.value = F.value.slice(0, t + 1), I.value && !F.value.some((e) => e.id === I.value) && (I.value = e));
|
|
624
|
+
}, ye = () => {
|
|
625
|
+
let e = F.value.filter(L);
|
|
626
|
+
e.length > 0 && !f(`Close all ${F.value.length} tabs? ${e.length} have unsaved changes.`) || (F.value = [], I.value = null);
|
|
627
|
+
}, be = (e, n) => {
|
|
628
|
+
let r = new Set(A.value), i = z(e)?.parentId ?? null;
|
|
629
|
+
for (; i;) r.add(i), i = z(i)?.parentId ?? null;
|
|
630
|
+
A.value = r, t(() => {
|
|
631
|
+
j.value = e, n?.(e);
|
|
632
|
+
});
|
|
633
|
+
};
|
|
634
|
+
function Y(e) {
|
|
635
|
+
let t = [], n = z(e);
|
|
636
|
+
for (; n;) t.unshift(n.name), n = n.parentId ? z(n.parentId) : null;
|
|
637
|
+
return t;
|
|
638
|
+
}
|
|
639
|
+
let xe = e(() => I.value ? Y(I.value) : []);
|
|
640
|
+
o(j, (e) => {
|
|
641
|
+
if (!e) return;
|
|
642
|
+
let t = z(e);
|
|
643
|
+
t && t.kind === "file" && q(t, { pinned: !1 });
|
|
644
|
+
});
|
|
645
|
+
let X = r(/* @__PURE__ */ new Set());
|
|
646
|
+
k && o(A, async (e, t) => {
|
|
647
|
+
let n = [];
|
|
648
|
+
e.forEach((e) => {
|
|
649
|
+
t?.has(e) || n.push(e);
|
|
650
|
+
});
|
|
651
|
+
for (let e of n) if (!X.value.has(e)) {
|
|
652
|
+
P(M, e, !0);
|
|
653
|
+
try {
|
|
654
|
+
b(await c.loadChildren(e)), X.value = new Set(X.value).add(e);
|
|
655
|
+
} catch (t) {
|
|
656
|
+
p("loadChildren", t, { id: e });
|
|
657
|
+
} finally {
|
|
658
|
+
P(M, e, !1);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}, {
|
|
662
|
+
deep: !0,
|
|
663
|
+
immediate: !0
|
|
664
|
+
});
|
|
665
|
+
let Z = !1, Q = async () => {
|
|
666
|
+
if (!_) {
|
|
667
|
+
y.value = !Z;
|
|
668
|
+
try {
|
|
669
|
+
let e = await c.loadTree();
|
|
670
|
+
if (x(e), !Z && (Z = !0, s.initialExpandedIds === void 0 && !k)) {
|
|
671
|
+
let t = e.filter((e) => e.parentId === null && e.kind === "folder").map((e) => e.id);
|
|
672
|
+
t.length > 0 && (A.value = new Set([...A.value, ...t]));
|
|
673
|
+
}
|
|
674
|
+
} catch (e) {
|
|
675
|
+
p("loadTree", e, {});
|
|
676
|
+
} finally {
|
|
677
|
+
y.value = !1;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}, Se = async (e) => {
|
|
681
|
+
if (!_) {
|
|
682
|
+
if (e == null) return Q();
|
|
683
|
+
if (k) {
|
|
684
|
+
P(M, e, !0);
|
|
685
|
+
try {
|
|
686
|
+
let t = await c.loadChildren(e);
|
|
687
|
+
m.value = [...m.value.filter((t) => t.parentId !== e), ...t], X.value = new Set(X.value).add(e);
|
|
688
|
+
} catch (t) {
|
|
689
|
+
p("loadChildren", t, { id: e });
|
|
690
|
+
} finally {
|
|
691
|
+
P(M, e, !1);
|
|
692
|
+
}
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
return Q();
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
Q();
|
|
699
|
+
let $ = (e) => {
|
|
700
|
+
R.value && (e.preventDefault(), e.returnValue = "");
|
|
701
|
+
};
|
|
702
|
+
return window.addEventListener("beforeunload", $), n(() => {
|
|
703
|
+
window.removeEventListener("beforeunload", $);
|
|
704
|
+
for (let e of V) URL.revokeObjectURL(e);
|
|
705
|
+
V.clear();
|
|
706
|
+
}), {
|
|
707
|
+
assets: v,
|
|
708
|
+
rootNodes: ee,
|
|
709
|
+
selectedId: j,
|
|
710
|
+
selectedAsset: oe,
|
|
711
|
+
expanded: A,
|
|
712
|
+
getId: te,
|
|
713
|
+
getChildren: ne,
|
|
714
|
+
getLabel: O,
|
|
715
|
+
isExpandable: re,
|
|
716
|
+
reorderable: T,
|
|
717
|
+
loading: y,
|
|
718
|
+
loadingNodes: M,
|
|
719
|
+
savingNodes: N,
|
|
720
|
+
openTabs: F,
|
|
721
|
+
activeId: I,
|
|
722
|
+
activeTab: ae,
|
|
723
|
+
anyDirty: R,
|
|
724
|
+
isDirty: L,
|
|
725
|
+
setContent: pe,
|
|
726
|
+
addFolder: U,
|
|
727
|
+
addFiles: W,
|
|
728
|
+
deleteNode: le,
|
|
729
|
+
moveNode: G,
|
|
730
|
+
rename: ue,
|
|
731
|
+
refresh: Se,
|
|
732
|
+
openFile: q,
|
|
733
|
+
activateNode: me,
|
|
734
|
+
saveTab: J,
|
|
735
|
+
saveActive: he,
|
|
736
|
+
closeTab: ge,
|
|
737
|
+
closeOthers: _e,
|
|
738
|
+
closeToRight: ve,
|
|
739
|
+
closeAll: ye,
|
|
740
|
+
pinTab: K,
|
|
741
|
+
unpinTab: fe,
|
|
742
|
+
reorderTab: de,
|
|
743
|
+
revealInTree: be,
|
|
744
|
+
breadcrumbPath: xe,
|
|
745
|
+
pathOf: Y,
|
|
746
|
+
fileMeta: B,
|
|
747
|
+
describeAsset: ce
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
//#endregion
|
|
751
|
+
export { h as buildAssetProperties, s as createAssetStore, c as createInMemoryAssetStore, l as defaultFileMetaFromName, u as resolveFileMeta, g as useFileExplorer };
|