@lvce-editor/status-bar-worker 1.1.0 → 1.3.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 +482 -15
- package/package.json +5 -2
|
@@ -54,6 +54,49 @@ class VError extends Error {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
class AssertionError extends Error {
|
|
58
|
+
constructor(message) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = 'AssertionError';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const Object$1 = 1;
|
|
64
|
+
const Number$1 = 2;
|
|
65
|
+
const Array$1 = 3;
|
|
66
|
+
const String = 4;
|
|
67
|
+
const Boolean = 5;
|
|
68
|
+
const Function = 6;
|
|
69
|
+
const Null = 7;
|
|
70
|
+
const Unknown = 8;
|
|
71
|
+
const getType = value => {
|
|
72
|
+
switch (typeof value) {
|
|
73
|
+
case 'number':
|
|
74
|
+
return Number$1;
|
|
75
|
+
case 'function':
|
|
76
|
+
return Function;
|
|
77
|
+
case 'string':
|
|
78
|
+
return String;
|
|
79
|
+
case 'object':
|
|
80
|
+
if (value === null) {
|
|
81
|
+
return Null;
|
|
82
|
+
}
|
|
83
|
+
if (Array.isArray(value)) {
|
|
84
|
+
return Array$1;
|
|
85
|
+
}
|
|
86
|
+
return Object$1;
|
|
87
|
+
case 'boolean':
|
|
88
|
+
return Boolean;
|
|
89
|
+
default:
|
|
90
|
+
return Unknown;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const number = value => {
|
|
94
|
+
const type = getType(value);
|
|
95
|
+
if (type !== Number$1) {
|
|
96
|
+
throw new AssertionError('expected value to be of type number');
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
57
100
|
const isMessagePort = value => {
|
|
58
101
|
return value && value instanceof MessagePort;
|
|
59
102
|
};
|
|
@@ -378,32 +421,32 @@ const create$4 = (method, params) => {
|
|
|
378
421
|
};
|
|
379
422
|
};
|
|
380
423
|
const callbacks = Object.create(null);
|
|
381
|
-
const set = (id, fn) => {
|
|
424
|
+
const set$2 = (id, fn) => {
|
|
382
425
|
callbacks[id] = fn;
|
|
383
426
|
};
|
|
384
|
-
const get = id => {
|
|
427
|
+
const get$3 = id => {
|
|
385
428
|
return callbacks[id];
|
|
386
429
|
};
|
|
387
430
|
const remove = id => {
|
|
388
431
|
delete callbacks[id];
|
|
389
432
|
};
|
|
390
433
|
let id = 0;
|
|
391
|
-
const create$3 = () => {
|
|
434
|
+
const create$3$1 = () => {
|
|
392
435
|
return ++id;
|
|
393
436
|
};
|
|
394
437
|
const registerPromise = () => {
|
|
395
|
-
const id = create$3();
|
|
438
|
+
const id = create$3$1();
|
|
396
439
|
const {
|
|
397
440
|
resolve,
|
|
398
441
|
promise
|
|
399
442
|
} = Promise.withResolvers();
|
|
400
|
-
set(id, resolve);
|
|
443
|
+
set$2(id, resolve);
|
|
401
444
|
return {
|
|
402
445
|
id,
|
|
403
446
|
promise
|
|
404
447
|
};
|
|
405
448
|
};
|
|
406
|
-
const create$2 = (method, params) => {
|
|
449
|
+
const create$2$1 = (method, params) => {
|
|
407
450
|
const {
|
|
408
451
|
id,
|
|
409
452
|
promise
|
|
@@ -562,7 +605,7 @@ const warn = (...args) => {
|
|
|
562
605
|
console.warn(...args);
|
|
563
606
|
};
|
|
564
607
|
const resolve = (id, response) => {
|
|
565
|
-
const fn = get(id);
|
|
608
|
+
const fn = get$3(id);
|
|
566
609
|
if (!fn) {
|
|
567
610
|
console.log(response);
|
|
568
611
|
warn(`callback ${id} may already be disposed`);
|
|
@@ -612,7 +655,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
612
655
|
}
|
|
613
656
|
};
|
|
614
657
|
};
|
|
615
|
-
const create$1 = (id, error) => {
|
|
658
|
+
const create$1$1 = (id, error) => {
|
|
616
659
|
return {
|
|
617
660
|
jsonrpc: Two,
|
|
618
661
|
id,
|
|
@@ -623,7 +666,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
623
666
|
const prettyError = preparePrettyError(error);
|
|
624
667
|
logError(error, prettyError);
|
|
625
668
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
626
|
-
return create$1(id, errorProperty);
|
|
669
|
+
return create$1$1(id, errorProperty);
|
|
627
670
|
};
|
|
628
671
|
const create$5 = (message, result) => {
|
|
629
672
|
return {
|
|
@@ -729,7 +772,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
729
772
|
const {
|
|
730
773
|
message,
|
|
731
774
|
promise
|
|
732
|
-
} = create$2(method, params);
|
|
775
|
+
} = create$2$1(method, params);
|
|
733
776
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
734
777
|
ipc.sendAndTransfer(message);
|
|
735
778
|
} else {
|
|
@@ -742,7 +785,7 @@ const send = (transport, method, ...params) => {
|
|
|
742
785
|
const message = create$4(method, params);
|
|
743
786
|
transport.send(message);
|
|
744
787
|
};
|
|
745
|
-
const invoke = (ipc, method, ...params) => {
|
|
788
|
+
const invoke$2 = (ipc, method, ...params) => {
|
|
746
789
|
return invokeHelper(ipc, method, params, false);
|
|
747
790
|
};
|
|
748
791
|
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
@@ -781,7 +824,7 @@ const createRpc = ipc => {
|
|
|
781
824
|
send(ipc, method, ...params);
|
|
782
825
|
},
|
|
783
826
|
invoke(method, ...params) {
|
|
784
|
-
return invoke(ipc, method, ...params);
|
|
827
|
+
return invoke$2(ipc, method, ...params);
|
|
785
828
|
},
|
|
786
829
|
invokeAndTransfer(method, ...params) {
|
|
787
830
|
return invokeAndTransfer(ipc, method, ...params);
|
|
@@ -822,7 +865,7 @@ const listen$1 = async (module, options) => {
|
|
|
822
865
|
const ipc = module.wrap(rawIpc);
|
|
823
866
|
return ipc;
|
|
824
867
|
};
|
|
825
|
-
const create = async ({
|
|
868
|
+
const create$3 = async ({
|
|
826
869
|
commandMap
|
|
827
870
|
}) => {
|
|
828
871
|
// TODO create a commandMap per rpc instance
|
|
@@ -834,10 +877,434 @@ const create = async ({
|
|
|
834
877
|
};
|
|
835
878
|
const WebWorkerRpcClient = {
|
|
836
879
|
__proto__: null,
|
|
837
|
-
create
|
|
880
|
+
create: create$3
|
|
838
881
|
};
|
|
839
882
|
|
|
840
|
-
const
|
|
883
|
+
const toCommandId = key => {
|
|
884
|
+
const dotIndex = key.indexOf('.');
|
|
885
|
+
return key.slice(dotIndex + 1);
|
|
886
|
+
};
|
|
887
|
+
const create$2 = () => {
|
|
888
|
+
const states = Object.create(null);
|
|
889
|
+
const commandMapRef = {};
|
|
890
|
+
return {
|
|
891
|
+
get(uid) {
|
|
892
|
+
return states[uid];
|
|
893
|
+
},
|
|
894
|
+
set(uid, oldState, newState) {
|
|
895
|
+
states[uid] = {
|
|
896
|
+
oldState,
|
|
897
|
+
newState
|
|
898
|
+
};
|
|
899
|
+
},
|
|
900
|
+
dispose(uid) {
|
|
901
|
+
delete states[uid];
|
|
902
|
+
},
|
|
903
|
+
getKeys() {
|
|
904
|
+
return Object.keys(states).map(key => {
|
|
905
|
+
return Number.parseInt(key);
|
|
906
|
+
});
|
|
907
|
+
},
|
|
908
|
+
clear() {
|
|
909
|
+
for (const key of Object.keys(states)) {
|
|
910
|
+
delete states[key];
|
|
911
|
+
}
|
|
912
|
+
},
|
|
913
|
+
wrapCommand(fn) {
|
|
914
|
+
const wrapped = async (uid, ...args) => {
|
|
915
|
+
const {
|
|
916
|
+
oldState,
|
|
917
|
+
newState
|
|
918
|
+
} = states[uid];
|
|
919
|
+
const newerState = await fn(newState, ...args);
|
|
920
|
+
if (oldState === newerState || newState === newerState) {
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
const latest = states[uid];
|
|
924
|
+
states[uid] = {
|
|
925
|
+
oldState: latest.oldState,
|
|
926
|
+
newState: newerState
|
|
927
|
+
};
|
|
928
|
+
};
|
|
929
|
+
return wrapped;
|
|
930
|
+
},
|
|
931
|
+
wrapGetter(fn) {
|
|
932
|
+
const wrapped = (uid, ...args) => {
|
|
933
|
+
const {
|
|
934
|
+
newState
|
|
935
|
+
} = states[uid];
|
|
936
|
+
return fn(newState, ...args);
|
|
937
|
+
};
|
|
938
|
+
return wrapped;
|
|
939
|
+
},
|
|
940
|
+
diff(uid, modules, numbers) {
|
|
941
|
+
const {
|
|
942
|
+
oldState,
|
|
943
|
+
newState
|
|
944
|
+
} = states[uid];
|
|
945
|
+
const diffResult = [];
|
|
946
|
+
for (let i = 0; i < modules.length; i++) {
|
|
947
|
+
const fn = modules[i];
|
|
948
|
+
if (!fn(oldState, newState)) {
|
|
949
|
+
diffResult.push(numbers[i]);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return diffResult;
|
|
953
|
+
},
|
|
954
|
+
getCommandIds() {
|
|
955
|
+
const keys = Object.keys(commandMapRef);
|
|
956
|
+
const ids = keys.map(toCommandId);
|
|
957
|
+
return ids;
|
|
958
|
+
},
|
|
959
|
+
registerCommands(commandMap) {
|
|
960
|
+
Object.assign(commandMapRef, commandMap);
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
};
|
|
964
|
+
const terminate = () => {
|
|
965
|
+
globalThis.close();
|
|
966
|
+
};
|
|
967
|
+
|
|
968
|
+
const {
|
|
969
|
+
get: get$2,
|
|
970
|
+
set: set$1,
|
|
971
|
+
wrapCommand} = create$2();
|
|
972
|
+
|
|
973
|
+
const create$1 = uid => {
|
|
974
|
+
const state = {
|
|
975
|
+
statusBarItemsLeft: [],
|
|
976
|
+
statusBarItemsRight: [],
|
|
977
|
+
uid
|
|
978
|
+
};
|
|
979
|
+
set$1(uid, state, state);
|
|
980
|
+
};
|
|
981
|
+
|
|
982
|
+
const isEqual = (oldState, newState) => {
|
|
983
|
+
return oldState.statusBarItemsLeft === newState.statusBarItemsLeft && oldState.statusBarItemsRight === newState.statusBarItemsRight;
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
const RenderItems = 4;
|
|
987
|
+
|
|
988
|
+
const modules = [isEqual];
|
|
989
|
+
const numbers = [RenderItems];
|
|
990
|
+
|
|
991
|
+
const diff = (oldState, newState) => {
|
|
992
|
+
const diffResult = [];
|
|
993
|
+
for (let i = 0; i < modules.length; i++) {
|
|
994
|
+
const fn = modules[i];
|
|
995
|
+
if (!fn(oldState, newState)) {
|
|
996
|
+
diffResult.push(numbers[i]);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
return diffResult;
|
|
1000
|
+
};
|
|
1001
|
+
|
|
1002
|
+
const diff2 = uid => {
|
|
1003
|
+
const {
|
|
1004
|
+
newState,
|
|
1005
|
+
oldState
|
|
1006
|
+
} = get$2(uid);
|
|
1007
|
+
const result = diff(oldState, newState);
|
|
1008
|
+
return result;
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
const handleClick = (state, name) => {
|
|
1012
|
+
// TODO
|
|
1013
|
+
// sendExtensionWorker([/* statusBarItemHandleClick */ 7657, /* name */ name])
|
|
1014
|
+
return state;
|
|
1015
|
+
};
|
|
1016
|
+
|
|
1017
|
+
const getIndex = (items, item) => {
|
|
1018
|
+
for (let i = 0; i < items.length; i++) {
|
|
1019
|
+
if (items[i].name === item.name) {
|
|
1020
|
+
return i;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
return -1;
|
|
1024
|
+
};
|
|
1025
|
+
const updateArray = (items, newItem) => {
|
|
1026
|
+
const index = getIndex(items, newItem);
|
|
1027
|
+
const before = items.slice(0, index);
|
|
1028
|
+
const after = items.slice(index + 1);
|
|
1029
|
+
return [...before, newItem, ...after];
|
|
1030
|
+
};
|
|
1031
|
+
|
|
1032
|
+
const itemLeftUpdate = (state, newItem) => {
|
|
1033
|
+
return {
|
|
1034
|
+
...state,
|
|
1035
|
+
statusBarItemsLeft: updateArray([...state.statusBarItemsLeft], newItem)
|
|
1036
|
+
};
|
|
1037
|
+
};
|
|
1038
|
+
|
|
1039
|
+
const itemRightCreate = (state, newItem) => {
|
|
1040
|
+
const {
|
|
1041
|
+
statusBarItemsRight
|
|
1042
|
+
} = state;
|
|
1043
|
+
const newStatusBarItemsRight = [...statusBarItemsRight, newItem];
|
|
1044
|
+
return {
|
|
1045
|
+
...state,
|
|
1046
|
+
statusBarItemsRight: newStatusBarItemsRight
|
|
1047
|
+
};
|
|
1048
|
+
};
|
|
1049
|
+
|
|
1050
|
+
const itemRightUpdate = (state, newItem) => {
|
|
1051
|
+
const {
|
|
1052
|
+
statusBarItemsRight
|
|
1053
|
+
} = state;
|
|
1054
|
+
const newStatusBarItemsRight = updateArray([...statusBarItemsRight], newItem);
|
|
1055
|
+
return {
|
|
1056
|
+
...state,
|
|
1057
|
+
statusBarItemsRight: newStatusBarItemsRight
|
|
1058
|
+
};
|
|
1059
|
+
};
|
|
1060
|
+
|
|
1061
|
+
const OnStatusBarItem = 'onStatusBarItem';
|
|
1062
|
+
|
|
1063
|
+
const GetStatusBarItems = 'ExtensionHost.getStatusBarItems';
|
|
1064
|
+
|
|
1065
|
+
const Button = 'button';
|
|
1066
|
+
|
|
1067
|
+
const Div = 4;
|
|
1068
|
+
const Text = 12;
|
|
1069
|
+
|
|
1070
|
+
const ExtensionHostWorker = 44;
|
|
1071
|
+
const RendererWorker = 1;
|
|
1072
|
+
|
|
1073
|
+
const SetDom2 = 'Viewlet.setDom2';
|
|
1074
|
+
|
|
1075
|
+
const rpcs = Object.create(null);
|
|
1076
|
+
const set = (id, rpc) => {
|
|
1077
|
+
rpcs[id] = rpc;
|
|
1078
|
+
};
|
|
1079
|
+
const get$1 = id => {
|
|
1080
|
+
return rpcs[id];
|
|
1081
|
+
};
|
|
1082
|
+
|
|
1083
|
+
const create = rpcId => {
|
|
1084
|
+
return {
|
|
1085
|
+
// @ts-ignore
|
|
1086
|
+
invoke(method, ...params) {
|
|
1087
|
+
const rpc = get$1(rpcId);
|
|
1088
|
+
// @ts-ignore
|
|
1089
|
+
return rpc.invoke(method, ...params);
|
|
1090
|
+
},
|
|
1091
|
+
// @ts-ignore
|
|
1092
|
+
invokeAndTransfer(method, ...params) {
|
|
1093
|
+
const rpc = get$1(rpcId);
|
|
1094
|
+
// @ts-ignore
|
|
1095
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1096
|
+
},
|
|
1097
|
+
set(rpc) {
|
|
1098
|
+
set(rpcId, rpc);
|
|
1099
|
+
},
|
|
1100
|
+
async dispose() {
|
|
1101
|
+
const rpc = get$1(rpcId);
|
|
1102
|
+
await rpc.dispose();
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
};
|
|
1106
|
+
|
|
1107
|
+
const {
|
|
1108
|
+
invoke: invoke$1} = create(ExtensionHostWorker);
|
|
1109
|
+
|
|
1110
|
+
const {
|
|
1111
|
+
invoke} = create(RendererWorker);
|
|
1112
|
+
const activateByEvent$1 = event => {
|
|
1113
|
+
return invoke('ExtensionHostManagement.activateByEvent', event);
|
|
1114
|
+
};
|
|
1115
|
+
const getPreference = async key => {
|
|
1116
|
+
return await invoke('Preferences.get', key);
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
const activateByEvent = event => {
|
|
1120
|
+
return activateByEvent$1(event);
|
|
1121
|
+
};
|
|
1122
|
+
|
|
1123
|
+
const executeProviders = async ({
|
|
1124
|
+
combineResults,
|
|
1125
|
+
event,
|
|
1126
|
+
method,
|
|
1127
|
+
noProviderFoundMessage = 'No provider found',
|
|
1128
|
+
noProviderFoundResult,
|
|
1129
|
+
params
|
|
1130
|
+
}) => {
|
|
1131
|
+
await activateByEvent(event);
|
|
1132
|
+
// @ts-ignore
|
|
1133
|
+
const result = await invoke$1(method, ...params);
|
|
1134
|
+
return result;
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
const combineResults = results => {
|
|
1138
|
+
return results.flat();
|
|
1139
|
+
};
|
|
1140
|
+
const getStatusBarItems$1 = () => {
|
|
1141
|
+
return executeProviders({
|
|
1142
|
+
combineResults,
|
|
1143
|
+
event: OnStatusBarItem,
|
|
1144
|
+
method: GetStatusBarItems,
|
|
1145
|
+
noProviderFoundMessage: 'No status bar item provider found',
|
|
1146
|
+
noProviderFoundResult: [],
|
|
1147
|
+
params: []
|
|
1148
|
+
});
|
|
1149
|
+
};
|
|
1150
|
+
|
|
1151
|
+
const toUiStatusBarItem = extensionHostStatusBarItem => {
|
|
1152
|
+
return {
|
|
1153
|
+
command: extensionHostStatusBarItem.command || '',
|
|
1154
|
+
icon: extensionHostStatusBarItem.icon || '',
|
|
1155
|
+
name: extensionHostStatusBarItem.id || '',
|
|
1156
|
+
text: extensionHostStatusBarItem.text || '',
|
|
1157
|
+
tooltip: extensionHostStatusBarItem.tooltip || ''
|
|
1158
|
+
};
|
|
1159
|
+
};
|
|
1160
|
+
const toUiStatusBarItems = statusBarItems => {
|
|
1161
|
+
if (!statusBarItems) {
|
|
1162
|
+
return [];
|
|
1163
|
+
}
|
|
1164
|
+
return statusBarItems.map(toUiStatusBarItem);
|
|
1165
|
+
};
|
|
1166
|
+
const getStatusBarItems = async showItems => {
|
|
1167
|
+
if (!showItems) {
|
|
1168
|
+
return [];
|
|
1169
|
+
}
|
|
1170
|
+
await activateByEvent('onSourceControl');
|
|
1171
|
+
const extensionStatusBarItems = await getStatusBarItems$1();
|
|
1172
|
+
const uiStatusBarItems = toUiStatusBarItems(extensionStatusBarItems);
|
|
1173
|
+
return uiStatusBarItems;
|
|
1174
|
+
};
|
|
1175
|
+
|
|
1176
|
+
const get = async key => {
|
|
1177
|
+
return getPreference(key);
|
|
1178
|
+
};
|
|
1179
|
+
|
|
1180
|
+
const itemsVisible = async () => {
|
|
1181
|
+
const statusBarItemsPreference = (await get('statusBar.itemsVisible')) ?? false;
|
|
1182
|
+
return statusBarItemsPreference;
|
|
1183
|
+
};
|
|
1184
|
+
|
|
1185
|
+
const loadContent = async state => {
|
|
1186
|
+
const statusBarItemsPreference = await itemsVisible();
|
|
1187
|
+
const statusBarItems = await getStatusBarItems(statusBarItemsPreference);
|
|
1188
|
+
return {
|
|
1189
|
+
...state,
|
|
1190
|
+
statusBarItemsLeft: [...statusBarItems]
|
|
1191
|
+
};
|
|
1192
|
+
};
|
|
1193
|
+
|
|
1194
|
+
const StatusBarItem = 'StatusBarItem';
|
|
1195
|
+
const StatusBarItemsLeft = 'StatusBarItemsLeft';
|
|
1196
|
+
const StatusBarItemsRight = 'StatusBarItemsRight';
|
|
1197
|
+
|
|
1198
|
+
const text = data => {
|
|
1199
|
+
return {
|
|
1200
|
+
type: Text,
|
|
1201
|
+
text: data,
|
|
1202
|
+
childCount: 0
|
|
1203
|
+
};
|
|
1204
|
+
};
|
|
1205
|
+
|
|
1206
|
+
const getStatusBarItemVirtualDom = statusBarItem => {
|
|
1207
|
+
const {
|
|
1208
|
+
tooltip
|
|
1209
|
+
} = statusBarItem;
|
|
1210
|
+
return [{
|
|
1211
|
+
childCount: 1,
|
|
1212
|
+
className: StatusBarItem,
|
|
1213
|
+
role: Button,
|
|
1214
|
+
tabIndex: -1,
|
|
1215
|
+
title: tooltip,
|
|
1216
|
+
type: Div
|
|
1217
|
+
}, text(statusBarItem.text)];
|
|
1218
|
+
};
|
|
1219
|
+
|
|
1220
|
+
const getStatusBarItemsVirtualDom = (items, className) => {
|
|
1221
|
+
return [{
|
|
1222
|
+
childCount: items.length,
|
|
1223
|
+
className,
|
|
1224
|
+
type: Div
|
|
1225
|
+
}, ...items.flatMap(getStatusBarItemVirtualDom)];
|
|
1226
|
+
};
|
|
1227
|
+
|
|
1228
|
+
const getStatusBarVirtualDom = (statusBarItemsLeft, statusBarItemsRight) => {
|
|
1229
|
+
const dom = [];
|
|
1230
|
+
if (statusBarItemsLeft.length > 0) {
|
|
1231
|
+
dom.push(...getStatusBarItemsVirtualDom(statusBarItemsLeft, StatusBarItemsLeft));
|
|
1232
|
+
}
|
|
1233
|
+
if (statusBarItemsRight.length > 0) {
|
|
1234
|
+
dom.push(...getStatusBarItemsVirtualDom(statusBarItemsRight, StatusBarItemsRight));
|
|
1235
|
+
}
|
|
1236
|
+
return dom;
|
|
1237
|
+
};
|
|
1238
|
+
|
|
1239
|
+
const renderItems = (oldState, newState) => {
|
|
1240
|
+
const {
|
|
1241
|
+
statusBarItemsLeft,
|
|
1242
|
+
statusBarItemsRight,
|
|
1243
|
+
uid
|
|
1244
|
+
} = newState;
|
|
1245
|
+
const dom = getStatusBarVirtualDom(statusBarItemsLeft, statusBarItemsRight);
|
|
1246
|
+
return [SetDom2, uid, dom];
|
|
1247
|
+
};
|
|
1248
|
+
|
|
1249
|
+
const getRenderer = diffType => {
|
|
1250
|
+
switch (diffType) {
|
|
1251
|
+
case RenderItems:
|
|
1252
|
+
return renderItems;
|
|
1253
|
+
default:
|
|
1254
|
+
throw new Error('unknown renderer');
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
|
|
1258
|
+
const applyRender = (oldState, newState, diffResult) => {
|
|
1259
|
+
const commands = [];
|
|
1260
|
+
for (const item of diffResult) {
|
|
1261
|
+
const fn = getRenderer(item);
|
|
1262
|
+
const result = fn(oldState, newState);
|
|
1263
|
+
if (result.length > 0) {
|
|
1264
|
+
commands.push(result);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
return commands;
|
|
1268
|
+
};
|
|
1269
|
+
|
|
1270
|
+
const render2 = (uid, diffResult) => {
|
|
1271
|
+
const {
|
|
1272
|
+
newState,
|
|
1273
|
+
oldState
|
|
1274
|
+
} = get$2(uid);
|
|
1275
|
+
set$1(uid, newState, newState);
|
|
1276
|
+
const commands = applyRender(oldState, newState, diffResult);
|
|
1277
|
+
return commands;
|
|
1278
|
+
};
|
|
1279
|
+
|
|
1280
|
+
const saveState = uid => {
|
|
1281
|
+
number(uid);
|
|
1282
|
+
const value = get$2(uid);
|
|
1283
|
+
const {
|
|
1284
|
+
newState
|
|
1285
|
+
} = value;
|
|
1286
|
+
const {
|
|
1287
|
+
statusBarItemsLeft,
|
|
1288
|
+
statusBarItemsRight
|
|
1289
|
+
} = newState;
|
|
1290
|
+
return {
|
|
1291
|
+
itemsLeft: statusBarItemsLeft,
|
|
1292
|
+
itemsRight: statusBarItemsRight
|
|
1293
|
+
};
|
|
1294
|
+
};
|
|
1295
|
+
|
|
1296
|
+
const commandMap = {
|
|
1297
|
+
'StatusBar.create': create$1,
|
|
1298
|
+
'StatusBar.diff2': diff2,
|
|
1299
|
+
'StatusBar.handleClick': wrapCommand(handleClick),
|
|
1300
|
+
'StatusBar.itemLeftUpdate': wrapCommand(itemLeftUpdate),
|
|
1301
|
+
'StatusBar.itemRightCreate': wrapCommand(itemRightCreate),
|
|
1302
|
+
'StatusBar.itemRightUpdate': wrapCommand(itemRightUpdate),
|
|
1303
|
+
'StatusBar.loadContent': wrapCommand(loadContent),
|
|
1304
|
+
'StatusBar.render2': render2,
|
|
1305
|
+
'StatusBar.saveState': saveState,
|
|
1306
|
+
'StatusBar.terminate': terminate
|
|
1307
|
+
};
|
|
841
1308
|
|
|
842
1309
|
const listen = async () => {
|
|
843
1310
|
await WebWorkerRpcClient.create({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/status-bar-worker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Status Bar Worker",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,5 +9,8 @@
|
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"author": "Lvce Editor",
|
|
11
11
|
"type": "module",
|
|
12
|
-
"main": "dist/statusBarWorkerMain.js"
|
|
12
|
+
"main": "dist/statusBarWorkerMain.js",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@lvce-editor/virtual-dom-worker": "^4.0.0"
|
|
15
|
+
}
|
|
13
16
|
}
|