@lvce-editor/status-bar-worker 1.13.0 → 1.15.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.
@@ -54,49 +54,6 @@ 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
-
100
57
  const isMessagePort = value => {
101
58
  return value && value instanceof MessagePort;
102
59
  };
@@ -225,8 +182,8 @@ const getModuleNotFoundError = stderr => {
225
182
  const messageIndex = lines.findIndex(isModuleNotFoundMessage);
226
183
  const message = lines[messageIndex];
227
184
  return {
228
- message,
229
- code: ERR_MODULE_NOT_FOUND
185
+ code: ERR_MODULE_NOT_FOUND,
186
+ message
230
187
  };
231
188
  };
232
189
  const isModuleNotFoundError = stderr => {
@@ -249,14 +206,14 @@ const isUnhelpfulNativeModuleError = stderr => {
249
206
  const getNativeModuleErrorMessage = stderr => {
250
207
  const message = getMessageCodeBlock(stderr);
251
208
  return {
252
- message: `Incompatible native node module: ${message}`,
253
- code: E_INCOMPATIBLE_NATIVE_MODULE
209
+ code: E_INCOMPATIBLE_NATIVE_MODULE,
210
+ message: `Incompatible native node module: ${message}`
254
211
  };
255
212
  };
256
213
  const getModuleSyntaxError = () => {
257
214
  return {
258
- message: `ES Modules are not supported in electron`,
259
- code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
215
+ code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
216
+ message: `ES Modules are not supported in electron`
260
217
  };
261
218
  };
262
219
  const getHelpfulChildProcessError = (stdout, stderr) => {
@@ -275,8 +232,8 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
275
232
  rest
276
233
  } = getDetails(lines);
277
234
  return {
278
- message: actualMessage,
279
235
  code: '',
236
+ message: actualMessage,
280
237
  stack: rest
281
238
  };
282
239
  };
@@ -286,8 +243,8 @@ class IpcError extends VError {
286
243
  if (stdout || stderr) {
287
244
  // @ts-ignore
288
245
  const {
289
- message,
290
246
  code,
247
+ message,
291
248
  stack
292
249
  } = getHelpfulChildProcessError(stdout, stderr);
293
250
  const cause = new Error(message);
@@ -348,8 +305,8 @@ const wrap$f = global => {
348
305
  };
349
306
  const waitForFirstMessage = async port => {
350
307
  const {
351
- resolve,
352
- promise
308
+ promise,
309
+ resolve
353
310
  } = Promise.withResolvers();
354
311
  port.addEventListener('message', resolve, {
355
312
  once: true
@@ -369,8 +326,8 @@ const listen$6 = async () => {
369
326
  const type = firstMessage.params[0];
370
327
  if (type === 'message-port') {
371
328
  parentIpc.send({
372
- jsonrpc: '2.0',
373
329
  id: firstMessage.id,
330
+ jsonrpc: '2.0',
374
331
  result: null
375
332
  });
376
333
  parentIpc.dispose();
@@ -427,8 +384,8 @@ const removeListener = (emitter, type, callback) => {
427
384
  };
428
385
  const getFirstEvent = (eventEmitter, eventMap) => {
429
386
  const {
430
- resolve,
431
- promise
387
+ promise,
388
+ resolve
432
389
  } = Promise.withResolvers();
433
390
  const listenerMap = Object.create(null);
434
391
  const cleanup = value => {
@@ -440,8 +397,8 @@ const getFirstEvent = (eventEmitter, eventMap) => {
440
397
  for (const [event, type] of Object.entries(eventMap)) {
441
398
  const listener = event => {
442
399
  cleanup({
443
- type,
444
- event
400
+ event,
401
+ type
445
402
  });
446
403
  };
447
404
  addListener(eventEmitter, event, listener);
@@ -451,8 +408,8 @@ const getFirstEvent = (eventEmitter, eventMap) => {
451
408
  };
452
409
  const Message$1 = 3;
453
410
  const create$5$1 = async ({
454
- messagePort,
455
- isMessagePortOpen
411
+ isMessagePortOpen,
412
+ messagePort
456
413
  }) => {
457
414
  if (!isMessagePort(messagePort)) {
458
415
  throw new IpcError('port must be of type MessagePort');
@@ -465,8 +422,8 @@ const create$5$1 = async ({
465
422
  });
466
423
  messagePort.start();
467
424
  const {
468
- type,
469
- event
425
+ event,
426
+ type
470
427
  } = await eventPromise;
471
428
  if (type !== Message$1) {
472
429
  throw new IpcError('Failed to wait for ipc message');
@@ -506,56 +463,14 @@ const IpcParentWithMessagePort$1 = {
506
463
  wrap: wrap$5
507
464
  };
508
465
 
509
- const Two = '2.0';
510
- const create$4$1 = (method, params) => {
511
- return {
512
- jsonrpc: Two,
513
- method,
514
- params
515
- };
516
- };
466
+ const Two$1 = '2.0';
517
467
  const callbacks = Object.create(null);
518
- const set$4 = (id, fn) => {
519
- callbacks[id] = fn;
520
- };
521
468
  const get$3 = id => {
522
469
  return callbacks[id];
523
470
  };
524
- const remove = id => {
471
+ const remove$1 = id => {
525
472
  delete callbacks[id];
526
473
  };
527
- let id$1 = 0;
528
- const create$3$1 = () => {
529
- return ++id$1;
530
- };
531
- const registerPromise = () => {
532
- const id = create$3$1();
533
- const {
534
- resolve,
535
- promise
536
- } = Promise.withResolvers();
537
- set$4(id, resolve);
538
- return {
539
- id,
540
- promise
541
- };
542
- };
543
- const create$2$1 = (method, params) => {
544
- const {
545
- id,
546
- promise
547
- } = registerPromise();
548
- const message = {
549
- jsonrpc: Two,
550
- method,
551
- params,
552
- id
553
- };
554
- return {
555
- message,
556
- promise
557
- };
558
- };
559
474
  class JsonRpcError extends Error {
560
475
  constructor(message) {
561
476
  super(message);
@@ -706,7 +621,7 @@ const resolve = (id, response) => {
706
621
  return;
707
622
  }
708
623
  fn(response);
709
- remove(id);
624
+ remove$1(id);
710
625
  };
711
626
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
712
627
  const getErrorType = prettyError => {
@@ -751,7 +666,7 @@ const getErrorProperty = (error, prettyError) => {
751
666
  };
752
667
  const create$1$1 = (id, error) => {
753
668
  return {
754
- jsonrpc: Two,
669
+ jsonrpc: Two$1,
755
670
  id,
756
671
  error
757
672
  };
@@ -762,20 +677,20 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
762
677
  const errorProperty = getErrorProperty(error, prettyError);
763
678
  return create$1$1(id, errorProperty);
764
679
  };
765
- const create$6 = (message, result) => {
680
+ const create$4 = (message, result) => {
766
681
  return {
767
- jsonrpc: Two,
682
+ jsonrpc: Two$1,
768
683
  id: message.id,
769
684
  result: result ?? null
770
685
  };
771
686
  };
772
687
  const getSuccessResponse = (message, result) => {
773
688
  const resultProperty = result ?? null;
774
- return create$6(message, resultProperty);
689
+ return create$4(message, resultProperty);
775
690
  };
776
691
  const getErrorResponseSimple = (id, error) => {
777
692
  return {
778
- jsonrpc: Two,
693
+ jsonrpc: Two$1,
779
694
  id,
780
695
  error: {
781
696
  code: Custom,
@@ -862,29 +777,6 @@ const handleJsonRpcMessage = async (...args) => {
862
777
  }
863
778
  throw new JsonRpcError('unexpected message');
864
779
  };
865
- const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
866
- const {
867
- message,
868
- promise
869
- } = create$2$1(method, params);
870
- if (useSendAndTransfer && ipc.sendAndTransfer) {
871
- ipc.sendAndTransfer(message);
872
- } else {
873
- ipc.send(message);
874
- }
875
- const responseMessage = await promise;
876
- return unwrapJsonRpcResult(responseMessage);
877
- };
878
- const send = (transport, method, ...params) => {
879
- const message = create$4$1(method, params);
880
- transport.send(message);
881
- };
882
- const invoke$2 = (ipc, method, ...params) => {
883
- return invokeHelper(ipc, method, params, false);
884
- };
885
- const invokeAndTransfer$1 = (ipc, method, ...params) => {
886
- return invokeHelper(ipc, method, params, true);
887
- };
888
780
 
889
781
  class CommandNotFoundError extends Error {
890
782
  constructor(command) {
@@ -907,24 +799,87 @@ const execute = (command, ...args) => {
907
799
  return fn(...args);
908
800
  };
909
801
 
802
+ const Two = '2.0';
803
+ const create$t = (method, params) => {
804
+ return {
805
+ jsonrpc: Two,
806
+ method,
807
+ params
808
+ };
809
+ };
810
+ const create$s = (id, method, params) => {
811
+ const message = {
812
+ id,
813
+ jsonrpc: Two,
814
+ method,
815
+ params
816
+ };
817
+ return message;
818
+ };
819
+ let id$1 = 0;
820
+ const create$r = () => {
821
+ return ++id$1;
822
+ };
823
+
824
+ /* eslint-disable n/no-unsupported-features/es-syntax */
825
+
826
+ const registerPromise = map => {
827
+ const id = create$r();
828
+ const {
829
+ promise,
830
+ resolve
831
+ } = Promise.withResolvers();
832
+ map[id] = resolve;
833
+ return {
834
+ id,
835
+ promise
836
+ };
837
+ };
838
+
839
+ // @ts-ignore
840
+ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
841
+ const {
842
+ id,
843
+ promise
844
+ } = registerPromise(callbacks);
845
+ const message = create$s(id, method, params);
846
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
847
+ ipc.sendAndTransfer(message);
848
+ } else {
849
+ ipc.send(message);
850
+ }
851
+ const responseMessage = await promise;
852
+ return unwrapJsonRpcResult(responseMessage);
853
+ };
910
854
  const createRpc = ipc => {
855
+ const callbacks = Object.create(null);
856
+ ipc._resolve = (id, response) => {
857
+ const fn = callbacks[id];
858
+ if (!fn) {
859
+ console.warn(`callback ${id} may already be disposed`);
860
+ return;
861
+ }
862
+ fn(response);
863
+ delete callbacks[id];
864
+ };
911
865
  const rpc = {
866
+ async dispose() {
867
+ await ipc?.dispose();
868
+ },
869
+ invoke(method, ...params) {
870
+ return invokeHelper(callbacks, ipc, method, params, false);
871
+ },
872
+ invokeAndTransfer(method, ...params) {
873
+ return invokeHelper(callbacks, ipc, method, params, true);
874
+ },
912
875
  // @ts-ignore
913
876
  ipc,
914
877
  /**
915
878
  * @deprecated
916
879
  */
917
880
  send(method, ...params) {
918
- send(ipc, method, ...params);
919
- },
920
- invoke(method, ...params) {
921
- return invoke$2(ipc, method, ...params);
922
- },
923
- invokeAndTransfer(method, ...params) {
924
- return invokeAndTransfer$1(ipc, method, ...params);
925
- },
926
- async dispose() {
927
- await ipc?.dispose();
881
+ const message = create$t(method, params);
882
+ ipc.send(message);
928
883
  }
929
884
  };
930
885
  return rpc;
@@ -941,7 +896,7 @@ const logError = () => {
941
896
  const handleMessage = event => {
942
897
  const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
943
898
  const actualExecute = event?.target?.execute || execute;
944
- return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
899
+ return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
945
900
  };
946
901
  const handleIpc = ipc => {
947
902
  if ('addEventListener' in ipc) {
@@ -961,13 +916,14 @@ const listen$1 = async (module, options) => {
961
916
  };
962
917
  const create$5 = async ({
963
918
  commandMap,
919
+ isMessagePortOpen = true,
964
920
  messagePort
965
921
  }) => {
966
922
  // TODO create a commandMap per rpc instance
967
923
  register(commandMap);
968
924
  const rawIpc = await IpcParentWithMessagePort$1.create({
969
- messagePort,
970
- isMessagePortOpen: true
925
+ isMessagePortOpen,
926
+ messagePort
971
927
  });
972
928
  const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
973
929
  handleIpc(ipc);
@@ -977,6 +933,7 @@ const create$5 = async ({
977
933
  };
978
934
  const create$3 = async ({
979
935
  commandMap,
936
+ isMessagePortOpen,
980
937
  send
981
938
  }) => {
982
939
  const {
@@ -986,6 +943,7 @@ const create$3 = async ({
986
943
  await send(port1);
987
944
  return create$5({
988
945
  commandMap,
946
+ isMessagePortOpen,
989
947
  messagePort: port2
990
948
  });
991
949
  };
@@ -993,7 +951,7 @@ const TransferMessagePortRpcParent = {
993
951
  __proto__: null,
994
952
  create: create$3
995
953
  };
996
- const create$4 = async ({
954
+ const create$2$1 = async ({
997
955
  commandMap
998
956
  }) => {
999
957
  // TODO create a commandMap per rpc instance
@@ -1005,12 +963,36 @@ const create$4 = async ({
1005
963
  };
1006
964
  const WebWorkerRpcClient = {
1007
965
  __proto__: null,
1008
- create: create$4
966
+ create: create$2$1
967
+ };
968
+ const createMockRpc = ({
969
+ commandMap
970
+ }) => {
971
+ const invocations = [];
972
+ const invoke = (method, ...params) => {
973
+ invocations.push([method, ...params]);
974
+ const command = commandMap[method];
975
+ if (!command) {
976
+ throw new Error(`command ${method} not found`);
977
+ }
978
+ return command(...params);
979
+ };
980
+ const mockRpc = {
981
+ invocations,
982
+ invoke,
983
+ invokeAndTransfer: invoke
984
+ };
985
+ return mockRpc;
1009
986
  };
1010
987
 
988
+ const TargetName = 'event.target.name';
989
+
1011
990
  const ExtensionHostWorker = 44;
1012
991
  const RendererWorker = 1;
1013
992
 
993
+ const SetDom2 = 'Viewlet.setDom2';
994
+ const SetPatches = 'Viewlet.setPatches';
995
+
1014
996
  const rpcs = Object.create(null);
1015
997
  const set$3 = (id, rpc) => {
1016
998
  rpcs[id] = rpc;
@@ -1018,7 +1000,11 @@ const set$3 = (id, rpc) => {
1018
1000
  const get$2 = id => {
1019
1001
  return rpcs[id];
1020
1002
  };
1003
+ const remove = id => {
1004
+ delete rpcs[id];
1005
+ };
1021
1006
 
1007
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
1022
1008
  const create$2 = rpcId => {
1023
1009
  return {
1024
1010
  async dispose() {
@@ -1037,6 +1023,18 @@ const create$2 = rpcId => {
1037
1023
  // @ts-ignore
1038
1024
  return rpc.invokeAndTransfer(method, ...params);
1039
1025
  },
1026
+ registerMockRpc(commandMap) {
1027
+ const mockRpc = createMockRpc({
1028
+ commandMap
1029
+ });
1030
+ set$3(rpcId, mockRpc);
1031
+ // @ts-ignore
1032
+ mockRpc[Symbol.dispose] = () => {
1033
+ remove(rpcId);
1034
+ };
1035
+ // @ts-ignore
1036
+ return mockRpc;
1037
+ },
1040
1038
  set(rpc) {
1041
1039
  set$3(rpcId, rpc);
1042
1040
  }
@@ -1072,42 +1070,68 @@ const create$1 = () => {
1072
1070
  const states = Object.create(null);
1073
1071
  const commandMapRef = {};
1074
1072
  return {
1075
- get(uid) {
1076
- return states[uid];
1073
+ clear() {
1074
+ for (const key of Object.keys(states)) {
1075
+ delete states[key];
1076
+ }
1077
1077
  },
1078
- set(uid, oldState, newState) {
1079
- states[uid] = {
1080
- oldState,
1081
- newState
1082
- };
1078
+ diff(uid, modules, numbers) {
1079
+ const {
1080
+ newState,
1081
+ oldState
1082
+ } = states[uid];
1083
+ const diffResult = [];
1084
+ for (let i = 0; i < modules.length; i++) {
1085
+ const fn = modules[i];
1086
+ if (!fn(oldState, newState)) {
1087
+ diffResult.push(numbers[i]);
1088
+ }
1089
+ }
1090
+ return diffResult;
1083
1091
  },
1084
1092
  dispose(uid) {
1085
1093
  delete states[uid];
1086
1094
  },
1095
+ get(uid) {
1096
+ return states[uid];
1097
+ },
1098
+ getCommandIds() {
1099
+ const keys = Object.keys(commandMapRef);
1100
+ const ids = keys.map(toCommandId);
1101
+ return ids;
1102
+ },
1087
1103
  getKeys() {
1088
1104
  return Object.keys(states).map(key => {
1089
1105
  return Number.parseInt(key);
1090
1106
  });
1091
1107
  },
1092
- clear() {
1093
- for (const key of Object.keys(states)) {
1094
- delete states[key];
1095
- }
1108
+ registerCommands(commandMap) {
1109
+ Object.assign(commandMapRef, commandMap);
1110
+ },
1111
+ set(uid, oldState, newState) {
1112
+ states[uid] = {
1113
+ newState,
1114
+ oldState
1115
+ };
1096
1116
  },
1097
1117
  wrapCommand(fn) {
1098
1118
  const wrapped = async (uid, ...args) => {
1099
1119
  const {
1100
- oldState,
1101
- newState
1120
+ newState,
1121
+ oldState
1102
1122
  } = states[uid];
1103
1123
  const newerState = await fn(newState, ...args);
1104
1124
  if (oldState === newerState || newState === newerState) {
1105
1125
  return;
1106
1126
  }
1107
- const latest = states[uid];
1127
+ const latestOld = states[uid];
1128
+ const latestNew = {
1129
+ ...latestOld.newState,
1130
+ ...newerState
1131
+ };
1108
1132
  states[uid] = {
1109
- oldState: latest.oldState,
1110
- newState: newerState
1133
+ newState: latestNew,
1134
+ oldState: latestOld.oldState
1111
1135
  };
1112
1136
  };
1113
1137
  return wrapped;
@@ -1120,28 +1144,6 @@ const create$1 = () => {
1120
1144
  return fn(newState, ...args);
1121
1145
  };
1122
1146
  return wrapped;
1123
- },
1124
- diff(uid, modules, numbers) {
1125
- const {
1126
- oldState,
1127
- newState
1128
- } = states[uid];
1129
- const diffResult = [];
1130
- for (let i = 0; i < modules.length; i++) {
1131
- const fn = modules[i];
1132
- if (!fn(oldState, newState)) {
1133
- diffResult.push(numbers[i]);
1134
- }
1135
- }
1136
- return diffResult;
1137
- },
1138
- getCommandIds() {
1139
- const keys = Object.keys(commandMapRef);
1140
- const ids = keys.map(toCommandId);
1141
- return ids;
1142
- },
1143
- registerCommands(commandMap) {
1144
- Object.assign(commandMapRef, commandMap);
1145
1147
  }
1146
1148
  };
1147
1149
  };
@@ -1154,15 +1156,20 @@ const {
1154
1156
  getCommandIds,
1155
1157
  registerCommands,
1156
1158
  set,
1157
- wrapCommand} = create$1();
1159
+ wrapCommand,
1160
+ wrapGetter
1161
+ } = create$1();
1158
1162
 
1159
1163
  const create = (uid, uri, x, y, width, height, platform, assetDir) => {
1160
1164
  const state = {
1161
1165
  assetDir,
1166
+ errorCount: 0,
1167
+ initial: true,
1162
1168
  platform,
1163
1169
  statusBarItemsLeft: [],
1164
1170
  statusBarItemsRight: [],
1165
- uid
1171
+ uid,
1172
+ warningCount: 0
1166
1173
  };
1167
1174
  set(uid, state, state);
1168
1175
  };
@@ -1172,6 +1179,7 @@ const isEqual = (oldState, newState) => {
1172
1179
  };
1173
1180
 
1174
1181
  const RenderItems = 4;
1182
+ const RenderIncremental = 11;
1175
1183
 
1176
1184
  const modules = [isEqual];
1177
1185
  const numbers = [RenderItems];
@@ -1320,12 +1328,6 @@ const itemRightUpdate = (state, newItem) => {
1320
1328
  };
1321
1329
  };
1322
1330
 
1323
- const ProblemsErrorIcon = 'ProblemsErrorIcon';
1324
- const ProblemsWarningIcon = 'ProblemsWarningIcon';
1325
- const StatusBarItem = 'StatusBarItem';
1326
- const StatusBarItemsLeft = 'StatusBarItemsLeft';
1327
- const StatusBarItemsRight = 'StatusBarItemsRight';
1328
-
1329
1331
  const OnStatusBarItem = 'onStatusBarItem';
1330
1332
 
1331
1333
  const GetStatusBarItems = 'ExtensionHost.getStatusBarItems2';
@@ -1367,6 +1369,59 @@ const getStatusBarItems$1 = (assetDir, platform) => {
1367
1369
  });
1368
1370
  };
1369
1371
 
1372
+ const ProblemsErrorIcon = 'ProblemsErrorIcon';
1373
+ const ProblemsWarningIcon = 'ProblemsWarningIcon';
1374
+ const StatusBarItem = 'StatusBarItem';
1375
+ const StatusBarItemsLeft = 'StatusBarItemsLeft';
1376
+ const StatusBarItemsRight = 'StatusBarItemsRight';
1377
+
1378
+ const getProblemsAriaLabel = (errorCount, warningCount) => {
1379
+ const parts = [];
1380
+ if (errorCount > 0) {
1381
+ parts.push(`${errorCount} ${errorCount === 1 ? 'Problem' : 'Problems'}`);
1382
+ }
1383
+ if (warningCount > 0) {
1384
+ parts.push(`${warningCount} ${warningCount === 1 ? 'Warning' : 'Warnings'}`);
1385
+ }
1386
+ if (parts.length === 0) {
1387
+ return 'No Problems';
1388
+ }
1389
+ return parts.join(', ');
1390
+ };
1391
+ const getBuiltinStatusBarItems = async (errorCount, warningCount) => {
1392
+ const extraItems = [{
1393
+ ariaLabel: 'Notifications',
1394
+ command: '',
1395
+ // TODO should show notifications center
1396
+ elements: [{
1397
+ type: 'text',
1398
+ value: 'Notifications'
1399
+ }],
1400
+ name: Notifications,
1401
+ tooltip: 'Notifications'
1402
+ }, {
1403
+ ariaLabel: getProblemsAriaLabel(errorCount, warningCount),
1404
+ command: '',
1405
+ // TODO should show problems view
1406
+ elements: [{
1407
+ type: 'icon',
1408
+ value: ProblemsErrorIcon
1409
+ }, {
1410
+ type: 'text',
1411
+ value: `${errorCount}`
1412
+ }, {
1413
+ type: 'icon',
1414
+ value: ProblemsWarningIcon
1415
+ }, {
1416
+ type: 'text',
1417
+ value: `${warningCount}`
1418
+ }],
1419
+ name: Problems,
1420
+ tooltip: 'Problems'
1421
+ }];
1422
+ return extraItems;
1423
+ };
1424
+
1370
1425
  const toStatusBarItem = uiStatusBarItem => {
1371
1426
  const elements = [];
1372
1427
  if (uiStatusBarItem.icon) {
@@ -1387,7 +1442,9 @@ const toStatusBarItem = uiStatusBarItem => {
1387
1442
  value: ''
1388
1443
  });
1389
1444
  }
1445
+ const ariaLabel = uiStatusBarItem.text || uiStatusBarItem.tooltip || uiStatusBarItem.name;
1390
1446
  return {
1447
+ ariaLabel,
1391
1448
  command: uiStatusBarItem.command || undefined,
1392
1449
  elements,
1393
1450
  name: uiStatusBarItem.name,
@@ -1395,10 +1452,16 @@ const toStatusBarItem = uiStatusBarItem => {
1395
1452
  };
1396
1453
  };
1397
1454
 
1455
+ const getActualIcon = extensionHostStatusBarItem => {
1456
+ if (extensionHostStatusBarItem.icon === 'branch') {
1457
+ return 'Branch';
1458
+ }
1459
+ return extensionHostStatusBarItem.icon || '';
1460
+ };
1398
1461
  const toUiStatusBarItem = extensionHostStatusBarItem => {
1399
1462
  return {
1400
1463
  command: extensionHostStatusBarItem.command || '',
1401
- icon: extensionHostStatusBarItem.icon || '',
1464
+ icon: getActualIcon(extensionHostStatusBarItem),
1402
1465
  name: extensionHostStatusBarItem.id || extensionHostStatusBarItem.name || '',
1403
1466
  text: extensionHostStatusBarItem.text || '',
1404
1467
  tooltip: extensionHostStatusBarItem.tooltip || ''
@@ -1412,39 +1475,14 @@ const toUiStatusBarItems = statusBarItems => {
1412
1475
  return statusBarItems.map(toUiStatusBarItem);
1413
1476
  };
1414
1477
 
1415
- const getStatusBarItems = async (showItems, assetDir, platform) => {
1478
+ const getStatusBarItems = async (showItems, assetDir, platform, errorCount, warningCount) => {
1416
1479
  if (!showItems) {
1417
1480
  return [];
1418
1481
  }
1419
1482
  await activateByEvent('onSourceControl', assetDir, platform);
1420
1483
  const extensionStatusBarItems = await getStatusBarItems$1(assetDir, platform);
1421
1484
  const uiStatusBarItems = toUiStatusBarItems(extensionStatusBarItems);
1422
- const extraItems = [{
1423
- command: undefined,
1424
- elements: [{
1425
- type: 'text',
1426
- value: 'Notifications'
1427
- }],
1428
- name: Notifications,
1429
- tooltip: ''
1430
- }, {
1431
- command: undefined,
1432
- elements: [{
1433
- type: 'icon',
1434
- value: ProblemsErrorIcon
1435
- }, {
1436
- type: 'text',
1437
- value: '0'
1438
- }, {
1439
- type: 'icon',
1440
- value: ProblemsWarningIcon
1441
- }, {
1442
- type: 'text',
1443
- value: '0'
1444
- }],
1445
- name: Problems,
1446
- tooltip: ''
1447
- }];
1485
+ const extraItems = await getBuiltinStatusBarItems(errorCount, warningCount);
1448
1486
  return [...uiStatusBarItems.map(toStatusBarItem), ...extraItems];
1449
1487
  };
1450
1488
 
@@ -1460,66 +1498,366 @@ const itemsVisible = async () => {
1460
1498
  const loadContent = async state => {
1461
1499
  const {
1462
1500
  assetDir,
1463
- platform
1501
+ errorCount,
1502
+ platform,
1503
+ warningCount
1464
1504
  } = state;
1465
1505
  const statusBarItemsPreference = await itemsVisible();
1466
- const statusBarItems = await getStatusBarItems(statusBarItemsPreference, assetDir, platform);
1506
+ const statusBarItems = await getStatusBarItems(statusBarItemsPreference, assetDir, platform, errorCount, warningCount);
1467
1507
  return {
1468
1508
  ...state,
1509
+ errorCount: 0,
1510
+ initial: false,
1469
1511
  statusBarItemsLeft: [...statusBarItems],
1470
- statusBarItemsRight: []
1512
+ statusBarItemsRight: [],
1513
+ warningCount: 0
1471
1514
  };
1472
1515
  };
1473
1516
 
1474
1517
  const Button$1 = 'button';
1518
+ const Status = 'status';
1519
+
1520
+ const MaskIcon = 'MaskIcon';
1475
1521
 
1476
1522
  const Button = 1;
1477
1523
  const Div = 4;
1524
+ const Span = 8;
1478
1525
  const Text = 12;
1479
1526
 
1480
- const TargetName = 'event.target.name';
1481
-
1482
- const SetDom2 = 'Viewlet.setDom2';
1527
+ const mergeClassNames = (...classNames) => {
1528
+ return classNames.filter(Boolean).join(' ');
1529
+ };
1483
1530
 
1484
1531
  const text = data => {
1485
1532
  return {
1486
- type: Text,
1533
+ childCount: 0,
1487
1534
  text: data,
1488
- childCount: 0
1535
+ type: Text
1536
+ };
1537
+ };
1538
+
1539
+ const SetText = 1;
1540
+ const Replace = 2;
1541
+ const SetAttribute = 3;
1542
+ const RemoveAttribute = 4;
1543
+ const Add = 6;
1544
+ const NavigateChild = 7;
1545
+ const NavigateParent = 8;
1546
+ const RemoveChild = 9;
1547
+ const NavigateSibling = 10;
1548
+
1549
+ const isKey = key => {
1550
+ return key !== 'type' && key !== 'childCount';
1551
+ };
1552
+
1553
+ const getKeys = node => {
1554
+ const keys = Object.keys(node).filter(isKey);
1555
+ return keys;
1556
+ };
1557
+
1558
+ const arrayToTree = nodes => {
1559
+ const result = [];
1560
+ let i = 0;
1561
+ while (i < nodes.length) {
1562
+ const node = nodes[i];
1563
+ const {
1564
+ children,
1565
+ nodesConsumed
1566
+ } = getChildrenWithCount(nodes, i + 1, node.childCount || 0);
1567
+ result.push({
1568
+ node,
1569
+ children
1570
+ });
1571
+ i += 1 + nodesConsumed;
1572
+ }
1573
+ return result;
1574
+ };
1575
+ const getChildrenWithCount = (nodes, startIndex, childCount) => {
1576
+ if (childCount === 0) {
1577
+ return {
1578
+ children: [],
1579
+ nodesConsumed: 0
1580
+ };
1581
+ }
1582
+ const children = [];
1583
+ let i = startIndex;
1584
+ let remaining = childCount;
1585
+ let totalConsumed = 0;
1586
+ while (remaining > 0 && i < nodes.length) {
1587
+ const node = nodes[i];
1588
+ const nodeChildCount = node.childCount || 0;
1589
+ const {
1590
+ children: nodeChildren,
1591
+ nodesConsumed
1592
+ } = getChildrenWithCount(nodes, i + 1, nodeChildCount);
1593
+ children.push({
1594
+ node,
1595
+ children: nodeChildren
1596
+ });
1597
+ const nodeSize = 1 + nodesConsumed;
1598
+ i += nodeSize;
1599
+ totalConsumed += nodeSize;
1600
+ remaining--;
1601
+ }
1602
+ return {
1603
+ children,
1604
+ nodesConsumed: totalConsumed
1489
1605
  };
1490
1606
  };
1491
1607
 
1608
+ const compareNodes = (oldNode, newNode) => {
1609
+ const patches = [];
1610
+ // Check if node type changed - return null to signal incompatible nodes
1611
+ // (caller should handle this with a Replace operation)
1612
+ if (oldNode.type !== newNode.type) {
1613
+ return null;
1614
+ }
1615
+ // Handle text nodes
1616
+ if (oldNode.type === Text && newNode.type === Text) {
1617
+ if (oldNode.text !== newNode.text) {
1618
+ patches.push({
1619
+ type: SetText,
1620
+ value: newNode.text
1621
+ });
1622
+ }
1623
+ return patches;
1624
+ }
1625
+ // Compare attributes
1626
+ const oldKeys = getKeys(oldNode);
1627
+ const newKeys = getKeys(newNode);
1628
+ // Check for attribute changes
1629
+ for (const key of newKeys) {
1630
+ if (oldNode[key] !== newNode[key]) {
1631
+ patches.push({
1632
+ type: SetAttribute,
1633
+ key,
1634
+ value: newNode[key]
1635
+ });
1636
+ }
1637
+ }
1638
+ // Check for removed attributes
1639
+ for (const key of oldKeys) {
1640
+ if (!(key in newNode)) {
1641
+ patches.push({
1642
+ type: RemoveAttribute,
1643
+ key
1644
+ });
1645
+ }
1646
+ }
1647
+ return patches;
1648
+ };
1649
+
1650
+ const treeToArray = node => {
1651
+ const result = [node.node];
1652
+ for (const child of node.children) {
1653
+ result.push(...treeToArray(child));
1654
+ }
1655
+ return result;
1656
+ };
1657
+
1658
+ const diffChildren = (oldChildren, newChildren, patches) => {
1659
+ const maxLength = Math.max(oldChildren.length, newChildren.length);
1660
+ // Track where we are: -1 means at parent, >= 0 means at child index
1661
+ let currentChildIndex = -1;
1662
+ // Collect indices of children to remove (we'll add these patches at the end in reverse order)
1663
+ const indicesToRemove = [];
1664
+ for (let i = 0; i < maxLength; i++) {
1665
+ const oldNode = oldChildren[i];
1666
+ const newNode = newChildren[i];
1667
+ if (!oldNode && !newNode) {
1668
+ continue;
1669
+ }
1670
+ if (!oldNode) {
1671
+ // Add new node - we should be at the parent
1672
+ if (currentChildIndex >= 0) {
1673
+ // Navigate back to parent
1674
+ patches.push({
1675
+ type: NavigateParent
1676
+ });
1677
+ currentChildIndex = -1;
1678
+ }
1679
+ // Flatten the entire subtree so renderInternal can handle it
1680
+ const flatNodes = treeToArray(newNode);
1681
+ patches.push({
1682
+ type: Add,
1683
+ nodes: flatNodes
1684
+ });
1685
+ } else if (newNode) {
1686
+ // Compare nodes to see if we need any patches
1687
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
1688
+ // If nodePatches is null, the node types are incompatible - need to replace
1689
+ if (nodePatches === null) {
1690
+ // Navigate to this child
1691
+ if (currentChildIndex === -1) {
1692
+ patches.push({
1693
+ type: NavigateChild,
1694
+ index: i
1695
+ });
1696
+ currentChildIndex = i;
1697
+ } else if (currentChildIndex !== i) {
1698
+ patches.push({
1699
+ type: NavigateSibling,
1700
+ index: i
1701
+ });
1702
+ currentChildIndex = i;
1703
+ }
1704
+ // Replace the entire subtree
1705
+ const flatNodes = treeToArray(newNode);
1706
+ patches.push({
1707
+ type: Replace,
1708
+ nodes: flatNodes
1709
+ });
1710
+ // After replace, we're at the new element (same position)
1711
+ continue;
1712
+ }
1713
+ // Check if we need to recurse into children
1714
+ const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
1715
+ // Only navigate to this element if we need to do something
1716
+ if (nodePatches.length > 0 || hasChildrenToCompare) {
1717
+ // Navigate to this child if not already there
1718
+ if (currentChildIndex === -1) {
1719
+ patches.push({
1720
+ type: NavigateChild,
1721
+ index: i
1722
+ });
1723
+ currentChildIndex = i;
1724
+ } else if (currentChildIndex !== i) {
1725
+ patches.push({
1726
+ type: NavigateSibling,
1727
+ index: i
1728
+ });
1729
+ currentChildIndex = i;
1730
+ }
1731
+ // Apply node patches (these apply to the current element, not children)
1732
+ if (nodePatches.length > 0) {
1733
+ patches.push(...nodePatches);
1734
+ }
1735
+ // Compare children recursively
1736
+ if (hasChildrenToCompare) {
1737
+ diffChildren(oldNode.children, newNode.children, patches);
1738
+ }
1739
+ }
1740
+ } else {
1741
+ // Remove old node - collect the index for later removal
1742
+ indicesToRemove.push(i);
1743
+ }
1744
+ }
1745
+ // Navigate back to parent if we ended at a child
1746
+ if (currentChildIndex >= 0) {
1747
+ patches.push({
1748
+ type: NavigateParent
1749
+ });
1750
+ currentChildIndex = -1;
1751
+ }
1752
+ // Add remove patches in reverse order (highest index first)
1753
+ // This ensures indices remain valid as we remove
1754
+ for (let j = indicesToRemove.length - 1; j >= 0; j--) {
1755
+ patches.push({
1756
+ type: RemoveChild,
1757
+ index: indicesToRemove[j]
1758
+ });
1759
+ }
1760
+ };
1761
+ const diffTrees = (oldTree, newTree, patches, path) => {
1762
+ // At the root level (path.length === 0), we're already AT the element
1763
+ // So we compare the root node directly, then compare its children
1764
+ if (path.length === 0 && oldTree.length === 1 && newTree.length === 1) {
1765
+ const oldNode = oldTree[0];
1766
+ const newNode = newTree[0];
1767
+ // Compare root nodes
1768
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
1769
+ // If nodePatches is null, the root node types are incompatible - need to replace
1770
+ if (nodePatches === null) {
1771
+ const flatNodes = treeToArray(newNode);
1772
+ patches.push({
1773
+ type: Replace,
1774
+ nodes: flatNodes
1775
+ });
1776
+ return;
1777
+ }
1778
+ if (nodePatches.length > 0) {
1779
+ patches.push(...nodePatches);
1780
+ }
1781
+ // Compare children
1782
+ if (oldNode.children.length > 0 || newNode.children.length > 0) {
1783
+ diffChildren(oldNode.children, newNode.children, patches);
1784
+ }
1785
+ } else {
1786
+ // Non-root level or multiple root elements - use the regular comparison
1787
+ diffChildren(oldTree, newTree, patches);
1788
+ }
1789
+ };
1790
+
1791
+ const removeTrailingNavigationPatches = patches => {
1792
+ // Find the last non-navigation patch
1793
+ let lastNonNavigationIndex = -1;
1794
+ for (let i = patches.length - 1; i >= 0; i--) {
1795
+ const patch = patches[i];
1796
+ if (patch.type !== NavigateChild && patch.type !== NavigateParent && patch.type !== NavigateSibling) {
1797
+ lastNonNavigationIndex = i;
1798
+ break;
1799
+ }
1800
+ }
1801
+ // Return patches up to and including the last non-navigation patch
1802
+ return lastNonNavigationIndex === -1 ? [] : patches.slice(0, lastNonNavigationIndex + 1);
1803
+ };
1804
+
1805
+ const diffTree = (oldNodes, newNodes) => {
1806
+ // Step 1: Convert flat arrays to tree structures
1807
+ const oldTree = arrayToTree(oldNodes);
1808
+ const newTree = arrayToTree(newNodes);
1809
+ // Step 3: Compare the trees
1810
+ const patches = [];
1811
+ diffTrees(oldTree, newTree, patches, []);
1812
+ // Remove trailing navigation patches since they serve no purpose
1813
+ return removeTrailingNavigationPatches(patches);
1814
+ };
1815
+
1492
1816
  const HandleClick = 11;
1493
1817
 
1494
- const getElementVirtualDom = element => {
1818
+ const getTextVirtualDom = element => {
1819
+ return [{
1820
+ childCount: 1,
1821
+ className: 'StatusBarItemLabel',
1822
+ type: Span
1823
+ }, text(element.value)];
1824
+ };
1825
+ const getIconVirtualDom = element => {
1826
+ return [{
1827
+ childCount: 0,
1828
+ className: mergeClassNames(MaskIcon, element.value),
1829
+ type: Div
1830
+ }];
1831
+ };
1832
+ const getStatusBarItemElementVirtualDom = element => {
1495
1833
  if (element.type === 'text') {
1496
- return [text(element.value)];
1834
+ return getTextVirtualDom(element);
1497
1835
  }
1498
1836
  if (element.type === 'icon') {
1499
- return [{
1500
- childCount: 0,
1501
- className: element.value,
1502
- type: Div
1503
- }];
1837
+ return getIconVirtualDom(element);
1504
1838
  }
1505
1839
  return [];
1506
1840
  };
1841
+
1507
1842
  const getStatusBarItemVirtualDom = statusBarItem => {
1508
1843
  const {
1844
+ ariaLabel,
1509
1845
  elements,
1510
1846
  name,
1511
1847
  tooltip
1512
1848
  } = statusBarItem;
1513
- const elementNodes = elements.flatMap(getElementVirtualDom);
1514
- return [{
1515
- childCount: elementNodes.length,
1849
+ const elementNodes = elements.flatMap(getStatusBarItemElementVirtualDom);
1850
+ const buttonNode = {
1851
+ ariaLabel,
1852
+ childCount: elements.length,
1516
1853
  className: StatusBarItem,
1517
1854
  name,
1518
1855
  role: Button$1,
1519
1856
  tabIndex: -1,
1520
1857
  title: tooltip,
1521
1858
  type: Button
1522
- }, ...elementNodes];
1859
+ };
1860
+ return [buttonNode, ...elementNodes];
1523
1861
  };
1524
1862
 
1525
1863
  const getStatusBarItemsVirtualDom = (items, className) => {
@@ -1548,6 +1886,7 @@ const getStatusBarVirtualDom = (statusBarItemsLeft, statusBarItemsRight) => {
1548
1886
  childCount: getChildCount(statusBarItemsLeft.length, statusBarItemsRight.length),
1549
1887
  className: 'StatusBar',
1550
1888
  onClick: HandleClick,
1889
+ role: Status,
1551
1890
  type: Div
1552
1891
  }, ...getStatusBarItemsVirtualDom(statusBarItemsLeft, StatusBarItemsLeft), ...getStatusBarItemsVirtualDom(statusBarItemsRight, StatusBarItemsRight)];
1553
1892
  return dom;
@@ -1563,8 +1902,17 @@ const renderItems = (oldState, newState) => {
1563
1902
  return [SetDom2, uid, dom];
1564
1903
  };
1565
1904
 
1905
+ const renderIcremental = (oldState, newState) => {
1906
+ const oldDom = renderItems(oldState, oldState)[2];
1907
+ const newDom = renderItems(newState, newState)[2];
1908
+ const patches = diffTree(oldDom, newDom);
1909
+ return [SetPatches, newState.uid, patches];
1910
+ };
1911
+
1566
1912
  const getRenderer = diffType => {
1567
1913
  switch (diffType) {
1914
+ case RenderIncremental:
1915
+ return renderIcremental;
1568
1916
  case RenderItems:
1569
1917
  return renderItems;
1570
1918
  default:
@@ -1608,16 +1956,11 @@ const resize = (state, dimensions) => {
1608
1956
  };
1609
1957
  };
1610
1958
 
1611
- const saveState = uid => {
1612
- number(uid);
1613
- const value = get$1(uid);
1614
- const {
1615
- newState
1616
- } = value;
1959
+ const saveState = state => {
1617
1960
  const {
1618
1961
  statusBarItemsLeft,
1619
1962
  statusBarItemsRight
1620
- } = newState;
1963
+ } = state;
1621
1964
  return {
1622
1965
  itemsLeft: statusBarItemsLeft,
1623
1966
  itemsRight: statusBarItemsRight
@@ -1637,7 +1980,7 @@ const commandMap = {
1637
1980
  'StatusBar.render2': render2,
1638
1981
  'StatusBar.renderEventListeners': renderEventListeners,
1639
1982
  'StatusBar.resize': wrapCommand(resize),
1640
- 'StatusBar.saveState': saveState,
1983
+ 'StatusBar.saveState': wrapGetter(saveState),
1641
1984
  'StatusBar.terminate': terminate
1642
1985
  };
1643
1986
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/status-bar-worker",
3
- "version": "1.13.0",
3
+ "version": "1.15.0",
4
4
  "description": "Status Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,6 +11,6 @@
11
11
  "type": "module",
12
12
  "main": "dist/statusBarWorkerMain.js",
13
13
  "dependencies": {
14
- "@lvce-editor/virtual-dom-worker": "^4.0.0"
14
+ "@lvce-editor/virtual-dom-worker": "^6.8.0"
15
15
  }
16
16
  }