@lvce-editor/menu-worker 2.1.0 → 2.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.
- package/dist/menuWorkerMain.js +287 -161
- 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
|
};
|
|
@@ -2896,20 +3067,6 @@ const getKeyBindings = () => {
|
|
|
2896
3067
|
}];
|
|
2897
3068
|
};
|
|
2898
3069
|
|
|
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
3070
|
const menus = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
|
|
2914
3071
|
|
|
2915
3072
|
const getMenuIds = () => {
|
|
@@ -2924,7 +3081,6 @@ const getMenuEntries = (id, platform) => {
|
|
|
2924
3081
|
};
|
|
2925
3082
|
|
|
2926
3083
|
// TODO lazyload menuEntries and use Command.execute (maybe)
|
|
2927
|
-
const CONTEXT_MENU_WIDTH = 250;
|
|
2928
3084
|
|
|
2929
3085
|
// TODO difference between focusing with mouse or keyboard
|
|
2930
3086
|
// with mouse -> open submenu
|
|
@@ -2938,49 +3094,6 @@ const CONTEXT_MENU_WIDTH = 250;
|
|
|
2938
3094
|
|
|
2939
3095
|
// TODO more tests
|
|
2940
3096
|
|
|
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
3097
|
const getMenuShowCommands = async (items, menuId, x, y, mouseBlocking = false) => {
|
|
2985
3098
|
const bounds = getMenuBounds(x, y, items);
|
|
2986
3099
|
const menu = addMenuInternal({
|
|
@@ -3037,7 +3150,7 @@ const showSubMenuAtEnter = async (level, index, enterX, enterY) => {
|
|
|
3037
3150
|
enterY
|
|
3038
3151
|
});
|
|
3039
3152
|
const width = getMenuWidth();
|
|
3040
|
-
const height = getMenuHeight
|
|
3153
|
+
const height = getMenuHeight(subMenuItems);
|
|
3041
3154
|
const visible = getVisible(subMenu.items, -1, false, subMenu.level);
|
|
3042
3155
|
const dom = getMenuVirtualDom(visible).slice(1);
|
|
3043
3156
|
return {
|
|
@@ -3104,7 +3217,7 @@ const renderFocusedIndex = (oldState, newState) => {
|
|
|
3104
3217
|
if (newState.focusedIndex === -1) {
|
|
3105
3218
|
return [];
|
|
3106
3219
|
}
|
|
3107
|
-
return [
|
|
3220
|
+
return [FocusSelector, '.ViewletTitleBarMenuBar'];
|
|
3108
3221
|
};
|
|
3109
3222
|
|
|
3110
3223
|
const SetMenus = 'setMenus';
|
|
@@ -3183,19 +3296,19 @@ const renderEventListeners = () => {
|
|
|
3183
3296
|
params: ['handleFocus']
|
|
3184
3297
|
}, {
|
|
3185
3298
|
name: HandleMenuClick,
|
|
3186
|
-
params: ['handleMenuClick',
|
|
3299
|
+
params: ['handleMenuClick', ClientX, ClientY]
|
|
3187
3300
|
}, {
|
|
3188
3301
|
name: HandleMenuMouseOver,
|
|
3189
|
-
params: ['handleMenuMouseOver',
|
|
3302
|
+
params: ['handleMenuMouseOver', ClientX, ClientY]
|
|
3190
3303
|
}, {
|
|
3191
3304
|
name: HandleClick,
|
|
3192
|
-
params: ['handleClickAt',
|
|
3305
|
+
params: ['handleClickAt', Button, ClientX, ClientY]
|
|
3193
3306
|
}, {
|
|
3194
3307
|
name: HandlePointerOut,
|
|
3195
|
-
params: ['handlePointerOut',
|
|
3308
|
+
params: ['handlePointerOut', ClientX, ClientY]
|
|
3196
3309
|
}, {
|
|
3197
3310
|
name: HandlePointerOver,
|
|
3198
|
-
params: ['handlePointerOver',
|
|
3311
|
+
params: ['handlePointerOver', ClientX, ClientY]
|
|
3199
3312
|
}];
|
|
3200
3313
|
};
|
|
3201
3314
|
|
|
@@ -3212,16 +3325,6 @@ const executeMenuItemCommand = async item => {
|
|
|
3212
3325
|
await invoke(item.command, ...(item.args || []));
|
|
3213
3326
|
};
|
|
3214
3327
|
|
|
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
3328
|
const selectIndexNone = async (menu, item) => {
|
|
3226
3329
|
await Promise.all([hide(/* restoreFocus */false), executeMenuItemCommand(item)]);
|
|
3227
3330
|
};
|
|
@@ -3290,13 +3393,13 @@ const wrapCommand = fn => {
|
|
|
3290
3393
|
};
|
|
3291
3394
|
|
|
3292
3395
|
const commandMap = {
|
|
3396
|
+
'Menu.closeSubMenu': closeSubMenu,
|
|
3293
3397
|
'Menu.diff2': diff2,
|
|
3294
|
-
'Menu.focusPrevious': focusPrevious,
|
|
3295
3398
|
'Menu.focusFirst': focusFirst,
|
|
3296
3399
|
'Menu.focusIndex': focusIndex,
|
|
3297
3400
|
'Menu.focusLast': focusLast,
|
|
3298
|
-
'Menu.closeSubMenu': closeSubMenu,
|
|
3299
3401
|
'Menu.focusNext': focusNext,
|
|
3402
|
+
'Menu.focusPrevious': focusPrevious,
|
|
3300
3403
|
'Menu.getCommands': getCommandIds,
|
|
3301
3404
|
'Menu.getHideCommands': getMenuHideCommands,
|
|
3302
3405
|
'Menu.getKeyBindings': getKeyBindings,
|
|
@@ -3307,22 +3410,45 @@ const commandMap = {
|
|
|
3307
3410
|
'Menu.handleContextMenu': handleContextMenu,
|
|
3308
3411
|
'Menu.handleMouseEnter': handleMouseEnter,
|
|
3309
3412
|
'Menu.handleMouseLeave': handleMouseLeave,
|
|
3413
|
+
'Menu.hide': hide,
|
|
3310
3414
|
'Menu.hideSubMenus': hideSubMenus,
|
|
3311
3415
|
'Menu.loadContent': wrapCommand(loadContent),
|
|
3312
3416
|
'Menu.render2': render2,
|
|
3313
3417
|
'Menu.renderEventListeners': renderEventListeners,
|
|
3314
3418
|
'Menu.saveState': saveState,
|
|
3419
|
+
'Menu.selectIndex': selectIndex,
|
|
3315
3420
|
'Menu.selectItem': selectItem,
|
|
3316
3421
|
'Menu.show': show,
|
|
3317
3422
|
'Menu.show2': show2,
|
|
3318
3423
|
'Menu.showSubMenu': showSubMenu
|
|
3319
3424
|
};
|
|
3320
3425
|
|
|
3426
|
+
const send = port => {
|
|
3427
|
+
return sendMessagePortToRendererProcess(port);
|
|
3428
|
+
};
|
|
3429
|
+
const createRendererProcessRpc = async () => {
|
|
3430
|
+
try {
|
|
3431
|
+
const rpc = await TransferMessagePortRpcParent.create({
|
|
3432
|
+
commandMap: {},
|
|
3433
|
+
send
|
|
3434
|
+
});
|
|
3435
|
+
return rpc;
|
|
3436
|
+
} catch (error) {
|
|
3437
|
+
throw new VError(error, `Failed to create renderer process rpc`);
|
|
3438
|
+
}
|
|
3439
|
+
};
|
|
3440
|
+
|
|
3441
|
+
const initializeRendererProcess = async () => {
|
|
3442
|
+
const rpc = await createRendererProcessRpc();
|
|
3443
|
+
set$3(rpc);
|
|
3444
|
+
};
|
|
3445
|
+
|
|
3321
3446
|
const listen = async () => {
|
|
3322
3447
|
const rpc = await WebWorkerRpcClient.create({
|
|
3323
3448
|
commandMap: commandMap
|
|
3324
3449
|
});
|
|
3325
3450
|
set$2(rpc);
|
|
3451
|
+
await initializeRendererProcess();
|
|
3326
3452
|
};
|
|
3327
3453
|
|
|
3328
3454
|
const main = async () => {
|