@lvce-editor/title-bar-worker 3.0.0 → 3.2.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.
@@ -1278,10 +1278,11 @@ const create$1 = () => {
1278
1278
  wrapCommand(fn) {
1279
1279
  const wrapped = async (uid, ...args) => {
1280
1280
  const {
1281
+ oldState,
1281
1282
  newState
1282
1283
  } = states[uid];
1283
1284
  const newerState = await fn(newState, ...args);
1284
- if (newState === newerState) {
1285
+ if (oldState === newerState || newState === newerState) {
1285
1286
  return;
1286
1287
  }
1287
1288
  const latest = states[uid];
@@ -1400,6 +1401,27 @@ const Selection$1 = 'Selection';
1400
1401
  const Terminal$1 = 'Terminal';
1401
1402
  const ToggleDeveloperTools = 'Toggle Developer Tools';
1402
1403
  const View$1 = 'View';
1404
+ const AddCursorAbove = 'Add Cursor Above';
1405
+ const AddCursorBelow = 'Add Cursor Below';
1406
+ const AddCursorsToLineEnds = 'Add Cursors to Line ends';
1407
+ const AddNextOccurrence = 'Add Next Occurrence';
1408
+ const AddPreviousOccurrence = 'Add Previous Occurrence';
1409
+ const Copy = 'Copy';
1410
+ const CopyLineDown = 'Copy Line Down';
1411
+ const CopyLineUp = 'Copy Line Up';
1412
+ const Cut = 'Cut';
1413
+ const DuplicateSelection = 'Duplicate Selection';
1414
+ const ExpandSelection = 'Expand Selection';
1415
+ const MoveLineDown = 'Move Line Down';
1416
+ const MoveLineUp = 'Move Line Up';
1417
+ const Paste = 'Paste';
1418
+ const Redo = 'Redo';
1419
+ const SelectAll = 'Select All';
1420
+ const SelectAllOccurrences = 'Select All Occurrences';
1421
+ const ShrinkSelection = 'Shrink Selection';
1422
+ const ToggleBlockComment = 'Toggle Block Comment';
1423
+ const ToggleLineComment = 'Toggle Line Comment';
1424
+ const Undo = 'Undo';
1403
1425
 
1404
1426
  const file = () => {
1405
1427
  return i18nString(File$2);
@@ -1678,58 +1700,68 @@ const getMenuIds = () => {
1678
1700
  return [Edit$2, File$3, Go$2, Help$2, OpenRecent$1, Run$2, Selection$2, Terminal$2, TitleBar, View$2, MenuIdTitleBarContextMenu, TitleBarContextMenu];
1679
1701
  };
1680
1702
 
1681
- /**
1682
- * @enum {string}
1683
- */
1684
- const UiStrings$1 = {
1685
- Copy: 'Copy',
1686
- CopyLineDown: 'Copy Line Down',
1687
- CopyLineUp: 'Copy Line Up',
1688
- Cut: 'Cut',
1689
- MoveLineDown: 'Move Line Down',
1690
- MoveLineUp: 'Move Line Up',
1691
- Paste: 'Paste',
1692
- Redo: 'Redo',
1693
- SelectAll: 'Select All',
1694
- ToggleBlockComment: 'Toggle Block Comment',
1695
- ToggleLineComment: 'Toggle Line Comment',
1696
- Undo: 'Undo'
1697
- };
1698
1703
  const cut = () => {
1699
- return i18nString(UiStrings$1.Cut);
1704
+ return i18nString(Cut);
1700
1705
  };
1701
1706
  const copy = () => {
1702
- return i18nString(UiStrings$1.Copy);
1707
+ return i18nString(Copy);
1703
1708
  };
1704
1709
  const paste = () => {
1705
- return i18nString(UiStrings$1.Paste);
1710
+ return i18nString(Paste);
1706
1711
  };
1707
1712
  const undo = () => {
1708
- return i18nString(UiStrings$1.Undo);
1713
+ return i18nString(Undo);
1709
1714
  };
1710
1715
  const redo = () => {
1711
- return i18nString(UiStrings$1.Redo);
1716
+ return i18nString(Redo);
1712
1717
  };
1713
1718
  const toggleLineComment = () => {
1714
- return i18nString(UiStrings$1.ToggleLineComment);
1719
+ return i18nString(ToggleLineComment);
1715
1720
  };
1716
1721
  const toggleBlockComment = () => {
1717
- return i18nString(UiStrings$1.ToggleBlockComment);
1722
+ return i18nString(ToggleBlockComment);
1718
1723
  };
1719
1724
  const selectAll = () => {
1720
- return i18nString(UiStrings$1.SelectAll);
1725
+ return i18nString(SelectAll);
1726
+ };
1727
+ const expandSelection = () => {
1728
+ return i18nString(ExpandSelection);
1729
+ };
1730
+ const shrinkSelection = () => {
1731
+ return i18nString(ShrinkSelection);
1721
1732
  };
1722
1733
  const copyLineUp = () => {
1723
- return i18nString(UiStrings$1.CopyLineUp);
1734
+ return i18nString(CopyLineUp);
1724
1735
  };
1725
1736
  const copyLineDown = () => {
1726
- return i18nString(UiStrings$1.CopyLineDown);
1737
+ return i18nString(CopyLineDown);
1727
1738
  };
1728
1739
  const moveLineUp = () => {
1729
- return i18nString(UiStrings$1.MoveLineUp);
1740
+ return i18nString(MoveLineUp);
1730
1741
  };
1731
1742
  const moveLineDown = () => {
1732
- return i18nString(UiStrings$1.MoveLineDown);
1743
+ return i18nString(MoveLineDown);
1744
+ };
1745
+ const duplicateSelection = () => {
1746
+ return i18nString(DuplicateSelection);
1747
+ };
1748
+ const addCursorAbove = () => {
1749
+ return i18nString(AddCursorAbove);
1750
+ };
1751
+ const addCursorBelow = () => {
1752
+ return i18nString(AddCursorBelow);
1753
+ };
1754
+ const addCursorsToLineEnds = () => {
1755
+ return i18nString(AddCursorsToLineEnds);
1756
+ };
1757
+ const addNextOccurrence = () => {
1758
+ return i18nString(AddNextOccurrence);
1759
+ };
1760
+ const addPreviousOccurrence = () => {
1761
+ return i18nString(AddPreviousOccurrence);
1762
+ };
1763
+ const selectAllOccurrences = () => {
1764
+ return i18nString(SelectAllOccurrences);
1733
1765
  };
1734
1766
 
1735
1767
  const menuEntrySeparator = {
@@ -2003,6 +2035,16 @@ const getMenuEntries$6 = () => {
2003
2035
  id: 'selectAll',
2004
2036
  label: selectAll()
2005
2037
  }, {
2038
+ command: 'Editor.expandSelection',
2039
+ flags: None,
2040
+ id: 'expandSelection',
2041
+ label: expandSelection()
2042
+ }, {
2043
+ command: 'Editor.shrinkSelection',
2044
+ flags: None,
2045
+ id: 'shrinkSelection',
2046
+ label: shrinkSelection()
2047
+ }, menuEntrySeparator, {
2006
2048
  command: 'Editor.copyLineUp',
2007
2049
  flags: None,
2008
2050
  id: 'copyLineUp',
@@ -2022,6 +2064,41 @@ const getMenuEntries$6 = () => {
2022
2064
  flags: Disabled,
2023
2065
  id: 'moveLineDown',
2024
2066
  label: moveLineDown()
2067
+ }, {
2068
+ command: 'Editor.duplicateSelection',
2069
+ flags: Disabled,
2070
+ id: 'duplicateSelection',
2071
+ label: duplicateSelection()
2072
+ }, menuEntrySeparator, {
2073
+ command: 'Editor.addCursorAbove',
2074
+ flags: Disabled,
2075
+ id: 'addCursorAbove',
2076
+ label: addCursorAbove()
2077
+ }, {
2078
+ command: 'Editor.addCursorBelow',
2079
+ flags: Disabled,
2080
+ id: 'addCursorBelow',
2081
+ label: addCursorBelow()
2082
+ }, {
2083
+ command: 'Editor.addCursorsToLineEnds',
2084
+ flags: Disabled,
2085
+ id: 'addCursorsToLineEnds',
2086
+ label: addCursorsToLineEnds()
2087
+ }, {
2088
+ command: 'Editor.addNextOccurrence',
2089
+ flags: Disabled,
2090
+ id: 'addNextOccurrence',
2091
+ label: addNextOccurrence()
2092
+ }, {
2093
+ command: 'Editor.addPreviousOccurrence',
2094
+ flags: Disabled,
2095
+ id: 'addPreviousOccurrence',
2096
+ label: addPreviousOccurrence()
2097
+ }, {
2098
+ command: 'Editor.selectAllOccurrences',
2099
+ flags: Disabled,
2100
+ id: 'selectAllOccurrences',
2101
+ label: selectAllOccurrences()
2025
2102
  }];
2026
2103
  };
2027
2104
 
@@ -2531,42 +2608,6 @@ const getMenuEntries$1 = async platform => {
2531
2608
  return fn();
2532
2609
  };
2533
2610
 
2534
- const getFn = id => {
2535
- switch (id) {
2536
- case Edit$2:
2537
- return getMenuEntries$c;
2538
- case File$3:
2539
- return getMenuEntries$b;
2540
- case Go$2:
2541
- return getMenuEntries$a;
2542
- case Help$2:
2543
- return getMenuEntries$9;
2544
- case OpenRecent$1:
2545
- return getMenuEntries$8;
2546
- case Run$2:
2547
- return getMenuEntries$7;
2548
- case Selection$2:
2549
- return getMenuEntries$6;
2550
- case Terminal$2:
2551
- return getMenuEntries$5;
2552
- case TitleBar:
2553
- return getMenuEntries$1;
2554
- case View$2:
2555
- return getMenuEntries$4;
2556
- default:
2557
- return undefined;
2558
- }
2559
- };
2560
- const getMenuEntries = async (id, ...args) => {
2561
- try {
2562
- const fn = getFn(id);
2563
- // @ts-ignore
2564
- return fn(...args);
2565
- } catch (error) {
2566
- throw new VError(error, `Failed to load menu entries for id ${id}`);
2567
- }
2568
- };
2569
-
2570
2611
  const loadContent2 = async state => {
2571
2612
  const {
2572
2613
  controlsOverlayEnabled,
@@ -2578,7 +2619,7 @@ const loadContent2 = async state => {
2578
2619
  platform,
2579
2620
  titleBarStyleCustom
2580
2621
  } = state;
2581
- const titleBarEntries = await getMenuEntries(TitleBar);
2622
+ const titleBarEntries = await getMenuEntries$1(platform);
2582
2623
  const withWidths = addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
2583
2624
  const buttons = getTitleBarButtons(platform, controlsOverlayEnabled, titleBarStyleCustom);
2584
2625
  const workspaceUri = await invoke('Workspace.getUri');
@@ -2885,7 +2926,10 @@ const createTitleBarButton = button => {
2885
2926
  return dom;
2886
2927
  };
2887
2928
 
2888
- const getTitleBarButtonsVirtualDom = buttons => {
2929
+ const getTitleBarButtonsVirtualDom = (buttonsEnabled, buttons) => {
2930
+ if (!buttonsEnabled) {
2931
+ return [];
2932
+ }
2889
2933
  return [{
2890
2934
  childCount: buttons.length,
2891
2935
  className: mergeClassNames(Viewlet, TitleBarButtons),
@@ -2898,7 +2942,10 @@ const parentNode$1 = {
2898
2942
  className: mergeClassNames(Viewlet, TitleBarIcon),
2899
2943
  type: Div
2900
2944
  };
2901
- const getTitleBarIconVirtualDom = iconSrc => {
2945
+ const getTitleBarIconVirtualDom = (titleBarIconEnabled, iconSrc) => {
2946
+ if (!titleBarIconEnabled) {
2947
+ return [];
2948
+ }
2902
2949
  return [parentNode$1, {
2903
2950
  alt: '',
2904
2951
  childCount: 0,
@@ -2928,34 +2975,27 @@ const getItemVirtualDom = item => {
2928
2975
  keyboardShortCut,
2929
2976
  label
2930
2977
  } = item;
2931
- // TODO avoid mutation
2932
- const dom = [{
2978
+ let className = TitleBarTopLevelEntry;
2979
+ if (isFocused) {
2980
+ className += ' ' + TitleBarEntryActive;
2981
+ }
2982
+ return [{
2933
2983
  ariaExpanded: isOpen,
2934
2984
  ariaHasPopup: true,
2935
2985
  ariaKeyShortcuts: keyboardShortCut,
2986
+ ariaOwns: isOpen ? 'Menu-0' : undefined,
2936
2987
  childCount: 1,
2937
- className: TitleBarTopLevelEntry,
2988
+ className,
2989
+ id: isFocused ? 'TitleBarEntryActive' : undefined,
2938
2990
  name: label,
2939
2991
  // TODO have separate name attribute
2940
2992
  role: MenuItem$1,
2941
2993
  type: Button$1
2942
- }];
2943
- if (isOpen) {
2944
- // @ts-ignore
2945
- dom[0].ariaOwns = 'Menu-0';
2946
- }
2947
- if (isFocused) {
2948
- dom[0].className += ' ' + TitleBarEntryActive;
2949
- // @ts-ignore
2950
- dom[0].id = 'TitleBarEntryActive';
2951
- dom.push({
2952
- childCount: 1,
2953
- className: TitleBarTopLevelEntryLabel,
2954
- type: Div
2955
- });
2956
- }
2957
- dom.push(text(label));
2958
- return dom;
2994
+ }, ...(isFocused ? [{
2995
+ childCount: 1,
2996
+ className: TitleBarTopLevelEntryLabel,
2997
+ type: Div
2998
+ }] : []), text(label)];
2959
2999
  };
2960
3000
  const getTitleBarMenuBarItemsVirtualDom = visibleItems => {
2961
3001
  const dom = visibleItems.flatMap(getItemVirtualDom);
@@ -2963,7 +3003,10 @@ const getTitleBarMenuBarItemsVirtualDom = visibleItems => {
2963
3003
  };
2964
3004
 
2965
3005
  const activeId = 'TitleBarEntryActive';
2966
- const getTitleBarMenuBarVirtualDom = (visibleItems, focusedIndex) => {
3006
+ const getTitleBarMenuBarVirtualDom = (menuBarEnabled, visibleItems, focusedIndex) => {
3007
+ if (!menuBarEnabled) {
3008
+ return [];
3009
+ }
2967
3010
  return [{
2968
3011
  ariaActivedescendant: focusedIndex === -1 ? '' : activeId,
2969
3012
  childCount: visibleItems.length,
@@ -2984,7 +3027,10 @@ const parentNode = {
2984
3027
  className: 'TitleBarTitle',
2985
3028
  type: Div
2986
3029
  };
2987
- const getTitleVirtualDom = title => {
3030
+ const getTitleVirtualDom = (titleBarTitleEnabled, title) => {
3031
+ if (!titleBarTitleEnabled) {
3032
+ return [];
3033
+ }
2988
3034
  return [parentNode, text(title)];
2989
3035
  };
2990
3036
 
@@ -3035,44 +3081,24 @@ const getTitleBarVirtualDom = state => {
3035
3081
  isMenuOpen,
3036
3082
  title,
3037
3083
  titleBarButtons,
3084
+ titleBarButtonsEnabled,
3038
3085
  titleBarEntries,
3086
+ titleBarIconEnabled,
3087
+ titleBarMenuBarEnabled,
3088
+ titleBarTitleEnabled,
3039
3089
  width
3040
3090
  } = state;
3041
- const dom = [{
3091
+ const iconSrc = getIcon(assetDir);
3092
+ const visibleEntries = getVisibleTitleBarEntries(titleBarEntries, width, focusedIndex, isMenuOpen);
3093
+ return [{
3042
3094
  ariaLabel: 'Title Bar',
3095
+ // TODO i18n string
3043
3096
  childCount: 4,
3044
3097
  className: 'Viewlet TitleBar',
3045
3098
  id: 'TitleBar',
3046
3099
  role: ContentInfo,
3047
3100
  type: Div
3048
- }];
3049
-
3050
- // Add icon if enabled
3051
- if (state.titleBarIconEnabled) {
3052
- const iconSrc = getIcon(assetDir);
3053
- const iconDom = getTitleBarIconVirtualDom(iconSrc);
3054
- dom.push(...iconDom);
3055
- }
3056
-
3057
- // Add menu bar if enabled
3058
- if (state.titleBarMenuBarEnabled) {
3059
- const visibleEntries = getVisibleTitleBarEntries(titleBarEntries, width, focusedIndex, isMenuOpen);
3060
- const menuBarDom = getTitleBarMenuBarVirtualDom(visibleEntries, focusedIndex);
3061
- dom.push(...menuBarDom);
3062
- }
3063
-
3064
- // Add title if enabled
3065
- if (state.titleBarTitleEnabled) {
3066
- const titleDom = getTitleVirtualDom(title);
3067
- dom.push(...titleDom);
3068
- }
3069
-
3070
- // Add buttons if enabled
3071
- if (state.titleBarButtonsEnabled) {
3072
- const buttonsDom = getTitleBarButtonsVirtualDom(titleBarButtons);
3073
- dom.push(...buttonsDom);
3074
- }
3075
- return dom;
3101
+ }, ...getTitleBarIconVirtualDom(titleBarIconEnabled, iconSrc), ...getTitleBarMenuBarVirtualDom(titleBarMenuBarEnabled, visibleEntries, focusedIndex), ...getTitleVirtualDom(titleBarTitleEnabled, title), ...getTitleBarButtonsVirtualDom(titleBarButtonsEnabled, titleBarButtons)];
3076
3102
  };
3077
3103
 
3078
3104
  const renderTitleBar = (oldState, newState) => {
@@ -3356,6 +3382,9 @@ const handleKeyArrowDownMenuOpen = state => {
3356
3382
  menus
3357
3383
  } = state;
3358
3384
  const menu = menus.at(-1);
3385
+ if (!menu) {
3386
+ return state;
3387
+ }
3359
3388
  const newFocusedIndex = getIndexToFocusNext(menu);
3360
3389
  const newMenus = [...menus.slice(0, -1), {
3361
3390
  ...menu,
@@ -3379,6 +3408,9 @@ const closeOneMenu = state => {
3379
3408
  menus
3380
3409
  } = state;
3381
3410
  const parentMenu = menus.at(-2);
3411
+ if (!parentMenu) {
3412
+ return state;
3413
+ }
3382
3414
  const newParentMenu = {
3383
3415
  ...parentMenu,
3384
3416
  expanded: false
@@ -3402,6 +3434,42 @@ const handleKeyArrowLeftMenuOpen = async state => {
3402
3434
 
3403
3435
  const handleKeyArrowLeft = ifElse(handleKeyArrowLeftMenuOpen, handleKeyArrowLeftMenuClosed);
3404
3436
 
3437
+ const getFn = id => {
3438
+ switch (id) {
3439
+ case Edit$2:
3440
+ return getMenuEntries$c;
3441
+ case File$3:
3442
+ return getMenuEntries$b;
3443
+ case Go$2:
3444
+ return getMenuEntries$a;
3445
+ case Help$2:
3446
+ return getMenuEntries$9;
3447
+ case OpenRecent$1:
3448
+ return getMenuEntries$8;
3449
+ case Run$2:
3450
+ return getMenuEntries$7;
3451
+ case Selection$2:
3452
+ return getMenuEntries$6;
3453
+ case Terminal$2:
3454
+ return getMenuEntries$5;
3455
+ case TitleBar:
3456
+ return getMenuEntries$1;
3457
+ case View$2:
3458
+ return getMenuEntries$4;
3459
+ default:
3460
+ return undefined;
3461
+ }
3462
+ };
3463
+ const getMenuEntries = async (id, ...args) => {
3464
+ try {
3465
+ const fn = getFn(id);
3466
+ // @ts-ignore
3467
+ return fn(...args);
3468
+ } catch (error) {
3469
+ throw new VError(error, `Failed to load menu entries for id ${id}`);
3470
+ }
3471
+ };
3472
+
3405
3473
  // TODO menu should not be needed initially, only when item is selected and menu is opened
3406
3474
  const handleKeyArrowRightMenuOpen = async state => {
3407
3475
  const {
@@ -3409,6 +3477,9 @@ const handleKeyArrowRightMenuOpen = async state => {
3409
3477
  } = state;
3410
3478
  // if menu can open sub menu to the right -> do that
3411
3479
  const menu = menus.at(-1);
3480
+ if (!menu) {
3481
+ return state;
3482
+ }
3412
3483
  const {
3413
3484
  focusedIndex,
3414
3485
  items,
@@ -3620,14 +3691,11 @@ const handleMenuClick = async (state, level, index) => {
3620
3691
  }
3621
3692
  };
3622
3693
 
3623
- const handleMenuMouseOver = async (state, level, index) => {
3624
- object(state);
3625
- number(level);
3626
- number(index);
3627
- const {
3628
- menus
3629
- } = state;
3694
+ const getNewMenus = async (menus, level, index, flags) => {
3630
3695
  const menu = menus[level];
3696
+ if (!menu) {
3697
+ return menus;
3698
+ }
3631
3699
  const {
3632
3700
  focusedIndex,
3633
3701
  items,
@@ -3637,7 +3705,7 @@ const handleMenuMouseOver = async (state, level, index) => {
3637
3705
  const item = items[index];
3638
3706
  if (focusedIndex === index) {
3639
3707
  if (index === -1) {
3640
- return state;
3708
+ return menus;
3641
3709
  }
3642
3710
  if (item.flags === SubMenu && level === menus.length - 2) {
3643
3711
  const subMenu = menus[level + 1];
@@ -3647,23 +3715,17 @@ const handleMenuMouseOver = async (state, level, index) => {
3647
3715
  focusedIndex: -1
3648
3716
  };
3649
3717
  const newMenus = [...menus.slice(0, -1), newSubMenu];
3650
- return {
3651
- ...state,
3652
- menus: newMenus
3653
- };
3718
+ return newMenus;
3654
3719
  }
3655
3720
  }
3656
- return state;
3721
+ return menus;
3657
3722
  }
3658
3723
  if (index === -1) {
3659
3724
  const newMenus = [...menus.slice(0, level), {
3660
3725
  ...menu,
3661
3726
  focusedIndex: -1
3662
3727
  }];
3663
- return {
3664
- ...state,
3665
- menus: newMenus
3666
- };
3728
+ return newMenus;
3667
3729
  }
3668
3730
  if (item.flags === SubMenu) {
3669
3731
  const item = items[index];
@@ -3680,15 +3742,36 @@ const handleMenuMouseOver = async (state, level, index) => {
3680
3742
  focusedIndex: index
3681
3743
  };
3682
3744
  const newMenus = [...menus.slice(0, level - 1), newParentMenu, subMenu];
3683
- return {
3684
- ...state,
3685
- menus: newMenus
3686
- };
3745
+ return newMenus;
3687
3746
  }
3688
3747
  const newMenus = [...menus.slice(0, level), {
3689
3748
  ...menu,
3690
3749
  focusedIndex: index
3691
3750
  }];
3751
+ return newMenus;
3752
+ };
3753
+ const handleMenuMouseOver = async (state, level, index) => {
3754
+ object(state);
3755
+ number(level);
3756
+ number(index);
3757
+ const {
3758
+ menus
3759
+ } = state;
3760
+ const menu = menus[level];
3761
+ if (!menu) {
3762
+ return state;
3763
+ }
3764
+ const {
3765
+ items
3766
+ } = menu;
3767
+ const item = items[index];
3768
+ if (!item) {
3769
+ return state;
3770
+ }
3771
+ const newMenus = await getNewMenus(menus, level, index);
3772
+ if (menus === newMenus) {
3773
+ return state;
3774
+ }
3692
3775
  return {
3693
3776
  ...state,
3694
3777
  menus: newMenus
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/title-bar-worker",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "Title Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",