@lvce-editor/title-bar-worker 1.7.0 → 1.9.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.
@@ -901,7 +901,7 @@ const DiffMenus = {
901
901
  isEqual
902
902
  };
903
903
 
904
- const modules = [DiffFocusedIndex, DiffEntries, DiffMenus];
904
+ const modules = [DiffEntries, DiffFocusedIndex, DiffMenus];
905
905
 
906
906
  const diff = (oldState, newState) => {
907
907
  const diffResult = [];
@@ -920,6 +920,17 @@ const MenuItemCheckBox = 'menuitemcheckbox';
920
920
  const None$1 = 'none';
921
921
  const Separator$1 = 'separator';
922
922
 
923
+ const HandleClick = 'handleClick';
924
+ const HandleClickMinimize = 'handleClickMinimize';
925
+ const HandleClickToggleClose = 'handleClickToggleClose';
926
+ const HandleClickToggleMaximize = 'handleClickToggleMaximize';
927
+ const HandleFocusIn = 'handleFocusIn';
928
+ const HandleFocusOut = 'handleFocusOut';
929
+ const HandlePointerOut = 'handlePointerOut';
930
+ const HandlePointerOver = 'handlePointerOver';
931
+ const HandleMenuClick = 'handleMenuClick';
932
+ const HandleMenuMouseOver = 'handleMenuMouseOver';
933
+
923
934
  const Menu = 'Menu';
924
935
  const MenuItem = 'MenuItem';
925
936
  const MenuItemFocused = 'MenuItemFocused';
@@ -931,6 +942,165 @@ const TitleBarEntryActive = 'TitleBarEntryActive';
931
942
  const TitleBarTopLevelEntry = 'TitleBarTopLevelEntry';
932
943
  const TitleBarTopLevelEntryLabel = 'TitleBarTopLevelEntryLabel';
933
944
 
945
+ const Button = 1;
946
+ const Div = 4;
947
+ const Text = 12;
948
+ const I = 16;
949
+ const Img = 17;
950
+ const Span = 8;
951
+
952
+ const text = data => {
953
+ return {
954
+ type: Text,
955
+ text: data,
956
+ childCount: 0
957
+ };
958
+ };
959
+
960
+ const getItemVirtualDom = item => {
961
+ // @ts-ignore
962
+ const {
963
+ keyboardShortCut,
964
+ label,
965
+ isOpen,
966
+ isFocused
967
+ } = item;
968
+ const dom = [];
969
+ dom.push({
970
+ type: Div,
971
+ className: TitleBarTopLevelEntry,
972
+ ariaHasPopup: true,
973
+ ariaExpanded: isOpen,
974
+ role: MenuItem$1,
975
+ childCount: 1,
976
+ ariaKeyShortcuts: keyboardShortCut
977
+ });
978
+ if (isOpen) {
979
+ // @ts-ignore
980
+ dom[0].ariaOwns = 'Menu-0';
981
+ }
982
+ if (isFocused) {
983
+ dom[0].className += ' ' + TitleBarEntryActive;
984
+ // @ts-ignore
985
+ dom[0].id = 'TitleBarEntryActive';
986
+ dom.push({
987
+ type: Div,
988
+ className: TitleBarTopLevelEntryLabel,
989
+ childCount: 1
990
+ });
991
+ }
992
+ dom.push(text(label));
993
+ return dom;
994
+ };
995
+ const getTitleBarMenuBarItemsVirtualDom = visibleItems => {
996
+ const dom = visibleItems.flatMap(getItemVirtualDom);
997
+ return dom;
998
+ };
999
+
1000
+ const activeId = 'TitleBarEntryActive';
1001
+ const getTitleBarMenuBarVirtualDom = (visibleItems, focusedIndex) => {
1002
+ return [{
1003
+ type: Div,
1004
+ className: 'Viewlet TitleBarMenuBar',
1005
+ role: MenuBar,
1006
+ tabIndex: 0,
1007
+ childCount: visibleItems.length,
1008
+ onMouseDown: HandleClick,
1009
+ onFocusOut: HandleFocusOut,
1010
+ onFocusIn: HandleFocusIn,
1011
+ onPointerOver: HandlePointerOver,
1012
+ onPointerOut: HandlePointerOut,
1013
+ ariaActivedescendant: focusedIndex === -1 ? '' : activeId
1014
+ }, ...getTitleBarMenuBarItemsVirtualDom(visibleItems)];
1015
+ };
1016
+
1017
+ const Ellipsis = 'Ellipsis';
1018
+
1019
+ const emptyObject = {};
1020
+ const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1021
+ const i18nString = (key, placeholders = emptyObject) => {
1022
+ if (placeholders === emptyObject) {
1023
+ return key;
1024
+ }
1025
+ const replacer = (match, rest) => {
1026
+ return placeholders[rest];
1027
+ };
1028
+ return key.replaceAll(RE_PLACEHOLDER, replacer);
1029
+ };
1030
+
1031
+ const About = 'About';
1032
+ const CheckForUpdates = 'Check For Updates';
1033
+ const ClearRecentlyOpened = 'Clear Recently Opened';
1034
+ const Edit$1 = 'Edit';
1035
+ const File$1 = 'File';
1036
+ const Go$1 = 'Go';
1037
+ const Help$1 = 'Help';
1038
+ const MoreDot = 'More ...';
1039
+ const OpenProcessExplorer = 'Open Process Explorer';
1040
+ const Run$1 = 'Run';
1041
+ const Selection$1 = 'Selection';
1042
+ const Terminal$1 = 'Terminal';
1043
+ const ToggleDeveloperTools = 'Toggle Developer Tools';
1044
+ const View$1 = 'View';
1045
+
1046
+ const moreDot = () => {
1047
+ return i18nString(MoreDot);
1048
+ };
1049
+ const clearRecentlyOpened = () => {
1050
+ return i18nString(ClearRecentlyOpened);
1051
+ };
1052
+
1053
+ const getVisibleTitleBarEntries = (entries, width, focusedIndex, isMenuOpen) => {
1054
+ array(entries);
1055
+ number(width);
1056
+ let total = 0;
1057
+ const visible = [];
1058
+ for (let i = 0; i < entries.length; i++) {
1059
+ const entry = entries[i];
1060
+ total += entry.width;
1061
+ if (total >= width) {
1062
+ break;
1063
+ }
1064
+ const isOpen = i === focusedIndex && isMenuOpen;
1065
+ const isFocused = i === focusedIndex;
1066
+ visible.push({
1067
+ ...entry,
1068
+ isOpen,
1069
+ isFocused
1070
+ });
1071
+ }
1072
+ const hasOverflow = visible.length < entries.length;
1073
+ if (hasOverflow) {
1074
+ const padding = 8;
1075
+ const moreIconWidth = 22;
1076
+ const totalPadding = padding * 2;
1077
+ const hasStillOverflow = total + moreIconWidth + totalPadding > width;
1078
+ if (hasStillOverflow) {
1079
+ visible.pop();
1080
+ }
1081
+ visible.push({
1082
+ ariaLabel: moreDot(),
1083
+ icon: Ellipsis,
1084
+ label: '',
1085
+ width: moreIconWidth + totalPadding
1086
+ });
1087
+ }
1088
+ return visible;
1089
+ };
1090
+
1091
+ const renderEntries = (oldState, newState) => {
1092
+ const visibleEntries = getVisibleTitleBarEntries(newState.titleBarEntries, newState.width, newState.focusedIndex, newState.isMenuOpen);
1093
+ const dom = getTitleBarMenuBarVirtualDom(visibleEntries, newState.focusedIndex);
1094
+ return ['Viewlet.setDom2', newState.uid, dom];
1095
+ };
1096
+
1097
+ const SetFocusedIndex = 'setFocusedIndex';
1098
+ const SetMenus = 'setMenus';
1099
+
1100
+ const renderFocusedIndex = (oldState, newState) => {
1101
+ return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */oldState.focusedIndex, /* newfocusedIndex */newState.focusedIndex, /* oldIsMenuOpen */oldState.isMenuOpen, /* newIsMenuOpen */newState.isMenuOpen];
1102
+ };
1103
+
934
1104
  const getKeyBindingString = (key, altKey, ctrlKey, shiftKey, metaKey) => {
935
1105
  let string = '';
936
1106
  if (ctrlKey) {
@@ -1234,21 +1404,6 @@ const parseKey = rawKey => {
1234
1404
  };
1235
1405
  };
1236
1406
 
1237
- const Button = 1;
1238
- const Div = 4;
1239
- const Text = 12;
1240
- const I = 16;
1241
- const Img = 17;
1242
- const Span = 8;
1243
-
1244
- const text = data => {
1245
- return {
1246
- type: Text,
1247
- text: data,
1248
- childCount: 0
1249
- };
1250
- };
1251
-
1252
1407
  const separator = {
1253
1408
  type: Div,
1254
1409
  className: MenuItemSeparator,
@@ -1402,72 +1557,6 @@ const getMenuVirtualDom = menuItems => {
1402
1557
  return dom;
1403
1558
  };
1404
1559
 
1405
- const HandleClick = 'handleClick';
1406
- const HandleClickMinimize = 'handleClickMinimize';
1407
- const HandleClickToggleClose = 'handleClickToggleClose';
1408
- const HandleClickToggleMaximize = 'handleClickToggleMaximize';
1409
- const HandleFocusIn = 'handleFocusIn';
1410
- const HandleFocusOut = 'handleFocusOut';
1411
- const HandlePointerOut = 'handlePointerOut';
1412
- const HandlePointerOver = 'handlePointerOver';
1413
- const HandleMenuClick = 'handleMenuClick';
1414
- const HandleMenuMouseOver = 'handleMenuMouseOver';
1415
-
1416
- const getItemVirtualDom = item => {
1417
- // @ts-ignore
1418
- const {
1419
- keyboardShortCut,
1420
- label,
1421
- isOpen,
1422
- isFocused
1423
- } = item;
1424
- const dom = [];
1425
- dom.push({
1426
- type: Div,
1427
- className: TitleBarTopLevelEntry,
1428
- ariaHasPopup: true,
1429
- ariaExpanded: isOpen,
1430
- role: MenuItem$1,
1431
- childCount: 1,
1432
- ariaKeyShortcuts: keyboardShortCut
1433
- });
1434
- if (isOpen) {
1435
- // @ts-ignore
1436
- dom[0].ariaOwns = 'Menu-0';
1437
- }
1438
- if (isFocused) {
1439
- dom[0].className += ' ' + TitleBarEntryActive;
1440
- // @ts-ignore
1441
- dom[0].id = 'TitleBarEntryActive';
1442
- dom.push({
1443
- type: Div,
1444
- className: TitleBarTopLevelEntryLabel,
1445
- childCount: 1
1446
- });
1447
- }
1448
- dom.push(text(label));
1449
- return dom;
1450
- };
1451
- const getTitleBarMenuBarItemsVirtualDom = visibleItems => {
1452
- const dom = visibleItems.flatMap(getItemVirtualDom);
1453
- return dom;
1454
- };
1455
-
1456
- const getTitleBarMenuBarVirtualDom = visibleItems => {
1457
- return [{
1458
- type: Div,
1459
- className: 'Viewlet TitleBarMenuBar',
1460
- role: MenuBar,
1461
- tabIndex: 0,
1462
- childCount: visibleItems.length,
1463
- onMouseDown: HandleClick,
1464
- onFocusOut: HandleFocusOut,
1465
- onFocusIn: HandleFocusIn,
1466
- onPointerOver: HandlePointerOver,
1467
- onPointerOut: HandlePointerOut
1468
- }, ...getTitleBarMenuBarItemsVirtualDom(visibleItems)];
1469
- };
1470
-
1471
1560
  const getVisible = (items, focusedIndex, expanded, level) => {
1472
1561
  const visibleItems = [];
1473
1562
  const {
@@ -1491,134 +1580,55 @@ const getVisible = (items, focusedIndex, expanded, level) => {
1491
1580
  return visibleItems;
1492
1581
  };
1493
1582
 
1494
- const Ellipsis = 'Ellipsis';
1495
-
1496
- const emptyObject = {};
1497
- const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1498
- const i18nString = (key, placeholders = emptyObject) => {
1499
- if (placeholders === emptyObject) {
1500
- return key;
1501
- }
1502
- const replacer = (match, rest) => {
1503
- return placeholders[rest];
1504
- };
1505
- return key.replaceAll(RE_PLACEHOLDER, replacer);
1506
- };
1507
-
1508
- const About = 'About';
1509
- const CheckForUpdates = 'Check For Updates';
1510
- const ClearRecentlyOpened = 'Clear Recently Opened';
1511
- const Edit$1 = 'Edit';
1512
- const File$1 = 'File';
1513
- const Go$1 = 'Go';
1514
- const Help$1 = 'Help';
1515
- const MoreDot = 'More ...';
1516
- const OpenProcessExplorer = 'Open Process Explorer';
1517
- const Run$1 = 'Run';
1518
- const Selection$1 = 'Selection';
1519
- const Terminal$1 = 'Terminal';
1520
- const ToggleDeveloperTools = 'Toggle Developer Tools';
1521
- const View$1 = 'View';
1522
-
1523
- const moreDot = () => {
1524
- return i18nString(MoreDot);
1525
- };
1526
- const clearRecentlyOpened = () => {
1527
- return i18nString(ClearRecentlyOpened);
1528
- };
1529
-
1530
- const getVisibleTitleBarEntries = (entries, width, focusedIndex, isMenuOpen) => {
1531
- array(entries);
1532
- number(width);
1533
- let total = 0;
1534
- const visible = [];
1535
- for (let i = 0; i < entries.length; i++) {
1536
- const entry = entries[i];
1537
- total += entry.width;
1538
- if (total >= width) {
1539
- break;
1583
+ const renderMEnus = (oldState, newState) => {
1584
+ const oldMenus = oldState.menus;
1585
+ const newMenus = newState.menus;
1586
+ const oldLength = oldMenus.length;
1587
+ const newLength = newMenus.length;
1588
+ const commonLength = Math.min(oldLength, newLength);
1589
+ const changes = [];
1590
+ for (let i = 0; i < commonLength; i++) {
1591
+ const oldMenu = oldMenus[i];
1592
+ const newMenu = newMenus[i];
1593
+ if (oldMenu !== newMenu) {
1594
+ const visible = getVisible(newMenu.items, newMenu.focusedIndex, newMenu.expanded, newMenu.level);
1595
+ const dom = getMenuVirtualDom(visible).slice(1);
1596
+ changes.push([/* method */'updateMenu', newMenu, /* newLength */newLength, dom]);
1540
1597
  }
1541
- const isOpen = i === focusedIndex && isMenuOpen;
1542
- const isFocused = i === focusedIndex;
1543
- visible.push({
1544
- ...entry,
1545
- isOpen,
1546
- isFocused
1547
- });
1548
1598
  }
1549
- const hasOverflow = visible.length < entries.length;
1550
- if (hasOverflow) {
1551
- const padding = 8;
1552
- const moreIconWidth = 22;
1553
- const totalPadding = padding * 2;
1554
- const hasStillOverflow = total + moreIconWidth + totalPadding > width;
1555
- if (hasStillOverflow) {
1556
- visible.pop();
1557
- }
1558
- visible.push({
1559
- ariaLabel: moreDot(),
1560
- icon: Ellipsis,
1561
- label: '',
1562
- width: moreIconWidth + totalPadding
1563
- });
1599
+ const difference = newLength - oldLength;
1600
+ if (difference > 0) {
1601
+ const newMenu = newMenus.at(-1);
1602
+ const visible = getVisible(newMenu.items, newMenu.focusedIndex, newMenu.expanded, newMenu.level);
1603
+ const dom = getMenuVirtualDom(visible).slice(1);
1604
+ changes.push(['addMenu', newMenu, dom]);
1605
+ } else if (difference < 0) {
1606
+ changes.push(['closeMenus', newLength]);
1607
+ }
1608
+ return ['Viewlet.send', newState.uid, /* method */SetMenus, /* changes */changes, newState.uid];
1609
+ };
1610
+
1611
+ const getRenderer = diffType => {
1612
+ switch (diffType) {
1613
+ case RenderEntries:
1614
+ return renderEntries;
1615
+ case RenderFocusedIndex:
1616
+ return renderFocusedIndex;
1617
+ case RenderMenus:
1618
+ return renderMEnus;
1619
+ default:
1620
+ throw new Error('unknown renderer');
1564
1621
  }
1565
- return visible;
1566
1622
  };
1567
1623
 
1568
- const SetFocusedIndex = 'setFocusedIndex';
1569
- const SetMenus = 'setMenus';
1570
-
1571
- const renderTitleBarEntries = {
1572
- isEqual(oldState, newState) {
1573
- return oldState.titleBarEntries === newState.titleBarEntries && oldState.width === newState.width && oldState.focusedIndex === newState.focusedIndex && oldState.isMenuOpen === newState.isMenuOpen;
1574
- },
1575
- apply(oldState, newState) {
1576
- const visibleEntries = getVisibleTitleBarEntries(newState.titleBarEntries, newState.width, newState.focusedIndex, newState.isMenuOpen);
1577
- const dom = getTitleBarMenuBarVirtualDom(visibleEntries);
1578
- return ['Viewlet.setDom2', newState.uid, dom];
1579
- }
1580
- };
1581
- const renderFocusedIndex = {
1582
- isEqual(oldState, newState) {
1583
- return oldState.focusedIndex === newState.focusedIndex && oldState.isMenuOpen === newState.isMenuOpen;
1584
- },
1585
- apply(oldState, newState) {
1586
- return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */oldState.focusedIndex, /* newfocusedIndex */newState.focusedIndex, /* oldIsMenuOpen */oldState.isMenuOpen, /* newIsMenuOpen */newState.isMenuOpen];
1587
- }
1588
- };
1589
- const renderMenus = {
1590
- isEqual(oldState, newState) {
1591
- return oldState.menus === newState.menus;
1592
- },
1593
- apply(oldState, newState) {
1594
- const oldMenus = oldState.menus;
1595
- const newMenus = newState.menus;
1596
- const oldLength = oldMenus.length;
1597
- const newLength = newMenus.length;
1598
- const commonLength = Math.min(oldLength, newLength);
1599
- const changes = [];
1600
- for (let i = 0; i < commonLength; i++) {
1601
- const oldMenu = oldMenus[i];
1602
- const newMenu = newMenus[i];
1603
- if (oldMenu !== newMenu) {
1604
- const visible = getVisible(newMenu.items, newMenu.focusedIndex, newMenu.expanded, newMenu.level);
1605
- const dom = getMenuVirtualDom(visible).slice(1);
1606
- changes.push([/* method */'updateMenu', newMenu, /* newLength */newLength, dom]);
1607
- }
1608
- }
1609
- const difference = newLength - oldLength;
1610
- if (difference > 0) {
1611
- const newMenu = newMenus.at(-1);
1612
- const visible = getVisible(newMenu.items, newMenu.focusedIndex, newMenu.expanded, newMenu.level);
1613
- const dom = getMenuVirtualDom(visible).slice(1);
1614
- changes.push(['addMenu', newMenu, dom]);
1615
- } else if (difference < 0) {
1616
- changes.push(['closeMenus', newLength]);
1617
- }
1618
- return ['Viewlet.send', newState.uid, /* method */SetMenus, /* changes */changes, newState.uid];
1624
+ const applyRender = (oldState, newState, diffResult) => {
1625
+ const commands = [];
1626
+ for (const item of diffResult) {
1627
+ const fn = getRenderer(item);
1628
+ commands.push(fn(oldState, newState));
1619
1629
  }
1630
+ return commands;
1620
1631
  };
1621
- const render = [renderTitleBarEntries, renderFocusedIndex, renderMenus];
1622
1632
 
1623
1633
  const create$1 = () => {
1624
1634
  const states = Object.create(null);
@@ -1645,12 +1655,8 @@ const doRender = async uid => {
1645
1655
  oldState,
1646
1656
  newState
1647
1657
  } = get(uid);
1648
- const commands = [];
1649
- for (const item of render) {
1650
- if (!item.isEqual(oldState, newState)) {
1651
- commands.push(item.apply(oldState, newState));
1652
- }
1653
- }
1658
+ const diffResult = diff(oldState, newState);
1659
+ const commands = applyRender(oldState, newState, diffResult);
1654
1660
  return commands;
1655
1661
  };
1656
1662
 
@@ -2689,7 +2695,7 @@ const renderEventListeners = () => {
2689
2695
  params: ['handleClickToggleMaximize']
2690
2696
  }, {
2691
2697
  name: HandleFocusIn,
2692
- params: ['handlefocus']
2698
+ params: ['handleFocus']
2693
2699
  }, {
2694
2700
  name: HandleMenuClick,
2695
2701
  params: ['handleMenuClick', 'event.clientX', 'event.clientY']
@@ -2698,7 +2704,7 @@ const renderEventListeners = () => {
2698
2704
  params: ['handleMenuMouseOver', 'event.clientX', 'event.clientY']
2699
2705
  }, {
2700
2706
  name: HandleClick,
2701
- params: ['handleClick', 'event.button', 'event.clientX', 'event.clientY']
2707
+ params: ['handleClickAt', 'event.button', 'event.clientX', 'event.clientY']
2702
2708
  }, {
2703
2709
  name: HandlePointerOut,
2704
2710
  params: ['handlePointerOut', 'event.clientX', 'event.clientY']
@@ -2712,7 +2718,9 @@ const renderEventListeners = () => {
2712
2718
  };
2713
2719
 
2714
2720
  const saveState = uid => {
2715
- return {};
2721
+ return {
2722
+ x: 1
2723
+ };
2716
2724
  };
2717
2725
 
2718
2726
  const terminate = () => {
@@ -2828,6 +2836,14 @@ const handleClick = async (state, button, index) => {
2828
2836
  return toggleIndex(state, index);
2829
2837
  };
2830
2838
 
2839
+ const handleClickAt = async (state, button, x, y) => {
2840
+ const index = getTitleBarIndexFromPosition(state.titleBarEntries, x - state.x);
2841
+ if (index === -1) {
2842
+ return state;
2843
+ }
2844
+ return handleClick(state, button, index);
2845
+ };
2846
+
2831
2847
  // TODO remove this file and merge with whenExpressions
2832
2848
  const TitleBarMenuBar = FocusTitleBarMenuBar;
2833
2849
 
@@ -3242,6 +3258,7 @@ const commandMap = {
3242
3258
  'TitleBarMenuBar.handleKeyArrowLeft': wrapCommand(handleKeyArrowLeft),
3243
3259
  'TitleBarMenuBar.handleKeyArrowRight': wrapCommand(handleKeyArrowRight),
3244
3260
  'TitleBarMenuBar.handleKeyArrowUp': wrapCommand(handleKeyArrowUp),
3261
+ 'TitleBarMenuBar.handleClickAt': wrapCommand(handleClickAt),
3245
3262
  'TitleBarMenuBar.handlePointerOver': wrapCommand(handlePointerOver),
3246
3263
  'TitleBarMenuBar.handleKeyEnd': wrapCommand(handleKeyEnd),
3247
3264
  'TitleBarMenuBar.handleKeyEnter': wrapCommand(handleKeyEnter),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/title-bar-worker",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "description": "Title Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",