@lvce-editor/explorer-view 7.9.1 → 7.10.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.
@@ -2627,6 +2627,9 @@ const acceptRename = async state => {
2627
2627
  };
2628
2628
 
2629
2629
  const acceptEdit = async state => {
2630
+ if (state.isReadonly) {
2631
+ return state;
2632
+ }
2630
2633
  const {
2631
2634
  editingType
2632
2635
  } = state;
@@ -4305,16 +4308,24 @@ const menuEntryRename = {
4305
4308
  id: 'rename',
4306
4309
  label: rename()
4307
4310
  };
4308
- const menuEntryRenameDisabled = {
4309
- ...menuEntryRename,
4310
- flags: Disabled
4311
- };
4312
4311
  const menuEntryDelete = {
4313
4312
  command: 'Explorer.removeDirent',
4314
4313
  flags: None$2,
4315
4314
  id: 'delete',
4316
4315
  label: deleteItem()
4317
4316
  };
4317
+ const disable = entry => {
4318
+ return {
4319
+ ...entry,
4320
+ flags: Disabled
4321
+ };
4322
+ };
4323
+ const getWritableEntry = (state, entry) => {
4324
+ if (state.isReadonly) {
4325
+ return disable(entry);
4326
+ }
4327
+ return entry;
4328
+ };
4318
4329
  const menuEntryRemoveFolderFromWorkspace = {
4319
4330
  command: 'Workspace.close',
4320
4331
  flags: None$2,
@@ -4331,26 +4342,23 @@ const getFocusedDirent = explorerState => {
4331
4342
  }
4332
4343
  return explorerState.items[explorerState.focusedIndex];
4333
4344
  };
4334
- const getMenuEntryRename = state => {
4335
- if (state.isReadonly) {
4336
- return menuEntryRenameDisabled;
4337
- }
4338
- return menuEntryRename;
4339
- };
4340
4345
  const getMenuEntriesDirectory = state => {
4341
- return [menuEntryNewFile, menuEntryNewFolder, menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, getMenuEntryRename(state), menuEntryDelete];
4346
+ return [getWritableEntry(state, menuEntryNewFile), getWritableEntry(state, menuEntryNewFolder), menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, getWritableEntry(state, menuEntryCut), menuEntryCopy, getWritableEntry(state, menuEntryPaste), menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, getWritableEntry(state, menuEntryRename), getWritableEntry(state, menuEntryDelete)];
4342
4347
  };
4343
4348
  const getMenuEntriesFile = state => {
4344
- return [menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntrySelectForCompare, menuEntrySeparator, getMenuEntryRename(state), menuEntryDelete];
4349
+ return [menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, getWritableEntry(state, menuEntryCut), menuEntryCopy, getWritableEntry(state, menuEntryPaste), menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntrySelectForCompare, menuEntrySeparator, getWritableEntry(state, menuEntryRename), getWritableEntry(state, menuEntryDelete)];
4345
4350
  };
4346
4351
  const getMenuEntriesFileCompareWithSelected = state => {
4347
- return [menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntryCompareWithSelected, menuEntrySeparator, getMenuEntryRename(state), menuEntryDelete];
4352
+ return [menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, getWritableEntry(state, menuEntryCut), menuEntryCopy, getWritableEntry(state, menuEntryPaste), menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntryCompareWithSelected, menuEntrySeparator, getWritableEntry(state, menuEntryRename), getWritableEntry(state, menuEntryDelete)];
4348
4353
  };
4349
4354
  const getMenuEntriesDefault = state => {
4350
4355
  return getMenuEntriesDirectory(state);
4351
4356
  };
4352
- const getMenuEntriesRoot = root => {
4353
- const entries = [menuEntryNewFile, menuEntryNewFolder, menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath];
4357
+ const getMenuEntriesRoot = state => {
4358
+ const {
4359
+ root
4360
+ } = state;
4361
+ const entries = [getWritableEntry(state, menuEntryNewFile), getWritableEntry(state, menuEntryNewFolder), menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, getWritableEntry(state, menuEntryPaste), menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath];
4354
4362
  if (root) {
4355
4363
  entries.push(menuEntrySeparator, menuEntryRemoveFolderFromWorkspace);
4356
4364
  }
@@ -4359,7 +4367,7 @@ const getMenuEntriesRoot = root => {
4359
4367
  const getMenuEntries = state => {
4360
4368
  const focusedDirent = getFocusedDirent(state);
4361
4369
  if (!focusedDirent) {
4362
- return getMenuEntriesRoot(state.root);
4370
+ return getMenuEntriesRoot(state);
4363
4371
  }
4364
4372
  switch (focusedDirent.type) {
4365
4373
  case Directory:
@@ -4753,6 +4761,9 @@ const newDirent = async (state, editingType, editingIcon = '') => {
4753
4761
 
4754
4762
  // TODO much shared logic with newFolder
4755
4763
  const newFile = state => {
4764
+ if (state.isReadonly) {
4765
+ return Promise.resolve(state);
4766
+ }
4756
4767
  return newDirent(state, CreateFile);
4757
4768
  };
4758
4769
 
@@ -4783,7 +4794,7 @@ const getEditingIcon = async (editingType, value, direntType) => {
4783
4794
  };
4784
4795
 
4785
4796
  const newFolder = async state => {
4786
- if (state.editingIndex !== -1) {
4797
+ if (state.isReadonly || state.editingIndex !== -1) {
4787
4798
  return state;
4788
4799
  }
4789
4800
  const editingIcon = await getEditingIcon(CreateFolder, '');
@@ -5235,6 +5246,9 @@ const getSelectedItems = (items, focusedIndex) => {
5235
5246
  };
5236
5247
 
5237
5248
  const handleCut = async state => {
5249
+ if (state.isReadonly) {
5250
+ return state;
5251
+ }
5238
5252
  // TODO handle multiple files
5239
5253
  // TODO if not file is selected, what happens?
5240
5254
  const {
@@ -5333,6 +5347,9 @@ const isEqual = (a, b) => {
5333
5347
  };
5334
5348
 
5335
5349
  const handleDragOverIndex = (state, index) => {
5350
+ if (state.isReadonly) {
5351
+ return state;
5352
+ }
5336
5353
  const {
5337
5354
  dropTargets
5338
5355
  } = state;
@@ -5349,6 +5366,9 @@ const handleDragOverIndex = (state, index) => {
5349
5366
  const handleDragOver = (state, x, y) => {
5350
5367
  number(x);
5351
5368
  number(y);
5369
+ if (state.isReadonly) {
5370
+ return state;
5371
+ }
5352
5372
  const index = getIndexFromPosition(state, x, y);
5353
5373
  return handleDragOverIndex(state, index);
5354
5374
  };
@@ -5900,6 +5920,9 @@ const getModule = isElectron => {
5900
5920
  return handleDrop$2;
5901
5921
  };
5902
5922
  const handleDropRoot = async (state, fileHandles, files, paths) => {
5923
+ if (state.isReadonly) {
5924
+ return state;
5925
+ }
5903
5926
  const isElectron = state.platform === Electron;
5904
5927
  const fn = getModule(isElectron);
5905
5928
  return fn(state, fileHandles, files, paths);
@@ -5950,6 +5973,9 @@ const handleDropIntoFile = (state, dirent, index, fileHandles, files, paths) =>
5950
5973
  return handleDropIndex(state, fileHandles, files, paths, parentIndex);
5951
5974
  };
5952
5975
  const handleDropIndex = async (state, fileHandles, files, paths, index) => {
5976
+ if (state.isReadonly) {
5977
+ return state;
5978
+ }
5953
5979
  const {
5954
5980
  items
5955
5981
  } = state;
@@ -6008,6 +6034,9 @@ const getFilePaths = async (files, platform) => {
6008
6034
  };
6009
6035
 
6010
6036
  const handleDrop = async (state, x, y, fileIds, fileList) => {
6037
+ if (state.isReadonly) {
6038
+ return state;
6039
+ }
6011
6040
  try {
6012
6041
  const {
6013
6042
  platform
@@ -6362,6 +6391,9 @@ const handlePasteCut = async (state, nativeFiles) => {
6362
6391
  const None$1 = 'none';
6363
6392
 
6364
6393
  const handlePaste = async state => {
6394
+ if (state.isReadonly) {
6395
+ return state;
6396
+ }
6365
6397
  const nativeFiles = await readNativeFiles();
6366
6398
  if (!nativeFiles) {
6367
6399
  return state;
@@ -6447,6 +6479,9 @@ const handleResize = (state, dimensions) => {
6447
6479
  };
6448
6480
 
6449
6481
  const handleUpload = async (state, dirents) => {
6482
+ if (state.isReadonly) {
6483
+ return state;
6484
+ }
6450
6485
  const {
6451
6486
  pathSeparator,
6452
6487
  root
@@ -6553,6 +6588,9 @@ const showErrorAlert = async errorMessage => {
6553
6588
  };
6554
6589
 
6555
6590
  const removeDirent = async state => {
6591
+ if (state.isReadonly) {
6592
+ return state;
6593
+ }
6556
6594
  const {
6557
6595
  confirmDelete: confirmDelete$1,
6558
6596
  focusedIndex,
@@ -6623,6 +6661,9 @@ const User = 1;
6623
6661
  const Script = 2;
6624
6662
 
6625
6663
  const renameDirent = async state => {
6664
+ if (state.isReadonly) {
6665
+ return state;
6666
+ }
6626
6667
  const {
6627
6668
  focusedIndex,
6628
6669
  icons,
@@ -7247,23 +7288,27 @@ const NewFile = 'NewFile';
7247
7288
  const NewFolder = 'NewFolder';
7248
7289
  const Refresh = 'Refresh';
7249
7290
 
7250
- const getActions = root => {
7291
+ const getActions = (root, isReadonly) => {
7251
7292
  if (!root) {
7252
7293
  return [];
7253
7294
  }
7254
- return [{
7255
- command: 'newFile',
7256
- icon: NewFile,
7257
- id: newFile$1(),
7258
- name: NewFile$1,
7259
- type: Button
7260
- }, {
7261
- command: 'newFolder',
7262
- icon: NewFolder,
7263
- id: newFolder$1(),
7264
- name: NewFolder$1,
7265
- type: Button
7266
- }, {
7295
+ const actions = [];
7296
+ if (!isReadonly) {
7297
+ actions.push({
7298
+ command: 'newFile',
7299
+ icon: NewFile,
7300
+ id: newFile$1(),
7301
+ name: NewFile$1,
7302
+ type: Button
7303
+ }, {
7304
+ command: 'newFolder',
7305
+ icon: NewFolder,
7306
+ id: newFolder$1(),
7307
+ name: NewFolder$1,
7308
+ type: Button
7309
+ });
7310
+ }
7311
+ actions.push({
7267
7312
  command: 'refresh',
7268
7313
  icon: Refresh,
7269
7314
  id: refresh$1(),
@@ -7275,7 +7320,8 @@ const getActions = root => {
7275
7320
  id: collapseAll$1(),
7276
7321
  name: CollapseAll$1,
7277
7322
  type: Button
7278
- }];
7323
+ });
7324
+ return actions;
7279
7325
  };
7280
7326
 
7281
7327
  const getIconVirtualDom = (icon, type = Div) => {
@@ -7325,7 +7371,7 @@ const renderActions = uid => {
7325
7371
  const {
7326
7372
  newState
7327
7373
  } = get(uid);
7328
- const actions = getActions(newState.root);
7374
+ const actions = getActions(newState.root, newState.isReadonly);
7329
7375
  const dom = getActionsVirtualDom(actions);
7330
7376
  return dom;
7331
7377
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "7.9.1",
3
+ "version": "7.10.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",