@lvce-editor/title-bar-worker 1.6.0 → 1.8.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.
- package/dist/titleBarWorkerMain.js +265 -209
- package/package.json +1 -1
|
@@ -864,6 +864,55 @@ const WebWorkerRpcClient = {
|
|
|
864
864
|
create: create$2
|
|
865
865
|
};
|
|
866
866
|
|
|
867
|
+
const RenderEntries = 1;
|
|
868
|
+
const RenderFocusedIndex = 2;
|
|
869
|
+
const RenderMenus = 3;
|
|
870
|
+
|
|
871
|
+
const diffType$2 = RenderEntries;
|
|
872
|
+
const isEqual$2 = (oldState, newState) => {
|
|
873
|
+
return oldState.titleBarEntries === newState.titleBarEntries && oldState.width === newState.width && oldState.focusedIndex === newState.focusedIndex && oldState.isMenuOpen === newState.isMenuOpen;
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
const DiffEntries = {
|
|
877
|
+
__proto__: null,
|
|
878
|
+
diffType: diffType$2,
|
|
879
|
+
isEqual: isEqual$2
|
|
880
|
+
};
|
|
881
|
+
|
|
882
|
+
const diffType$1 = RenderFocusedIndex;
|
|
883
|
+
const isEqual$1 = (oldState, newState) => {
|
|
884
|
+
return oldState.focusedIndex === newState.focusedIndex && oldState.isMenuOpen === newState.isMenuOpen;
|
|
885
|
+
};
|
|
886
|
+
|
|
887
|
+
const DiffFocusedIndex = {
|
|
888
|
+
__proto__: null,
|
|
889
|
+
diffType: diffType$1,
|
|
890
|
+
isEqual: isEqual$1
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
const diffType = RenderMenus;
|
|
894
|
+
const isEqual = (oldState, newState) => {
|
|
895
|
+
return oldState.menus === newState.menus;
|
|
896
|
+
};
|
|
897
|
+
|
|
898
|
+
const DiffMenus = {
|
|
899
|
+
__proto__: null,
|
|
900
|
+
diffType,
|
|
901
|
+
isEqual
|
|
902
|
+
};
|
|
903
|
+
|
|
904
|
+
const modules = [DiffEntries, DiffFocusedIndex, DiffMenus];
|
|
905
|
+
|
|
906
|
+
const diff = (oldState, newState) => {
|
|
907
|
+
const diffResult = [];
|
|
908
|
+
for (const module of modules) {
|
|
909
|
+
if (!module.isEqual(oldState, newState)) {
|
|
910
|
+
diffResult.push(module.diffType);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
return diffResult;
|
|
914
|
+
};
|
|
915
|
+
|
|
867
916
|
const Menu$1 = 'menu';
|
|
868
917
|
const MenuBar = 'menubar';
|
|
869
918
|
const MenuItem$1 = 'menuitem';
|
|
@@ -871,6 +920,17 @@ const MenuItemCheckBox = 'menuitemcheckbox';
|
|
|
871
920
|
const None$1 = 'none';
|
|
872
921
|
const Separator$1 = 'separator';
|
|
873
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
|
+
|
|
874
934
|
const Menu = 'Menu';
|
|
875
935
|
const MenuItem = 'MenuItem';
|
|
876
936
|
const MenuItemFocused = 'MenuItemFocused';
|
|
@@ -882,6 +942,163 @@ const TitleBarEntryActive = 'TitleBarEntryActive';
|
|
|
882
942
|
const TitleBarTopLevelEntry = 'TitleBarTopLevelEntry';
|
|
883
943
|
const TitleBarTopLevelEntryLabel = 'TitleBarTopLevelEntryLabel';
|
|
884
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 getTitleBarMenuBarVirtualDom = visibleItems => {
|
|
1001
|
+
return [{
|
|
1002
|
+
type: Div,
|
|
1003
|
+
className: 'Viewlet TitleBarMenuBar',
|
|
1004
|
+
role: MenuBar,
|
|
1005
|
+
tabIndex: 0,
|
|
1006
|
+
childCount: visibleItems.length,
|
|
1007
|
+
onMouseDown: HandleClick,
|
|
1008
|
+
onFocusOut: HandleFocusOut,
|
|
1009
|
+
onFocusIn: HandleFocusIn,
|
|
1010
|
+
onPointerOver: HandlePointerOver,
|
|
1011
|
+
onPointerOut: HandlePointerOut
|
|
1012
|
+
}, ...getTitleBarMenuBarItemsVirtualDom(visibleItems)];
|
|
1013
|
+
};
|
|
1014
|
+
|
|
1015
|
+
const Ellipsis = 'Ellipsis';
|
|
1016
|
+
|
|
1017
|
+
const emptyObject = {};
|
|
1018
|
+
const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
|
|
1019
|
+
const i18nString = (key, placeholders = emptyObject) => {
|
|
1020
|
+
if (placeholders === emptyObject) {
|
|
1021
|
+
return key;
|
|
1022
|
+
}
|
|
1023
|
+
const replacer = (match, rest) => {
|
|
1024
|
+
return placeholders[rest];
|
|
1025
|
+
};
|
|
1026
|
+
return key.replaceAll(RE_PLACEHOLDER, replacer);
|
|
1027
|
+
};
|
|
1028
|
+
|
|
1029
|
+
const About = 'About';
|
|
1030
|
+
const CheckForUpdates = 'Check For Updates';
|
|
1031
|
+
const ClearRecentlyOpened = 'Clear Recently Opened';
|
|
1032
|
+
const Edit$1 = 'Edit';
|
|
1033
|
+
const File$1 = 'File';
|
|
1034
|
+
const Go$1 = 'Go';
|
|
1035
|
+
const Help$1 = 'Help';
|
|
1036
|
+
const MoreDot = 'More ...';
|
|
1037
|
+
const OpenProcessExplorer = 'Open Process Explorer';
|
|
1038
|
+
const Run$1 = 'Run';
|
|
1039
|
+
const Selection$1 = 'Selection';
|
|
1040
|
+
const Terminal$1 = 'Terminal';
|
|
1041
|
+
const ToggleDeveloperTools = 'Toggle Developer Tools';
|
|
1042
|
+
const View$1 = 'View';
|
|
1043
|
+
|
|
1044
|
+
const moreDot = () => {
|
|
1045
|
+
return i18nString(MoreDot);
|
|
1046
|
+
};
|
|
1047
|
+
const clearRecentlyOpened = () => {
|
|
1048
|
+
return i18nString(ClearRecentlyOpened);
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
const getVisibleTitleBarEntries = (entries, width, focusedIndex, isMenuOpen) => {
|
|
1052
|
+
array(entries);
|
|
1053
|
+
number(width);
|
|
1054
|
+
let total = 0;
|
|
1055
|
+
const visible = [];
|
|
1056
|
+
for (let i = 0; i < entries.length; i++) {
|
|
1057
|
+
const entry = entries[i];
|
|
1058
|
+
total += entry.width;
|
|
1059
|
+
if (total >= width) {
|
|
1060
|
+
break;
|
|
1061
|
+
}
|
|
1062
|
+
const isOpen = i === focusedIndex && isMenuOpen;
|
|
1063
|
+
const isFocused = i === focusedIndex;
|
|
1064
|
+
visible.push({
|
|
1065
|
+
...entry,
|
|
1066
|
+
isOpen,
|
|
1067
|
+
isFocused
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
const hasOverflow = visible.length < entries.length;
|
|
1071
|
+
if (hasOverflow) {
|
|
1072
|
+
const padding = 8;
|
|
1073
|
+
const moreIconWidth = 22;
|
|
1074
|
+
const totalPadding = padding * 2;
|
|
1075
|
+
const hasStillOverflow = total + moreIconWidth + totalPadding > width;
|
|
1076
|
+
if (hasStillOverflow) {
|
|
1077
|
+
visible.pop();
|
|
1078
|
+
}
|
|
1079
|
+
visible.push({
|
|
1080
|
+
ariaLabel: moreDot(),
|
|
1081
|
+
icon: Ellipsis,
|
|
1082
|
+
label: '',
|
|
1083
|
+
width: moreIconWidth + totalPadding
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
return visible;
|
|
1087
|
+
};
|
|
1088
|
+
|
|
1089
|
+
const renderEntries = (oldState, newState) => {
|
|
1090
|
+
const visibleEntries = getVisibleTitleBarEntries(newState.titleBarEntries, newState.width, newState.focusedIndex, newState.isMenuOpen);
|
|
1091
|
+
const dom = getTitleBarMenuBarVirtualDom(visibleEntries);
|
|
1092
|
+
return ['Viewlet.setDom2', newState.uid, dom];
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
const SetFocusedIndex = 'setFocusedIndex';
|
|
1096
|
+
const SetMenus = 'setMenus';
|
|
1097
|
+
|
|
1098
|
+
const renderFocusedIndex = (oldState, newState) => {
|
|
1099
|
+
return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */oldState.focusedIndex, /* newfocusedIndex */newState.focusedIndex, /* oldIsMenuOpen */oldState.isMenuOpen, /* newIsMenuOpen */newState.isMenuOpen];
|
|
1100
|
+
};
|
|
1101
|
+
|
|
885
1102
|
const getKeyBindingString = (key, altKey, ctrlKey, shiftKey, metaKey) => {
|
|
886
1103
|
let string = '';
|
|
887
1104
|
if (ctrlKey) {
|
|
@@ -1185,21 +1402,6 @@ const parseKey = rawKey => {
|
|
|
1185
1402
|
};
|
|
1186
1403
|
};
|
|
1187
1404
|
|
|
1188
|
-
const Button = 1;
|
|
1189
|
-
const Div = 4;
|
|
1190
|
-
const Span = 8;
|
|
1191
|
-
const Text = 12;
|
|
1192
|
-
const I = 16;
|
|
1193
|
-
const Img = 17;
|
|
1194
|
-
|
|
1195
|
-
const text = data => {
|
|
1196
|
-
return {
|
|
1197
|
-
type: Text,
|
|
1198
|
-
text: data,
|
|
1199
|
-
childCount: 0
|
|
1200
|
-
};
|
|
1201
|
-
};
|
|
1202
|
-
|
|
1203
1405
|
const separator = {
|
|
1204
1406
|
type: Div,
|
|
1205
1407
|
className: MenuItemSeparator,
|
|
@@ -1353,72 +1555,6 @@ const getMenuVirtualDom = menuItems => {
|
|
|
1353
1555
|
return dom;
|
|
1354
1556
|
};
|
|
1355
1557
|
|
|
1356
|
-
const HandleClick = 'handleClick';
|
|
1357
|
-
const HandleClickMinimize = 'handleClickMinimize';
|
|
1358
|
-
const HandleClickToggleClose = 'handleClickToggleClose';
|
|
1359
|
-
const HandleClickToggleMaximize = 'handleClickToggleMaximize';
|
|
1360
|
-
const HandleFocusIn = 'handleFocusIn';
|
|
1361
|
-
const HandleFocusOut = 'handleFocusOut';
|
|
1362
|
-
const HandlePointerOut = 'handlePointerOut';
|
|
1363
|
-
const HandlePointerOver = 'handlePointerOver';
|
|
1364
|
-
const HandleMenuClick = 'handleMenuClick';
|
|
1365
|
-
const HandleMenuMouseOver = 'handleMenuMouseOver';
|
|
1366
|
-
|
|
1367
|
-
const getItemVirtualDom = item => {
|
|
1368
|
-
// @ts-ignore
|
|
1369
|
-
const {
|
|
1370
|
-
keyboardShortCut,
|
|
1371
|
-
label,
|
|
1372
|
-
isOpen,
|
|
1373
|
-
isFocused
|
|
1374
|
-
} = item;
|
|
1375
|
-
const dom = [];
|
|
1376
|
-
dom.push({
|
|
1377
|
-
type: Div,
|
|
1378
|
-
className: TitleBarTopLevelEntry,
|
|
1379
|
-
ariaHasPopup: true,
|
|
1380
|
-
ariaExpanded: isOpen,
|
|
1381
|
-
role: MenuItem$1,
|
|
1382
|
-
childCount: 1,
|
|
1383
|
-
ariaKeyShortcuts: keyboardShortCut
|
|
1384
|
-
});
|
|
1385
|
-
if (isOpen) {
|
|
1386
|
-
// @ts-ignore
|
|
1387
|
-
dom[0].ariaOwns = 'Menu-0';
|
|
1388
|
-
}
|
|
1389
|
-
if (isFocused) {
|
|
1390
|
-
dom[0].className += ' ' + TitleBarEntryActive;
|
|
1391
|
-
// @ts-ignore
|
|
1392
|
-
dom[0].id = 'TitleBarEntryActive';
|
|
1393
|
-
dom.push({
|
|
1394
|
-
type: Div,
|
|
1395
|
-
className: TitleBarTopLevelEntryLabel,
|
|
1396
|
-
childCount: 1
|
|
1397
|
-
});
|
|
1398
|
-
}
|
|
1399
|
-
dom.push(text(label));
|
|
1400
|
-
return dom;
|
|
1401
|
-
};
|
|
1402
|
-
const getTitleBarMenuBarItemsVirtualDom = visibleItems => {
|
|
1403
|
-
const dom = visibleItems.flatMap(getItemVirtualDom);
|
|
1404
|
-
return dom;
|
|
1405
|
-
};
|
|
1406
|
-
|
|
1407
|
-
const getTitleBarMenuBarVirtualDom = visibleItems => {
|
|
1408
|
-
return [{
|
|
1409
|
-
type: Div,
|
|
1410
|
-
className: 'Viewlet TitleBarMenuBar',
|
|
1411
|
-
role: MenuBar,
|
|
1412
|
-
tabIndex: 0,
|
|
1413
|
-
childCount: visibleItems.length,
|
|
1414
|
-
onMouseDown: HandleClick,
|
|
1415
|
-
onFocusOut: HandleFocusOut,
|
|
1416
|
-
onFocusIn: HandleFocusIn,
|
|
1417
|
-
onPointerOver: HandlePointerOver,
|
|
1418
|
-
onPointerOut: HandlePointerOut
|
|
1419
|
-
}, ...getTitleBarMenuBarItemsVirtualDom(visibleItems)];
|
|
1420
|
-
};
|
|
1421
|
-
|
|
1422
1558
|
const getVisible = (items, focusedIndex, expanded, level) => {
|
|
1423
1559
|
const visibleItems = [];
|
|
1424
1560
|
const {
|
|
@@ -1442,134 +1578,55 @@ const getVisible = (items, focusedIndex, expanded, level) => {
|
|
|
1442
1578
|
return visibleItems;
|
|
1443
1579
|
};
|
|
1444
1580
|
|
|
1445
|
-
const
|
|
1446
|
-
|
|
1447
|
-
const
|
|
1448
|
-
const
|
|
1449
|
-
const
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
const About = 'About';
|
|
1460
|
-
const CheckForUpdates = 'Check For Updates';
|
|
1461
|
-
const ClearRecentlyOpened = 'Clear Recently Opened';
|
|
1462
|
-
const Edit$1 = 'Edit';
|
|
1463
|
-
const File$1 = 'File';
|
|
1464
|
-
const Go$1 = 'Go';
|
|
1465
|
-
const Help$1 = 'Help';
|
|
1466
|
-
const MoreDot = 'More ...';
|
|
1467
|
-
const OpenProcessExplorer = 'Open Process Explorer';
|
|
1468
|
-
const Run$1 = 'Run';
|
|
1469
|
-
const Selection$1 = 'Selection';
|
|
1470
|
-
const Terminal$1 = 'Terminal';
|
|
1471
|
-
const ToggleDeveloperTools = 'Toggle Developer Tools';
|
|
1472
|
-
const View$1 = 'View';
|
|
1473
|
-
|
|
1474
|
-
const moreDot = () => {
|
|
1475
|
-
return i18nString(MoreDot);
|
|
1476
|
-
};
|
|
1477
|
-
const clearRecentlyOpened = () => {
|
|
1478
|
-
return i18nString(ClearRecentlyOpened);
|
|
1479
|
-
};
|
|
1480
|
-
|
|
1481
|
-
const getVisibleTitleBarEntries = (entries, width, focusedIndex, isMenuOpen) => {
|
|
1482
|
-
array(entries);
|
|
1483
|
-
number(width);
|
|
1484
|
-
let total = 0;
|
|
1485
|
-
const visible = [];
|
|
1486
|
-
for (let i = 0; i < entries.length; i++) {
|
|
1487
|
-
const entry = entries[i];
|
|
1488
|
-
total += entry.width;
|
|
1489
|
-
if (total >= width) {
|
|
1490
|
-
break;
|
|
1581
|
+
const renderMEnus = (oldState, newState) => {
|
|
1582
|
+
const oldMenus = oldState.menus;
|
|
1583
|
+
const newMenus = newState.menus;
|
|
1584
|
+
const oldLength = oldMenus.length;
|
|
1585
|
+
const newLength = newMenus.length;
|
|
1586
|
+
const commonLength = Math.min(oldLength, newLength);
|
|
1587
|
+
const changes = [];
|
|
1588
|
+
for (let i = 0; i < commonLength; i++) {
|
|
1589
|
+
const oldMenu = oldMenus[i];
|
|
1590
|
+
const newMenu = newMenus[i];
|
|
1591
|
+
if (oldMenu !== newMenu) {
|
|
1592
|
+
const visible = getVisible(newMenu.items, newMenu.focusedIndex, newMenu.expanded, newMenu.level);
|
|
1593
|
+
const dom = getMenuVirtualDom(visible).slice(1);
|
|
1594
|
+
changes.push([/* method */'updateMenu', newMenu, /* newLength */newLength, dom]);
|
|
1491
1595
|
}
|
|
1492
|
-
const isOpen = i === focusedIndex && isMenuOpen;
|
|
1493
|
-
const isFocused = i === focusedIndex;
|
|
1494
|
-
visible.push({
|
|
1495
|
-
...entry,
|
|
1496
|
-
isOpen,
|
|
1497
|
-
isFocused
|
|
1498
|
-
});
|
|
1499
1596
|
}
|
|
1500
|
-
const
|
|
1501
|
-
if (
|
|
1502
|
-
const
|
|
1503
|
-
const
|
|
1504
|
-
const
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1597
|
+
const difference = newLength - oldLength;
|
|
1598
|
+
if (difference > 0) {
|
|
1599
|
+
const newMenu = newMenus.at(-1);
|
|
1600
|
+
const visible = getVisible(newMenu.items, newMenu.focusedIndex, newMenu.expanded, newMenu.level);
|
|
1601
|
+
const dom = getMenuVirtualDom(visible).slice(1);
|
|
1602
|
+
changes.push(['addMenu', newMenu, dom]);
|
|
1603
|
+
} else if (difference < 0) {
|
|
1604
|
+
changes.push(['closeMenus', newLength]);
|
|
1605
|
+
}
|
|
1606
|
+
return ['Viewlet.send', newState.uid, /* method */SetMenus, /* changes */changes, newState.uid];
|
|
1607
|
+
};
|
|
1608
|
+
|
|
1609
|
+
const getRenderer = diffType => {
|
|
1610
|
+
switch (diffType) {
|
|
1611
|
+
case RenderEntries:
|
|
1612
|
+
return renderEntries;
|
|
1613
|
+
case RenderFocusedIndex:
|
|
1614
|
+
return renderFocusedIndex;
|
|
1615
|
+
case RenderMenus:
|
|
1616
|
+
return renderMEnus;
|
|
1617
|
+
default:
|
|
1618
|
+
throw new Error('unknown renderer');
|
|
1515
1619
|
}
|
|
1516
|
-
return visible;
|
|
1517
1620
|
};
|
|
1518
1621
|
|
|
1519
|
-
const
|
|
1520
|
-
const
|
|
1521
|
-
|
|
1522
|
-
const
|
|
1523
|
-
|
|
1524
|
-
return oldState.titleBarEntries === newState.titleBarEntries && oldState.width === newState.width && oldState.focusedIndex === newState.focusedIndex && oldState.isMenuOpen === newState.isMenuOpen;
|
|
1525
|
-
},
|
|
1526
|
-
apply(oldState, newState) {
|
|
1527
|
-
const visibleEntries = getVisibleTitleBarEntries(newState.titleBarEntries, newState.width, newState.focusedIndex, newState.isMenuOpen);
|
|
1528
|
-
const dom = getTitleBarMenuBarVirtualDom(visibleEntries);
|
|
1529
|
-
return ['Viewlet.setDom2', newState.uid, dom];
|
|
1530
|
-
}
|
|
1531
|
-
};
|
|
1532
|
-
const renderFocusedIndex = {
|
|
1533
|
-
isEqual(oldState, newState) {
|
|
1534
|
-
return oldState.focusedIndex === newState.focusedIndex && oldState.isMenuOpen === newState.isMenuOpen;
|
|
1535
|
-
},
|
|
1536
|
-
apply(oldState, newState) {
|
|
1537
|
-
return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */oldState.focusedIndex, /* newfocusedIndex */newState.focusedIndex, /* oldIsMenuOpen */oldState.isMenuOpen, /* newIsMenuOpen */newState.isMenuOpen];
|
|
1538
|
-
}
|
|
1539
|
-
};
|
|
1540
|
-
const renderMenus = {
|
|
1541
|
-
isEqual(oldState, newState) {
|
|
1542
|
-
return oldState.menus === newState.menus;
|
|
1543
|
-
},
|
|
1544
|
-
apply(oldState, newState) {
|
|
1545
|
-
const oldMenus = oldState.menus;
|
|
1546
|
-
const newMenus = newState.menus;
|
|
1547
|
-
const oldLength = oldMenus.length;
|
|
1548
|
-
const newLength = newMenus.length;
|
|
1549
|
-
const commonLength = Math.min(oldLength, newLength);
|
|
1550
|
-
const changes = [];
|
|
1551
|
-
for (let i = 0; i < commonLength; i++) {
|
|
1552
|
-
const oldMenu = oldMenus[i];
|
|
1553
|
-
const newMenu = newMenus[i];
|
|
1554
|
-
if (oldMenu !== newMenu) {
|
|
1555
|
-
const visible = getVisible(newMenu.items, newMenu.focusedIndex, newMenu.expanded, newMenu.level);
|
|
1556
|
-
const dom = getMenuVirtualDom(visible).slice(1);
|
|
1557
|
-
changes.push([/* method */'updateMenu', newMenu, /* newLength */newLength, dom]);
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
const difference = newLength - oldLength;
|
|
1561
|
-
if (difference > 0) {
|
|
1562
|
-
const newMenu = newMenus.at(-1);
|
|
1563
|
-
const visible = getVisible(newMenu.items, newMenu.focusedIndex, newMenu.expanded, newMenu.level);
|
|
1564
|
-
const dom = getMenuVirtualDom(visible).slice(1);
|
|
1565
|
-
changes.push(['addMenu', newMenu, dom]);
|
|
1566
|
-
} else if (difference < 0) {
|
|
1567
|
-
changes.push(['closeMenus', newLength]);
|
|
1568
|
-
}
|
|
1569
|
-
return ['Viewlet.send', newState.uid, /* method */SetMenus, /* changes */changes, newState.uid];
|
|
1622
|
+
const applyRender = (oldState, newState, diffResult) => {
|
|
1623
|
+
const commands = [];
|
|
1624
|
+
for (const item of diffResult) {
|
|
1625
|
+
const fn = getRenderer(item);
|
|
1626
|
+
commands.push(fn(oldState, newState));
|
|
1570
1627
|
}
|
|
1628
|
+
return commands;
|
|
1571
1629
|
};
|
|
1572
|
-
const render = [renderTitleBarEntries, renderFocusedIndex, renderMenus];
|
|
1573
1630
|
|
|
1574
1631
|
const create$1 = () => {
|
|
1575
1632
|
const states = Object.create(null);
|
|
@@ -1596,12 +1653,8 @@ const doRender = async uid => {
|
|
|
1596
1653
|
oldState,
|
|
1597
1654
|
newState
|
|
1598
1655
|
} = get(uid);
|
|
1599
|
-
const
|
|
1600
|
-
|
|
1601
|
-
if (!item.isEqual(oldState, newState)) {
|
|
1602
|
-
commands.push(item.apply(oldState, newState));
|
|
1603
|
-
}
|
|
1604
|
-
}
|
|
1656
|
+
const diffResult = diff(oldState, newState);
|
|
1657
|
+
const commands = applyRender(oldState, newState, diffResult);
|
|
1605
1658
|
return commands;
|
|
1606
1659
|
};
|
|
1607
1660
|
|
|
@@ -2663,7 +2716,9 @@ const renderEventListeners = () => {
|
|
|
2663
2716
|
};
|
|
2664
2717
|
|
|
2665
2718
|
const saveState = uid => {
|
|
2666
|
-
return {
|
|
2719
|
+
return {
|
|
2720
|
+
x: 1
|
|
2721
|
+
};
|
|
2667
2722
|
};
|
|
2668
2723
|
|
|
2669
2724
|
const terminate = () => {
|
|
@@ -3185,6 +3240,7 @@ const commandMap = {
|
|
|
3185
3240
|
'TitleBarMenuBar.getCommands': getCommandIds,
|
|
3186
3241
|
'TitleBarMenuBar.getKeyBindings': getKeyBindings,
|
|
3187
3242
|
'TitleBarMenuBar.getMenus': getMenus,
|
|
3243
|
+
'TitleBarMenuBar.diff': diff,
|
|
3188
3244
|
'TitleBarMenuBar.getVirtualDom': getTitleBarMenuBarVirtualDom,
|
|
3189
3245
|
'TitleBarMenuBar.handleClick': wrapCommand(handleClick),
|
|
3190
3246
|
'TitleBarMenuBar.handleFocus': wrapCommand(handleFocus),
|