@lvce-editor/status-bar-worker 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -463,6 +463,27 @@ const IpcParentWithMessagePort$1 = {
463
463
  wrap: wrap$5
464
464
  };
465
465
 
466
+ class CommandNotFoundError extends Error {
467
+ constructor(command) {
468
+ super(`Command not found ${command}`);
469
+ this.name = 'CommandNotFoundError';
470
+ }
471
+ }
472
+ const commands = Object.create(null);
473
+ const register = commandMap => {
474
+ Object.assign(commands, commandMap);
475
+ };
476
+ const getCommand = key => {
477
+ return commands[key];
478
+ };
479
+ const execute = (command, ...args) => {
480
+ const fn = getCommand(command);
481
+ if (!fn) {
482
+ throw new CommandNotFoundError(command);
483
+ }
484
+ return fn(...args);
485
+ };
486
+
466
487
  const Two$1 = '2.0';
467
488
  const callbacks = Object.create(null);
468
489
  const get$3 = id => {
@@ -487,12 +508,12 @@ const getErrorConstructor = (message, type) => {
487
508
  switch (type) {
488
509
  case DomException:
489
510
  return DOMException;
490
- case TypeError$1:
491
- return TypeError;
492
- case SyntaxError$1:
493
- return SyntaxError;
494
511
  case ReferenceError$1:
495
512
  return ReferenceError;
513
+ case SyntaxError$1:
514
+ return SyntaxError;
515
+ case TypeError$1:
516
+ return TypeError;
496
517
  default:
497
518
  return Error;
498
519
  }
@@ -648,27 +669,27 @@ const getErrorProperty = (error, prettyError) => {
648
669
  if (error && error.code === E_COMMAND_NOT_FOUND) {
649
670
  return {
650
671
  code: MethodNotFound,
651
- message: error.message,
652
- data: error.stack
672
+ data: error.stack,
673
+ message: error.message
653
674
  };
654
675
  }
655
676
  return {
656
677
  code: Custom,
657
- message: prettyError.message,
658
678
  data: {
659
- stack: getStack(prettyError),
660
- codeFrame: prettyError.codeFrame,
661
- type: getErrorType(prettyError),
662
679
  code: prettyError.code,
663
- name: prettyError.name
664
- }
680
+ codeFrame: prettyError.codeFrame,
681
+ name: prettyError.name,
682
+ stack: getStack(prettyError),
683
+ type: getErrorType(prettyError)
684
+ },
685
+ message: prettyError.message
665
686
  };
666
687
  };
667
688
  const create$1$1 = (id, error) => {
668
689
  return {
669
- jsonrpc: Two$1,
690
+ error,
670
691
  id,
671
- error
692
+ jsonrpc: Two$1
672
693
  };
673
694
  };
674
695
  const getErrorResponse = (id, error, preparePrettyError, logError) => {
@@ -677,27 +698,27 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
677
698
  const errorProperty = getErrorProperty(error, prettyError);
678
699
  return create$1$1(id, errorProperty);
679
700
  };
680
- const create$4 = (message, result) => {
701
+ const create$9 = (message, result) => {
681
702
  return {
682
- jsonrpc: Two$1,
683
703
  id: message.id,
704
+ jsonrpc: Two$1,
684
705
  result: result ?? null
685
706
  };
686
707
  };
687
708
  const getSuccessResponse = (message, result) => {
688
709
  const resultProperty = result ?? null;
689
- return create$4(message, resultProperty);
710
+ return create$9(message, resultProperty);
690
711
  };
691
712
  const getErrorResponseSimple = (id, error) => {
692
713
  return {
693
- jsonrpc: Two$1,
694
- id,
695
714
  error: {
696
715
  code: Custom,
716
+ data: error,
697
717
  // @ts-ignore
698
- message: error.message,
699
- data: error
700
- }
718
+ message: error.message
719
+ },
720
+ id,
721
+ jsonrpc: Two$1
701
722
  };
702
723
  };
703
724
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
@@ -727,35 +748,35 @@ const normalizeParams = args => {
727
748
  if (args.length === 1) {
728
749
  const options = args[0];
729
750
  return {
751
+ execute: options.execute,
730
752
  ipc: options.ipc,
753
+ logError: options.logError || defaultLogError,
731
754
  message: options.message,
732
- execute: options.execute,
733
- resolve: options.resolve || defaultResolve,
734
755
  preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
735
- logError: options.logError || defaultLogError,
736
- requiresSocket: options.requiresSocket || defaultRequiresSocket
756
+ requiresSocket: options.requiresSocket || defaultRequiresSocket,
757
+ resolve: options.resolve || defaultResolve
737
758
  };
738
759
  }
739
760
  return {
761
+ execute: args[2],
740
762
  ipc: args[0],
763
+ logError: args[5],
741
764
  message: args[1],
742
- execute: args[2],
743
- resolve: args[3],
744
765
  preparePrettyError: args[4],
745
- logError: args[5],
746
- requiresSocket: args[6]
766
+ requiresSocket: args[6],
767
+ resolve: args[3]
747
768
  };
748
769
  };
749
770
  const handleJsonRpcMessage = async (...args) => {
750
771
  const options = normalizeParams(args);
751
772
  const {
752
- message,
753
- ipc,
754
773
  execute,
755
- resolve,
756
- preparePrettyError,
774
+ ipc,
757
775
  logError,
758
- requiresSocket
776
+ message,
777
+ preparePrettyError,
778
+ requiresSocket,
779
+ resolve
759
780
  } = options;
760
781
  if ('id' in message) {
761
782
  if ('method' in message) {
@@ -778,36 +799,17 @@ const handleJsonRpcMessage = async (...args) => {
778
799
  throw new JsonRpcError('unexpected message');
779
800
  };
780
801
 
781
- class CommandNotFoundError extends Error {
782
- constructor(command) {
783
- super(`Command not found ${command}`);
784
- this.name = 'CommandNotFoundError';
785
- }
786
- }
787
- const commands = Object.create(null);
788
- const register = commandMap => {
789
- Object.assign(commands, commandMap);
790
- };
791
- const getCommand = key => {
792
- return commands[key];
793
- };
794
- const execute = (command, ...args) => {
795
- const fn = getCommand(command);
796
- if (!fn) {
797
- throw new CommandNotFoundError(command);
798
- }
799
- return fn(...args);
800
- };
801
-
802
802
  const Two = '2.0';
803
- const create$t = (method, params) => {
803
+
804
+ const create$8 = (method, params) => {
804
805
  return {
805
806
  jsonrpc: Two,
806
807
  method,
807
808
  params
808
809
  };
809
810
  };
810
- const create$s = (id, method, params) => {
811
+
812
+ const create$7 = (id, method, params) => {
811
813
  const message = {
812
814
  id,
813
815
  jsonrpc: Two,
@@ -816,15 +818,14 @@ const create$s = (id, method, params) => {
816
818
  };
817
819
  return message;
818
820
  };
821
+
819
822
  let id$1 = 0;
820
- const create$r = () => {
823
+ const create$6 = () => {
821
824
  return ++id$1;
822
825
  };
823
826
 
824
- /* eslint-disable n/no-unsupported-features/es-syntax */
825
-
826
827
  const registerPromise = map => {
827
- const id = create$r();
828
+ const id = create$6();
828
829
  const {
829
830
  promise,
830
831
  resolve
@@ -836,13 +837,12 @@ const registerPromise = map => {
836
837
  };
837
838
  };
838
839
 
839
- // @ts-ignore
840
840
  const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
841
841
  const {
842
842
  id,
843
843
  promise
844
844
  } = registerPromise(callbacks);
845
- const message = create$s(id, method, params);
845
+ const message = create$7(id, method, params);
846
846
  if (useSendAndTransfer && ipc.sendAndTransfer) {
847
847
  ipc.sendAndTransfer(message);
848
848
  } else {
@@ -878,12 +878,13 @@ const createRpc = ipc => {
878
878
  * @deprecated
879
879
  */
880
880
  send(method, ...params) {
881
- const message = create$t(method, params);
881
+ const message = create$8(method, params);
882
882
  ipc.send(message);
883
883
  }
884
884
  };
885
885
  return rpc;
886
886
  };
887
+
887
888
  const requiresSocket = () => {
888
889
  return false;
889
890
  };
@@ -898,6 +899,7 @@ const handleMessage = event => {
898
899
  const actualExecute = event?.target?.execute || execute;
899
900
  return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
900
901
  };
902
+
901
903
  const handleIpc = ipc => {
902
904
  if ('addEventListener' in ipc) {
903
905
  ipc.addEventListener('message', handleMessage);
@@ -906,6 +908,7 @@ const handleIpc = ipc => {
906
908
  ipc.on('message', handleMessage);
907
909
  }
908
910
  };
911
+
909
912
  const listen$1 = async (module, options) => {
910
913
  const rawIpc = await module.listen(options);
911
914
  if (module.signal) {
@@ -914,6 +917,7 @@ const listen$1 = async (module, options) => {
914
917
  const ipc = module.wrap(rawIpc);
915
918
  return ipc;
916
919
  };
920
+
917
921
  const create$5 = async ({
918
922
  commandMap,
919
923
  isMessagePortOpen = true,
@@ -931,7 +935,8 @@ const create$5 = async ({
931
935
  messagePort.start();
932
936
  return rpc;
933
937
  };
934
- const create$3 = async ({
938
+
939
+ const create$4 = async ({
935
940
  commandMap,
936
941
  isMessagePortOpen,
937
942
  send
@@ -947,11 +952,8 @@ const create$3 = async ({
947
952
  messagePort: port2
948
953
  });
949
954
  };
950
- const TransferMessagePortRpcParent = {
951
- __proto__: null,
952
- create: create$3
953
- };
954
- const create$2$1 = async ({
955
+
956
+ const create$3 = async ({
955
957
  commandMap
956
958
  }) => {
957
959
  // TODO create a commandMap per rpc instance
@@ -961,10 +963,7 @@ const create$2$1 = async ({
961
963
  const rpc = createRpc(ipc);
962
964
  return rpc;
963
965
  };
964
- const WebWorkerRpcClient = {
965
- __proto__: null,
966
- create: create$2$1
967
- };
966
+
968
967
  const createMockRpc = ({
969
968
  commandMap
970
969
  }) => {
@@ -985,14 +984,6 @@ const createMockRpc = ({
985
984
  return mockRpc;
986
985
  };
987
986
 
988
- const TargetName = 'event.target.name';
989
-
990
- const ExtensionHostWorker = 44;
991
- const RendererWorker = 1;
992
-
993
- const SetDom2 = 'Viewlet.setDom2';
994
- const SetPatches = 'Viewlet.setPatches';
995
-
996
987
  const rpcs = Object.create(null);
997
988
  const set$3 = (id, rpc) => {
998
989
  rpcs[id] = rpc;
@@ -1041,6 +1032,25 @@ const create$2 = rpcId => {
1041
1032
  };
1042
1033
  };
1043
1034
 
1035
+ const Button$1 = 'button';
1036
+ const Status = 'status';
1037
+
1038
+ const MaskIcon = 'MaskIcon';
1039
+
1040
+ const Button = 1;
1041
+ const Div = 4;
1042
+ const Span = 8;
1043
+ const Text = 12;
1044
+ const Reference = 100;
1045
+
1046
+ const TargetName = 'event.target.name';
1047
+
1048
+ const ExtensionHostWorker = 44;
1049
+ const RendererWorker = 1;
1050
+
1051
+ const SetDom2 = 'Viewlet.setDom2';
1052
+ const SetPatches = 'Viewlet.setPatches';
1053
+
1044
1054
  const {
1045
1055
  invoke: invoke$1,
1046
1056
  set: set$2
@@ -1102,7 +1112,7 @@ const create$1 = () => {
1102
1112
  },
1103
1113
  getKeys() {
1104
1114
  return Object.keys(states).map(key => {
1105
- return Number.parseInt(key);
1115
+ return Number.parseFloat(key);
1106
1116
  });
1107
1117
  },
1108
1118
  registerCommands(commandMap) {
@@ -1144,6 +1154,37 @@ const create$1 = () => {
1144
1154
  return fn(newState, ...args);
1145
1155
  };
1146
1156
  return wrapped;
1157
+ },
1158
+ wrapLoadContent(fn) {
1159
+ const wrapped = async (uid, ...args) => {
1160
+ const {
1161
+ newState,
1162
+ oldState
1163
+ } = states[uid];
1164
+ const result = await fn(newState, ...args);
1165
+ const {
1166
+ error,
1167
+ state
1168
+ } = result;
1169
+ if (oldState === state || newState === state) {
1170
+ return {
1171
+ error
1172
+ };
1173
+ }
1174
+ const latestOld = states[uid];
1175
+ const latestNew = {
1176
+ ...latestOld.newState,
1177
+ ...state
1178
+ };
1179
+ states[uid] = {
1180
+ newState: latestNew,
1181
+ oldState: latestOld.oldState
1182
+ };
1183
+ return {
1184
+ error
1185
+ };
1186
+ };
1187
+ return wrapped;
1147
1188
  }
1148
1189
  };
1149
1190
  };
@@ -1265,6 +1306,11 @@ const handleContextMenu = async state => {
1265
1306
  return state;
1266
1307
  };
1267
1308
 
1309
+ const handleExtensionsChanged = async state => {
1310
+ // TODO requery status bar items
1311
+ return state;
1312
+ };
1313
+
1268
1314
  const id = 7201;
1269
1315
  const sendMessagePortToExtensionHostWorker = async port => {
1270
1316
  await sendMessagePortToExtensionHostWorker$1(port, id);
@@ -1272,7 +1318,7 @@ const sendMessagePortToExtensionHostWorker = async port => {
1272
1318
 
1273
1319
  const createExtensionHostRpc = async () => {
1274
1320
  try {
1275
- const rpc = await TransferMessagePortRpcParent.create({
1321
+ const rpc = await create$4({
1276
1322
  commandMap: {},
1277
1323
  send: sendMessagePortToExtensionHostWorker
1278
1324
  });
@@ -1373,6 +1419,23 @@ const getStatusBarItems$1 = (assetDir, platform) => {
1373
1419
  });
1374
1420
  };
1375
1421
 
1422
+ const getNotificationsStatusBarItem = enabled => {
1423
+ if (!enabled) {
1424
+ return [];
1425
+ }
1426
+ return [{
1427
+ ariaLabel: 'Notifications',
1428
+ command: '',
1429
+ // TODO should show notifications center
1430
+ elements: [{
1431
+ type: 'text',
1432
+ value: 'Notifications'
1433
+ }],
1434
+ name: Notifications,
1435
+ tooltip: 'Notifications'
1436
+ }];
1437
+ };
1438
+
1376
1439
  const ProblemsErrorIcon = 'ProblemsErrorIcon';
1377
1440
  const ProblemsWarningIcon = 'ProblemsWarningIcon';
1378
1441
  const StatusBarItem = 'StatusBarItem';
@@ -1392,18 +1455,12 @@ const getProblemsAriaLabel = (errorCount, warningCount) => {
1392
1455
  }
1393
1456
  return parts.join(', ');
1394
1457
  };
1395
- const getBuiltinStatusBarItems = async (errorCount, warningCount) => {
1396
- const extraItems = [{
1397
- ariaLabel: 'Notifications',
1398
- command: '',
1399
- // TODO should show notifications center
1400
- elements: [{
1401
- type: 'text',
1402
- value: 'Notifications'
1403
- }],
1404
- name: Notifications,
1405
- tooltip: 'Notifications'
1406
- }, {
1458
+
1459
+ const getProblemsStatusBarItem = (errorCount, warningCount, enabled) => {
1460
+ if (!enabled) {
1461
+ return [];
1462
+ }
1463
+ return [{
1407
1464
  ariaLabel: getProblemsAriaLabel(errorCount, warningCount),
1408
1465
  command: '',
1409
1466
  // TODO should show problems view
@@ -1423,7 +1480,13 @@ const getBuiltinStatusBarItems = async (errorCount, warningCount) => {
1423
1480
  name: Problems,
1424
1481
  tooltip: 'Problems'
1425
1482
  }];
1426
- return extraItems;
1483
+ };
1484
+
1485
+ const getBuiltinStatusBarItems = async (errorCount, warningCount, {
1486
+ notificationsEnabled = true,
1487
+ problemsEnabled = true
1488
+ } = {}) => {
1489
+ return [...getNotificationsStatusBarItem(notificationsEnabled), ...getProblemsStatusBarItem(errorCount, warningCount, problemsEnabled)];
1427
1490
  };
1428
1491
 
1429
1492
  const toStatusBarItem = uiStatusBarItem => {
@@ -1479,14 +1542,26 @@ const toUiStatusBarItems = statusBarItems => {
1479
1542
  return statusBarItems.map(toUiStatusBarItem);
1480
1543
  };
1481
1544
 
1482
- const getStatusBarItems = async (showItems, assetDir, platform, errorCount, warningCount) => {
1545
+ const getStatusBarItems = async ({
1546
+ assetDir,
1547
+ builtinNotificationsEnabled = true,
1548
+ builtinProblemsEnabled = true,
1549
+ errorCount,
1550
+ platform,
1551
+ showItems,
1552
+ warningCount
1553
+ }) => {
1483
1554
  if (!showItems) {
1484
1555
  return [];
1485
1556
  }
1557
+ await activateByEvent('onStatusBarItem', assetDir, platform);
1486
1558
  await activateByEvent('onSourceControl', assetDir, platform);
1487
1559
  const extensionStatusBarItems = await getStatusBarItems$1(assetDir, platform);
1488
1560
  const uiStatusBarItems = toUiStatusBarItems(extensionStatusBarItems);
1489
- const extraItems = await getBuiltinStatusBarItems(errorCount, warningCount);
1561
+ const extraItems = await getBuiltinStatusBarItems(errorCount, warningCount, {
1562
+ notificationsEnabled: builtinNotificationsEnabled,
1563
+ problemsEnabled: builtinProblemsEnabled
1564
+ });
1490
1565
  return [...uiStatusBarItems.map(toStatusBarItem), ...extraItems];
1491
1566
  };
1492
1567
 
@@ -1494,9 +1569,17 @@ const get = async key => {
1494
1569
  return getPreference(key);
1495
1570
  };
1496
1571
 
1497
- const itemsVisible = async () => {
1498
- const statusBarItemsPreference = (await get('statusBar.itemsVisible')) ?? true;
1499
- return statusBarItemsPreference;
1572
+ const getBooleanPreference = async key => {
1573
+ const value = await get(key);
1574
+ return value ?? true;
1575
+ };
1576
+ const loadStatusBarPreferences = async () => {
1577
+ const [itemsVisible, builtinNotificationsEnabled, builtinProblemsEnabled] = await Promise.all([getBooleanPreference('statusBar.itemsVisible'), getBooleanPreference('statusBar.builtinNotificationsEnabled'), getBooleanPreference('statusBar.builtinProblemsEnabled')]);
1578
+ return {
1579
+ builtinNotificationsEnabled,
1580
+ builtinProblemsEnabled,
1581
+ itemsVisible
1582
+ };
1500
1583
  };
1501
1584
 
1502
1585
  const loadContent = async state => {
@@ -1506,8 +1589,16 @@ const loadContent = async state => {
1506
1589
  platform,
1507
1590
  warningCount
1508
1591
  } = state;
1509
- const statusBarItemsPreference = await itemsVisible();
1510
- const statusBarItems = await getStatusBarItems(statusBarItemsPreference, assetDir, platform, errorCount, warningCount);
1592
+ const statusBarPreferences = await loadStatusBarPreferences();
1593
+ const statusBarItems = await getStatusBarItems({
1594
+ assetDir,
1595
+ builtinNotificationsEnabled: statusBarPreferences.builtinNotificationsEnabled,
1596
+ builtinProblemsEnabled: statusBarPreferences.builtinProblemsEnabled,
1597
+ errorCount,
1598
+ platform,
1599
+ showItems: statusBarPreferences.itemsVisible,
1600
+ warningCount
1601
+ });
1511
1602
  return {
1512
1603
  ...state,
1513
1604
  errorCount: 0,
@@ -1518,16 +1609,6 @@ const loadContent = async state => {
1518
1609
  };
1519
1610
  };
1520
1611
 
1521
- const Button$1 = 'button';
1522
- const Status = 'status';
1523
-
1524
- const MaskIcon = 'MaskIcon';
1525
-
1526
- const Button = 1;
1527
- const Div = 4;
1528
- const Span = 8;
1529
- const Text = 12;
1530
-
1531
1612
  const mergeClassNames = (...classNames) => {
1532
1613
  return classNames.filter(Boolean).join(' ');
1533
1614
  };
@@ -1549,6 +1630,7 @@ const NavigateChild = 7;
1549
1630
  const NavigateParent = 8;
1550
1631
  const RemoveChild = 9;
1551
1632
  const NavigateSibling = 10;
1633
+ const SetReferenceNodeUid = 11;
1552
1634
 
1553
1635
  const isKey = key => {
1554
1636
  return key !== 'type' && key !== 'childCount';
@@ -1616,6 +1698,16 @@ const compareNodes = (oldNode, newNode) => {
1616
1698
  if (oldNode.type !== newNode.type) {
1617
1699
  return null;
1618
1700
  }
1701
+ // Handle reference nodes - special handling for uid changes
1702
+ if (oldNode.type === Reference) {
1703
+ if (oldNode.uid !== newNode.uid) {
1704
+ patches.push({
1705
+ type: SetReferenceNodeUid,
1706
+ uid: newNode.uid
1707
+ });
1708
+ }
1709
+ return patches;
1710
+ }
1619
1711
  // Handle text nodes
1620
1712
  if (oldNode.type === Text && newNode.type === Text) {
1621
1713
  if (oldNode.text !== newNode.text) {
@@ -1751,7 +1843,6 @@ const diffChildren = (oldChildren, newChildren, patches) => {
1751
1843
  patches.push({
1752
1844
  type: NavigateParent
1753
1845
  });
1754
- currentChildIndex = -1;
1755
1846
  }
1756
1847
  // Add remove patches in reverse order (highest index first)
1757
1848
  // This ensures indices remain valid as we remove
@@ -1995,6 +2086,7 @@ const commandMap = {
1995
2086
  'StatusBar.getCommandIds': getCommandIds,
1996
2087
  'StatusBar.handleClick': wrapCommand(handleClick),
1997
2088
  'StatusBar.handleContextMenu': wrapCommand(handleContextMenu),
2089
+ 'StatusBar.handleExtensionsChanged': wrapCommand(handleExtensionsChanged),
1998
2090
  'StatusBar.initialize': initialize,
1999
2091
  'StatusBar.itemLeftUpdate': wrapCommand(itemLeftUpdate),
2000
2092
  'StatusBar.itemRightCreate': wrapCommand(itemRightCreate),
@@ -2009,7 +2101,7 @@ const commandMap = {
2009
2101
 
2010
2102
  const listen = async () => {
2011
2103
  registerCommands(commandMap);
2012
- const rpc = await WebWorkerRpcClient.create({
2104
+ const rpc = await create$3({
2013
2105
  commandMap: commandMap
2014
2106
  });
2015
2107
  set$1(rpc);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/status-bar-worker",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Status Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",