@lvce-editor/activity-bar-worker 4.0.0 → 4.4.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.
@@ -412,6 +412,27 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
412
412
  wrap: wrap$e
413
413
  };
414
414
 
415
+ class CommandNotFoundError extends Error {
416
+ constructor(command) {
417
+ super(`Command not found ${command}`);
418
+ this.name = 'CommandNotFoundError';
419
+ }
420
+ }
421
+ const commands = Object.create(null);
422
+ const register = commandMap => {
423
+ Object.assign(commands, commandMap);
424
+ };
425
+ const getCommand = key => {
426
+ return commands[key];
427
+ };
428
+ const execute = (command, ...args) => {
429
+ const fn = getCommand(command);
430
+ if (!fn) {
431
+ throw new CommandNotFoundError(command);
432
+ }
433
+ return fn(...args);
434
+ };
435
+
415
436
  const Two$1 = '2.0';
416
437
  const callbacks = Object.create(null);
417
438
  const get$2 = id => {
@@ -436,12 +457,12 @@ const getErrorConstructor = (message, type) => {
436
457
  switch (type) {
437
458
  case DomException:
438
459
  return DOMException;
439
- case TypeError$1:
440
- return TypeError;
441
- case SyntaxError$1:
442
- return SyntaxError;
443
460
  case ReferenceError$1:
444
461
  return ReferenceError;
462
+ case SyntaxError$1:
463
+ return SyntaxError;
464
+ case TypeError$1:
465
+ return TypeError;
445
466
  default:
446
467
  return Error;
447
468
  }
@@ -597,27 +618,27 @@ const getErrorProperty = (error, prettyError) => {
597
618
  if (error && error.code === E_COMMAND_NOT_FOUND) {
598
619
  return {
599
620
  code: MethodNotFound,
600
- message: error.message,
601
- data: error.stack
621
+ data: error.stack,
622
+ message: error.message
602
623
  };
603
624
  }
604
625
  return {
605
626
  code: Custom,
606
- message: prettyError.message,
607
627
  data: {
608
- stack: getStack(prettyError),
609
- codeFrame: prettyError.codeFrame,
610
- type: getErrorType(prettyError),
611
628
  code: prettyError.code,
612
- name: prettyError.name
613
- }
629
+ codeFrame: prettyError.codeFrame,
630
+ name: prettyError.name,
631
+ stack: getStack(prettyError),
632
+ type: getErrorType(prettyError)
633
+ },
634
+ message: prettyError.message
614
635
  };
615
636
  };
616
637
  const create$1$1 = (id, error) => {
617
638
  return {
618
- jsonrpc: Two$1,
639
+ error,
619
640
  id,
620
- error
641
+ jsonrpc: Two$1
621
642
  };
622
643
  };
623
644
  const getErrorResponse = (id, error, preparePrettyError, logError) => {
@@ -626,27 +647,27 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
626
647
  const errorProperty = getErrorProperty(error, prettyError);
627
648
  return create$1$1(id, errorProperty);
628
649
  };
629
- const create$3 = (message, result) => {
650
+ const create$7 = (message, result) => {
630
651
  return {
631
- jsonrpc: Two$1,
632
652
  id: message.id,
653
+ jsonrpc: Two$1,
633
654
  result: result ?? null
634
655
  };
635
656
  };
636
657
  const getSuccessResponse = (message, result) => {
637
658
  const resultProperty = result ?? null;
638
- return create$3(message, resultProperty);
659
+ return create$7(message, resultProperty);
639
660
  };
640
661
  const getErrorResponseSimple = (id, error) => {
641
662
  return {
642
- jsonrpc: Two$1,
643
- id,
644
663
  error: {
645
664
  code: Custom,
665
+ data: error,
646
666
  // @ts-ignore
647
- message: error.message,
648
- data: error
649
- }
667
+ message: error.message
668
+ },
669
+ id,
670
+ jsonrpc: Two$1
650
671
  };
651
672
  };
652
673
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
@@ -676,35 +697,35 @@ const normalizeParams = args => {
676
697
  if (args.length === 1) {
677
698
  const options = args[0];
678
699
  return {
700
+ execute: options.execute,
679
701
  ipc: options.ipc,
702
+ logError: options.logError || defaultLogError,
680
703
  message: options.message,
681
- execute: options.execute,
682
- resolve: options.resolve || defaultResolve,
683
704
  preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
684
- logError: options.logError || defaultLogError,
685
- requiresSocket: options.requiresSocket || defaultRequiresSocket
705
+ requiresSocket: options.requiresSocket || defaultRequiresSocket,
706
+ resolve: options.resolve || defaultResolve
686
707
  };
687
708
  }
688
709
  return {
710
+ execute: args[2],
689
711
  ipc: args[0],
712
+ logError: args[5],
690
713
  message: args[1],
691
- execute: args[2],
692
- resolve: args[3],
693
714
  preparePrettyError: args[4],
694
- logError: args[5],
695
- requiresSocket: args[6]
715
+ requiresSocket: args[6],
716
+ resolve: args[3]
696
717
  };
697
718
  };
698
719
  const handleJsonRpcMessage = async (...args) => {
699
720
  const options = normalizeParams(args);
700
721
  const {
701
- message,
702
- ipc,
703
722
  execute,
704
- resolve,
705
- preparePrettyError,
723
+ ipc,
706
724
  logError,
707
- requiresSocket
725
+ message,
726
+ preparePrettyError,
727
+ requiresSocket,
728
+ resolve
708
729
  } = options;
709
730
  if ('id' in message) {
710
731
  if ('method' in message) {
@@ -727,36 +748,17 @@ const handleJsonRpcMessage = async (...args) => {
727
748
  throw new JsonRpcError('unexpected message');
728
749
  };
729
750
 
730
- class CommandNotFoundError extends Error {
731
- constructor(command) {
732
- super(`Command not found ${command}`);
733
- this.name = 'CommandNotFoundError';
734
- }
735
- }
736
- const commands = Object.create(null);
737
- const register = commandMap => {
738
- Object.assign(commands, commandMap);
739
- };
740
- const getCommand = key => {
741
- return commands[key];
742
- };
743
- const execute = (command, ...args) => {
744
- const fn = getCommand(command);
745
- if (!fn) {
746
- throw new CommandNotFoundError(command);
747
- }
748
- return fn(...args);
749
- };
750
-
751
751
  const Two = '2.0';
752
- const create$t = (method, params) => {
752
+
753
+ const create$6 = (method, params) => {
753
754
  return {
754
755
  jsonrpc: Two,
755
756
  method,
756
757
  params
757
758
  };
758
759
  };
759
- const create$s = (id, method, params) => {
760
+
761
+ const create$5 = (id, method, params) => {
760
762
  const message = {
761
763
  id,
762
764
  jsonrpc: Two,
@@ -765,15 +767,14 @@ const create$s = (id, method, params) => {
765
767
  };
766
768
  return message;
767
769
  };
770
+
768
771
  let id = 0;
769
- const create$r = () => {
772
+ const create$4 = () => {
770
773
  return ++id;
771
774
  };
772
775
 
773
- /* eslint-disable n/no-unsupported-features/es-syntax */
774
-
775
776
  const registerPromise = map => {
776
- const id = create$r();
777
+ const id = create$4();
777
778
  const {
778
779
  promise,
779
780
  resolve
@@ -785,13 +786,12 @@ const registerPromise = map => {
785
786
  };
786
787
  };
787
788
 
788
- // @ts-ignore
789
789
  const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
790
790
  const {
791
791
  id,
792
792
  promise
793
793
  } = registerPromise(callbacks);
794
- const message = create$s(id, method, params);
794
+ const message = create$5(id, method, params);
795
795
  if (useSendAndTransfer && ipc.sendAndTransfer) {
796
796
  ipc.sendAndTransfer(message);
797
797
  } else {
@@ -827,12 +827,13 @@ const createRpc = ipc => {
827
827
  * @deprecated
828
828
  */
829
829
  send(method, ...params) {
830
- const message = create$t(method, params);
830
+ const message = create$6(method, params);
831
831
  ipc.send(message);
832
832
  }
833
833
  };
834
834
  return rpc;
835
835
  };
836
+
836
837
  const requiresSocket = () => {
837
838
  return false;
838
839
  };
@@ -847,6 +848,7 @@ const handleMessage = event => {
847
848
  const actualExecute = event?.target?.execute || execute;
848
849
  return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
849
850
  };
851
+
850
852
  const handleIpc = ipc => {
851
853
  if ('addEventListener' in ipc) {
852
854
  ipc.addEventListener('message', handleMessage);
@@ -855,6 +857,7 @@ const handleIpc = ipc => {
855
857
  ipc.on('message', handleMessage);
856
858
  }
857
859
  };
860
+
858
861
  const listen$1 = async (module, options) => {
859
862
  const rawIpc = await module.listen(options);
860
863
  if (module.signal) {
@@ -863,7 +866,8 @@ const listen$1 = async (module, options) => {
863
866
  const ipc = module.wrap(rawIpc);
864
867
  return ipc;
865
868
  };
866
- const create$2$1 = async ({
869
+
870
+ const create$3 = async ({
867
871
  commandMap
868
872
  }) => {
869
873
  // TODO create a commandMap per rpc instance
@@ -873,10 +877,7 @@ const create$2$1 = async ({
873
877
  const rpc = createRpc(ipc);
874
878
  return rpc;
875
879
  };
876
- const WebWorkerRpcClient = {
877
- __proto__: null,
878
- create: create$2$1
879
- };
880
+
880
881
  const createMockRpc = ({
881
882
  commandMap
882
883
  }) => {
@@ -897,54 +898,6 @@ const createMockRpc = ({
897
898
  return mockRpc;
898
899
  };
899
900
 
900
- const Button$2 = 'button';
901
- const None$1 = 'none';
902
- const Tab$1 = 'tab';
903
- const ToolBar = 'toolbar';
904
-
905
- const Div = 4;
906
- const Text = 12;
907
- const Reference = 100;
908
-
909
- const Button$1 = 'event.button';
910
- const ClientX = 'event.clientX';
911
- const ClientY = 'event.clientY';
912
-
913
- const Enter = 3;
914
- const Space = 9;
915
- const PageUp = 10;
916
- const PageDown = 11;
917
- const End = 255;
918
- const Home = 12;
919
- const UpArrow = 14;
920
- const DownArrow = 16;
921
-
922
- const ActivityBar$3 = 1;
923
- const Settings$1 = 12;
924
- const ActivityBarAdditionalViews = 17;
925
-
926
- const Separator = 1;
927
- const None = 0;
928
- const Checked = 2;
929
- const Unchecked = 3;
930
-
931
- const LeftClick = 0;
932
-
933
- const Web = 1;
934
-
935
- const RendererWorker = 1;
936
-
937
- const Left = 1;
938
- const Right = 2;
939
-
940
- const SetCss = 'Viewlet.setCss';
941
- const SetDom2 = 'Viewlet.setDom2';
942
- const SetFocusContext = 'Viewlet.setFocusContext';
943
- const SetPatches = 'Viewlet.setPatches';
944
-
945
- const FocusActivityBar = 5;
946
- const FocusExplorer = 13;
947
-
948
901
  const rpcs = Object.create(null);
949
902
  const set$2 = (id, rpc) => {
950
903
  rpcs[id] = rpc;
@@ -993,6 +946,54 @@ const create$2 = rpcId => {
993
946
  };
994
947
  };
995
948
 
949
+ const Button$2 = 'button';
950
+ const None$1 = 'none';
951
+ const Tab$1 = 'tab';
952
+ const ToolBar = 'toolbar';
953
+
954
+ const Div = 4;
955
+ const Text = 12;
956
+ const Reference = 100;
957
+
958
+ const Button$1 = 'event.button';
959
+ const ClientX = 'event.clientX';
960
+ const ClientY = 'event.clientY';
961
+
962
+ const Enter = 3;
963
+ const Space = 9;
964
+ const PageUp = 10;
965
+ const PageDown = 11;
966
+ const End = 255;
967
+ const Home = 12;
968
+ const UpArrow = 14;
969
+ const DownArrow = 16;
970
+
971
+ const ActivityBar$3 = 1;
972
+ const Settings$1 = 12;
973
+ const ActivityBarAdditionalViews = 17;
974
+
975
+ const Separator = 1;
976
+ const None = 0;
977
+ const Checked = 2;
978
+ const Unchecked = 3;
979
+
980
+ const LeftClick = 0;
981
+
982
+ const Web = 1;
983
+
984
+ const RendererWorker = 1;
985
+
986
+ const Left = 1;
987
+ const Right = 2;
988
+
989
+ const SetCss = 'Viewlet.setCss';
990
+ const SetDom2 = 'Viewlet.setDom2';
991
+ const SetFocusContext = 'Viewlet.setFocusContext';
992
+ const SetPatches = 'Viewlet.setPatches';
993
+
994
+ const FocusActivityBar = 5;
995
+ const FocusExplorer = 13;
996
+
996
997
  const {
997
998
  invoke,
998
999
  set: set$1
@@ -1045,7 +1046,7 @@ const create$1 = () => {
1045
1046
  },
1046
1047
  getKeys() {
1047
1048
  return Object.keys(states).map(key => {
1048
- return Number.parseInt(key);
1049
+ return Number.parseFloat(key);
1049
1050
  });
1050
1051
  },
1051
1052
  registerCommands(commandMap) {
@@ -1087,6 +1088,37 @@ const create$1 = () => {
1087
1088
  return fn(newState, ...args);
1088
1089
  };
1089
1090
  return wrapped;
1091
+ },
1092
+ wrapLoadContent(fn) {
1093
+ const wrapped = async (uid, ...args) => {
1094
+ const {
1095
+ newState,
1096
+ oldState
1097
+ } = states[uid];
1098
+ const result = await fn(newState, ...args);
1099
+ const {
1100
+ error,
1101
+ state
1102
+ } = result;
1103
+ if (oldState === state || newState === state) {
1104
+ return {
1105
+ error
1106
+ };
1107
+ }
1108
+ const latestOld = states[uid];
1109
+ const latestNew = {
1110
+ ...latestOld.newState,
1111
+ ...state
1112
+ };
1113
+ states[uid] = {
1114
+ newState: latestNew,
1115
+ oldState: latestOld.oldState
1116
+ };
1117
+ return {
1118
+ error
1119
+ };
1120
+ };
1121
+ return wrapped;
1090
1122
  }
1091
1123
  };
1092
1124
  };
@@ -1126,6 +1158,7 @@ const create = (id, uri, x, y, width, height, args, parentUid, platform = 0) =>
1126
1158
  uid: id,
1127
1159
  updateProgress: 0,
1128
1160
  updateState: '',
1161
+ userLoginState: 'logged out',
1129
1162
  width,
1130
1163
  x,
1131
1164
  y
@@ -1143,7 +1176,7 @@ const isEqual$1 = (oldState, newState) => {
1143
1176
  };
1144
1177
 
1145
1178
  const isEqual = (oldState, newState) => {
1146
- return oldState.activityBarItems === newState.activityBarItems && oldState.filteredItems === newState.filteredItems && oldState.focusedIndex === newState.focusedIndex && oldState.updateProgress === newState.updateProgress && oldState.updateState === newState.updateState;
1179
+ return oldState.activityBarItems === newState.activityBarItems && oldState.filteredItems === newState.filteredItems && oldState.focusedIndex === newState.focusedIndex && oldState.sideBarLocation === newState.sideBarLocation && oldState.sideBarVisible === newState.sideBarVisible && oldState.updateProgress === newState.updateProgress && oldState.updateState === newState.updateState;
1147
1180
  };
1148
1181
 
1149
1182
  const RenderItems = 4;
@@ -1589,7 +1622,7 @@ const hide = async () => {
1589
1622
  await invoke('Layout.hideSideBar');
1590
1623
  };
1591
1624
 
1592
- const handleClickOther = async (state, x, y, viewletId) => {
1625
+ const handleClickOther = async (state, viewletId) => {
1593
1626
  const {
1594
1627
  currentViewletId,
1595
1628
  sideBarVisible
@@ -1636,7 +1669,7 @@ const handleClickIndex = async (state, button, index, x, y) => {
1636
1669
  case 'Settings':
1637
1670
  return handleClickSettings(state, x, y);
1638
1671
  default:
1639
- return handleClickOther(state, x, y, viewletId);
1672
+ return handleClickOther(state, viewletId);
1640
1673
  }
1641
1674
  };
1642
1675
 
@@ -1822,14 +1855,22 @@ const handleSettingsChanged = async state => {
1822
1855
  };
1823
1856
  };
1824
1857
 
1858
+ const clearItem = item => {
1859
+ const withoutSelected = setFlag(item, Selected, false);
1860
+ return setFlag(withoutSelected, Focused, false);
1861
+ };
1825
1862
  const handleSideBarHidden = state => {
1826
- const itemsCleared = state.activityBarItems.map(item => {
1827
- const withoutSelected = setFlag(item, Selected, false);
1828
- return setFlag(withoutSelected, Focused, false);
1829
- });
1863
+ const {
1864
+ activityBarItems,
1865
+ height,
1866
+ itemHeight
1867
+ } = state;
1868
+ const itemsCleared = activityBarItems.map(clearItem);
1869
+ const filteredItems = getFilteredActivityBarItems(itemsCleared, height, itemHeight);
1830
1870
  return {
1831
1871
  ...state,
1832
1872
  activityBarItems: itemsCleared,
1873
+ filteredItems,
1833
1874
  focusedIndex: -1,
1834
1875
  selectedIndex: -1,
1835
1876
  sideBarVisible: false
@@ -1845,12 +1886,22 @@ const findIndex = (activityBarItems, id) => {
1845
1886
  return -1;
1846
1887
  };
1847
1888
 
1848
- const handleSideBarViewletChange = (state, id, ...args) => {
1889
+ const getSideBarVisible = async () => {
1890
+ try {
1891
+ const visible = await invoke('Layout.getSideBarVisible');
1892
+ return visible;
1893
+ } catch {
1894
+ return true;
1895
+ }
1896
+ };
1897
+
1898
+ const handleSideBarViewletChange = async (state, id, ...args) => {
1849
1899
  const {
1850
1900
  activityBarItems,
1851
1901
  height,
1852
1902
  itemHeight
1853
1903
  } = state;
1904
+ const sideBarVisible = await getSideBarVisible();
1854
1905
  const index = findIndex(activityBarItems, id);
1855
1906
  const newActivityBarItems = markSelected(activityBarItems, index);
1856
1907
  const filteredItems = getFilteredActivityBarItems(newActivityBarItems, height, itemHeight);
@@ -1860,7 +1911,7 @@ const handleSideBarViewletChange = (state, id, ...args) => {
1860
1911
  currentViewletId: id,
1861
1912
  filteredItems,
1862
1913
  selectedIndex: index,
1863
- sideBarVisible: true
1914
+ sideBarVisible
1864
1915
  };
1865
1916
  };
1866
1917
 
@@ -1911,37 +1962,25 @@ const getActiveView = async () => {
1911
1962
  }
1912
1963
  };
1913
1964
 
1914
- const getSideBarVisible = async () => {
1915
- try {
1916
- const visible = await invoke('Layout.getSideBarVisible');
1917
- return visible;
1918
- } catch {
1919
- return true;
1920
- }
1921
- };
1922
-
1923
1965
  const loadContent = async state => {
1924
1966
  const {
1925
1967
  height,
1926
1968
  itemHeight
1927
1969
  } = state;
1928
1970
  const items = getActivityBarItems(state);
1929
- // TODO parallelize async calls
1930
- // or add one function that returns all needed data
1931
- const activeView = await getActiveView();
1932
- const sideBarVisible = await getSideBarVisible();
1971
+ const [activeView, sideBarVisible, sidebarLocation] = await Promise.all([getActiveView(), getSideBarVisible(), getSideBarPosition()]);
1933
1972
  const index = items.findIndex(item => item.id === activeView);
1934
- const itemsWithSelected = markSelected(items, index);
1973
+ const selectedIndex = sideBarVisible ? index : -1;
1974
+ const itemsWithSelected = markSelected(items, selectedIndex);
1935
1975
  const filteredItems = getFilteredActivityBarItems(itemsWithSelected, height, itemHeight);
1936
1976
  const newItems = await updateItemsWithBadgeCount(filteredItems);
1937
- const sidebarLocation = await getSideBarPosition();
1938
1977
  return {
1939
1978
  ...state,
1940
1979
  activityBarItems: itemsWithSelected,
1941
1980
  currentViewletId: Explorer,
1942
1981
  filteredItems: newItems,
1943
1982
  initial: false,
1944
- selectedIndex: index,
1983
+ selectedIndex,
1945
1984
  sideBarLocation: sidebarLocation,
1946
1985
  sideBarVisible
1947
1986
  };
@@ -2492,6 +2531,9 @@ const renderIncremental = (oldState, newState) => {
2492
2531
  const oldDom = renderItems(oldState, oldState)[2];
2493
2532
  const newDom = renderItems(newState, newState)[2];
2494
2533
  const patches = diffTree(oldDom, newDom);
2534
+ if (patches.length === 0) {
2535
+ return [];
2536
+ }
2495
2537
  return [SetPatches, newState.uid, patches];
2496
2538
  };
2497
2539
 
@@ -2619,6 +2661,7 @@ const commandMap = {
2619
2661
  'ActivityBar.handleBlur': wrapCommand(handleBlur),
2620
2662
  'ActivityBar.handleClick': wrapCommand(handleClick),
2621
2663
  'ActivityBar.handleClickIndex': wrapCommand(handleClickIndex),
2664
+ 'ActivityBar.handleClickSettings': wrapCommand(handleClickSettings),
2622
2665
  'ActivityBar.handleContextMenu': wrapCommand(handleContextMenu),
2623
2666
  'ActivityBar.handleFocus': wrapCommand(handleFocus),
2624
2667
  'ActivityBar.handleSettingsChanged': wrapCommand(handleSettingsChanged),
@@ -2637,7 +2680,7 @@ const commandMap = {
2637
2680
 
2638
2681
  const listen = async () => {
2639
2682
  registerCommands(commandMap);
2640
- const rpc = await WebWorkerRpcClient.create({
2683
+ const rpc = await create$3({
2641
2684
  commandMap: commandMap
2642
2685
  });
2643
2686
  set$1(rpc);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/activity-bar-worker",
3
- "version": "4.0.0",
3
+ "version": "4.4.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",