@lvce-editor/explorer-view 1.13.0 → 1.16.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.
@@ -1005,7 +1005,7 @@ const computeExplorerRenamedDirent = (dirents, index, newName) => {
1005
1005
  };
1006
1006
  };
1007
1007
 
1008
- const None$3 = 0;
1008
+ const None$5 = 0;
1009
1009
  const CreateFile = 1;
1010
1010
  const CreateFolder = 2;
1011
1011
  const Rename$1 = 3;
@@ -1155,7 +1155,7 @@ const acceptCreate = async (state, newDirentType, createFn) => {
1155
1155
  items: newDirents,
1156
1156
  editingIndex: -1,
1157
1157
  focusedIndex: insertIndex + 1,
1158
- editingType: None$3,
1158
+ editingType: None$5,
1159
1159
  maxLineY: newMaxlineY
1160
1160
  };
1161
1161
  };
@@ -1189,7 +1189,7 @@ const acceptRename = async state => {
1189
1189
  ...state,
1190
1190
  editingIndex: -1,
1191
1191
  editingValue: '',
1192
- editingType: None$3,
1192
+ editingType: None$5,
1193
1193
  editingIcon: '',
1194
1194
  focusedIndex,
1195
1195
  focused: true
@@ -1221,7 +1221,7 @@ const cancelEdit = state => {
1221
1221
  focused: true,
1222
1222
  editingIndex: -1,
1223
1223
  editingValue: '',
1224
- editingType: None$3
1224
+ editingType: None$5
1225
1225
  };
1226
1226
  };
1227
1227
 
@@ -1740,7 +1740,7 @@ const getActions = root => {
1740
1740
  }];
1741
1741
  };
1742
1742
 
1743
- const None$2 = 'none';
1743
+ const None$4 = 'none';
1744
1744
  const ToolBar = 'toolbar';
1745
1745
  const Tree = 'tree';
1746
1746
  const TreeItem$1 = 'treeitem';
@@ -1764,6 +1764,7 @@ const HandleBlur = 'handleBlur';
1764
1764
  const HandleClick = 'handleClick';
1765
1765
  const handleClickOpenFolder$1 = 'handleClickOpenFolder';
1766
1766
  const HandleContextMenu = 'handleContextMenu';
1767
+ const HandleEditingInput = 'handleEditingInput';
1767
1768
  const HandleFocus = 'handleFocus';
1768
1769
  const HandlePointerDown = 'handlePointerDown';
1769
1770
  const HandleWheel = 'handleWheel';
@@ -1775,12 +1776,29 @@ const Text = 12;
1775
1776
  const Img = 17;
1776
1777
  const P = 50;
1777
1778
 
1779
+ const chevronDownVirtualDom = {
1780
+ type: Div,
1781
+ className: `${Chevron} MaskIconChevronDown`,
1782
+ childCount: 0
1783
+ };
1784
+
1785
+ const chevronRightVirtualDom = {
1786
+ type: Div,
1787
+ className: `${Chevron} MaskIconChevronRight`,
1788
+ childCount: 0
1789
+ };
1790
+
1791
+ const chevronDomNodes = [[], [chevronRightVirtualDom], [chevronDownVirtualDom]];
1792
+ const getChevronVirtualDom = chevronType => {
1793
+ return chevronDomNodes[chevronType];
1794
+ };
1795
+
1778
1796
  const getFileIconVirtualDom = icon => {
1779
1797
  return {
1780
1798
  type: Img,
1781
1799
  className: FileIcon,
1782
1800
  src: icon,
1783
- role: None$2,
1801
+ role: None$4,
1784
1802
  childCount: 0
1785
1803
  };
1786
1804
  };
@@ -1795,76 +1813,26 @@ const text = data => {
1795
1813
  };
1796
1814
  };
1797
1815
 
