@lvce-editor/activity-bar-worker 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activityBarWorkerMain.js +74 -74
- package/package.json +1 -1
|
@@ -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 => {
|
|
@@ -626,7 +647,7 @@ 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$
|
|
650
|
+
const create$7 = (message, result) => {
|
|
630
651
|
return {
|
|
631
652
|
jsonrpc: Two$1,
|
|
632
653
|
id: message.id,
|
|
@@ -635,7 +656,7 @@ const create$3 = (message, result) => {
|
|
|
635
656
|
};
|
|
636
657
|
const getSuccessResponse = (message, result) => {
|
|
637
658
|
const resultProperty = result ?? null;
|
|
638
|
-
return create$
|
|
659
|
+
return create$7(message, resultProperty);
|
|
639
660
|
};
|
|
640
661
|
const getErrorResponseSimple = (id, error) => {
|
|
641
662
|
return {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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$
|
|
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$
|
|
777
|
+
const id = create$4();
|
|
777
778
|
const {
|
|
778
779
|
promise,
|
|
779
780
|
resolve
|
|
@@ -791,7 +792,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
791
792
|
id,
|
|
792
793
|
promise
|
|
793
794
|
} = registerPromise(callbacks);
|
|
794
|
-
const message = create$
|
|
795
|
+
const message = create$5(id, method, params);
|
|
795
796
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
796
797
|
ipc.sendAndTransfer(message);
|
|
797
798
|
} else {
|
|
@@ -827,12 +828,13 @@ const createRpc = ipc => {
|
|
|
827
828
|
* @deprecated
|
|
828
829
|
*/
|
|
829
830
|
send(method, ...params) {
|
|
830
|
-
const message = create$
|
|
831
|
+
const message = create$6(method, params);
|
|
831
832
|
ipc.send(message);
|
|
832
833
|
}
|
|
833
834
|
};
|
|
834
835
|
return rpc;
|
|
835
836
|
};
|
|
837
|
+
|
|
836
838
|
const requiresSocket = () => {
|
|
837
839
|
return false;
|
|
838
840
|
};
|
|
@@ -847,6 +849,7 @@ const handleMessage = event => {
|
|
|
847
849
|
const actualExecute = event?.target?.execute || execute;
|
|
848
850
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
849
851
|
};
|
|
852
|
+
|
|
850
853
|
const handleIpc = ipc => {
|
|
851
854
|
if ('addEventListener' in ipc) {
|
|
852
855
|
ipc.addEventListener('message', handleMessage);
|
|
@@ -855,6 +858,7 @@ const handleIpc = ipc => {
|
|
|
855
858
|
ipc.on('message', handleMessage);
|
|
856
859
|
}
|
|
857
860
|
};
|
|
861
|
+
|
|
858
862
|
const listen$1 = async (module, options) => {
|
|
859
863
|
const rawIpc = await module.listen(options);
|
|
860
864
|
if (module.signal) {
|
|
@@ -863,7 +867,8 @@ const listen$1 = async (module, options) => {
|
|
|
863
867
|
const ipc = module.wrap(rawIpc);
|
|
864
868
|
return ipc;
|
|
865
869
|
};
|
|
866
|
-
|
|
870
|
+
|
|
871
|
+
const create$3 = async ({
|
|
867
872
|
commandMap
|
|
868
873
|
}) => {
|
|
869
874
|
// TODO create a commandMap per rpc instance
|
|
@@ -873,29 +878,6 @@ const create$2$1 = async ({
|
|
|
873
878
|
const rpc = createRpc(ipc);
|
|
874
879
|
return rpc;
|
|
875
880
|
};
|
|
876
|
-
const WebWorkerRpcClient = {
|
|
877
|
-
__proto__: null,
|
|
878
|
-
create: create$2$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;
|
|
898
|
-
};
|
|
899
881
|
|
|
900
882
|
const Button$2 = 'button';
|
|
901
883
|
const None$1 = 'none';
|
|
@@ -945,6 +927,26 @@ const SetPatches = 'Viewlet.setPatches';
|
|
|
945
927
|
const FocusActivityBar = 5;
|
|
946
928
|
const FocusExplorer = 13;
|
|
947
929
|
|
|
930
|
+
const createMockRpc = ({
|
|
931
|
+
commandMap
|
|
932
|
+
}) => {
|
|
933
|
+
const invocations = [];
|
|
934
|
+
const invoke = (method, ...params) => {
|
|
935
|
+
invocations.push([method, ...params]);
|
|
936
|
+
const command = commandMap[method];
|
|
937
|
+
if (!command) {
|
|
938
|
+
throw new Error(`command ${method} not found`);
|
|
939
|
+
}
|
|
940
|
+
return command(...params);
|
|
941
|
+
};
|
|
942
|
+
const mockRpc = {
|
|
943
|
+
invocations,
|
|
944
|
+
invoke,
|
|
945
|
+
invokeAndTransfer: invoke
|
|
946
|
+
};
|
|
947
|
+
return mockRpc;
|
|
948
|
+
};
|
|
949
|
+
|
|
948
950
|
const rpcs = Object.create(null);
|
|
949
951
|
const set$2 = (id, rpc) => {
|
|
950
952
|
rpcs[id] = rpc;
|
|
@@ -1845,12 +1847,22 @@ const findIndex = (activityBarItems, id) => {
|
|
|
1845
1847
|
return -1;
|
|
1846
1848
|
};
|
|
1847
1849
|
|
|
1848
|
-
const
|
|
1850
|
+
const getSideBarVisible = async () => {
|
|
1851
|
+
try {
|
|
1852
|
+
const visible = await invoke('Layout.getSideBarVisible');
|
|
1853
|
+
return visible;
|
|
1854
|
+
} catch {
|
|
1855
|
+
return true;
|
|
1856
|
+
}
|
|
1857
|
+
};
|
|
1858
|
+
|
|
1859
|
+
const handleSideBarViewletChange = async (state, id, ...args) => {
|
|
1849
1860
|
const {
|
|
1850
1861
|
activityBarItems,
|
|
1851
1862
|
height,
|
|
1852
1863
|
itemHeight
|
|
1853
1864
|
} = state;
|
|
1865
|
+
const sideBarVisible = await getSideBarVisible();
|
|
1854
1866
|
const index = findIndex(activityBarItems, id);
|
|
1855
1867
|
const newActivityBarItems = markSelected(activityBarItems, index);
|
|
1856
1868
|
const filteredItems = getFilteredActivityBarItems(newActivityBarItems, height, itemHeight);
|
|
@@ -1860,7 +1872,7 @@ const handleSideBarViewletChange = (state, id, ...args) => {
|
|
|
1860
1872
|
currentViewletId: id,
|
|
1861
1873
|
filteredItems,
|
|
1862
1874
|
selectedIndex: index,
|
|
1863
|
-
sideBarVisible
|
|
1875
|
+
sideBarVisible
|
|
1864
1876
|
};
|
|
1865
1877
|
};
|
|
1866
1878
|
|
|
@@ -1911,37 +1923,25 @@ const getActiveView = async () => {
|
|
|
1911
1923
|
}
|
|
1912
1924
|
};
|
|
1913
1925
|
|
|
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
1926
|
const loadContent = async state => {
|
|
1924
1927
|
const {
|
|
1925
1928
|
height,
|
|
1926
1929
|
itemHeight
|
|
1927
1930
|
} = state;
|
|
1928
1931
|
const items = getActivityBarItems(state);
|
|
1929
|
-
|
|
1930
|
-
// or add one function that returns all needed data
|
|
1931
|
-
const activeView = await getActiveView();
|
|
1932
|
-
const sideBarVisible = await getSideBarVisible();
|
|
1932
|
+
const [activeView, sideBarVisible, sidebarLocation] = await Promise.all([getActiveView(), getSideBarVisible(), getSideBarPosition()]);
|
|
1933
1933
|
const index = items.findIndex(item => item.id === activeView);
|
|
1934
|
-
const
|
|
1934
|
+
const selectedIndex = sideBarVisible ? index : -1;
|
|
1935
|
+
const itemsWithSelected = markSelected(items, selectedIndex);
|
|
1935
1936
|
const filteredItems = getFilteredActivityBarItems(itemsWithSelected, height, itemHeight);
|
|
1936
1937
|
const newItems = await updateItemsWithBadgeCount(filteredItems);
|
|
1937
|
-
const sidebarLocation = await getSideBarPosition();
|
|
1938
1938
|
return {
|
|
1939
1939
|
...state,
|
|
1940
1940
|
activityBarItems: itemsWithSelected,
|
|
1941
1941
|
currentViewletId: Explorer,
|
|
1942
1942
|
filteredItems: newItems,
|
|
1943
1943
|
initial: false,
|
|
1944
|
-
selectedIndex
|
|
1944
|
+
selectedIndex,
|
|
1945
1945
|
sideBarLocation: sidebarLocation,
|
|
1946
1946
|
sideBarVisible
|
|
1947
1947
|
};
|
|
@@ -2637,7 +2637,7 @@ const commandMap = {
|
|
|
2637
2637
|
|
|
2638
2638
|
const listen = async () => {
|
|
2639
2639
|
registerCommands(commandMap);
|
|
2640
|
-
const rpc = await
|
|
2640
|
+
const rpc = await create$3({
|
|
2641
2641
|
commandMap: commandMap
|
|
2642
2642
|
});
|
|
2643
2643
|
set$1(rpc);
|