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

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);
@@ -391,6 +397,10 @@ const focusPrevious = state => {
391
397
  return focusIndex(state, focusedIndex - 1);
392
398
  };
393
399
 
400
+ const getComponentState = uid => {
401
+ return get$2(uid).newState;
402
+ };
403
+
394
404
  const Button$3 = 'button';
395
405
  const None$1 = 'none';
396
406
  const Tab$1 = 'tab';
@@ -593,6 +603,7 @@ const LeftClick = 0;
593
603
 
594
604
  const Electron = 2;
595
605
 
606
+ const DragAndDropWorker = 3404;
596
607
  const ExtensionManagementWorker = 9006;
597
608
  const RendererProcess = 1670;
598
609
  const RendererWorker = 1;
@@ -1495,6 +1506,9 @@ const restoreExistingError = (error, currentStack) => {
1495
1506
  };
1496
1507
  const restoreMethodNotFoundError = (error, currentStack) => {
1497
1508
  const restoredError = new JsonRpcError(error.message);
1509
+ Object.assign(restoredError, {
1510
+ code: error.code
1511
+ });
1498
1512
  const parentStack = getParentStack(error);
1499
1513
  setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
1500
1514
  return restoredError;
@@ -1514,9 +1528,13 @@ const applyDataProperties = (restoredError, error) => {
1514
1528
  // @ts-ignore
1515
1529
  restoredError.codeFrame = error.data.codeFrame;
1516
1530
  }
1517
- if (error.data.code) {
1531
+ if (typeof error.data.code === 'string' || typeof error.data.code === 'number') {
1518
1532
  // @ts-ignore
1519
- restoredError.code = error.data.code;
1533
+ Object.defineProperty(restoredError, 'code', {
1534
+ configurable: true,
1535
+ value: error.data.code,
1536
+ writable: true
1537
+ });
1520
1538
  }
1521
1539
  if (error.data.type) {
1522
1540
  // @ts-ignore
@@ -1538,6 +1556,13 @@ const applyDirectProperties = (restoredError, error) => {
1538
1556
  };
1539
1557
  const restoreMessageError = (error, _currentStack) => {
1540
1558
  const restoredError = constructError(error.message, error.type, error.name);
1559
+ if (typeof error.code === 'string' || typeof error.code === 'number') {
1560
+ Object.defineProperty(restoredError, 'code', {
1561
+ configurable: true,
1562
+ value: error.code,
1563
+ writable: true
1564
+ });
1565
+ }
1541
1566
  if (error.data) {
1542
1567
  applyDataProperties(restoredError, error);
1543
1568
  } else {
@@ -1616,7 +1641,7 @@ const getErrorProperty = (error, prettyError) => {
1616
1641
  return {
1617
1642
  code: Custom,
1618
1643
  data: {
1619
- code: prettyError.code,
1644
+ code: prettyError.code ?? error?.code,
1620
1645
  codeFrame: prettyError.codeFrame,
1621
1646
  name: prettyError.name,
1622
1647
  stack: getStack(prettyError),
@@ -1653,7 +1678,12 @@ const getErrorResponseSimple = (id, error) => {
1653
1678
  return {
1654
1679
  error: {
1655
1680
  code: Custom,
1656
- data: error,
1681
+ data: error instanceof Error ? {
1682
+ ...error,
1683
+ code: 'code' in error ? error.code : undefined,
1684
+ stack: error.stack,
1685
+ type: error.name
1686
+ } : error,
1657
1687
  // @ts-ignore
1658
1688
  message: error.message
1659
1689
  },
@@ -1967,7 +1997,7 @@ const createMockRpc = ({
1967
1997
  };
1968
1998
 
1969
1999
  const rpcs = Object.create(null);
1970
- const set$4 = (id, rpc) => {
2000
+ const set$5 = (id, rpc) => {
1971
2001
  rpcs[id] = rpc;
1972
2002
  };
1973
2003
  const get = id => {
@@ -2000,7 +2030,7 @@ const create = rpcId => {
2000
2030
  const mockRpc = createMockRpc({
2001
2031
  commandMap
2002
2032
  });
2003
- set$4(rpcId, mockRpc);
2033
+ set$5(rpcId, mockRpc);
2004
2034
  // @ts-ignore
2005
2035
  mockRpc[Symbol.dispose] = () => {
2006
2036
  remove(rpcId);
@@ -2009,11 +2039,16 @@ const create = rpcId => {
2009
2039
  return mockRpc;
2010
2040
  },
2011
2041
  set(rpc) {
2012
- set$4(rpcId, rpc);
2042
+ set$5(rpcId, rpc);
2013
2043
  }
2014
2044
  };
2015
2045
  };
2016
2046
 
2047
+ const {
2048
+ invoke: invoke$4,
2049
+ set: set$4
2050
+ } = create(DragAndDropWorker);
2051
+
2017
2052
  const {
2018
2053
  invoke: invoke$3,
2019
2054
  set: set$3
@@ -2021,12 +2056,13 @@ const {
2021
2056
 
2022
2057
  const {
2023
2058
  invoke: invoke$2,
2059
+ invokeAndTransfer: invokeAndTransfer$2,
2024
2060
  set: set$2
2025
2061
  } = create(RendererProcess);
2026
2062
 
2027
2063
  const {
2028
2064
  invoke: invoke$1,
2029
- invokeAndTransfer,
2065
+ invokeAndTransfer: invokeAndTransfer$1,
2030
2066
  set: set$1
2031
2067
  } = create(RendererWorker);
2032
2068
  const showContextMenu2 = async (uid, menuId, x, y, args) => {
@@ -2038,7 +2074,7 @@ const showContextMenu2 = async (uid, menuId, x, y, args) => {
2038
2074
  };
2039
2075
  const sendMessagePortToExtensionManagementWorker = async (port, rpcId) => {
2040
2076
  const command = 'Extensions.handleMessagePort';
2041
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
2077
+ await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
2042
2078
  };
2043
2079
 
2044
2080
  const show2 = async (uid, menuId, x, y, args) => {
@@ -2319,14 +2355,14 @@ const handleBlur = state => {
2319
2355
  };
2320
2356
  };
2321
2357
 
2322
- const isBottomItem$1 = item => {
2358
+ const isBottomItem$3 = item => {
2323
2359
  return item.id === 'Account' || item.id === 'Settings';
2324
2360
  };
2325
2361
  const getBottomItemCount = items => {
2326
2362
  if (typeof items === 'number') {
2327
2363
  return items > 1 ? 1 : 0;
2328
2364
  }
2329
- return items.filter(isBottomItem$1).length;
2365
+ return items.filter(isBottomItem$3).length;
2330
2366
  };
2331
2367
  const getItemCount = items => {
2332
2368
  if (typeof items === 'number') {
@@ -2552,6 +2588,163 @@ const handleContextMenu = async (context, button, eventX, eventY) => {
2552
2588
  });
2553
2589
  };
2554
2590
 
2591
+ const handleDragEnd = state => {
2592
+ const {
2593
+ draggedItemId,
2594
+ dropIndicator
2595
+ } = state;
2596
+ if (!draggedItemId && !dropIndicator) {
2597
+ return state;
2598
+ }
2599
+ return {
2600
+ ...state,
2601
+ draggedItemId: undefined,
2602
+ dropIndicator: undefined
2603
+ };
2604
+ };
2605
+
2606
+ const handleDragLeave = state => {
2607
+ const {
2608
+ dropIndicator
2609
+ } = state;
2610
+ if (!dropIndicator) {
2611
+ return state;
2612
+ }
2613
+ return {
2614
+ ...state,
2615
+ dropIndicator: undefined
2616
+ };
2617
+ };
2618
+
2619
+ const isMovableActivityBarItem = item => {
2620
+ return Boolean(item && item.flags & Tab && item.id !== 'Additional Views');
2621
+ };
2622
+
2623
+ const isBottomItem$2 = item => item.id === 'Account' || item.id === 'Settings';
2624
+ const getDropIndicator = (state, clientY) => {
2625
+ const {
2626
+ draggedItemId,
2627
+ filteredItems,
2628
+ itemHeight,
2629
+ y
2630
+ } = state;
2631
+ if (!draggedItemId || !isMovableActivityBarItem(filteredItems.find(item => item.id === draggedItemId))) {
2632
+ return undefined;
2633
+ }
2634
+ const topItems = filteredItems.filter(item => !isBottomItem$2(item));
2635
+ for (let index = 0; index < topItems.length; index++) {
2636
+ const item = topItems[index];
2637
+ const itemY = y + index * itemHeight;
2638
+ if (clientY < itemY || clientY >= itemY + itemHeight) {
2639
+ continue;
2640
+ }
2641
+ if (!isMovableActivityBarItem(item)) {
2642
+ return undefined;
2643
+ }
2644
+ if (item.id === draggedItemId) {
2645
+ return undefined;
2646
+ }
2647
+ const position = clientY < itemY + itemHeight / 2 ? 'before' : 'after';
2648
+ const sourceIndex = topItems.findIndex(candidate => candidate.id === draggedItemId);
2649
+ if (position === 'before' && sourceIndex === index - 1 || position === 'after' && sourceIndex === index + 1) {
2650
+ return undefined;
2651
+ }
2652
+ return {
2653
+ id: item.id,
2654
+ position
2655
+ };
2656
+ }
2657
+ return undefined;
2658
+ };
2659
+ const handleDragOver = (state, clientY) => {
2660
+ const dropIndicator = getDropIndicator(state, clientY);
2661
+ const {
2662
+ dropIndicator: oldIndicator
2663
+ } = state;
2664
+ if (oldIndicator?.id === dropIndicator?.id && oldIndicator?.position === dropIndicator?.position) {
2665
+ return state;
2666
+ }
2667
+ return {
2668
+ ...state,
2669
+ dropIndicator
2670
+ };
2671
+ };
2672
+
2673
+ const handleDragStart = (state, id) => {
2674
+ const {
2675
+ dragAndDropEnabled,
2676
+ filteredItems
2677
+ } = state;
2678
+ if (!dragAndDropEnabled || !isMovableActivityBarItem(filteredItems.find(item => item.id === id))) {
2679
+ return state;
2680
+ }
2681
+ return {
2682
+ ...state,
2683
+ draggedItemId: id,
2684
+ dropIndicator: undefined
2685
+ };
2686
+ };
2687
+
2688
+ const Type = 'application/x-lvce-editor-activity-bar-item';
2689
+ const getData = id => `${Type}:${id}`;
2690
+ const getId = value => {
2691
+ const prefix = `${Type}:`;
2692
+ return value.startsWith(prefix) ? value.slice(prefix.length) : undefined;
2693
+ };
2694
+
2695
+ const reorderActivityBarItems = (items, draggedItemId, targetId, position) => {
2696
+ const sourceIndex = items.findIndex(item => item.id === draggedItemId);
2697
+ const targetIndex = items.findIndex(item => item.id === targetId);
2698
+ if (sourceIndex === -1 || targetIndex === -1 || sourceIndex === targetIndex || !isMovableActivityBarItem(items[sourceIndex]) || !isMovableActivityBarItem(items[targetIndex])) {
2699
+ return items;
2700
+ }
2701
+ const result = [...items];
2702
+ const [source] = result.splice(sourceIndex, 1);
2703
+ const newTargetIndex = result.findIndex(item => item.id === targetId);
2704
+ const insertionIndex = newTargetIndex + (position === 'after' ? 1 : 0);
2705
+ result.splice(insertionIndex, 0, source);
2706
+ return result;
2707
+ };
2708
+
2709
+ const handleDrop = async (context, dropId) => {
2710
+ const state = context.getState();
2711
+ const {
2712
+ activityBarItems: initialActivityBarItems,
2713
+ dragAndDropEnabled,
2714
+ draggedItemId,
2715
+ dropIndicator,
2716
+ filteredItems: initialFilteredItems,
2717
+ focusedIndex: initialFocusedIndex,
2718
+ height,
2719
+ itemHeight,
2720
+ platform,
2721
+ selectedIndex: initialSelectedIndex
2722
+ } = state;
2723
+ const clearState = handleDragEnd(state);
2724
+ if (!dragAndDropEnabled || !draggedItemId || !dropIndicator) {
2725
+ await context.updateState(() => clearState);
2726
+ return;
2727
+ }
2728
+ const isElectron = platform === Electron;
2729
+ const result = await invoke$4('DragAndDrop.getDroppedItemsByDropId', dropId, isElectron);
2730
+ const values = Array.isArray(result?.strings) ? result.strings : [];
2731
+ if (values.length !== 1 || getId(values[0]) !== draggedItemId) {
2732
+ await context.updateState(() => clearState);
2733
+ return;
2734
+ }
2735
+ const activityBarItems = reorderActivityBarItems(initialActivityBarItems, draggedItemId, dropIndicator.id, dropIndicator.position);
2736
+ const filteredItems = getFilteredActivityBarItems(activityBarItems, height, itemHeight);
2737
+ const selectedId = initialActivityBarItems.find(item => item.flags & Selected)?.id;
2738
+ const focusedId = initialFilteredItems[initialFocusedIndex]?.id;
2739
+ await context.updateState(() => ({
2740
+ ...clearState,
2741
+ activityBarItems,
2742
+ filteredItems,
2743
+ focusedIndex: focusedId ? filteredItems.findIndex(item => item.id === focusedId) : initialFocusedIndex,
2744
+ selectedIndex: selectedId ? filteredItems.findIndex(item => item.id === selectedId) : initialSelectedIndex
2745
+ }));
2746
+ };
2747
+
2555
2748
  const commandMap$1 = {};
2556
2749
 
2557
2750
  const handleExtensionManagementMessagePort = async port => {
@@ -2606,6 +2799,18 @@ const toActivityBarItem = view => {
2606
2799
  title: view.title || view.id
2607
2800
  };
2608
2801
  };
2802
+ const isBottomItem$1 = item => item.id === 'Account' || item.id === 'Settings';
2803
+ const applyExistingOrder = (items, existingItems) => {
2804
+ if (existingItems.length === 0) {
2805
+ return items;
2806
+ }
2807
+ const itemsById = new Map(items.map(item => [item.id, item]));
2808
+ const orderedTopItems = existingItems.filter(item => !isBottomItem$1(item)).map(item => itemsById.get(item.id)).filter(item => Boolean(item));
2809
+ const orderedTopIds = new Set(orderedTopItems.map(item => item.id));
2810
+ const newTopItems = items.filter(item => !isBottomItem$1(item) && !orderedTopIds.has(item.id));
2811
+ const bottomItems = items.filter(isBottomItem$1);
2812
+ return [...orderedTopItems, ...newTopItems, ...bottomItems];
2813
+ };
2609
2814
  const getActivityBarItems = (state, contributedViews = []) => {
2610
2815
  const {
2611
2816
  accountEnabled,
@@ -2726,7 +2931,7 @@ const getActivityBarItems = (state, contributedViews = []) => {
2726
2931
  preferredLocation: Default,
2727
2932
  title: settings()
2728
2933
  });
2729
- return items;
2934
+ return applyExistingOrder(items, activityBarItems);
2730
2935
  };
2731
2936
 
2732
2937
  const getContributedViews = async platform => {
@@ -2807,6 +3012,9 @@ const isConnected = () => {
2807
3012
  const invoke = (method, ...params) => {
2808
3013
  return invoke$2(method, ...params);
2809
3014
  };
3015
+ const invokeAndTransfer = (method, ...params) => {
3016
+ return invokeAndTransfer$2(method, ...params);
3017
+ };
2810
3018
  const set = rpc => {
2811
3019
  set$2(rpc);
2812
3020
  state.connected = true;
@@ -2863,17 +3071,28 @@ const getAccountEnabled = async defaultValue => {
2863
3071
  }
2864
3072
  };
2865
3073
 
3074
+ const getDragAndDropEnabled = async defaultValue => {
3075
+ try {
3076
+ const value = await invoke$1('Preferences.get', 'activityBar.dragAndDropEnabled');
3077
+ return typeof value === 'boolean' ? value : defaultValue;
3078
+ } catch {
3079
+ return defaultValue;
3080
+ }
3081
+ };
3082
+
2866
3083
  const handleSettingsChanged = async state => {
2867
3084
  const {
2868
3085
  accountEnabled: currentAccountEnabled,
3086
+ dragAndDropEnabled: currentDragAndDropEnabled,
2869
3087
  height,
2870
3088
  itemHeight,
2871
3089
  platform
2872
3090
  } = state;
2873
- const [accountEnabled, contributedViews, sidebarLocation] = await Promise.all([getAccountEnabled(currentAccountEnabled), getContributedViews(platform), getSideBarPosition()]);
3091
+ const [accountEnabled, dragAndDropEnabled, contributedViews, sidebarLocation] = await Promise.all([getAccountEnabled(currentAccountEnabled), getDragAndDropEnabled(Boolean(currentDragAndDropEnabled)), getContributedViews(platform), getSideBarPosition()]);
2874
3092
  const newState = {
2875
3093
  ...state,
2876
- accountEnabled
3094
+ accountEnabled,
3095
+ dragAndDropEnabled
2877
3096
  };
2878
3097
  const items = getActivityBarItems(newState, contributedViews);
2879
3098
  const activeViewIds = resolveActiveViewIds(state, items);
@@ -2994,11 +3213,12 @@ const getActiveView = async () => {
2994
3213
  };
2995
3214
 
2996
3215
  const loadPreferences = async (accountEnabled, platform) => {
2997
- const [accountEnabledNew, activeView, contributedViews, sidebarLocation, sideBarVisible] = await Promise.all([getAccountEnabled(accountEnabled), getActiveView(), getContributedViews(platform), getSideBarPosition(), getSideBarVisible()]);
3216
+ const [accountEnabledNew, dragAndDropEnabled, activeView, contributedViews, sidebarLocation, sideBarVisible] = await Promise.all([getAccountEnabled(accountEnabled), getDragAndDropEnabled(false), getActiveView(), getContributedViews(platform), getSideBarPosition(), getSideBarVisible()]);
2998
3217
  return {
2999
3218
  accountEnabled: accountEnabledNew,
3000
3219
  activeView,
3001
3220
  contributedViews,
3221
+ dragAndDropEnabled,
3002
3222
  sidebarLocation,
3003
3223
  sideBarVisible
3004
3224
  };
@@ -3093,6 +3313,25 @@ const renderCss = (oldState, newState) => {
3093
3313
  return [SetCss, uid, css];
3094
3314
  };
3095
3315
 
3316
+ const renderDragData = (_oldState, newState) => {
3317
+ const {
3318
+ draggedItemId,
3319
+ filteredItems,
3320
+ uid
3321
+ } = newState;
3322
+ const item = filteredItems.find(candidate => candidate.id === draggedItemId);
3323
+ if (!draggedItemId || !item) {
3324
+ return [];
3325
+ }
3326
+ return ['Viewlet.setDragData', uid, {
3327
+ items: [{
3328
+ data: getData(draggedItemId),
3329
+ type: Type
3330
+ }],
3331
+ label: item.title
3332
+ }];
3333
+ };
3334
+
3096
3335
  const ActivityBar$1 = 'ActivityBar';
3097
3336
 
3098
3337
  const renderFocus = (oldState, newState) => {
@@ -3400,6 +3639,11 @@ const HandleBlur = 1;
3400
3639
  const HandleContextMenu = 2;
3401
3640
  const HandleFocus = 3;
3402
3641
  const HandleMouseDown = 4;
3642
+ const HandleDragOver = 5;
3643
+ const HandleDragLeave = 6;
3644
+ const HandleDrop = 7;
3645
+ const HandleDragStart = 8;
3646
+ const HandleDragEnd = 9;
3403
3647
 
3404
3648
  const getActivityBarItemHasPopup = item => {
3405
3649
  return item.hasPopup;
@@ -3530,7 +3774,13 @@ const getIconVirtualDom = (icon, type = Div, customIconClass = '') => {
3530
3774
  };
3531
3775
  };
3532
3776
 
3533
- const getActivityBarItemVirtualDom = item => {
3777
+ const getDropIndicatorStyle = (dropIndicator, id) => {
3778
+ if (!dropIndicator || dropIndicator.id !== id) {
3779
+ return undefined;
3780
+ }
3781
+ return dropIndicator.position === 'before' ? 'box-shadow:inset 0 2px 0 white;' : 'box-shadow:inset 0 -2px 0 white;';
3782
+ };
3783
+ const getActivityBarItemVirtualDom = (item, draggable = false, dropIndicator) => {
3534
3784
  const {
3535
3785
  badgeText,
3536
3786
  flags,
@@ -3547,8 +3797,9 @@ const getActivityBarItemVirtualDom = item => {
3547
3797
  const ariaSelected = getAriaSelected(isTab, isSelected);
3548
3798
  const marginTop = flags & MarginTop;
3549
3799
  const className = getClassName(isFocused, marginTop, isSelected);
3800
+ let dom;
3550
3801
  if (isSelected && !badgeText) {
3551
- return [{
3802
+ dom = [{
3552
3803
  ariaHasPopup,
3553
3804
  ariaSelected,
3554
3805
  childCount: 1,
@@ -3561,36 +3812,47 @@ const getActivityBarItemVirtualDom = item => {
3561
3812
  ...getIconVirtualDom(icon, Div, item.customIconClass),
3562
3813
  name: id
3563
3814
  }];
3815
+ } else if (isProgress) {
3816
+ dom = getActivityBarItemInProgressDom(item);
3817
+ } else if (badgeText) {
3818
+ dom = getActivityBarItemWithBadgeDom(item);
3819
+ } else {
3820
+ dom = [{
3821
+ ariaHasPopup,
3822
+ ariaSelected,
3823
+ childCount: 0,
3824
+ className: mergeClassNames(className, getIconClass(item, 'Icon')),
3825
+ name: id,
3826
+ role,
3827
+ title,
3828
+ type: Div
3829
+ }];
3564
3830
  }
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
- }
3831
+ const [root, ...children] = dom;
3573
3832
  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);
3833
+ ...root,
3834
+ ...(draggable && {
3835
+ draggable: true
3836
+ }),
3837
+ ...(draggable && {
3838
+ onDragEnd: HandleDragEnd,
3839
+ onDragStart: HandleDragStart
3840
+ }),
3841
+ ...(getDropIndicatorStyle(dropIndicator, id) && {
3842
+ style: getDropIndicatorStyle(dropIndicator, id)
3843
+ })
3844
+ }, ...children];
3845
+ };
3846
+
3847
+ const getVirtualDom = (visibleItems, dragAndDropEnabled = false, dropIndicator) => {
3848
+ const dom = visibleItems.flatMap(item => getActivityBarItemVirtualDom(item, dragAndDropEnabled && isMovableActivityBarItem(item), dropIndicator));
3587
3849
  return dom;
3588
3850
  };
3589
3851
 
3590
3852
  const Focusable = 0;
3591
3853
 
3592
3854
  const className = mergeClassNames(Viewlet, ActivityBar);
3593
- const getActivityBarVirtualDom = visibleItems => {
3855
+ const getActivityBarVirtualDom = (visibleItems, dragAndDropEnabled = false, dropIndicator) => {
3594
3856
  return [{
3595
3857
  ariaOrientation: Vertical,
3596
3858
  ariaRoleDescription: activityBar(),
@@ -3599,12 +3861,15 @@ const getActivityBarVirtualDom = visibleItems => {
3599
3861
  id: ActivityBar$1,
3600
3862
  onBlur: HandleBlur,
3601
3863
  onContextMenu: HandleContextMenu,
3864
+ onDragLeave: HandleDragLeave,
3865
+ onDragOver: HandleDragOver,
3866
+ onDrop: HandleDrop,
3602
3867
  onFocus: HandleFocus,
3603
3868
  onMouseDown: HandleMouseDown,
3604
3869
  role: ToolBar,
3605
3870
  tabIndex: Focusable,
3606
3871
  type: Div
3607
- }, ...getVirtualDom(visibleItems)];
3872
+ }, ...getVirtualDom(visibleItems, dragAndDropEnabled, dropIndicator)];
3608
3873
  };
3609
3874
 
3610
3875
  const getVisibleActivityBarItems = (items, focusedIndex) => {
@@ -3613,6 +3878,8 @@ const getVisibleActivityBarItems = (items, focusedIndex) => {
3613
3878
 
3614
3879
  const renderItems = (oldState, newState) => {
3615
3880
  const {
3881
+ dragAndDropEnabled,
3882
+ dropIndicator,
3616
3883
  filteredItems,
3617
3884
  focused,
3618
3885
  focusedIndex,
@@ -3623,7 +3890,7 @@ const renderItems = (oldState, newState) => {
3623
3890
  return [SetDom2, uid, []];
3624
3891
  }
3625
3892
  const visibleItems = getVisibleActivityBarItems(filteredItems, focused ? focusedIndex : -1);
3626
- const dom = getActivityBarVirtualDom(visibleItems);
3893
+ const dom = getActivityBarVirtualDom(visibleItems, Boolean(dragAndDropEnabled), dropIndicator);
3627
3894
  return [SetDom2, uid, dom];
3628
3895
  };
3629
3896
 
@@ -3641,6 +3908,8 @@ const getRenderer = diffType => {
3641
3908
  switch (diffType) {
3642
3909
  case RenderCss:
3643
3910
  return renderCss;
3911
+ case RenderDragData:
3912
+ return renderDragData;
3644
3913
  case RenderFocus:
3645
3914
  return renderFocus;
3646
3915
  case RenderFocusContext:
@@ -3677,7 +3946,7 @@ const render2 = (uid, diffResult) => {
3677
3946
  newState,
3678
3947
  oldState
3679
3948
  } = get$2(uid);
3680
- set$5(uid, newState, newState);
3949
+ set$6(uid, newState, newState);
3681
3950
  const commands = applyRender(oldState, newState, diffResult);
3682
3951
  if (!isConnected()) {
3683
3952
  return commands;
@@ -3686,6 +3955,7 @@ const render2 = (uid, diffResult) => {
3686
3955
  };
3687
3956
 
3688
3957
  const renderEventListeners = () => {
3958
+ const DropId = 'event.dropId';
3689
3959
  return [{
3690
3960
  name: HandleBlur,
3691
3961
  params: ['handleBlur']
@@ -3701,6 +3971,25 @@ const renderEventListeners = () => {
3701
3971
  params: ['handleClick', Button$1, ClientX, ClientY, TargetName],
3702
3972
  preventDefault: false,
3703
3973
  stopPropagation: false
3974
+ }, {
3975
+ name: HandleDragOver,
3976
+ params: ['handleDragOver', ClientY],
3977
+ preventDefault: true
3978
+ }, {
3979
+ name: HandleDragLeave,
3980
+ params: ['handleDragLeave']
3981
+ }, {
3982
+ name: HandleDrop,
3983
+ params: ['handleDrop', DropId],
3984
+ preventDefault: true
3985
+ }, {
3986
+ // @ts-ignore
3987
+ dragEffect: 'move',
3988
+ name: HandleDragStart,
3989
+ params: ['handleDragStart', TargetName]
3990
+ }, {
3991
+ name: HandleDragEnd,
3992
+ params: ['handleDragEnd']
3704
3993
  }];
3705
3994
  };
3706
3995
 
@@ -3708,6 +3997,7 @@ const createDefaultState = () => ({
3708
3997
  accountEnabled: true,
3709
3998
  activityBarItems: [],
3710
3999
  currentViewletId: '',
4000
+ dragAndDropEnabled: false,
3711
4001
  filteredItems: [],
3712
4002
  focus: 0,
3713
4003
  focused: false,
@@ -3825,6 +4115,36 @@ const setAccountEnabled = (state, enabled) => {
3825
4115
  };
3826
4116
  };
3827
4117
 
4118
+ const applyComponentState = (currentState, state) => {
4119
+ if (!state || typeof state !== 'object' || Array.isArray(state)) {
4120
+ throw new TypeError('Activity Bar state must be an object');
4121
+ }
4122
+ const {
4123
+ uid
4124
+ } = state;
4125
+ const {
4126
+ uid: currentUid
4127
+ } = currentState;
4128
+ if (uid !== currentUid) {
4129
+ throw new Error(`Activity Bar state uid must remain ${currentUid}`);
4130
+ }
4131
+ return state;
4132
+ };
4133
+ const setComponentState = wrapCommand(applyComponentState);
4134
+
4135
+ const setDragAndDropEnabled = (state, enabled) => {
4136
+ const {
4137
+ dragAndDropEnabled
4138
+ } = state;
4139
+ if (dragAndDropEnabled === enabled) {
4140
+ return state;
4141
+ }
4142
+ return {
4143
+ ...state,
4144
+ dragAndDropEnabled: enabled
4145
+ };
4146
+ };
4147
+
3828
4148
  const providerKeys = ['userLoginProvider', 'loginProvider', 'authProvider', 'provider'];
3829
4149
  const getUserLoginProvider = userInfo => {
3830
4150
  if (!userInfo || typeof userInfo !== 'object') {
@@ -3890,7 +4210,7 @@ const toggleActivityBarItem = async (state, itemId) => {
3890
4210
  };
3891
4211
 
3892
4212
  const wakeUp = sleepState => {
3893
- set$5(sleepState.uid, sleepState, sleepState);
4213
+ set$6(sleepState.uid, sleepState, sleepState);
3894
4214
  };
3895
4215
 
3896
4216
  const handleDirectMessagePort = (port, setAsRendererProcess) => handleMessagePort(port, commandMap, setAsRendererProcess);
@@ -3905,6 +4225,7 @@ const commandMap = {
3905
4225
  'ActivityBar.focusNone': wrapCommand(focusNone),
3906
4226
  'ActivityBar.focusPrevious': wrapCommand(focusPrevious),
3907
4227
  'ActivityBar.getCommandIds': getCommandIds,
4228
+ 'ActivityBar.getComponentState': getComponentState,
3908
4229
  'ActivityBar.getKeyBindings': getKeyBindings,
3909
4230
  'ActivityBar.getMenuEntries': wrapGetter(getMenuEntries),
3910
4231
  'ActivityBar.getMenuEntryIds': getMenuEntryIds,
@@ -3920,6 +4241,11 @@ const commandMap = {
3920
4241
  'ActivityBar.handleClickSignIn': wrapCommand(handleClickSignIn),
3921
4242
  'ActivityBar.handleClickSignOut': wrapCommand(handleClickSignOut),
3922
4243
  'ActivityBar.handleContextMenu': wrapAsyncCommand(handleContextMenu),
4244
+ 'ActivityBar.handleDragEnd': wrapCommand(handleDragEnd),
4245
+ 'ActivityBar.handleDragLeave': wrapCommand(handleDragLeave),
4246
+ 'ActivityBar.handleDragOver': wrapCommand(handleDragOver),
4247
+ 'ActivityBar.handleDragStart': wrapCommand(handleDragStart),
4248
+ 'ActivityBar.handleDrop': wrapAsyncCommand(handleDrop),
3923
4249
  'ActivityBar.handleExtensionManagementMessagePort': handleExtensionManagementMessagePort,
3924
4250
  'ActivityBar.handleExtensionsChanged': wrapCommand(handleExtensionsChanged),
3925
4251
  'ActivityBar.handleFocus': wrapCommand(handleFocus),
@@ -3935,6 +4261,8 @@ const commandMap = {
3935
4261
  'ActivityBar.saveState': wrapGetter(saveState),
3936
4262
  'ActivityBar.selectCurrent': wrapCommand(selectCurrent),
3937
4263
  'ActivityBar.setAccountEnabled': wrapCommand(setAccountEnabled),
4264
+ 'ActivityBar.setComponentState': setComponentState,
4265
+ 'ActivityBar.setDragAndDropEnabled': wrapCommand(setDragAndDropEnabled),
3938
4266
  'ActivityBar.setUserLoginState': wrapCommand(setUserLoginState),
3939
4267
  'ActivityBar.sleep': sleep,
3940
4268
  'ActivityBar.terminate': terminate,
@@ -3942,6 +4270,20 @@ const commandMap = {
3942
4270
  'ActivityBar.wakeUp': wakeUp
3943
4271
  };
3944
4272
 
4273
+ const send$1 = async port => {
4274
+ await invokeAndTransfer('DragAndDrop.handleMessagePort', port);
4275
+ };
4276
+ const createDragAndDropWorkerRpc = async () => {
4277
+ return create$2({
4278
+ commandMap: {},
4279
+ send: send$1
4280
+ });
4281
+ };
4282
+
4283
+ const initializeDragAndDropWorker = async () => {
4284
+ set$4(await createDragAndDropWorkerRpc());
4285
+ };
4286
+
3945
4287
  const send = async port => {
3946
4288
  await sendMessagePortToExtensionManagementWorker(port, 0);
3947
4289
  };
@@ -3962,7 +4304,7 @@ const initializeRendererWorker = async () => {
3962
4304
 
3963
4305
  const listen = async () => {
3964
4306
  registerCommands(commandMap);
3965
- await Promise.all([initializeRendererWorker(), initializeExtensionManagementWorker()]);
4307
+ await Promise.all([initializeRendererWorker(), initializeExtensionManagementWorker(), initializeDragAndDropWorker()]);
3966
4308
  };
3967
4309
 
3968
4310
  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.2",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",