@kubohiroya/turbowarp-plus-editor-project-folder 0.8.0 → 0.9.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/dist/THIRD_PARTY_NOTICES.md +716 -0
- package/dist/create-folder.d.ts +8 -0
- package/dist/explorer-files.d.ts +23 -0
- package/dist/explorer-menu.d.ts +53 -0
- package/dist/explorer.d.ts +34 -4
- package/dist/explorer.js +2020 -694
- package/dist/file-preview.d.ts +24 -0
- package/dist/folder-registry.d.ts +4 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1019 -555
- package/dist/session.d.ts +6 -0
- package/dist/shared-JdaDvk2R.js +588 -0
- package/dist/shared-kI7qYraF.js +30130 -0
- package/dist/text-file-editor.d.ts +17 -0
- package/package.json +16 -1
- package/src/create-folder.ts +99 -0
- package/src/explorer-files.ts +197 -0
- package/src/explorer-menu.tsx +135 -0
- package/src/explorer.tsx +388 -22
- package/src/file-preview.ts +134 -0
- package/src/folder-registry.ts +5 -0
- package/src/index.ts +27 -2
- package/src/session.ts +77 -12
- package/src/source.ts +16 -8
- package/src/text-file-editor.ts +356 -0
- package/vite.config.ts +2 -0
- package/dist/shared-DlmcdO1_.js +0 -458
package/dist/explorer.js
CHANGED
|
@@ -1,474 +1,634 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import * as
|
|
3
|
-
import { useEffect
|
|
1
|
+
import { C as _asyncIterator, S as _objectSpread2, d as manifestFile, g as projectFile, r as FolderError, t as followProjectFolder, u as isObject } from "./shared-JdaDvk2R.js";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
4
5
|
// node_modules/@headless-tree/core/dist/index.mjs
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
6
|
+
var __defProp$1 = Object.defineProperty;
|
|
7
|
+
var __defProps$1 = Object.defineProperties;
|
|
8
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
9
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
10
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value
|
|
17
|
+
}) : obj[key] = value;
|
|
18
|
+
var __spreadValues$1 = (a, b) => {
|
|
19
|
+
for (var prop in b || (b = {})) if (__hasOwnProp$1.call(b, prop)) __defNormalProp$1(a, prop, b[prop]);
|
|
20
|
+
if (__getOwnPropSymbols$1) {
|
|
21
|
+
for (var prop of __getOwnPropSymbols$1(b)) if (__propIsEnum$1.call(b, prop)) __defNormalProp$1(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
26
|
+
var __async = (__this, __arguments, generator) => {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
var fulfilled = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.next(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var rejected = (value) => {
|
|
36
|
+
try {
|
|
37
|
+
step(generator.throw(value));
|
|
38
|
+
} catch (e) {
|
|
39
|
+
reject(e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
43
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
function functionalUpdate(updater, input) {
|
|
47
|
+
return typeof updater === "function" ? updater(input) : updater;
|
|
32
48
|
}
|
|
33
|
-
function
|
|
34
|
-
return (
|
|
35
|
-
|
|
49
|
+
function makeStateUpdater(key, instance) {
|
|
50
|
+
return (updater) => {
|
|
51
|
+
instance.setState((old) => {
|
|
52
|
+
return __spreadProps$1(__spreadValues$1({}, old), { [key]: functionalUpdate(updater, old[key]) });
|
|
53
|
+
});
|
|
36
54
|
};
|
|
37
55
|
}
|
|
38
|
-
var
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
56
|
+
var poll = (fn, interval = 100, timeout = 1e3) => new Promise((resolve) => {
|
|
57
|
+
let clear;
|
|
58
|
+
const i = setInterval(() => {
|
|
59
|
+
if (fn()) {
|
|
60
|
+
resolve();
|
|
61
|
+
clearInterval(i);
|
|
62
|
+
clearTimeout(clear);
|
|
63
|
+
}
|
|
64
|
+
}, interval);
|
|
65
|
+
clear = setTimeout(() => {
|
|
66
|
+
clearInterval(i);
|
|
67
|
+
resolve();
|
|
68
|
+
}, timeout);
|
|
69
|
+
});
|
|
70
|
+
var prefix$1 = "Headless Tree: ";
|
|
71
|
+
var throwError = (message) => Error(prefix$1 + message);
|
|
72
|
+
var logWarning = (message) => console.warn(prefix$1 + message);
|
|
73
|
+
var treeFeature = {
|
|
46
74
|
key: "tree",
|
|
47
|
-
getInitialState: (
|
|
75
|
+
getInitialState: (initialState) => __spreadValues$1({
|
|
48
76
|
expandedItems: [],
|
|
49
77
|
focusedItem: null
|
|
50
|
-
},
|
|
51
|
-
getDefaultConfig: (
|
|
52
|
-
setExpandedItems:
|
|
53
|
-
setFocusedItem:
|
|
54
|
-
},
|
|
78
|
+
}, initialState),
|
|
79
|
+
getDefaultConfig: (defaultConfig, tree) => __spreadValues$1({
|
|
80
|
+
setExpandedItems: makeStateUpdater("expandedItems", tree),
|
|
81
|
+
setFocusedItem: makeStateUpdater("focusedItem", tree)
|
|
82
|
+
}, defaultConfig),
|
|
55
83
|
stateHandlerNames: {
|
|
56
84
|
expandedItems: "setExpandedItems",
|
|
57
85
|
focusedItem: "setFocusedItem"
|
|
58
86
|
},
|
|
59
87
|
treeInstance: {
|
|
60
|
-
getItemsMeta: ({ tree
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
posInSet: c
|
|
71
|
-
}), i.has(t)) {
|
|
72
|
-
let r = (l = e.retrieveChildrenIds(t)) == null ? [] : l, i = 0;
|
|
73
|
-
for (let e of r) a(e, n.concat(t), o + 1, r.length, i++);
|
|
88
|
+
getItemsMeta: ({ tree }) => {
|
|
89
|
+
const { rootItemId } = tree.getConfig();
|
|
90
|
+
const { expandedItems } = tree.getState();
|
|
91
|
+
const flatItems = [];
|
|
92
|
+
const expandedItemsSet = new Set(expandedItems);
|
|
93
|
+
const recursiveAdd = (itemId, path, level, setSize, posInSet) => {
|
|
94
|
+
var _a;
|
|
95
|
+
if (path.includes(itemId)) {
|
|
96
|
+
logWarning(`Circular reference for ${path.join(".")}`);
|
|
97
|
+
return;
|
|
74
98
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
99
|
+
flatItems.push({
|
|
100
|
+
itemId,
|
|
101
|
+
level,
|
|
102
|
+
index: flatItems.length,
|
|
103
|
+
parentId: path.at(-1),
|
|
104
|
+
setSize,
|
|
105
|
+
posInSet
|
|
106
|
+
});
|
|
107
|
+
if (expandedItemsSet.has(itemId)) {
|
|
108
|
+
const children2 = (_a = tree.retrieveChildrenIds(itemId)) != null ? _a : [];
|
|
109
|
+
let i2 = 0;
|
|
110
|
+
for (const childId of children2) recursiveAdd(childId, path.concat(itemId), level + 1, children2.length, i2++);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const children = tree.retrieveChildrenIds(rootItemId);
|
|
114
|
+
let i = 0;
|
|
115
|
+
for (const itemId of children) recursiveAdd(itemId, [rootItemId], 0, children.length, i++);
|
|
116
|
+
return flatItems;
|
|
78
117
|
},
|
|
79
|
-
getFocusedItem: ({ tree
|
|
80
|
-
var
|
|
81
|
-
|
|
82
|
-
return (
|
|
118
|
+
getFocusedItem: ({ tree }) => {
|
|
119
|
+
var _a;
|
|
120
|
+
const focusedItemId = tree.getState().focusedItem;
|
|
121
|
+
return (_a = focusedItemId !== null ? tree.getItemInstance(focusedItemId) : null) != null ? _a : tree.getItems()[0];
|
|
83
122
|
},
|
|
84
|
-
getRootItem: ({ tree
|
|
85
|
-
|
|
86
|
-
return
|
|
123
|
+
getRootItem: ({ tree }) => {
|
|
124
|
+
const { rootItemId } = tree.getConfig();
|
|
125
|
+
return tree.getItemInstance(rootItemId);
|
|
87
126
|
},
|
|
88
|
-
focusNextItem: ({ tree
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
if (!
|
|
92
|
-
|
|
93
|
-
(
|
|
127
|
+
focusNextItem: ({ tree }) => {
|
|
128
|
+
var _a;
|
|
129
|
+
const focused = tree.getFocusedItem().getItemMeta();
|
|
130
|
+
if (!focused) return;
|
|
131
|
+
const nextIndex = Math.min(focused.index + 1, tree.getItems().length - 1);
|
|
132
|
+
(_a = tree.getItems()[nextIndex]) == null || _a.setFocused();
|
|
94
133
|
},
|
|
95
|
-
focusPreviousItem: ({ tree
|
|
96
|
-
var
|
|
97
|
-
|
|
98
|
-
if (!
|
|
99
|
-
|
|
100
|
-
(
|
|
134
|
+
focusPreviousItem: ({ tree }) => {
|
|
135
|
+
var _a;
|
|
136
|
+
const focused = tree.getFocusedItem().getItemMeta();
|
|
137
|
+
if (!focused) return;
|
|
138
|
+
const nextIndex = Math.max(focused.index - 1, 0);
|
|
139
|
+
(_a = tree.getItems()[nextIndex]) == null || _a.setFocused();
|
|
101
140
|
},
|
|
102
|
-
updateDomFocus: ({ tree
|
|
103
|
-
setTimeout(() =>
|
|
104
|
-
var
|
|
105
|
-
|
|
106
|
-
(
|
|
107
|
-
|
|
108
|
-
|
|
141
|
+
updateDomFocus: ({ tree }) => {
|
|
142
|
+
setTimeout(() => __async(null, null, function* () {
|
|
143
|
+
var _a, _b, _c, _d, _e;
|
|
144
|
+
const focusedItem = tree.getFocusedItem();
|
|
145
|
+
(_b = (_a = tree.getConfig()).scrollToItem) == null || _b.call(_a, focusedItem);
|
|
146
|
+
yield poll(() => focusedItem.getElement() !== null, 20, 500);
|
|
147
|
+
const focusedElement = focusedItem.getElement();
|
|
148
|
+
if (!focusedElement) {
|
|
149
|
+
(_c = tree.getItems()[0]) == null || _c.setFocused();
|
|
150
|
+
(_e = (_d = tree.getItems()[0]) == null ? void 0 : _d.getElement()) == null || _e.focus();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
focusedElement.focus();
|
|
109
154
|
}));
|
|
110
155
|
},
|
|
111
|
-
getContainerProps: ({ prev
|
|
156
|
+
getContainerProps: ({ prev, tree }, treeLabel) => __spreadProps$1(__spreadValues$1({}, prev == null ? void 0 : prev()), {
|
|
112
157
|
role: "tree",
|
|
113
|
-
"aria-label":
|
|
114
|
-
ref:
|
|
158
|
+
"aria-label": treeLabel != null ? treeLabel : "",
|
|
159
|
+
ref: tree.registerElement
|
|
115
160
|
}),
|
|
116
|
-
isSearchOpen: () =>
|
|
161
|
+
isSearchOpen: () => false
|
|
117
162
|
},
|
|
118
163
|
itemInstance: {
|
|
119
|
-
scrollTo: (
|
|
120
|
-
var
|
|
121
|
-
(
|
|
164
|
+
scrollTo: (_0, _1) => __async(null, [_0, _1], function* ({ tree, item }, scrollIntoViewArg) {
|
|
165
|
+
var _a, _b, _c;
|
|
166
|
+
(_b = (_a = tree.getConfig()).scrollToItem) == null || _b.call(_a, item);
|
|
167
|
+
yield poll(() => item.getElement() !== null, 20);
|
|
168
|
+
(_c = item.getElement()) == null || _c.scrollIntoView(scrollIntoViewArg);
|
|
122
169
|
}),
|
|
123
|
-
getId: ({ itemId
|
|
124
|
-
getKey: ({ itemId
|
|
125
|
-
getProps: ({ item
|
|
126
|
-
|
|
127
|
-
return
|
|
128
|
-
ref:
|
|
170
|
+
getId: ({ itemId }) => itemId,
|
|
171
|
+
getKey: ({ itemId }) => itemId,
|
|
172
|
+
getProps: ({ item, prev }) => {
|
|
173
|
+
const itemMeta = item.getItemMeta();
|
|
174
|
+
return __spreadProps$1(__spreadValues$1({}, prev == null ? void 0 : prev()), {
|
|
175
|
+
ref: item.registerElement,
|
|
129
176
|
role: "treeitem",
|
|
130
|
-
"aria-setsize":
|
|
131
|
-
"aria-posinset":
|
|
177
|
+
"aria-setsize": itemMeta.setSize,
|
|
178
|
+
"aria-posinset": itemMeta.posInSet + 1,
|
|
132
179
|
"aria-selected": "false",
|
|
133
|
-
"aria-label":
|
|
134
|
-
"aria-level":
|
|
135
|
-
"aria-expanded":
|
|
136
|
-
tabIndex:
|
|
137
|
-
onClick: (
|
|
138
|
-
|
|
180
|
+
"aria-label": item.getItemName(),
|
|
181
|
+
"aria-level": itemMeta.level + 1,
|
|
182
|
+
"aria-expanded": item.isFolder() ? item.isExpanded() : void 0,
|
|
183
|
+
tabIndex: item.isFocused() ? 0 : -1,
|
|
184
|
+
onClick: (e) => {
|
|
185
|
+
item.setFocused();
|
|
186
|
+
item.primaryAction();
|
|
187
|
+
if (e.ctrlKey || e.shiftKey || e.metaKey) return;
|
|
188
|
+
if (!item.isFolder()) return;
|
|
189
|
+
if (item.isExpanded()) item.collapse();
|
|
190
|
+
else item.expand();
|
|
139
191
|
}
|
|
140
192
|
});
|
|
141
193
|
},
|
|
142
|
-
expand: ({ tree
|
|
143
|
-
var
|
|
144
|
-
|
|
194
|
+
expand: ({ tree, item, itemId }) => {
|
|
195
|
+
var _a;
|
|
196
|
+
if (!item.isFolder()) return;
|
|
197
|
+
if ((_a = tree.getState().loadingItemChildrens) == null ? void 0 : _a.includes(itemId)) return;
|
|
198
|
+
tree.applySubStateUpdate("expandedItems", (expandedItems) => [...expandedItems, itemId]);
|
|
199
|
+
tree.rebuildTree();
|
|
200
|
+
},
|
|
201
|
+
collapse: ({ tree, item, itemId }) => {
|
|
202
|
+
if (!item.isFolder()) return;
|
|
203
|
+
tree.applySubStateUpdate("expandedItems", (expandedItems) => expandedItems.filter((id) => id !== itemId));
|
|
204
|
+
tree.rebuildTree();
|
|
145
205
|
},
|
|
146
|
-
|
|
147
|
-
|
|
206
|
+
getItemData: ({ tree, itemId }) => tree.retrieveItemData(itemId),
|
|
207
|
+
equals: ({ item }, other) => item.getId() === (other == null ? void 0 : other.getId()),
|
|
208
|
+
isExpanded: ({ tree, itemId }) => tree.getState().expandedItems.includes(itemId),
|
|
209
|
+
isDescendentOf: ({ item }, parentId) => {
|
|
210
|
+
const parent = item.getParent();
|
|
211
|
+
return Boolean((parent == null ? void 0 : parent.getId()) === parentId || (parent == null ? void 0 : parent.isDescendentOf(parentId)));
|
|
148
212
|
},
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
let n = e.getParent();
|
|
154
|
-
return !!((n == null ? void 0 : n.getId()) === t || n != null && n.isDescendentOf(t));
|
|
213
|
+
isFocused: ({ tree, item, itemId }) => tree.getState().focusedItem === itemId || tree.getState().focusedItem === null && item.getItemMeta().index === 0,
|
|
214
|
+
isFolder: ({ tree, item, itemId }) => itemId === tree.getConfig().rootItemId || tree.getConfig().isItemFolder(item),
|
|
215
|
+
getItemName: ({ tree, item }) => {
|
|
216
|
+
return tree.getConfig().getItemName(item);
|
|
155
217
|
},
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
getItemName: ({ tree: e, item: t }) => e.getConfig().getItemName(t),
|
|
159
|
-
setFocused: ({ tree: e, itemId: t }) => {
|
|
160
|
-
e.applySubStateUpdate("focusedItem", t);
|
|
218
|
+
setFocused: ({ tree, itemId }) => {
|
|
219
|
+
tree.applySubStateUpdate("focusedItem", itemId);
|
|
161
220
|
},
|
|
162
|
-
primaryAction: ({ tree
|
|
163
|
-
var
|
|
164
|
-
return (
|
|
221
|
+
primaryAction: ({ tree, item }) => {
|
|
222
|
+
var _a, _b;
|
|
223
|
+
return (_b = (_a = tree.getConfig()).onPrimaryAction) == null ? void 0 : _b.call(_a, item);
|
|
165
224
|
},
|
|
166
|
-
getParent: ({ tree
|
|
167
|
-
getIndexInParent: ({ item
|
|
168
|
-
getChildren: ({ tree
|
|
169
|
-
getTree: ({ tree
|
|
170
|
-
getItemAbove: ({ tree
|
|
171
|
-
getItemBelow: ({ tree
|
|
225
|
+
getParent: ({ tree, item }) => item.getItemMeta().parentId ? tree.getItemInstance(item.getItemMeta().parentId) : void 0,
|
|
226
|
+
getIndexInParent: ({ item }) => item.getItemMeta().posInSet,
|
|
227
|
+
getChildren: ({ tree, itemId }) => tree.retrieveChildrenIds(itemId).map((id) => tree.getItemInstance(id)),
|
|
228
|
+
getTree: ({ tree }) => tree,
|
|
229
|
+
getItemAbove: ({ tree, item }) => tree.getItems()[item.getItemMeta().index - 1],
|
|
230
|
+
getItemBelow: ({ tree, item }) => tree.getItems()[item.getItemMeta().index + 1]
|
|
172
231
|
},
|
|
173
232
|
hotkeys: {
|
|
174
233
|
focusNextItem: {
|
|
175
234
|
hotkey: "ArrowDown",
|
|
176
|
-
canRepeat:
|
|
177
|
-
preventDefault:
|
|
178
|
-
isEnabled: (
|
|
179
|
-
var
|
|
180
|
-
return !((
|
|
235
|
+
canRepeat: true,
|
|
236
|
+
preventDefault: true,
|
|
237
|
+
isEnabled: (tree) => {
|
|
238
|
+
var _a, _b;
|
|
239
|
+
return !((_b = (_a = tree.isSearchOpen) == null ? void 0 : _a.call(tree)) != null ? _b : false) && !tree.getState().dnd;
|
|
181
240
|
},
|
|
182
|
-
handler: (e,
|
|
183
|
-
|
|
241
|
+
handler: (e, tree) => {
|
|
242
|
+
tree.focusNextItem();
|
|
243
|
+
tree.updateDomFocus();
|
|
184
244
|
}
|
|
185
245
|
},
|
|
186
246
|
focusPreviousItem: {
|
|
187
247
|
hotkey: "ArrowUp",
|
|
188
|
-
canRepeat:
|
|
189
|
-
preventDefault:
|
|
190
|
-
isEnabled: (
|
|
191
|
-
var
|
|
192
|
-
return !((
|
|
248
|
+
canRepeat: true,
|
|
249
|
+
preventDefault: true,
|
|
250
|
+
isEnabled: (tree) => {
|
|
251
|
+
var _a, _b;
|
|
252
|
+
return !((_b = (_a = tree.isSearchOpen) == null ? void 0 : _a.call(tree)) != null ? _b : false) && !tree.getState().dnd;
|
|
193
253
|
},
|
|
194
|
-
handler: (e,
|
|
195
|
-
|
|
254
|
+
handler: (e, tree) => {
|
|
255
|
+
tree.focusPreviousItem();
|
|
256
|
+
tree.updateDomFocus();
|
|
196
257
|
}
|
|
197
258
|
},
|
|
198
259
|
expandOrDown: {
|
|
199
260
|
hotkey: "ArrowRight",
|
|
200
|
-
canRepeat:
|
|
201
|
-
handler: (e,
|
|
202
|
-
|
|
203
|
-
|
|
261
|
+
canRepeat: true,
|
|
262
|
+
handler: (e, tree) => {
|
|
263
|
+
const item = tree.getFocusedItem();
|
|
264
|
+
if (item.isExpanded() || !item.isFolder()) {
|
|
265
|
+
tree.focusNextItem();
|
|
266
|
+
tree.updateDomFocus();
|
|
267
|
+
} else item.expand();
|
|
204
268
|
}
|
|
205
269
|
},
|
|
206
270
|
collapseOrUp: {
|
|
207
271
|
hotkey: "ArrowLeft",
|
|
208
|
-
canRepeat:
|
|
209
|
-
handler: (e,
|
|
210
|
-
var
|
|
211
|
-
|
|
212
|
-
(!
|
|
272
|
+
canRepeat: true,
|
|
273
|
+
handler: (e, tree) => {
|
|
274
|
+
var _a;
|
|
275
|
+
const item = tree.getFocusedItem();
|
|
276
|
+
if ((!item.isExpanded() || !item.isFolder()) && item.getItemMeta().level !== 0) {
|
|
277
|
+
(_a = item.getParent()) == null || _a.setFocused();
|
|
278
|
+
tree.updateDomFocus();
|
|
279
|
+
} else item.collapse();
|
|
213
280
|
}
|
|
214
281
|
},
|
|
215
282
|
focusFirstItem: {
|
|
216
283
|
hotkey: "Home",
|
|
217
|
-
handler: (e,
|
|
218
|
-
var
|
|
219
|
-
(
|
|
284
|
+
handler: (e, tree) => {
|
|
285
|
+
var _a;
|
|
286
|
+
(_a = tree.getItems()[0]) == null || _a.setFocused();
|
|
287
|
+
tree.updateDomFocus();
|
|
220
288
|
}
|
|
221
289
|
},
|
|
222
290
|
focusLastItem: {
|
|
223
291
|
hotkey: "End",
|
|
224
|
-
handler: (e,
|
|
225
|
-
var
|
|
226
|
-
(
|
|
292
|
+
handler: (e, tree) => {
|
|
293
|
+
var _a;
|
|
294
|
+
(_a = tree.getItems()[tree.getItems().length - 1]) == null || _a.setFocused();
|
|
295
|
+
tree.updateDomFocus();
|
|
227
296
|
}
|
|
228
297
|
}
|
|
229
298
|
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
299
|
+
};
|
|
300
|
+
var buildStaticInstance = (features, instanceType, buildOpts) => {
|
|
301
|
+
const instance = {};
|
|
302
|
+
const finalize = () => {
|
|
303
|
+
const opts = buildOpts(instance);
|
|
304
|
+
featureLoop: for (let i = 0; i < features.length; i++) {
|
|
305
|
+
const definition = features[i][instanceType];
|
|
306
|
+
if (!definition) continue featureLoop;
|
|
307
|
+
methodLoop: for (const [key, method] of Object.entries(definition)) {
|
|
308
|
+
if (!method) continue methodLoop;
|
|
309
|
+
const prev = instance[key];
|
|
310
|
+
instance[key] = (...args) => {
|
|
311
|
+
return method(__spreadProps$1(__spreadValues$1({}, opts), { prev }), ...args);
|
|
312
|
+
};
|
|
241
313
|
}
|
|
242
314
|
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
315
|
+
};
|
|
316
|
+
return [instance, finalize];
|
|
317
|
+
};
|
|
318
|
+
var verifyFeatures = (features) => {
|
|
319
|
+
var _a;
|
|
320
|
+
const loadedFeatures = features == null ? void 0 : features.map((feature) => feature.key);
|
|
321
|
+
for (const feature of features != null ? features : []) {
|
|
322
|
+
const missingDependency = (_a = feature.deps) == null ? void 0 : _a.find((dep) => !(loadedFeatures == null ? void 0 : loadedFeatures.includes(dep)));
|
|
323
|
+
if (missingDependency) throw throwError(`${feature.key} needs ${missingDependency}`);
|
|
250
324
|
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
325
|
+
};
|
|
326
|
+
var exhaustiveSort = (arr, compareFn) => {
|
|
327
|
+
const n = arr.length;
|
|
328
|
+
for (let i = 0; i < n; i++) for (let j = i + 1; j < n; j++) if (compareFn(arr[j], arr[i]) < 0) [arr[i], arr[j]] = [arr[j], arr[i]];
|
|
329
|
+
return arr;
|
|
330
|
+
};
|
|
331
|
+
var compareFeatures = (originalOrder) => (feature1, feature2) => {
|
|
332
|
+
var _a, _b;
|
|
333
|
+
if (feature2.key && ((_a = feature1.overwrites) == null ? void 0 : _a.includes(feature2.key))) return 1;
|
|
334
|
+
if (feature1.key && ((_b = feature2.overwrites) == null ? void 0 : _b.includes(feature1.key))) return -1;
|
|
335
|
+
return originalOrder.indexOf(feature1) - originalOrder.indexOf(feature2);
|
|
336
|
+
};
|
|
337
|
+
var sortFeatures = (features = []) => exhaustiveSort(features, compareFeatures(features));
|
|
338
|
+
var createTree = (initialConfig) => {
|
|
339
|
+
var _a, _b, _c, _d;
|
|
340
|
+
const buildInstance = (_a = initialConfig.instanceBuilder) != null ? _a : buildStaticInstance;
|
|
341
|
+
const additionalFeatures = [treeFeature, ...sortFeatures(initialConfig.features)];
|
|
342
|
+
verifyFeatures(additionalFeatures);
|
|
343
|
+
const features = [...additionalFeatures];
|
|
344
|
+
const [treeInstance, finalizeTree] = buildInstance(features, "treeInstance", (tree) => ({ tree }));
|
|
345
|
+
let state = additionalFeatures.reduce((acc, feature) => {
|
|
346
|
+
var _a2, _b2;
|
|
347
|
+
return (_b2 = (_a2 = feature.getInitialState) == null ? void 0 : _a2.call(feature, acc, treeInstance)) != null ? _b2 : acc;
|
|
348
|
+
}, (_c = (_b = initialConfig.initialState) != null ? _b : initialConfig.state) != null ? _c : {});
|
|
349
|
+
let config = additionalFeatures.reduce((acc, feature) => {
|
|
350
|
+
var _a2, _b2;
|
|
351
|
+
return (_b2 = (_a2 = feature.getDefaultConfig) == null ? void 0 : _a2.call(feature, acc, treeInstance)) != null ? _b2 : acc;
|
|
352
|
+
}, initialConfig);
|
|
353
|
+
const stateHandlerNames = additionalFeatures.reduce((acc, feature) => __spreadValues$1(__spreadValues$1({}, acc), feature.stateHandlerNames), {});
|
|
354
|
+
let treeElement;
|
|
355
|
+
const treeDataRef = { current: {} };
|
|
356
|
+
let rebuildScheduled = false;
|
|
357
|
+
const itemInstancesMap = {};
|
|
358
|
+
let itemInstances = [];
|
|
359
|
+
const itemElementsMap = {};
|
|
360
|
+
const itemDataRefs = {};
|
|
361
|
+
let itemMetaMap = {};
|
|
362
|
+
const hotkeyPresets = {};
|
|
363
|
+
const rebuildItemMeta = () => {
|
|
364
|
+
itemInstances = [];
|
|
365
|
+
itemMetaMap = {};
|
|
366
|
+
const [rootInstance, finalizeRootInstance] = buildInstance(features, "itemInstance", (item) => ({
|
|
367
|
+
item,
|
|
368
|
+
tree: treeInstance,
|
|
369
|
+
itemId: config.rootItemId
|
|
274
370
|
}));
|
|
275
|
-
|
|
276
|
-
|
|
371
|
+
finalizeRootInstance();
|
|
372
|
+
itemInstancesMap[config.rootItemId] = rootInstance;
|
|
373
|
+
itemMetaMap[config.rootItemId] = {
|
|
374
|
+
itemId: config.rootItemId,
|
|
277
375
|
index: -1,
|
|
278
376
|
parentId: null,
|
|
279
377
|
level: -1,
|
|
280
378
|
posInSet: 0,
|
|
281
379
|
setSize: 1
|
|
282
380
|
};
|
|
283
|
-
for (
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
381
|
+
for (const item of treeInstance.getItemsMeta()) {
|
|
382
|
+
itemMetaMap[item.itemId] = item;
|
|
383
|
+
if (!itemInstancesMap[item.itemId]) {
|
|
384
|
+
const [instance, finalizeInstance] = buildInstance(features, "itemInstance", (instance2) => ({
|
|
385
|
+
item: instance2,
|
|
386
|
+
tree: treeInstance,
|
|
387
|
+
itemId: item.itemId
|
|
388
|
+
}));
|
|
389
|
+
finalizeInstance();
|
|
390
|
+
itemInstancesMap[item.itemId] = instance;
|
|
391
|
+
itemInstances.push(instance);
|
|
392
|
+
} else itemInstances.push(itemInstancesMap[item.itemId]);
|
|
291
393
|
}
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
394
|
+
rebuildScheduled = false;
|
|
395
|
+
};
|
|
396
|
+
const eachFeature = (fn) => {
|
|
397
|
+
for (const feature of additionalFeatures) fn(feature);
|
|
295
398
|
};
|
|
296
|
-
|
|
399
|
+
features.unshift({
|
|
297
400
|
key: "main",
|
|
298
401
|
treeInstance: {
|
|
299
|
-
getState: () =>
|
|
300
|
-
setState: ({},
|
|
301
|
-
var
|
|
302
|
-
(
|
|
402
|
+
getState: () => state,
|
|
403
|
+
setState: ({}, updater) => {
|
|
404
|
+
var _a2;
|
|
405
|
+
(_a2 = config.setState) == null || _a2.call(config, state);
|
|
303
406
|
},
|
|
304
|
-
setMounted: ({},
|
|
305
|
-
var
|
|
306
|
-
|
|
307
|
-
|
|
407
|
+
setMounted: ({}, isMounted) => {
|
|
408
|
+
var _a2;
|
|
409
|
+
const ref = treeDataRef.current;
|
|
410
|
+
ref.isMounted = isMounted;
|
|
411
|
+
if (isMounted) {
|
|
412
|
+
(_a2 = ref.waitingForMount) == null || _a2.forEach((cb) => cb());
|
|
413
|
+
ref.waitingForMount = [];
|
|
414
|
+
}
|
|
308
415
|
},
|
|
309
|
-
applySubStateUpdate: ({},
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
|
|
416
|
+
applySubStateUpdate: ({}, stateName, updater) => {
|
|
417
|
+
const apply = () => {
|
|
418
|
+
state[stateName] = typeof updater === "function" ? updater(state[stateName]) : updater;
|
|
419
|
+
const externalStateSetter = config[stateHandlerNames[stateName]];
|
|
420
|
+
externalStateSetter == null || externalStateSetter(state[stateName]);
|
|
421
|
+
};
|
|
422
|
+
const ref = treeDataRef.current;
|
|
423
|
+
if (ref.isMounted) apply();
|
|
424
|
+
else {
|
|
425
|
+
ref.waitingForMount != null || (ref.waitingForMount = []);
|
|
426
|
+
ref.waitingForMount.push(apply);
|
|
427
|
+
}
|
|
316
428
|
},
|
|
317
429
|
rebuildTree: () => {
|
|
318
|
-
var
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
430
|
+
var _a2;
|
|
431
|
+
const ref = treeDataRef.current;
|
|
432
|
+
if (ref.isMounted) {
|
|
433
|
+
rebuildItemMeta();
|
|
434
|
+
(_a2 = config.setState) == null || _a2.call(config, state);
|
|
435
|
+
} else {
|
|
436
|
+
ref.waitingForMount != null || (ref.waitingForMount = []);
|
|
437
|
+
ref.waitingForMount.push(() => {
|
|
438
|
+
var _a3;
|
|
439
|
+
rebuildItemMeta();
|
|
440
|
+
(_a3 = config.setState) == null || _a3.call(config, state);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
324
443
|
},
|
|
325
444
|
scheduleRebuildTree: () => {
|
|
326
|
-
|
|
445
|
+
rebuildScheduled = true;
|
|
327
446
|
},
|
|
328
|
-
getConfig: () =>
|
|
329
|
-
setConfig: (
|
|
330
|
-
var
|
|
331
|
-
|
|
332
|
-
|
|
447
|
+
getConfig: () => config,
|
|
448
|
+
setConfig: (_, updater) => {
|
|
449
|
+
var _a2, _b2, _c2;
|
|
450
|
+
const newConfig = typeof updater === "function" ? updater(config) : updater;
|
|
451
|
+
const hasChangedExpandedItems = ((_a2 = newConfig.state) == null ? void 0 : _a2.expandedItems) && ((_b2 = newConfig.state) == null ? void 0 : _b2.expandedItems) !== state.expandedItems;
|
|
452
|
+
config = newConfig;
|
|
453
|
+
if (newConfig.state) state = __spreadValues$1(__spreadValues$1({}, state), newConfig.state);
|
|
454
|
+
if (hasChangedExpandedItems) {
|
|
455
|
+
rebuildItemMeta();
|
|
456
|
+
(_c2 = config.setState) == null || _c2.call(config, state);
|
|
457
|
+
}
|
|
333
458
|
},
|
|
334
|
-
getItemInstance: ({},
|
|
335
|
-
|
|
336
|
-
if (!
|
|
337
|
-
|
|
338
|
-
item:
|
|
339
|
-
tree:
|
|
340
|
-
itemId
|
|
459
|
+
getItemInstance: ({}, itemId) => {
|
|
460
|
+
const existingInstance = itemInstancesMap[itemId];
|
|
461
|
+
if (!existingInstance) {
|
|
462
|
+
const [instance, finalizeInstance] = buildInstance(features, "itemInstance", (instance2) => ({
|
|
463
|
+
item: instance2,
|
|
464
|
+
tree: treeInstance,
|
|
465
|
+
itemId
|
|
341
466
|
}));
|
|
342
|
-
|
|
467
|
+
finalizeInstance();
|
|
468
|
+
return instance;
|
|
343
469
|
}
|
|
344
|
-
return
|
|
470
|
+
return existingInstance;
|
|
471
|
+
},
|
|
472
|
+
getItems: () => {
|
|
473
|
+
if (rebuildScheduled) rebuildItemMeta();
|
|
474
|
+
return itemInstances;
|
|
345
475
|
},
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
var
|
|
350
|
-
return (
|
|
351
|
-
})
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
476
|
+
registerElement: ({}, element) => {
|
|
477
|
+
if (treeElement === element) return;
|
|
478
|
+
if (treeElement && !element) eachFeature((feature) => {
|
|
479
|
+
var _a2;
|
|
480
|
+
return (_a2 = feature.onTreeUnmount) == null ? void 0 : _a2.call(feature, treeInstance, treeElement);
|
|
481
|
+
});
|
|
482
|
+
else if (!treeElement && element) eachFeature((feature) => {
|
|
483
|
+
var _a2;
|
|
484
|
+
return (_a2 = feature.onTreeMount) == null ? void 0 : _a2.call(feature, treeInstance, element);
|
|
485
|
+
});
|
|
486
|
+
treeElement = element;
|
|
355
487
|
},
|
|
356
|
-
getElement: () =>
|
|
357
|
-
getDataRef: () =>
|
|
358
|
-
getHotkeyPresets: () =>
|
|
488
|
+
getElement: () => treeElement,
|
|
489
|
+
getDataRef: () => treeDataRef,
|
|
490
|
+
getHotkeyPresets: () => hotkeyPresets
|
|
359
491
|
},
|
|
360
492
|
itemInstance: {
|
|
361
|
-
registerElement: ({ itemId
|
|
362
|
-
if (
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
var
|
|
366
|
-
return (
|
|
367
|
-
})
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
493
|
+
registerElement: ({ itemId, item }, element) => {
|
|
494
|
+
if (itemElementsMap[itemId] === element) return;
|
|
495
|
+
const oldElement = itemElementsMap[itemId];
|
|
496
|
+
if (oldElement && !element) eachFeature((feature) => {
|
|
497
|
+
var _a2;
|
|
498
|
+
return (_a2 = feature.onItemUnmount) == null ? void 0 : _a2.call(feature, item, oldElement, treeInstance);
|
|
499
|
+
});
|
|
500
|
+
else if (!oldElement && element) eachFeature((feature) => {
|
|
501
|
+
var _a2;
|
|
502
|
+
return (_a2 = feature.onItemMount) == null ? void 0 : _a2.call(feature, item, element, treeInstance);
|
|
503
|
+
});
|
|
504
|
+
itemElementsMap[itemId] = element;
|
|
371
505
|
},
|
|
372
|
-
getElement: ({ itemId
|
|
373
|
-
getDataRef: ({ itemId
|
|
374
|
-
var
|
|
375
|
-
return (
|
|
506
|
+
getElement: ({ itemId }) => itemElementsMap[itemId],
|
|
507
|
+
getDataRef: ({ itemId }) => {
|
|
508
|
+
var _a2;
|
|
509
|
+
return (_a2 = itemDataRefs[itemId]) != null ? _a2 : itemDataRefs[itemId] = { current: {} };
|
|
376
510
|
},
|
|
377
|
-
getItemMeta: ({ itemId
|
|
378
|
-
var
|
|
379
|
-
return (
|
|
380
|
-
itemId
|
|
511
|
+
getItemMeta: ({ itemId }) => {
|
|
512
|
+
var _a2;
|
|
513
|
+
return (_a2 = itemMetaMap[itemId]) != null ? _a2 : {
|
|
514
|
+
itemId,
|
|
381
515
|
parentId: null,
|
|
382
516
|
level: -1,
|
|
383
517
|
index: -1,
|
|
384
518
|
posInSet: 0,
|
|
385
519
|
setSize: 1
|
|
386
|
-
}
|
|
520
|
+
};
|
|
387
521
|
}
|
|
388
522
|
}
|
|
389
523
|
});
|
|
390
|
-
for (
|
|
391
|
-
|
|
392
|
-
|
|
524
|
+
for (const feature of features) Object.assign(hotkeyPresets, (_d = feature.hotkeys) != null ? _d : {});
|
|
525
|
+
finalizeTree();
|
|
526
|
+
return treeInstance;
|
|
527
|
+
};
|
|
528
|
+
var selectionFeature = {
|
|
393
529
|
key: "selection",
|
|
394
|
-
getInitialState: (
|
|
395
|
-
getDefaultConfig: (
|
|
530
|
+
getInitialState: (initialState) => __spreadValues$1({ selectedItems: [] }, initialState),
|
|
531
|
+
getDefaultConfig: (defaultConfig, tree) => __spreadValues$1({ setSelectedItems: makeStateUpdater("selectedItems", tree) }, defaultConfig),
|
|
396
532
|
stateHandlerNames: { selectedItems: "setSelectedItems" },
|
|
397
533
|
treeInstance: {
|
|
398
|
-
setSelectedItems: ({ tree
|
|
399
|
-
|
|
534
|
+
setSelectedItems: ({ tree }, selectedItems) => {
|
|
535
|
+
tree.applySubStateUpdate("selectedItems", selectedItems);
|
|
400
536
|
},
|
|
401
|
-
getSelectedItems: ({ tree
|
|
537
|
+
getSelectedItems: ({ tree }) => {
|
|
538
|
+
return tree.getState().selectedItems.map(tree.getItemInstance);
|
|
539
|
+
}
|
|
402
540
|
},
|
|
403
541
|
itemInstance: {
|
|
404
|
-
select: ({ tree
|
|
405
|
-
|
|
406
|
-
|
|
542
|
+
select: ({ tree, itemId }) => {
|
|
543
|
+
const { selectedItems } = tree.getState();
|
|
544
|
+
tree.setSelectedItems(selectedItems.includes(itemId) ? selectedItems : [...selectedItems, itemId]);
|
|
407
545
|
},
|
|
408
|
-
deselect: ({ tree
|
|
409
|
-
|
|
410
|
-
|
|
546
|
+
deselect: ({ tree, itemId }) => {
|
|
547
|
+
const { selectedItems } = tree.getState();
|
|
548
|
+
tree.setSelectedItems(selectedItems.filter((id) => id !== itemId));
|
|
411
549
|
},
|
|
412
|
-
isSelected: ({ tree
|
|
413
|
-
|
|
414
|
-
return
|
|
550
|
+
isSelected: ({ tree, itemId }) => {
|
|
551
|
+
const { selectedItems } = tree.getState();
|
|
552
|
+
return selectedItems.includes(itemId);
|
|
415
553
|
},
|
|
416
|
-
selectUpTo: ({ tree
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
554
|
+
selectUpTo: ({ tree, item, itemId }, ctrl) => {
|
|
555
|
+
const indexA = item.getItemMeta().index;
|
|
556
|
+
const dataRef = tree.getDataRef();
|
|
557
|
+
if (!dataRef.current.selectUpToAnchorId) {
|
|
558
|
+
dataRef.current.selectUpToAnchorId = itemId;
|
|
559
|
+
tree.setSelectedItems([itemId]);
|
|
420
560
|
return;
|
|
421
561
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
562
|
+
const indexB = tree.getItemInstance(dataRef.current.selectUpToAnchorId).getItemMeta().index;
|
|
563
|
+
const [a, b] = indexA < indexB ? [indexA, indexB] : [indexB, indexA];
|
|
564
|
+
const newSelectedItems = tree.getItems().slice(a, b + 1).map((treeItem) => treeItem.getItemMeta().itemId);
|
|
565
|
+
if (!ctrl) {
|
|
566
|
+
tree.setSelectedItems(newSelectedItems);
|
|
425
567
|
return;
|
|
426
568
|
}
|
|
427
|
-
|
|
428
|
-
|
|
569
|
+
const { selectedItems } = tree.getState();
|
|
570
|
+
const uniqueSelectedItems = [.../* @__PURE__ */ new Set([...selectedItems, ...newSelectedItems])];
|
|
571
|
+
tree.setSelectedItems(uniqueSelectedItems);
|
|
429
572
|
},
|
|
430
|
-
toggleSelect: ({ item
|
|
431
|
-
|
|
573
|
+
toggleSelect: ({ item }) => {
|
|
574
|
+
if (item.isSelected()) item.deselect();
|
|
575
|
+
else item.select();
|
|
432
576
|
},
|
|
433
|
-
getProps: ({ tree
|
|
434
|
-
"aria-selected":
|
|
435
|
-
onClick: (
|
|
436
|
-
var
|
|
437
|
-
|
|
577
|
+
getProps: ({ tree, item, itemId, prev }) => __spreadProps$1(__spreadValues$1({}, prev == null ? void 0 : prev()), {
|
|
578
|
+
"aria-selected": item.isSelected() ? "true" : "false",
|
|
579
|
+
onClick: (e) => {
|
|
580
|
+
var _a, _b;
|
|
581
|
+
if (e.shiftKey) item.selectUpTo(e.ctrlKey || e.metaKey);
|
|
582
|
+
else if (e.ctrlKey || e.metaKey) item.toggleSelect();
|
|
583
|
+
else tree.setSelectedItems([itemId]);
|
|
584
|
+
if (!e.shiftKey) tree.getDataRef().current.selectUpToAnchorId = itemId;
|
|
585
|
+
(_b = (_a = prev == null ? void 0 : prev()) == null ? void 0 : _a.onClick) == null || _b.call(_a, e);
|
|
438
586
|
}
|
|
439
587
|
})
|
|
440
588
|
},
|
|
441
589
|
hotkeys: {
|
|
442
590
|
toggleSelectedItem: {
|
|
443
591
|
hotkey: "Control+Space",
|
|
444
|
-
preventDefault:
|
|
445
|
-
handler: (
|
|
446
|
-
|
|
592
|
+
preventDefault: true,
|
|
593
|
+
handler: (_, tree) => {
|
|
594
|
+
tree.getFocusedItem().toggleSelect();
|
|
447
595
|
}
|
|
448
596
|
},
|
|
449
597
|
selectUpwards: {
|
|
450
598
|
hotkey: "Shift+ArrowUp",
|
|
451
|
-
handler: (e,
|
|
452
|
-
|
|
453
|
-
|
|
599
|
+
handler: (e, tree) => {
|
|
600
|
+
const focused = tree.getFocusedItem();
|
|
601
|
+
const above = focused.getItemAbove();
|
|
602
|
+
if (!above) return;
|
|
603
|
+
if (focused.isSelected() && above.isSelected()) focused.deselect();
|
|
604
|
+
else above.select();
|
|
605
|
+
above.setFocused();
|
|
606
|
+
tree.updateDomFocus();
|
|
454
607
|
}
|
|
455
608
|
},
|
|
456
609
|
selectDownwards: {
|
|
457
610
|
hotkey: "Shift+ArrowDown",
|
|
458
|
-
handler: (e,
|
|
459
|
-
|
|
460
|
-
|
|
611
|
+
handler: (e, tree) => {
|
|
612
|
+
const focused = tree.getFocusedItem();
|
|
613
|
+
const below = focused.getItemBelow();
|
|
614
|
+
if (!below) return;
|
|
615
|
+
if (focused.isSelected() && below.isSelected()) focused.deselect();
|
|
616
|
+
else below.select();
|
|
617
|
+
below.setFocused();
|
|
618
|
+
tree.updateDomFocus();
|
|
461
619
|
}
|
|
462
620
|
},
|
|
463
621
|
selectAll: {
|
|
464
622
|
hotkey: "Control+KeyA",
|
|
465
|
-
preventDefault:
|
|
466
|
-
handler: (e,
|
|
467
|
-
|
|
623
|
+
preventDefault: true,
|
|
624
|
+
handler: (e, tree) => {
|
|
625
|
+
tree.setSelectedItems(tree.getItems().map((item) => item.getId()));
|
|
468
626
|
}
|
|
469
627
|
}
|
|
470
628
|
}
|
|
471
|
-
}
|
|
629
|
+
};
|
|
630
|
+
var resolveKeyCode = (event) => event.code !== "" && event.code !== "Unidentified" ? event.code : event.key;
|
|
631
|
+
var specialKeys = {
|
|
472
632
|
letter: /^Key[A-Z]$/,
|
|
473
633
|
letterornumber: /^(Key[A-Z]|Digit[0-9])$/,
|
|
474
634
|
plus: /^(NumpadAdd|Plus)$/,
|
|
@@ -477,7 +637,8 @@ var x = (e, t = 100, n = 1e3) => new Promise((r) => {
|
|
|
477
637
|
shift: /^(ShiftLeft|ShiftRight)$/,
|
|
478
638
|
metaorcontrol: /^(MetaLeft|MetaRight|ControlLeft|ControlRight)$/,
|
|
479
639
|
enter: /^(Enter|NumpadEnter)$/
|
|
480
|
-
}
|
|
640
|
+
};
|
|
641
|
+
var modifierKeyCodes = /* @__PURE__ */ new Set([
|
|
481
642
|
"MetaLeft",
|
|
482
643
|
"MetaRight",
|
|
483
644
|
"Meta",
|
|
@@ -490,177 +651,822 @@ var x = (e, t = 100, n = 1e3) => new Promise((r) => {
|
|
|
490
651
|
"ShiftLeft",
|
|
491
652
|
"ShiftRight",
|
|
492
653
|
"Shift"
|
|
493
|
-
])
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
return
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
return
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
|
|
654
|
+
]);
|
|
655
|
+
var testHotkeyMatch = (pressedKeys, tree, hotkey) => {
|
|
656
|
+
const supposedKeys = hotkey.hotkey.toLowerCase().split("+");
|
|
657
|
+
const doKeysMatch = supposedKeys.every((key) => {
|
|
658
|
+
if (key in specialKeys) return [...pressedKeys].some((pressedKey) => specialKeys[key].test(pressedKey));
|
|
659
|
+
const pressedKeysLowerCase = [...pressedKeys].map((pressedKey) => pressedKey.toLowerCase());
|
|
660
|
+
return pressedKeysLowerCase.includes(key.toLowerCase()) || pressedKeysLowerCase.includes(`key${key.toLowerCase()}`);
|
|
661
|
+
});
|
|
662
|
+
const isEnabled = !hotkey.isEnabled || hotkey.isEnabled(tree);
|
|
663
|
+
return doKeysMatch && isEnabled && pressedKeys.size === supposedKeys.length;
|
|
664
|
+
};
|
|
665
|
+
var findHotkeyMatch = (pressedKeys, tree, config1, config2) => {
|
|
666
|
+
var _a;
|
|
667
|
+
return (_a = Object.entries(__spreadValues$1(__spreadValues$1({}, config1), config2)).find(([, hotkey]) => testHotkeyMatch(pressedKeys, tree, hotkey))) == null ? void 0 : _a[0];
|
|
668
|
+
};
|
|
669
|
+
var hotkeysCoreController = {
|
|
670
|
+
clearPressedKeys: (dataRef) => {
|
|
671
|
+
dataRef.current.pressedKeys = /* @__PURE__ */ new Set();
|
|
506
672
|
},
|
|
507
|
-
dispatchKeyDown: (
|
|
508
|
-
var
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
673
|
+
dispatchKeyDown: (tree, dataRef, eventLike, options = {}) => {
|
|
674
|
+
var _a, _b, _c, _e;
|
|
675
|
+
const { isInputFocused = false, releaseAfterDispatch = false } = options;
|
|
676
|
+
const { ignoreHotkeysOnInputs, onTreeHotkey, hotkeys } = tree.getConfig();
|
|
677
|
+
if (isInputFocused && ignoreHotkeysOnInputs) return;
|
|
678
|
+
const resolvedCode = resolveKeyCode({
|
|
679
|
+
code: (_a = eventLike.code) != null ? _a : "",
|
|
680
|
+
key: (_b = eventLike.key) != null ? _b : ""
|
|
514
681
|
});
|
|
515
|
-
(
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
if (
|
|
520
|
-
|
|
521
|
-
|
|
682
|
+
(_c = dataRef.current).pressedKeys != null || (_c.pressedKeys = /* @__PURE__ */ new Set());
|
|
683
|
+
const isNewKey = !dataRef.current.pressedKeys.has(resolvedCode);
|
|
684
|
+
if (resolvedCode) dataRef.current.pressedKeys.add(resolvedCode);
|
|
685
|
+
const hotkeyName = findHotkeyMatch(dataRef.current.pressedKeys, tree, tree.getHotkeyPresets(), hotkeys);
|
|
686
|
+
if (releaseAfterDispatch && resolvedCode) dataRef.current.pressedKeys.delete(resolvedCode);
|
|
687
|
+
if (!hotkeyName) return;
|
|
688
|
+
const hotkeyConfig = __spreadValues$1(__spreadValues$1({}, tree.getHotkeyPresets()[hotkeyName]), hotkeys == null ? void 0 : hotkeys[hotkeyName]);
|
|
689
|
+
if (!hotkeyConfig) return;
|
|
690
|
+
if (!hotkeyConfig.allowWhenInputFocused && isInputFocused) return;
|
|
691
|
+
if (!hotkeyConfig.canRepeat && !isNewKey) return;
|
|
692
|
+
if (hotkeyConfig.preventDefault) (_e = eventLike.preventDefault) == null || _e.call(eventLike);
|
|
693
|
+
hotkeyConfig.handler(eventLike, tree);
|
|
694
|
+
onTreeHotkey == null || onTreeHotkey(hotkeyName, eventLike);
|
|
522
695
|
},
|
|
523
|
-
dispatchKeyUp: (
|
|
524
|
-
var
|
|
525
|
-
|
|
526
|
-
code: (
|
|
527
|
-
key: (
|
|
696
|
+
dispatchKeyUp: (dataRef, eventLike) => {
|
|
697
|
+
var _a, _b, _c;
|
|
698
|
+
const resolvedCode = resolveKeyCode({
|
|
699
|
+
code: (_a = eventLike.code) != null ? _a : "",
|
|
700
|
+
key: (_b = eventLike.key) != null ? _b : ""
|
|
528
701
|
});
|
|
529
|
-
|
|
702
|
+
if (!resolvedCode) return;
|
|
703
|
+
(_c = dataRef.current).pressedKeys != null || (_c.pressedKeys = /* @__PURE__ */ new Set());
|
|
704
|
+
if (modifierKeyCodes.has(resolvedCode)) dataRef.current.pressedKeys = new Set([...dataRef.current.pressedKeys].filter((pressedKey) => modifierKeyCodes.has(pressedKey)));
|
|
705
|
+
dataRef.current.pressedKeys.delete(resolvedCode);
|
|
530
706
|
}
|
|
531
|
-
}
|
|
707
|
+
};
|
|
708
|
+
var hotkeysCoreFeature = {
|
|
532
709
|
key: "hotkeys-core",
|
|
533
|
-
onTreeMount: (
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
710
|
+
onTreeMount: (tree, element) => {
|
|
711
|
+
const data = tree.getDataRef();
|
|
712
|
+
const keydown = (e) => {
|
|
713
|
+
const isInputFocused = e.target instanceof HTMLInputElement;
|
|
714
|
+
hotkeysCoreController.dispatchKeyDown(tree, data, e, {
|
|
715
|
+
isInputFocused,
|
|
716
|
+
releaseAfterDispatch: isInputFocused
|
|
539
717
|
});
|
|
540
|
-
}, i = (e) => {
|
|
541
|
-
A.dispatchKeyUp(n, e);
|
|
542
|
-
}, a = () => {
|
|
543
|
-
A.clearPressedKeys(n);
|
|
544
718
|
};
|
|
545
|
-
|
|
719
|
+
const keyup = (e) => {
|
|
720
|
+
hotkeysCoreController.dispatchKeyUp(data, e);
|
|
721
|
+
};
|
|
722
|
+
const reset = () => {
|
|
723
|
+
hotkeysCoreController.clearPressedKeys(data);
|
|
724
|
+
};
|
|
725
|
+
element.addEventListener("keydown", keydown);
|
|
726
|
+
document.addEventListener("keyup", keyup);
|
|
727
|
+
window.addEventListener("focus", reset);
|
|
728
|
+
data.current.keydownHandler = keydown;
|
|
729
|
+
data.current.keyupHandler = keyup;
|
|
730
|
+
data.current.resetHandler = reset;
|
|
546
731
|
},
|
|
547
|
-
onTreeUnmount: (
|
|
548
|
-
|
|
549
|
-
|
|
732
|
+
onTreeUnmount: (tree, element) => {
|
|
733
|
+
const data = tree.getDataRef();
|
|
734
|
+
if (data.current.keyupHandler) {
|
|
735
|
+
document.removeEventListener("keyup", data.current.keyupHandler);
|
|
736
|
+
delete data.current.keyupHandler;
|
|
737
|
+
}
|
|
738
|
+
if (data.current.keydownHandler) {
|
|
739
|
+
element.removeEventListener("keydown", data.current.keydownHandler);
|
|
740
|
+
delete data.current.keydownHandler;
|
|
741
|
+
}
|
|
742
|
+
if (data.current.resetHandler) {
|
|
743
|
+
window.removeEventListener("focus", data.current.resetHandler);
|
|
744
|
+
delete data.current.resetHandler;
|
|
745
|
+
}
|
|
550
746
|
}
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
747
|
+
};
|
|
748
|
+
var getDataRef = (tree) => {
|
|
749
|
+
var _a, _c, _e, _g;
|
|
750
|
+
const dataRef = tree.getDataRef();
|
|
751
|
+
(_a = dataRef.current).itemData != null || (_a.itemData = {});
|
|
752
|
+
(_c = dataRef.current).childrenIds != null || (_c.childrenIds = {});
|
|
753
|
+
(_e = dataRef.current).loadingDataSubs != null || (_e.loadingDataSubs = {});
|
|
754
|
+
(_g = dataRef.current).loadingChildrenSubs != null || (_g.loadingChildrenSubs = {});
|
|
755
|
+
return dataRef;
|
|
756
|
+
};
|
|
757
|
+
var loadItemData = (tree, itemId) => __async(null, null, function* () {
|
|
758
|
+
var _a, _b;
|
|
759
|
+
const config = tree.getConfig();
|
|
760
|
+
const dataRef = getDataRef(tree);
|
|
761
|
+
if (tree.getState().loadingItemData.includes(itemId)) return new Promise((resolve) => {
|
|
762
|
+
var _a2;
|
|
763
|
+
(_a2 = dataRef.current.loadingDataSubs)[itemId] != null || (_a2[itemId] = []);
|
|
764
|
+
dataRef.current.loadingDataSubs[itemId].push(() => {
|
|
765
|
+
resolve(dataRef.current.itemData[itemId]);
|
|
562
766
|
});
|
|
563
767
|
});
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
768
|
+
if (!dataRef.current.itemData[itemId]) tree.applySubStateUpdate("loadingItemData", (loadingItemData) => [...loadingItemData, itemId]);
|
|
769
|
+
const item = yield config.dataLoader.getItem(itemId);
|
|
770
|
+
dataRef.current.itemData[itemId] = item;
|
|
771
|
+
(_a = config.onLoadedItem) == null || _a.call(config, itemId, item);
|
|
772
|
+
tree.applySubStateUpdate("loadingItemData", (loadingItemData) => loadingItemData.filter((id) => id !== itemId));
|
|
773
|
+
(_b = dataRef.current.loadingDataSubs[itemId]) == null || _b.forEach((cb) => cb());
|
|
774
|
+
return item;
|
|
775
|
+
});
|
|
776
|
+
var loadChildrenIds = (tree, itemId) => __async(null, null, function* () {
|
|
777
|
+
var _a, _b, _c;
|
|
778
|
+
const config = tree.getConfig();
|
|
779
|
+
const dataRef = getDataRef(tree);
|
|
780
|
+
let childrenIds;
|
|
781
|
+
if (tree.getState().loadingItemChildrens.includes(itemId)) return new Promise((resolve) => {
|
|
782
|
+
var _a2;
|
|
783
|
+
(_a2 = dataRef.current.loadingChildrenSubs)[itemId] != null || (_a2[itemId] = []);
|
|
784
|
+
dataRef.current.loadingChildrenSubs[itemId].push(() => {
|
|
785
|
+
resolve(dataRef.current.childrenIds[itemId]);
|
|
574
786
|
});
|
|
575
787
|
});
|
|
576
|
-
if (
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
788
|
+
if (!dataRef.current.childrenIds[itemId]) tree.applySubStateUpdate("loadingItemChildrens", (loadingItemChildrens) => [...loadingItemChildrens, itemId]);
|
|
789
|
+
if ("getChildrenWithData" in config.dataLoader) {
|
|
790
|
+
const children = yield config.dataLoader.getChildrenWithData(itemId);
|
|
791
|
+
childrenIds = children.map((c) => c.id);
|
|
792
|
+
dataRef.current.childrenIds[itemId] = childrenIds;
|
|
793
|
+
children.forEach(({ id, data }) => {
|
|
794
|
+
var _a2;
|
|
795
|
+
dataRef.current.itemData[id] = data;
|
|
796
|
+
(_a2 = config.onLoadedItem) == null || _a2.call(config, id, data);
|
|
797
|
+
});
|
|
798
|
+
(_a = config.onLoadedChildren) == null || _a.call(config, itemId, childrenIds);
|
|
799
|
+
tree.rebuildTree();
|
|
800
|
+
tree.applySubStateUpdate("loadingItemData", (loadingItemData) => loadingItemData.filter((id) => !childrenIds.includes(id)));
|
|
801
|
+
} else {
|
|
802
|
+
childrenIds = yield config.dataLoader.getChildren(itemId);
|
|
803
|
+
dataRef.current.childrenIds[itemId] = childrenIds;
|
|
804
|
+
(_b = config.onLoadedChildren) == null || _b.call(config, itemId, childrenIds);
|
|
805
|
+
tree.rebuildTree();
|
|
806
|
+
}
|
|
807
|
+
tree.applySubStateUpdate("loadingItemChildrens", (loadingItemChildrens) => loadingItemChildrens.filter((id) => id !== itemId));
|
|
808
|
+
(_c = dataRef.current.loadingChildrenSubs[itemId]) == null || _c.forEach((cb) => cb());
|
|
809
|
+
return childrenIds;
|
|
810
|
+
});
|
|
811
|
+
var asyncDataLoaderFeature = {
|
|
585
812
|
key: "async-data-loader",
|
|
586
|
-
getInitialState: (
|
|
813
|
+
getInitialState: (initialState) => __spreadValues$1({
|
|
587
814
|
loadingItemData: [],
|
|
588
815
|
loadingItemChildrens: []
|
|
589
|
-
},
|
|
590
|
-
getDefaultConfig: (
|
|
591
|
-
setLoadingItemData:
|
|
592
|
-
setLoadingItemChildrens:
|
|
593
|
-
},
|
|
816
|
+
}, initialState),
|
|
817
|
+
getDefaultConfig: (defaultConfig, tree) => __spreadValues$1({
|
|
818
|
+
setLoadingItemData: makeStateUpdater("loadingItemData", tree),
|
|
819
|
+
setLoadingItemChildrens: makeStateUpdater("loadingItemChildrens", tree)
|
|
820
|
+
}, defaultConfig),
|
|
594
821
|
stateHandlerNames: {
|
|
595
822
|
loadingItemData: "setLoadingItemData",
|
|
596
823
|
loadingItemChildrens: "setLoadingItemChildrens"
|
|
597
824
|
},
|
|
598
825
|
treeInstance: {
|
|
599
|
-
waitForItemDataLoaded: ({ tree
|
|
600
|
-
waitForItemChildrenLoaded: ({ tree
|
|
601
|
-
loadItemData: (
|
|
602
|
-
var
|
|
603
|
-
return (
|
|
826
|
+
waitForItemDataLoaded: ({ tree }, itemId) => tree.loadItemData(itemId),
|
|
827
|
+
waitForItemChildrenLoaded: ({ tree }, itemId) => tree.loadChildrenIds(itemId),
|
|
828
|
+
loadItemData: (_0, _1) => __async(null, [_0, _1], function* ({ tree }, itemId) {
|
|
829
|
+
var _a;
|
|
830
|
+
return (_a = getDataRef(tree).current.itemData[itemId]) != null ? _a : yield loadItemData(tree, itemId);
|
|
604
831
|
}),
|
|
605
|
-
loadChildrenIds: (
|
|
606
|
-
var
|
|
607
|
-
return (
|
|
832
|
+
loadChildrenIds: (_0, _1) => __async(null, [_0, _1], function* ({ tree }, itemId) {
|
|
833
|
+
var _a;
|
|
834
|
+
return (_a = getDataRef(tree).current.childrenIds[itemId]) != null ? _a : yield loadChildrenIds(tree, itemId);
|
|
608
835
|
}),
|
|
609
|
-
retrieveItemData: ({ tree
|
|
610
|
-
var
|
|
611
|
-
|
|
612
|
-
|
|
836
|
+
retrieveItemData: ({ tree }, itemId, skipFetch = false) => {
|
|
837
|
+
var _a, _b;
|
|
838
|
+
const config = tree.getConfig();
|
|
839
|
+
const dataRef = getDataRef(tree);
|
|
840
|
+
if (dataRef.current.itemData[itemId]) return dataRef.current.itemData[itemId];
|
|
841
|
+
if (!tree.getState().loadingItemData.includes(itemId) && !skipFetch) setTimeout(() => loadItemData(tree, itemId));
|
|
842
|
+
return (_b = (_a = config.createLoadingItemData) == null ? void 0 : _a.call(config)) != null ? _b : null;
|
|
613
843
|
},
|
|
614
|
-
retrieveChildrenIds: ({ tree
|
|
615
|
-
|
|
616
|
-
|
|
844
|
+
retrieveChildrenIds: ({ tree }, itemId, skipFetch = false) => {
|
|
845
|
+
const dataRef = getDataRef(tree);
|
|
846
|
+
if (dataRef.current.childrenIds[itemId]) return dataRef.current.childrenIds[itemId];
|
|
847
|
+
if (tree.getState().loadingItemChildrens.includes(itemId) || skipFetch) return [];
|
|
848
|
+
setTimeout(() => loadChildrenIds(tree, itemId));
|
|
849
|
+
return [];
|
|
617
850
|
}
|
|
618
851
|
},
|
|
619
852
|
itemInstance: {
|
|
620
|
-
isLoading: ({ tree
|
|
621
|
-
invalidateItemData: (
|
|
622
|
-
var
|
|
623
|
-
|
|
853
|
+
isLoading: ({ tree, item }) => tree.getState().loadingItemData.includes(item.getItemMeta().itemId) || tree.getState().loadingItemChildrens.includes(item.getItemMeta().itemId),
|
|
854
|
+
invalidateItemData: (_0, _1) => __async(null, [_0, _1], function* ({ tree, itemId }, optimistic) {
|
|
855
|
+
var _a;
|
|
856
|
+
if (!optimistic) (_a = getDataRef(tree).current.itemData) == null || delete _a[itemId];
|
|
857
|
+
yield loadItemData(tree, itemId);
|
|
624
858
|
}),
|
|
625
|
-
invalidateChildrenIds: (
|
|
626
|
-
var
|
|
627
|
-
|
|
859
|
+
invalidateChildrenIds: (_0, _1) => __async(null, [_0, _1], function* ({ tree, itemId }, optimistic) {
|
|
860
|
+
var _a;
|
|
861
|
+
if (!optimistic) (_a = getDataRef(tree).current.childrenIds) == null || delete _a[itemId];
|
|
862
|
+
yield loadChildrenIds(tree, itemId);
|
|
628
863
|
}),
|
|
629
|
-
updateCachedChildrenIds: ({ tree
|
|
630
|
-
|
|
864
|
+
updateCachedChildrenIds: ({ tree, itemId }, childrenIds, skipUpdateTree) => {
|
|
865
|
+
getDataRef(tree).current.childrenIds[itemId] = childrenIds;
|
|
866
|
+
if (!skipUpdateTree) tree.rebuildTree();
|
|
631
867
|
},
|
|
632
|
-
updateCachedData: ({ tree
|
|
633
|
-
|
|
868
|
+
updateCachedData: ({ tree, itemId }, data, skipUpdateTree) => {
|
|
869
|
+
getDataRef(tree).current.itemData[itemId] = data;
|
|
870
|
+
if (!skipUpdateTree) tree.rebuildTree();
|
|
634
871
|
},
|
|
635
|
-
hasLoadedData: ({ tree
|
|
872
|
+
hasLoadedData: ({ tree, itemId }) => {
|
|
873
|
+
return tree.getDataRef().current.itemData[itemId] !== void 0;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
// node_modules/@headless-tree/react/dist/chunk-FWCSY2DS.mjs
|
|
878
|
+
var __defProp = Object.defineProperty;
|
|
879
|
+
var __defProps = Object.defineProperties;
|
|
880
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
881
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
882
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
883
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
884
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
885
|
+
enumerable: true,
|
|
886
|
+
configurable: true,
|
|
887
|
+
writable: true,
|
|
888
|
+
value
|
|
889
|
+
}) : obj[key] = value;
|
|
890
|
+
var __spreadValues = (a, b) => {
|
|
891
|
+
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
892
|
+
if (__getOwnPropSymbols) {
|
|
893
|
+
for (var prop of __getOwnPropSymbols(b)) if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
636
894
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
},
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
var n;
|
|
654
|
-
r(t), (n = e.setState) == null || n.call(e, t);
|
|
895
|
+
return a;
|
|
896
|
+
};
|
|
897
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
898
|
+
// node_modules/@headless-tree/react/dist/react17/index.mjs
|
|
899
|
+
var useTree = (config) => {
|
|
900
|
+
const [tree] = useState(() => ({ current: createTree(config) }));
|
|
901
|
+
const [state, setState] = useState(() => tree.current.getState());
|
|
902
|
+
useEffect(() => {
|
|
903
|
+
tree.current.rebuildTree();
|
|
904
|
+
}, [tree]);
|
|
905
|
+
tree.current.setConfig((prev) => __spreadProps(__spreadValues(__spreadValues({}, prev), config), {
|
|
906
|
+
state: __spreadValues(__spreadValues({}, state), config.state),
|
|
907
|
+
setState: (state2) => {
|
|
908
|
+
var _a;
|
|
909
|
+
setState(state2);
|
|
910
|
+
(_a = config.setState) == null || _a.call(config, state2);
|
|
655
911
|
}
|
|
656
|
-
}))
|
|
657
|
-
|
|
912
|
+
}));
|
|
913
|
+
return tree.current;
|
|
914
|
+
};
|
|
915
|
+
// src/explorer-files.ts
|
|
916
|
+
var ExplorerFileError = class extends Error {
|
|
917
|
+
constructor(code) {
|
|
918
|
+
super(code);
|
|
919
|
+
this.code = code;
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
function parentPath(path) {
|
|
923
|
+
return path.slice(0, Math.max(0, path.lastIndexOf("/")));
|
|
924
|
+
}
|
|
925
|
+
function validateName(name) {
|
|
926
|
+
if (!name.trim() || name === "." || name === ".." || name.toLowerCase() === ".git" || /[\\/\u0000]/u.test(name)) throw new ExplorerFileError("invalidName");
|
|
927
|
+
}
|
|
928
|
+
async function resolveExplorerDirectory(root, path) {
|
|
929
|
+
var _await$root$resolve;
|
|
930
|
+
let directory = root;
|
|
931
|
+
const parts = path ? path.split("/") : [];
|
|
932
|
+
for (const part of parts) {
|
|
933
|
+
validateName(part);
|
|
934
|
+
directory = await directory.getDirectoryHandle(part);
|
|
935
|
+
}
|
|
936
|
+
if (((_await$root$resolve = await root.resolve(directory)) === null || _await$root$resolve === void 0 ? void 0 : _await$root$resolve.join("/")) !== path) throw new ExplorerFileError("sourceChanged");
|
|
937
|
+
return directory;
|
|
938
|
+
}
|
|
939
|
+
async function explorerNameAvailable(directory, name) {
|
|
940
|
+
try {
|
|
941
|
+
await directory.getFileHandle(name);
|
|
942
|
+
} catch (error) {
|
|
943
|
+
if (error instanceof DOMException && error.name === "NotFoundError") return true;
|
|
944
|
+
if (!(error instanceof DOMException) || error.name !== "TypeMismatchError") throw error;
|
|
945
|
+
}
|
|
946
|
+
return false;
|
|
947
|
+
}
|
|
948
|
+
async function assertUnused(directory, name) {
|
|
949
|
+
if (!await explorerNameAvailable(directory, name)) throw new ExplorerFileError("exists");
|
|
950
|
+
}
|
|
951
|
+
async function createExplorerDirectory(parent, name, guard) {
|
|
952
|
+
validateName(name);
|
|
953
|
+
await assertUnused(parent, name);
|
|
954
|
+
guard();
|
|
955
|
+
await parent.getDirectoryHandle(name, { create: true });
|
|
956
|
+
}
|
|
957
|
+
var sameVersion = (a, b) => a.size === b.size && a.lastModified === b.lastModified;
|
|
958
|
+
async function writeNewFile(directory, name, file, guard) {
|
|
959
|
+
await assertUnused(directory, name);
|
|
960
|
+
guard();
|
|
961
|
+
const handle = await directory.getFileHandle(name, { create: true });
|
|
962
|
+
const empty = await handle.getFile();
|
|
963
|
+
if (empty.size) throw new ExplorerFileError("exists");
|
|
964
|
+
const options = { mode: "exclusive" };
|
|
965
|
+
let stream;
|
|
966
|
+
try {
|
|
967
|
+
stream = await handle.createWritable(options);
|
|
968
|
+
await stream.write(file);
|
|
969
|
+
if (!sameVersion(empty, await handle.getFile())) throw new ExplorerFileError("exists");
|
|
970
|
+
guard();
|
|
971
|
+
await stream.close();
|
|
972
|
+
} catch (error) {
|
|
973
|
+
await (stream === null || stream === void 0 ? void 0 : stream.abort().catch(() => {}));
|
|
974
|
+
try {
|
|
975
|
+
if (sameVersion(empty, await handle.getFile())) await directory.removeEntry(name);
|
|
976
|
+
} catch (_unused) {
|
|
977
|
+
throw new ExplorerFileError("cleanupFailed");
|
|
978
|
+
}
|
|
979
|
+
throw error;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
async function copyExplorerFile(directory, file, guard) {
|
|
983
|
+
validateName(file.name);
|
|
984
|
+
await writeNewFile(directory, file.name, file, guard);
|
|
985
|
+
}
|
|
986
|
+
async function copyEntry(sourceParent, source, parent, name, guard) {
|
|
987
|
+
validateName(source.name);
|
|
988
|
+
if (source.kind === "file") {
|
|
989
|
+
const handle = source;
|
|
990
|
+
const file = await handle.getFile();
|
|
991
|
+
await writeNewFile(parent, name, file, guard);
|
|
992
|
+
const verify = async () => {
|
|
993
|
+
if (!sameVersion(file, await handle.getFile())) throw new ExplorerFileError("sourceChanged");
|
|
994
|
+
};
|
|
995
|
+
return {
|
|
996
|
+
verify,
|
|
997
|
+
async removeSource() {
|
|
998
|
+
await verify();
|
|
999
|
+
guard();
|
|
1000
|
+
await sourceParent.removeEntry(source.name);
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
await assertUnused(parent, name);
|
|
1005
|
+
guard();
|
|
1006
|
+
const destination = await parent.getDirectoryHandle(name, { create: true });
|
|
1007
|
+
const directory = source;
|
|
1008
|
+
const children = /* @__PURE__ */ new Map();
|
|
1009
|
+
try {
|
|
1010
|
+
var _iteratorAbruptCompletion = false;
|
|
1011
|
+
var _didIteratorError = false;
|
|
1012
|
+
var _iteratorError;
|
|
1013
|
+
try {
|
|
1014
|
+
for (var _iterator = _asyncIterator(directory.values()), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
|
|
1015
|
+
const handle = _step.value;
|
|
1016
|
+
children.set(handle.name, {
|
|
1017
|
+
handle,
|
|
1018
|
+
copy: await copyEntry(directory, handle, destination, handle.name, guard)
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
} catch (err) {
|
|
1022
|
+
_didIteratorError = true;
|
|
1023
|
+
_iteratorError = err;
|
|
1024
|
+
} finally {
|
|
1025
|
+
try {
|
|
1026
|
+
if (_iteratorAbruptCompletion && _iterator.return != null) await _iterator.return();
|
|
1027
|
+
} finally {
|
|
1028
|
+
if (_didIteratorError) throw _iteratorError;
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
} catch (error) {
|
|
1032
|
+
await removeIncompleteCopy(parent, name);
|
|
1033
|
+
throw error;
|
|
1034
|
+
}
|
|
1035
|
+
const verify = async () => {
|
|
1036
|
+
let count = 0;
|
|
1037
|
+
var _iteratorAbruptCompletion2 = false;
|
|
1038
|
+
var _didIteratorError2 = false;
|
|
1039
|
+
var _iteratorError2;
|
|
1040
|
+
try {
|
|
1041
|
+
for (var _iterator2 = _asyncIterator(directory.values()), _step2; _iteratorAbruptCompletion2 = !(_step2 = await _iterator2.next()).done; _iteratorAbruptCompletion2 = false) {
|
|
1042
|
+
const handle = _step2.value;
|
|
1043
|
+
{
|
|
1044
|
+
const child = children.get(handle.name);
|
|
1045
|
+
if (!child || !await handle.isSameEntry(child.handle)) throw new ExplorerFileError("sourceChanged");
|
|
1046
|
+
await child.copy.verify();
|
|
1047
|
+
count++;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
} catch (err) {
|
|
1051
|
+
_didIteratorError2 = true;
|
|
1052
|
+
_iteratorError2 = err;
|
|
1053
|
+
} finally {
|
|
1054
|
+
try {
|
|
1055
|
+
if (_iteratorAbruptCompletion2 && _iterator2.return != null) await _iterator2.return();
|
|
1056
|
+
} finally {
|
|
1057
|
+
if (_didIteratorError2) throw _iteratorError2;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
if (count !== children.size) throw new ExplorerFileError("sourceChanged");
|
|
1061
|
+
};
|
|
1062
|
+
return {
|
|
1063
|
+
verify,
|
|
1064
|
+
async removeSource() {
|
|
1065
|
+
for (const { copy } of children.values()) await copy.removeSource();
|
|
1066
|
+
guard();
|
|
1067
|
+
await sourceParent.removeEntry(source.name);
|
|
1068
|
+
}
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
async function removeIncompleteCopy(parent, name) {
|
|
1072
|
+
try {
|
|
1073
|
+
await parent.removeEntry(name, { recursive: true });
|
|
1074
|
+
} catch (_unused2) {
|
|
1075
|
+
throw new ExplorerFileError("cleanupFailed");
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
async function renameExplorerEntry(parent, entry, name, guard) {
|
|
1079
|
+
if (name === entry.name) return;
|
|
1080
|
+
await relocateEntry(parent, entry, parent, name, guard);
|
|
1081
|
+
}
|
|
1082
|
+
function canMoveExplorerEntry(path, destination) {
|
|
1083
|
+
return parentPath(path) !== destination && path !== destination && !destination.startsWith(`${path}/`);
|
|
1084
|
+
}
|
|
1085
|
+
async function moveExplorerEntry(root, entry, destination, destinationPath, guard) {
|
|
1086
|
+
if (!canMoveExplorerEntry(entry.path, destinationPath)) throw new ExplorerFileError("invalidDestination");
|
|
1087
|
+
const parent = await resolveExplorerDirectory(root, parentPath(entry.path));
|
|
1088
|
+
guard();
|
|
1089
|
+
await relocateEntry(parent, entry, destination, entry.name, guard);
|
|
1090
|
+
}
|
|
1091
|
+
async function relocateEntry(sourceParent, entry, destination, name, guard) {
|
|
1092
|
+
validateName(entry.name);
|
|
1093
|
+
validateName(name);
|
|
1094
|
+
const copy = await copyEntry(sourceParent, entry.kind === "file" ? await sourceParent.getFileHandle(entry.name) : await sourceParent.getDirectoryHandle(entry.name), destination, name, guard);
|
|
1095
|
+
try {
|
|
1096
|
+
await copy.verify();
|
|
1097
|
+
guard();
|
|
1098
|
+
} catch (error) {
|
|
1099
|
+
await removeIncompleteCopy(destination, name);
|
|
1100
|
+
throw error;
|
|
1101
|
+
}
|
|
1102
|
+
try {
|
|
1103
|
+
await copy.removeSource();
|
|
1104
|
+
} catch (_unused3) {
|
|
1105
|
+
throw new ExplorerFileError("originalKept");
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
async function deleteExplorerEntry(parent, entry, guard) {
|
|
1109
|
+
validateName(entry.name);
|
|
1110
|
+
if (entry.kind === "directory") {
|
|
1111
|
+
const check = async (directory) => {
|
|
1112
|
+
var _iteratorAbruptCompletion3 = false;
|
|
1113
|
+
var _didIteratorError3 = false;
|
|
1114
|
+
var _iteratorError3;
|
|
1115
|
+
try {
|
|
1116
|
+
for (var _iterator3 = _asyncIterator(directory.values()), _step3; _iteratorAbruptCompletion3 = !(_step3 = await _iterator3.next()).done; _iteratorAbruptCompletion3 = false) {
|
|
1117
|
+
const child = _step3.value;
|
|
1118
|
+
guard();
|
|
1119
|
+
validateName(child.name);
|
|
1120
|
+
if (child.kind === "directory") await check(child);
|
|
1121
|
+
}
|
|
1122
|
+
} catch (err) {
|
|
1123
|
+
_didIteratorError3 = true;
|
|
1124
|
+
_iteratorError3 = err;
|
|
1125
|
+
} finally {
|
|
1126
|
+
try {
|
|
1127
|
+
if (_iteratorAbruptCompletion3 && _iterator3.return != null) await _iterator3.return();
|
|
1128
|
+
} finally {
|
|
1129
|
+
if (_didIteratorError3) throw _iteratorError3;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
await check(await parent.getDirectoryHandle(entry.name));
|
|
1134
|
+
} else await parent.getFileHandle(entry.name);
|
|
1135
|
+
guard();
|
|
1136
|
+
await parent.removeEntry(entry.name, { recursive: entry.kind === "directory" });
|
|
1137
|
+
}
|
|
1138
|
+
// src/explorer-menu.tsx
|
|
1139
|
+
var actionMessages = (locale = "en") => locale.toLowerCase().startsWith("ja") ? {
|
|
1140
|
+
actions: "ファイルとフォルダの操作",
|
|
1141
|
+
rename: "名前を変更…",
|
|
1142
|
+
renameTitle: "名前を変更",
|
|
1143
|
+
delete: "削除…",
|
|
1144
|
+
deleteTitle: "削除",
|
|
1145
|
+
createFolder: "新規フォルダを作成",
|
|
1146
|
+
folderName: "フォルダ名",
|
|
1147
|
+
newName: "新しい名前",
|
|
1148
|
+
cancel: "キャンセル",
|
|
1149
|
+
remove: (name, folder) => folder ? `「${name}」とその中身を削除しますか?` : `「${name}」を削除しますか?`,
|
|
1150
|
+
stage: "Git にステージ",
|
|
1151
|
+
unstage: "Git のステージを解除",
|
|
1152
|
+
working: "処理中…",
|
|
1153
|
+
copyFailed: "コピーできませんでした",
|
|
1154
|
+
filesOnly: "ファイルをドロップしてください。",
|
|
1155
|
+
invalidName: "この名前は使用できません。",
|
|
1156
|
+
exists: "同じ名前のファイルまたはフォルダがあります。",
|
|
1157
|
+
invalidDestination: "このフォルダには移動できません。",
|
|
1158
|
+
denied: "このフォルダへの書き込みが許可されていません。",
|
|
1159
|
+
conflict: "プロジェクトフォルダが変更されたか、別の操作が実行中です。",
|
|
1160
|
+
sourceChanged: "操作中に対象が変更されました。",
|
|
1161
|
+
originalKept: "元の項目を削除できなかったため、コピーを残しました。",
|
|
1162
|
+
cleanupFailed: "失敗したコピーを削除できませんでした。",
|
|
1163
|
+
failed: "操作を完了できませんでした。"
|
|
1164
|
+
} : {
|
|
1165
|
+
actions: "File and folder actions",
|
|
1166
|
+
rename: "Rename…",
|
|
1167
|
+
renameTitle: "Rename",
|
|
1168
|
+
delete: "Delete…",
|
|
1169
|
+
deleteTitle: "Delete",
|
|
1170
|
+
createFolder: "Create New Folder",
|
|
1171
|
+
folderName: "Folder name",
|
|
1172
|
+
newName: "New name",
|
|
1173
|
+
cancel: "Cancel",
|
|
1174
|
+
remove: (name, folder) => folder ? `Delete “${name}” and its contents?` : `Delete “${name}”?`,
|
|
1175
|
+
stage: "Stage in Git",
|
|
1176
|
+
unstage: "Unstage in Git",
|
|
1177
|
+
working: "Working…",
|
|
1178
|
+
copyFailed: "Could not copy",
|
|
1179
|
+
filesOnly: "Drop files here.",
|
|
1180
|
+
invalidName: "This name cannot be used.",
|
|
1181
|
+
exists: "A file or folder with this name already exists.",
|
|
1182
|
+
invalidDestination: "This item cannot be moved to that folder.",
|
|
1183
|
+
denied: "Permission to write to this folder was not granted.",
|
|
1184
|
+
conflict: "The project folder changed or another operation is running.",
|
|
1185
|
+
sourceChanged: "The item changed during the operation.",
|
|
1186
|
+
originalKept: "The original could not be removed, so the copy was kept.",
|
|
1187
|
+
cleanupFailed: "The incomplete copy could not be removed.",
|
|
1188
|
+
failed: "The operation could not be completed."
|
|
1189
|
+
};
|
|
1190
|
+
var actionCss = `
|
|
1191
|
+
.twpf-explorer-actions{position:fixed;z-index:2147483647;max-width:calc(100vw - 8px);padding:4px;
|
|
1192
|
+
border:1px solid GrayText;border-radius:5px;background:Canvas;color:CanvasText;box-shadow:0 2px 8px #0004}
|
|
1193
|
+
.twpf-explorer-actions button{display:block;width:100%;border:0;padding:.35em .65em;text-align:start;background:Canvas;color:CanvasText;
|
|
1194
|
+
font:inherit;cursor:pointer;border-radius:3px}
|
|
1195
|
+
.twpf-explorer-actions button:is(:hover,:focus-visible){background:Highlight;color:HighlightText}
|
|
1196
|
+
.twpf-explorer-dialog{max-width:min(28em,calc(100vw - 2em));color:CanvasText;background:Canvas;
|
|
1197
|
+
border:1px solid GrayText;border-radius:6px;padding:1em;overflow-wrap:anywhere}
|
|
1198
|
+
.twpf-explorer-dialog::backdrop{background:#0006}
|
|
1199
|
+
.twpf-explorer-dialog h2{font-size:1.1em;margin:0 0 .75em}
|
|
1200
|
+
.twpf-explorer-dialog input{display:block;width:100%;box-sizing:border-box;margin-top:.3em}
|
|
1201
|
+
.twpf-explorer-dialog-footer{display:flex;justify-content:flex-end;gap:.5em;margin-top:1em}
|
|
1202
|
+
.twpf-explorer-drop{min-height:100%;box-sizing:border-box}
|
|
1203
|
+
.twpf-explorer [data-drop-active],.twpf-explorer[data-drop-active]{outline:2px solid Highlight;outline-offset:-2px}
|
|
1204
|
+
.twpf-explorer-item[data-move-unavailable]{color:GrayText;opacity:.65;filter:grayscale(1)}
|
|
1205
|
+
.twpf-explorer-item[data-move-active] .twpf-explorer-name{font-weight:700}
|
|
1206
|
+
.twpf-explorer-drag-image{position:fixed;top:0;left:0;z-index:2147483647;pointer-events:none;
|
|
1207
|
+
display:flex;align-items:center;gap:.4em;max-width:18em;white-space:nowrap;padding:.3em .5em;
|
|
1208
|
+
border:1px solid GrayText;border-radius:4px;background:Canvas;color:CanvasText;box-shadow:0 2px 8px #0004}
|
|
1209
|
+
.twpf-explorer-feedback{white-space:pre-wrap;overflow-wrap:anywhere;padding:.25em .5em}
|
|
1210
|
+
`;
|
|
1211
|
+
function ExplorerMenu({ anchor, label, actions, close }) {
|
|
1212
|
+
const ref = React.useRef(null);
|
|
1213
|
+
const document = anchor.row.ownerDocument;
|
|
1214
|
+
React.useLayoutEffect(() => {
|
|
1215
|
+
var _menu$querySelector;
|
|
1216
|
+
const menu = ref.current;
|
|
1217
|
+
const { width, height } = menu.getBoundingClientRect();
|
|
1218
|
+
menu.style.left = `${Math.max(4, Math.min(anchor.x, document.documentElement.clientWidth - width - 4))}px`;
|
|
1219
|
+
menu.style.top = `${Math.max(4, Math.min(anchor.y, document.documentElement.clientHeight - height - 4))}px`;
|
|
1220
|
+
(_menu$querySelector = menu.querySelector("button")) === null || _menu$querySelector === void 0 || _menu$querySelector.focus();
|
|
1221
|
+
const outside = (event) => {
|
|
1222
|
+
if (!menu.contains(event.target)) close(false);
|
|
1223
|
+
};
|
|
1224
|
+
document.addEventListener("pointerdown", outside, true);
|
|
1225
|
+
document.addEventListener("focusin", outside, true);
|
|
1226
|
+
return () => {
|
|
1227
|
+
document.removeEventListener("pointerdown", outside, true);
|
|
1228
|
+
document.removeEventListener("focusin", outside, true);
|
|
1229
|
+
};
|
|
1230
|
+
}, [anchor]);
|
|
1231
|
+
return createPortal(/* @__PURE__ */ React.createElement("div", {
|
|
1232
|
+
ref,
|
|
1233
|
+
role: "menu",
|
|
1234
|
+
"aria-label": label,
|
|
1235
|
+
className: "twpf-explorer-actions",
|
|
1236
|
+
onKeyDown: (event) => {
|
|
1237
|
+
var _buttons$next;
|
|
1238
|
+
if (event.key === "Tab") {
|
|
1239
|
+
close(true);
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
if (event.key === "Escape") {
|
|
1243
|
+
event.preventDefault();
|
|
1244
|
+
event.stopPropagation();
|
|
1245
|
+
close(true);
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
const buttons = Array.from(event.currentTarget.querySelectorAll("button"));
|
|
1249
|
+
const index = buttons.indexOf(document.activeElement);
|
|
1250
|
+
const next = {
|
|
1251
|
+
ArrowDown: (index + 1) % buttons.length,
|
|
1252
|
+
ArrowUp: (index + buttons.length - 1) % buttons.length,
|
|
1253
|
+
Home: 0,
|
|
1254
|
+
End: buttons.length - 1
|
|
1255
|
+
}[event.key];
|
|
1256
|
+
if (next === void 0) return;
|
|
1257
|
+
event.preventDefault();
|
|
1258
|
+
event.stopPropagation();
|
|
1259
|
+
(_buttons$next = buttons[next]) === null || _buttons$next === void 0 || _buttons$next.focus();
|
|
1260
|
+
}
|
|
1261
|
+
}, actions.map((action) => /* @__PURE__ */ React.createElement("button", {
|
|
1262
|
+
key: action.label,
|
|
1263
|
+
type: "button",
|
|
1264
|
+
role: "menuitem",
|
|
1265
|
+
tabIndex: -1,
|
|
1266
|
+
onClick: action.run
|
|
1267
|
+
}, action.label))), document.body);
|
|
1268
|
+
}
|
|
1269
|
+
function ExplorerFileDialog({ anchor, name, folder, action, message, close, submit }) {
|
|
1270
|
+
const ref = React.useRef(null);
|
|
1271
|
+
const input = React.useRef(null);
|
|
1272
|
+
const cancel = React.useRef(null);
|
|
1273
|
+
const title = action === "createFolder" ? message.createFolder : action === "rename" ? message.renameTitle : message.deleteTitle;
|
|
1274
|
+
React.useLayoutEffect(() => {
|
|
1275
|
+
var _cancel$current;
|
|
1276
|
+
const dialog = ref.current;
|
|
1277
|
+
dialog.showModal();
|
|
1278
|
+
if (input.current) {
|
|
1279
|
+
input.current.focus();
|
|
1280
|
+
input.current.select();
|
|
1281
|
+
} else (_cancel$current = cancel.current) === null || _cancel$current === void 0 || _cancel$current.focus();
|
|
1282
|
+
return () => {
|
|
1283
|
+
dialog.close();
|
|
1284
|
+
if (anchor.row.isConnected) anchor.row.focus({ preventScroll: true });
|
|
1285
|
+
};
|
|
1286
|
+
}, []);
|
|
1287
|
+
return createPortal(/* @__PURE__ */ React.createElement("dialog", {
|
|
1288
|
+
ref,
|
|
1289
|
+
"aria-label": title,
|
|
1290
|
+
className: "twpf-explorer-dialog",
|
|
1291
|
+
onCancel: (event) => {
|
|
1292
|
+
event.preventDefault();
|
|
1293
|
+
close();
|
|
1294
|
+
}
|
|
1295
|
+
}, /* @__PURE__ */ React.createElement("form", { onSubmit: (event) => {
|
|
1296
|
+
var _input$current$value, _input$current;
|
|
1297
|
+
event.preventDefault();
|
|
1298
|
+
submit((_input$current$value = (_input$current = input.current) === null || _input$current === void 0 ? void 0 : _input$current.value) !== null && _input$current$value !== void 0 ? _input$current$value : name);
|
|
1299
|
+
} }, /* @__PURE__ */ React.createElement("h2", null, title), action === "delete" ? /* @__PURE__ */ React.createElement("p", null, message.remove(name, folder)) : /* @__PURE__ */ React.createElement("label", null, action === "rename" ? message.newName : message.folderName, /* @__PURE__ */ React.createElement("input", {
|
|
1300
|
+
ref: input,
|
|
1301
|
+
defaultValue: action === "rename" ? name : "",
|
|
1302
|
+
required: true
|
|
1303
|
+
})), /* @__PURE__ */ React.createElement("div", { className: "twpf-explorer-dialog-footer" }, /* @__PURE__ */ React.createElement("button", {
|
|
1304
|
+
ref: cancel,
|
|
1305
|
+
type: "button",
|
|
1306
|
+
onClick: close
|
|
1307
|
+
}, message.cancel), /* @__PURE__ */ React.createElement("button", { type: "submit" }, title)))), anchor.row.ownerDocument.body);
|
|
1308
|
+
}
|
|
1309
|
+
// src/file-preview.ts
|
|
1310
|
+
var mimeTypes = new Map(Object.entries({
|
|
1311
|
+
apng: "image/apng",
|
|
1312
|
+
avif: "image/avif",
|
|
1313
|
+
bmp: "image/bmp",
|
|
1314
|
+
gif: "image/gif",
|
|
1315
|
+
ico: "image/x-icon",
|
|
1316
|
+
jpg: "image/jpeg",
|
|
1317
|
+
jpeg: "image/jpeg",
|
|
1318
|
+
png: "image/png",
|
|
1319
|
+
svg: "image/svg+xml",
|
|
1320
|
+
webp: "image/webp",
|
|
1321
|
+
aac: "audio/aac",
|
|
1322
|
+
aif: "audio/aiff",
|
|
1323
|
+
aiff: "audio/aiff",
|
|
1324
|
+
flac: "audio/flac",
|
|
1325
|
+
m4a: "audio/mp4",
|
|
1326
|
+
mp3: "audio/mpeg",
|
|
1327
|
+
oga: "audio/ogg",
|
|
1328
|
+
ogg: "audio/ogg",
|
|
1329
|
+
opus: "audio/ogg",
|
|
1330
|
+
wav: "audio/wav",
|
|
1331
|
+
m4v: "video/mp4",
|
|
1332
|
+
mov: "video/quicktime",
|
|
1333
|
+
mp4: "video/mp4",
|
|
1334
|
+
ogv: "video/ogg",
|
|
1335
|
+
webm: "video/webm"
|
|
1336
|
+
}));
|
|
1337
|
+
var textLimit = 4194304;
|
|
1338
|
+
var styles = `
|
|
1339
|
+
.twpf-preview{box-sizing:border-box;height:100%;overflow:auto;padding:1rem;color:var(--text-primary,inherit);
|
|
1340
|
+
background:var(--ui-primary,transparent)}
|
|
1341
|
+
.twpf-preview:has(.twpf-text-file){padding:0;overflow:hidden}
|
|
1342
|
+
.twpf-preview img,.twpf-preview video{display:block;max-width:100%;max-height:100%;margin:auto;object-fit:contain}
|
|
1343
|
+
.twpf-preview audio{width:min(100%,32rem)}
|
|
1344
|
+
`;
|
|
1345
|
+
var messages$1 = {
|
|
1346
|
+
en: {
|
|
1347
|
+
loading: "Loading file…",
|
|
1348
|
+
failed: "This file could not be read.",
|
|
1349
|
+
unsupported: "This file cannot be previewed.",
|
|
1350
|
+
mediaError: "This media could not be opened.",
|
|
1351
|
+
large: "This text file is too large to open (4 MiB limit)."
|
|
1352
|
+
},
|
|
1353
|
+
ja: {
|
|
1354
|
+
loading: "ファイルを読み込んでいます…",
|
|
1355
|
+
failed: "このファイルを読み込めません。",
|
|
1356
|
+
unsupported: "このファイルはプレビューできません。",
|
|
1357
|
+
mediaError: "このメディアを開けません。",
|
|
1358
|
+
large: "このテキストファイルは開けるサイズの上限(4 MiB)を超えています。"
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
async function fileAt(directory, path) {
|
|
1362
|
+
const parts = path.split("/");
|
|
1363
|
+
const name = parts.pop();
|
|
1364
|
+
for (const part of parts) directory = await directory.getDirectoryHandle(part);
|
|
1365
|
+
return directory.getFileHandle(name);
|
|
1366
|
+
}
|
|
1367
|
+
function createFilePreview(directory, documentId, { name, path }, locale, readBaseline) {
|
|
1368
|
+
return {
|
|
1369
|
+
reference: {
|
|
1370
|
+
providerId: "turbowarp-plus-project-folder",
|
|
1371
|
+
documentId
|
|
1372
|
+
},
|
|
1373
|
+
filename: name,
|
|
1374
|
+
title: name,
|
|
1375
|
+
transient: true,
|
|
1376
|
+
mount(element, close) {
|
|
1377
|
+
const message = locale.toLowerCase().startsWith("ja") ? messages$1.ja : messages$1.en;
|
|
1378
|
+
const { ownerDocument: document } = element;
|
|
1379
|
+
const panel = document.createElement("div");
|
|
1380
|
+
panel.className = "twpf-preview";
|
|
1381
|
+
const style = document.createElement("style");
|
|
1382
|
+
style.textContent = styles;
|
|
1383
|
+
const status = document.createElement("p");
|
|
1384
|
+
status.setAttribute("role", "status");
|
|
1385
|
+
status.textContent = message.loading;
|
|
1386
|
+
panel.append(style, status);
|
|
1387
|
+
element.append(panel);
|
|
1388
|
+
let disposed = false;
|
|
1389
|
+
let url;
|
|
1390
|
+
let media;
|
|
1391
|
+
let textSession;
|
|
1392
|
+
const readHandle = () => fileAt(directory, path);
|
|
1393
|
+
const show = (node) => status.replaceWith(node);
|
|
1394
|
+
const load = async () => {
|
|
1395
|
+
var _mimeTypes$get;
|
|
1396
|
+
const file = await (await readHandle()).getFile();
|
|
1397
|
+
if (disposed) return;
|
|
1398
|
+
const extension = name.includes(".") ? name.split(".").pop().toLowerCase() : "";
|
|
1399
|
+
const mime = (_mimeTypes$get = mimeTypes.get(extension)) !== null && _mimeTypes$get !== void 0 ? _mimeTypes$get : file.type;
|
|
1400
|
+
const kind = mime.split("/")[0];
|
|
1401
|
+
if (kind === "image" || kind === "audio" || kind === "video") {
|
|
1402
|
+
url = URL.createObjectURL(mime === file.type ? file : file.slice(0, file.size, mime));
|
|
1403
|
+
const view = document.createElement(kind === "image" ? "img" : kind);
|
|
1404
|
+
view.addEventListener("error", () => {
|
|
1405
|
+
status.textContent = message.mediaError;
|
|
1406
|
+
view.replaceWith(status);
|
|
1407
|
+
}, { once: true });
|
|
1408
|
+
if (view.tagName === "IMG") view.alt = name;
|
|
1409
|
+
else {
|
|
1410
|
+
media = view;
|
|
1411
|
+
media.controls = true;
|
|
1412
|
+
media.preload = "metadata";
|
|
1413
|
+
media.setAttribute("aria-label", name);
|
|
1414
|
+
}
|
|
1415
|
+
view.src = url;
|
|
1416
|
+
show(view);
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
if (file.size > 4194304) {
|
|
1420
|
+
status.textContent = message.large;
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
const [bytes, { decodeText, mountTextFile }] = await Promise.all([file.arrayBuffer(), import("./shared-kI7qYraF.js")]);
|
|
1424
|
+
if (disposed) return;
|
|
1425
|
+
const content = decodeText(bytes);
|
|
1426
|
+
if (content === null) {
|
|
1427
|
+
status.textContent = message.unsupported;
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
textSession = mountTextFile(panel, {
|
|
1431
|
+
path,
|
|
1432
|
+
extension,
|
|
1433
|
+
content,
|
|
1434
|
+
locale,
|
|
1435
|
+
limit: textLimit,
|
|
1436
|
+
readHandle,
|
|
1437
|
+
close,
|
|
1438
|
+
readBaseline: readBaseline && (() => readBaseline(directory, path, 4194304))
|
|
1439
|
+
});
|
|
1440
|
+
status.remove();
|
|
1441
|
+
};
|
|
1442
|
+
load().catch(() => {
|
|
1443
|
+
if (!disposed) status.textContent = message.failed;
|
|
1444
|
+
});
|
|
1445
|
+
return {
|
|
1446
|
+
requestClose() {
|
|
1447
|
+
if (textSession) textSession.requestClose();
|
|
1448
|
+
else close();
|
|
1449
|
+
},
|
|
1450
|
+
dispose() {
|
|
1451
|
+
disposed = true;
|
|
1452
|
+
textSession === null || textSession === void 0 || textSession.dispose();
|
|
1453
|
+
media === null || media === void 0 || media.pause();
|
|
1454
|
+
if (url) URL.revokeObjectURL(url);
|
|
1455
|
+
panel.remove();
|
|
1456
|
+
}
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
// src/explorer.tsx
|
|
1462
|
+
var messages = {
|
|
658
1463
|
en: {
|
|
659
1464
|
label: "Project folder",
|
|
660
1465
|
loading: "Loading…",
|
|
661
1466
|
empty: "This folder is empty.",
|
|
662
1467
|
noFolder: "Open a project folder to show its files here.",
|
|
663
1468
|
open: "Open Project Folder…",
|
|
1469
|
+
unavailable: "File tabs are unavailable in this editor layout.",
|
|
664
1470
|
failed: "This folder could not be read.",
|
|
665
1471
|
denied: "Permission to read this folder was not granted.",
|
|
666
1472
|
separator: ", ",
|
|
@@ -670,15 +1476,22 @@ var x = (e, t = 100, n = 1e3) => new Promise((r) => {
|
|
|
670
1476
|
deleted: "Deleted",
|
|
671
1477
|
untracked: "Untracked"
|
|
672
1478
|
},
|
|
1479
|
+
unsaved: "Unsaved changes",
|
|
1480
|
+
staged: "Staged",
|
|
1481
|
+
revisions: {
|
|
1482
|
+
committed: "Committed",
|
|
1483
|
+
pushed: "Pushed",
|
|
1484
|
+
merged: "Pull request merged"
|
|
1485
|
+
},
|
|
673
1486
|
project: "Project data",
|
|
674
1487
|
manifest: "Folder manifest",
|
|
675
1488
|
extensions: "Embedded extensions",
|
|
676
1489
|
assetsDirectory: "Costume and sound files",
|
|
677
1490
|
extensionsDirectory: "Extension files",
|
|
678
|
-
costume: (
|
|
679
|
-
backdrop: (
|
|
680
|
-
sound: (
|
|
681
|
-
stageSound: (
|
|
1491
|
+
costume: (sprite, name) => `${sprite} · costume ${name}`,
|
|
1492
|
+
backdrop: (name) => `Stage · backdrop ${name}`,
|
|
1493
|
+
sound: (sprite, name) => `${sprite} · sound ${name}`,
|
|
1494
|
+
stageSound: (name) => `Stage · sound ${name}`
|
|
682
1495
|
},
|
|
683
1496
|
ja: {
|
|
684
1497
|
label: "作品フォルダ",
|
|
@@ -686,6 +1499,7 @@ var x = (e, t = 100, n = 1e3) => new Promise((r) => {
|
|
|
686
1499
|
empty: "このフォルダは空です。",
|
|
687
1500
|
noFolder: "プロジェクトフォルダを開くと、ここにファイルを表示します。",
|
|
688
1501
|
open: "プロジェクトフォルダを開く…",
|
|
1502
|
+
unavailable: "このエディターのレイアウトではファイルをタブで開けません。",
|
|
689
1503
|
failed: "このフォルダを読み込めません。",
|
|
690
1504
|
denied: "このフォルダを読む許可がありません。",
|
|
691
1505
|
separator: "、",
|
|
@@ -695,94 +1509,135 @@ var x = (e, t = 100, n = 1e3) => new Promise((r) => {
|
|
|
695
1509
|
deleted: "削除",
|
|
696
1510
|
untracked: "未追跡"
|
|
697
1511
|
},
|
|
1512
|
+
unsaved: "未保存の変更あり",
|
|
1513
|
+
staged: "ステージ済み",
|
|
1514
|
+
revisions: {
|
|
1515
|
+
committed: "コミット済み",
|
|
1516
|
+
pushed: "プッシュ済み",
|
|
1517
|
+
merged: "PR マージ済み"
|
|
1518
|
+
},
|
|
698
1519
|
project: "作品データ",
|
|
699
1520
|
manifest: "作品フォルダの目録",
|
|
700
1521
|
extensions: "埋め込み拡張の一覧",
|
|
701
1522
|
assetsDirectory: "コスチュームと音のファイル",
|
|
702
1523
|
extensionsDirectory: "拡張のファイル",
|
|
703
|
-
costume: (
|
|
704
|
-
backdrop: (
|
|
705
|
-
sound: (
|
|
706
|
-
stageSound: (
|
|
1524
|
+
costume: (sprite, name) => `${sprite} のコスチューム ${name}`,
|
|
1525
|
+
backdrop: (name) => `ステージの背景 ${name}`,
|
|
1526
|
+
sound: (sprite, name) => `${sprite} の音 ${name}`,
|
|
1527
|
+
stageSound: (name) => `ステージの音 ${name}`
|
|
707
1528
|
}
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
1529
|
+
};
|
|
1530
|
+
var messagesFor = (locale = "en") => locale.toLowerCase().startsWith("ja") ? messages.ja : messages.en;
|
|
1531
|
+
/**
|
|
1532
|
+
* Describes the files of a project folder for `ProjectFolderExplorer`'s `descriptions`: the project, manifest and
|
|
1533
|
+
* extension files, and each asset file with the costumes and sounds that use it. `folder` is the project folder's
|
|
1534
|
+
* path inside the explorer's root ('' when the root is the project folder). Malformed entries are skipped.
|
|
1535
|
+
*/
|
|
1536
|
+
function describeProjectFolder(project, locale, { manifest, folder = "" } = {}) {
|
|
1537
|
+
const message = messagesFor(locale);
|
|
1538
|
+
const prefix = folder.replace(/^\/+|\/+$/gu, "");
|
|
1539
|
+
const at = (name) => prefix ? `${prefix}/${name}` : name;
|
|
1540
|
+
const assetsDirectory = isObject(manifest) && typeof manifest.assetsDirectory === "string" && manifest.assetsDirectory ? manifest.assetsDirectory.replace(/^\/+|\/+$/gu, "") : "assets";
|
|
1541
|
+
const extensions = isObject(manifest) && typeof manifest.embeddedExtensions === "string" ? manifest.embeddedExtensions : "embedded-extensions.json";
|
|
1542
|
+
const descriptions = /* @__PURE__ */ new Map([
|
|
1543
|
+
[at(projectFile), message.project],
|
|
1544
|
+
[at(manifestFile), message.manifest],
|
|
1545
|
+
[at(extensions), message.extensions],
|
|
1546
|
+
[at(assetsDirectory), message.assetsDirectory],
|
|
1547
|
+
[at("extensions"), message.extensionsDirectory]
|
|
1548
|
+
]);
|
|
1549
|
+
const users = /* @__PURE__ */ new Map();
|
|
1550
|
+
for (const target of Array.isArray(project.targets) ? project.targets : []) {
|
|
1551
|
+
if (!isObject(target)) continue;
|
|
1552
|
+
const sprite = typeof target.name === "string" ? target.name : "";
|
|
1553
|
+
for (const kind of ["costumes", "sounds"]) {
|
|
1554
|
+
const entries = target[kind];
|
|
1555
|
+
if (!Array.isArray(entries)) continue;
|
|
1556
|
+
for (const entry of entries) {
|
|
1557
|
+
var _users$get;
|
|
1558
|
+
if (!isObject(entry) || typeof entry.assetId !== "string" || typeof entry.dataFormat !== "string") continue;
|
|
1559
|
+
const file = typeof entry.md5ext === "string" ? entry.md5ext : `${entry.assetId}.${entry.dataFormat}`;
|
|
1560
|
+
const name = typeof entry.name === "string" ? entry.name : "";
|
|
1561
|
+
const text = kind === "costumes" ? target.isStage ? message.backdrop(name) : message.costume(sprite, name) : target.isStage ? message.stageSound(name) : message.sound(sprite, name);
|
|
1562
|
+
const path = at(`${assetsDirectory}/${file}`);
|
|
1563
|
+
const list = (_users$get = users.get(path)) !== null && _users$get !== void 0 ? _users$get : [];
|
|
1564
|
+
if (!list.includes(text)) list.push(text);
|
|
1565
|
+
users.set(path, list);
|
|
727
1566
|
}
|
|
728
1567
|
}
|
|
729
1568
|
}
|
|
730
|
-
for (
|
|
731
|
-
return
|
|
1569
|
+
for (const [path, list] of users) descriptions.set(path, list.join(message.separator));
|
|
1570
|
+
return descriptions;
|
|
732
1571
|
}
|
|
733
|
-
var
|
|
734
|
-
|
|
1572
|
+
var rootId = "/";
|
|
1573
|
+
var errorId = (parent) => `${parent}\0error`;
|
|
1574
|
+
var failure = (error, message) => error instanceof DOMException && (error.name === "NotAllowedError" || error.name === "SecurityError") ? message.denied : message.failed;
|
|
1575
|
+
var prefix = "twpf-explorer";
|
|
1576
|
+
var entryDragType = "application/x-twpf-explorer-entry";
|
|
1577
|
+
var css = `.${prefix}{font:inherit;color:inherit}
|
|
1578
|
+
.${prefix}-item{display:flex;align-items:center;gap:.4em;width:100%;box-sizing:border-box;margin:0;border:0;border-radius:3px;
|
|
735
1579
|
padding-block:.15em;padding-inline-end:.4em;background:none;color:inherit;font:inherit;text-align:start;cursor:pointer;white-space:nowrap}
|
|
736
|
-
.${
|
|
737
|
-
.${
|
|
738
|
-
.${
|
|
739
|
-
.${
|
|
740
|
-
.${
|
|
741
|
-
.${
|
|
1580
|
+
.${prefix}-item:hover{background:rgba(128,128,128,.12)}
|
|
1581
|
+
.${prefix}-item[aria-selected="true"]{background:rgba(128,128,128,.24)}
|
|
1582
|
+
.${prefix}-item:focus-visible{outline:2px solid currentColor;outline-offset:-2px}
|
|
1583
|
+
.${prefix}-caret{display:inline-block;width:1em;flex:none;text-align:center}
|
|
1584
|
+
.${prefix}-icon{display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;flex:none}
|
|
1585
|
+
.${prefix}-icon img{width:20px;height:20px;object-fit:contain;border-radius:2px;
|
|
742
1586
|
background:repeating-conic-gradient(rgba(128,128,128,.22) 0 25%,transparent 0 50%) 0 0/8px 8px}
|
|
743
|
-
.${
|
|
744
|
-
.${
|
|
745
|
-
.${
|
|
746
|
-
.${
|
|
747
|
-
.${
|
|
748
|
-
.${
|
|
749
|
-
.${
|
|
750
|
-
.${
|
|
751
|
-
|
|
1587
|
+
.${prefix}-icon img[hidden]{display:none}
|
|
1588
|
+
.${prefix}-filename{display:inline-flex;min-width:0}
|
|
1589
|
+
.${prefix}-name{overflow:hidden;text-overflow:ellipsis}
|
|
1590
|
+
.${prefix}-item[data-staged] .${prefix}-filename{font-weight:700}
|
|
1591
|
+
.${prefix}-item[data-revision="committed"] .${prefix}-filename{color:#174b9d;color:light-dark(#174b9d,#91c1ff)}
|
|
1592
|
+
.${prefix}-item[data-revision="pushed"] .${prefix}-filename{color:#67369a;color:light-dark(#67369a,#dfafff)}
|
|
1593
|
+
.${prefix}-item[data-revision="merged"] .${prefix}-filename{color:#17603e;color:light-dark(#17603e,#85e3ad)}
|
|
1594
|
+
.${prefix}-unsaved{flex:none}
|
|
1595
|
+
.${prefix}-mark{flex:none;font-size:.85em;padding:0 .3em;border:1px solid currentColor;border-radius:3px;opacity:.85}
|
|
1596
|
+
.${prefix}-description{overflow:hidden;text-overflow:ellipsis;opacity:.7;font-size:.9em}
|
|
1597
|
+
.${prefix}-status{opacity:.7;font-style:italic;padding-block:.15em}
|
|
1598
|
+
.${prefix}-empty{padding:.5em}
|
|
1599
|
+
.${prefix}-empty p{margin:0 0 .6em}
|
|
1600
|
+
.${prefix}-empty button{color:inherit;background:transparent;border:1px solid currentColor;border-radius:4px;padding:.2em .6em;font:inherit;cursor:pointer}`;
|
|
1601
|
+
var indent = (level) => ({ paddingInlineStart: `${.25 + level * 1.1}em` });
|
|
1602
|
+
var page = "M3.5 1.5h6l3 3v10h-9z";
|
|
1603
|
+
var corner = "M9.5 1.5v3h3";
|
|
1604
|
+
var icons = {
|
|
1605
|
+
"folder": ["M1.5 3.5h4l1.5 1.5h7.5v8h-13z"],
|
|
752
1606
|
"folder-open": ["M1.5 13V3.5h4l1.5 1.5h6v2", "M1.5 13l2-6h11l-2 6z"],
|
|
753
|
-
project: [
|
|
1607
|
+
"project": [
|
|
754
1608
|
"M8 1.5l6 3v7l-6 3-6-3v-7z",
|
|
755
1609
|
"M2 4.5l6 3 6-3",
|
|
756
1610
|
"M8 7.5v7"
|
|
757
1611
|
],
|
|
758
|
-
json: [
|
|
759
|
-
|
|
760
|
-
|
|
1612
|
+
"json": [
|
|
1613
|
+
page,
|
|
1614
|
+
corner,
|
|
761
1615
|
"M7 7c-1 0-1 .6-1 1.4s-.3 1.1-.8 1.1c.5 0 .8.4.8 1.1S6 12 7 12",
|
|
762
1616
|
"M9 7c1 0 1 .6 1 1.4s.3 1.1.8 1.1c-.5 0-.8.4-.8 1.1S10 12 9 12"
|
|
763
1617
|
],
|
|
764
|
-
image: [
|
|
1618
|
+
"image": [
|
|
765
1619
|
"M1.5 2.5h13v11h-13z",
|
|
766
1620
|
"M1.5 11l4-4 3 3 2-2 4 4",
|
|
767
1621
|
"M12.2 5.5a1.2 1.2 0 1 1-2.4 0a1.2 1.2 0 1 1 2.4 0"
|
|
768
1622
|
],
|
|
769
|
-
sound: [
|
|
1623
|
+
"sound": [
|
|
770
1624
|
"M2 6h3l3.5-3v10L5 10H2z",
|
|
771
1625
|
"M10.5 5.5a3.5 3.5 0 0 1 0 5",
|
|
772
1626
|
"M12.5 3.5a6.5 6.5 0 0 1 0 9"
|
|
773
1627
|
],
|
|
774
|
-
code: [
|
|
1628
|
+
"code": [
|
|
775
1629
|
"M5.5 4.5L2 8l3.5 3.5",
|
|
776
1630
|
"M10.5 4.5L14 8l-3.5 3.5",
|
|
777
1631
|
"M9 3l-2 10"
|
|
778
1632
|
],
|
|
779
|
-
text: [
|
|
780
|
-
|
|
781
|
-
|
|
1633
|
+
"text": [
|
|
1634
|
+
page,
|
|
1635
|
+
corner,
|
|
782
1636
|
"M5.5 7.5h5M5.5 9.5h5M5.5 11.5h3"
|
|
783
1637
|
],
|
|
784
|
-
file: [
|
|
785
|
-
}
|
|
1638
|
+
"file": [page, corner]
|
|
1639
|
+
};
|
|
1640
|
+
var extensionIcons = {
|
|
786
1641
|
json: "json",
|
|
787
1642
|
svg: "image",
|
|
788
1643
|
png: "image",
|
|
@@ -799,37 +1654,54 @@ background:repeating-conic-gradient(rgba(128,128,128,.22) 0 25%,transparent 0 50
|
|
|
799
1654
|
ts: "code",
|
|
800
1655
|
md: "text",
|
|
801
1656
|
txt: "text"
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
1657
|
+
};
|
|
1658
|
+
var iconFor = (name) => {
|
|
1659
|
+
var _extensionIcons$name$;
|
|
1660
|
+
return name === "project.source.json" || name === "sb3-source.json" ? "project" : (_extensionIcons$name$ = extensionIcons[name.slice(name.lastIndexOf(".") + 1).toLowerCase()]) !== null && _extensionIcons$name$ !== void 0 ? _extensionIcons$name$ : "file";
|
|
1661
|
+
};
|
|
1662
|
+
var thumbnailLimit = 2097152;
|
|
1663
|
+
function Icon({ kind, path, readFile }) {
|
|
1664
|
+
const ref = React.useRef(null);
|
|
1665
|
+
const [state, setState] = React.useState("waiting");
|
|
1666
|
+
const [url, setUrl] = React.useState();
|
|
1667
|
+
React.useEffect(() => {
|
|
1668
|
+
if (!readFile) return void 0;
|
|
1669
|
+
let live = true;
|
|
1670
|
+
let created;
|
|
1671
|
+
const load = async () => {
|
|
1672
|
+
setState("loading");
|
|
812
1673
|
try {
|
|
813
|
-
|
|
814
|
-
if (!
|
|
815
|
-
if (
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
1674
|
+
const file = await readFile(path);
|
|
1675
|
+
if (!live) return;
|
|
1676
|
+
if (file.size > thumbnailLimit) return setState("skipped");
|
|
1677
|
+
created = URL.createObjectURL(file);
|
|
1678
|
+
setUrl(created);
|
|
1679
|
+
} catch (_unused) {
|
|
1680
|
+
if (live) setState("failed");
|
|
819
1681
|
}
|
|
820
|
-
}, s;
|
|
821
|
-
return typeof IntersectionObserver == "function" && r.current ? (s = new IntersectionObserver((e) => {
|
|
822
|
-
e.some((e) => e.isIntersecting) && (s == null || s.disconnect(), o());
|
|
823
|
-
}), s.observe(r.current)) : o(), () => {
|
|
824
|
-
e = !1, s == null || s.disconnect(), i && URL.revokeObjectURL(i);
|
|
825
1682
|
};
|
|
826
|
-
|
|
827
|
-
ref
|
|
828
|
-
|
|
1683
|
+
let observer;
|
|
1684
|
+
if (typeof IntersectionObserver === "function" && ref.current) {
|
|
1685
|
+
observer = new IntersectionObserver((entries) => {
|
|
1686
|
+
if (!entries.some((entry) => entry.isIntersecting)) return;
|
|
1687
|
+
observer === null || observer === void 0 || observer.disconnect();
|
|
1688
|
+
load();
|
|
1689
|
+
});
|
|
1690
|
+
observer.observe(ref.current);
|
|
1691
|
+
} else load();
|
|
1692
|
+
return () => {
|
|
1693
|
+
live = false;
|
|
1694
|
+
observer === null || observer === void 0 || observer.disconnect();
|
|
1695
|
+
if (created) URL.revokeObjectURL(created);
|
|
1696
|
+
};
|
|
1697
|
+
}, [path]);
|
|
1698
|
+
return /* @__PURE__ */ React.createElement("span", {
|
|
1699
|
+
ref,
|
|
1700
|
+
className: `${prefix}-icon`,
|
|
829
1701
|
"aria-hidden": "true",
|
|
830
|
-
"data-icon":
|
|
831
|
-
"data-thumbnail":
|
|
832
|
-
},
|
|
1702
|
+
"data-icon": kind,
|
|
1703
|
+
"data-thumbnail": readFile ? state : void 0
|
|
1704
|
+
}, state === "loaded" ? null : /* @__PURE__ */ React.createElement("svg", {
|
|
833
1705
|
viewBox: "0 0 16 16",
|
|
834
1706
|
width: "16",
|
|
835
1707
|
height: "16",
|
|
@@ -839,123 +1711,161 @@ function ye({ kind: e, path: t, readFile: n }) {
|
|
|
839
1711
|
strokeLinecap: "round",
|
|
840
1712
|
strokeLinejoin: "round",
|
|
841
1713
|
focusable: "false"
|
|
842
|
-
},
|
|
843
|
-
key:
|
|
844
|
-
d
|
|
845
|
-
}))),
|
|
846
|
-
src:
|
|
1714
|
+
}, icons[kind].map((d) => /* @__PURE__ */ React.createElement("path", {
|
|
1715
|
+
key: d,
|
|
1716
|
+
d
|
|
1717
|
+
}))), url && state !== "failed" ? /* @__PURE__ */ React.createElement("img", {
|
|
1718
|
+
src: url,
|
|
847
1719
|
alt: "",
|
|
848
1720
|
decoding: "async",
|
|
849
|
-
hidden:
|
|
850
|
-
onLoad: () =>
|
|
851
|
-
onError: () =>
|
|
1721
|
+
hidden: state !== "loaded",
|
|
1722
|
+
onLoad: () => setState("loaded"),
|
|
1723
|
+
onError: () => setState("failed")
|
|
852
1724
|
}) : null);
|
|
853
1725
|
}
|
|
854
|
-
function
|
|
855
|
-
|
|
856
|
-
|
|
1726
|
+
function Explorer({ directory, locale, descriptions, marks, fileStatuses, unsavedPaths, refreshKey, onOpen, label, mutate, git, isCurrent }) {
|
|
1727
|
+
const message = messagesFor(locale);
|
|
1728
|
+
const actions = actionMessages(locale);
|
|
1729
|
+
const [handles] = React.useState(() => /* @__PURE__ */ new Map([[rootId, directory]]));
|
|
1730
|
+
const [files] = React.useState(() => /* @__PURE__ */ new Map());
|
|
1731
|
+
const [loadedFolders] = React.useState(() => /* @__PURE__ */ new Set());
|
|
1732
|
+
const [rootLoaded, setRootLoaded] = React.useState(false);
|
|
1733
|
+
const [drag, setDrag] = React.useState(null);
|
|
1734
|
+
const [move, setMove] = React.useState();
|
|
1735
|
+
const [menu, setMenu] = React.useState();
|
|
1736
|
+
const [dialog, setDialog] = React.useState();
|
|
1737
|
+
const [feedback, setFeedback] = React.useState("");
|
|
1738
|
+
const [working, setWorking] = React.useState(false);
|
|
1739
|
+
const running = React.useRef(false);
|
|
1740
|
+
const mounted = React.useRef(true);
|
|
1741
|
+
React.useEffect(() => {
|
|
1742
|
+
mounted.current = true;
|
|
1743
|
+
return () => {
|
|
1744
|
+
mounted.current = false;
|
|
1745
|
+
};
|
|
1746
|
+
}, []);
|
|
1747
|
+
const collator = React.useMemo(() => new Intl.Collator(locale, {
|
|
1748
|
+
numeric: true,
|
|
857
1749
|
sensitivity: "base"
|
|
858
|
-
}), [
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
1750
|
+
}), [locale]);
|
|
1751
|
+
const directoryAt = async (id) => {
|
|
1752
|
+
let handle = handles.get(id);
|
|
1753
|
+
if (handle) return handle;
|
|
1754
|
+
handle = directory;
|
|
1755
|
+
for (const name of id.split("/")) handle = await handle.getDirectoryHandle(name);
|
|
1756
|
+
handles.set(id, handle);
|
|
1757
|
+
return handle;
|
|
1758
|
+
};
|
|
1759
|
+
const readFile = async (path) => {
|
|
1760
|
+
let handle = files.get(path);
|
|
1761
|
+
if (!handle) {
|
|
1762
|
+
const parts = path.split("/");
|
|
1763
|
+
const name = parts.pop();
|
|
1764
|
+
handle = await (parts.length ? await directoryAt(parts.join("/")) : directory).getFileHandle(name);
|
|
869
1765
|
}
|
|
870
|
-
return
|
|
871
|
-
}
|
|
872
|
-
|
|
1766
|
+
return handle.getFile();
|
|
1767
|
+
};
|
|
1768
|
+
const tree = useTree({
|
|
1769
|
+
rootItemId: rootId,
|
|
873
1770
|
initialState: {
|
|
874
1771
|
expandedItems: [],
|
|
875
1772
|
selectedItems: [],
|
|
876
1773
|
focusedItem: null
|
|
877
1774
|
},
|
|
878
|
-
getItemName: (
|
|
879
|
-
var
|
|
880
|
-
return (
|
|
1775
|
+
getItemName: (item) => {
|
|
1776
|
+
var _item$getItemData$nam, _item$getItemData;
|
|
1777
|
+
return (_item$getItemData$nam = (_item$getItemData = item.getItemData()) === null || _item$getItemData === void 0 ? void 0 : _item$getItemData.name) !== null && _item$getItemData$nam !== void 0 ? _item$getItemData$nam : "";
|
|
881
1778
|
},
|
|
882
|
-
isItemFolder: (
|
|
883
|
-
var
|
|
884
|
-
return ((
|
|
1779
|
+
isItemFolder: (item) => {
|
|
1780
|
+
var _item$getItemData2;
|
|
1781
|
+
return ((_item$getItemData2 = item.getItemData()) === null || _item$getItemData2 === void 0 ? void 0 : _item$getItemData2.kind) === "directory";
|
|
885
1782
|
},
|
|
886
1783
|
createLoadingItemData: () => ({
|
|
887
1784
|
name: "",
|
|
888
1785
|
path: "",
|
|
889
1786
|
kind: "file"
|
|
890
1787
|
}),
|
|
891
|
-
onPrimaryAction: (
|
|
892
|
-
|
|
893
|
-
(
|
|
894
|
-
path:
|
|
895
|
-
name:
|
|
1788
|
+
onPrimaryAction: (item) => {
|
|
1789
|
+
const data = item.getItemData();
|
|
1790
|
+
if ((data === null || data === void 0 ? void 0 : data.kind) === "file") onOpen === null || onOpen === void 0 || onOpen({
|
|
1791
|
+
path: data.path,
|
|
1792
|
+
name: data.name,
|
|
896
1793
|
kind: "file"
|
|
897
|
-
})
|
|
1794
|
+
});
|
|
898
1795
|
},
|
|
899
|
-
onLoadedChildren: (
|
|
900
|
-
|
|
1796
|
+
onLoadedChildren: (id) => {
|
|
1797
|
+
if (id === rootId) setRootLoaded(true);
|
|
901
1798
|
},
|
|
902
1799
|
dataLoader: {
|
|
903
|
-
getItem: async (
|
|
904
|
-
if (
|
|
905
|
-
name:
|
|
1800
|
+
getItem: async (id) => {
|
|
1801
|
+
if (id === rootId) return {
|
|
1802
|
+
name: directory.name,
|
|
906
1803
|
path: "",
|
|
907
1804
|
kind: "directory"
|
|
908
1805
|
};
|
|
909
|
-
|
|
1806
|
+
const parts = id.split("/");
|
|
1807
|
+
const name = parts.pop();
|
|
1808
|
+
const parent = parts.length ? await directoryAt(parts.join("/")) : directory;
|
|
910
1809
|
try {
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
1810
|
+
await parent.getDirectoryHandle(name);
|
|
1811
|
+
return {
|
|
1812
|
+
name,
|
|
1813
|
+
path: id,
|
|
914
1814
|
kind: "directory"
|
|
915
1815
|
};
|
|
916
|
-
} catch (
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
1816
|
+
} catch (_unused2) {
|
|
1817
|
+
await parent.getFileHandle(name);
|
|
1818
|
+
return {
|
|
1819
|
+
name,
|
|
1820
|
+
path: id,
|
|
920
1821
|
kind: "file"
|
|
921
1822
|
};
|
|
922
1823
|
}
|
|
923
1824
|
},
|
|
924
|
-
getChildrenWithData: async (
|
|
1825
|
+
getChildrenWithData: async (id) => {
|
|
925
1826
|
try {
|
|
926
|
-
|
|
927
|
-
|
|
1827
|
+
const handle = await directoryAt(id);
|
|
1828
|
+
const base = id === rootId ? "" : `${id}/`;
|
|
1829
|
+
const nodes = [];
|
|
1830
|
+
var _iteratorAbruptCompletion = false;
|
|
1831
|
+
var _didIteratorError = false;
|
|
1832
|
+
var _iteratorError;
|
|
928
1833
|
try {
|
|
929
|
-
for (var
|
|
930
|
-
|
|
1834
|
+
for (var _iterator = _asyncIterator(handle.values()), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
|
|
1835
|
+
const entry = _step.value;
|
|
931
1836
|
{
|
|
932
|
-
if (
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
1837
|
+
if (entry.name.toLowerCase() === ".git") continue;
|
|
1838
|
+
const path = base + entry.name;
|
|
1839
|
+
if (entry.kind === "directory") handles.set(path, entry);
|
|
1840
|
+
else files.set(path, entry);
|
|
1841
|
+
nodes.push({
|
|
1842
|
+
name: entry.name,
|
|
1843
|
+
path,
|
|
1844
|
+
kind: entry.kind
|
|
938
1845
|
});
|
|
939
1846
|
}
|
|
940
1847
|
}
|
|
941
|
-
} catch (
|
|
942
|
-
|
|
1848
|
+
} catch (err) {
|
|
1849
|
+
_didIteratorError = true;
|
|
1850
|
+
_iteratorError = err;
|
|
943
1851
|
} finally {
|
|
944
1852
|
try {
|
|
945
|
-
|
|
1853
|
+
if (_iteratorAbruptCompletion && _iterator.return != null) await _iterator.return();
|
|
946
1854
|
} finally {
|
|
947
|
-
if (
|
|
1855
|
+
if (_didIteratorError) throw _iteratorError;
|
|
948
1856
|
}
|
|
949
1857
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
1858
|
+
loadedFolders.add(id);
|
|
1859
|
+
nodes.sort((a, b) => (a.kind === "directory" ? 0 : 1) - (b.kind === "directory" ? 0 : 1) || collator.compare(a.name, b.name) || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
1860
|
+
return nodes.map((data) => ({
|
|
1861
|
+
id: data.path,
|
|
1862
|
+
data
|
|
953
1863
|
}));
|
|
954
|
-
} catch (
|
|
1864
|
+
} catch (error) {
|
|
955
1865
|
return [{
|
|
956
|
-
id:
|
|
1866
|
+
id: errorId(id),
|
|
957
1867
|
data: {
|
|
958
|
-
name:
|
|
1868
|
+
name: failure(error, message),
|
|
959
1869
|
path: "",
|
|
960
1870
|
kind: "error"
|
|
961
1871
|
}
|
|
@@ -964,96 +1874,512 @@ function X({ directory: n, locale: r, descriptions: i, marks: a, onOpen: s, labe
|
|
|
964
1874
|
}
|
|
965
1875
|
},
|
|
966
1876
|
features: [
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1877
|
+
asyncDataLoaderFeature,
|
|
1878
|
+
selectionFeature,
|
|
1879
|
+
hotkeysCoreFeature
|
|
970
1880
|
]
|
|
971
1881
|
});
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1882
|
+
React.useEffect(() => {
|
|
1883
|
+
tree.setMounted(true);
|
|
1884
|
+
return () => tree.setMounted(false);
|
|
1885
|
+
}, [tree]);
|
|
1886
|
+
const lastRefresh = React.useRef(refreshKey);
|
|
1887
|
+
React.useEffect(() => {
|
|
1888
|
+
if (lastRefresh.current === refreshKey) return;
|
|
1889
|
+
lastRefresh.current = refreshKey;
|
|
1890
|
+
Promise.all([...loadedFolders].map((id) => tree.getItemInstance(id).invalidateChildrenIds(true)));
|
|
1891
|
+
}, [
|
|
1892
|
+
tree,
|
|
1893
|
+
loadedFolders,
|
|
1894
|
+
refreshKey
|
|
1895
|
+
]);
|
|
1896
|
+
const errorText = (error) => {
|
|
1897
|
+
if (error instanceof ExplorerFileError) return actions[error.code];
|
|
1898
|
+
if (error instanceof DOMException && ["NotAllowedError", "SecurityError"].includes(error.name)) return actions.denied;
|
|
1899
|
+
if (error instanceof FolderError && error.code === "conflict") return actions.conflict;
|
|
1900
|
+
return actions.failed;
|
|
1901
|
+
};
|
|
1902
|
+
const run = async (operation) => {
|
|
1903
|
+
if (running.current) return;
|
|
1904
|
+
running.current = true;
|
|
1905
|
+
setWorking(true);
|
|
1906
|
+
setFeedback("");
|
|
1907
|
+
try {
|
|
1908
|
+
const result = await operation();
|
|
1909
|
+
if (mounted.current) setFeedback(result !== null && result !== void 0 ? result : "");
|
|
1910
|
+
} catch (error) {
|
|
1911
|
+
if (mounted.current) setFeedback(errorText(error));
|
|
1912
|
+
} finally {
|
|
1913
|
+
running.current = false;
|
|
1914
|
+
if (mounted.current) setWorking(false);
|
|
1915
|
+
}
|
|
1916
|
+
};
|
|
1917
|
+
const write = (path, operation) => mutate(async (guard) => {
|
|
1918
|
+
const permission = directory.requestPermission;
|
|
1919
|
+
if (permission && await permission.call(directory, { mode: "readwrite" }) !== "granted") throw new DOMException("Write permission denied", "NotAllowedError");
|
|
1920
|
+
guard();
|
|
1921
|
+
const parent = await resolveExplorerDirectory(directory, path);
|
|
1922
|
+
guard();
|
|
1923
|
+
await operation(parent, guard);
|
|
1924
|
+
});
|
|
1925
|
+
const reread = async (path, expand = false) => {
|
|
1926
|
+
if (!mounted.current) return;
|
|
1927
|
+
const parent = path ? tree.getItemInstance(path) : tree.getRootItem();
|
|
1928
|
+
if (expand && path && !parent.isExpanded()) parent.expand();
|
|
1929
|
+
await parent.invalidateChildrenIds(true);
|
|
1930
|
+
};
|
|
1931
|
+
const forget = (path) => {
|
|
1932
|
+
const cache = tree.getDataRef();
|
|
1933
|
+
for (const id of handles.keys()) {
|
|
1934
|
+
if (id !== path && !id.startsWith(`${path}/`)) continue;
|
|
1935
|
+
delete cache.current.childrenIds[id];
|
|
1936
|
+
loadedFolders.delete(id);
|
|
1937
|
+
handles.delete(id);
|
|
1938
|
+
}
|
|
1939
|
+
for (const id of files.keys()) if (id === path || id.startsWith(`${path}/`)) files.delete(id);
|
|
1940
|
+
};
|
|
1941
|
+
const dropPath = (target) => {
|
|
1942
|
+
var _target$closest$getAt, _target$closest;
|
|
1943
|
+
return (_target$closest$getAt = (_target$closest = target.closest("[data-drop-directory]")) === null || _target$closest === void 0 ? void 0 : _target$closest.getAttribute("data-drop-directory")) !== null && _target$closest$getAt !== void 0 ? _target$closest$getAt : "";
|
|
1944
|
+
};
|
|
1945
|
+
const moveDropPath = (target) => {
|
|
1946
|
+
const row = target.closest(`.${prefix}-item`);
|
|
1947
|
+
const path = row ? row.getAttribute("data-move-directory") : "";
|
|
1948
|
+
return path !== null && (move === null || move === void 0 ? void 0 : move.destinations.has(path)) ? path : null;
|
|
1949
|
+
};
|
|
1950
|
+
const startMove = (event, entry) => {
|
|
1951
|
+
var _document$defaultView;
|
|
1952
|
+
if (running.current || dialog) {
|
|
1953
|
+
event.preventDefault();
|
|
1954
|
+
return;
|
|
1955
|
+
}
|
|
1956
|
+
event.stopPropagation();
|
|
1957
|
+
setMenu(void 0);
|
|
1958
|
+
setDrag(null);
|
|
1959
|
+
event.dataTransfer.effectAllowed = "move";
|
|
1960
|
+
event.dataTransfer.setData(entryDragType, entry.path);
|
|
1961
|
+
const row = event.currentTarget;
|
|
1962
|
+
const document = row.ownerDocument;
|
|
1963
|
+
const image = document.createElement("div");
|
|
1964
|
+
image.className = `${prefix}-drag-image`;
|
|
1965
|
+
const icon = row.querySelector(`.${prefix}-icon`);
|
|
1966
|
+
if (icon) image.appendChild(icon.cloneNode(true));
|
|
1967
|
+
const name = document.createElement("span");
|
|
1968
|
+
name.className = `${prefix}-name`;
|
|
1969
|
+
name.textContent = entry.name;
|
|
1970
|
+
image.appendChild(name);
|
|
1971
|
+
document.body.appendChild(image);
|
|
1972
|
+
event.dataTransfer.setDragImage(image, -12, -12);
|
|
1973
|
+
(_document$defaultView = document.defaultView) === null || _document$defaultView === void 0 || _document$defaultView.requestAnimationFrame(() => image.remove());
|
|
1974
|
+
setMove({
|
|
1975
|
+
entry,
|
|
1976
|
+
destinations: /* @__PURE__ */ new Set()
|
|
1977
|
+
});
|
|
1978
|
+
const candidates = ["", ...tree.getItems().filter((item) => item.isFolder()).map((item) => item.getId())];
|
|
1979
|
+
Promise.all(candidates.filter((path) => canMoveExplorerEntry(entry.path, path)).map(async (path) => {
|
|
1980
|
+
try {
|
|
1981
|
+
return await explorerNameAvailable(await directoryAt(path || rootId), entry.name) ? path : null;
|
|
1982
|
+
} catch (_unused3) {
|
|
1983
|
+
return null;
|
|
1984
|
+
}
|
|
1985
|
+
})).then((paths) => {
|
|
1986
|
+
if (mounted.current) setMove((current) => (current === null || current === void 0 ? void 0 : current.entry) === entry ? {
|
|
1987
|
+
entry,
|
|
1988
|
+
destinations: new Set(paths.filter((path) => path !== null))
|
|
1989
|
+
} : current);
|
|
1990
|
+
});
|
|
1991
|
+
};
|
|
1992
|
+
const endMove = () => {
|
|
1993
|
+
setMove(void 0);
|
|
1994
|
+
setDrag(null);
|
|
1995
|
+
};
|
|
1996
|
+
const dropMove = (event, entry) => {
|
|
1997
|
+
event.preventDefault();
|
|
1998
|
+
event.stopPropagation();
|
|
1999
|
+
const path = moveDropPath(event.target);
|
|
2000
|
+
endMove();
|
|
2001
|
+
if (path === null || event.dataTransfer.getData(entryDragType) !== entry.path) return;
|
|
2002
|
+
run(async () => {
|
|
2003
|
+
let moved = false;
|
|
2004
|
+
try {
|
|
2005
|
+
await write(path, (destination, guard) => moveExplorerEntry(directory, entry, destination, path, guard));
|
|
2006
|
+
moved = true;
|
|
2007
|
+
} finally {
|
|
2008
|
+
if (mounted.current) forget(entry.path);
|
|
2009
|
+
await reread(parentPath(entry.path));
|
|
2010
|
+
await reread(path, moved);
|
|
2011
|
+
await (git === null || git === void 0 ? void 0 : git.refresh());
|
|
2012
|
+
}
|
|
2013
|
+
});
|
|
2014
|
+
};
|
|
2015
|
+
const acceptsFiles = (event) => Boolean(mutate && event.dataTransfer.types.includes("Files"));
|
|
2016
|
+
const drop = (event) => {
|
|
2017
|
+
if (move && event.dataTransfer.types.includes(entryDragType)) return dropMove(event, move.entry);
|
|
2018
|
+
if (!acceptsFiles(event)) return;
|
|
2019
|
+
event.preventDefault();
|
|
2020
|
+
event.stopPropagation();
|
|
2021
|
+
setDrag(null);
|
|
2022
|
+
const path = dropPath(event.target);
|
|
2023
|
+
const items = Array.from(event.dataTransfer.items);
|
|
2024
|
+
const problems = [];
|
|
2025
|
+
const dropped = items.length ? items.flatMap((item) => {
|
|
2026
|
+
var _item$webkitGetAsEntr;
|
|
2027
|
+
if (item.kind !== "file") return [];
|
|
2028
|
+
const entry = (_item$webkitGetAsEntr = item.webkitGetAsEntry) === null || _item$webkitGetAsEntr === void 0 ? void 0 : _item$webkitGetAsEntr.call(item);
|
|
2029
|
+
if (entry === null || entry === void 0 ? void 0 : entry.isDirectory) {
|
|
2030
|
+
problems.push(`${entry.name} — ${actions.filesOnly}`);
|
|
2031
|
+
return [];
|
|
2032
|
+
}
|
|
2033
|
+
const file = item.getAsFile();
|
|
2034
|
+
return file ? [file] : [];
|
|
2035
|
+
}) : Array.from(event.dataTransfer.files);
|
|
2036
|
+
run(async () => {
|
|
2037
|
+
if (!dropped.length) return problems.join("\n") || actions.filesOnly;
|
|
2038
|
+
try {
|
|
2039
|
+
await write(path, async (parent, guard) => {
|
|
2040
|
+
for (const file of dropped) {
|
|
2041
|
+
guard();
|
|
2042
|
+
try {
|
|
2043
|
+
await copyExplorerFile(parent, file, guard);
|
|
2044
|
+
} catch (error) {
|
|
2045
|
+
problems.push(`${actions.copyFailed} ${file.name} — ${errorText(error)}`);
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
});
|
|
2049
|
+
} finally {
|
|
2050
|
+
await reread(path, true);
|
|
2051
|
+
await (git === null || git === void 0 ? void 0 : git.refresh());
|
|
2052
|
+
}
|
|
2053
|
+
return problems.join("\n");
|
|
2054
|
+
});
|
|
2055
|
+
};
|
|
2056
|
+
const closeMenu = (restoreFocus) => {
|
|
2057
|
+
setMenu(void 0);
|
|
2058
|
+
if (restoreFocus && (menu === null || menu === void 0 ? void 0 : menu.anchor.row.isConnected)) menu.anchor.row.focus({ preventScroll: true });
|
|
2059
|
+
};
|
|
2060
|
+
const showMenu = (event, entry) => {
|
|
2061
|
+
if (running.current || !mutate && !git) return;
|
|
2062
|
+
event.preventDefault();
|
|
2063
|
+
event.stopPropagation();
|
|
2064
|
+
const row = event.currentTarget;
|
|
2065
|
+
const rect = row.getBoundingClientRect();
|
|
2066
|
+
const pointer = "clientX" in event && (event.clientX || event.clientY);
|
|
2067
|
+
setMenu({
|
|
2068
|
+
entry,
|
|
2069
|
+
anchor: {
|
|
2070
|
+
row,
|
|
2071
|
+
x: pointer ? event.clientX : rect.left,
|
|
2072
|
+
y: pointer ? event.clientY : rect.bottom
|
|
2073
|
+
}
|
|
2074
|
+
});
|
|
2075
|
+
};
|
|
2076
|
+
const submitFileAction = (name) => {
|
|
2077
|
+
if (!dialog) return;
|
|
2078
|
+
const { entry, action } = dialog;
|
|
2079
|
+
setDialog(void 0);
|
|
2080
|
+
if (action === "rename" && entry.name === name) return;
|
|
2081
|
+
run(async () => {
|
|
2082
|
+
const parent = action === "createFolder" ? entry.path : parentPath(entry.path);
|
|
2083
|
+
let changed = false;
|
|
2084
|
+
try {
|
|
2085
|
+
await write(parent, (handle, guard) => {
|
|
2086
|
+
if (action === "createFolder") return createExplorerDirectory(handle, name, guard);
|
|
2087
|
+
if (action === "rename") return renameExplorerEntry(handle, entry, name, guard);
|
|
2088
|
+
return deleteExplorerEntry(handle, entry, guard);
|
|
2089
|
+
});
|
|
2090
|
+
changed = true;
|
|
2091
|
+
} finally {
|
|
2092
|
+
if (mounted.current && action !== "createFolder") forget(entry.path);
|
|
2093
|
+
await reread(parent, action === "createFolder" && changed);
|
|
2094
|
+
await (git === null || git === void 0 ? void 0 : git.refresh());
|
|
2095
|
+
}
|
|
2096
|
+
});
|
|
2097
|
+
};
|
|
2098
|
+
const renderItem = (item) => {
|
|
2099
|
+
var _status$change;
|
|
2100
|
+
const data = item.getItemData();
|
|
2101
|
+
const entry = (data === null || data === void 0 ? void 0 : data.path) && data.kind !== "error" ? {
|
|
2102
|
+
path: data.path,
|
|
2103
|
+
name: data.name,
|
|
2104
|
+
kind: data.kind
|
|
2105
|
+
} : void 0;
|
|
2106
|
+
const itemProps = item.getProps();
|
|
2107
|
+
const level = item.getItemMeta().level;
|
|
2108
|
+
const folder = item.isFolder();
|
|
2109
|
+
const expanded = folder && item.isExpanded();
|
|
2110
|
+
const status = (data === null || data === void 0 ? void 0 : data.kind) === "file" ? fileStatuses === null || fileStatuses === void 0 ? void 0 : fileStatuses.get(data.path) : void 0;
|
|
2111
|
+
const unsaved = (data === null || data === void 0 ? void 0 : data.kind) === "file" && (unsavedPaths === null || unsavedPaths === void 0 ? void 0 : unsavedPaths.has(data.path));
|
|
2112
|
+
const mark = (_status$change = status === null || status === void 0 ? void 0 : status.change) !== null && _status$change !== void 0 ? _status$change : data && data.kind !== "error" ? marks === null || marks === void 0 ? void 0 : marks.get(data.path) : void 0;
|
|
2113
|
+
const markLabel = mark ? message.marks[mark] : "";
|
|
2114
|
+
const description = data && data.kind !== "error" ? descriptions === null || descriptions === void 0 ? void 0 : descriptions.get(data.path) : void 0;
|
|
2115
|
+
const icon = !data || data.kind === "error" ? void 0 : folder ? expanded ? "folder-open" : "folder" : iconFor(data.name);
|
|
2116
|
+
const accessibleName = [
|
|
2117
|
+
item.getItemName(),
|
|
2118
|
+
unsaved && message.unsaved,
|
|
2119
|
+
(status === null || status === void 0 ? void 0 : status.staged) && message.staged,
|
|
2120
|
+
(status === null || status === void 0 ? void 0 : status.revision) && message.revisions[status.revision],
|
|
2121
|
+
markLabel,
|
|
2122
|
+
description
|
|
2123
|
+
].filter(Boolean).join(message.separator);
|
|
2124
|
+
const moveDestination = (entry === null || entry === void 0 ? void 0 : entry.kind) === "directory" && (move === null || move === void 0 ? void 0 : move.destinations.has(entry.path));
|
|
2125
|
+
const moveActive = moveDestination && drag === entry.path;
|
|
2126
|
+
const rows = [/* @__PURE__ */ React.createElement("button", _objectSpread2(_objectSpread2({}, itemProps), {}, {
|
|
2127
|
+
key: item.getId(),
|
|
980
2128
|
type: "button",
|
|
981
|
-
"aria-label":
|
|
982
|
-
className: `${
|
|
983
|
-
style:
|
|
984
|
-
"data-path":
|
|
985
|
-
|
|
986
|
-
|
|
2129
|
+
"aria-label": accessibleName,
|
|
2130
|
+
className: `${prefix}-item${(data === null || data === void 0 ? void 0 : data.kind) === "error" ? ` ${prefix}-error` : ""}`,
|
|
2131
|
+
style: indent(level),
|
|
2132
|
+
"data-path": data === null || data === void 0 ? void 0 : data.path,
|
|
2133
|
+
"data-staged": (status === null || status === void 0 ? void 0 : status.staged) ? "" : void 0,
|
|
2134
|
+
"data-revision": status === null || status === void 0 ? void 0 : status.revision,
|
|
2135
|
+
title: unsaved || (status === null || status === void 0 ? void 0 : status.staged) || (status === null || status === void 0 ? void 0 : status.revision) ? accessibleName : void 0,
|
|
2136
|
+
"data-drop-directory": (entry === null || entry === void 0 ? void 0 : entry.kind) === "directory" ? entry.path : entry ? parentPath(entry.path) : void 0,
|
|
2137
|
+
"data-drop-active": (entry === null || entry === void 0 ? void 0 : entry.kind) === "directory" && drag === entry.path ? "" : void 0,
|
|
2138
|
+
"data-move-directory": (entry === null || entry === void 0 ? void 0 : entry.kind) === "directory" ? entry.path : void 0,
|
|
2139
|
+
"data-move-unavailable": move && !moveDestination ? "" : void 0,
|
|
2140
|
+
"data-move-active": moveActive ? "" : void 0,
|
|
2141
|
+
draggable: entry && mutate ? !working : void 0,
|
|
2142
|
+
onDragStart: entry && mutate ? (event) => startMove(event, entry) : void 0,
|
|
2143
|
+
onDragEnd: entry && mutate ? endMove : void 0,
|
|
2144
|
+
"aria-haspopup": entry && (mutate || git) ? "menu" : void 0,
|
|
2145
|
+
onContextMenu: entry ? (event) => showMenu(event, entry) : void 0,
|
|
2146
|
+
onKeyDown: entry ? (event) => {
|
|
2147
|
+
var _itemProps$onKeyDown;
|
|
2148
|
+
if ((mutate || git) && (event.key === "ContextMenu" || event.shiftKey && event.key === "F10")) showMenu(event, entry);
|
|
2149
|
+
else (_itemProps$onKeyDown = itemProps.onKeyDown) === null || _itemProps$onKeyDown === void 0 || _itemProps$onKeyDown.call(itemProps, event);
|
|
2150
|
+
} : itemProps.onKeyDown
|
|
2151
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
2152
|
+
className: `${prefix}-caret`,
|
|
2153
|
+
"aria-hidden": "true"
|
|
2154
|
+
}, folder ? expanded ? "▾" : "▸" : ""), icon ? /* @__PURE__ */ React.createElement(Icon, {
|
|
2155
|
+
kind: icon,
|
|
2156
|
+
path: data.path,
|
|
2157
|
+
readFile: icon === "image" ? readFile : void 0
|
|
2158
|
+
}) : null, /* @__PURE__ */ React.createElement("span", { className: `${prefix}-filename` }, /* @__PURE__ */ React.createElement("span", { className: `${prefix}-name` }, item.getItemName()), unsaved ? /* @__PURE__ */ React.createElement("span", {
|
|
2159
|
+
className: `${prefix}-unsaved`,
|
|
987
2160
|
"aria-hidden": "true"
|
|
988
|
-
},
|
|
989
|
-
|
|
990
|
-
path: n.path,
|
|
991
|
-
readFile: p === "image" ? g : void 0
|
|
992
|
-
}) : null, /* @__PURE__ */ o.createElement("span", { className: `${G}-name` }, e.getItemName()), d ? /* @__PURE__ */ o.createElement("span", {
|
|
993
|
-
className: `${G}-mark`,
|
|
2161
|
+
}, "*") : null), markLabel ? /* @__PURE__ */ React.createElement("span", {
|
|
2162
|
+
className: `${prefix}-mark`,
|
|
994
2163
|
"aria-hidden": "true"
|
|
995
|
-
},
|
|
996
|
-
className: `${
|
|
2164
|
+
}, markLabel) : null, description ? /* @__PURE__ */ React.createElement("span", {
|
|
2165
|
+
className: `${prefix}-description`,
|
|
997
2166
|
"aria-hidden": "true"
|
|
998
|
-
},
|
|
999
|
-
|
|
1000
|
-
key: `${
|
|
1001
|
-
className: `${
|
|
2167
|
+
}, description) : null)];
|
|
2168
|
+
if (expanded && item.isLoading()) rows.push(/* @__PURE__ */ React.createElement("div", {
|
|
2169
|
+
key: `${item.getId()}\0loading`,
|
|
2170
|
+
className: `${prefix}-status`,
|
|
1002
2171
|
role: "status",
|
|
1003
|
-
style:
|
|
1004
|
-
},
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
2172
|
+
style: indent(level + 1)
|
|
2173
|
+
}, message.loading));
|
|
2174
|
+
return rows;
|
|
2175
|
+
};
|
|
2176
|
+
const items = tree.getItems();
|
|
2177
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
2178
|
+
className: `${prefix}${mutate ? ` ${prefix}-drop` : ""}`,
|
|
2179
|
+
"data-drop-active": drag === "" ? "" : void 0,
|
|
2180
|
+
onDrop: drop,
|
|
2181
|
+
onDragOver: (event) => {
|
|
2182
|
+
if (move && event.dataTransfer.types.includes(entryDragType)) {
|
|
2183
|
+
const path = running.current ? null : moveDropPath(event.target);
|
|
2184
|
+
event.stopPropagation();
|
|
2185
|
+
if (path !== null) event.preventDefault();
|
|
2186
|
+
event.dataTransfer.dropEffect = path === null ? "none" : "move";
|
|
2187
|
+
setDrag(path);
|
|
2188
|
+
return;
|
|
2189
|
+
}
|
|
2190
|
+
if (!acceptsFiles(event)) return;
|
|
2191
|
+
event.preventDefault();
|
|
2192
|
+
event.stopPropagation();
|
|
2193
|
+
event.dataTransfer.dropEffect = running.current ? "none" : "copy";
|
|
2194
|
+
if (!running.current) setDrag(dropPath(event.target));
|
|
2195
|
+
},
|
|
2196
|
+
onDragLeave: (event) => {
|
|
2197
|
+
if (!event.currentTarget.contains(event.relatedTarget)) setDrag(null);
|
|
2198
|
+
}
|
|
2199
|
+
}, /* @__PURE__ */ React.createElement("style", null, css + actionCss), /* @__PURE__ */ React.createElement("div", tree.getContainerProps(label !== null && label !== void 0 ? label : message.label), items.map(renderItem)), items.length ? null : /* @__PURE__ */ React.createElement("div", {
|
|
2200
|
+
className: `${prefix}-status`,
|
|
1008
2201
|
role: "status"
|
|
1009
|
-
},
|
|
2202
|
+
}, rootLoaded ? message.empty : message.loading), working || feedback ? /* @__PURE__ */ React.createElement("div", {
|
|
2203
|
+
className: `${prefix}-feedback`,
|
|
2204
|
+
role: feedback ? "alert" : "status"
|
|
2205
|
+
}, feedback || actions.working) : null, menu ? /* @__PURE__ */ React.createElement(ExplorerMenu, {
|
|
2206
|
+
anchor: menu.anchor,
|
|
2207
|
+
label: actions.actions,
|
|
2208
|
+
close: closeMenu,
|
|
2209
|
+
actions: [
|
|
2210
|
+
...mutate && menu.entry.kind === "directory" ? [{
|
|
2211
|
+
label: actions.createFolder,
|
|
2212
|
+
run: () => {
|
|
2213
|
+
closeMenu(false);
|
|
2214
|
+
setDialog(_objectSpread2(_objectSpread2({}, menu), {}, { action: "createFolder" }));
|
|
2215
|
+
}
|
|
2216
|
+
}] : [],
|
|
2217
|
+
...mutate ? [{
|
|
2218
|
+
label: actions.rename,
|
|
2219
|
+
run: () => {
|
|
2220
|
+
closeMenu(false);
|
|
2221
|
+
setDialog(_objectSpread2(_objectSpread2({}, menu), {}, { action: "rename" }));
|
|
2222
|
+
}
|
|
2223
|
+
}, {
|
|
2224
|
+
label: actions.delete,
|
|
2225
|
+
run: () => {
|
|
2226
|
+
closeMenu(false);
|
|
2227
|
+
setDialog(_objectSpread2(_objectSpread2({}, menu), {}, { action: "delete" }));
|
|
2228
|
+
}
|
|
2229
|
+
}] : [],
|
|
2230
|
+
...git ? ["stage", "unstage"].map((kind) => ({
|
|
2231
|
+
label: actions[kind],
|
|
2232
|
+
run: () => {
|
|
2233
|
+
closeMenu(true);
|
|
2234
|
+
run(async () => {
|
|
2235
|
+
var _result$error;
|
|
2236
|
+
const result = await git.change(kind, menu.entry, isCurrent !== null && isCurrent !== void 0 ? isCurrent : (() => mounted.current));
|
|
2237
|
+
if (!result.done) return (_result$error = result.error) !== null && _result$error !== void 0 ? _result$error : actions.conflict;
|
|
2238
|
+
});
|
|
2239
|
+
}
|
|
2240
|
+
})) : []
|
|
2241
|
+
]
|
|
2242
|
+
}) : null, dialog ? /* @__PURE__ */ React.createElement(ExplorerFileDialog, {
|
|
2243
|
+
anchor: dialog.anchor,
|
|
2244
|
+
name: dialog.entry.name,
|
|
2245
|
+
folder: dialog.entry.kind === "directory",
|
|
2246
|
+
action: dialog.action,
|
|
2247
|
+
message: actions,
|
|
2248
|
+
close: () => setDialog(void 0),
|
|
2249
|
+
submit: submitFileAction
|
|
2250
|
+
}) : null);
|
|
1010
2251
|
}
|
|
1011
|
-
var
|
|
1012
|
-
|
|
1013
|
-
|
|
2252
|
+
var nextKey = 0;
|
|
2253
|
+
var keys = /* @__PURE__ */ new WeakMap();
|
|
2254
|
+
var keyFor = (directory) => {
|
|
2255
|
+
if (!keys.has(directory)) keys.set(directory, nextKey++);
|
|
2256
|
+
return keys.get(directory);
|
|
2257
|
+
};
|
|
2258
|
+
/**
|
|
2259
|
+
* A tree of a folder for the Editor's side panel, built on Headless Tree. Folders load when expanded, folders
|
|
2260
|
+
* sort before files, and `.git` is hidden. Keyboard: arrow keys, Home and End move and expand; Enter or Space opens a
|
|
2261
|
+
* file. Needs React 16.14–18 from the host.
|
|
2262
|
+
*/
|
|
2263
|
+
function ProjectFolderExplorer(props) {
|
|
2264
|
+
return /* @__PURE__ */ React.createElement(Explorer, _objectSpread2({ key: keyFor(props.directory) }, props));
|
|
1014
2265
|
}
|
|
1015
|
-
var
|
|
1016
|
-
function
|
|
1017
|
-
|
|
2266
|
+
var readJson = async (directory, name) => JSON.parse(await (await (await directory.getFileHandle(name)).getFile()).text());
|
|
2267
|
+
function FolderView({ vm, locale = "en", marks: followMarks, fileStatuses: followStatuses, git: followGit, openFile, readBaseline }) {
|
|
2268
|
+
const message = messagesFor(locale);
|
|
2269
|
+
const [{ folder, directory, version }, setFollowed] = React.useState({
|
|
1018
2270
|
directory: null,
|
|
1019
2271
|
version: 0
|
|
1020
2272
|
});
|
|
1021
|
-
|
|
1022
|
-
folder
|
|
1023
|
-
directory
|
|
1024
|
-
version:
|
|
1025
|
-
}))), [
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
let
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
2273
|
+
React.useEffect(() => followProjectFolder(vm, (folder, directory) => setFollowed((previous) => ({
|
|
2274
|
+
folder,
|
|
2275
|
+
directory,
|
|
2276
|
+
version: previous.version + 1
|
|
2277
|
+
}))), [vm]);
|
|
2278
|
+
const [descriptions, setDescriptions] = React.useState();
|
|
2279
|
+
React.useEffect(() => {
|
|
2280
|
+
let current = true;
|
|
2281
|
+
setDescriptions(void 0);
|
|
2282
|
+
if (!directory) return;
|
|
2283
|
+
Promise.all([readJson(directory, projectFile), readJson(directory, manifestFile).catch(() => void 0)]).then(([project, manifest]) => {
|
|
2284
|
+
if (current && isObject(project)) setDescriptions(describeProjectFolder(project, locale, { manifest }));
|
|
2285
|
+
}, () => {});
|
|
2286
|
+
return () => {
|
|
2287
|
+
current = false;
|
|
2288
|
+
};
|
|
2289
|
+
}, [
|
|
2290
|
+
directory,
|
|
2291
|
+
version,
|
|
2292
|
+
locale
|
|
2293
|
+
]);
|
|
2294
|
+
const [marks, setMarks] = React.useState();
|
|
2295
|
+
const [unavailable, setUnavailable] = React.useState();
|
|
2296
|
+
React.useEffect(() => {
|
|
2297
|
+
setMarks(void 0);
|
|
2298
|
+
if (!directory || !followMarks) return;
|
|
2299
|
+
return followMarks(directory, setMarks);
|
|
2300
|
+
}, [directory, followMarks]);
|
|
2301
|
+
const [statuses, setStatuses] = React.useState();
|
|
2302
|
+
React.useEffect(() => {
|
|
2303
|
+
if (!directory || !followStatuses) return;
|
|
2304
|
+
return followStatuses(directory, (paths) => setStatuses({
|
|
2305
|
+
directory,
|
|
2306
|
+
paths
|
|
2307
|
+
}));
|
|
2308
|
+
}, [directory, followStatuses]);
|
|
2309
|
+
const [unsaved, setUnsaved] = React.useState();
|
|
2310
|
+
React.useEffect(() => {
|
|
2311
|
+
if (!folder || !directory) return;
|
|
2312
|
+
const update = () => {
|
|
2313
|
+
const paths = folder.unsavedPaths();
|
|
2314
|
+
if (paths) setUnsaved({
|
|
2315
|
+
directory,
|
|
2316
|
+
paths
|
|
2317
|
+
});
|
|
2318
|
+
};
|
|
2319
|
+
let timer;
|
|
2320
|
+
const schedule = () => {
|
|
2321
|
+
clearTimeout(timer);
|
|
2322
|
+
timer = setTimeout(update, 100);
|
|
2323
|
+
};
|
|
2324
|
+
update();
|
|
2325
|
+
const stop = folder.subscribeEdits(schedule);
|
|
2326
|
+
return () => {
|
|
2327
|
+
stop();
|
|
2328
|
+
clearTimeout(timer);
|
|
1033
2329
|
};
|
|
1034
2330
|
}, [
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
2331
|
+
folder,
|
|
2332
|
+
directory,
|
|
2333
|
+
version
|
|
1038
2334
|
]);
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
if (
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
2335
|
+
const [git, setGit] = React.useState();
|
|
2336
|
+
React.useEffect(() => {
|
|
2337
|
+
if (!directory || !followGit) return;
|
|
2338
|
+
return followGit(directory, (actions) => setGit({
|
|
2339
|
+
directory,
|
|
2340
|
+
actions
|
|
2341
|
+
}));
|
|
2342
|
+
}, [directory, followGit]);
|
|
2343
|
+
if (!folder) return null;
|
|
2344
|
+
if (!directory) return /* @__PURE__ */ React.createElement("div", { className: `${prefix}-empty` }, /* @__PURE__ */ React.createElement("style", null, css), /* @__PURE__ */ React.createElement("p", null, message.noFolder), /* @__PURE__ */ React.createElement("button", {
|
|
1048
2345
|
type: "button",
|
|
1049
|
-
onClick: () =>
|
|
1050
|
-
},
|
|
2346
|
+
onClick: () => folder.open(locale !== null && locale !== void 0 ? locale : "en")
|
|
2347
|
+
}, message.open));
|
|
2348
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ProjectFolderExplorer, {
|
|
2349
|
+
directory,
|
|
2350
|
+
locale,
|
|
2351
|
+
descriptions,
|
|
2352
|
+
marks,
|
|
2353
|
+
refreshKey: version,
|
|
2354
|
+
fileStatuses: (statuses === null || statuses === void 0 ? void 0 : statuses.directory) === directory ? statuses.paths : void 0,
|
|
2355
|
+
unsavedPaths: (unsaved === null || unsaved === void 0 ? void 0 : unsaved.directory) === directory ? unsaved.paths : void 0,
|
|
2356
|
+
mutate: (operation) => folder.mutate(directory, operation),
|
|
2357
|
+
isCurrent: () => folder.directory === directory,
|
|
2358
|
+
git: (git === null || git === void 0 ? void 0 : git.directory) === directory ? git.actions : void 0,
|
|
2359
|
+
onOpen: openFile && ((entry) => {
|
|
2360
|
+
const request = createFilePreview(directory, `${keyFor(directory)}/${entry.path}`, entry, locale, readBaseline);
|
|
2361
|
+
setUnavailable(openFile(request) ? void 0 : directory);
|
|
2362
|
+
})
|
|
2363
|
+
}), unavailable === directory && /* @__PURE__ */ React.createElement("p", {
|
|
2364
|
+
className: `${prefix}-status`,
|
|
2365
|
+
role: "status"
|
|
2366
|
+
}, message.unavailable));
|
|
1051
2367
|
}
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
2368
|
+
/**
|
|
2369
|
+
* Renders the explorer of the project folder open for `vm`, for a side panel of the host: its files with what each is
|
|
2370
|
+
* for, and `marks` (such as the Git status) when given. It follows the folder as it opens, closes and saves; with no
|
|
2371
|
+
* folder open it offers Open Project Folder…, and it renders nothing while no project folder is mounted for `vm`.
|
|
2372
|
+
* Pass the same `marks` function across renders, or the marks are followed again.
|
|
2373
|
+
*/
|
|
2374
|
+
function renderProjectFolderExplorer(createElement, { vm, locale = "en", marks, fileStatuses, git, openFile, readBaseline }) {
|
|
2375
|
+
return createElement(FolderView, {
|
|
2376
|
+
vm,
|
|
2377
|
+
locale,
|
|
2378
|
+
marks,
|
|
2379
|
+
fileStatuses,
|
|
2380
|
+
git,
|
|
2381
|
+
openFile,
|
|
2382
|
+
readBaseline
|
|
1057
2383
|
});
|
|
1058
2384
|
}
|
|
1059
|
-
export {
|
|
2385
|
+
export { ProjectFolderExplorer, describeProjectFolder, renderProjectFolderExplorer };
|