@lvce-editor/explorer-view 7.32.0 → 7.33.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.
@@ -1413,10 +1413,7 @@ const {
1413
1413
  invoke: invoke$6,
1414
1414
  set: set$9
1415
1415
  } = create$2(DragAndDropWorker);
1416
- const getDroppedItems$1 = async (itemIds, isElectron) => {
1417
- return invoke$6('DragAndDrop.getDroppedItems', itemIds, isElectron);
1418
- };
1419
- const getDroppedItemsByDropId = async (dropId, isElectron) => {
1416
+ const getDroppedItemsByDropId$1 = async (dropId, isElectron) => {
1420
1417
  return invoke$6('DragAndDrop.getDroppedItemsByDropId', dropId, isElectron);
1421
1418
  };
1422
1419
  const discardDrop = async dropId => {
@@ -1459,6 +1456,9 @@ const showContextMenu2 = async (uid, menuId, x, y, args) => {
1459
1456
  number(y);
1460
1457
  await invoke$3('ContextMenu.show2', uid, menuId, x, y, args);
1461
1458
  };
1459
+ const getFileHandles = async fileIds => {
1460
+ return invoke$3('FileHandles.get', fileIds);
1461
+ };
1462
1462
  const sendMessagePortToDialogWorker = async port => {
1463
1463
  const command = 'HandleMessagePort.handleMessagePort';
1464
1464
  await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToDialogWorker', port, command);
@@ -1780,9 +1780,6 @@ const readDirWithFileTypes = async uri => {
1780
1780
  const readFile = async uri => {
1781
1781
  return invoke$1('FileSystem.readFile', uri);
1782
1782
  };
1783
- const getPathSeparator$1 = async root => {
1784
- return invoke$1('FileSystem.getPathSeparator', root);
1785
- };
1786
1783
  const isReadonly = async root => {
1787
1784
  return invoke$1('FileSystem.isReadonly', root);
1788
1785
  };
@@ -5859,10 +5856,6 @@ const getFriendlyErrorMessage = (errorMessage, errorCode) => {
5859
5856
  }
5860
5857
  };
5861
5858
 
5862
- const getPathSeparator = async root => {
5863
- return getPathSeparator$1(root);
5864
- };
5865
-
5866
5859
  const getRestoredDeltaY = savedState => {
5867
5860
  if (savedState && typeof savedState.deltaY === 'number') {
5868
5861
  return savedState.deltaY;
@@ -6054,10 +6047,8 @@ const loadContent = async (state, savedState) => {
6054
6047
  const root = getSavedRoot(savedState, workspacePath);
6055
6048
  const expandedPaths = getExpandedPaths(savedState, root, currentRoot, currentExpandedPaths, preserveExpandState);
6056
6049
  try {
6057
- // TODO path separator could be restored from saved state
6058
- const [pathSeparator, isReadonly$1] = await Promise.all([getPathSeparator(root),
6059
- // TODO only load path separator once
6060
- root === '' ? false : isReadonly(root)]);
6050
+ const pathSeparator = Slash;
6051
+ const isReadonly$1 = root === '' ? false : await isReadonly(root);
6061
6052
  const restoredDirents = await restoreExpandedState(expandedPaths, root, pathSeparator, excluded);
6062
6053
  const rawDeltaY = getRestoredDeltaY(savedState);
6063
6054
  const maxDeltaY = Math.max(restoredDirents.length * itemHeight - height, 0);
@@ -6170,30 +6161,11 @@ const getFileOperations = (root, uploadTree) => {
6170
6161
  return operations;
6171
6162
  };
6172
6163
 
6173
- const isDroppedFile = item => {
6174
- return item.kind === 'file' && 'value' in item;
6175
- };
6176
- const getFileSystemHandle = item => {
6177
- if (isDroppedFile(item)) {
6178
- return item.value;
6179
- }
6180
- return item;
6181
- };
6182
- const getDroppedName = item => {
6183
- if (isDroppedFile(item)) {
6184
- return item.value.name;
6185
- }
6186
- return item.name;
6187
- };
6188
- const getFileSystemHandlesNormalized = fileSystemHandles => {
6189
- return Array.from(fileSystemHandles, getFileSystemHandle);
6190
- };
6191
6164
  const uploadFileSystemHandles = async (root, pathSeparator, fileSystemHandles) => {
6192
6165
  if (fileSystemHandles.length === 0) {
6193
6166
  return true;
6194
6167
  }
6195
- const fileSystemHandlesNormalized = getFileSystemHandlesNormalized(fileSystemHandles);
6196
- const uploadTree = await createUploadTree(root, fileSystemHandlesNormalized);
6168
+ const uploadTree = await createUploadTree(root, fileSystemHandles);
6197
6169
  const fileOperations = getFileOperations(root, uploadTree);
6198
6170
  await applyFileOperations(fileOperations);
6199
6171
 
@@ -6233,15 +6205,14 @@ const getFirstDroppedDirectory = (state, fileHandles) => {
6233
6205
  if (root !== '') {
6234
6206
  return undefined;
6235
6207
  }
6236
- for (const item of fileHandles) {
6237
- const fileHandle = getFileSystemHandle(item);
6208
+ for (const fileHandle of fileHandles) {
6238
6209
  if (isDirectoryHandle(fileHandle)) {
6239
6210
  return fileHandle;
6240
6211
  }
6241
6212
  }
6242
6213
  return undefined;
6243
6214
  };
6244
- const handleDrop$2 = async (state, fileHandles, files, paths) => {
6215
+ const handleDrop$2 = async (state, fileHandles, paths) => {
6245
6216
  const {
6246
6217
  excluded,
6247
6218
  items,
@@ -6278,7 +6249,9 @@ const getFileOperationsElectron = async (root, paths, fileHandles, pathSeparator
6278
6249
  const operations = [];
6279
6250
  for (let i = 0; i < paths.length; i++) {
6280
6251
  const fileHandle = fileHandles[i];
6281
- const name = getDroppedName(fileHandle);
6252
+ const {
6253
+ name
6254
+ } = fileHandle;
6282
6255
  const path = paths[i];
6283
6256
  operations.push({
6284
6257
  from: path,
@@ -6290,9 +6263,8 @@ const getFileOperationsElectron = async (root, paths, fileHandles, pathSeparator
6290
6263
  };
6291
6264
 
6292
6265
  // TODO copy files in parallel
6293
- const copyFilesElectron = async (root, fileHandles, files, paths) => {
6294
- const pathSeparator = await getPathSeparator$1(root);
6295
- const operations = await getFileOperationsElectron(root, paths, fileHandles, pathSeparator);
6266
+ const copyFilesElectron = async (root, fileHandles, paths) => {
6267
+ const operations = await getFileOperationsElectron(root, paths, fileHandles, Slash);
6296
6268
  await applyFileOperations(operations);
6297
6269
  };
6298
6270
 
@@ -6320,14 +6292,14 @@ const getFirstDroppedDirectoryPath = (state, fileHandles, paths) => {
6320
6292
  return undefined;
6321
6293
  }
6322
6294
  for (let i = 0; i < fileHandles.length; i++) {
6323
- const fileHandle = getFileSystemHandle(fileHandles[i]);
6295
+ const fileHandle = fileHandles[i];
6324
6296
  if (isDirectoryHandle(fileHandle)) {
6325
6297
  return paths[i];
6326
6298
  }
6327
6299
  }
6328
6300
  return undefined;
6329
6301
  };
6330
- const handleDrop$1 = async (state, fileHandles, files, paths) => {
6302
+ const handleDrop$1 = async (state, fileHandles, paths) => {
6331
6303
  const {
6332
6304
  excluded,
6333
6305
  items,
@@ -6344,7 +6316,7 @@ const handleDrop$1 = async (state, fileHandles, files, paths) => {
6344
6316
  dropTargets: []
6345
6317
  };
6346
6318
  }
6347
- await copyFilesElectron(root, fileHandles, files, paths);
6319
+ await copyFilesElectron(root, fileHandles, paths);
6348
6320
  const mergedDirents = await getMergedDirents$1(root, pathSeparator, items, excluded);
6349
6321
  return {
6350
6322
  ...state,
@@ -6480,7 +6452,7 @@ const getModule = isElectron => {
6480
6452
  }
6481
6453
  return handleDrop$2;
6482
6454
  };
6483
- const handleDropRoot = async (state, fileHandles, files, paths) => {
6455
+ const handleDropRoot = async (state, fileHandles, paths) => {
6484
6456
  const {
6485
6457
  isReadonly,
6486
6458
  platform,
@@ -6494,7 +6466,7 @@ const handleDropRoot = async (state, fileHandles, files, paths) => {
6494
6466
  }
6495
6467
  const isElectron = platform === Electron;
6496
6468
  const fn = getModule(isElectron);
6497
- return fn(state, fileHandles, files, paths);
6469
+ return fn(state, fileHandles, paths);
6498
6470
  };
6499
6471
 
6500
6472
  const getEndIndex = (items, index, dirent) => {
@@ -6514,7 +6486,7 @@ const getMergedDirents = (items, index, dirent, childDirents) => {
6514
6486
  }, ...childDirents, ...items.slice(endIndex)];
6515
6487
  return mergedDirents;
6516
6488
  };
6517
- const handleDropIntoFolder = async (state, dirent, index, fileHandles, files, paths) => {
6489
+ const handleDropIntoFolder = async (state, dirent, index, fileHandles) => {
6518
6490
  const {
6519
6491
  excluded,
6520
6492
  items,
@@ -6531,17 +6503,17 @@ const handleDropIntoFolder = async (state, dirent, index, fileHandles, files, pa
6531
6503
  items: mergedDirents
6532
6504
  };
6533
6505
  };
6534
- const handleDropIntoFile = (state, dirent, index, fileHandles, files, paths) => {
6506
+ const handleDropIntoFile = (state, dirent, index, fileHandles, paths) => {
6535
6507
  const {
6536
6508
  items
6537
6509
  } = state;
6538
6510
  const parentIndex = getParentStartIndex(items, index);
6539
6511
  if (parentIndex === -1) {
6540
- return handleDropRoot(state, fileHandles, files, paths);
6512
+ return handleDropRoot(state, fileHandles, paths);
6541
6513
  }
6542
- return handleDropIndex(state, fileHandles, files, paths, parentIndex);
6514
+ return handleDropIndex(state, fileHandles, paths, parentIndex);
6543
6515
  };
6544
- const handleDropIndex = async (state, fileHandles, files, paths, index) => {
6516
+ const handleDropIndex = async (state, fileHandles, paths, index) => {
6545
6517
  const {
6546
6518
  isReadonly,
6547
6519
  items
@@ -6561,7 +6533,7 @@ const handleDropIndex = async (state, fileHandles, files, paths, index) => {
6561
6533
  case DirectoryExpanded:
6562
6534
  return handleDropIntoFolder(state, dirent, index, fileHandles);
6563
6535
  case File:
6564
- return handleDropIntoFile(state, dirent, index, fileHandles, files, paths);
6536
+ return handleDropIntoFile(state, dirent, index, fileHandles, paths);
6565
6537
  default:
6566
6538
  return state;
6567
6539
  }
@@ -6576,10 +6548,9 @@ const getDropHandler = index => {
6576
6548
  }
6577
6549
  };
6578
6550
 
6579
- const getDroppedItems = async (dropIdOrItemIds, isElectron) => {
6580
- const result = typeof dropIdOrItemIds === 'number' ? await getDroppedItemsByDropId(dropIdOrItemIds, isElectron) : await getDroppedItems$1(dropIdOrItemIds, isElectron);
6551
+ const toExplorerDroppedItems = (result, isElectron) => {
6581
6552
  const files = isElectron ? result.files : result.files.filter(file => file.handle);
6582
- const fileHandles = files.map(file => file.handle || {
6553
+ const fileHandles = files.map(file => file.handle ?? {
6583
6554
  kind: file.kind,
6584
6555
  name: file.name
6585
6556
  });
@@ -6590,6 +6561,29 @@ const getDroppedItems = async (dropIdOrItemIds, isElectron) => {
6590
6561
  uris: result.uris
6591
6562
  };
6592
6563
  };
6564
+ const getDroppedItemsByDropId = async (dropId, isElectron) => {
6565
+ const result = await getDroppedItemsByDropId$1(dropId, isElectron);
6566
+ return toExplorerDroppedItems(result, isElectron);
6567
+ };
6568
+ const getClipboardItems = async (itemIds, isElectron) => {
6569
+ const items = await getFileHandles(itemIds);
6570
+ const files = items.filter(item => item.kind === 'file' || isElectron && item.kind === 'file-legacy');
6571
+ const fileHandles = files.map(item => {
6572
+ if (item.kind === 'file') {
6573
+ return item.value;
6574
+ }
6575
+ return {
6576
+ kind: 'file',
6577
+ name: item.value.name
6578
+ };
6579
+ });
6580
+ const paths = files.map(item => item.path ?? '');
6581
+ return {
6582
+ fileHandles,
6583
+ paths,
6584
+ uris: []
6585
+ };
6586
+ };
6593
6587
 
6594
6588
  const directoryTypes$1 = new Set([Directory, DirectoryExpanded, DirectoryExpanding, EditingDirectoryExpanded, EditingFolder, SymLinkFolder]);
6595
6589
  const getDragUri = item => {
@@ -6616,7 +6610,7 @@ const getInternalDragPaths = (items, uris) => {
6616
6610
  return paths;
6617
6611
  };
6618
6612
 
6619
- const handleDrop = async (state, x, y, dropIdOrFileIds) => {
6613
+ const handleDrop = async (state, x, y, dropId) => {
6620
6614
  const {
6621
6615
  isReadonly,
6622
6616
  items,
@@ -6624,9 +6618,7 @@ const handleDrop = async (state, x, y, dropIdOrFileIds) => {
6624
6618
  root
6625
6619
  } = state;
6626
6620
  if (isReadonly && root !== '') {
6627
- if (typeof dropIdOrFileIds === 'number') {
6628
- await discardDrop(dropIdOrFileIds);
6629
- }
6621
+ await discardDrop(dropId);
6630
6622
  return state;
6631
6623
  }
6632
6624
  try {
@@ -6635,12 +6627,12 @@ const handleDrop = async (state, x, y, dropIdOrFileIds) => {
6635
6627
  fileHandles,
6636
6628
  paths,
6637
6629
  uris
6638
- } = await getDroppedItems(dropIdOrFileIds, isElectron);
6630
+ } = await getDroppedItemsByDropId(dropId, isElectron);
6639
6631
  const internalPaths = getInternalDragPaths(items, uris);
6640
6632
  const droppedPaths = internalPaths.length > 0 ? internalPaths : paths;
6641
6633
  const index = getIndexFromPosition(state, x, y);
6642
6634
  const fn = getDropHandler(index);
6643
- const result = await fn(state, fileHandles, [], droppedPaths, index);
6635
+ const result = await fn(state, fileHandles, droppedPaths, index);
6644
6636
  return result;
6645
6637
  } catch (error) {
6646
6638
  throw new VError(error, 'Failed to drop files');
@@ -7073,7 +7065,7 @@ const handleNativePaste = async (state, itemIds) => {
7073
7065
  const {
7074
7066
  fileHandles,
7075
7067
  paths
7076
- } = await getDroppedItems(itemIds, isElectron);
7068
+ } = await getClipboardItems(itemIds, isElectron);
7077
7069
  if (isElectron) {
7078
7070
  const nativePaths = paths.filter(Boolean);
7079
7071
  if (nativePaths.length === 0) {
@@ -7086,7 +7078,7 @@ const handleNativePaste = async (state, itemIds) => {
7086
7078
  });
7087
7079
  }
7088
7080
  const handleDrop = getDropHandler(focusedIndex);
7089
- return handleDrop(state, fileHandles, [], paths, focusedIndex);
7081
+ return handleDrop(state, fileHandles, paths, focusedIndex);
7090
7082
  } catch (error) {
7091
7083
  throw new VError(error, 'Failed to paste native files');
7092
7084
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "7.32.0",
3
+ "version": "7.33.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",