@lvce-editor/explorer-view 1.9.0 → 1.11.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.
@@ -320,14 +320,14 @@ const readyMessage = 'ready';
320
320
  const getData$2 = event => {
321
321
  return event.data;
322
322
  };
323
- const listen$6 = () => {
323
+ const listen$7 = () => {
324
324
  // @ts-ignore
325
325
  if (typeof WorkerGlobalScope === 'undefined') {
326
326
  throw new TypeError('module is not in web worker scope');
327
327
  }
328
328
  return globalThis;
329
329
  };
330
- const signal$6 = global => {
330
+ const signal$7 = global => {
331
331
  global.postMessage(readyMessage);
332
332
  };
333
333
  class IpcChildWithModuleWorker extends Ipc {
@@ -353,7 +353,7 @@ class IpcChildWithModuleWorker extends Ipc {
353
353
  this._rawIpc.addEventListener('message', callback);
354
354
  }
355
355
  }
356
- const wrap$d = global => {
356
+ const wrap$e = global => {
357
357
  return new IpcChildWithModuleWorker(global);
358
358
  };
359
359
  const withResolvers = () => {
@@ -378,10 +378,10 @@ const waitForFirstMessage = async port => {
378
378
  // @ts-ignore
379
379
  return event.data;
380
380
  };
381
- const listen$5 = async () => {
382
- const parentIpcRaw = listen$6();
383
- signal$6(parentIpcRaw);
384
- const parentIpc = wrap$d(parentIpcRaw);
381
+ const listen$6 = async () => {
382
+ const parentIpcRaw = listen$7();
383
+ signal$7(parentIpcRaw);
384
+ const parentIpc = wrap$e(parentIpcRaw);
385
385
  const firstMessage = await waitForFirstMessage(parentIpc);
386
386
  if (firstMessage.method !== 'initialize') {
387
387
  throw new IpcError('unexpected first message');
@@ -426,13 +426,13 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
426
426
  this._rawIpc.start();
427
427
  }
428
428
  }
429
- const wrap$c = port => {
429
+ const wrap$d = port => {
430
430
  return new IpcChildWithModuleWorkerAndMessagePort(port);
431
431
  };
432
432
  const IpcChildWithModuleWorkerAndMessagePort$1 = {
433
433
  __proto__: null,
434
- listen: listen$5,
435
- wrap: wrap$c
434
+ listen: listen$6,
435
+ wrap: wrap$d
436
436
  };
437
437
 
438
438
  const Two = '2.0';
@@ -2167,23 +2167,24 @@ const getMenuEntries = state => {
2167
2167
  }
2168
2168
  };
2169
2169
 
2170
- const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editingIndex, editingType, editingValue) => {
2170
+ const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editingIndex, editingType, editingValue, icons) => {
2171
2171
  const visible = [];
2172
+ let iconIndex = 0;
2172
2173
  for (let i = minLineY; i < Math.min(maxLineY, items.length); i++) {
2173
2174
  const item = items[i];
2175
+ const icon = icons[iconIndex++];
2174
2176
  if (i === editingIndex) {
2175
2177
  visible.push({
2176
2178
  ...item,
2177
2179
  isFocused: i === focusedIndex,
2178
2180
  isEditing: true,
2179
- icon: getFileIcon$1({
2180
- name: editingValue
2181
- })
2181
+ icon
2182
2182
  });
2183
2183
  } else {
2184
2184
  visible.push({
2185
2185
  ...item,
2186
- isFocused: i === focusedIndex
2186
+ isFocused: i === focusedIndex,
2187
+ icon
2187
2188
  });
2188
2189
  }
2189
2190
  }
@@ -2677,6 +2678,65 @@ const handleCopy = async state => {
2677
2678
  return state;
2678
2679
  };
2679
2680
 
2681
+ const canBeDroppedInto = dirent => {
2682
+ if (!dirent) {
2683
+ return false;
2684
+ }
2685
+ switch (dirent.type) {
2686
+ case Directory:
2687
+ case DirectoryExpanded:
2688
+ case DirectoryExpanding:
2689
+ return true;
2690
+ default:
2691
+ return false;
2692
+ }
2693
+ };
2694
+
2695
+ const getNewDropTargets = (state, x, y) => {
2696
+ const {
2697
+ items
2698
+ } = state;
2699
+ const index = getIndexFromPosition(state, x, y);
2700
+ if (index === -1) {
2701
+ return [-1];
2702
+ }
2703
+ const item = items[index];
2704
+ if (!canBeDroppedInto(item)) {
2705
+ return [];
2706
+ }
2707
+ const newDropTargets = [index];
2708
+ return newDropTargets;
2709
+ };
2710
+
2711
+ const isEqual = (a, b) => {
2712
+ if (a.length !== b.length) {
2713
+ return false;
2714
+ }
2715
+ const length = a.length;
2716
+ for (let i = 0; i < length; i++) {
2717
+ if (a[i] !== b[i]) {
2718
+ return false;
2719
+ }
2720
+ }
2721
+ return true;
2722
+ };
2723
+
2724
+ const handleDragOver = (state, x, y) => {
2725
+ number(x);
2726
+ number(y);
2727
+ const {
2728
+ dropTargets
2729
+ } = state;
2730
+ const newDropTargets = getNewDropTargets(state, x, y);
2731
+ if (isEqual(dropTargets, newDropTargets)) {
2732
+ return state;
2733
+ }
2734
+ return {
2735
+ ...state,
2736
+ dropTargets: newDropTargets
2737
+ };
2738
+ };
2739
+
2680
2740
  const getFilePathElectron = async file => {
2681
2741
  return invoke('GetFilePathElectron.getFilePathElectron', file);
2682
2742
  };
@@ -3308,6 +3368,57 @@ const renameDirent = state => {
3308
3368
  };
3309
3369
  };
3310
3370
 
3371
+ const renderItems = {
3372
+ isEqual(oldState, newState) {
3373
+ 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;
3374
+ },
3375
+ apply(oldState, newState) {
3376
+ const visibleDirents = getVisibleExplorerItems(newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex, newState.editingIndex, newState.editingType, newState.editingValue, newState.icons);
3377
+ const isWide = newState.width > 450;
3378
+ const dom = getExplorerVirtualDom(visibleDirents, newState.focusedIndex, newState.root, isWide);
3379
+ return ['Viewlet.setDom2', dom];
3380
+ }
3381
+ };
3382
+
3383
+ // const renderFocusedIndex = {
3384
+ // isEqual(oldState:any, newState:any) {
3385
+ // return oldState.focusedIndex === newState.focusedIndex && oldState.focused === newState.focused && oldState.minLineY === newState.minLineY
3386
+ // },
3387
+ // apply(oldState:any, newState:any) {
3388
+ // const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY
3389
+ // const newFocusedIndex = newState.focusedIndex - newState.minLineY
3390
+ // return [/* method */ 'setFocusedIndex', /* oldindex */ oldFocusedIndex, /* newIndex */ newFocusedIndex, /* focused */ newState.focused]
3391
+ // },
3392
+ // }
3393
+
3394
+ // const renderDropTargets = {
3395
+ // isEqual(oldState:any, newState:any) {
3396
+ // return oldState.dropTargets === newState.dropTargets
3397
+ // },
3398
+ // apply(oldState:any, newState:any) {
3399
+ // return [/* method */ 'setDropTargets', /* oldDropTargets */ oldState.dropTargets, /* newDropTargets */ newState.dropTargets]
3400
+ // },
3401
+ // }
3402
+
3403
+ const renderEditingIndex = {
3404
+ isEqual(oldState, newState) {
3405
+ return oldState.editingIndex === newState.editingIndex && oldState.editingType === newState.editingType;
3406
+ },
3407
+ apply(oldState, newState) {
3408
+ return ['focusInput', 'ExplorerInput'];
3409
+ }
3410
+ };
3411
+ const render = [renderItems, renderEditingIndex];
3412
+ const doRender = (oldState, newState) => {
3413
+ const commands = [];
3414
+ for (const fn of render) {
3415
+ if (!fn.isEqual(oldState, newState)) {
3416
+ commands.push(fn.apply(oldState, newState));
3417
+ }
3418
+ }
3419
+ return commands;
3420
+ };
3421
+
3311
3422
  const getIconVirtualDom = (icon, type = Div) => {
3312
3423
  return {
3313
3424
  type,
@@ -3694,6 +3805,7 @@ const commandMap = {
3694
3805
  'Explorer.handleClickOpenFolder': handleClickOpenFolder,
3695
3806
  'Explorer.handleContextMenu': handleContextMenu,
3696
3807
  'Explorer.handleCopy': handleCopy,
3808
+ 'Explorer.handleDragOver': handleDragOver,
3697
3809
  'Explorer.handleDrop': handleDrop,
3698
3810
  'Explorer.handleIconThemeChange': handleIconThemeChange,
3699
3811
  'Explorer.handlePaste': handlePaste,
@@ -3707,6 +3819,7 @@ const commandMap = {
3707
3819
  'Explorer.openContainingFolder': openContainingFolder,
3708
3820
  'Explorer.removeDirent': removeDirent,
3709
3821
  'Explorer.renameDirent': renameDirent,
3822
+ 'Explorer.render': doRender,
3710
3823
  'Explorer.renderActions': renderActions,
3711
3824
  'Explorer.restoreState': restoreState,
3712
3825
  'Explorer.revealItem': revealItem,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "Explorer Worker",
5
5
  "main": "dist/explorerViewWorkerMain.js",
6
6
  "type": "module",