@lvce-editor/status-bar-worker 1.5.0 → 1.6.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/statusBarWorkerMain.js +241 -85
- package/package.json +1 -1
|
@@ -411,9 +411,103 @@ 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
|
-
const create$4 = (method, params) => {
|
|
510
|
+
const create$4$1 = (method, params) => {
|
|
417
511
|
return {
|
|
418
512
|
jsonrpc: Two,
|
|
419
513
|
method,
|
|
@@ -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$4 = (id, fn) => {
|
|
425
519
|
callbacks[id] = fn;
|
|
426
520
|
};
|
|
427
521
|
const get$3 = id => {
|
|
@@ -440,7 +534,7 @@ const registerPromise = () => {
|
|
|
440
534
|
resolve,
|
|
441
535
|
promise
|
|
442
536
|
} = Promise.withResolvers();
|
|
443
|
-
set$
|
|
537
|
+
set$4(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 {
|
|
@@ -782,13 +876,13 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
782
876
|
return unwrapJsonRpcResult(responseMessage);
|
|
783
877
|
};
|
|
784
878
|
const send = (transport, method, ...params) => {
|
|
785
|
-
const message = create$4(method, params);
|
|
879
|
+
const message = create$4$1(method, params);
|
|
786
880
|
transport.send(message);
|
|
787
881
|
};
|
|
788
882
|
const invoke$2 = (ipc, method, ...params) => {
|
|
789
883
|
return invokeHelper(ipc, method, params, false);
|
|
790
884
|
};
|
|
791
|
-
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
885
|
+
const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
792
886
|
return invokeHelper(ipc, method, params, true);
|
|
793
887
|
};
|
|
794
888
|
|
|
@@ -827,7 +921,7 @@ const createRpc = ipc => {
|
|
|
827
921
|
return invoke$2(ipc, method, ...params);
|
|
828
922
|
},
|
|
829
923
|
invokeAndTransfer(method, ...params) {
|
|
830
|
-
return invokeAndTransfer(ipc, method, ...params);
|
|
924
|
+
return invokeAndTransfer$1(ipc, method, ...params);
|
|
831
925
|
},
|
|
832
926
|
async dispose() {
|
|
833
927
|
await ipc?.dispose();
|
|
@@ -865,7 +959,41 @@ 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
|
+
};
|
|
868
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
|
+
};
|
|
996
|
+
const create$4 = async ({
|
|
869
997
|
commandMap
|
|
870
998
|
}) => {
|
|
871
999
|
// TODO create a commandMap per rpc instance
|
|
@@ -877,14 +1005,84 @@ const create$3 = async ({
|
|
|
877
1005
|
};
|
|
878
1006
|
const WebWorkerRpcClient = {
|
|
879
1007
|
__proto__: null,
|
|
880
|
-
create: create$
|
|
1008
|
+
create: create$4
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
const Button$1 = 'button';
|
|
1012
|
+
|
|
1013
|
+
const Div = 4;
|
|
1014
|
+
const Text = 12;
|
|
1015
|
+
|
|
1016
|
+
const Button = 'event.button';
|
|
1017
|
+
const ClientX = 'event.clientX';
|
|
1018
|
+
const ClientY = 'event.clientY';
|
|
1019
|
+
const DeltaMode = 'event.deltaMode';
|
|
1020
|
+
const DeltaY = 'event.deltaY';
|
|
1021
|
+
const TargetName = 'event.target.name';
|
|
1022
|
+
const TargetValue = 'event.target.value';
|
|
1023
|
+
|
|
1024
|
+
const ExtensionHostWorker = 44;
|
|
1025
|
+
const RendererWorker = 1;
|
|
1026
|
+
const SourceControlWorker = 66;
|
|
1027
|
+
|
|
1028
|
+
const SetDom2 = 'Viewlet.setDom2';
|
|
1029
|
+
|
|
1030
|
+
const rpcs = Object.create(null);
|
|
1031
|
+
const set$3 = (id, rpc) => {
|
|
1032
|
+
rpcs[id] = rpc;
|
|
1033
|
+
};
|
|
1034
|
+
const get$2 = id => {
|
|
1035
|
+
return rpcs[id];
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
const create$2 = rpcId => {
|
|
1039
|
+
return {
|
|
1040
|
+
// @ts-ignore
|
|
1041
|
+
invoke(method, ...params) {
|
|
1042
|
+
const rpc = get$2(rpcId);
|
|
1043
|
+
// @ts-ignore
|
|
1044
|
+
return rpc.invoke(method, ...params);
|
|
1045
|
+
},
|
|
1046
|
+
// @ts-ignore
|
|
1047
|
+
invokeAndTransfer(method, ...params) {
|
|
1048
|
+
const rpc = get$2(rpcId);
|
|
1049
|
+
// @ts-ignore
|
|
1050
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1051
|
+
},
|
|
1052
|
+
set(rpc) {
|
|
1053
|
+
set$3(rpcId, rpc);
|
|
1054
|
+
},
|
|
1055
|
+
async dispose() {
|
|
1056
|
+
const rpc = get$2(rpcId);
|
|
1057
|
+
await rpc.dispose();
|
|
1058
|
+
}
|
|
1059
|
+
};
|
|
1060
|
+
};
|
|
1061
|
+
|
|
1062
|
+
const {
|
|
1063
|
+
invoke: invoke$1,
|
|
1064
|
+
set: set$2} = create$2(ExtensionHostWorker);
|
|
1065
|
+
|
|
1066
|
+
const {
|
|
1067
|
+
invoke,
|
|
1068
|
+
invokeAndTransfer,
|
|
1069
|
+
set: set$1} = create$2(RendererWorker);
|
|
1070
|
+
const sendMessagePortToExtensionHostWorker$1 = async (port, rpcId = 0) => {
|
|
1071
|
+
const command = 'HandleMessagePort.handleMessagePort2';
|
|
1072
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
|
|
1073
|
+
};
|
|
1074
|
+
const activateByEvent$1 = event => {
|
|
1075
|
+
return invoke('ExtensionHostManagement.activateByEvent', event);
|
|
1076
|
+
};
|
|
1077
|
+
const getPreference = async key => {
|
|
1078
|
+
return await invoke('Preferences.get', key);
|
|
881
1079
|
};
|
|
882
1080
|
|
|
883
1081
|
const toCommandId = key => {
|
|
884
1082
|
const dotIndex = key.indexOf('.');
|
|
885
1083
|
return key.slice(dotIndex + 1);
|
|
886
1084
|
};
|
|
887
|
-
const create$
|
|
1085
|
+
const create$1 = () => {
|
|
888
1086
|
const states = Object.create(null);
|
|
889
1087
|
const commandMapRef = {};
|
|
890
1088
|
return {
|
|
@@ -966,17 +1164,19 @@ const terminate = () => {
|
|
|
966
1164
|
};
|
|
967
1165
|
|
|
968
1166
|
const {
|
|
969
|
-
get: get$
|
|
970
|
-
|
|
971
|
-
|
|
1167
|
+
get: get$1,
|
|
1168
|
+
getCommandIds,
|
|
1169
|
+
registerCommands,
|
|
1170
|
+
set,
|
|
1171
|
+
wrapCommand} = create$1();
|
|
972
1172
|
|
|
973
|
-
const create
|
|
1173
|
+
const create = uid => {
|
|
974
1174
|
const state = {
|
|
975
1175
|
statusBarItemsLeft: [],
|
|
976
1176
|
statusBarItemsRight: [],
|
|
977
1177
|
uid
|
|
978
1178
|
};
|
|
979
|
-
set
|
|
1179
|
+
set(uid, state, state);
|
|
980
1180
|
};
|
|
981
1181
|
|
|
982
1182
|
const isEqual = (oldState, newState) => {
|
|
@@ -1003,7 +1203,7 @@ const diff2 = uid => {
|
|
|
1003
1203
|
const {
|
|
1004
1204
|
newState,
|
|
1005
1205
|
oldState
|
|
1006
|
-
} = get$
|
|
1206
|
+
} = get$1(uid);
|
|
1007
1207
|
const result = diff(oldState, newState);
|
|
1008
1208
|
return result;
|
|
1009
1209
|
};
|
|
@@ -1014,10 +1214,25 @@ const handleClick = (state, name) => {
|
|
|
1014
1214
|
return state;
|
|
1015
1215
|
};
|
|
1016
1216
|
|
|
1017
|
-
const
|
|
1217
|
+
const sendMessagePortToExtensionHostWorker = async port => {
|
|
1218
|
+
await sendMessagePortToExtensionHostWorker$1(port, SourceControlWorker);
|
|
1219
|
+
};
|
|
1220
|
+
|
|
1221
|
+
const createExtensionHostRpc = async () => {
|
|
1222
|
+
try {
|
|
1223
|
+
const rpc = await TransferMessagePortRpcParent.create({
|
|
1224
|
+
commandMap: {},
|
|
1225
|
+
send: sendMessagePortToExtensionHostWorker
|
|
1226
|
+
});
|
|
1227
|
+
return rpc;
|
|
1228
|
+
} catch (error) {
|
|
1229
|
+
throw new VError(error, `Failed to create extension host rpc`);
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1018
1232
|
|
|
1019
1233
|
const initialize = async () => {
|
|
1020
|
-
await
|
|
1234
|
+
const rpc = await createExtensionHostRpc();
|
|
1235
|
+
set$2(rpc);
|
|
1021
1236
|
};
|
|
1022
1237
|
|
|
1023
1238
|
const getIndex = (items, item) => {
|
|
@@ -1068,68 +1283,6 @@ const OnStatusBarItem = 'onStatusBarItem';
|
|
|
1068
1283
|
|
|
1069
1284
|
const GetStatusBarItems = 'ExtensionHost.getStatusBarItems';
|
|
1070
1285
|
|
|
1071
|
-
const Button$1 = 'button';
|
|
1072
|
-
|
|
1073
|
-
const Div = 4;
|
|
1074
|
-
const Text = 12;
|
|
1075
|
-
|
|
1076
|
-
const Button = 'event.button';
|
|
1077
|
-
const ClientX = 'event.clientX';
|
|
1078
|
-
const ClientY = 'event.clientY';
|
|
1079
|
-
const DeltaMode = 'event.deltaMode';
|
|
1080
|
-
const DeltaY = 'event.deltaY';
|
|
1081
|
-
const TargetName = 'event.target.name';
|
|
1082
|
-
const TargetValue = 'event.target.value';
|
|
1083
|
-
|
|
1084
|
-
const ExtensionHostWorker = 44;
|
|
1085
|
-
const RendererWorker = 1;
|
|
1086
|
-
|
|
1087
|
-
const SetDom2 = 'Viewlet.setDom2';
|
|
1088
|
-
|
|
1089
|
-
const rpcs = Object.create(null);
|
|
1090
|
-
const set = (id, rpc) => {
|
|
1091
|
-
rpcs[id] = rpc;
|
|
1092
|
-
};
|
|
1093
|
-
const get$1 = id => {
|
|
1094
|
-
return rpcs[id];
|
|
1095
|
-
};
|
|
1096
|
-
|
|
1097
|
-
const create = rpcId => {
|
|
1098
|
-
return {
|
|
1099
|
-
// @ts-ignore
|
|
1100
|
-
invoke(method, ...params) {
|
|
1101
|
-
const rpc = get$1(rpcId);
|
|
1102
|
-
// @ts-ignore
|
|
1103
|
-
return rpc.invoke(method, ...params);
|
|
1104
|
-
},
|
|
1105
|
-
// @ts-ignore
|
|
1106
|
-
invokeAndTransfer(method, ...params) {
|
|
1107
|
-
const rpc = get$1(rpcId);
|
|
1108
|
-
// @ts-ignore
|
|
1109
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
1110
|
-
},
|
|
1111
|
-
set(rpc) {
|
|
1112
|
-
set(rpcId, rpc);
|
|
1113
|
-
},
|
|
1114
|
-
async dispose() {
|
|
1115
|
-
const rpc = get$1(rpcId);
|
|
1116
|
-
await rpc.dispose();
|
|
1117
|
-
}
|
|
1118
|
-
};
|
|
1119
|
-
};
|
|
1120
|
-
|
|
1121
|
-
const {
|
|
1122
|
-
invoke: invoke$1} = create(ExtensionHostWorker);
|
|
1123
|
-
|
|
1124
|
-
const {
|
|
1125
|
-
invoke} = create(RendererWorker);
|
|
1126
|
-
const activateByEvent$1 = event => {
|
|
1127
|
-
return invoke('ExtensionHostManagement.activateByEvent', event);
|
|
1128
|
-
};
|
|
1129
|
-
const getPreference = async key => {
|
|
1130
|
-
return await invoke('Preferences.get', key);
|
|
1131
|
-
};
|
|
1132
|
-
|
|
1133
1286
|
const activateByEvent = event => {
|
|
1134
1287
|
return activateByEvent$1(event);
|
|
1135
1288
|
};
|
|
@@ -1285,8 +1438,8 @@ const render2 = (uid, diffResult) => {
|
|
|
1285
1438
|
const {
|
|
1286
1439
|
newState,
|
|
1287
1440
|
oldState
|
|
1288
|
-
} = get$
|
|
1289
|
-
set
|
|
1441
|
+
} = get$1(uid);
|
|
1442
|
+
set(uid, newState, newState);
|
|
1290
1443
|
const commands = applyRender(oldState, newState, diffResult);
|
|
1291
1444
|
return commands;
|
|
1292
1445
|
};
|
|
@@ -1347,7 +1500,7 @@ const resize = (state, dimensions) => {
|
|
|
1347
1500
|
|
|
1348
1501
|
const saveState = uid => {
|
|
1349
1502
|
number(uid);
|
|
1350
|
-
const value = get$
|
|
1503
|
+
const value = get$1(uid);
|
|
1351
1504
|
const {
|
|
1352
1505
|
newState
|
|
1353
1506
|
} = value;
|
|
@@ -1362,8 +1515,9 @@ const saveState = uid => {
|
|
|
1362
1515
|
};
|
|
1363
1516
|
|
|
1364
1517
|
const commandMap = {
|
|
1365
|
-
'StatusBar.create': create
|
|
1518
|
+
'StatusBar.create': create,
|
|
1366
1519
|
'StatusBar.diff2': diff2,
|
|
1520
|
+
'StatusBar.getCommandIds': getCommandIds,
|
|
1367
1521
|
'StatusBar.handleClick': wrapCommand(handleClick),
|
|
1368
1522
|
'StatusBar.initialize': initialize,
|
|
1369
1523
|
'StatusBar.itemLeftUpdate': wrapCommand(itemLeftUpdate),
|
|
@@ -1378,9 +1532,11 @@ const commandMap = {
|
|
|
1378
1532
|
};
|
|
1379
1533
|
|
|
1380
1534
|
const listen = async () => {
|
|
1381
|
-
|
|
1535
|
+
registerCommands(commandMap);
|
|
1536
|
+
const rpc = await WebWorkerRpcClient.create({
|
|
1382
1537
|
commandMap: commandMap
|
|
1383
1538
|
});
|
|
1539
|
+
set$1(rpc);
|
|
1384
1540
|
};
|
|
1385
1541
|
|
|
1386
1542
|
const main = async () => {
|