1798
- const getItemVirtualDomFile = item => {
1799
- const {
1800
- posInSet,
1801
- setSize,
1802
- icon,
1803
- name,
1804
- path,
1805
- depth,
1806
- isFocused,
1807
- isEditing,
1808
- indent
1809
- } = item;
1810
-
1811
- // TODO avoid mutation
1812
- const dom = [];
1813
- dom.push({
1814
- type: Div,
1815
- role: TreeItem$1,
1816
- className: TreeItem,
1817
- draggable: true,
1818
- title: path,
1819
- ariaPosInSet: posInSet,
1820
- ariaSetSize: setSize,
1821
- ariaLevel: depth,
1822
- childCount: 2,
1823
- paddingLeft: indent,
1824
- ariaLabel: name,
1825
- ariaDescription: ''
1826
- }, getFileIconVirtualDom(icon));
1816
+ const label = {
1817
+ type: Div,
1818
+ className: Label,
1819
+ childCount: 1
1820
+ };
1821
+ const getInputOrLabelDom = (isEditing, name) => {
1827
1822
  if (isEditing) {
1828
- dom.push({
1823
+ return [{
1829
1824
  type: Input,
1830
1825
  className: InputBox,
1831
1826
  id: 'ExplorerInput',
1832
- onInput: 'handleEditingInput',
1827
+ onInput: HandleEditingInput,
1833
1828
  childCount: 0,
1834
1829
  name: ExplorerInput
1835
- });
1836
- } else {
1837
- dom.push({
1838
- type: Div,
1839
- className: Label,
1840
- childCount: 1
1841
- }, text(name));
1842
- }
1843
- if (isFocused) {
1844
- // @ts-ignore
1845
- dom[0].id = 'TreeItemActive';
1846
- // @ts-ignore
1847
- dom[0].className += ' ' + TreeItemActive;
1830
+ }];
1848
1831
  }
1849
- return dom;
1850
- };
1851
-
1852
- const getChevronDownVirtualDom = () => {
1853
- return {
1854
- type: Div,
1855
- className: `${Chevron} MaskIconChevronDown`,
1856
- childCount: 0
1857
- };
1858
- };
1859
- const getChevronRightVirtualDom = () => {
1860
- return {
1861
- type: Div,
1862
- className: `${Chevron} MaskIconChevronRight`,
1863
- childCount: 0
1864
- };
1832
+ return [label, text(name)];
1865
1833
  };
1866
1834
 
1867
- const getItemVirtualDomFolder = item => {
1835
+ const getExplorerItemVirtualDom = item => {
1868
1836
  const {
1869
1837
  posInSet,
1870
1838
  setSize,
@@ -1872,76 +1840,33 @@ const getItemVirtualDomFolder = item => {
1872
1840
  name,
1873
1841
  path,
1874
1842
  depth,
1875
- type,
1876
- isFocused,
1877
- useChevrons,
1878
- indent
1843
+ indent,
1844
+ chevron,
1845
+ id,
1846
+ className,
1847
+ isEditing,
1848
+ ariaExpanded
1879
1849
  } = item;
1880
- let ariaExpanded = '';
1881
- let chevron;
1882
- switch (type) {
1883
- // TODO decide on directory vs folder
1884
- case Directory:
1885
- ariaExpanded = 'false';
1886
- chevron = getChevronRightVirtualDom();
1887
- break;
1888
- case DirectoryExpanding:
1889
- ariaExpanded = 'true'; // TODO tree should be aria-busy then
1890
- chevron = getChevronRightVirtualDom();
1891
- break;
1892
- case DirectoryExpanded:
1893
- ariaExpanded = 'true';
1894
- chevron = getChevronDownVirtualDom();
1895
- break;
1896
- }
1897
- const dom = [];
1898
- dom.push({
1850
+ const chevronDom = getChevronVirtualDom(chevron);
1851
+ const dom = [{
1899
1852
  type: Div,
1900
1853
  role: TreeItem$1,
1901
- className: TreeItem,
1854
+ className,
1902
1855
  draggable: true,
1903
1856
  title: path,
1904
1857
  ariaPosInSet: posInSet,
1905
1858
  ariaSetSize: setSize,
1906
1859
  ariaLevel: depth,
1907
- childCount: 2,
1860
+ childCount: 2 + chevronDom.length,
1908
1861
  paddingLeft: indent,
1909
1862
  ariaLabel: name,
1910
1863
  ariaExpanded,
1911
- ariaDescription: ''
1912
- });
1913
- if (useChevrons) {
1914
- // @ts-ignore
1915
- dom[0].childCount++;
1916
- // @ts-ignore
1917
- dom.push(chevron);
1918
- }
1919
- dom.push(getFileIconVirtualDom(icon), {
1920
- type: Div,
1921
- className: Label,
1922
- childCount: 1
1923
- }, text(name));
1924
- if (isFocused) {
1925
- // @ts-ignore
1926
- dom[0].id = 'TreeItemActive';
1927
- }
1864
+ ariaDescription: '',
1865
+ id
1866
+ }, ...chevronDom, getFileIconVirtualDom(icon), ...getInputOrLabelDom(isEditing, name)];
1928
1867
  return dom;
1929
1868
  };
1930
1869
 
1931
- const getExplorerItemVirtualDom = item => {
1932
- const {
1933
- type
1934
- } = item;
1935
- switch (type) {
1936
- case Directory:
1937
- case DirectoryExpanding:
1938
- case DirectoryExpanded:
1939
- return getItemVirtualDomFolder(item);
1940
- default:
1941
- return getItemVirtualDomFile(item);
1942
- }
1943
- };
1944
-
1945
1870
  const mergeClassNames = (...classNames) => {
1946
1871
  return classNames.filter(Boolean).join(' ');
1947
1872
  };
@@ -1972,9 +1897,7 @@ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide) => {
1972
1897
  if (!root) {
1973
1898
  return getExplorerWelcomeVirtualDom(isWide);
1974
1899
  }
1975
- // TODO
1976
- const dom = [];
1977
- dom.push({
1900
+ const dom = [{
1978
1901
  type: Div,
1979
1902
  className: mergeClassNames(Viewlet, Explorer$1),
1980
1903
  tabIndex: 0,
@@ -1988,8 +1911,7 @@ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide) => {
1988
1911
  onPointerDown: HandlePointerDown,
1989
1912
  onWheel: HandleWheel,
1990
1913
  onClick: HandleClick
1991
- });
1992
- dom.push(...visibleItems.flatMap(getExplorerItemVirtualDom));
1914
+ }, ...visibleItems.flatMap(getExplorerItemVirtualDom)];
1993
1915
  return dom;
1994
1916
  };
1995
1917
 
@@ -2091,7 +2013,7 @@ const getKeyBindings = () => {
2091
2013
  };
2092
2014
 
2093
2015
  const Separator = 1;
2094
- const None$1 = 0;
2016
+ const None$3 = 0;
2095
2017
  const RestoreFocus = 6;
2096
2018
 
2097
2019
  const menuEntrySeparator = {
@@ -2104,13 +2026,13 @@ const menuEntrySeparator = {
2104
2026
  const menuEntryNewFile = {
2105
2027
  id: 'newFile',
2106
2028
  label: newFile$1(),
2107
- flags: None$1,
2029
+ flags: None$3,
2108
2030
  command: 'Explorer.newFile'
2109
2031
  };
2110
2032
  const menuEntryNewFolder = {
2111
2033
  id: 'newFolder',
2112
2034
  label: newFolder$1(),
2113
- flags: None$1,
2035
+ flags: None$3,
2114
2036
  command: 'Explorer.newFolder'
2115
2037
  };
2116
2038
  const menuEntryOpenContainingFolder = {
@@ -2122,7 +2044,7 @@ const menuEntryOpenContainingFolder = {
2122
2044
  const menuEntryOpenInIntegratedTerminal = {
2123
2045
  id: 'openInIntegratedTerminal',
2124
2046
  label: openInIntegratedTerminal(),
2125
- flags: None$1,
2047
+ flags: None$3,
2126
2048
  command: /* TODO */-1
2127
2049
  };
2128
2050
  const menuEntryCut = {
@@ -2140,7 +2062,7 @@ const menuEntryCopy = {
2140
2062
  const menuEntryPaste = {
2141
2063
  id: 'paste',
2142
2064
  label: paste(),
2143
- flags: None$1,
2065
+ flags: None$3,
2144
2066
  command: 'Explorer.handlePaste'
2145
2067
  };
2146
2068
  const menuEntryCopyPath = {
@@ -2158,13 +2080,13 @@ const menuEntryCopyRelativePath = {
2158
2080
  const menuEntryRename = {
2159
2081
  id: 'rename',
2160
2082
  label: rename(),
2161
- flags: None$1,
2083
+ flags: None$3,
2162
2084
  command: 'Explorer.renameDirent'
2163
2085
  };
2164
2086
  const menuEntryDelete = {
2165
2087
  id: 'delete',
2166
2088
  label: deleteItem(),
2167
- flags: None$1,
2089
+ flags: None$3,
2168
2090
  command: 'Explorer.removeDirent'
2169
2091
  };
2170
2092
  const ALL_ENTRIES = [menuEntryNewFile, menuEntryNewFolder, menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntryRename, menuEntryDelete];
@@ -2205,51 +2127,98 @@ const getMenuEntries = state => {
2205
2127
  }
2206
2128
  };
2207
2129
 
2208
- const defaultIndent = 1;
2130
+ const None$2 = 0;
2131
+ const Right = 1;
2132
+ const Down = 2;
2133
+
2134
+ const getChevronType = (type, useChevrons) => {
2135
+ if (!useChevrons) {
2136
+ return None$2;
2137
+ }
2138
+ switch (type) {
2139
+ case Directory:
2140
+ return Right;
2141
+ case DirectoryExpanded:
2142
+ case DirectoryExpanding:
2143
+ return Down;
2144
+ default:
2145
+ return None$2;
2146
+ }
2147
+ };
2148
+
2149
+ const None$1 = 0;
2150
+ const Expanded = 1;
2151
+ const Collapsed = 2;
2152
+
2153
+ const getExpandedType = type => {
2154
+ switch (type) {
2155
+ case Directory:
2156
+ return Collapsed;
2157
+ case DirectoryExpanding:
2158
+ case DirectoryExpanded:
2159
+ return Expanded;
2160
+ default:
2161
+ return None$1;
2162
+ }
2163
+ };
2164
+
2165
+ const defaultIndent$1 = 1;
2209
2166
  const getTreeItemIndent = depth => {
2210
- // TODO logic should be in getVisibleItems
2211
- return `${depth * defaultIndent}rem`;
2167
+ return `${depth * defaultIndent$1}rem`;
2212
2168
  };
2213
2169
 
2170
+ // TODO make all of these variable configurable
2171
+ const defaultPaddingLeft = 4;
2172
+ const defaultIndent = 8;
2173
+
2174
+ // TODO make chevron size configurable
2175
+ const chevronSize = 22;
2176
+ const getTreeItemIndentWithChevron = (depth, chevron) => {
2177
+ // TODO use numeric value here, convert to string value in renderer process
2178
+ const extraSpace = chevron ? 0 : chevronSize;
2179
+ return `${depth * defaultIndent + extraSpace + defaultPaddingLeft}px`;
2180
+ };
2181
+
2182
+ const ariaExpandedValues = [undefined, 'true', 'false'];
2214
2183
  const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editingIndex, editingType, editingValue, icons, useChevrons) => {
2215
2184
  const visible = [];
2185
+ const indentFn = useChevrons ? getTreeItemIndentWithChevron : getTreeItemIndent;
2216
2186
  let iconIndex = 0;
2217
2187
  for (let i = minLineY; i < Math.min(maxLineY, items.length); i++) {
2218
2188
  const item = items[i];
2219
2189
  const icon = icons[iconIndex++];
2220
- const indent = getTreeItemIndent(item.depth);
2221
- if (i === editingIndex) {
2222
- visible.push({
2223
- ...item,
2224
- isFocused: i === focusedIndex,
2225
- isEditing: true,
2226
- icon,
2227
- useChevrons,
2228
- indent
2229
- });
2230
- } else {
2231
- visible.push({
2232
- ...item,
2233
- isFocused: i === focusedIndex,
2234
- icon,
2235
- useChevrons,
2236
- indent
2237
- });
2238
- }
2190
+ const chevron = getChevronType(item.type, useChevrons);
2191
+ const indent = indentFn(item.depth, chevron);
2192
+ const isFocused = i === focusedIndex;
2193
+ const id = isFocused ? 'TreeItemActive' : undefined;
2194
+ const className = isFocused ? TreeItem + ' ' + TreeItemActive : TreeItem;
2195
+ const expanded = getExpandedType(item.type);
2196
+ const ariaExpanded = ariaExpandedValues[expanded];
2197
+ visible.push({
2198
+ ...item,
2199
+ isEditing: i === editingIndex,
2200
+ icon,
2201
+ indent,
2202
+ ariaExpanded,
2203
+ chevron,
2204
+ id,
2205
+ className
2206
+ });
2239
2207
  }
2240
- if (editingType !== None$3 && editingIndex === -1) {
2208
+ if (editingType !== None$5 && editingIndex === -1) {
2241
2209
  visible.push({
2242
2210
  depth: 3,
2243
2211
  posInSet: 1,
2244
2212
  setSize: 1,
2245
2213
  icon: '',
2246
- isFocused: false,
2247
2214
  name: 'new',
2248
2215
  path: '/test/new',
2249
- type: 2,
2250
2216
  isEditing: true,
2251
- useChevrons,
2252
- indent: ''
2217
+ indent: '',
2218
+ ariaExpanded: undefined,
2219
+ chevron: 0,
2220
+ id: undefined,
2221
+ className: TreeItem
2253
2222
  });
2254
2223
  }
2255
2224
  return visible;
@@ -2261,7 +2230,7 @@ const handleBlur = state => {
2261
2230
  const {
2262
2231
  editingType
2263
2232
  } = state;
2264
- if (editingType !== None$3) {
2233
+ if (editingType !== None$5) {
2265
2234
  return state;
2266
2235
  }
2267
2236
  return {
@@ -3243,7 +3212,8 @@ const getSavedRoot$1 = (savedState, workspacePath) => {
3243
3212
  return workspacePath;
3244
3213
  };
3245
3214
  const loadContent = async (state, savedState) => {
3246
- const useChevrons = true;
3215
+ const useChevronsRaw = await invoke('Preferences.get', 'explorer.useChevrons');
3216
+ const useChevrons = Boolean(useChevronsRaw);
3247
3217
  const workspacePath = await getWorkspacePath();
3248
3218
  const root = getSavedRoot$1(savedState, workspacePath);
3249
3219
  // TODO path separator could be restored from saved state
@@ -3432,11 +3402,7 @@ const renderItems = {
3432
3402
  return JSON.stringify(oldState.items) === JSON.stringify(newState.items) && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.focusedIndex === newState.focusedIndex && oldState.editingIndex === newState.editingIndex && oldState.editingType === newState.editingType && oldState.editingValue === newState.editingValue && oldState.width === newState.width;
3433
3403
  },
3434
3404
  apply(oldState, newState) {
3435
- const visibleDirents = getVisibleExplorerItems(newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex, newState.editingIndex, newState.editingType, newState.editingValue,
3436
- // @ts-ignore
3437
- newState.icons,
3438
- // @ts-ignore
3439
- newState.useChevrons);
3405
+ const visibleDirents = getVisibleExplorerItems(newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex, newState.editingIndex, newState.editingType, newState.editingValue, newState.icons, newState.useChevrons);
3440
3406
  const isWide = newState.width > 450;
3441
3407
  const dom = getExplorerVirtualDom(visibleDirents, newState.focusedIndex, newState.root, isWide);
3442
3408
  return ['Viewlet.setDom2', dom];
@@ -3486,7 +3452,7 @@ const getIconVirtualDom = (icon, type = Div) => {
3486
3452
  return {
3487
3453
  type,
3488
3454
  className: `MaskIcon MaskIcon${icon}`,
3489
- role: None$2,
3455
+ role: None$4,
3490
3456
  childCount: 0
3491
3457
  };
3492
3458
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "1.13.0",
3
+ "version": "1.16.0",
4
4
  "description": "Explorer Worker",
5
5
  "main": "dist/explorerViewWorkerMain.js",
6
6
  "type": "module",