@lvce-editor/explorer-view 5.17.0 → 5.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,88 @@
1
+ const toCommandId = key => {
2
+ const dotIndex = key.indexOf('.');
3
+ return key.slice(dotIndex + 1);
4
+ };
5
+ const create$6 = () => {
6
+ const states = Object.create(null);
7
+ const commandMapRef = {};
8
+ return {
9
+ get(uid) {
10
+ return states[uid];
11
+ },
12
+ set(uid, oldState, newState) {
13
+ states[uid] = {
14
+ oldState,
15
+ newState
16
+ };
17
+ },
18
+ dispose(uid) {
19
+ delete states[uid];
20
+ },
21
+ getKeys() {
22
+ return Object.keys(states).map(key => {
23
+ return Number.parseInt(key);
24
+ });
25
+ },
26
+ clear() {
27
+ for (const key of Object.keys(states)) {
28
+ delete states[key];
29
+ }
30
+ },
31
+ wrapCommand(fn) {
32
+ const wrapped = async (uid, ...args) => {
33
+ const {
34
+ oldState,
35
+ newState
36
+ } = states[uid];
37
+ const newerState = await fn(newState, ...args);
38
+ if (oldState === newerState || newState === newerState) {
39
+ return;
40
+ }
41
+ const latest = states[uid];
42
+ states[uid] = {
43
+ oldState: latest.oldState,
44
+ newState: newerState
45
+ };
46
+ };
47
+ return wrapped;
48
+ },
49
+ wrapGetter(fn) {
50
+ const wrapped = (uid, ...args) => {
51
+ const {
52
+ newState
53
+ } = states[uid];
54
+ return fn(newState, ...args);
55
+ };
56
+ return wrapped;
57
+ },
58
+ diff(uid, modules, numbers) {
59
+ const {
60
+ oldState,
61
+ newState
62
+ } = states[uid];
63
+ const diffResult = [];
64
+ for (let i = 0; i < modules.length; i++) {
65
+ const fn = modules[i];
66
+ if (!fn(oldState, newState)) {
67
+ diffResult.push(numbers[i]);
68
+ }
69
+ }
70
+ return diffResult;
71
+ },
72
+ getCommandIds() {
73
+ const keys = Object.keys(commandMapRef);
74
+ const ids = keys.map(toCommandId);
75
+ return ids;
76
+ },
77
+ registerCommands(commandMap) {
78
+ Object.assign(commandMapRef, commandMap);
79
+ }
80
+ };
81
+ };
82
+ const terminate = () => {
83
+ globalThis.close();
84
+ };
85
+
1
86
  const normalizeLine = line => {
2
87
  if (line.startsWith('Error: ')) {
3
88
  return line.slice('Error: '.length);
@@ -54,6 +139,64 @@ class VError extends Error {
54
139
  }
55
140
  }
56
141
 
142
+ const CreateFolder$1 = 1;
143
+ const CreateFile$1 = 2;
144
+ const Copy$1 = 3;
145
+ const Rename$2 = 4;
146
+ const Remove = 5;
147
+
148
+ const Text = 12;
149
+
150
+ const Button$3 = 'event.button';
151
+ const ClientX = 'event.clientX';
152
+ const ClientY = 'event.clientY';
153
+ const CtrlKey = 'event.ctrlKey';
154
+ const DataTransferFiles = 'event.dataTransfer.files';
155
+ const DataTransferFiles2 = 'event.dataTransfer.files2';
156
+ const DefaultPrevented = 'event.defaultPrevented';
157
+ const DeltaMode = 'event.deltaMode';
158
+ const DeltaY = 'event.deltaY';
159
+ const EventTargetClassName = 'event.target.className';
160
+ const IsTrusted = 'event.isTrusted';
161
+ const ShiftKey = 'event.shiftKey';
162
+ const TargetName = 'event.target.name';
163
+ const TargetValue = 'event.target.value';
164
+
165
+ const Enter = 3;
166
+ const Escape = 8;
167
+ const Space = 9;
168
+ const End = 255;
169
+ const Home = 12;
170
+ const LeftArrow = 13;
171
+ const UpArrow = 14;
172
+ const RightArrow = 15;
173
+ const DownArrow = 16;
174
+ const Delete$1 = 18;
175
+ const KeyA = 29;
176
+ const KeyC = 31;
177
+ const KeyV = 50;
178
+ const KeyX = 52;
179
+ const F2 = 58;
180
+ const Star = 131;
181
+
182
+ const CtrlCmd = 1 << 11 >>> 0;
183
+ const Shift = 1 << 10 >>> 0;
184
+ const Alt = 1 << 9 >>> 0;
185
+
186
+ const FileSystemWorker$1 = 209;
187
+ const IconThemeWorker = 7009;
188
+ const RendererWorker = 1;
189
+ const SourceControlWorker = 66;
190
+
191
+ const FocusElementByName = 'Viewlet.focusElementByName';
192
+ const FocusSelector = 'Viewlet.focusSelector';
193
+ const SetCss = 'Viewlet.setCss';
194
+ const SetDom2 = 'Viewlet.setDom2';
195
+ const SetFocusContext = 'Viewlet.setFocusContext';
196
+
197
+ const FocusExplorer = 13;
198
+ const FocusExplorerEditBox = 14;
199
+
57
200
  class AssertionError extends Error {
58
201
  constructor(message) {
59
202
  super(message);
@@ -529,7 +672,7 @@ const callbacks = Object.create(null);
529
672
  const get$2 = id => {
530
673
  return callbacks[id];
531
674
  };
532
- const remove$2 = id => {
675
+ const remove$3 = id => {
533
676
  delete callbacks[id];
534
677
  };
535
678
  class JsonRpcError extends Error {
@@ -682,7 +825,7 @@ const resolve = (id, response) => {
682
825
  return;
683
826
  }
684
827
  fn(response);
685
- remove$2(id);
828
+ remove$3(id);
686
829
  };
687
830
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
688
831
  const getErrorType = prettyError => {
@@ -975,6 +1118,53 @@ const listen$1 = async (module, options) => {
975
1118
  const ipc = module.wrap(rawIpc);
976
1119
  return ipc;
977
1120
  };
1121
+
1122
+ /* eslint-disable @typescript-eslint/no-misused-promises */
1123
+
1124
+ const createSharedLazyRpc = factory => {
1125
+ let rpcPromise;
1126
+ const getOrCreate = () => {
1127
+ if (!rpcPromise) {
1128
+ rpcPromise = factory();
1129
+ }
1130
+ return rpcPromise;
1131
+ };
1132
+ return {
1133
+ async dispose() {
1134
+ const rpc = await getOrCreate();
1135
+ await rpc.dispose();
1136
+ },
1137
+ async invoke(method, ...params) {
1138
+ const rpc = await getOrCreate();
1139
+ return rpc.invoke(method, ...params);
1140
+ },
1141
+ async invokeAndTransfer(method, ...params) {
1142
+ const rpc = await getOrCreate();
1143
+ return rpc.invokeAndTransfer(method, ...params);
1144
+ },
1145
+ async send(method, ...params) {
1146
+ const rpc = await getOrCreate();
1147
+ rpc.send(method, ...params);
1148
+ }
1149
+ };
1150
+ };
1151
+ const create$i = async ({
1152
+ commandMap,
1153
+ isMessagePortOpen,
1154
+ send
1155
+ }) => {
1156
+ return createSharedLazyRpc(() => {
1157
+ return create$2({
1158
+ commandMap,
1159
+ isMessagePortOpen,
1160
+ send
1161
+ });
1162
+ });
1163
+ };
1164
+ const LazyTransferMessagePortRpcParent = {
1165
+ __proto__: null,
1166
+ create: create$i
1167
+ };
978
1168
  const create$4 = async ({
979
1169
  commandMap,
980
1170
  isMessagePortOpen = true,
@@ -992,7 +1182,7 @@ const create$4 = async ({
992
1182
  messagePort.start();
993
1183
  return rpc;
994
1184
  };
995
- const create$2$1 = async ({
1185
+ const create$2 = async ({
996
1186
  commandMap,
997
1187
  isMessagePortOpen,
998
1188
  send
@@ -1008,10 +1198,6 @@ const create$2$1 = async ({
1008
1198
  messagePort: port2
1009
1199
  });
1010
1200
  };
1011
- const TransferMessagePortRpcParent = {
1012
- __proto__: null,
1013
- create: create$2$1
1014
- };
1015
1201
  const create$1$1 = async ({
1016
1202
  commandMap
1017
1203
  }) => {
@@ -1046,35 +1232,6 @@ const createMockRpc = ({
1046
1232
  return mockRpc;
1047
1233
  };
1048
1234
 
1049
- const Button$3 = 'event.button';
1050
- const ClientX = 'event.clientX';
1051
- const ClientY = 'event.clientY';
1052
- const CtrlKey = 'event.ctrlKey';
1053
- const DataTransferFiles = 'event.dataTransfer.files';
1054
- const DataTransferFiles2 = 'event.dataTransfer.files2';
1055
- const DefaultPrevented = 'event.defaultPrevented';
1056
- const DeltaMode = 'event.deltaMode';
1057
- const DeltaY = 'event.deltaY';
1058
- const EventTargetClassName = 'event.target.className';
1059
- const IsTrusted = 'event.isTrusted';
1060
- const ShiftKey = 'event.shiftKey';
1061
- const TargetName = 'event.target.name';
1062
- const TargetValue = 'event.target.value';
1063
-
1064
- const FileSystemWorker$1 = 209;
1065
- const IconThemeWorker = 7009;
1066
- const RendererWorker = 1;
1067
- const SourceControlWorker = 66;
1068
-
1069
- const FocusElementByName = 'Viewlet.focusElementByName';
1070
- const FocusSelector = 'Viewlet.focusSelector';
1071
- const SetCss = 'Viewlet.setCss';
1072
- const SetDom2 = 'Viewlet.setDom2';
1073
- const SetFocusContext = 'Viewlet.setFocusContext';
1074
-
1075
- const FocusExplorer = 13;
1076
- const FocusExplorerEditBox = 14;
1077
-
1078
1235
  const rpcs = Object.create(null);
1079
1236
  const set$6 = (id, rpc) => {
1080
1237
  rpcs[id] = rpc;
@@ -1082,8 +1239,12 @@ const set$6 = (id, rpc) => {
1082
1239
  const get$1 = id => {
1083
1240
  return rpcs[id];
1084
1241
  };
1242
+ const remove$2 = id => {
1243
+ delete rpcs[id];
1244
+ };
1085
1245
 
1086
- const create$2 = rpcId => {
1246
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
1247
+ const create$1 = rpcId => {
1087
1248
  return {
1088
1249
  async dispose() {
1089
1250
  const rpc = get$1(rpcId);
@@ -1101,6 +1262,18 @@ const create$2 = rpcId => {
1101
1262
  // @ts-ignore
1102
1263
  return rpc.invokeAndTransfer(method, ...params);
1103
1264
  },
1265
+ registerMockRpc(commandMap) {
1266
+ const mockRpc = createMockRpc({
1267
+ commandMap
1268
+ });
1269
+ set$6(rpcId, mockRpc);
1270
+ // @ts-ignore
1271
+ mockRpc[Symbol.dispose] = () => {
1272
+ remove$2(rpcId);
1273
+ };
1274
+ // @ts-ignore
1275
+ return mockRpc;
1276
+ },
1104
1277
  set(rpc) {
1105
1278
  set$6(rpcId, rpc);
1106
1279
  }
@@ -1111,8 +1284,9 @@ const {
1111
1284
  dispose,
1112
1285
  invoke: invoke$4,
1113
1286
  invokeAndTransfer: invokeAndTransfer$1,
1287
+ registerMockRpc,
1114
1288
  set: set$5
1115
- } = create$2(FileSystemWorker$1);
1289
+ } = create$1(FileSystemWorker$1);
1116
1290
  const remove$1 = async dirent => {
1117
1291
  return invoke$4('FileSystem.remove', dirent);
1118
1292
  };
@@ -1120,7 +1294,6 @@ const readDirWithFileTypes$1 = async uri => {
1120
1294
  return invoke$4('FileSystem.readDirWithFileTypes', uri);
1121
1295
  };
1122
1296
  const getPathSeparator$2 = async root => {
1123
- // @ts-ignore
1124
1297
  return invoke$4('FileSystem.getPathSeparator', root);
1125
1298
  };
1126
1299
  const getRealPath$1 = async path => {
@@ -1148,27 +1321,22 @@ const copy$2 = async (oldUri, newUri) => {
1148
1321
  return invoke$4('FileSystem.copy', oldUri, newUri);
1149
1322
  };
1150
1323
  const exists = async uri => {
1151
- // @ts-ignore
1152
1324
  return invoke$4('FileSystem.exists', uri);
1153
1325
  };
1154
1326
  const getFolderSize = async uri => {
1155
- // @ts-ignore
1156
1327
  return invoke$4('FileSystem.getFolderSize', uri);
1157
1328
  };
1158
1329
  const readFileAsBlob = async uri => {
1159
- // @ts-ignore
1160
1330
  return invoke$4('FileSystem.readFileAsBlob', uri);
1161
1331
  };
1162
1332
  const appendFile = async (uri, text) => {
1163
- // @ts-ignore
1164
1333
  return invoke$4('FileSystem.appendFile', uri, text);
1165
1334
  };
1166
- const registerMockRpc = commandMap => {
1167
- const mockRpc = createMockRpc({
1168
- commandMap
1169
- });
1170
- set$5(mockRpc);
1171
- return mockRpc;
1335
+ const watchFile = async (watchId, uri, rpcId) => {
1336
+ await invoke$4('FileSystem.watchFile', watchId, uri, rpcId);
1337
+ };
1338
+ const unwatchFile = async watchId => {
1339
+ await invoke$4('FileSystem.unwatchFile', watchId);
1172
1340
  };
1173
1341
 
1174
1342
  const FileSystemWorker = {
@@ -1192,13 +1360,15 @@ const FileSystemWorker = {
1192
1360
  rename: rename$2,
1193
1361
  set: set$5,
1194
1362
  stat: stat$1,
1363
+ unwatchFile,
1364
+ watchFile,
1195
1365
  writeFile: writeFile$1
1196
1366
  };
1197
1367
 
1198
1368
  const {
1199
1369
  invoke: invoke$3,
1200
1370
  set: set$4
1201
- } = create$2(IconThemeWorker);
1371
+ } = create$1(IconThemeWorker);
1202
1372
  const getIcons = async iconRequests => {
1203
1373
  // @ts-ignore
1204
1374
  return invoke$3('IconTheme.getIcons', iconRequests);
@@ -1208,7 +1378,7 @@ const {
1208
1378
  invoke: invoke$2,
1209
1379
  invokeAndTransfer,
1210
1380
  set: set$3
1211
- } = create$2(RendererWorker);
1381
+ } = create$1(RendererWorker);
1212
1382
  const showContextMenu2 = async (uid, menuId, x, y, args) => {
1213
1383
  number(uid);
1214
1384
  number(menuId);
@@ -1217,6 +1387,10 @@ const showContextMenu2 = async (uid, menuId, x, y, args) => {
1217
1387
  // @ts-ignore
1218
1388
  await invoke$2('ContextMenu.show2', uid, menuId, x, y, args);
1219
1389
  };
1390
+ const getFileHandles$1 = async fileIds => {
1391
+ const files = await invoke$2('FileSystemHandle.getFileHandles', fileIds);
1392
+ return files;
1393
+ };
1220
1394
  const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
1221
1395
  const command = 'IconTheme.handleMessagePort';
1222
1396
  // @ts-ignore
@@ -1244,98 +1418,7 @@ const sendMessagePortToSourceControlWorker = async port => {
1244
1418
  const {
1245
1419
  invoke: invoke$1,
1246
1420
  set: set$2
1247
- } = create$2(SourceControlWorker);
1248
-
1249
- const toCommandId = key => {
1250
- const dotIndex = key.indexOf('.');
1251
- return key.slice(dotIndex + 1);
1252
- };
1253
- const create$1 = () => {
1254
- const states = Object.create(null);
1255
- const commandMapRef = {};
1256
- return {
1257
- get(uid) {
1258
- return states[uid];
1259
- },
1260
- set(uid, oldState, newState) {
1261
- states[uid] = {
1262
- oldState,
1263
- newState
1264
- };
1265
- },
1266
- dispose(uid) {
1267
- delete states[uid];
1268
- },
1269
- getKeys() {
1270
- return Object.keys(states).map(key => {
1271
- return Number.parseInt(key);
1272
- });
1273
- },
1274
- clear() {
1275
- for (const key of Object.keys(states)) {
1276
- delete states[key];
1277
- }
1278
- },
1279
- wrapCommand(fn) {
1280
- const wrapped = async (uid, ...args) => {
1281
- const {
1282
- oldState,
1283
- newState
1284
- } = states[uid];
1285
- const newerState = await fn(newState, ...args);
1286
- if (oldState === newerState || newState === newerState) {
1287
- return;
1288
- }
1289
- const latest = states[uid];
1290
- states[uid] = {
1291
- oldState: latest.oldState,
1292
- newState: newerState
1293
- };
1294
- };
1295
- return wrapped;
1296
- },
1297
- wrapGetter(fn) {
1298
- const wrapped = (uid, ...args) => {
1299
- const {
1300
- newState
1301
- } = states[uid];
1302
- return fn(newState, ...args);
1303
- };
1304
- return wrapped;
1305
- },
1306
- diff(uid, modules, numbers) {
1307
- const {
1308
- oldState,
1309
- newState
1310
- } = states[uid];
1311
- const diffResult = [];
1312
- for (let i = 0; i < modules.length; i++) {
1313
- const fn = modules[i];
1314
- if (!fn(oldState, newState)) {
1315
- diffResult.push(numbers[i]);
1316
- }
1317
- }
1318
- return diffResult;
1319
- },
1320
- getCommandIds() {
1321
- const keys = Object.keys(commandMapRef);
1322
- const ids = keys.map(toCommandId);
1323
- return ids;
1324
- },
1325
- registerCommands(commandMap) {
1326
- Object.assign(commandMapRef, commandMap);
1327
- }
1328
- };
1329
- };
1330
- const terminate = () => {
1331
- globalThis.close();
1332
- };
1333
-
1334
- const CreateFolder$1 = 1;
1335
- const CreateFile$1 = 2;
1336
- const Copy$1 = 3;
1337
- const Rename$2 = 4;
1338
- const Remove = 5;
1421
+ } = create$1(SourceControlWorker);
1339
1422
 
1340
1423
  // TODO use direct connection
1341
1424
  const invoke = async (method, ...params) => {
@@ -1815,7 +1898,7 @@ const Copy = 'Copy';
1815
1898
  const CopyPath = 'Copy Path';
1816
1899
  const CopyRelativePath = 'Copy Relative Path';
1817
1900
  const Cut = 'Cut';
1818
- const Delete$1 = 'Delete';
1901
+ const Delete = 'Delete';
1819
1902
  const FileNameCannotStartWithSlash = 'A file or folder name cannot start with a slash.';
1820
1903
  const FileOrFolderAlreadyExists = 'A file or folder **{PH1}** already exists at this location. Please choose a different name.';
1821
1904
  const FileOrFolderNameMustBeProvider = 'A file or folder name must be provided.';
@@ -1864,7 +1947,7 @@ const rename = () => {
1864
1947
  return i18nString(Rename);
1865
1948
  };
1866
1949
  const deleteItem = () => {
1867
- return i18nString(Delete$1);
1950
+ return i18nString(Delete);
1868
1951
  };
1869
1952
  const refresh$1 = () => {
1870
1953
  return i18nString(RefreshExplorer);
@@ -2438,29 +2521,6 @@ const Viewlet = 'Viewlet';
2438
2521
  const Welcome = 'Welcome';
2439
2522
  const WelcomeMessage = 'WelcomeMessage';
2440
2523
 
2441
- const Text = 12;
2442
-
2443
- const Enter = 3;
2444
- const Escape = 8;
2445
- const Space = 9;
2446
- const End = 255;
2447
- const Home = 12;
2448
- const LeftArrow = 13;
2449
- const UpArrow = 14;
2450
- const RightArrow = 15;
2451
- const DownArrow = 16;
2452
- const Delete = 18;
2453
- const KeyA = 29;
2454
- const KeyC = 31;
2455
- const KeyV = 50;
2456
- const KeyX = 52;
2457
- const F2 = 58;
2458
- const Star = 131;
2459
-
2460
- const CtrlCmd = 1 << 11 >>> 0;
2461
- const Shift = 1 << 10 >>> 0;
2462
- const Alt = 1 << 9 >>> 0;
2463
-
2464
2524
  const mergeClassNames = (...classNames) => {
2465
2525
  return classNames.filter(Boolean).join(' ');
2466
2526
  };
@@ -2474,9 +2534,9 @@ const position = (x, y) => {
2474
2534
 
2475
2535
  const text = data => {
2476
2536
  return {
2477
- type: Text,
2537
+ childCount: 0,
2478
2538
  text: data,
2479
- childCount: 0
2539
+ type: Text
2480
2540
  };
2481
2541
  };
2482
2542
 
@@ -2576,7 +2636,7 @@ const {
2576
2636
  registerCommands,
2577
2637
  set,
2578
2638
  wrapGetter
2579
- } = create$1();
2639
+ } = create$6();
2580
2640
  const wrapListItemCommand = fn => {
2581
2641
  const wrappedCommand = async (id, ...args) => {
2582
2642
  const {
@@ -3076,7 +3136,7 @@ const getKeyBindings = () => {
3076
3136
  when: FocusExplorerEditBox
3077
3137
  }, {
3078
3138
  command: 'Explorer.removeDirent',
3079
- key: Delete,
3139
+ key: Delete$1,
3080
3140
  when: FocusExplorer
3081
3141
  }, {
3082
3142
  command: 'Explorer.focusNone',
@@ -3545,21 +3605,25 @@ const getFittingIndex = (dirents, startIndex) => {
3545
3605
  const newDirent = async (state, editingType) => {
3546
3606
  // TODO do it like vscode, select position between folders and files
3547
3607
  const {
3608
+ editingIndex,
3548
3609
  focusedIndex,
3549
3610
  items,
3550
3611
  root
3551
3612
  } = state;
3613
+ if (editingIndex !== -1) {
3614
+ return state;
3615
+ }
3552
3616
  const index = getFittingIndex(items, focusedIndex);
3553
3617
  const direntType = getNewDirentType(editingType);
3554
3618
  const newDirents = await getNewDirentsForNewDirent(items, index, direntType, root);
3555
- const editingIndex = newDirents.findIndex(item => item.type === EditingFile || item.type === EditingFolder);
3619
+ const newEditingIndex = newDirents.findIndex(item => item.type === EditingFile || item.type === EditingFolder);
3556
3620
  return {
3557
3621
  ...state,
3558
- editingIndex,
3622
+ editingIndex: newEditingIndex,
3559
3623
  editingType,
3560
3624
  editingValue: '',
3561
3625
  focus: Input$1,
3562
- focusedIndex: editingIndex,
3626
+ focusedIndex: newEditingIndex,
3563
3627
  items: newDirents
3564
3628
  };
3565
3629
  };
@@ -3934,17 +3998,16 @@ const handleContextMenuAtIndex = async (state, index, x, y) => {
3934
3998
  return newState;
3935
3999
  };
3936
4000
 
3937
- const handleContextMenuKeyboard = async state => {
4001
+ const handleContextMenuKeyboard = async (state, index = state.focusedIndex) => {
3938
4002
  const {
3939
- focusedIndex,
3940
4003
  itemHeight,
3941
4004
  minLineY,
3942
4005
  x,
3943
4006
  y
3944
4007
  } = state;
3945
4008
  const menuX = x;
3946
- const menuY = y + (focusedIndex - minLineY + 1) * itemHeight;
3947
- return handleContextMenuAtIndex(state, focusedIndex, menuX, menuY);
4009
+ const menuY = y + (index - minLineY + 1) * itemHeight;
4010
+ return handleContextMenuAtIndex(state, index, menuX, menuY);
3948
4011
  };
3949
4012
 
3950
4013
  const handleContextMenuMouseAt = async (state, x, y) => {
@@ -4013,6 +4076,14 @@ const handleCut = async state => {
4013
4076
  };
4014
4077
  };
4015
4078
 
4079
+ const handleDoubleClick = async (state, eventX, eventY) => {
4080
+ const index = getIndexFromPosition(state, eventX, eventY);
4081
+ if (index !== -1) {
4082
+ return state;
4083
+ }
4084
+ return newFile(state);
4085
+ };
4086
+
4016
4087
  const handleDragEnd = state => {
4017
4088
  return {
4018
4089
  ...state,
@@ -4128,7 +4199,8 @@ const isFileHandle = fileHandle => {
4128
4199
 
4129
4200
  const createUploadTree = async (root, fileHandles) => {
4130
4201
  const uploadTree = Object.create(null);
4131
- for (const fileHandle of fileHandles) {
4202
+ const normalized = fileHandles.filter(Boolean);
4203
+ for (const fileHandle of normalized) {
4132
4204
  const {
4133
4205
  name
4134
4206
  } = fileHandle;
@@ -4170,6 +4242,9 @@ const getFileOperations = (root, uploadTree) => {
4170
4242
  };
4171
4243
 
4172
4244
  const uploadFileSystemHandles = async (root, pathSeparator, fileSystemHandles) => {
4245
+ if (fileSystemHandles.length === 0) {
4246
+ return true;
4247
+ }
4173
4248
  const uploadTree = await createUploadTree(root, fileSystemHandles);
4174
4249
  const fileOperations = getFileOperations(root, uploadTree);
4175
4250
  await applyFileOperations(fileOperations);
@@ -4295,14 +4370,7 @@ const handleDropIntoFolder = async (state, dirent, index, fileHandles, files, pa
4295
4370
  items,
4296
4371
  pathSeparator
4297
4372
  } = state;
4298
- // @ts-ignore
4299
- for (const file of fileHandles) {
4300
- // TODO path basename
4301
- const baseName = file.name;
4302
- const to = dirent.path + pathSeparator + baseName;
4303
- // @ts-ignore
4304
- await copy$1(file, to);
4305
- }
4373
+ await uploadFileSystemHandles(dirent.path, '/', fileHandles);
4306
4374
  const childDirents = await getChildDirents(pathSeparator, dirent.path, dirent.depth);
4307
4375
  const mergedDirents = getMergedDirents(items, index, dirent, childDirents);
4308
4376
  // TODO update maxlineY
@@ -4357,7 +4425,10 @@ const getFileArray = fileList => {
4357
4425
  };
4358
4426
 
4359
4427
  const getFileHandles = async fileIds => {
4360
- const files = await invoke$2('FileSystemHandle.getFileHandles', fileIds);
4428
+ if (fileIds.length === 0) {
4429
+ return [];
4430
+ }
4431
+ const files = await getFileHandles$1(fileIds);
4361
4432
  return files;
4362
4433
  };
4363
4434
 
@@ -4379,9 +4450,12 @@ const getFilePaths = async (files, platform) => {
4379
4450
 
4380
4451
  const handleDrop = async (state, x, y, fileIds, fileList) => {
4381
4452
  try {
4453
+ const {
4454
+ platform
4455
+ } = state;
4382
4456
  const files = getFileArray(fileList);
4383
4457
  const fileHandles = await getFileHandles(fileIds);
4384
- const paths = await getFilePaths(files, state.platform);
4458
+ const paths = await getFilePaths(files, platform);
4385
4459
  const index = getIndexFromPosition(state, x, y);
4386
4460
  const fn = getDropHandler(index);
4387
4461
  const result = await fn(state, fileHandles, files, paths, index);
@@ -5043,75 +5117,8 @@ const handleWorkspaceRefresh = async state => {
5043
5117
  return refresh(state);
5044
5118
  };
5045
5119
 
5046
- const sendMessagePortToFileSystemWorker = async port => {
5047
- await sendMessagePortToFileSystemWorker$1(port, 0);
5048
- };
5049
-
5050
- const createFileSystemWorkerRpc = async () => {
5051
- try {
5052
- const rpc = await TransferMessagePortRpcParent.create({
5053
- commandMap: {},
5054
- send: sendMessagePortToFileSystemWorker
5055
- });
5056
- return rpc;
5057
- } catch (error) {
5058
- throw new VError(error, `Failed to create file system worker rpc`);
5059
- }
5060
- };
5061
-
5062
- const initializeFileSystemWorker = async () => {
5063
- const rpc = await createFileSystemWorkerRpc();
5064
- set$1(rpc);
5065
- };
5066
-
5067
- const send$1 = port => {
5068
- return sendMessagePortToIconThemeWorker(port, 0);
5069
- };
5070
- const createIconThemeWorkerRpc = async () => {
5071
- try {
5072
- const rpc = await TransferMessagePortRpcParent.create({
5073
- commandMap: {},
5074
- send: send$1
5075
- });
5076
- return rpc;
5077
- } catch (error) {
5078
- throw new VError(error, `Failed to create icon theme worker rpc`);
5079
- }
5080
- };
5081
-
5082
- const initializeIconThemeWorker = async () => {
5083
- const rpc = await createIconThemeWorkerRpc();
5084
- set$4(rpc);
5085
- };
5086
-
5087
- const send = port => {
5088
- // @ts-ignore
5089
- return sendMessagePortToSourceControlWorker(port);
5090
- };
5091
- const createSourceControlWorkerRpc = async () => {
5092
- try {
5093
- const rpc = await TransferMessagePortRpcParent.create({
5094
- commandMap: {},
5095
- send
5096
- });
5097
- return rpc;
5098
- } catch (error) {
5099
- throw new VError(error, `Failed to create source control worker rpc`);
5100
- }
5101
- };
5102
-
5103
- const initializeSourceControlWorker = async () => {
5104
- try {
5105
- const rpc = await createSourceControlWorkerRpc();
5106
- // TODO
5107
- set$2(rpc);
5108
- } catch {
5109
- // ignore
5110
- }
5111
- };
5112
-
5113
5120
  const initialize = async () => {
5114
- await Promise.all([initializeFileSystemWorker(), initializeIconThemeWorker(), initializeSourceControlWorker()]);
5121
+ // this function is not needed anymore
5115
5122
  };
5116
5123
 
5117
5124
  const getContainingFolder = (root, dirents, focusedIndex, pathSeparator) => {
@@ -5342,20 +5349,22 @@ const getDragData = urls => {
5342
5349
  data,
5343
5350
  type: 'text/plain'
5344
5351
  }];
5345
- // @ts-ignore
5346
- dragData.label = getDragLabel(urls);
5347
- return dragData;
5352
+ return {
5353
+ items: dragData,
5354
+ label: getDragLabel(urls)
5355
+ };
5348
5356
  };
5349
5357
 
5350
5358
  const renderDragData = (oldState, newState) => {
5351
5359
  const {
5352
5360
  focusedIndex,
5353
- items
5361
+ items,
5362
+ uid
5354
5363
  } = newState;
5355
5364
  const selected = items.filter((item, index) => item.selected || index === focusedIndex);
5356
5365
  const urls = selected.map(item => item.path);
5357
5366
  const dragData = getDragData(urls);
5358
- return ['Viewlet.setDragData', newState.uid, dragData];
5367
+ return ['Viewlet.setDragData', uid, dragData];
5359
5368
  };
5360
5369
 
5361
5370
  const renderEditingSelection = (oldState, newState) => {
@@ -5431,6 +5440,7 @@ const HandleListBlur = 11;
5431
5440
  const HandleListFocus = 12;
5432
5441
  const HandlePointerDown = 14;
5433
5442
  const HandleWheel = 15;
5443
+ const HandleDoubleClick = 16;
5434
5444
 
5435
5445
  const getExplorerWelcomeVirtualDom = isWide => {
5436
5446
  return [{
@@ -5588,6 +5598,7 @@ const getListItemsVirtualDom = (visibleItems, focusedIndex, focused, dropTargets
5588
5598
  onBlur: HandleListBlur,
5589
5599
  onClick: HandleClick,
5590
5600
  onContextMenu: HandleContextMenu,
5601
+ onDblClick: HandleDoubleClick,
5591
5602
  onDragEnd: HandleDragEnd,
5592
5603
  onDragLeave: HandleDragLeave,
5593
5604
  onDragOver: HandleDragOver,
@@ -5853,6 +5864,9 @@ const renderEventListeners = () => {
5853
5864
  }, {
5854
5865
  name: HandlePointerDown,
5855
5866
  params: ['handlePointerDown', Button$3, ClientX, ClientY]
5867
+ }, {
5868
+ name: HandleDoubleClick,
5869
+ params: ['handleDoubleClick', ClientX, ClientY]
5856
5870
  }, {
5857
5871
  name: HandleEditingInput,
5858
5872
  params: ['updateEditingValue', TargetValue]
@@ -6211,12 +6225,14 @@ const commandMap = {
6211
6225
  'Explorer.handleContextMenuKeyboard': wrapListItemCommand(handleContextMenuKeyboard),
6212
6226
  'Explorer.handleCopy': wrapListItemCommand(handleCopy),
6213
6227
  'Explorer.handleCut': wrapListItemCommand(handleCut),
6228
+ 'Explorer.handleDoubleClick': wrapListItemCommand(handleDoubleClick),
6214
6229
  'Explorer.handleDragEnd': wrapListItemCommand(handleDragEnd),
6215
6230
  'Explorer.handleDragLeave': wrapListItemCommand(handleDragLeave),
6216
6231
  'Explorer.handleDragOver': wrapListItemCommand(handleDragOver),
6217
6232
  'Explorer.handleDragOverIndex': wrapListItemCommand(handleDragOverIndex),
6218
6233
  'Explorer.handleDragStart': wrapListItemCommand(handleDragStart),
6219
6234
  'Explorer.handleDrop': wrapListItemCommand(handleDrop),
6235
+ 'Explorer.handleDropIndex': wrapListItemCommand(handleDropIndex),
6220
6236
  'Explorer.handleEscape': wrapListItemCommand(handleEscape),
6221
6237
  'Explorer.handleFocus': wrapListItemCommand(handleFocus),
6222
6238
  'Explorer.handleIconThemeChange': wrapListItemCommand(handleIconThemeChange),
@@ -6256,14 +6272,85 @@ const commandMap = {
6256
6272
  'Explorer.updateIcons': wrapListItemCommand(updateIcons)
6257
6273
  };
6258
6274
 
6259
- const listen = async () => {
6260
- registerCommands(commandMap);
6275
+ const sendMessagePortToFileSystemWorker = async port => {
6276
+ await sendMessagePortToFileSystemWorker$1(port, 0);
6277
+ };
6278
+
6279
+ const createFileSystemWorkerRpc = async () => {
6280
+ try {
6281
+ const rpc = await LazyTransferMessagePortRpcParent.create({
6282
+ commandMap: {},
6283
+ send: sendMessagePortToFileSystemWorker
6284
+ });
6285
+ return rpc;
6286
+ } catch (error) {
6287
+ throw new VError(error, `Failed to create file system worker rpc`);
6288
+ }
6289
+ };
6290
+
6291
+ const initializeFileSystemWorker = async () => {
6292
+ const rpc = await createFileSystemWorkerRpc();
6293
+ set$1(rpc);
6294
+ };
6295
+
6296
+ const send$1 = port => {
6297
+ return sendMessagePortToIconThemeWorker(port, 0);
6298
+ };
6299
+ const createIconThemeWorkerRpc = async () => {
6300
+ try {
6301
+ const rpc = await LazyTransferMessagePortRpcParent.create({
6302
+ commandMap: {},
6303
+ send: send$1
6304
+ });
6305
+ return rpc;
6306
+ } catch (error) {
6307
+ throw new VError(error, `Failed to create icon theme worker rpc`);
6308
+ }
6309
+ };
6310
+
6311
+ const initializeIconThemeWorker = async () => {
6312
+ const rpc = await createIconThemeWorkerRpc();
6313
+ set$4(rpc);
6314
+ };
6315
+
6316
+ const initializeRendererWorker = async () => {
6261
6317
  const rpc = await WebWorkerRpcClient.create({
6262
6318
  commandMap: commandMap
6263
6319
  });
6264
6320
  set$3(rpc);
6265
6321
  };
6266
6322
 
6323
+ const send = port => {
6324
+ // @ts-ignore
6325
+ return sendMessagePortToSourceControlWorker(port);
6326
+ };
6327
+ const createSourceControlWorkerRpc = async () => {
6328
+ try {
6329
+ const rpc = await LazyTransferMessagePortRpcParent.create({
6330
+ commandMap: {},
6331
+ send
6332
+ });
6333
+ return rpc;
6334
+ } catch (error) {
6335
+ throw new VError(error, `Failed to create source control worker rpc`);
6336
+ }
6337
+ };
6338
+
6339
+ const initializeSourceControlWorker = async () => {
6340
+ try {
6341
+ const rpc = await createSourceControlWorkerRpc();
6342
+ // TODO
6343
+ set$2(rpc);
6344
+ } catch {
6345
+ // ignore
6346
+ }
6347
+ };
6348
+
6349
+ const listen = async () => {
6350
+ registerCommands(commandMap);
6351
+ await Promise.all([initializeRendererWorker(), initializeFileSystemWorker(), initializeIconThemeWorker(), initializeSourceControlWorker()]);
6352
+ };
6353
+
6267
6354
  const main = async () => {
6268
6355
  await listen();
6269
6356
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "5.17.0",
3
+ "version": "5.19.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",