@lvce-editor/explorer-view 2.21.0 → 2.23.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.
@@ -996,6 +996,8 @@ const Symlink = 9;
996
996
  const SymLinkFile = 10;
997
997
  const SymLinkFolder = 11;
998
998
  const Unknown = 12;
999
+ const EditingFile = 13;
1000
+ const EditingFolder = 14;
999
1001
 
1000
1002
  const RendererWorker = 1;
1001
1003
 
@@ -1156,7 +1158,7 @@ const getNewDirentsAccept = async (state, newDirentType, createFn) => {
1156
1158
  newDirent.posInSet = posInSet;
1157
1159
  // @ts-ignore
1158
1160
  items.splice(insertIndex + 1, 0, newDirent);
1159
- const newDirents = [...items];
1161
+ const newDirents = [...items].filter(item => item.type !== EditingFile && item.type !== EditingFolder);
1160
1162
  return {
1161
1163
  dirents: newDirents,
1162
1164
  newFocusedIndex: insertIndex + 1
@@ -1977,6 +1979,16 @@ const focusNext = state => {
1977
1979
  return focusIndex(state, focusedIndex + 1);
1978
1980
  };
1979
1981
 
1982
+ const focusNone = state => {
1983
+ const {
1984
+ focusedIndex
1985
+ } = state;
1986
+ if (focusedIndex === -1) {
1987
+ return state;
1988
+ }
1989
+ return focusIndex(state, -1);
1990
+ };
1991
+
1980
1992
  const focusPrevious = state => {
1981
1993
  const {
1982
1994
  focusedIndex,
@@ -1995,7 +2007,7 @@ const focusPrevious = state => {
1995
2007
  }
1996
2008
  };
1997
2009
 
1998
- const commandIds = ['acceptEdit', 'cancelEdit', 'collapseAll', 'copyPath', 'copyRelativePath', 'dispose', 'expandAll', 'expandRecursively', 'selectUp', 'selectDown', 'getMouseActions', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'getFocusedDirent', 'getMenuEntries2', 'handleArrowLeft', 'handleArrowLeft', 'handleArrowRight', 'handleArrowRight', 'handleBlur', 'handleClick', 'handleClickAt', 'handleClickCurrent', 'handleClickCurrentButKeepFocus', 'handleClickOpenFolder', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleCopy', 'handleDragLeave', 'handleDragOver', 'handleDrop', 'handleFocus', 'handleIconThemeChange', 'handleLanguagesChanged', 'handleMouseEnter', 'handleMouseLeave', 'handlePaste', 'handlePointerDown', 'handleUpload', 'handleWheel', 'handleWorkspaceChange', 'hotReload', 'newFile', 'newFolder', 'openContainingFolder', 'refresh', 'refresh', 'removeDirent', 'rename', 'renameDirent', 'renderEventListeners', 'revealItem', 'revealItem', 'scrollDown', 'scrollUp', 'setDeltaY', 'updateEditingValue', 'updateIcons'];
2010
+ const commandIds = ['acceptEdit', 'cancelEdit', 'collapseAll', 'copyPath', 'copyRelativePath', 'dispose', 'expandAll', 'expandRecursively', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'getFocusedDirent', 'getMenuEntries2', 'getMouseActions', 'handleArrowLeft', 'handleArrowLeft', 'handleArrowRight', 'handleArrowRight', 'handleBlur', 'handleClick', 'handleClickAt', 'handleClickCurrent', 'handleClickCurrentButKeepFocus', 'handleClickOpenFolder', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleCopy', 'handleDragLeave', 'handleDragOver', 'handleDrop', 'handleFocus', 'handleIconThemeChange', 'handleInputBlur', 'handleLanguagesChanged', 'handleMouseEnter', 'handleMouseLeave', 'handlePaste', 'handlePointerDown', 'handleUpload', 'handleWheel', 'handleWorkspaceChange', 'hotReload', 'newFile', 'newFolder', 'openContainingFolder', 'refresh', 'removeDirent', 'rename', 'renameDirent', 'renderEventListeners', 'revealItem', 'revealItem', 'scrollDown', 'scrollUp', 'selectAll', 'selectDown', 'selectUp', 'setDeltaY', 'setSelectedIndices', 'updateEditingValue', 'updateIcons'];
1999
2011
 
2000
2012
  const getCommandIds = () => {
2001
2013
  return commandIds;
@@ -2011,6 +2023,7 @@ const UpArrow = 14;
2011
2023
  const RightArrow = 15;
2012
2024
  const DownArrow = 16;
2013
2025
  const Delete = 18;
2026
+ const KeyA = 29;
2014
2027
  const KeyC = 31;
2015
2028
  const KeyV = 50;
2016
2029
  const F2 = 58;
@@ -2078,7 +2091,7 @@ const getKeyBindings = () => {
2078
2091
  when: FocusExplorer
2079
2092
  }, {
2080
2093
  key: F2,
2081
- command: 'Explorer.rename',
2094
+ command: 'Explorer.renameDirent',
2082
2095
  when: FocusExplorer
2083
2096
  }, {
2084
2097
  key: Escape,
@@ -2104,6 +2117,10 @@ const getKeyBindings = () => {
2104
2117
  key: Enter,
2105
2118
  command: 'Explorer.handleClickCurrent',
2106
2119
  when: FocusExplorer
2120
+ }, {
2121
+ key: CtrlCmd | KeyA,
2122
+ command: 'Explorer.selectAll',
2123
+ when: FocusExplorer
2107
2124
  }];
2108
2125
  };
2109
2126
 
@@ -2854,6 +2871,7 @@ const applyOperation = operation => {
2854
2871
  }
2855
2872
  return writeFile(operation.path, operation.text);
2856
2873
  };
2874
+
2857
2875
  const applyFileOperations = async operations => {
2858
2876
  // TODO run operations in parallel if possible
2859
2877
  for (const operation of operations) {
@@ -3181,6 +3199,10 @@ const handleIconThemeChange = state => {
3181
3199
  return updateIcons(state);
3182
3200
  };
3183
3201
 
3202
+ const handleInputBlur = state => {
3203
+ return cancelEdit(state);
3204
+ };
3205
+
3184
3206
  // TODO add lots of tests for this
3185
3207
  const updateRoot = async state1 => {
3186
3208
  // @ts-ignore
@@ -3534,28 +3556,103 @@ const handleWorkspaceChange = async state => {
3534
3556
 
3535
3557
  const ExplorerEditBox = FocusExplorerEditBox;
3536
3558
 
3559
+ const getNewChildDirentsForNewDirent = async (items, depth, parentPath, direntType) => {
3560
+ // Get existing children or query them if they don't exist
3561
+ let existingChildren = items.filter(item => item.depth === depth && item.path.startsWith(parentPath));
3562
+ if (existingChildren.length === 0) {
3563
+ const childDirents = await readDirWithFileTypes(parentPath);
3564
+ existingChildren = childDirents.map((dirent, index) => ({
3565
+ name: dirent.name,
3566
+ type: dirent.type,
3567
+ path: `${parentPath}/${dirent.name}`,
3568
+ depth,
3569
+ selected: false,
3570
+ posInSet: index + 1,
3571
+ setSize: childDirents.length,
3572
+ icon: ''
3573
+ }));
3574
+ }
3575
+ const updatedChildren = existingChildren.map((child, index) => ({
3576
+ ...child,
3577
+ posInSet: index + 1,
3578
+ setSize: existingChildren.length + 2
3579
+ }));
3580
+ const newDirent = {
3581
+ name: '',
3582
+ type: direntType,
3583
+ path: '',
3584
+ depth,
3585
+ selected: false,
3586
+ posInSet: updatedChildren.length + 1,
3587
+ setSize: existingChildren.length + 2,
3588
+ icon: ''
3589
+ };
3590
+ const allChildDirents = [...updatedChildren, newDirent];
3591
+ return allChildDirents;
3592
+ };
3593
+
3594
+ const getNewDirentsForNewDirent = async (items, focusedIndex, type) => {
3595
+ const focusedItem = items[focusedIndex];
3596
+ if (!focusedItem) {
3597
+ return items;
3598
+ }
3599
+ const parentPath = focusedItem.path;
3600
+ const depth = focusedItem.depth + 1;
3601
+ const updatedChildren = await getNewChildDirentsForNewDirent(items, depth, parentPath, type);
3602
+
3603
+ // Create new array with updated items
3604
+ const parentIndex = focusedIndex;
3605
+ const itemsBeforeParent = items.slice(0, parentIndex);
3606
+ const itemsAfterChildren = items.slice(parentIndex + updatedChildren.length);
3607
+ const updatedParent = {
3608
+ ...items[parentIndex],
3609
+ setSize: (items[parentIndex]?.setSize || 0) + 1
3610
+ };
3611
+ return [...itemsBeforeParent, updatedParent, ...updatedChildren, ...itemsAfterChildren];
3612
+ };
3613
+
3614
+ const getNewDirentType = editingType => {
3615
+ switch (editingType) {
3616
+ case CreateFile:
3617
+ return EditingFile;
3618
+ case CreateFolder:
3619
+ return EditingFolder;
3620
+ default:
3621
+ return File;
3622
+ }
3623
+ };
3624
+
3537
3625
  const newDirent = async (state, editingType) => {
3538
3626
  // TODO make focus functional instead of side effect
3539
3627
  await setFocus(ExplorerEditBox);
3540
3628
  // TODO do it like vscode, select position between folders and files
3541
3629
  const {
3542
3630
  focusedIndex,
3543
- items
3631
+ items,
3632
+ minLineY,
3633
+ height,
3634
+ itemHeight,
3635
+ fileIconCache
3544
3636
  } = state;
3545
- if (focusedIndex >= 0) {
3546
- const dirent = items[focusedIndex];
3547
- if (dirent.type === Directory) {
3548
- // TODO handle error
3549
- // @ts-ignore
3550
- await handleClickDirectory(state, dirent);
3551
- }
3552
- }
3637
+ const direntType = getNewDirentType(editingType);
3638
+ const newDirents = await getNewDirentsForNewDirent(items, focusedIndex, direntType);
3639
+ const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, newDirents.length);
3640
+ const visible = newDirents.slice(minLineY, maxLineY);
3641
+ const {
3642
+ icons,
3643
+ newFileIconCache
3644
+ } = await getFileIcons(visible, fileIconCache);
3645
+ const editingIndex = newDirents.findIndex(item => item.type === EditingFile || item.type === EditingFolder);
3553
3646
  return {
3554
3647
  ...state,
3555
- editingIndex: focusedIndex,
3648
+ items: newDirents,
3649
+ editingIndex,
3556
3650
  editingType,
3557
3651
  editingValue: '',
3558
- focus: Input$1
3652
+ focus: Input$1,
3653
+ icons,
3654
+ fileIconCache: newFileIconCache,
3655
+ maxLineY
3559
3656
  };
3560
3657
  };
3561
3658
 
@@ -3750,14 +3847,15 @@ const WelcomeMessage = 'WelcomeMessage';
3750
3847
  const HandleClick = 'handleClick';
3751
3848
  const HandleClickOpenFolder = 'handleClickOpenFolder';
3752
3849
  const HandleContextMenu = 'handleContextMenu';
3850
+ const HandleDragLeave = 'handleDragLeave';
3851
+ const HandleDragOver = 'handleDragOver';
3852
+ const HandleDrop = 'handleDrop';
3753
3853
  const HandleEditingInput = 'handleEditingInput';
3854
+ const HandleInputBlur = 'handleInputBlur';
3754
3855
  const HandleListBlur = 'handleListBlur';
3755
3856
  const HandleListFocus = 'handleListFocus';
3756
3857
  const HandlePointerDown = 'handlePointerDown';
3757
3858
  const HandleWheel = 'handleWheel';
3758
- const HandleDragOver = 'handleDragOver';
3759
- const HandleDrop = 'handleDrop';
3760
- const HandleDragLeave = 'handleDragLeave';
3761
3859
 
3762
3860
  const mergeClassNames = (...classNames) => {
3763
3861
  return classNames.filter(Boolean).join(' ');
@@ -3816,6 +3914,7 @@ const getInputDom = hasEditingError => {
3816
3914
  className: getClassName$2(hasEditingError),
3817
3915
  id: 'ExplorerInput',
3818
3916
  onInput: HandleEditingInput,
3917
+ onBlur: HandleInputBlur,
3819
3918
  childCount: 0,
3820
3919
  name: ExplorerInput
3821
3920
  }];
@@ -4187,8 +4286,8 @@ const renderActions = uid => {
4187
4286
 
4188
4287
  const renderEventListeners = () => {
4189
4288
  return [{
4190
- name: HandleListBlur,
4191
- params: ['handleBlur']
4289
+ name: HandleInputBlur,
4290
+ params: ['handleInputBlur']
4192
4291
  }, {
4193
4292
  name: HandleListFocus,
4194
4293
  params: ['handleFocus', 'event.isTrusted', 'event.target.className']
@@ -4466,13 +4565,36 @@ const saveState = uid => {
4466
4565
  };
4467
4566
  };
4468
4567
 
4568
+ const selectAll = state => {
4569
+ const {
4570
+ items
4571
+ } = state;
4572
+ const newItems = items.map(item => ({
4573
+ ...item,
4574
+ selected: true
4575
+ }));
4576
+ return {
4577
+ ...state,
4578
+ items: newItems
4579
+ };
4580
+ };
4581
+
4582
+ const getLastSelectedIndex = items => {
4583
+ let lastSelectedIndex = -1;
4584
+ for (let index = 0; index < items.length; index++) {
4585
+ if (items[index].selected) {
4586
+ lastSelectedIndex = index;
4587
+ }
4588
+ }
4589
+ return lastSelectedIndex;
4590
+ };
4469
4591
  const selectDown = state => {
4470
4592
  const {
4471
4593
  items,
4472
4594
  focusedIndex
4473
4595
  } = state;
4474
- const firstSelectedIndex = items.findIndex(item => item.selected);
4475
- const targetIndex = firstSelectedIndex === -1 ? focusedIndex : firstSelectedIndex;
4596
+ const lastSelectedIndex = getLastSelectedIndex(items);
4597
+ const targetIndex = lastSelectedIndex === -1 ? focusedIndex : lastSelectedIndex;
4476
4598
  if (targetIndex >= items.length - 1) {
4477
4599
  return state;
4478
4600
  }
@@ -4480,6 +4602,21 @@ const selectDown = state => {
4480
4602
  ...item,
4481
4603
  selected: i === targetIndex + 1 ? true : item.selected
4482
4604
  }));
4605
+ return {
4606
+ ...state,
4607
+ items: newItems,
4608
+ focusedIndex: targetIndex + 1
4609
+ };
4610
+ };
4611
+
4612
+ const setSelectedIndices = (state, indices) => {
4613
+ const {
4614
+ items
4615
+ } = state;
4616
+ const newItems = items.map((item, i) => ({
4617
+ ...item,
4618
+ selected: indices.includes(i)
4619
+ }));
4483
4620
  return {
4484
4621
  ...state,
4485
4622
  items: newItems
@@ -4548,10 +4685,10 @@ const wrapCommand = fn => {
4548
4685
  };
4549
4686
 
4550
4687
  const commandMap = {
4551
- 'Explorer.getMenuEntries2': getMenuEntries2,
4552
4688
  'Explorer.acceptEdit': wrapCommand(acceptEdit),
4553
4689
  'Explorer.cancelEdit': wrapCommand(cancelEdit),
4554
4690
  'Explorer.collapseAll': wrapCommand(collapseAll),
4691
+ 'Explorer.handleInputBlur': wrapCommand(handleInputBlur),
4555
4692
  'Explorer.copyPath': wrapCommand(copyPath),
4556
4693
  'Explorer.copyRelativePath': wrapCommand(copyRelativePath),
4557
4694
  'Explorer.expandAll': wrapCommand(expandAll),
@@ -4560,20 +4697,20 @@ const commandMap = {
4560
4697
  'Explorer.focusIndex': wrapCommand(focusIndex),
4561
4698
  'Explorer.focusLast': wrapCommand(focusLast),
4562
4699
  'Explorer.focusNext': wrapCommand(focusNext),
4700
+ 'Explorer.focusNone': wrapCommand(focusNone),
4563
4701
  'Explorer.focusPrevious': wrapCommand(focusPrevious),
4564
4702
  'Explorer.getCommandIds': getCommandIds,
4703
+ 'Explorer.getMenuEntries2': getMenuEntries2,
4704
+ 'Explorer.getMouseActions': getMouseActions,
4565
4705
  'Explorer.handleArrowLeft': wrapCommand(handleArrowLeft),
4566
4706
  'Explorer.handleArrowRight': wrapCommand(handleArrowRight),
4567
4707
  'Explorer.handleBlur': wrapCommand(handleBlur),
4568
- 'Explorer.selectUp': wrapCommand(selectUp),
4569
- 'Explorer.selectDown': wrapCommand(selectDown),
4570
4708
  'Explorer.handleClick': wrapCommand(handleClick),
4571
4709
  'Explorer.handleClickAt': wrapCommand(handleClickAt),
4572
4710
  'Explorer.handleClickCurrent': wrapCommand(handleClickCurrent),
4573
4711
  'Explorer.handleClickCurrentButKeepFocus': wrapCommand(handleClickCurrentButKeepFocus),
4574
4712
  'Explorer.handleClickOpenFolder': wrapCommand(handleClickOpenFolder),
4575
4713
  'Explorer.handleContextMenu': wrapCommand(handleContextMenu),
4576
- 'Explorer.getMouseActions': getMouseActions,
4577
4714
  'Explorer.handleContextMenuKeyboard': wrapCommand(handleContextMenuKeyboard),
4578
4715
  'Explorer.handleCopy': wrapCommand(handleCopy),
4579
4716
  'Explorer.handleDragLeave': wrapCommand(handleDragLeave),
@@ -4595,7 +4732,11 @@ const commandMap = {
4595
4732
  'Explorer.renameDirent': wrapCommand(renameDirent),
4596
4733
  'Explorer.restoreState': restoreState,
4597
4734
  'Explorer.revealItem': wrapCommand(revealItem),
4735
+ 'Explorer.selectAll': wrapCommand(selectAll),
4736
+ 'Explorer.selectDown': wrapCommand(selectDown),
4737
+ 'Explorer.selectUp': wrapCommand(selectUp),
4598
4738
  'Explorer.setDeltaY': wrapCommand(setDeltaY),
4739
+ 'Explorer.setSelectedIndices': wrapCommand(setSelectedIndices),
4599
4740
  'Explorer.updateEditingValue': wrapCommand(updateEditingValue),
4600
4741
  'Explorer.updateIcons': wrapCommand(updateIcons),
4601
4742
  // not wrapped
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.21.0",
3
+ "version": "2.23.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",