@lvce-editor/activity-bar-worker 7.27.0 → 7.27.1

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.
@@ -249,7 +249,7 @@ const {
249
249
  get: get$2,
250
250
  getCommandIds,
251
251
  registerCommands,
252
- set: set$5,
252
+ set: set$6,
253
253
  wrapAsyncCommand,
254
254
  wrapCommand,
255
255
  wrapGetter
@@ -261,6 +261,7 @@ const create$9 = (id, uri, x, y, width, height, args, parentUid, platform = 0) =
261
261
  accountEnabled: true,
262
262
  activityBarItems: [],
263
263
  currentViewletId: '',
264
+ dragAndDropEnabled: false,
264
265
  filteredItems: [],
265
266
  focus: 0,
266
267
  focused: false,
@@ -284,7 +285,7 @@ const create$9 = (id, uri, x, y, width, height, args, parentUid, platform = 0) =
284
285
  x,
285
286
  y
286
287
  };
287
- set$5(id, state, state);
288
+ set$6(id, state, state);
288
289
  return state;
289
290
  };
290
291
 
@@ -297,16 +298,20 @@ const getCustomIconSignature = items => {
297
298
  }).filter(Boolean).join('\n');
298
299
  };
299
300
 
300
- const isEqual$2 = (oldState, newState) => {
301
+ const isEqual$3 = (oldState, newState) => {
301
302
  return oldState.itemHeight === newState.itemHeight && getCustomIconSignature(oldState.filteredItems) === getCustomIconSignature(newState.filteredItems);
302
303
  };
303
304
 
305
+ const isEqual$2 = (oldState, newState) => {
306
+ return oldState.draggedItemId === newState.draggedItemId;
307
+ };
308
+
304
309
  const isEqual$1 = (oldState, newState) => {
305
310
  return oldState.focused === newState.focused && oldState.focus === newState.focus;
306
311
  };
307
312
 
308
313
  const isEqual = (oldState, newState) => {
309
- return oldState.activityBarItems === newState.activityBarItems && oldState.filteredItems === newState.filteredItems && oldState.focused === newState.focused && oldState.focusedIndex === newState.focusedIndex && oldState.sideBarLocation === newState.sideBarLocation && oldState.sideBarVisible === newState.sideBarVisible && oldState.updateProgress === newState.updateProgress && oldState.updateState === newState.updateState;
314
+ return oldState.activityBarItems === newState.activityBarItems && oldState.dragAndDropEnabled === newState.dragAndDropEnabled && oldState.draggedItemId === newState.draggedItemId && oldState.dropIndicator === newState.dropIndicator && oldState.filteredItems === newState.filteredItems && oldState.focused === newState.focused && oldState.focusedIndex === newState.focusedIndex && oldState.sideBarLocation === newState.sideBarLocation && oldState.sideBarVisible === newState.sideBarVisible && oldState.updateProgress === newState.updateProgress && oldState.updateState === newState.updateState;
310
315
  };
311
316
 
312
317
  const RenderItems = 4;
@@ -314,9 +319,10 @@ const RenderFocus = 6;
314
319
  const RenderFocusContext = 7;
315
320
  const RenderCss = 11;
316
321
  const RenderIncremental = 12;
322
+ const RenderDragData = 13;
317
323
 
318
- const modules = [isEqual, isEqual$1, isEqual$1, isEqual$2];
319
- const numbers = [RenderIncremental, RenderFocus, RenderFocusContext, RenderCss];
324
+ const modules = [isEqual, isEqual$1, isEqual$1, isEqual$3, isEqual$2];
325
+ const numbers = [RenderIncremental, RenderFocus, RenderFocusContext, RenderCss, RenderDragData];
320
326
 
321
327
  const diff2 = uid => {
322
328
  return diff(uid, modules, numbers);
@@ -593,6 +599,7 @@ const LeftClick = 0;
593
599
 
594
600
  const Electron = 2;
595
601
 
602
+ const DragAndDropWorker = 3404;
596
603
  const ExtensionManagementWorker = 9006;
597
604
  const RendererProcess = 1670;
598
605
  const RendererWorker = 1;
@@ -1495,6 +1502,9 @@ const restoreExistingError = (error, currentStack) => {
1495
1502
  };
1496
1503
  const restoreMethodNotFoundError = (error, currentStack) => {
1497
1504
  const restoredError = new JsonRpcError(error.message);
1505
+ Object.assign(restoredError, {
1506
+ code: error.code
1507
+ });
1498
1508
  const parentStack = getParentStack(error);
1499
1509
  setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
1500
1510
  return restoredError;
@@ -1514,9 +1524,13 @@ const applyDataProperties = (restoredError, error) => {
1514
1524
  // @ts-ignore
1515
1525
  restoredError.codeFrame = error.data.codeFrame;
1516
1526
  }
1517
- if (error.data.code) {
1527
+ if (typeof error.data.code === 'string' || typeof error.data.code === 'number') {
1518
1528
  // @ts-ignore
1519
- restoredError.code = error.data.code;
1529
+ Object.defineProperty(restoredError, 'code', {
1530
+ configurable: true,
1531
+ value: error.data.code,
1532
+ writable: true
1533
+ });
1520
1534
  }
1521
1535
  if (error.data.type) {
1522
1536
  // @ts-ignore
@@ -1538,6 +1552,13 @@ const applyDirectProperties = (restoredError, error) => {
1538
1552
  };
1539
1553
  const restoreMessageError = (error, _currentStack) => {
1540
1554
  const restoredError = constructError(error.message, error.type, error.name);
1555
+ if (typeof error.code === 'string' || typeof error.code === 'number') {
1556
+ Object.defineProperty(restoredError, 'code', {
1557
+ configurable: true,
1558
+ value: error.code,
1559
+ writable: true
1560
+ });
1561
+ }
1541
1562
  if (error.data) {
1542
1563
  applyDataProperties(restoredError, error);
1543
1564
  } else {
@@ -1616,7 +1637,7 @@ const getErrorProperty = (error, prettyError) => {
1616
1637
  return {
1617
1638
  code: Custom,
1618
1639
  data: {
1619
- code: prettyError.code,
1640
+ code: prettyError.code ?? error?.code,
1620
1641
  codeFrame: prettyError.codeFrame,
1621
1642
  name: prettyError.name,
1622
1643
  stack: getStack(prettyError),
@@ -1653,7 +1674,12 @@ const getErrorResponseSimple = (id, error) => {
1653
1674
  return {
1654
1675
  error: {
1655
1676
  code: Custom,
1656
- data: error,
1677
+ data: error instanceof Error ? {
1678
+ ...error,
1679
+ code: 'code' in error ? error.code : undefined,
1680
+ stack: error.stack,
1681
+ type: error.name
1682
+ } : error,
1657
1683
  // @ts-ignore
1658
1684
  message: error.message
1659
1685
  },
@@ -1967,7 +1993,7 @@ const createMockRpc = ({
1967
1993
  };
1968
1994
 
1969
1995
  const rpcs = Object.create(null);
1970
- const set$4 = (id, rpc) => {
1996
+ const set$5 = (id, rpc) => {
1971
1997
  rpcs[id] = rpc;
1972
1998
  };
1973
1999
  const get = id => {
@@ -2000,7 +2026,7 @@ const create = rpcId => {
2000
2026
  const mockRpc = createMockRpc({
2001
2027
  commandMap
2002
2028
  });
2003
- set$4(rpcId, mockRpc);
2029
+ set$5(rpcId, mockRpc);
2004
2030
  // @ts-ignore
2005
2031
  mockRpc[Symbol.dispose] = () => {
2006
2032
  remove(rpcId);
@@ -2009,11 +2035,16 @@ const create = rpcId => {
2009
2035
  return mockRpc;
2010
2036
  },
2011
2037
  set(rpc) {
2012
- set$4(rpcId, rpc);
2038
+ set$5(rpcId, rpc);
2013
2039
  }
2014
2040
  };
2015
2041
  };
2016
2042
 
2043
+ const {
2044
+ invoke: invoke$4,
2045
+ set: set$4
2046
+ } = create(DragAndDropWorker);
2047
+
2017
2048
  const {
2018
2049
  invoke: invoke$3,
2019
2050
  set: set$3
@@ -2021,12 +2052,13 @@ const {
2021
2052
 
2022
2053
  const {
2023
2054
  invoke: invoke$2,
2055
+ invokeAndTransfer: invokeAndTransfer$2,
2024
2056
  set: set$2
2025
2057
  } = create(RendererProcess);
2026
2058
 
2027
2059
  const {
2028
2060
  invoke: invoke$1,
2029
- invokeAndTransfer,
2061
+ invokeAndTransfer: invokeAndTransfer$1,
2030
2062
  set: set$1
2031
2063
  } = create(RendererWorker);
2032
2064
  const showContextMenu2 = async (uid, menuId, x, y, args) => {
@@ -2038,7 +2070,7 @@ const showContextMenu2 = async (uid, menuId, x, y, args) => {
2038
2070
  };
2039
2071
  const sendMessagePortToExtensionManagementWorker = async (port, rpcId) => {
2040
2072
  const command = 'Extensions.handleMessagePort';
2041
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
2073
+ await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
2042
2074
  };
2043
2075
 
2044
2076
  const show2 = async (uid, menuId, x, y, args) => {
@@ -2319,14 +2351,14 @@ const handleBlur = state => {
2319
2351
  };
2320
2352
  };
2321
2353
 
2322
- const isBottomItem$1 = item => {
2354
+ const isBottomItem$3 = item => {
2323
2355
  return item.id === 'Account' || item.id === 'Settings';
2324
2356
  };
2325
2357
  const getBottomItemCount = items => {
2326
2358
  if (typeof items === 'number') {
2327
2359
  return items > 1 ? 1 : 0;
2328
2360
  }
2329
- return items.filter(isBottomItem$1).length;
2361
+ return items.filter(isBottomItem$3).length;
2330
2362
  };
2331
2363
  const getItemCount = items => {
2332
2364
  if (typeof items === 'number') {
@@ -2552,6 +2584,163 @@ const handleContextMenu = async (context, button, eventX, eventY) => {
2552
2584
  });
2553
2585
  };
2554
2586
 
2587
+ const handleDragEnd = state => {
2588
+ const {
2589
+ draggedItemId,
2590
+ dropIndicator
2591
+ } = state;
2592
+ if (!draggedItemId && !dropIndicator) {
2593
+ return state;
2594
+ }
2595
+ return {
2596
+ ...state,
2597
+ draggedItemId: undefined,
2598
+ dropIndicator: undefined
2599
+ };
2600
+ };
2601
+
2602
+ const handleDragLeave = state => {
2603
+ const {
2604
+ dropIndicator
2605
+ } = state;
2606
+ if (!dropIndicator) {
2607
+ return state;
2608
+ }
2609
+ return {
2610
+ ...state,
2611
+ dropIndicator: undefined
2612
+ };
2613
+ };
2614
+
2615
+ const isMovableActivityBarItem = item => {
2616
+ return Boolean(item && item.flags & Tab && item.id !== 'Additional Views');
2617
+ };
2618
+
2619
+ const isBottomItem$2 = item => item.id === 'Account' || item.id === 'Settings';
2620
+ const getDropIndicator = (state, clientY) => {
2621
+ const {
2622
+ draggedItemId,
2623
+ filteredItems,
2624
+ itemHeight,
2625
+ y
2626
+ } = state;
2627
+ if (!draggedItemId || !isMovableActivityBarItem(filteredItems.find(item => item.id === draggedItemId))) {
2628
+ return undefined;
2629
+ }
2630
+ const topItems = filteredItems.filter(item => !isBottomItem$2(item));
2631
+ for (let index = 0; index < topItems.length; index++) {
2632
+ const item = topItems[index];
2633
+ const itemY = y + index * itemHeight;
2634
+ if (clientY < itemY || clientY >= itemY + itemHeight) {
2635
+ continue;
2636
+ }
2637
+ if (!isMovableActivityBarItem(item)) {
2638
+ return undefined;
2639
+ }
2640
+ if (item.id === draggedItemId) {
2641
+ return undefined;
2642
+ }
2643
+ const position = clientY < itemY + itemHeight / 2 ? 'before' : 'after';
2644
+ const sourceIndex = topItems.findIndex(candidate => candidate.id === draggedItemId);
2645
+ if (position === 'before' && sourceIndex === index - 1 || position === 'after' && sourceIndex === index + 1) {
2646
+ return undefined;
2647
+ }
2648
+ return {
2649
+ id: item.id,
2650
+ position
2651
+ };
2652
+ }
2653
+ return undefined;
2654
+ };
2655
+ const handleDragOver = (state, clientY) => {
2656
+ const dropIndicator = getDropIndicator(state, clientY);
2657
+ const {
2658
+ dropIndicator: oldIndicator
2659
+ } = state;
2660
+ if (oldIndicator?.id === dropIndicator?.id && oldIndicator?.position === dropIndicator?.position) {
2661
+ return state;
2662
+ }
2663
+ return {
2664
+ ...state,
2665
+ dropIndicator
2666
+ };
2667
+ };
2668
+
2669
+ const handleDragStart = (state, id) => {
2670
+ const {
2671
+ dragAndDropEnabled,
2672
+ filteredItems
2673
+ } = state;
2674
+ if (!dragAndDropEnabled || !isMovableActivityBarItem(filteredItems.find(item => item.id === id))) {
2675
+ return state;
2676
+ }
2677
+ return {
2678
+ ...state,
2679
+ draggedItemId: id,
2680
+ dropIndicator: undefined
2681
+ };
2682
+ };
2683
+
2684
+ const Type = 'application/x-lvce-editor-activity-bar-item';
2685
+ const getData = id => `${Type}:${id}`;
2686
+ const getId = value => {
2687
+ const prefix = `${Type}:`;
2688
+ return value.startsWith(prefix) ? value.slice(prefix.length) : undefined;
2689
+ };
2690
+
2691
+ const reorderActivityBarItems = (items, draggedItemId, targetId, position) => {
2692
+ const sourceIndex = items.findIndex(item => item.id === draggedItemId);
2693
+ const targetIndex = items.findIndex(item => item.id === targetId);
2694
+ if (sourceIndex === -1 || targetIndex === -1 || sourceIndex === targetIndex || !isMovableActivityBarItem(items[sourceIndex]) || !isMovableActivityBarItem(items[targetIndex])) {
2695
+ return items;
2696
+ }
2697
+ const result = [...items];
2698
+ const [source] = result.splice(sourceIndex, 1);
2699
+ const newTargetIndex = result.findIndex(item => item.id === targetId);
2700
+ const insertionIndex = newTargetIndex + (position === 'after' ? 1 : 0);
2701
+ result.splice(insertionIndex, 0, source);
2702
+ return result;
2703
+ };
2704
+
2705
+ const handleDrop = async (context, dropId) => {
2706
+ const state = context.getState();
2707
+ const {
2708
+ activityBarItems: initialActivityBarItems,
2709
+ dragAndDropEnabled,
2710
+ draggedItemId,
2711
+ dropIndicator,
2712
+ filteredItems: initialFilteredItems,
2713
+ focusedIndex: initialFocusedIndex,
2714
+ height,
2715
+ itemHeight,
2716
+ platform,
2717
+ selectedIndex: initialSelectedIndex
2718
+ } = state;
2719
+ const clearState = handleDragEnd(state);
2720
+ if (!dragAndDropEnabled || !draggedItemId || !dropIndicator) {
2721
+ await context.updateState(() => clearState);
2722
+ return;
2723
+ }
2724
+ const isElectron = platform === Electron;
2725
+ const result = await invoke$4('DragAndDrop.getDroppedItemsByDropId', dropId, isElectron);
2726
+ const values = Array.isArray(result?.strings) ? result.strings : [];
2727
+ if (values.length !== 1 || getId(values[0]) !== draggedItemId) {
2728
+ await context.updateState(() => clearState);
2729
+ return;
2730
+ }
2731
+ const activityBarItems = reorderActivityBarItems(initialActivityBarItems, draggedItemId, dropIndicator.id, dropIndicator.position);
2732
+ const filteredItems = getFilteredActivityBarItems(activityBarItems, height, itemHeight);
2733
+ const selectedId = initialActivityBarItems.find(item => item.flags & Selected)?.id;
2734
+ const focusedId = initialFilteredItems[initialFocusedIndex]?.id;
2735
+ await context.updateState(() => ({
2736
+ ...clearState,
2737
+ activityBarItems,
2738
+ filteredItems,
2739
+ focusedIndex: focusedId ? filteredItems.findIndex(item => item.id === focusedId) : initialFocusedIndex,
2740
+ selectedIndex: selectedId ? filteredItems.findIndex(item => item.id === selectedId) : initialSelectedIndex
2741
+ }));
2742
+ };
2743
+
2555
2744
  const commandMap$1 = {};
2556
2745
 
2557
2746
  const handleExtensionManagementMessagePort = async port => {
@@ -2606,6 +2795,18 @@ const toActivityBarItem = view => {
2606
2795
  title: view.title || view.id
2607
2796
  };
2608
2797
  };
2798
+ const isBottomItem$1 = item => item.id === 'Account' || item.id === 'Settings';
2799
+ const applyExistingOrder = (items, existingItems) => {
2800
+ if (existingItems.length === 0) {
2801
+ return items;
2802
+ }
2803
+ const itemsById = new Map(items.map(item => [item.id, item]));
2804
+ const orderedTopItems = existingItems.filter(item => !isBottomItem$1(item)).map(item => itemsById.get(item.id)).filter(item => Boolean(item));
2805
+ const orderedTopIds = new Set(orderedTopItems.map(item => item.id));
2806
+ const newTopItems = items.filter(item => !isBottomItem$1(item) && !orderedTopIds.has(item.id));
2807
+ const bottomItems = items.filter(isBottomItem$1);
2808
+ return [...orderedTopItems, ...newTopItems, ...bottomItems];
2809
+ };
2609
2810
  const getActivityBarItems = (state, contributedViews = []) => {
2610
2811
  const {
2611
2812
  accountEnabled,
@@ -2726,7 +2927,7 @@ const getActivityBarItems = (state, contributedViews = []) => {
2726
2927
  preferredLocation: Default,
2727
2928
  title: settings()
2728
2929
  });
2729
- return items;
2930
+ return applyExistingOrder(items, activityBarItems);
2730
2931
  };
2731
2932
 
2732
2933
  const getContributedViews = async platform => {
@@ -2807,6 +3008,9 @@ const isConnected = () => {
2807
3008
  const invoke = (method, ...params) => {
2808
3009
  return invoke$2(method, ...params);
2809
3010
  };
3011
+ const invokeAndTransfer = (method, ...params) => {
3012
+ return invokeAndTransfer$2(method, ...params);
3013
+ };
2810
3014
  const set = rpc => {
2811
3015
  set$2(rpc);
2812
3016
  state.connected = true;
@@ -2863,17 +3067,28 @@ const getAccountEnabled = async defaultValue => {
2863
3067
  }
2864
3068
  };
2865
3069
 
3070
+ const getDragAndDropEnabled = async defaultValue => {
3071
+ try {
3072
+ const value = await invoke$1('Preferences.get', 'activityBar.dragAndDropEnabled');
3073
+ return typeof value === 'boolean' ? value : defaultValue;
3074
+ } catch {
3075
+ return defaultValue;
3076
+ }
3077
+ };
3078
+
2866
3079
  const handleSettingsChanged = async state => {
2867
3080
  const {
2868
3081
  accountEnabled: currentAccountEnabled,
3082
+ dragAndDropEnabled: currentDragAndDropEnabled,
2869
3083
  height,
2870
3084
  itemHeight,
2871
3085
  platform
2872
3086
  } = state;
2873
- const [accountEnabled, contributedViews, sidebarLocation] = await Promise.all([getAccountEnabled(currentAccountEnabled), getContributedViews(platform), getSideBarPosition()]);
3087
+ const [accountEnabled, dragAndDropEnabled, contributedViews, sidebarLocation] = await Promise.all([getAccountEnabled(currentAccountEnabled), getDragAndDropEnabled(Boolean(currentDragAndDropEnabled)), getContributedViews(platform), getSideBarPosition()]);
2874
3088
  const newState = {
2875
3089
  ...state,
2876
- accountEnabled
3090
+ accountEnabled,
3091
+ dragAndDropEnabled
2877
3092
  };
2878
3093
  const items = getActivityBarItems(newState, contributedViews);
2879
3094
  const activeViewIds = resolveActiveViewIds(state, items);
@@ -2994,11 +3209,12 @@ const getActiveView = async () => {
2994
3209
  };
2995
3210
 
2996
3211
  const loadPreferences = async (accountEnabled, platform) => {
2997
- const [accountEnabledNew, activeView, contributedViews, sidebarLocation, sideBarVisible] = await Promise.all([getAccountEnabled(accountEnabled), getActiveView(), getContributedViews(platform), getSideBarPosition(), getSideBarVisible()]);
3212
+ const [accountEnabledNew, dragAndDropEnabled, activeView, contributedViews, sidebarLocation, sideBarVisible] = await Promise.all([getAccountEnabled(accountEnabled), getDragAndDropEnabled(false), getActiveView(), getContributedViews(platform), getSideBarPosition(), getSideBarVisible()]);
2998
3213
  return {
2999
3214
  accountEnabled: accountEnabledNew,
3000
3215
  activeView,
3001
3216
  contributedViews,
3217
+ dragAndDropEnabled,
3002
3218
  sidebarLocation,
3003
3219
  sideBarVisible
3004
3220
  };
@@ -3093,6 +3309,25 @@ const renderCss = (oldState, newState) => {
3093
3309
  return [SetCss, uid, css];
3094
3310
  };
3095
3311
 
3312
+ const renderDragData = (_oldState, newState) => {
3313
+ const {
3314
+ draggedItemId,
3315
+ filteredItems,
3316
+ uid
3317
+ } = newState;
3318
+ const item = filteredItems.find(candidate => candidate.id === draggedItemId);
3319
+ if (!draggedItemId || !item) {
3320
+ return [];
3321
+ }
3322
+ return ['Viewlet.setDragData', uid, {
3323
+ items: [{
3324
+ data: getData(draggedItemId),
3325
+ type: Type
3326
+ }],
3327
+ label: item.title
3328
+ }];
3329
+ };
3330
+
3096
3331
  const ActivityBar$1 = 'ActivityBar';
3097
3332
 
3098
3333
  const renderFocus = (oldState, newState) => {
@@ -3400,6 +3635,11 @@ const HandleBlur = 1;
3400
3635
  const HandleContextMenu = 2;
3401
3636
  const HandleFocus = 3;
3402
3637
  const HandleMouseDown = 4;
3638
+ const HandleDragOver = 5;
3639
+ const HandleDragLeave = 6;
3640
+ const HandleDrop = 7;
3641
+ const HandleDragStart = 8;
3642
+ const HandleDragEnd = 9;
3403
3643
 
3404
3644
  const getActivityBarItemHasPopup = item => {
3405
3645
  return item.hasPopup;
@@ -3530,7 +3770,13 @@ const getIconVirtualDom = (icon, type = Div, customIconClass = '') => {
3530
3770
  };
3531
3771
  };
3532
3772
 
3533
- const getActivityBarItemVirtualDom = item => {
3773
+ const getDropIndicatorStyle = (dropIndicator, id) => {
3774
+ if (!dropIndicator || dropIndicator.id !== id) {
3775
+ return undefined;
3776
+ }
3777
+ return dropIndicator.position === 'before' ? 'box-shadow:inset 0 2px 0 white;' : 'box-shadow:inset 0 -2px 0 white;';
3778
+ };
3779
+ const getActivityBarItemVirtualDom = (item, draggable = false, dropIndicator) => {
3534
3780
  const {
3535
3781
  badgeText,
3536
3782
  flags,
@@ -3547,8 +3793,9 @@ const getActivityBarItemVirtualDom = item => {
3547
3793
  const ariaSelected = getAriaSelected(isTab, isSelected);
3548
3794
  const marginTop = flags & MarginTop;
3549
3795
  const className = getClassName(isFocused, marginTop, isSelected);
3796
+ let dom;
3550
3797
  if (isSelected && !badgeText) {
3551
- return [{
3798
+ dom = [{
3552
3799
  ariaHasPopup,
3553
3800
  ariaSelected,
3554
3801
  childCount: 1,
@@ -3561,36 +3808,47 @@ const getActivityBarItemVirtualDom = item => {
3561
3808
  ...getIconVirtualDom(icon, Div, item.customIconClass),
3562
3809
  name: id
3563
3810
  }];
3811
+ } else if (isProgress) {
3812
+ dom = getActivityBarItemInProgressDom(item);
3813
+ } else if (badgeText) {
3814
+ dom = getActivityBarItemWithBadgeDom(item);
3815
+ } else {
3816
+ dom = [{
3817
+ ariaHasPopup,
3818
+ ariaSelected,
3819
+ childCount: 0,
3820
+ className: mergeClassNames(className, getIconClass(item, 'Icon')),
3821
+ name: id,
3822
+ role,
3823
+ title,
3824
+ type: Div
3825
+ }];
3564
3826
  }
3565
-
3566
- // TODO support progress on selected activity bar item
3567
- if (isProgress) {
3568
- return getActivityBarItemInProgressDom(item);
3569
- }
3570
- if (badgeText) {
3571
- return getActivityBarItemWithBadgeDom(item);
3572
- }
3827
+ const [root, ...children] = dom;
3573
3828
  return [{
3574
- ariaHasPopup,
3575
- ariaSelected,
3576
- childCount: 0,
3577
- className: mergeClassNames(className, getIconClass(item, 'Icon')),
3578
- name: id,
3579
- role,
3580
- title,
3581
- type: Div
3582
- }];
3583
- };
3584
-
3585
- const getVirtualDom = visibleItems => {
3586
- const dom = visibleItems.flatMap(getActivityBarItemVirtualDom);
3829
+ ...root,
3830
+ ...(draggable && {
3831
+ draggable: true
3832
+ }),
3833
+ ...(draggable && {
3834
+ onDragEnd: HandleDragEnd,
3835
+ onDragStart: HandleDragStart
3836
+ }),
3837
+ ...(getDropIndicatorStyle(dropIndicator, id) && {
3838
+ style: getDropIndicatorStyle(dropIndicator, id)
3839
+ })
3840
+ }, ...children];
3841
+ };
3842
+
3843
+ const getVirtualDom = (visibleItems, dragAndDropEnabled = false, dropIndicator) => {
3844
+ const dom = visibleItems.flatMap(item => getActivityBarItemVirtualDom(item, dragAndDropEnabled && isMovableActivityBarItem(item), dropIndicator));
3587
3845
  return dom;
3588
3846
  };
3589
3847
 
3590
3848
  const Focusable = 0;
3591
3849
 
3592
3850
  const className = mergeClassNames(Viewlet, ActivityBar);
3593
- const getActivityBarVirtualDom = visibleItems => {
3851
+ const getActivityBarVirtualDom = (visibleItems, dragAndDropEnabled = false, dropIndicator) => {
3594
3852
  return [{
3595
3853
  ariaOrientation: Vertical,
3596
3854
  ariaRoleDescription: activityBar(),
@@ -3599,12 +3857,15 @@ const getActivityBarVirtualDom = visibleItems => {
3599
3857
  id: ActivityBar$1,
3600
3858
  onBlur: HandleBlur,
3601
3859
  onContextMenu: HandleContextMenu,
3860
+ onDragLeave: HandleDragLeave,
3861
+ onDragOver: HandleDragOver,
3862
+ onDrop: HandleDrop,
3602
3863
  onFocus: HandleFocus,
3603
3864
  onMouseDown: HandleMouseDown,
3604
3865
  role: ToolBar,
3605
3866
  tabIndex: Focusable,
3606
3867
  type: Div
3607
- }, ...getVirtualDom(visibleItems)];
3868
+ }, ...getVirtualDom(visibleItems, dragAndDropEnabled, dropIndicator)];
3608
3869
  };
3609
3870
 
3610
3871
  const getVisibleActivityBarItems = (items, focusedIndex) => {
@@ -3613,6 +3874,8 @@ const getVisibleActivityBarItems = (items, focusedIndex) => {
3613
3874
 
3614
3875
  const renderItems = (oldState, newState) => {
3615
3876
  const {
3877
+ dragAndDropEnabled,
3878
+ dropIndicator,
3616
3879
  filteredItems,
3617
3880
  focused,
3618
3881
  focusedIndex,
@@ -3623,7 +3886,7 @@ const renderItems = (oldState, newState) => {
3623
3886
  return [SetDom2, uid, []];
3624
3887
  }
3625
3888
  const visibleItems = getVisibleActivityBarItems(filteredItems, focused ? focusedIndex : -1);
3626
- const dom = getActivityBarVirtualDom(visibleItems);
3889
+ const dom = getActivityBarVirtualDom(visibleItems, Boolean(dragAndDropEnabled), dropIndicator);
3627
3890
  return [SetDom2, uid, dom];
3628
3891
  };
3629
3892
 
@@ -3641,6 +3904,8 @@ const getRenderer = diffType => {
3641
3904
  switch (diffType) {
3642
3905
  case RenderCss:
3643
3906
  return renderCss;
3907
+ case RenderDragData:
3908
+ return renderDragData;
3644
3909
  case RenderFocus:
3645
3910
  return renderFocus;
3646
3911
  case RenderFocusContext:
@@ -3677,7 +3942,7 @@ const render2 = (uid, diffResult) => {
3677
3942
  newState,
3678
3943
  oldState
3679
3944
  } = get$2(uid);
3680
- set$5(uid, newState, newState);
3945
+ set$6(uid, newState, newState);
3681
3946
  const commands = applyRender(oldState, newState, diffResult);
3682
3947
  if (!isConnected()) {
3683
3948
  return commands;
@@ -3686,6 +3951,7 @@ const render2 = (uid, diffResult) => {
3686
3951
  };
3687
3952
 
3688
3953
  const renderEventListeners = () => {
3954
+ const DropId = 'event.dropId';
3689
3955
  return [{
3690
3956
  name: HandleBlur,
3691
3957
  params: ['handleBlur']
@@ -3701,6 +3967,25 @@ const renderEventListeners = () => {
3701
3967
  params: ['handleClick', Button$1, ClientX, ClientY, TargetName],
3702
3968
  preventDefault: false,
3703
3969
  stopPropagation: false
3970
+ }, {
3971
+ name: HandleDragOver,
3972
+ params: ['handleDragOver', ClientY],
3973
+ preventDefault: true
3974
+ }, {
3975
+ name: HandleDragLeave,
3976
+ params: ['handleDragLeave']
3977
+ }, {
3978
+ name: HandleDrop,
3979
+ params: ['handleDrop', DropId],
3980
+ preventDefault: true
3981
+ }, {
3982
+ // @ts-ignore
3983
+ dragEffect: 'move',
3984
+ name: HandleDragStart,
3985
+ params: ['handleDragStart', TargetName]
3986
+ }, {
3987
+ name: HandleDragEnd,
3988
+ params: ['handleDragEnd']
3704
3989
  }];
3705
3990
  };
3706
3991
 
@@ -3708,6 +3993,7 @@ const createDefaultState = () => ({
3708
3993
  accountEnabled: true,
3709
3994
  activityBarItems: [],
3710
3995
  currentViewletId: '',
3996
+ dragAndDropEnabled: false,
3711
3997
  filteredItems: [],
3712
3998
  focus: 0,
3713
3999
  focused: false,
@@ -3825,6 +4111,19 @@ const setAccountEnabled = (state, enabled) => {
3825
4111
  };
3826
4112
  };
3827
4113
 
4114
+ const setDragAndDropEnabled = (state, enabled) => {
4115
+ const {
4116
+ dragAndDropEnabled
4117
+ } = state;
4118
+ if (dragAndDropEnabled === enabled) {
4119
+ return state;
4120
+ }
4121
+ return {
4122
+ ...state,
4123
+ dragAndDropEnabled: enabled
4124
+ };
4125
+ };
4126
+
3828
4127
  const providerKeys = ['userLoginProvider', 'loginProvider', 'authProvider', 'provider'];
3829
4128
  const getUserLoginProvider = userInfo => {
3830
4129
  if (!userInfo || typeof userInfo !== 'object') {
@@ -3890,7 +4189,7 @@ const toggleActivityBarItem = async (state, itemId) => {
3890
4189
  };
3891
4190
 
3892
4191
  const wakeUp = sleepState => {
3893
- set$5(sleepState.uid, sleepState, sleepState);
4192
+ set$6(sleepState.uid, sleepState, sleepState);
3894
4193
  };
3895
4194
 
3896
4195
  const handleDirectMessagePort = (port, setAsRendererProcess) => handleMessagePort(port, commandMap, setAsRendererProcess);
@@ -3920,6 +4219,11 @@ const commandMap = {
3920
4219
  'ActivityBar.handleClickSignIn': wrapCommand(handleClickSignIn),
3921
4220
  'ActivityBar.handleClickSignOut': wrapCommand(handleClickSignOut),
3922
4221
  'ActivityBar.handleContextMenu': wrapAsyncCommand(handleContextMenu),
4222
+ 'ActivityBar.handleDragEnd': wrapCommand(handleDragEnd),
4223
+ 'ActivityBar.handleDragLeave': wrapCommand(handleDragLeave),
4224
+ 'ActivityBar.handleDragOver': wrapCommand(handleDragOver),
4225
+ 'ActivityBar.handleDragStart': wrapCommand(handleDragStart),
4226
+ 'ActivityBar.handleDrop': wrapAsyncCommand(handleDrop),
3923
4227
  'ActivityBar.handleExtensionManagementMessagePort': handleExtensionManagementMessagePort,
3924
4228
  'ActivityBar.handleExtensionsChanged': wrapCommand(handleExtensionsChanged),
3925
4229
  'ActivityBar.handleFocus': wrapCommand(handleFocus),
@@ -3935,6 +4239,7 @@ const commandMap = {
3935
4239
  'ActivityBar.saveState': wrapGetter(saveState),
3936
4240
  'ActivityBar.selectCurrent': wrapCommand(selectCurrent),
3937
4241
  'ActivityBar.setAccountEnabled': wrapCommand(setAccountEnabled),
4242
+ 'ActivityBar.setDragAndDropEnabled': wrapCommand(setDragAndDropEnabled),
3938
4243
  'ActivityBar.setUserLoginState': wrapCommand(setUserLoginState),
3939
4244
  'ActivityBar.sleep': sleep,
3940
4245
  'ActivityBar.terminate': terminate,
@@ -3942,6 +4247,20 @@ const commandMap = {
3942
4247
  'ActivityBar.wakeUp': wakeUp
3943
4248
  };
3944
4249
 
4250
+ const send$1 = async port => {
4251
+ await invokeAndTransfer('DragAndDrop.handleMessagePort', port);
4252
+ };
4253
+ const createDragAndDropWorkerRpc = async () => {
4254
+ return create$2({
4255
+ commandMap: {},
4256
+ send: send$1
4257
+ });
4258
+ };
4259
+
4260
+ const initializeDragAndDropWorker = async () => {
4261
+ set$4(await createDragAndDropWorkerRpc());
4262
+ };
4263
+
3945
4264
  const send = async port => {
3946
4265
  await sendMessagePortToExtensionManagementWorker(port, 0);
3947
4266
  };
@@ -3962,7 +4281,7 @@ const initializeRendererWorker = async () => {
3962
4281
 
3963
4282
  const listen = async () => {
3964
4283
  registerCommands(commandMap);
3965
- await Promise.all([initializeRendererWorker(), initializeExtensionManagementWorker()]);
4284
+ await Promise.all([initializeRendererWorker(), initializeExtensionManagementWorker(), initializeDragAndDropWorker()]);
3966
4285
  };
3967
4286
 
3968
4287
  const main = async () => {
@@ -6,5 +6,13 @@
6
6
  "id": "activityBar.accountEnabled",
7
7
  "type": "boolean",
8
8
  "value": true
9
+ },
10
+ {
11
+ "category": "workbench",
12
+ "description": "Enable dragging activity bar items to reorder them",
13
+ "heading": "Activity Bar",
14
+ "id": "activityBar.dragAndDropEnabled",
15
+ "type": "boolean",
16
+ "value": false
9
17
  }
10
18
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/activity-bar-worker",
3
- "version": "7.27.0",
3
+ "version": "7.27.1",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",