@lvce-editor/menu-worker 2.1.0 → 3.0.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/menuWorkerMain.js +299 -178
- package/package.json +1 -1
package/dist/menuWorkerMain.js
CHANGED
|
@@ -411,6 +411,100 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
411
411
|
listen: listen$6,
|
|
412
412
|
wrap: wrap$e
|
|
413
413
|
};
|
|
414
|
+
const addListener = (emitter, type, callback) => {
|
|
415
|
+
if ('addEventListener' in emitter) {
|
|
416
|
+
emitter.addEventListener(type, callback);
|
|
417
|
+
} else {
|
|
418
|
+
emitter.on(type, callback);
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
const removeListener = (emitter, type, callback) => {
|
|
422
|
+
if ('removeEventListener' in emitter) {
|
|
423
|
+
emitter.removeEventListener(type, callback);
|
|
424
|
+
} else {
|
|
425
|
+
emitter.off(type, callback);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
429
|
+
const {
|
|
430
|
+
resolve,
|
|
431
|
+
promise
|
|
432
|
+
} = Promise.withResolvers();
|
|
433
|
+
const listenerMap = Object.create(null);
|
|
434
|
+
const cleanup = value => {
|
|
435
|
+
for (const event of Object.keys(eventMap)) {
|
|
436
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
437
|
+
}
|
|
438
|
+
resolve(value);
|
|
439
|
+
};
|
|
440
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
441
|
+
const listener = event => {
|
|
442
|
+
cleanup({
|
|
443
|
+
type,
|
|
444
|
+
event
|
|
445
|
+
});
|
|
446
|
+
};
|
|
447
|
+
addListener(eventEmitter, event, listener);
|
|
448
|
+
listenerMap[event] = listener;
|
|
449
|
+
}
|
|
450
|
+
return promise;
|
|
451
|
+
};
|
|
452
|
+
const Message$1 = 3;
|
|
453
|
+
const create$5$1 = async ({
|
|
454
|
+
messagePort,
|
|
455
|
+
isMessagePortOpen
|
|
456
|
+
}) => {
|
|
457
|
+
if (!isMessagePort(messagePort)) {
|
|
458
|
+
throw new IpcError('port must be of type MessagePort');
|
|
459
|
+
}
|
|
460
|
+
if (isMessagePortOpen) {
|
|
461
|
+
return messagePort;
|
|
462
|
+
}
|
|
463
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
464
|
+
message: Message$1
|
|
465
|
+
});
|
|
466
|
+
messagePort.start();
|
|
467
|
+
const {
|
|
468
|
+
type,
|
|
469
|
+
event
|
|
470
|
+
} = await eventPromise;
|
|
471
|
+
if (type !== Message$1) {
|
|
472
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
473
|
+
}
|
|
474
|
+
if (event.data !== readyMessage) {
|
|
475
|
+
throw new IpcError('unexpected first message');
|
|
476
|
+
}
|
|
477
|
+
return messagePort;
|
|
478
|
+
};
|
|
479
|
+
const signal$1 = messagePort => {
|
|
480
|
+
messagePort.start();
|
|
481
|
+
};
|
|
482
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
483
|
+
getData = getData$2;
|
|
484
|
+
send(message) {
|
|
485
|
+
this._rawIpc.postMessage(message);
|
|
486
|
+
}
|
|
487
|
+
sendAndTransfer(message) {
|
|
488
|
+
const transfer = getTransferrables(message);
|
|
489
|
+
this._rawIpc.postMessage(message, transfer);
|
|
490
|
+
}
|
|
491
|
+
dispose() {
|
|
492
|
+
this._rawIpc.close();
|
|
493
|
+
}
|
|
494
|
+
onMessage(callback) {
|
|
495
|
+
this._rawIpc.addEventListener('message', callback);
|
|
496
|
+
}
|
|
497
|
+
onClose(callback) {}
|
|
498
|
+
}
|
|
499
|
+
const wrap$5 = messagePort => {
|
|
500
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
501
|
+
};
|
|
502
|
+
const IpcParentWithMessagePort$1 = {
|
|
503
|
+
__proto__: null,
|
|
504
|
+
create: create$5$1,
|
|
505
|
+
signal: signal$1,
|
|
506
|
+
wrap: wrap$5
|
|
507
|
+
};
|
|
414
508
|
|
|
415
509
|
const Two = '2.0';
|
|
416
510
|
const create$4 = (method, params) => {
|
|
@@ -421,7 +515,7 @@ const create$4 = (method, params) => {
|
|
|
421
515
|
};
|
|
422
516
|
};
|
|
423
517
|
const callbacks = Object.create(null);
|
|
424
|
-
const set$
|
|
518
|
+
const set$5 = (id, fn) => {
|
|
425
519
|
callbacks[id] = fn;
|
|
426
520
|
};
|
|
427
521
|
const get$3 = id => {
|
|
@@ -431,16 +525,16 @@ const remove = id => {
|
|
|
431
525
|
delete callbacks[id];
|
|
432
526
|
};
|
|
433
527
|
let id$a = 0;
|
|
434
|
-
const create$3 = () => {
|
|
528
|
+
const create$3$1 = () => {
|
|
435
529
|
return ++id$a;
|
|
436
530
|
};
|
|
437
531
|
const registerPromise = () => {
|
|
438
|
-
const id = create$3();
|
|
532
|
+
const id = create$3$1();
|
|
439
533
|
const {
|
|
440
534
|
resolve,
|
|
441
535
|
promise
|
|
442
536
|
} = Promise.withResolvers();
|
|
443
|
-
set$
|
|
537
|
+
set$5(id, resolve);
|
|
444
538
|
return {
|
|
445
539
|
id,
|
|
446
540
|
promise
|
|
@@ -668,7 +762,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
668
762
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
669
763
|
return create$1$1(id, errorProperty);
|
|
670
764
|
};
|
|
671
|
-
const create$
|
|
765
|
+
const create$6 = (message, result) => {
|
|
672
766
|
return {
|
|
673
767
|
jsonrpc: Two,
|
|
674
768
|
id: message.id,
|
|
@@ -677,7 +771,7 @@ const create$5 = (message, result) => {
|
|
|
677
771
|
};
|
|
678
772
|
const getSuccessResponse = (message, result) => {
|
|
679
773
|
const resultProperty = result ?? null;
|
|
680
|
-
return create$
|
|
774
|
+
return create$6(message, resultProperty);
|
|
681
775
|
};
|
|
682
776
|
const getErrorResponseSimple = (id, error) => {
|
|
683
777
|
return {
|
|
@@ -781,7 +875,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
781
875
|
const responseMessage = await promise;
|
|
782
876
|
return unwrapJsonRpcResult(responseMessage);
|
|
783
877
|
};
|
|
784
|
-
const send = (transport, method, ...params) => {
|
|
878
|
+
const send$1 = (transport, method, ...params) => {
|
|
785
879
|
const message = create$4(method, params);
|
|
786
880
|
transport.send(message);
|
|
787
881
|
};
|
|
@@ -821,7 +915,7 @@ const createRpc = ipc => {
|
|
|
821
915
|
* @deprecated
|
|
822
916
|
*/
|
|
823
917
|
send(method, ...params) {
|
|
824
|
-
send(ipc, method, ...params);
|
|
918
|
+
send$1(ipc, method, ...params);
|
|
825
919
|
},
|
|
826
920
|
invoke(method, ...params) {
|
|
827
921
|
return invoke$4(ipc, method, ...params);
|
|
@@ -865,6 +959,40 @@ const listen$1 = async (module, options) => {
|
|
|
865
959
|
const ipc = module.wrap(rawIpc);
|
|
866
960
|
return ipc;
|
|
867
961
|
};
|
|
962
|
+
const create$5 = async ({
|
|
963
|
+
commandMap,
|
|
964
|
+
messagePort
|
|
965
|
+
}) => {
|
|
966
|
+
// TODO create a commandMap per rpc instance
|
|
967
|
+
register(commandMap);
|
|
968
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
969
|
+
messagePort,
|
|
970
|
+
isMessagePortOpen: true
|
|
971
|
+
});
|
|
972
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
973
|
+
handleIpc(ipc);
|
|
974
|
+
const rpc = createRpc(ipc);
|
|
975
|
+
messagePort.start();
|
|
976
|
+
return rpc;
|
|
977
|
+
};
|
|
978
|
+
const create$3 = async ({
|
|
979
|
+
commandMap,
|
|
980
|
+
send
|
|
981
|
+
}) => {
|
|
982
|
+
const {
|
|
983
|
+
port1,
|
|
984
|
+
port2
|
|
985
|
+
} = new MessageChannel();
|
|
986
|
+
await send(port1);
|
|
987
|
+
return create$5({
|
|
988
|
+
commandMap,
|
|
989
|
+
messagePort: port2
|
|
990
|
+
});
|
|
991
|
+
};
|
|
992
|
+
const TransferMessagePortRpcParent = {
|
|
993
|
+
__proto__: null,
|
|
994
|
+
create: create$3
|
|
995
|
+
};
|
|
868
996
|
const create$2 = async ({
|
|
869
997
|
commandMap
|
|
870
998
|
}) => {
|
|
@@ -901,6 +1029,10 @@ const createMockRpc = ({
|
|
|
901
1029
|
|
|
902
1030
|
const Text = 12;
|
|
903
1031
|
|
|
1032
|
+
const Button = 'event.button';
|
|
1033
|
+
const ClientX = 'event.clientX';
|
|
1034
|
+
const ClientY = 'event.clientY';
|
|
1035
|
+
|
|
904
1036
|
const Backspace$1 = 1;
|
|
905
1037
|
const Tab$1 = 2;
|
|
906
1038
|
const Enter$1 = 3;
|
|
@@ -1195,8 +1327,10 @@ const DebugWorker = 55;
|
|
|
1195
1327
|
const RendererProcess = 1670;
|
|
1196
1328
|
const RendererWorker$1 = 1;
|
|
1197
1329
|
|
|
1330
|
+
const FocusSelector = 'Viewlet.focusSelector';
|
|
1331
|
+
|
|
1198
1332
|
const rpcs = Object.create(null);
|
|
1199
|
-
const set$
|
|
1333
|
+
const set$4 = (id, rpc) => {
|
|
1200
1334
|
rpcs[id] = rpc;
|
|
1201
1335
|
};
|
|
1202
1336
|
const get$2 = id => {
|
|
@@ -1218,7 +1352,7 @@ const create$1 = rpcId => {
|
|
|
1218
1352
|
return rpc.invokeAndTransfer(method, ...params);
|
|
1219
1353
|
},
|
|
1220
1354
|
set(rpc) {
|
|
1221
|
-
set$
|
|
1355
|
+
set$4(rpcId, rpc);
|
|
1222
1356
|
},
|
|
1223
1357
|
async dispose() {
|
|
1224
1358
|
const rpc = get$2(rpcId);
|
|
@@ -1228,7 +1362,8 @@ const create$1 = rpcId => {
|
|
|
1228
1362
|
};
|
|
1229
1363
|
|
|
1230
1364
|
const {
|
|
1231
|
-
invoke: invoke$3
|
|
1365
|
+
invoke: invoke$3,
|
|
1366
|
+
set: set$3} = create$1(RendererProcess);
|
|
1232
1367
|
|
|
1233
1368
|
const {
|
|
1234
1369
|
invoke: invoke$2,
|
|
@@ -1658,6 +1793,74 @@ const closeSubMenu = async () => {
|
|
|
1658
1793
|
await invoke$3(/* Menu.hideSubMenu */7903, /* parentIndex */parentMenu.focusedIndex);
|
|
1659
1794
|
};
|
|
1660
1795
|
|
|
1796
|
+
const Separator$1 = 1;
|
|
1797
|
+
const None = 0;
|
|
1798
|
+
const SubMenu = 4;
|
|
1799
|
+
const Checked = 2;
|
|
1800
|
+
const Unchecked = 3;
|
|
1801
|
+
const Disabled = 5;
|
|
1802
|
+
const RestoreFocus = 6;
|
|
1803
|
+
const Ignore = 7;
|
|
1804
|
+
|
|
1805
|
+
// TODO lazyload menuEntries and use Command.execute (maybe)
|
|
1806
|
+
const CONTEXT_MENU_WIDTH$1 = 250;
|
|
1807
|
+
|
|
1808
|
+
// TODO difference between focusing with mouse or keyboard
|
|
1809
|
+
// with mouse -> open submenu
|
|
1810
|
+
// with keyboard -> don't open submenu, only focus
|
|
1811
|
+
|
|
1812
|
+
// TODO this code seems a bit too complicated, maybe it can be simplified
|
|
1813
|
+
|
|
1814
|
+
// TODO handle printable letter and focus item that starts with that letter
|
|
1815
|
+
|
|
1816
|
+
// TODO pageup / pagedown keys
|
|
1817
|
+
|
|
1818
|
+
// TODO more tests
|
|
1819
|
+
|
|
1820
|
+
const CONTEXT_MENU_ITEM_HEIGHT$1 = 26;
|
|
1821
|
+
const CONTEXT_MENU_SEPARATOR_HEIGHT$1 = 11;
|
|
1822
|
+
const CONTEXT_MENU_PADDING$1 = 8;
|
|
1823
|
+
const getMenuHeight$1 = items => {
|
|
1824
|
+
let height = CONTEXT_MENU_PADDING$1;
|
|
1825
|
+
for (const item of items) {
|
|
1826
|
+
switch (item.flags) {
|
|
1827
|
+
case Separator$1:
|
|
1828
|
+
height += CONTEXT_MENU_SEPARATOR_HEIGHT$1;
|
|
1829
|
+
break;
|
|
1830
|
+
default:
|
|
1831
|
+
height += CONTEXT_MENU_ITEM_HEIGHT$1;
|
|
1832
|
+
break;
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
return height;
|
|
1836
|
+
};
|
|
1837
|
+
const getMenuBounds = (x, y, items) => {
|
|
1838
|
+
const menuWidth = CONTEXT_MENU_WIDTH$1;
|
|
1839
|
+
const menuHeight = getMenuHeight$1(items);
|
|
1840
|
+
const layoutState = {
|
|
1841
|
+
points: [0, 0]
|
|
1842
|
+
};
|
|
1843
|
+
const windowWidth = layoutState.points[0];
|
|
1844
|
+
const windowHeight = layoutState.points[1];
|
|
1845
|
+
// TODO maybe only send labels and keybindings to ui (id not needed on ui)
|
|
1846
|
+
// TODO what about separators?
|
|
1847
|
+
|
|
1848
|
+
if (x + menuWidth > windowWidth) {
|
|
1849
|
+
x -= menuWidth;
|
|
1850
|
+
x = Math.max(x, 0);
|
|
1851
|
+
}
|
|
1852
|
+
if (y + menuHeight > windowHeight) {
|
|
1853
|
+
y -= menuHeight;
|
|
1854
|
+
y = Math.max(y, 0);
|
|
1855
|
+
}
|
|
1856
|
+
return {
|
|
1857
|
+
x,
|
|
1858
|
+
y,
|
|
1859
|
+
width: menuWidth,
|
|
1860
|
+
height: menuHeight
|
|
1861
|
+
};
|
|
1862
|
+
};
|
|
1863
|
+
|
|
1661
1864
|
const matchesArgs = (a, b) => {
|
|
1662
1865
|
if (!a && !b) {
|
|
1663
1866
|
return true;
|
|
@@ -1784,15 +1987,6 @@ const menuEntrySeparator = {
|
|
|
1784
1987
|
command: ''
|
|
1785
1988
|
};
|
|
1786
1989
|
|
|
1787
|
-
const Separator$1 = 1;
|
|
1788
|
-
const None = 0;
|
|
1789
|
-
const SubMenu = 4;
|
|
1790
|
-
const Checked = 2;
|
|
1791
|
-
const Unchecked = 3;
|
|
1792
|
-
const Disabled = 5;
|
|
1793
|
-
const RestoreFocus = 6;
|
|
1794
|
-
const Ignore = 7;
|
|
1795
|
-
|
|
1796
1990
|
const id$9 = Edit$1;
|
|
1797
1991
|
const getMenuEntries$d = () => {
|
|
1798
1992
|
return [{
|
|
@@ -2528,31 +2722,56 @@ const getVisible = (items, focusedIndex, expanded, level) => {
|
|
|
2528
2722
|
return visibleItems;
|
|
2529
2723
|
};
|
|
2530
2724
|
|
|
2725
|
+
const CONTEXT_MENU_WIDTH = 250;
|
|
2726
|
+
const getMenuWidth = () => {
|
|
2727
|
+
return CONTEXT_MENU_WIDTH;
|
|
2728
|
+
};
|
|
2729
|
+
|
|
2531
2730
|
// TODO lazyload menuEntries and use Command.execute (maybe)
|
|
2532
|
-
const CONTEXT_MENU_ITEM_HEIGHT
|
|
2533
|
-
const CONTEXT_MENU_SEPARATOR_HEIGHT
|
|
2534
|
-
const CONTEXT_MENU_PADDING
|
|
2535
|
-
const getMenuHeight
|
|
2536
|
-
let height = CONTEXT_MENU_PADDING
|
|
2731
|
+
const CONTEXT_MENU_ITEM_HEIGHT = 26;
|
|
2732
|
+
const CONTEXT_MENU_SEPARATOR_HEIGHT = 11;
|
|
2733
|
+
const CONTEXT_MENU_PADDING = 8;
|
|
2734
|
+
const getMenuHeight = items => {
|
|
2735
|
+
let height = CONTEXT_MENU_PADDING;
|
|
2537
2736
|
for (const item of items) {
|
|
2538
2737
|
switch (item.flags) {
|
|
2539
2738
|
case Separator$1:
|
|
2540
|
-
height += CONTEXT_MENU_SEPARATOR_HEIGHT
|
|
2739
|
+
height += CONTEXT_MENU_SEPARATOR_HEIGHT;
|
|
2541
2740
|
break;
|
|
2542
2741
|
default:
|
|
2543
|
-
height += CONTEXT_MENU_ITEM_HEIGHT
|
|
2742
|
+
height += CONTEXT_MENU_ITEM_HEIGHT;
|
|
2544
2743
|
break;
|
|
2545
2744
|
}
|
|
2546
2745
|
}
|
|
2547
2746
|
return height;
|
|
2548
2747
|
};
|
|
2549
2748
|
|
|
2749
|
+
const getMenuHideCommands = async (restoreFocus = true) => {
|
|
2750
|
+
if (getCount() === 0) {
|
|
2751
|
+
return {
|
|
2752
|
+
newMenus: [],
|
|
2753
|
+
commands: []
|
|
2754
|
+
};
|
|
2755
|
+
}
|
|
2756
|
+
reset();
|
|
2757
|
+
return {
|
|
2758
|
+
commands: [/* Menu.hide */'Menu.hide', /* restoreFocus */restoreFocus],
|
|
2759
|
+
newMenus: []
|
|
2760
|
+
};
|
|
2761
|
+
};
|
|
2762
|
+
|
|
2763
|
+
const hide = async (restoreFocus = true) => {
|
|
2764
|
+
const {
|
|
2765
|
+
commands
|
|
2766
|
+
} = await getMenuHideCommands(restoreFocus);
|
|
2767
|
+
if (commands.length > 0) {
|
|
2768
|
+
// @ts-ignore
|
|
2769
|
+
await invoke$3(...commands);
|
|
2770
|
+
}
|
|
2771
|
+
};
|
|
2772
|
+
|
|
2550
2773
|
// TODO lazyload menuEntries and use Command.execute (maybe)
|
|
2551
2774
|
const MENU_WIDTH = 150;
|
|
2552
|
-
const CONTEXT_MENU_WIDTH$1 = 250;
|
|
2553
|
-
const getMenuWidth = () => {
|
|
2554
|
-
return CONTEXT_MENU_WIDTH$1;
|
|
2555
|
-
};
|
|
2556
2775
|
|
|
2557
2776
|
// TODO difference between focusing with mouse or keyboard
|
|
2558
2777
|
// with mouse -> open submenu
|
|
@@ -2564,50 +2783,9 @@ const getMenuWidth = () => {
|
|
|
2564
2783
|
|
|
2565
2784
|
// TODO more tests
|
|
2566
2785
|
|
|
2567
|
-
const CONTEXT_MENU_ITEM_HEIGHT$1 = 26;
|
|
2568
|
-
const CONTEXT_MENU_SEPARATOR_HEIGHT$1 = 11;
|
|
2569
|
-
const CONTEXT_MENU_PADDING$1 = 8;
|
|
2570
|
-
const getMenuHeight$1 = items => {
|
|
2571
|
-
let height = CONTEXT_MENU_PADDING$1;
|
|
2572
|
-
for (const item of items) {
|
|
2573
|
-
switch (item.flags) {
|
|
2574
|
-
case Separator$1:
|
|
2575
|
-
height += CONTEXT_MENU_SEPARATOR_HEIGHT$1;
|
|
2576
|
-
break;
|
|
2577
|
-
default:
|
|
2578
|
-
height += CONTEXT_MENU_ITEM_HEIGHT$1;
|
|
2579
|
-
break;
|
|
2580
|
-
}
|
|
2581
|
-
}
|
|
2582
|
-
return height;
|
|
2583
|
-
};
|
|
2584
|
-
const getMenuBounds$1 = (x, y, items) => {
|
|
2585
|
-
const menuWidth = CONTEXT_MENU_WIDTH$1;
|
|
2586
|
-
const menuHeight = getMenuHeight$1(items);
|
|
2587
|
-
const layoutState = {
|
|
2588
|
-
points: [0, 0]
|
|
2589
|
-
};
|
|
2590
|
-
const windowWidth = layoutState.points[0];
|
|
2591
|
-
const windowHeight = layoutState.points[1];
|
|
2592
|
-
// TODO maybe only send labels and keybindings to ui (id not needed on ui)
|
|
2593
|
-
// TODO what about separators?
|
|
2594
|
-
|
|
2595
|
-
if (x + menuWidth > windowWidth) {
|
|
2596
|
-
x -= menuWidth;
|
|
2597
|
-
}
|
|
2598
|
-
if (y + menuHeight > windowHeight) {
|
|
2599
|
-
y -= menuHeight;
|
|
2600
|
-
}
|
|
2601
|
-
return {
|
|
2602
|
-
x,
|
|
2603
|
-
y,
|
|
2604
|
-
width: menuWidth,
|
|
2605
|
-
height: menuHeight
|
|
2606
|
-
};
|
|
2607
|
-
};
|
|
2608
2786
|
const show$2 = async (x, y, id, mouseBlocking = false, ...args) => {
|
|
2609
2787
|
const items = await getMenuEntriesWithKeyBindings(id, ...args);
|
|
2610
|
-
const bounds = getMenuBounds
|
|
2788
|
+
const bounds = getMenuBounds(x, y, items);
|
|
2611
2789
|
const menu = addMenuInternal({
|
|
2612
2790
|
id,
|
|
2613
2791
|
items,
|
|
@@ -2622,7 +2800,7 @@ const show$2 = async (x, y, id, mouseBlocking = false, ...args) => {
|
|
|
2622
2800
|
};
|
|
2623
2801
|
const show2$2 = async (uid, menuId, x, y, mouseBlocking = false, ...args) => {
|
|
2624
2802
|
const items = await getMenuEntriesWithKeyBindings2(uid, menuId, ...args);
|
|
2625
|
-
const bounds = getMenuBounds
|
|
2803
|
+
const bounds = getMenuBounds(x, y, items);
|
|
2626
2804
|
const menu = addMenuInternal({
|
|
2627
2805
|
id: menuId,
|
|
2628
2806
|
items,
|
|
@@ -2635,17 +2813,10 @@ const show2$2 = async (uid, menuId, x, y, mouseBlocking = false, ...args) => {
|
|
|
2635
2813
|
const dom = getMenuVirtualDom(visible).slice(1);
|
|
2636
2814
|
await invoke$1(/* Menu.show */'Menu.showMenu', /* x */bounds.x, /* y */bounds.y, /* width */bounds.width, /* height */bounds.height, /* items */menu.items, /* level */menu.level, /* parentIndex */-1, /* dom */dom, /* mouseBlocking */mouseBlocking);
|
|
2637
2815
|
};
|
|
2638
|
-
const hide$1 = async (restoreFocus = true) => {
|
|
2639
|
-
if (getCount() === 0) {
|
|
2640
|
-
return;
|
|
2641
|
-
}
|
|
2642
|
-
reset();
|
|
2643
|
-
await invoke$1(/* Menu.hide */'Menu.hide', /* restoreFocus */restoreFocus);
|
|
2644
|
-
};
|
|
2645
2816
|
|
|
2646
2817
|
const show$1 = async (x, y, id, ...args) => {
|
|
2647
2818
|
// @ts-ignore
|
|
2648
|
-
await hide
|
|
2819
|
+
await hide();
|
|
2649
2820
|
// TODO handle error
|
|
2650
2821
|
// TODO race condition
|
|
2651
2822
|
await show$2(x, y, id, /* mouseBlocking */true, ...args);
|
|
@@ -2654,7 +2825,7 @@ const show$1 = async (x, y, id, ...args) => {
|
|
|
2654
2825
|
};
|
|
2655
2826
|
const show2$1 = async (uid, menuId, x, y, ...args) => {
|
|
2656
2827
|
// @ts-ignore
|
|
2657
|
-
await hide
|
|
2828
|
+
await hide();
|
|
2658
2829
|
// TODO handle error
|
|
2659
2830
|
// TODO race condition
|
|
2660
2831
|
await show2$2(uid, menuId, x, y, /* mouseBlocking */true, ...args);
|
|
@@ -2683,7 +2854,7 @@ const show2 = async (uid, menuId, x, y, ...args) => {
|
|
|
2683
2854
|
number(menuId);
|
|
2684
2855
|
number(x);
|
|
2685
2856
|
number(y);
|
|
2686
|
-
const module = getModule();
|
|
2857
|
+
const module = await getModule();
|
|
2687
2858
|
// @ts-ignore
|
|
2688
2859
|
return module.show2(uid, menuId, x, y, ...args);
|
|
2689
2860
|
};
|
|
@@ -2765,10 +2936,7 @@ const focusIndex = async (menu, index) => {
|
|
|
2765
2936
|
}
|
|
2766
2937
|
const oldFocusedIndex = menu.focusedIndex;
|
|
2767
2938
|
menu.focusedIndex = index;
|
|
2768
|
-
|
|
2769
|
-
commands: [/* Menu.focusIndex */'Menu.focusIndex', /* level */menu.level, /* oldFocusedIndex */oldFocusedIndex, /* newFocusedIndex */index],
|
|
2770
|
-
menus: getAll()
|
|
2771
|
-
};
|
|
2939
|
+
await invoke$3('Menu.focusIndex', /* level */menu.level, /* oldFocusedIndex */oldFocusedIndex, /* newFocusedIndex */index);
|
|
2772
2940
|
};
|
|
2773
2941
|
|
|
2774
2942
|
const getCurrentMenu = () => {
|
|
@@ -2896,20 +3064,6 @@ const getKeyBindings = () => {
|
|
|
2896
3064
|
}];
|
|
2897
3065
|
};
|
|
2898
3066
|
|
|
2899
|
-
const getMenuHideCommands = async (restoreFocus = true) => {
|
|
2900
|
-
if (getCount() === 0) {
|
|
2901
|
-
return {
|
|
2902
|
-
newMenus: [],
|
|
2903
|
-
commands: []
|
|
2904
|
-
};
|
|
2905
|
-
}
|
|
2906
|
-
reset();
|
|
2907
|
-
return {
|
|
2908
|
-
commands: [/* Menu.hide */'Menu.hide', /* restoreFocus */restoreFocus],
|
|
2909
|
-
newMenus: []
|
|
2910
|
-
};
|
|
2911
|
-
};
|
|
2912
|
-
|
|
2913
3067
|
const menus = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
|
|
2914
3068
|
|
|
2915
3069
|
const getMenuIds = () => {
|
|
@@ -2924,7 +3078,6 @@ const getMenuEntries = (id, platform) => {
|
|
|
2924
3078
|
};
|
|
2925
3079
|
|
|
2926
3080
|
// TODO lazyload menuEntries and use Command.execute (maybe)
|
|
2927
|
-
const CONTEXT_MENU_WIDTH = 250;
|
|
2928
3081
|
|
|
2929
3082
|
// TODO difference between focusing with mouse or keyboard
|
|
2930
3083
|
// with mouse -> open submenu
|
|
@@ -2938,49 +3091,6 @@ const CONTEXT_MENU_WIDTH = 250;
|
|
|
2938
3091
|
|
|
2939
3092
|
// TODO more tests
|
|
2940
3093
|
|
|
2941
|
-
const CONTEXT_MENU_ITEM_HEIGHT = 26;
|
|
2942
|
-
const CONTEXT_MENU_SEPARATOR_HEIGHT = 11;
|
|
2943
|
-
const CONTEXT_MENU_PADDING = 8;
|
|
2944
|
-
const getMenuHeight = items => {
|
|
2945
|
-
let height = CONTEXT_MENU_PADDING;
|
|
2946
|
-
for (const item of items) {
|
|
2947
|
-
switch (item.flags) {
|
|
2948
|
-
case Separator$1:
|
|
2949
|
-
height += CONTEXT_MENU_SEPARATOR_HEIGHT;
|
|
2950
|
-
break;
|
|
2951
|
-
default:
|
|
2952
|
-
height += CONTEXT_MENU_ITEM_HEIGHT;
|
|
2953
|
-
break;
|
|
2954
|
-
}
|
|
2955
|
-
}
|
|
2956
|
-
return height;
|
|
2957
|
-
};
|
|
2958
|
-
const getMenuBounds = (x, y, items) => {
|
|
2959
|
-
const menuWidth = CONTEXT_MENU_WIDTH;
|
|
2960
|
-
const menuHeight = getMenuHeight(items);
|
|
2961
|
-
const layoutState = {
|
|
2962
|
-
points: [0, 0]
|
|
2963
|
-
};
|
|
2964
|
-
const windowWidth = layoutState.points[0];
|
|
2965
|
-
const windowHeight = layoutState.points[1];
|
|
2966
|
-
// TODO maybe only send labels and keybindings to ui (id not needed on ui)
|
|
2967
|
-
// TODO what about separators?
|
|
2968
|
-
|
|
2969
|
-
if (x + menuWidth > windowWidth) {
|
|
2970
|
-
x -= menuWidth;
|
|
2971
|
-
x = Math.max(x, 0);
|
|
2972
|
-
}
|
|
2973
|
-
if (y + menuHeight > windowHeight) {
|
|
2974
|
-
y -= menuHeight;
|
|
2975
|
-
y = Math.max(y, 0);
|
|
2976
|
-
}
|
|
2977
|
-
return {
|
|
2978
|
-
x,
|
|
2979
|
-
y,
|
|
2980
|
-
width: menuWidth,
|
|
2981
|
-
height: menuHeight
|
|
2982
|
-
};
|
|
2983
|
-
};
|
|
2984
3094
|
const getMenuShowCommands = async (items, menuId, x, y, mouseBlocking = false) => {
|
|
2985
3095
|
const bounds = getMenuBounds(x, y, items);
|
|
2986
3096
|
const menu = addMenuInternal({
|
|
@@ -3007,17 +3117,18 @@ const handleContextMenu = state => {
|
|
|
3007
3117
|
const hideSubMenus = async level => {
|
|
3008
3118
|
if (level < getCount()) {
|
|
3009
3119
|
set$1(getAll().slice(0, level + 1));
|
|
3010
|
-
|
|
3011
|
-
commands: [/* Menu.hideSubMenu */'Menu.hideSubMenu', /* level */level + 1],
|
|
3012
|
-
menus: getAll()
|
|
3013
|
-
};
|
|
3120
|
+
await invoke$3('Menu.hideSubMenu', /* level */level + 1);
|
|
3014
3121
|
}
|
|
3015
3122
|
};
|
|
3016
3123
|
|
|
3017
|
-
/* eslint-disable @typescript-eslint/no-implied-eval */
|
|
3018
3124
|
const MENU_DELAY_TRIANGLE = 300;
|
|
3019
|
-
const resolveAfterTimeout =
|
|
3020
|
-
|
|
3125
|
+
const resolveAfterTimeout = async () => {
|
|
3126
|
+
const {
|
|
3127
|
+
resolve,
|
|
3128
|
+
promise
|
|
3129
|
+
} = Promise.withResolvers();
|
|
3130
|
+
setTimeout(resolve, MENU_DELAY_TRIANGLE);
|
|
3131
|
+
await promise;
|
|
3021
3132
|
};
|
|
3022
3133
|
|
|
3023
3134
|
const showSubMenuAtEnter = async (level, index, enterX, enterY) => {
|
|
@@ -3037,13 +3148,10 @@ const showSubMenuAtEnter = async (level, index, enterX, enterY) => {
|
|
|
3037
3148
|
enterY
|
|
3038
3149
|
});
|
|
3039
3150
|
const width = getMenuWidth();
|
|
3040
|
-
const height = getMenuHeight
|
|
3151
|
+
const height = getMenuHeight(subMenuItems);
|
|
3041
3152
|
const visible = getVisible(subMenu.items, -1, false, subMenu.level);
|
|
3042
3153
|
const dom = getMenuVirtualDom(visible).slice(1);
|
|
3043
|
-
|
|
3044
|
-
commands: [/* Menu.showMenu */'Menu.showMenu', /* x */subMenu.x, /* y */subMenu.y, /* width */width, /* height */height, /* items */subMenu.items, /* level */subMenu.level, /* parentIndex */index, /* dom */dom],
|
|
3045
|
-
menus: getAll()
|
|
3046
|
-
};
|
|
3154
|
+
await invoke$3(/* Menu.showMenu */'Menu.showMenu', /* x */subMenu.x, /* y */subMenu.y, /* width */width, /* height */height, /* items */subMenu.items, /* level */subMenu.level, /* parentIndex */index, /* dom */dom);
|
|
3047
3155
|
};
|
|
3048
3156
|
const showSubMenu = async (level, index) => {
|
|
3049
3157
|
return showSubMenuAtEnter(level, index, -1, -1);
|
|
@@ -3063,7 +3171,7 @@ const handleMouseEnter = async (level, index, enterX, enterY, enterTimeStamp) =>
|
|
|
3063
3171
|
const subMenuEnterX = subMenu.enterX;
|
|
3064
3172
|
// TODO should check for triangle position here
|
|
3065
3173
|
if (enterX >= subMenuEnterX) {
|
|
3066
|
-
await
|
|
3174
|
+
await resolveAfterTimeout();
|
|
3067
3175
|
if (getLatestTimestamp() !== enterTimeStamp) {
|
|
3068
3176
|
return;
|
|
3069
3177
|
}
|
|
@@ -3072,7 +3180,7 @@ const handleMouseEnter = async (level, index, enterX, enterY, enterTimeStamp) =>
|
|
|
3072
3180
|
const item = menu.items[index];
|
|
3073
3181
|
await focusIndex(menu, index);
|
|
3074
3182
|
switch (item.flags) {
|
|
3075
|
-
case
|
|
3183
|
+
case SubMenu:
|
|
3076
3184
|
await showSubMenuAtEnter(menu.level, index, enterX, enterY);
|
|
3077
3185
|
break;
|
|
3078
3186
|
default:
|
|
@@ -3104,7 +3212,7 @@ const renderFocusedIndex = (oldState, newState) => {
|
|
|
3104
3212
|
if (newState.focusedIndex === -1) {
|
|
3105
3213
|
return [];
|
|
3106
3214
|
}
|
|
3107
|
-
return [
|
|
3215
|
+
return [FocusSelector, '.ViewletTitleBarMenuBar'];
|
|
3108
3216
|
};
|
|
3109
3217
|
|
|
3110
3218
|
const SetMenus = 'setMenus';
|
|
@@ -3183,19 +3291,19 @@ const renderEventListeners = () => {
|
|
|
3183
3291
|
params: ['handleFocus']
|
|
3184
3292
|
}, {
|
|
3185
3293
|
name: HandleMenuClick,
|
|
3186
|
-
params: ['handleMenuClick',
|
|
3294
|
+
params: ['handleMenuClick', ClientX, ClientY]
|
|
3187
3295
|
}, {
|
|
3188
3296
|
name: HandleMenuMouseOver,
|
|
3189
|
-
params: ['handleMenuMouseOver',
|
|
3297
|
+
params: ['handleMenuMouseOver', ClientX, ClientY]
|
|
3190
3298
|
}, {
|
|
3191
3299
|
name: HandleClick,
|
|
3192
|
-
params: ['handleClickAt',
|
|
3300
|
+
params: ['handleClickAt', Button, ClientX, ClientY]
|
|
3193
3301
|
}, {
|
|
3194
3302
|
name: HandlePointerOut,
|
|
3195
|
-
params: ['handlePointerOut',
|
|
3303
|
+
params: ['handlePointerOut', ClientX, ClientY]
|
|
3196
3304
|
}, {
|
|
3197
3305
|
name: HandlePointerOver,
|
|
3198
|
-
params: ['handlePointerOver',
|
|
3306
|
+
params: ['handlePointerOver', ClientX, ClientY]
|
|
3199
3307
|
}];
|
|
3200
3308
|
};
|
|
3201
3309
|
|
|
@@ -3212,16 +3320,6 @@ const executeMenuItemCommand = async item => {
|
|
|
3212
3320
|
await invoke(item.command, ...(item.args || []));
|
|
3213
3321
|
};
|
|
3214
3322
|
|
|
3215
|
-
const hide = async (restoreFocus = true) => {
|
|
3216
|
-
const {
|
|
3217
|
-
commands
|
|
3218
|
-
} = await getMenuHideCommands(restoreFocus);
|
|
3219
|
-
if (commands.length > 0) {
|
|
3220
|
-
// @ts-ignore
|
|
3221
|
-
await invoke$2(...commands);
|
|
3222
|
-
}
|
|
3223
|
-
};
|
|
3224
|
-
|
|
3225
3323
|
const selectIndexNone = async (menu, item) => {
|
|
3226
3324
|
await Promise.all([hide(/* restoreFocus */false), executeMenuItemCommand(item)]);
|
|
3227
3325
|
};
|
|
@@ -3290,13 +3388,13 @@ const wrapCommand = fn => {
|
|
|
3290
3388
|
};
|
|
3291
3389
|
|
|
3292
3390
|
const commandMap = {
|
|
3391
|
+
'Menu.closeSubMenu': closeSubMenu,
|
|
3293
3392
|
'Menu.diff2': diff2,
|
|
3294
|
-
'Menu.focusPrevious': focusPrevious,
|
|
3295
3393
|
'Menu.focusFirst': focusFirst,
|
|
3296
3394
|
'Menu.focusIndex': focusIndex,
|
|
3297
3395
|
'Menu.focusLast': focusLast,
|
|
3298
|
-
'Menu.closeSubMenu': closeSubMenu,
|
|
3299
3396
|
'Menu.focusNext': focusNext,
|
|
3397
|
+
'Menu.focusPrevious': focusPrevious,
|
|
3300
3398
|
'Menu.getCommands': getCommandIds,
|
|
3301
3399
|
'Menu.getHideCommands': getMenuHideCommands,
|
|
3302
3400
|
'Menu.getKeyBindings': getKeyBindings,
|
|
@@ -3307,22 +3405,45 @@ const commandMap = {
|
|
|
3307
3405
|
'Menu.handleContextMenu': handleContextMenu,
|
|
3308
3406
|
'Menu.handleMouseEnter': handleMouseEnter,
|
|
3309
3407
|
'Menu.handleMouseLeave': handleMouseLeave,
|
|
3408
|
+
'Menu.hide': hide,
|
|
3310
3409
|
'Menu.hideSubMenus': hideSubMenus,
|
|
3311
3410
|
'Menu.loadContent': wrapCommand(loadContent),
|
|
3312
3411
|
'Menu.render2': render2,
|
|
3313
3412
|
'Menu.renderEventListeners': renderEventListeners,
|
|
3314
3413
|
'Menu.saveState': saveState,
|
|
3414
|
+
'Menu.selectIndex': selectIndex,
|
|
3315
3415
|
'Menu.selectItem': selectItem,
|
|
3316
3416
|
'Menu.show': show,
|
|
3317
3417
|
'Menu.show2': show2,
|
|
3318
3418
|
'Menu.showSubMenu': showSubMenu
|
|
3319
3419
|
};
|
|
3320
3420
|
|
|
3421
|
+
const send = port => {
|
|
3422
|
+
return sendMessagePortToRendererProcess(port);
|
|
3423
|
+
};
|
|
3424
|
+
const createRendererProcessRpc = async () => {
|
|
3425
|
+
try {
|
|
3426
|
+
const rpc = await TransferMessagePortRpcParent.create({
|
|
3427
|
+
commandMap: {},
|
|
3428
|
+
send
|
|
3429
|
+
});
|
|
3430
|
+
return rpc;
|
|
3431
|
+
} catch (error) {
|
|
3432
|
+
throw new VError(error, `Failed to create renderer process rpc`);
|
|
3433
|
+
}
|
|
3434
|
+
};
|
|
3435
|
+
|
|
3436
|
+
const initializeRendererProcess = async () => {
|
|
3437
|
+
const rpc = await createRendererProcessRpc();
|
|
3438
|
+
set$3(rpc);
|
|
3439
|
+
};
|
|
3440
|
+
|
|
3321
3441
|
const listen = async () => {
|
|
3322
3442
|
const rpc = await WebWorkerRpcClient.create({
|
|
3323
3443
|
commandMap: commandMap
|
|
3324
3444
|
});
|
|
3325
3445
|
set$2(rpc);
|
|
3446
|
+
await initializeRendererProcess();
|
|
3326
3447
|
};
|
|
3327
3448
|
|
|
3328
3449
|
const main = async () => {
|