@lvce-editor/explorer-view 2.25.0 → 2.27.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.
@@ -1004,6 +1004,7 @@ const SymLinkFolder = 11;
1004
1004
  const Unknown = 12;
1005
1005
  const EditingFile = File + DELTA_EDITING;
1006
1006
  const EditingFolder = Directory + DELTA_EDITING;
1007
+ const EditingDirectoryExpanded = DirectoryExpanded + DELTA_EDITING;
1007
1008
 
1008
1009
  const RendererWorker = 1;
1009
1010
 
@@ -1422,12 +1423,19 @@ const acceptEdit = async state => {
1422
1423
  }
1423
1424
  };
1424
1425
 
1426
+ const normalizeDirentType = direntType => {
1427
+ if (direntType > DELTA_EDITING) {
1428
+ return direntType - DELTA_EDITING;
1429
+ }
1430
+ return direntType;
1431
+ };
1432
+
1425
1433
  const getNewDirentsForCancelRename = (items, editingIndex) => {
1426
1434
  const item = items[editingIndex];
1427
1435
  const newItems = [...items];
1428
1436
  newItems[editingIndex] = {
1429
1437
  ...item,
1430
- type: item.type - DELTA_EDITING
1438
+ type: normalizeDirentType(item.type)
1431
1439
  };
1432
1440
  return newItems;
1433
1441
  };
@@ -2064,7 +2072,7 @@ const focusPrevious = state => {
2064
2072
  }
2065
2073
  };
2066
2074
 
2067
- 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'];
2075
+ 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', 'handleInputClick', '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'];
2068
2076
 
2069
2077
  const getCommandIds = () => {
2070
2078
  return commandIds;
@@ -2615,6 +2623,18 @@ const getClickFn = direntType => {
2615
2623
  }
2616
2624
  };
2617
2625
 
2626
+ const resetEditing = {
2627
+ editingIndex: -1,
2628
+ editingValue: '',
2629
+ editingType: None$5,
2630
+ editingIcon: '',
2631
+ editingErrorMessage: '',
2632
+ editingSelection: {
2633
+ start: 0,
2634
+ end: 0
2635
+ }
2636
+ };
2637
+
2618
2638
  // TODO viewlet should only have create and refresh functions
2619
2639
  // every thing else can be in a separate module <viewlet>.lazy.js
2620
2640
  // and <viewlet>.ipc.js
@@ -2644,8 +2664,16 @@ const handleClick = async (state, index, keepFocus = false) => {
2644
2664
  console.warn(`[explorer] dirent at index ${actualIndex} not found`, state);
2645
2665
  return state;
2646
2666
  }
2647
- const clickFn = getClickFn(dirent.type);
2648
- return clickFn(state, dirent, actualIndex, keepFocus);
2667
+ const normalizedType = normalizeDirentType(dirent.type);
2668
+ const clickFn = getClickFn(normalizedType);
2669
+ const newState = await clickFn(state, dirent, actualIndex, keepFocus);
2670
+ if (newState.editingIndex === -1) {
2671
+ return newState;
2672
+ }
2673
+ return {
2674
+ ...newState,
2675
+ ...resetEditing
2676
+ };
2649
2677
  };
2650
2678
 
2651
2679
  // export const handleBlur=()=>{}
@@ -2705,7 +2733,10 @@ const handleClickAtRangeSelection = async (state, index) => {
2705
2733
  return handleRangeSelection(state, min, max);
2706
2734
  };
2707
2735
 
