@lvce-editor/activity-bar-worker 3.0.0 → 3.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.
@@ -225,8 +225,8 @@ const getModuleNotFoundError = stderr => {
225
225
  const messageIndex = lines.findIndex(isModuleNotFoundMessage);
226
226
  const message = lines[messageIndex];
227
227
  return {
228
- message,
229
- code: ERR_MODULE_NOT_FOUND
228
+ code: ERR_MODULE_NOT_FOUND,
229
+ message
230
230
  };
231
231
  };
232
232
  const isModuleNotFoundError = stderr => {
@@ -249,14 +249,14 @@ const isUnhelpfulNativeModuleError = stderr => {
249
249
  const getNativeModuleErrorMessage = stderr => {
250
250
  const message = getMessageCodeBlock(stderr);
251
251
  return {
252
- message: `Incompatible native node module: ${message}`,
253
- code: E_INCOMPATIBLE_NATIVE_MODULE
252
+ code: E_INCOMPATIBLE_NATIVE_MODULE,
253
+ message: `Incompatible native node module: ${message}`
254
254
  };
255
255
  };
256
256
  const getModuleSyntaxError = () => {
257
257
  return {
258
- message: `ES Modules are not supported in electron`,
259
- code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
258
+ code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
259
+ message: `ES Modules are not supported in electron`
260
260
  };
261
261
  };
262
262
  const getHelpfulChildProcessError = (stdout, stderr) => {
@@ -275,8 +275,8 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
275
275
  rest
276
276
  } = getDetails(lines);
277
277
  return {
278
- message: actualMessage,
279
278
  code: '',
279
+ message: actualMessage,
280
280
  stack: rest
281
281
  };
282
282
  };
@@ -286,8 +286,8 @@ class IpcError extends VError {
286
286
  if (stdout || stderr) {
287
287
  // @ts-ignore
288
288
  const {
289
- message,
290
289
  code,
290
+ message,
291
291
  stack
292
292
  } = getHelpfulChildProcessError(stdout, stderr);
293
293
  const cause = new Error(message);
@@ -348,8 +348,8 @@ const wrap$f = global => {
348
348
  };
349
349
  const waitForFirstMessage = async port => {
350
350
  const {
351
- resolve,
352
- promise
351
+ promise,
352
+ resolve
353
353
  } = Promise.withResolvers();
354
354
  port.addEventListener('message', resolve, {
355
355
  once: true
@@ -369,8 +369,8 @@ const listen$6 = async () => {
369
369
  const type = firstMessage.params[0];
370
370
  if (type === 'message-port') {
371
371
  parentIpc.send({
372
- jsonrpc: '2.0',
373
372
  id: firstMessage.id,
373
+ jsonrpc: '2.0',
374
374
  result: null
375
375
  });
376
376
  parentIpc.dispose();
@@ -412,56 +412,14 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
412
412
  wrap: wrap$e
413
413
  };
414
414
 
415
- const Two = '2.0';
416
- const create$4 = (method, params) => {
417
- return {
418
- jsonrpc: Two,
419
- method,
420
- params
421
- };
422
- };
415
+ const Two$1 = '2.0';
423
416
  const callbacks = Object.create(null);
424
- const set$3 = (id, fn) => {
425
- callbacks[id] = fn;
426
- };
427
417
  const get$2 = id => {
428
418
  return callbacks[id];
429
419
  };
430
- const remove = id => {
420
+ const remove$1 = id => {
431
421
  delete callbacks[id];
432
422
  };
433
- let id = 0;
434
- const create$3$1 = () => {
435
- return ++id;
436
- };
437
- const registerPromise = () => {
438
- const id = create$3$1();
439
- const {
440
- resolve,
441
- promise
442
- } = Promise.withResolvers();
443
- set$3(id, resolve);
444
- return {
445
- id,
446
- promise
447
- };
448
- };
449
- const create$2$1 = (method, params) => {
450
- const {
451
- id,
452
- promise
453
- } = registerPromise();
454
- const message = {
455
- jsonrpc: Two,
456
- method,
457
- params,
458
- id
459
- };
460
- return {
461
- message,
462
- promise
463
- };
464
- };
465
423
  class JsonRpcError extends Error {
466
424
  constructor(message) {
467
425
  super(message);
@@ -612,7 +570,7 @@ const resolve = (id, response) => {
612
570
  return;
613
571
  }
614
572
  fn(response);
615
- remove(id);
573
+ remove$1(id);
616
574
  };
617
575
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
618
576
  const getErrorType = prettyError => {
@@ -655,9 +613,9 @@ const getErrorProperty = (error, prettyError) => {
655
613
  }
656
614
  };
657
615
  };
658
- const create$1$1 = (id, error) => {
616
+ const create$1$2 = (id, error) => {
659
617
  return {
660
- jsonrpc: Two,
618
+ jsonrpc: Two$1,
661
619
  id,
662
620
  error
663
621
  };
@@ -666,22 +624,22 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
666
624
  const prettyError = preparePrettyError(error);
667
625
  logError(error, prettyError);
668
626
  const errorProperty = getErrorProperty(error, prettyError);
669
- return create$1$1(id, errorProperty);
627
+ return create$1$2(id, errorProperty);
670
628
  };
671
- const create$5 = (message, result) => {
629
+ const create$3 = (message, result) => {
672
630
  return {
673
- jsonrpc: Two,
631
+ jsonrpc: Two$1,
674
632
  id: message.id,
675
633
  result: result ?? null
676
634
  };
677
635
  };
678
636
  const getSuccessResponse = (message, result) => {
679
637
  const resultProperty = result ?? null;
680
- return create$5(message, resultProperty);
638
+ return create$3(message, resultProperty);
681
639
  };
682
640
  const getErrorResponseSimple = (id, error) => {
683
641
  return {
684
- jsonrpc: Two,
642
+ jsonrpc: Two$1,
685
643
  id,
686
644
  error: {
687
645
  code: Custom,
@@ -768,29 +726,6 @@ const handleJsonRpcMessage = async (...args) => {
768
726
  }
769
727
  throw new JsonRpcError('unexpected message');
770
728
  };
771
- const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
772
- const {
773
- message,
774
- promise
775
- } = create$2$1(method, params);
776
- if (useSendAndTransfer && ipc.sendAndTransfer) {
777
- ipc.sendAndTransfer(message);
778
- } else {
779
- ipc.send(message);
780
- }
781
- const responseMessage = await promise;
782
- return unwrapJsonRpcResult(responseMessage);
783
- };
784
- const send = (transport, method, ...params) => {
785
- const message = create$4(method, params);
786
- transport.send(message);
787
- };
788
- const invoke$1 = (ipc, method, ...params) => {
789
- return invokeHelper(ipc, method, params, false);
790
- };
791
- const invokeAndTransfer = (ipc, method, ...params) => {
792
- return invokeHelper(ipc, method, params, true);
793
- };
794
729
 
795
730
  class CommandNotFoundError extends Error {
796
731
  constructor(command) {
@@ -813,24 +748,87 @@ const execute = (command, ...args) => {
813
748
  return fn(...args);
814
749
  };
815
750
 
751
+ const Two = '2.0';
752
+ const create$s = (method, params) => {
753
+ return {
754
+ jsonrpc: Two,
755
+ method,
756
+ params
757
+ };
758
+ };
759
+ const create$r = (id, method, params) => {
760
+ const message = {
761
+ id,
762
+ jsonrpc: Two,
763
+ method,
764
+ params
765
+ };
766
+ return message;
767
+ };
768
+ let id = 0;
769
+ const create$q = () => {
770
+ return ++id;
771
+ };
772
+
773
+ /* eslint-disable n/no-unsupported-features/es-syntax */
774
+
775
+ const registerPromise = map => {
776
+ const id = create$q();
777
+ const {
778
+ promise,
779
+ resolve
780
+ } = Promise.withResolvers();
781
+ map[id] = resolve;
782
+ return {
783
+ id,
784
+ promise
785
+ };
786
+ };
787
+
788
+ // @ts-ignore
789
+ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
790
+ const {
791
+ id,
792
+ promise
793
+ } = registerPromise(callbacks);
794
+ const message = create$r(id, method, params);
795
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
796
+ ipc.sendAndTransfer(message);
797
+ } else {
798
+ ipc.send(message);
799
+ }
800
+ const responseMessage = await promise;
801
+ return unwrapJsonRpcResult(responseMessage);
802
+ };
816
803
  const createRpc = ipc => {
804
+ const callbacks = Object.create(null);
805
+ ipc._resolve = (id, response) => {
806
+ const fn = callbacks[id];
807
+ if (!fn) {
808
+ console.warn(`callback ${id} may already be disposed`);
809
+ return;
810
+ }
811
+ fn(response);
812
+ delete callbacks[id];
813
+ };
817
814
  const rpc = {
815
+ async dispose() {
816
+ await ipc?.dispose();
817
+ },
818
+ invoke(method, ...params) {
819
+ return invokeHelper(callbacks, ipc, method, params, false);
820
+ },
821
+ invokeAndTransfer(method, ...params) {
822
+ return invokeHelper(callbacks, ipc, method, params, true);
823
+ },
818
824
  // @ts-ignore
819
825
  ipc,
820
826
  /**
821
827
  * @deprecated
822
828
  */
823
829
  send(method, ...params) {
824
- send(ipc, method, ...params);
825
- },
826
- invoke(method, ...params) {
827
- return invoke$1(ipc, method, ...params);
828
- },
829
- invokeAndTransfer(method, ...params) {
830
- return invokeAndTransfer(ipc, method, ...params);
831
- },
832
- async dispose() {
833
- await ipc?.dispose();
830
+ const message = create$s(method, params);
831
+ ipc.send(message);
834
832
  }
835
833
  };
836
834
  return rpc;
@@ -847,7 +845,7 @@ const logError = () => {
847
845
  const handleMessage = event => {
848
846
  const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
849
847
  const actualExecute = event?.target?.execute || execute;
850
- return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
848
+ return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
851
849
  };
852
850
  const handleIpc = ipc => {
853
851
  if ('addEventListener' in ipc) {
@@ -865,7 +863,7 @@ const listen$1 = async (module, options) => {
865
863
  const ipc = module.wrap(rawIpc);
866
864
  return ipc;
867
865
  };
868
- const create$3 = async ({
866
+ const create$1$1 = async ({
869
867
  commandMap
870
868
  }) => {
871
869
  // TODO create a commandMap per rpc instance
@@ -877,7 +875,26 @@ const create$3 = async ({
877
875
  };
878
876
  const WebWorkerRpcClient = {
879
877
  __proto__: null,
880
- create: create$3
878
+ create: create$1$1
879
+ };
880
+ const createMockRpc = ({
881
+ commandMap
882
+ }) => {
883
+ const invocations = [];
884
+ const invoke = (method, ...params) => {
885
+ invocations.push([method, ...params]);
886
+ const command = commandMap[method];
887
+ if (!command) {
888
+ throw new Error(`command ${method} not found`);
889
+ }
890
+ return command(...params);
891
+ };
892
+ const mockRpc = {
893
+ invocations,
894
+ invoke,
895
+ invokeAndTransfer: invoke
896
+ };
897
+ return mockRpc;
881
898
  };
882
899
 
883
900
  const Button$2 = 'button';
@@ -916,9 +933,13 @@ const Web = 1;
916
933
 
917
934
  const RendererWorker = 1;
918
935
 
936
+ const Left = 1;
937
+ const Right = 2;
938
+
919
939
  const SetCss = 'Viewlet.setCss';
920
940
  const SetDom2 = 'Viewlet.setDom2';
921
941
  const SetFocusContext = 'Viewlet.setFocusContext';
942
+ const SetPatches = 'Viewlet.setPatches';
922
943
 
923
944
  const FocusActivityBar = 5;
924
945
  const FocusExplorer = 13;
@@ -930,9 +951,17 @@ const set$2 = (id, rpc) => {
930
951
  const get$1 = id => {
931
952
  return rpcs[id];
932
953
  };
954
+ const remove = id => {
955
+ delete rpcs[id];
956
+ };
933
957
 
958
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
934
959
  const create$2 = rpcId => {
935
960
  return {
961
+ async dispose() {
962
+ const rpc = get$1(rpcId);
963
+ await rpc.dispose();
964
+ },
936
965
  // @ts-ignore
937
966
  invoke(method, ...params) {
938
967
  const rpc = get$1(rpcId);
@@ -945,19 +974,28 @@ const create$2 = rpcId => {
945
974
  // @ts-ignore
946
975
  return rpc.invokeAndTransfer(method, ...params);
947
976
  },
977
+ registerMockRpc(commandMap) {
978
+ const mockRpc = createMockRpc({
979
+ commandMap
980
+ });
981
+ set$2(rpcId, mockRpc);
982
+ // @ts-ignore
983
+ mockRpc[Symbol.dispose] = () => {
984
+ remove(rpcId);
985
+ };
986
+ // @ts-ignore
987
+ return mockRpc;
988
+ },
948
989
  set(rpc) {
949
990
  set$2(rpcId, rpc);
950
- },
951
- async dispose() {
952
- const rpc = get$1(rpcId);
953
- await rpc.dispose();
954
991
  }
955
992
  };
956
993
  };
957
994
 
958
995
  const {
959
996
  invoke,
960
- set: set$1} = create$2(RendererWorker);
997
+ set: set$1
998
+ } = create$2(RendererWorker);
961
999
  const showContextMenu2 = async (uid, menuId, x, y, args) => {
962
1000
  number(uid);
963
1001
  number(menuId);
@@ -975,42 +1013,68 @@ const create$1 = () => {
975
1013
  const states = Object.create(null);
976
1014
  const commandMapRef = {};
977
1015
  return {
978
- get(uid) {
979
- return states[uid];
1016
+ clear() {
1017
+ for (const key of Object.keys(states)) {
1018
+ delete states[key];
1019
+ }
980
1020
  },
981
- set(uid, oldState, newState) {
982
- states[uid] = {
983
- oldState,
984
- newState
985
- };
1021
+ diff(uid, modules, numbers) {
1022
+ const {
1023
+ newState,
1024
+ oldState
1025
+ } = states[uid];
1026
+ const diffResult = [];
1027
+ for (let i = 0; i < modules.length; i++) {
1028
+ const fn = modules[i];
1029
+ if (!fn(oldState, newState)) {
1030
+ diffResult.push(numbers[i]);
1031
+ }
1032
+ }
1033
+ return diffResult;
986
1034
  },
987
1035
  dispose(uid) {
988
1036
  delete states[uid];
989
1037
  },
1038
+ get(uid) {
1039
+ return states[uid];
1040
+ },
1041
+ getCommandIds() {
1042
+ const keys = Object.keys(commandMapRef);
1043
+ const ids = keys.map(toCommandId);
1044
+ return ids;
1045
+ },
990
1046
  getKeys() {
991
1047
  return Object.keys(states).map(key => {
992
1048
  return Number.parseInt(key);
993
1049
  });
994
1050
  },
995
- clear() {
996
- for (const key of Object.keys(states)) {
997
- delete states[key];
998
- }
1051
+ registerCommands(commandMap) {
1052
+ Object.assign(commandMapRef, commandMap);
1053
+ },
1054
+ set(uid, oldState, newState) {
1055
+ states[uid] = {
1056
+ newState,
1057
+ oldState
1058
+ };
999
1059
  },
1000
1060
  wrapCommand(fn) {
1001
1061
  const wrapped = async (uid, ...args) => {
1002
1062
  const {
1003
- oldState,
1004
- newState
1063
+ newState,
1064
+ oldState
1005
1065
  } = states[uid];
1006
1066
  const newerState = await fn(newState, ...args);
1007
1067
  if (oldState === newerState || newState === newerState) {
1008
1068
  return;
1009
1069
  }
1010
- const latest = states[uid];
1070
+ const latestOld = states[uid];
1071
+ const latestNew = {
1072
+ ...latestOld.newState,
1073
+ ...newerState
1074
+ };
1011
1075
  states[uid] = {
1012
- oldState: latest.oldState,
1013
- newState: newerState
1076
+ newState: latestNew,
1077
+ oldState: latestOld.oldState
1014
1078
  };
1015
1079
  };
1016
1080
  return wrapped;
@@ -1023,28 +1087,6 @@ const create$1 = () => {
1023
1087
  return fn(newState, ...args);
1024
1088
  };
1025
1089
  return wrapped;
1026
- },
1027
- diff(uid, modules, numbers) {
1028
- const {
1029
- oldState,
1030
- newState
1031
- } = states[uid];
1032
- const diffResult = [];
1033
- for (let i = 0; i < modules.length; i++) {
1034
- const fn = modules[i];
1035
- if (!fn(oldState, newState)) {
1036
- diffResult.push(numbers[i]);
1037
- }
1038
- }
1039
- return diffResult;
1040
- },
1041
- getCommandIds() {
1042
- const keys = Object.keys(commandMapRef);
1043
- const ids = keys.map(toCommandId);
1044
- return ids;
1045
- },
1046
- registerCommands(commandMap) {
1047
- Object.assign(commandMapRef, commandMap);
1048
1090
  }
1049
1091
  };
1050
1092
  };
@@ -1065,6 +1107,7 @@ const {
1065
1107
  // TODO parentUid might ot be needed
1066
1108
  const create = (id, uri, x, y, width, height, args, parentUid, platform = 0) => {
1067
1109
  const state = {
1110
+ accountEnabled: false,
1068
1111
  activityBarItems: [],
1069
1112
  currentViewletId: '',
1070
1113
  filteredItems: [],
@@ -1072,6 +1115,7 @@ const create = (id, uri, x, y, width, height, args, parentUid, platform = 0) =>
1072
1115
  focused: false,
1073
1116
  focusedIndex: -1,
1074
1117
  height,
1118
+ initial: true,
1075
1119
  itemHeight: 48,
1076
1120
  numberOfVisibleItems: 0,
1077
1121
  platform,
@@ -1106,9 +1150,10 @@ const RenderItems = 4;
1106
1150
  const RenderFocus = 6;
1107
1151
  const RenderFocusContext = 7;
1108
1152
  const RenderCss = 11;
1153
+ const RenderIncremental = 12;
1109
1154
 
1110
1155
  const modules = [isEqual, isEqual$1, isEqual$1, isEqual$2];
1111
- const numbers = [RenderItems, RenderFocus, RenderFocusContext, RenderCss];
1156
+ const numbers = [RenderIncremental, RenderFocus, RenderFocusContext, RenderCss];
1112
1157
 
1113
1158
  const diff2 = uid => {
1114
1159
  return diff(uid, modules, numbers);
@@ -1195,13 +1240,19 @@ const getKeyBindings = () => {
1195
1240
  }];
1196
1241
  };
1197
1242
 
1198
- const Tab = 1;
1199
- const Button = 1 << 1;
1200
- const Progress = 1 << 2;
1201
- const Enabled = 1 << 3;
1202
- const Selected = 1 << 4;
1203
- const Focused = 1 << 5;
1204
- const MarginTop = 1 << 6;
1243
+ const getMenuEntriesAccount = state => {
1244
+ return [{
1245
+ command: 'Account.signIn',
1246
+ flags: None,
1247
+ id: 'signIn',
1248
+ label: 'Sign In'
1249
+ }, {
1250
+ command: 'Account.signOut',
1251
+ flags: None,
1252
+ id: 'signOut',
1253
+ label: 'Sign Out'
1254
+ }];
1255
+ };
1205
1256
 
1206
1257
  const emptyObject = {};
1207
1258
  const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
@@ -1215,6 +1266,7 @@ const i18nString = (key, placeholders = emptyObject) => {
1215
1266
  return key.replaceAll(RE_PLACEHOLDER, replacer);
1216
1267
  };
1217
1268
 
1269
+ const Account$1 = 'Account';
1218
1270
  const Explorer$1 = 'Explorer';
1219
1271
  const Search$2 = 'Search';
1220
1272
  const SourceControl$2 = 'Source Control';
@@ -1231,6 +1283,9 @@ const ColorTheme = 'Color Theme';
1231
1283
  const CommandPalette = 'Command Palette';
1232
1284
  const KeyboardShortcuts = 'Keyboard Shortcuts';
1233
1285
 
1286
+ const account = () => {
1287
+ return i18nString(Account$1);
1288
+ };
1234
1289
  const explorer = () => {
1235
1290
  return i18nString(Explorer$1);
1236
1291
  };
@@ -1277,9 +1332,6 @@ const colorTheme = () => {
1277
1332
  return i18nString(ColorTheme);
1278
1333
  };
1279
1334
 
1280
- const Left = 1;
1281
- const Right = 2;
1282
-
1283
1335
  const menuEntryMoveSideBar = sideBarLocation => {
1284
1336
  switch (sideBarLocation) {
1285
1337
  case Left:
@@ -1308,16 +1360,25 @@ const menuEntrySeparator = {
1308
1360
  label: ''
1309
1361
  };
1310
1362
 
1363
+ const Tab = 1;
1364
+ const Button = 1 << 1;
1365
+ const Progress = 1 << 2;
1366
+ const Enabled = 1 << 3;
1367
+ const Selected = 1 << 4;
1368
+ const Focused = 1 << 5;
1369
+ const MarginTop = 1 << 6;
1370
+
1311
1371
  const toContextMenuItem$1 = activityBarItem => {
1312
1372
  const isEnabled = activityBarItem.flags & Enabled;
1313
1373
  return {
1314
- command: '',
1374
+ args: [activityBarItem.id],
1375
+ command: 'ActivityBar.toggleActivityBarItem',
1315
1376
  flags: isEnabled ? Checked : Unchecked,
1316
- id: '',
1317
- // TODO
1377
+ id: `toggle-${activityBarItem.id}`,
1318
1378
  label: activityBarItem.id
1319
1379
  };
1320
1380
  };
1381
+
1321
1382
  const getMenuEntriesActivityBar = state => {
1322
1383
  const {
1323
1384
  activityBarItems,
@@ -1401,11 +1462,15 @@ const getMenuEntriesSettings = state => {
1401
1462
  return items;
1402
1463
  };
1403
1464
 
1465
+ // Use a unique number for the Account menu ID
1466
+ const ACCOUNT_MENU_ID$1 = 1000;
1404
1467
  const getMenuEntries = (state, options) => {
1405
1468
  const {
1406
1469
  menuId
1407
1470
  } = options;
1408
1471
  switch (menuId) {
1472
+ case ACCOUNT_MENU_ID$1:
1473
+ return getMenuEntriesAccount();
1409
1474
  case ActivityBar$3:
1410
1475
  return getMenuEntriesActivityBar(state);
1411
1476
  case ActivityBarAdditionalViews:
@@ -1489,6 +1554,18 @@ const show2 = async (uid, menuId, x, y, args) => {
1489
1554
  await showContextMenu2(uid, menuId, x, y, args);
1490
1555
  };
1491
1556
 
1557
+ // Use a unique number for the Account menu ID
1558
+ const ACCOUNT_MENU_ID = 1000;
1559
+ const handleClickAccount = async (state, eventX, eventY, viewletId) => {
1560
+ const {
1561
+ uid
1562
+ } = state;
1563
+ await show2(uid, ACCOUNT_MENU_ID, eventX, eventY, {
1564
+ menuId: ACCOUNT_MENU_ID
1565
+ });
1566
+ return state;
1567
+ };
1568
+
1492
1569
  const handleClickAdditionalViews = async (state, eventX, eventY, viewletId) => {
1493
1570
  const {
1494
1571
  uid
@@ -1552,6 +1629,8 @@ const handleClickIndex = async (state, button, index, x, y) => {
1552
1629
  const item = filteredItems[index];
1553
1630
  const viewletId = item.id;
1554
1631
  switch (viewletId) {
1632
+ case 'Account':
1633
+ return handleClickAccount(state, x, y);
1555
1634
  case 'Additional Views':
1556
1635
  return handleClickAdditionalViews(state, x, y, viewletId);
1557
1636
  case 'Settings':
@@ -1582,6 +1661,7 @@ const handleContextMenu = async (state, button, eventX, eventY) => {
1582
1661
  return state;
1583
1662
  };
1584
1663
 
1664
+ const Account = 'Account';
1585
1665
  const DebugAlt2 = 'DebugAlt2';
1586
1666
  const Extensions$1 = 'Extensions';
1587
1667
  const Files = 'Files';
@@ -1630,6 +1710,78 @@ const handleResize = (state, dimensions) => {
1630
1710
  };
1631
1711
  };
1632
1712
 
1713
+ const Explorer = 'Explorer';
1714
+ const Extensions = 'Extensions';
1715
+ const RunAndDebug = 'Run And Debug';
1716
+ const Search = 'Search';
1717
+ const SourceControl = 'Source Control';
1718
+
1719
+ const getActivityBarItems = state => {
1720
+ const {
1721
+ accountEnabled
1722
+ } = state;
1723
+ const items = [
1724
+ // Top
1725
+ {
1726
+ flags: Tab | Enabled,
1727
+ icon: Files,
1728
+ id: Explorer,
1729
+ keyShortcuts: 'Control+Shift+E',
1730
+ title: explorer()
1731
+ }, {
1732
+ flags: Tab | Enabled,
1733
+ icon: Search$1,
1734
+ id: Search,
1735
+ keyShortcuts: 'Control+Shift+F',
1736
+ title: search()
1737
+ }, {
1738
+ flags: Tab | Enabled,
1739
+ icon: SourceControl$1,
1740
+ id: SourceControl,
1741
+ keyShortcuts: 'Control+Shift+G',
1742
+ title: sourceControl()
1743
+ }, {
1744
+ flags: Tab | Enabled,
1745
+ icon: DebugAlt2,
1746
+ id: RunAndDebug,
1747
+ keyShortcuts: 'Control+Shift+D',
1748
+ title: runAndDebug()
1749
+ }, {
1750
+ flags: Tab | Enabled,
1751
+ icon: Extensions$1,
1752
+ id: Extensions,
1753
+ keyShortcuts: 'Control+Shift+X',
1754
+ title: extensions()
1755
+ }
1756
+ // Bottom
1757
+ ];
1758
+ if (accountEnabled) {
1759
+ items.push({
1760
+ flags: Button | Enabled | MarginTop,
1761
+ icon: Account,
1762
+ id: 'Account',
1763
+ keyShortcuts: '',
1764
+ title: account()
1765
+ });
1766
+ }
1767
+ items.push({
1768
+ flags: Button | Enabled | MarginTop,
1769
+ icon: SettingsGear,
1770
+ id: 'Settings',
1771
+ keyShortcuts: '',
1772
+ title: settings()
1773
+ });
1774
+ return items;
1775
+ };
1776
+
1777
+ const getSideBarPosition = async () => {
1778
+ try {
1779
+ return await invoke('Layout.getSideBarPosition');
1780
+ } catch {
1781
+ return Left;
1782
+ }
1783
+ };
1784
+
1633
1785
  const setFlag = (item, flag, enabled) => {
1634
1786
  return {
1635
1787
  ...item,
@@ -1637,6 +1789,32 @@ const setFlag = (item, flag, enabled) => {
1637
1789
  };
1638
1790
  };
1639
1791
 
1792
+ const markSelected = (items, selectedIndex) => {
1793
+ return items.map((item, index) => {
1794
+ const isSelected = index === selectedIndex;
1795
+ return setFlag(item, Selected, isSelected);
1796
+ });
1797
+ };
1798
+
1799
+ const handleSettingsChanged = async state => {
1800
+ const {
1801
+ height,
1802
+ itemHeight,
1803
+ selectedIndex
1804
+ } = state;
1805
+ const items = getActivityBarItems(state);
1806
+ const itemsWithSelected = markSelected(items, selectedIndex);
1807
+ const filteredItems = getFilteredActivityBarItems(itemsWithSelected, height, itemHeight);
1808
+ const newItems = await updateItemsWithBadgeCount(filteredItems);
1809
+ const sidebarLocation = await getSideBarPosition();
1810
+ return {
1811
+ ...state,
1812
+ activityBarItems: itemsWithSelected,
1813
+ filteredItems: newItems,
1814
+ sideBarLocation: sidebarLocation
1815
+ };
1816
+ };
1817
+
1640
1818
  const handleSideBarHidden = state => {
1641
1819
  const itemsCleared = state.activityBarItems.map(item => {
1642
1820
  const withoutSelected = setFlag(item, Selected, false);
@@ -1660,13 +1838,6 @@ const findIndex = (activityBarItems, id) => {
1660
1838
  return -1;
1661
1839
  };
1662
1840
 
1663
- const markSelected = (items, selectedIndex) => {
1664
- return items.map((item, index) => {
1665
- const isSelected = index === selectedIndex;
1666
- return setFlag(item, Selected, isSelected);
1667
- });
1668
- };
1669
-
1670
1841
  const handleSideBarViewletChange = (state, id, ...args) => {
1671
1842
  const {
1672
1843
  activityBarItems,
@@ -1724,56 +1895,6 @@ const handleUpdateStateChange = async (state, config) => {
1724
1895
  };
1725
1896
  };
1726
1897
 
1727
- const Explorer = 'Explorer';
1728
- const Extensions = 'Extensions';
1729
- const RunAndDebug = 'Run And Debug';
1730
- const Search = 'Search';
1731
- const SourceControl = 'Source Control';
1732
-
1733
- const getActivityBarItems = () => {
1734
- return [
1735
- // Top
1736
- {
1737
- flags: Tab | Enabled,
1738
- icon: Files,
1739
- id: Explorer,
1740
- keyShortcuts: 'Control+Shift+E',
1741
- title: explorer()
1742
- }, {
1743
- flags: Tab | Enabled,
1744
- icon: Search$1,
1745
- id: Search,
1746
- keyShortcuts: 'Control+Shift+F',
1747
- title: search()
1748
- }, {
1749
- flags: Tab | Enabled,
1750
- icon: SourceControl$1,
1751
- id: SourceControl,
1752
- keyShortcuts: 'Control+Shift+G',
1753
- title: sourceControl()
1754
- }, {
1755
- flags: Tab | Enabled,
1756
- icon: DebugAlt2,
1757
- id: RunAndDebug,
1758
- keyShortcuts: 'Control+Shift+D',
1759
- title: runAndDebug()
1760
- }, {
1761
- flags: Tab | Enabled,
1762
- icon: Extensions$1,
1763
- id: Extensions,
1764
- keyShortcuts: 'Control+Shift+X',
1765
- title: extensions()
1766
- },
1767
- // Bottom
1768
- {
1769
- flags: Button | Enabled | MarginTop,
1770
- icon: SettingsGear,
1771
- id: 'Settings',
1772
- keyShortcuts: '',
1773
- title: settings()
1774
- }];
1775
- };
1776
-
1777
1898
  const getActiveView = async () => {
1778
1899
  try {
1779
1900
  const activeView = await invoke('Layout.getActiveSideBarView');
@@ -1782,24 +1903,27 @@ const getActiveView = async () => {
1782
1903
  return Explorer;
1783
1904
  }
1784
1905
  };
1785
- const loadContent = async (state, savedState) => {
1906
+
1907
+ const loadContent = async state => {
1786
1908
  const {
1787
1909
  height,
1788
1910
  itemHeight
1789
1911
  } = state;
1790
- const items = getActivityBarItems();
1912
+ const items = getActivityBarItems(state);
1791
1913
  const activeView = await getActiveView();
1792
1914
  const index = items.findIndex(item => item.id === activeView);
1793
1915
  const itemsWithSelected = markSelected(items, index);
1794
1916
  const filteredItems = getFilteredActivityBarItems(itemsWithSelected, height, itemHeight);
1795
1917
  const newItems = await updateItemsWithBadgeCount(filteredItems);
1918
+ const sidebarLocation = await getSideBarPosition();
1796
1919
  return {
1797
1920
  ...state,
1798
1921
  activityBarItems: itemsWithSelected,
1799
1922
  currentViewletId: Explorer,
1800
1923
  filteredItems: newItems,
1924
+ initial: false,
1801
1925
  selectedIndex: index,
1802
- sideBarLocation: Left,
1926
+ sideBarLocation: sidebarLocation,
1803
1927
  sideBarVisible: true
1804
1928
  };
1805
1929
  };
@@ -1833,12 +1957,289 @@ const mergeClassNames = (...classNames) => {
1833
1957
 
1834
1958
  const text = data => {
1835
1959
  return {
1836
- type: Text,
1960
+ childCount: 0,
1837
1961
  text: data,
1838
- childCount: 0
1962
+ type: Text
1963
+ };
1964
+ };
1965
+
1966
+ const SetText = 1;
1967
+ const Replace = 2;
1968
+ const SetAttribute = 3;
1969
+ const RemoveAttribute = 4;
1970
+ const Add = 6;
1971
+ const NavigateChild = 7;
1972
+ const NavigateParent = 8;
1973
+ const RemoveChild = 9;
1974
+ const NavigateSibling = 10;
1975
+
1976
+ const isKey = key => {
1977
+ return key !== 'type' && key !== 'childCount';
1978
+ };
1979
+
1980
+ const getKeys = node => {
1981
+ const keys = Object.keys(node).filter(isKey);
1982
+ return keys;
1983
+ };
1984
+
1985
+ const arrayToTree = nodes => {
1986
+ const result = [];
1987
+ let i = 0;
1988
+ while (i < nodes.length) {
1989
+ const node = nodes[i];
1990
+ const {
1991
+ children,
1992
+ nodesConsumed
1993
+ } = getChildrenWithCount(nodes, i + 1, node.childCount || 0);
1994
+ result.push({
1995
+ node,
1996
+ children
1997
+ });
1998
+ i += 1 + nodesConsumed;
1999
+ }
2000
+ return result;
2001
+ };
2002
+ const getChildrenWithCount = (nodes, startIndex, childCount) => {
2003
+ if (childCount === 0) {
2004
+ return {
2005
+ children: [],
2006
+ nodesConsumed: 0
2007
+ };
2008
+ }
2009
+ const children = [];
2010
+ let i = startIndex;
2011
+ let remaining = childCount;
2012
+ let totalConsumed = 0;
2013
+ while (remaining > 0 && i < nodes.length) {
2014
+ const node = nodes[i];
2015
+ const nodeChildCount = node.childCount || 0;
2016
+ const {
2017
+ children: nodeChildren,
2018
+ nodesConsumed
2019
+ } = getChildrenWithCount(nodes, i + 1, nodeChildCount);
2020
+ children.push({
2021
+ node,
2022
+ children: nodeChildren
2023
+ });
2024
+ const nodeSize = 1 + nodesConsumed;
2025
+ i += nodeSize;
2026
+ totalConsumed += nodeSize;
2027
+ remaining--;
2028
+ }
2029
+ return {
2030
+ children,
2031
+ nodesConsumed: totalConsumed
1839
2032
  };
1840
2033
  };
1841
2034
 
2035
+ const compareNodes = (oldNode, newNode) => {
2036
+ const patches = [];
2037
+ // Check if node type changed - return null to signal incompatible nodes
2038
+ // (caller should handle this with a Replace operation)
2039
+ if (oldNode.type !== newNode.type) {
2040
+ return null;
2041
+ }
2042
+ // Handle text nodes
2043
+ if (oldNode.type === Text && newNode.type === Text) {
2044
+ if (oldNode.text !== newNode.text) {
2045
+ patches.push({
2046
+ type: SetText,
2047
+ value: newNode.text
2048
+ });
2049
+ }
2050
+ return patches;
2051
+ }
2052
+ // Compare attributes
2053
+ const oldKeys = getKeys(oldNode);
2054
+ const newKeys = getKeys(newNode);
2055
+ // Check for attribute changes
2056
+ for (const key of newKeys) {
2057
+ if (oldNode[key] !== newNode[key]) {
2058
+ patches.push({
2059
+ type: SetAttribute,
2060
+ key,
2061
+ value: newNode[key]
2062
+ });
2063
+ }
2064
+ }
2065
+ // Check for removed attributes
2066
+ for (const key of oldKeys) {
2067
+ if (!(key in newNode)) {
2068
+ patches.push({
2069
+ type: RemoveAttribute,
2070
+ key
2071
+ });
2072
+ }
2073
+ }
2074
+ return patches;
2075
+ };
2076
+
2077
+ const treeToArray = node => {
2078
+ const result = [node.node];
2079
+ for (const child of node.children) {
2080
+ result.push(...treeToArray(child));
2081
+ }
2082
+ return result;
2083
+ };
2084
+
2085
+ const diffChildren = (oldChildren, newChildren, patches) => {
2086
+ const maxLength = Math.max(oldChildren.length, newChildren.length);
2087
+ // Track where we are: -1 means at parent, >= 0 means at child index
2088
+ let currentChildIndex = -1;
2089
+ // Collect indices of children to remove (we'll add these patches at the end in reverse order)
2090
+ const indicesToRemove = [];
2091
+ for (let i = 0; i < maxLength; i++) {
2092
+ const oldNode = oldChildren[i];
2093
+ const newNode = newChildren[i];
2094
+ if (!oldNode && !newNode) {
2095
+ continue;
2096
+ }
2097
+ if (!oldNode) {
2098
+ // Add new node - we should be at the parent
2099
+ if (currentChildIndex >= 0) {
2100
+ // Navigate back to parent
2101
+ patches.push({
2102
+ type: NavigateParent
2103
+ });
2104
+ currentChildIndex = -1;
2105
+ }
2106
+ // Flatten the entire subtree so renderInternal can handle it
2107
+ const flatNodes = treeToArray(newNode);
2108
+ patches.push({
2109
+ type: Add,
2110
+ nodes: flatNodes
2111
+ });
2112
+ } else if (newNode) {
2113
+ // Compare nodes to see if we need any patches
2114
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2115
+ // If nodePatches is null, the node types are incompatible - need to replace
2116
+ if (nodePatches === null) {
2117
+ // Navigate to this child
2118
+ if (currentChildIndex === -1) {
2119
+ patches.push({
2120
+ type: NavigateChild,
2121
+ index: i
2122
+ });
2123
+ currentChildIndex = i;
2124
+ } else if (currentChildIndex !== i) {
2125
+ patches.push({
2126
+ type: NavigateSibling,
2127
+ index: i
2128
+ });
2129
+ currentChildIndex = i;
2130
+ }
2131
+ // Replace the entire subtree
2132
+ const flatNodes = treeToArray(newNode);
2133
+ patches.push({
2134
+ type: Replace,
2135
+ nodes: flatNodes
2136
+ });
2137
+ // After replace, we're at the new element (same position)
2138
+ continue;
2139
+ }
2140
+ // Check if we need to recurse into children
2141
+ const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
2142
+ // Only navigate to this element if we need to do something
2143
+ if (nodePatches.length > 0 || hasChildrenToCompare) {
2144
+ // Navigate to this child if not already there
2145
+ if (currentChildIndex === -1) {
2146
+ patches.push({
2147
+ type: NavigateChild,
2148
+ index: i
2149
+ });
2150
+ currentChildIndex = i;
2151
+ } else if (currentChildIndex !== i) {
2152
+ patches.push({
2153
+ type: NavigateSibling,
2154
+ index: i
2155
+ });
2156
+ currentChildIndex = i;
2157
+ }
2158
+ // Apply node patches (these apply to the current element, not children)
2159
+ if (nodePatches.length > 0) {
2160
+ patches.push(...nodePatches);
2161
+ }
2162
+ // Compare children recursively
2163
+ if (hasChildrenToCompare) {
2164
+ diffChildren(oldNode.children, newNode.children, patches);
2165
+ }
2166
+ }
2167
+ } else {
2168
+ // Remove old node - collect the index for later removal
2169
+ indicesToRemove.push(i);
2170
+ }
2171
+ }
2172
+ // Navigate back to parent if we ended at a child
2173
+ if (currentChildIndex >= 0) {
2174
+ patches.push({
2175
+ type: NavigateParent
2176
+ });
2177
+ currentChildIndex = -1;
2178
+ }
2179
+ // Add remove patches in reverse order (highest index first)
2180
+ // This ensures indices remain valid as we remove
2181
+ for (let j = indicesToRemove.length - 1; j >= 0; j--) {
2182
+ patches.push({
2183
+ type: RemoveChild,
2184
+ index: indicesToRemove[j]
2185
+ });
2186
+ }
2187
+ };
2188
+ const diffTrees = (oldTree, newTree, patches, path) => {
2189
+ // At the root level (path.length === 0), we're already AT the element
2190
+ // So we compare the root node directly, then compare its children
2191
+ if (path.length === 0 && oldTree.length === 1 && newTree.length === 1) {
2192
+ const oldNode = oldTree[0];
2193
+ const newNode = newTree[0];
2194
+ // Compare root nodes
2195
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2196
+ // If nodePatches is null, the root node types are incompatible - need to replace
2197
+ if (nodePatches === null) {
2198
+ const flatNodes = treeToArray(newNode);
2199
+ patches.push({
2200
+ type: Replace,
2201
+ nodes: flatNodes
2202
+ });
2203
+ return;
2204
+ }
2205
+ if (nodePatches.length > 0) {
2206
+ patches.push(...nodePatches);
2207
+ }
2208
+ // Compare children
2209
+ if (oldNode.children.length > 0 || newNode.children.length > 0) {
2210
+ diffChildren(oldNode.children, newNode.children, patches);
2211
+ }
2212
+ } else {
2213
+ // Non-root level or multiple root elements - use the regular comparison
2214
+ diffChildren(oldTree, newTree, patches);
2215
+ }
2216
+ };
2217
+
2218
+ const removeTrailingNavigationPatches = patches => {
2219
+ // Find the last non-navigation patch
2220
+ let lastNonNavigationIndex = -1;
2221
+ for (let i = patches.length - 1; i >= 0; i--) {
2222
+ const patch = patches[i];
2223
+ if (patch.type !== NavigateChild && patch.type !== NavigateParent && patch.type !== NavigateSibling) {
2224
+ lastNonNavigationIndex = i;
2225
+ break;
2226
+ }
2227
+ }
2228
+ // Return patches up to and including the last non-navigation patch
2229
+ return lastNonNavigationIndex === -1 ? [] : patches.slice(0, lastNonNavigationIndex + 1);
2230
+ };
2231
+
2232
+ const diffTree = (oldNodes, newNodes) => {
2233
+ // Step 1: Convert flat arrays to tree structures
2234
+ const oldTree = arrayToTree(oldNodes);
2235
+ const newTree = arrayToTree(newNodes);
2236
+ // Step 3: Compare the trees
2237
+ const patches = [];
2238
+ diffTrees(oldTree, newTree, patches, []);
2239
+ // Remove trailing navigation patches since they serve no purpose
2240
+ return removeTrailingNavigationPatches(patches);
2241
+ };
2242
+
1842
2243
  const Vertical = 'vertical';
1843
2244
 
1844
2245
  const ActivityBar$1 = 'ActivityBar';
@@ -2047,12 +2448,23 @@ const getActivityBarVirtualDom = visibleItems => {
2047
2448
  const renderItems = (oldState, newState) => {
2048
2449
  const {
2049
2450
  filteredItems,
2451
+ initial,
2050
2452
  uid
2051
2453
  } = newState;
2454
+ if (initial) {
2455
+ return [SetDom2, uid, []];
2456
+ }
2052
2457
  const dom = getActivityBarVirtualDom(filteredItems);
2053
2458
  return [SetDom2, uid, dom];
2054
2459
  };
2055
2460
 
2461
+ const renderIncremental = (oldState, newState) => {
2462
+ const oldDom = renderItems(oldState, oldState)[2];
2463
+ const newDom = renderItems(newState, newState)[2];
2464
+ const patches = diffTree(oldDom, newDom);
2465
+ return [SetPatches, newState.uid, patches];
2466
+ };
2467
+
2056
2468
  const getRenderer = diffType => {
2057
2469
  switch (diffType) {
2058
2470
  case RenderCss:
@@ -2061,6 +2473,8 @@ const getRenderer = diffType => {
2061
2473
  return renderFocusContext;
2062
2474
  case RenderFocusContext:
2063
2475
  return renderFocusContext;
2476
+ case RenderIncremental:
2477
+ return renderIncremental;
2064
2478
  case RenderItems:
2065
2479
  return renderItems;
2066
2480
  default:
@@ -2111,25 +2525,50 @@ const renderEventListeners = () => {
2111
2525
 
2112
2526
  const saveState = state => {
2113
2527
  const {
2114
- currentViewletId,
2115
- uid
2528
+ currentViewletId
2116
2529
  } = state;
2117
2530
  return {
2118
- currentViewletId,
2119
- uid
2531
+ currentViewletId
2120
2532
  };
2121
2533
  };
2122
2534
 
2123
- const isEnabled = activityBarItem => {
2124
- return activityBarItem.enabled;
2535
+ const setAccountEnabled = (state, enabled) => {
2536
+ const {
2537
+ height,
2538
+ itemHeight,
2539
+ selectedIndex
2540
+ } = state;
2541
+ const newState = {
2542
+ ...state,
2543
+ accountEnabled: enabled
2544
+ };
2545
+ const newActivityBarItems = getActivityBarItems(newState);
2546
+ const markedItems = markSelected(newActivityBarItems, selectedIndex);
2547
+ const filteredItems = getFilteredActivityBarItems(markedItems, height, itemHeight);
2548
+ return {
2549
+ ...newState,
2550
+ activityBarItems: markedItems,
2551
+ filteredItems: filteredItems
2552
+ };
2125
2553
  };
2126
- const toggleActivityBarItem = async (state, item) => {
2127
- const activityBarItem = state.activityBarItems.find(activityBarItem => activityBarItem.id === item.label);
2128
- // @ts-ignore
2129
- activityBarItem.enabled = !activityBarItem.enabled;
2554
+
2555
+ const toggleActivityBarItem = async (state, itemId) => {
2556
+ const {
2557
+ activityBarItems
2558
+ } = state;
2559
+ const updatedItems = activityBarItems.map(item => {
2560
+ if (item.id === itemId) {
2561
+ const isCurrentlyEnabled = item.flags & Enabled;
2562
+ return {
2563
+ ...item,
2564
+ flags: isCurrentlyEnabled ? item.flags & -9 : item.flags | Enabled
2565
+ };
2566
+ }
2567
+ return item;
2568
+ });
2130
2569
  return {
2131
2570
  ...state,
2132
- activityBarItems: state.activityBarItems.filter(isEnabled)
2571
+ activityBarItems: updatedItems
2133
2572
  };
2134
2573
  };
2135
2574
 
@@ -2151,6 +2590,7 @@ const commandMap = {
2151
2590
  'ActivityBar.handleClick': wrapCommand(handleClick),
2152
2591
  'ActivityBar.handleClickIndex': wrapCommand(handleClickIndex),
2153
2592
  'ActivityBar.handleContextMenu': wrapCommand(handleContextMenu),
2593
+ 'ActivityBar.handleSettingsChanged': wrapCommand(handleSettingsChanged),
2154
2594
  'ActivityBar.handleSideBarHidden': wrapCommand(handleSideBarHidden),
2155
2595
  'ActivityBar.handleSideBarViewletChange': wrapCommand(handleSideBarViewletChange),
2156
2596
  'ActivityBar.handleUpdateStateChange': wrapCommand(handleUpdateStateChange),
@@ -2159,6 +2599,7 @@ const commandMap = {
2159
2599
  'ActivityBar.renderEventListeners': renderEventListeners,
2160
2600
  'ActivityBar.resize': wrapCommand(handleResize),
2161
2601
  'ActivityBar.saveState': wrapGetter(saveState),
2602
+ 'ActivityBar.setAccountEnabled': wrapCommand(setAccountEnabled),
2162
2603
  'ActivityBar.terminate': terminate,
2163
2604
  'ActivityBar.toggleActivityBarItem': wrapCommand(toggleActivityBarItem)
2164
2605
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/activity-bar-worker",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",