@lvce-editor/title-bar-worker 4.9.0 → 4.9.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.
@@ -598,7 +598,10 @@ const constructError = (message, type, name) => {
598
598
  if (ErrorConstructor === Error) {
599
599
  const error = new Error(message);
600
600
  if (name && name !== 'VError') {
601
- error.name = name;
601
+ Object.defineProperty(error, 'name', {
602
+ configurable: true,
603
+ value: name
604
+ });
602
605
  }
603
606
  return error;
604
607
  }
@@ -629,31 +632,45 @@ const getParentStack = error => {
629
632
  };
630
633
  const MethodNotFound = -32601;
631
634
  const Custom = -32001;
635
+ const setStack = (error, stack) => {
636
+ const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
637
+ if (descriptor) {
638
+ if (!descriptor.configurable && !descriptor.writable) {
639
+ return;
640
+ }
641
+ if (!descriptor.configurable && descriptor.writable) {
642
+ error.stack = stack;
643
+ return;
644
+ }
645
+ }
646
+ Object.defineProperty(error, 'stack', {
647
+ configurable: true,
648
+ value: stack,
649
+ writable: true
650
+ });
651
+ };
632
652
  const restoreExistingError = (error, currentStack) => {
633
653
  if (typeof error.stack === 'string') {
634
- error.stack = error.stack + NewLine + currentStack;
654
+ setStack(error, `${error.stack}${NewLine}${currentStack}`);
635
655
  }
636
656
  return error;
637
657
  };
638
658
  const restoreMethodNotFoundError = (error, currentStack) => {
639
659
  const restoredError = new JsonRpcError(error.message);
640
660
  const parentStack = getParentStack(error);
641
- restoredError.stack = parentStack + NewLine + currentStack;
661
+ setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
642
662
  return restoredError;
643
663
  };
644
664
  const restoreStackFromData = (restoredError, error, currentStack) => {
645
665
  if (error.data.stack && error.data.type && error.message) {
646
- restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
666
+ setStack(restoredError, `${error.data.type}: ${error.message}${NewLine}${error.data.stack}${NewLine}${currentStack}`);
647
667
  return;
648
668
  }
649
669
  if (error.data.stack) {
650
- restoredError.stack = error.data.stack;
670
+ setStack(restoredError, error.data.stack);
651
671
  }
652
672
  };
653
673
  const applyDataProperties = (restoredError, error) => {
654
- if (!error.data) {
655
- return;
656
- }
657
674
  restoreStackFromData(restoredError, error, getCurrentStack());
658
675
  if (error.data.codeFrame) {
659
676
  // @ts-ignore
@@ -674,7 +691,7 @@ const applyDirectProperties = (restoredError, error) => {
674
691
  const indexNewLine = getNewLineIndex(lowerStack);
675
692
  const parentStack = getParentStack(error);
676
693
  // @ts-ignore
677
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
694
+ setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
678
695
  }
679
696
  if (error.codeFrame) {
680
697
  // @ts-ignore
@@ -1358,9 +1375,9 @@ const F5$1 = 61;
1358
1375
  const F6$1 = 62;
1359
1376
  const Equal$1 = 84;
1360
1377
  const Comma$1 = 85;
1361
- const Minus$1 = 86;
1362
- const Backquote$1 = 89;
1363
- const Backslash$1 = 91;
1378
+ const Minus$2 = 86;
1379
+ const Backquote$2 = 89;
1380
+ const Backslash$2 = 91;
1364
1381
  const Star$1 = 131;
1365
1382
  const Plus$1 = 132;
1366
1383
 
@@ -1424,15 +1441,15 @@ const F5 = 'F5';
1424
1441
  const F6 = 'F6';
1425
1442
  const Equal = '=';
1426
1443
  const Comma = ',';
1427
- const Minus = 'Minus';
1428
- const Backquote = 'Backquote';
1429
- const Backslash = 'Backslash';
1444
+ const Minus$1 = 'Minus';
1445
+ const Backquote$1 = 'Backquote';
1446
+ const Backslash$1 = 'Backslash';
1430
1447
  const Star = '*';
1431
1448
  const Plus = '+';
1432
1449
 
1433
1450
  const keyCodeStringMap = {
1434
- [Backquote$1]: Backquote,
1435
- [Backslash$1]: Backslash,
1451
+ [Backquote$2]: Backquote$1,
1452
+ [Backslash$2]: Backslash$1,
1436
1453
  [Backspace$1]: Backspace,
1437
1454
  [Comma$1]: Comma,
1438
1455
  [Delete$1]: Delete,
@@ -1486,7 +1503,7 @@ const keyCodeStringMap = {
1486
1503
  [KeyY$1]: KeyY,
1487
1504
  [KeyZ$1]: KeyZ,
1488
1505
  [LeftArrow$1]: LeftArrow,
1489
- [Minus$1]: Minus,
1506
+ [Minus$2]: Minus$1,
1490
1507
  [PageDown$1]: PageDown,
1491
1508
  [PageUp$1]: PageUp,
1492
1509
  [Plus$1]: Plus,
@@ -2342,12 +2359,12 @@ const selectAllOccurrences = () => {
2342
2359
 
2343
2360
  const getMenuEntries$d = () => {
2344
2361
  return [{
2345
- command: /* TODO */'-1',
2362
+ command: 'Editor.undo',
2346
2363
  flags: None,
2347
2364
  id: 'undo',
2348
2365
  label: undo()
2349
2366
  }, {
2350
- command: /* TODO */'-1',
2367
+ command: 'Editor.redo',
2351
2368
  flags: None,
2352
2369
  id: 'redo',
2353
2370
  label: redo()
@@ -2381,79 +2398,79 @@ const getMenuEntries$d = () => {
2381
2398
 
2382
2399
  const getMenuEntries$c = () => {
2383
2400
  return [{
2384
- command: 'MainArea.splitUp',
2401
+ command: 'Main.splitUp',
2385
2402
  flags: None,
2386
2403
  id: 'splitUp',
2387
2404
  keyboardShortCut: 'Ctrl+K Ctrl+\\',
2388
2405
  label: i18nString(SplitUp)
2389
2406
  }, {
2390
- command: 'MainArea.splitDown',
2407
+ command: 'Main.splitDown',
2391
2408
  flags: None,
2392
2409
  id: 'splitDown',
2393
2410
  label: i18nString(SplitDown)
2394
2411
  }, {
2395
- command: 'MainArea.splitLeft',
2412
+ command: 'Main.splitLeft',
2396
2413
  flags: None,
2397
2414
  id: 'splitLeft',
2398
2415
  label: i18nString(SplitLeft)
2399
2416
  }, {
2400
- command: 'MainArea.splitRight',
2417
+ command: 'Main.splitRight',
2401
2418
  flags: None,
2402
2419
  id: 'splitRight',
2403
2420
  label: i18nString(SplitRight)
2404
2421
  }, menuEntrySeparator, {
2405
- command: 'MainArea.moveIntoNewWindow',
2422
+ command: 'Main.moveIntoNewWindow',
2406
2423
  flags: None,
2407
2424
  id: 'moveEditorIntoNewWindow',
2408
2425
  label: i18nString(MoveEditorIntoNewWindow)
2409
2426
  }, {
2410
- command: 'MainArea.copyIntoNewWindow',
2427
+ command: 'Main.copyIntoNewWindow',
2411
2428
  flags: None,
2412
2429
  id: 'copyEditorIntoNewWindow',
2413
2430
  keyboardShortCut: 'Ctrl+K O',
2414
2431
  label: i18nString(CopyEditorIntoNewWindow)
2415
2432
  }, menuEntrySeparator, {
2416
- command: 'MainArea.setEditorLayoutSingle',
2433
+ command: 'Main.setEditorLayoutSingle',
2417
2434
  flags: None,
2418
2435
  id: 'single',
2419
2436
  label: i18nString(Single)
2420
2437
  }, {
2421
- command: 'MainArea.setEditorLayoutTwoColumns',
2438
+ command: 'Main.setEditorLayoutTwoColumns',
2422
2439
  flags: None,
2423
2440
  id: 'twoColumns',
2424
2441
  label: i18nString(TwoColumns)
2425
2442
  }, {
2426
- command: 'MainArea.setEditorLayoutThreeColumns',
2443
+ command: 'Main.setEditorLayoutThreeColumns',
2427
2444
  flags: None,
2428
2445
  id: 'threeColumns',
2429
2446
  label: i18nString(ThreeColumns)
2430
2447
  }, {
2431
- command: 'MainArea.setEditorLayoutTwoRows',
2448
+ command: 'Main.setEditorLayoutTwoRows',
2432
2449
  flags: None,
2433
2450
  id: 'twoRows',
2434
2451
  label: i18nString(TwoRows)
2435
2452
  }, {
2436
- command: 'MainArea.setEditorLayoutThreeRows',
2453
+ command: 'Main.setEditorLayoutThreeRows',
2437
2454
  flags: None,
2438
2455
  id: 'threeRows',
2439
2456
  label: i18nString(ThreeRows)
2440
2457
  }, {
2441
- command: 'MainArea.setEditorLayoutGrid',
2458
+ command: 'Main.setEditorLayoutGrid',
2442
2459
  flags: None,
2443
2460
  id: 'gridTwoByTwo',
2444
2461
  label: i18nString(GridTwoByTwo)
2445
2462
  }, {
2446
- command: 'MainArea.setEditorLayoutTwoRowsRight',
2463
+ command: 'Main.setEditorLayoutTwoRowsRight',
2447
2464
  flags: None,
2448
2465
  id: 'twoRowsRight',
2449
2466
  label: i18nString(TwoRowsRight)
2450
2467
  }, {
2451
- command: 'MainArea.setEditorLayoutTwoColumnsBottom',
2468
+ command: 'Main.setEditorLayoutTwoColumnsBottom',
2452
2469
  flags: None,
2453
2470
  id: 'twoColumnsBottom',
2454
2471
  label: i18nString(TwoColumnsBottom)
2455
2472
  }, menuEntrySeparator, {
2456
- command: 'MainArea.flipEditorLayout',
2473
+ command: 'Main.flipEditorLayout',
2457
2474
  flags: None,
2458
2475
  id: 'flipLayout',
2459
2476
  keyboardShortCut: 'Shift+Alt+8',
@@ -3490,6 +3507,34 @@ const getTitleBarIndexFromPosition = (titleBarEntries, x, y) => {
3490
3507
  return -1;
3491
3508
  };
3492
3509
 
3510
+ const toCommandInfo = entry => {
3511
+ return {
3512
+ args: entry.args,
3513
+ command: entry.command
3514
+ };
3515
+ };
3516
+ const addMenuEntryKeyBindings = async entries => {
3517
+ try {
3518
+ const commands = entries.map(toCommandInfo);
3519
+ const keys = await invoke('Layout.getKeyBindings', commands);
3520
+ if (!keys.some(Boolean)) {
3521
+ return entries;
3522
+ }
3523
+ return entries.map((entry, index) => {
3524
+ const key = keys[index];
3525
+ if (!key) {
3526
+ return entry;
3527
+ }
3528
+ return {
3529
+ ...entry,
3530
+ key
3531
+ };
3532
+ });
3533
+ } catch {
3534
+ return entries;
3535
+ }
3536
+ };
3537
+
3493
3538
  const getTotalWidth = entries => {
3494
3539
  let total = 0;
3495
3540
  for (const entry of entries) {
@@ -3601,10 +3646,11 @@ const openMenuAtIndex = async (state, index, shouldBeFocused) => {
3601
3646
  const {
3602
3647
  id
3603
3648
  } = titleBarEntry;
3604
- const items = id === OverflowMenuId ? getOverflowMenuItems(titleBarEntry.hiddenEntries || []) : await getMenuEntries2(state, {
3649
+ const rawItems = id === OverflowMenuId ? getOverflowMenuItems(titleBarEntry.hiddenEntries || []) : await getMenuEntries2(state, {
3605
3650
  menuId: id,
3606
3651
  platform
3607
3652
  });
3653
+ const items = id === OverflowMenuId ? rawItems : await addMenuEntryKeyBindings(rawItems);
3608
3654
  const relevantEntries = titleBarEntries.slice(0, index);
3609
3655
  const totalWidths = getTotalWidth(relevantEntries);
3610
3656
  const offset = totalWidths;
@@ -3942,42 +3988,53 @@ const TitleBarTopLevelEntry = 'TitleBarTopLevelEntry';
3942
3988
  const TitleBarTopLevelEntryLabel = 'TitleBarTopLevelEntryLabel';
3943
3989
  const Viewlet = 'Viewlet';
3944
3990
 
3945
- const checkMark = {
3946
- className: mergeClassNames(MenuItemCheckmarkIcon, MaskIconCheck),
3947
- type: Div
3948
- };
3949
- const getMenuItemCheckedDom = menuItem => {
3950
- const {
3951
- isFocused,
3952
- label
3953
- } = menuItem;
3954
- const baseClassName = mergeClassNames(MenuItem, MenuItemCheckMark);
3955
- const className = isFocused ? mergeClassNames(baseClassName, MenuItemFocused) : baseClassName;
3956
- return [{
3957
- ariaChecked: true,
3958
- childCount: 2,
3959
- className,
3960
- role: MenuItemCheckBox,
3961
- tabIndex: -1,
3962
- type: Div
3963
- }, checkMark, text(label)];
3964
- };
3965
-
3966
3991
  const getKeyBindingString = (key, altKey, ctrlKey, shiftKey, metaKey) => {
3967
3992
  let string = '';
3968
3993
  if (ctrlKey) {
3969
3994
  string += 'Ctrl+';
3970
3995
  }
3996
+ if (altKey) {
3997
+ string += 'Alt+';
3998
+ }
3971
3999
  if (shiftKey) {
3972
4000
  string += 'Shift+';
3973
4001
  }
3974
- string += key.toUpperCase();
4002
+ string += key.length === 1 ? key.toUpperCase() : key;
3975
4003
  return string;
3976
4004
  };
3977
4005
 
4006
+ const F11 = 67;
4007
+ const Minus = 86;
4008
+ const Slash = 88;
4009
+ const Backquote = 89;
4010
+ const Backslash = 91;
4011
+ const Numpad0 = 96;
4012
+
4013
+ const getKeyLabel = (keyCode, fallback) => {
4014
+ switch (keyCode) {
4015
+ case Backquote:
4016
+ return '`';
4017
+ case Backslash:
4018
+ return '\\';
4019
+ case F11:
4020
+ return 'F11';
4021
+ case Minus:
4022
+ return '-';
4023
+ case Numpad0:
4024
+ return 'NumPad0';
4025
+ case Slash:
4026
+ return '/';
4027
+ default:
4028
+ return fallback;
4029
+ }
4030
+ };
4031
+
4032
+ const altKeyMask = 1 << 9;
3978
4033
  const getKeyDom = key => {
3979
4034
  const parsedKey = parseKey(key);
3980
- const keyBindingsString = getKeyBindingString(parsedKey.key, false, parsedKey.isCtrl, parsedKey.isShift);
4035
+ const isAlt = Boolean(key & altKeyMask);
4036
+ const keyLabel = getKeyLabel(key & 0xff, parsedKey.key);
4037
+ const keyBindingsString = getKeyBindingString(keyLabel, isAlt, parsedKey.isCtrl, parsedKey.isShift);
3981
4038
  return [{
3982
4039
  childCount: 1,
3983
4040
  className: MenuItemKeyBinding,
@@ -3985,6 +4042,29 @@ const getKeyDom = key => {
3985
4042
  }, text(keyBindingsString)];
3986
4043
  };
3987
4044
 
4045
+ const checkMark = {
4046
+ className: mergeClassNames(MenuItemCheckmarkIcon, MaskIconCheck),
4047
+ type: Div
4048
+ };
4049
+ const getMenuItemCheckedDom = menuItem => {
4050
+ const {
4051
+ isFocused,
4052
+ key,
4053
+ label
4054
+ } = menuItem;
4055
+ const baseClassName = mergeClassNames(MenuItem, MenuItemCheckMark);
4056
+ const className = isFocused ? mergeClassNames(baseClassName, MenuItemFocused) : baseClassName;
4057
+ const keyDom = key ? getKeyDom(key) : [];
4058
+ return [{
4059
+ ariaChecked: true,
4060
+ childCount: key ? 3 : 2,
4061
+ className,
4062
+ role: MenuItemCheckBox,
4063
+ tabIndex: -1,
4064
+ type: Div
4065
+ }, checkMark, text(label), ...keyDom];
4066
+ };
4067
+
3988
4068
  const classNameFocused = mergeClassNames(MenuItem, MenuItemFocused);
3989
4069
  const getMenuItemClassName = isFocused => {
3990
4070
  if (isFocused) {
@@ -4010,19 +4090,20 @@ const getMenuItemDefaultDom = menuItem => {
4010
4090
  }, text(label), ...keyDom];
4011
4091
  };
4012
4092
 
4013
- const disabled = {
4014
- childCount: 1,
4015
- className: MenuItem,
4016
- disabled: true,
4017
- role: MenuItem$1,
4018
- tabIndex: -1,
4019
- type: Div
4020
- };
4021
4093
  const getMenuItemDisabledDom = menuItem => {
4022
4094
  const {
4095
+ key,
4023
4096
  label
4024
4097
  } = menuItem;
4025
- return [disabled, text(label)];
4098
+ const keyDom = key ? getKeyDom(key) : [];
4099
+ return [{
4100
+ childCount: key ? 2 : 1,
4101
+ className: MenuItem,
4102
+ disabled: true,
4103
+ role: MenuItem$1,
4104
+ tabIndex: -1,
4105
+ type: Div
4106
+ }, text(label), ...keyDom];
4026
4107
  };
4027
4108
 
4028
4109
  const getMenuItemsNoopDom = () => {
@@ -4073,17 +4154,19 @@ const getMenuItemSubMenuDom = menuItem => {
4073
4154
  const getMenuItemUncheckedDom = menuItem => {
4074
4155
  const {
4075
4156
  isFocused,
4157
+ key,
4076
4158
  label
4077
4159
  } = menuItem;
4078
4160
  const className = isFocused ? mergeClassNames(MenuItem, MenuItemFocused) : MenuItem;
4161
+ const keyDom = key ? getKeyDom(key) : [];
4079
4162
  return [{
4080
4163
  ariaChecked: false,
4081
- childCount: 1,
4164
+ childCount: key ? 2 : 1,
4082
4165
  className,
4083
4166
  role: MenuItemCheckBox,
4084
4167
  tabIndex: -1,
4085
4168
  type: Div
4086
- }, text(label)];
4169
+ }, text(label), ...keyDom];
4087
4170
  };
4088
4171
 
4089
4172
  const getMenuItemRenderer = flags => {
@@ -4778,7 +4861,8 @@ const handleKeyArrowRightMenuOpen = async state => {
4778
4861
  }
4779
4862
  const item = items[focusedIndex];
4780
4863
  if (item.flags === SubMenu$1 && item.id !== undefined) {
4781
- const subMenuEntries = await getMenuEntries(item.id);
4864
+ const rawSubMenuEntries = await getMenuEntries(item.id);
4865
+ const subMenuEntries = await addMenuEntryKeyBindings(rawSubMenuEntries);
4782
4866
  const subMenu = {
4783
4867
  focusedIndex: 0,
4784
4868
  items: subMenuEntries,
@@ -4943,7 +5027,8 @@ const selectIndexSubMenu = async (state, menu, index) => {
4943
5027
  if (!item.id) {
4944
5028
  return state;
4945
5029
  }
4946
- const subMenuEntries = await getMenuEntries(item.id);
5030
+ const rawSubMenuEntries = await getMenuEntries(item.id);
5031
+ const subMenuEntries = await addMenuEntryKeyBindings(rawSubMenuEntries);
4947
5032
  const subMenu = {
4948
5033
  focusedIndex: -1,
4949
5034
  items: subMenuEntries,
@@ -5030,7 +5115,8 @@ const getNewMenus = async (menus, level, index, flags) => {
5030
5115
  if (!item.id) {
5031
5116
  return menus;
5032
5117
  }
5033
- const subMenuEntries = await getMenuEntries(item.id);
5118
+ const rawSubMenuEntries = await getMenuEntries(item.id);
5119
+ const subMenuEntries = await addMenuEntryKeyBindings(rawSubMenuEntries);
5034
5120
  const subMenu = {
5035
5121
  focusedIndex: -1,
5036
5122
  items: subMenuEntries,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/title-bar-worker",
3
- "version": "4.9.0",
3
+ "version": "4.9.1",
4
4
  "description": "Title Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",