2708
- const handleClickAt = async (state, button, ctrlKey, shiftKey, x, y) => {
2736
+ const handleClickAt = async (state, defaultPrevented, button, ctrlKey, shiftKey, x, y) => {
2737
+ if (defaultPrevented) {
2738
+ return state;
2739
+ }
2709
2740
  if (button !== LeftClick) {
2710
2741
  return state;
2711
2742
  }
@@ -3260,6 +3291,10 @@ const handleInputBlur = state => {
3260
3291
  return cancelEdit(state);
3261
3292
  };
3262
3293
 
3294
+ const handleInputClick = state => {
3295
+ return state;
3296
+ };
3297
+
3263
3298
  // TODO add lots of tests for this
3264
3299
  const updateRoot = async state1 => {
3265
3300
  // @ts-ignore
@@ -3921,6 +3956,7 @@ const FocusOutline = 'FocusOutline';
3921
3956
  const ListItems = 'ListItems';
3922
3957
  const IconButton = 'IconButton';
3923
3958
  const InputBox = 'InputBox';
3959
+ const ExplorerInputBox = 'ExplorerInputBox';
3924
3960
  const InputValidationError = 'InputValidationError';
3925
3961
  const Label = 'Label';
3926
3962
  const MaskIconChevronDown = 'MaskIconChevronDown';
@@ -3951,6 +3987,7 @@ const HandleDragOver = 'handleDragOver';
3951
3987
  const HandleDrop = 'handleDrop';
3952
3988
  const HandleEditingInput = 'handleEditingInput';
3953
3989
  const HandleInputBlur = 'handleInputBlur';
3990
+ const HandleInputClick = 'handleInputClick';
3954
3991
  const HandleListBlur = 'handleListBlur';
3955
3992
  const HandleListFocus = 'handleListFocus';
3956
3993
  const HandlePointerDown = 'handlePointerDown';
@@ -4001,26 +4038,28 @@ const getFileIconVirtualDom = icon => {
4001
4038
  };
4002
4039
  };
4003
4040
 
4004
- const getClassName$2 = hasEditingError => {
4041
+ const getInputClassName = hasEditingError => {
4005
4042
  if (hasEditingError) {
4006
- return mergeClassNames(InputBox, InputValidationError);
4043
+ return mergeClassNames(InputBox, ExplorerInputBox, InputValidationError);
4007
4044
  }
4008
- return InputBox;
4045
+ return mergeClassNames(InputBox, ExplorerInputBox);
4009
4046
  };
4047
+
4010
4048
  const getInputDom = hasEditingError => {
4011
4049
  const ariaLabel = typeAFileName();
4012
4050
  return [{
4013
4051
  type: Input,
4014
- className: getClassName$2(hasEditingError),
4015
- id: 'ExplorerInput',
4016
- onInput: HandleEditingInput,
4017
- onBlur: HandleInputBlur,
4052
+ ariaLabel: ariaLabel,
4053
+ autocapitalize: 'off',
4054
+ autocorrect: 'off',
4018
4055
  childCount: 0,
4056
+ className: getInputClassName(hasEditingError),
4057
+ id: 'ExplorerInput',
4019
4058
  name: ExplorerInput,
4020
- autocorrect: 'off',
4021
- autocapitalize: 'off',
4022
- spellcheck: 'false',
4023
- ariaLabel: ariaLabel
4059
+ onBlur: HandleInputBlur,
4060
+ onClick: HandleInputClick,
4061
+ onInput: HandleEditingInput,
4062
+ spellcheck: 'false'
4024
4063
  }];
4025
4064
  };
4026
4065
 
@@ -4029,31 +4068,35 @@ const label = {
4029
4068
  className: Label,
4030
4069
  childCount: 1
4031
4070
  };
4071
+ const getLabelDom = name => {
4072
+ return [label, text(name)];
4073
+ };
4074
+
4032
4075
  const getInputOrLabelDom = (isEditing, hasEditingError, name) => {
4033
4076
  if (isEditing) {
4034
4077
  return getInputDom(hasEditingError);
4035
4078
  }
4036
- return [label, text(name)];
4079
+ return getLabelDom(name);
4037
4080
  };
4038
4081
 
4039
4082
  const getExplorerItemVirtualDom = item => {
4040
4083
  const {
4041
- posInSet,
4042
- setSize,
4043
- icon,
4044
- name,
4045
- path,
4046
- depth,
4047
- indent,
4084
+ ariaExpanded,
4048
4085
  chevron,
4049
- id,
4050
4086
  className,
4087
+ depth,
4088
+ hasEditingError,
4089
+ icon,
4090
+ id,
4091
+ indent,
4051
4092
  isEditing,
4052
- ariaExpanded,
4053
- hasEditingError
4093
+ name,
4094
+ path,
4095
+ setSize,
4096
+ posInSet
4054
4097
  } = item;
4055
4098
  const chevronDom = getChevronVirtualDom(chevron);
4056
- const dom = [{
4099
+ return [{
4057
4100
  type: Div,
4058
4101
  role: TreeItem$1,
4059
4102
  className,
@@ -4069,7 +4112,6 @@ const getExplorerItemVirtualDom = item => {
4069
4112
  ariaDescription: '',
4070
4113
  id
4071
4114
  }, ...chevronDom, getFileIconVirtualDom(icon), ...getInputOrLabelDom(isEditing, hasEditingError, name)];
4072
- return dom;
4073
4115
  };
4074
4116
 
4075
4117
  const getExplorerWelcomeVirtualDom = isWide => {
@@ -4100,7 +4142,7 @@ const getActiveDescendant = focusedIndex => {
4100
4142
  }
4101
4143
  return undefined;
4102
4144
  };
4103
- const getClassName$1 = (focused, focusedIndex, dropTarget) => {
4145
+ const getClassName = (focused, focusedIndex, dropTarget) => {
4104
4146
  const extraClass1 = focused && focusedIndex === -1 ? FocusOutline : Empty;
4105
4147
  const extraClass2 = dropTarget === dropTargetFull ? ExplorerDropTarget : Empty;
4106
4148
  const className = mergeClassNames(ListItems, extraClass1, extraClass2);
@@ -4118,7 +4160,7 @@ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused
4118
4160
  }
4119
4161
  const dom = [parentNode, {
4120
4162
  type: Div,
4121
- className: getClassName$1(focused, focusedIndex, dropTargets),
4163
+ className: getClassName(focused, focusedIndex, dropTargets),
4122
4164
  tabIndex: 0,
4123
4165
  role: Tree,
4124
4166
  ariaLabel: filesExplorer(),
@@ -4172,6 +4214,18 @@ const getExpandedType = type => {
4172
4214
  }
4173
4215
  };
4174
4216
 
4217
+ const focused = mergeClassNames(TreeItem, TreeItemActive);
4218
+ const selected = mergeClassNames(TreeItem, TreeItemActive);
4219
+ const getTreeItemClassName = (isSelected, isFocused) => {
4220
+ if (isFocused) {
4221
+ return focused;
4222
+ }
4223
+ if (isSelected) {
4224
+ return selected;
4225
+ }
4226
+ return TreeItem;
4227
+ };
4228
+
4175
4229
  const defaultIndent$1 = 1;
4176
4230
  const getTreeItemIndent = depth => {
4177
4231
  return `${depth * defaultIndent$1}rem`;
@@ -4190,14 +4244,15 @@ const getTreeItemIndentWithChevron = (depth, chevron) => {
4190
4244
  };
4191
4245
 
4192
4246
  const ariaExpandedValues = [undefined, 'true', 'false'];
4193
- const getClassName = (isSelected, isFocused) => {
4194
- if (isFocused) {
4195
- return mergeClassNames(TreeItem, TreeItemActive);
4196
- }
4197
- if (isSelected) {
4198
- return mergeClassNames(TreeItem, TreeItemActive);
4247
+ const getEditingChevron = direntType => {
4248
+ switch (direntType) {
4249
+ case EditingDirectoryExpanded:
4250
+ return Down;
4251
+ case EditingFolder:
4252
+ return Right;
4253
+ default:
4254
+ return None$1;
4199
4255
  }
4200
- return TreeItem;
4201
4256
  };
4202
4257
  const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editingIndex, editingType, editingValue, editingErrorMessage, icons, useChevrons, dropTargets, editingIcon) => {
4203
4258
  const visible = [];
@@ -4205,19 +4260,20 @@ const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editin
4205
4260
  let iconIndex = 0;
4206
4261
  for (let i = minLineY; i < Math.min(maxLineY, items.length); i++) {
4207
4262
  const item = items[i];
4208
- const chevron = getChevronType(item.type, useChevrons);
4209
- const indent = indentFn(item.depth, chevron);
4263
+ let chevron = getChevronType(item.type, useChevrons);
4210
4264
  const isFocused = i === focusedIndex;
4211
4265
  const id = isFocused ? 'TreeItemActive' : undefined;
4212
4266
  const isSelected = item.selected;
4213
- const className = getClassName(isSelected, isFocused);
4267
+ const className = getTreeItemClassName(isSelected, isFocused);
4214
4268
  const expanded = getExpandedType(item.type);
4215
4269
  const ariaExpanded = ariaExpandedValues[expanded];
4216
4270
  const isEditing = i === editingIndex;
4217
4271
  let icon = icons[iconIndex++];
4218
4272
  if (isEditing) {
4219
4273
  icon = editingIcon;
4274
+ chevron = getEditingChevron(item.type);
4220
4275
  }
4276
+ const indent = indentFn(item.depth, chevron);
4221
4277
  visible.push({
4222
4278
  ...item,
4223
4279
  posInSet: item.posInSet ?? i + 1,
@@ -4392,7 +4448,11 @@ const renderEventListeners = () => {
4392
4448
  params: ['handleBlur']
4393
4449
  }, {
4394
4450
  name: HandleClick,
4395
- params: ['handleClickAt', 'event.button', 'event.ctrlKey', 'event.shiftKey', 'event.clientX', 'event.clientY'],
4451
+ params: ['handleClickAt', 'event.defaultPrevented', 'event.button', 'event.ctrlKey', 'event.shiftKey', 'event.clientX', 'event.clientY'],
4452
+ preventDefault: true
4453
+ }, {
4454
+ name: HandleInputClick,
4455
+ params: ['handleInputClick'],
4396
4456
  preventDefault: true
4397
4457
  }, {
4398
4458
  name: HandleClickOpenFolder,
@@ -4797,7 +4857,6 @@ const commandMap = {
4797
4857
  'Explorer.acceptEdit': wrapCommand(acceptEdit),
4798
4858
  'Explorer.cancelEdit': wrapCommand(cancelEdit),
4799
4859
  'Explorer.collapseAll': wrapCommand(collapseAll),
4800
- 'Explorer.handleInputBlur': wrapCommand(handleInputBlur),
4801
4860
  'Explorer.copyPath': wrapCommand(copyPath),
4802
4861
  'Explorer.copyRelativePath': wrapCommand(copyRelativePath),
4803
4862
  'Explorer.expandAll': wrapCommand(expandAll),
@@ -4827,6 +4886,8 @@ const commandMap = {
4827
4886
  'Explorer.handleDrop': wrapCommand(handleDrop),
4828
4887
  'Explorer.handleFocus': wrapCommand(handleFocus),
4829
4888
  'Explorer.handleIconThemeChange': wrapCommand(handleIconThemeChange),
4889
+ 'Explorer.handleInputBlur': wrapCommand(handleInputBlur),
4890
+ 'Explorer.handleInputClick': wrapCommand(handleInputClick),
4830
4891
  'Explorer.handlePaste': wrapCommand(handlePaste),
4831
4892
  'Explorer.handlePointerDown': wrapCommand(handlePointerDown),
4832
4893
  'Explorer.handleUpload': wrapCommand(handleUpload),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.25.0",
3
+ "version": "2.27.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",