@lvce-editor/extension-search-view 1.5.0 → 2.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.
|
@@ -840,7 +840,7 @@ const WebWorkerRpcClient = {
|
|
|
840
840
|
create
|
|
841
841
|
};
|
|
842
842
|
|
|
843
|
-
const handleError =
|
|
843
|
+
const handleError = (error, notify = true, prefix = '') => {
|
|
844
844
|
console.error(error);
|
|
845
845
|
};
|
|
846
846
|
|
|
@@ -862,17 +862,9 @@ const i18nString = (key, placeholders = emptyObject) => {
|
|
|
862
862
|
const UiStrings = {
|
|
863
863
|
NoExtensionsFound: 'No extensions found.',
|
|
864
864
|
Filter: 'Filter',
|
|
865
|
-
Refresh: 'Refresh',
|
|
866
865
|
ClearExtensionSearchResults: 'Clear extension search results',
|
|
867
|
-
Enable: 'Enable',
|
|
868
|
-
Disable: 'Disable',
|
|
869
|
-
Uninstall: 'Uninstall',
|
|
870
|
-
InstallAnotherVersion: 'Install Another Version',
|
|
871
866
|
SearchExtensionsInMarketplace: 'Search Extensions in Marketplace',
|
|
872
|
-
|
|
873
|
-
Extensions: 'Extensions',
|
|
874
|
-
Installed: 'Installed'
|
|
875
|
-
};
|
|
867
|
+
Extensions: 'Extensions'};
|
|
876
868
|
const noExtensionsFound = () => {
|
|
877
869
|
return i18nString(UiStrings.NoExtensionsFound);
|
|
878
870
|
};
|
|
@@ -913,24 +905,42 @@ const getNumberOfVisibleItems = (listHeight, itemHeight) => {
|
|
|
913
905
|
return Math.ceil(listHeight / itemHeight) + 1;
|
|
914
906
|
};
|
|
915
907
|
|
|
916
|
-
/**
|
|
917
|
-
*
|
|
918
|
-
* @param {number} size
|
|
919
|
-
* @param {number} contentSize
|
|
920
|
-
* @param {number} minimumSliderSize
|
|
921
|
-
* @returns
|
|
922
|
-
*/
|
|
923
908
|
const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
|
|
924
909
|
if (size >= contentSize) {
|
|
925
910
|
return 0;
|
|
926
911
|
}
|
|
927
912
|
return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
|
|
928
913
|
};
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
914
|
+
|
|
915
|
+
const Web = 1;
|
|
916
|
+
const Electron = 2;
|
|
917
|
+
const Remote = 3;
|
|
918
|
+
const Test = 4;
|
|
919
|
+
|
|
920
|
+
// TODO treeshake this function out
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* @returns {number}
|
|
924
|
+
*/
|
|
925
|
+
const getPlatform = () => {
|
|
926
|
+
// @ts-ignore
|
|
927
|
+
if (typeof PLATFORM !== 'undefined') {
|
|
928
|
+
// @ts-ignore
|
|
929
|
+
return PLATFORM;
|
|
930
|
+
}
|
|
931
|
+
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
|
|
932
|
+
return Test;
|
|
933
|
+
}
|
|
934
|
+
// TODO find a better way to pass runtime environment
|
|
935
|
+
if (typeof name !== 'undefined' && name.endsWith('(Electron)')) {
|
|
936
|
+
return Electron;
|
|
937
|
+
}
|
|
938
|
+
if (typeof name !== 'undefined' && name.endsWith('(Web)')) {
|
|
939
|
+
return Web;
|
|
940
|
+
}
|
|
941
|
+
return Remote;
|
|
932
942
|
};
|
|
933
|
-
const
|
|
943
|
+
const platform = getPlatform();
|
|
934
944
|
|
|
935
945
|
const Installed = '@installed';
|
|
936
946
|
const Enabled = '@enabled';
|
|
@@ -982,37 +992,7 @@ const parseValue = value => {
|
|
|
982
992
|
|
|
983
993
|
const assetDir = '';
|
|
984
994
|
|
|
985
|
-
const
|
|
986
|
-
const Electron = 2;
|
|
987
|
-
const Remote = 3;
|
|
988
|
-
const Test = 4;
|
|
989
|
-
|
|
990
|
-
// TODO treeshake this function out
|
|
991
|
-
|
|
992
|
-
/**
|
|
993
|
-
* @returns {number}
|
|
994
|
-
*/
|
|
995
|
-
const getPlatform = () => {
|
|
996
|
-
// @ts-ignore
|
|
997
|
-
if (typeof PLATFORM !== 'undefined') {
|
|
998
|
-
// @ts-ignore
|
|
999
|
-
return PLATFORM;
|
|
1000
|
-
}
|
|
1001
|
-
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
|
|
1002
|
-
return Test;
|
|
1003
|
-
}
|
|
1004
|
-
// TODO find a better way to pass runtime environment
|
|
1005
|
-
if (typeof name !== 'undefined' && name.endsWith('(Electron)')) {
|
|
1006
|
-
return Electron;
|
|
1007
|
-
}
|
|
1008
|
-
if (typeof name !== 'undefined' && name.endsWith('(Web)')) {
|
|
1009
|
-
return Web;
|
|
1010
|
-
}
|
|
1011
|
-
return Remote;
|
|
1012
|
-
};
|
|
1013
|
-
const platform = getPlatform();
|
|
1014
|
-
|
|
1015
|
-
const getRemoteUrl = extension => {
|
|
995
|
+
const getRemoteUrl = (extension, platform) => {
|
|
1016
996
|
if (platform === Remote || platform === Electron) {
|
|
1017
997
|
if (extension.builtin) {
|
|
1018
998
|
return `${assetDir}/extensions/${extension.id}/${extension.icon}`;
|
|
@@ -1032,7 +1012,7 @@ const isLanguageBasicsExtension = extension => {
|
|
|
1032
1012
|
const isThemeExtension = extension => {
|
|
1033
1013
|
return extension.name && extension.name.endsWith(' Theme');
|
|
1034
1014
|
};
|
|
1035
|
-
const getIcon = extension => {
|
|
1015
|
+
const getIcon = (extension, platform) => {
|
|
1036
1016
|
if (!extension) {
|
|
1037
1017
|
return ExtensionDefaultIcon;
|
|
1038
1018
|
}
|
|
@@ -1045,21 +1025,7 @@ const getIcon = extension => {
|
|
|
1045
1025
|
}
|
|
1046
1026
|
return ExtensionDefaultIcon;
|
|
1047
1027
|
}
|
|
1048
|
-
return getRemoteUrl(extension);
|
|
1049
|
-
};
|
|
1050
|
-
const RE_PUBLISHER = /^[a-z\d\-]+/;
|
|
1051
|
-
|
|
1052
|
-
// TODO handle case when extension is of type number|array|null|string
|
|
1053
|
-
const getPublisher = extension => {
|
|
1054
|
-
if (!extension || !extension.id) {
|
|
1055
|
-
return 'n/a';
|
|
1056
|
-
}
|
|
1057
|
-
// TODO handle case when id is not of type string -> should not crash application
|
|
1058
|
-
const match = extension.id.match(RE_PUBLISHER);
|
|
1059
|
-
if (!match) {
|
|
1060
|
-
return 'n/a';
|
|
1061
|
-
}
|
|
1062
|
-
return match[0];
|
|
1028
|
+
return getRemoteUrl(extension, platform);
|
|
1063
1029
|
};
|
|
1064
1030
|
const getName = extension => {
|
|
1065
1031
|
if (extension && extension.name) {
|
|
@@ -1083,6 +1049,21 @@ const getId = extension => {
|
|
|
1083
1049
|
return extension.id;
|
|
1084
1050
|
};
|
|
1085
1051
|
|
|
1052
|
+
const RE_PUBLISHER = /^[a-z\d-]+/;
|
|
1053
|
+
|
|
1054
|
+
// TODO handle case when extension is of type number|array|null|string
|
|
1055
|
+
const getPublisher = extension => {
|
|
1056
|
+
if (!extension || !extension.id) {
|
|
1057
|
+
return 'n/a';
|
|
1058
|
+
}
|
|
1059
|
+
// TODO handle case when id is not of type string -> should not crash application
|
|
1060
|
+
const match = extension.id.match(RE_PUBLISHER);
|
|
1061
|
+
if (!match) {
|
|
1062
|
+
return 'n/a';
|
|
1063
|
+
}
|
|
1064
|
+
return match[0];
|
|
1065
|
+
};
|
|
1066
|
+
|
|
1086
1067
|
const matchesParsedValue = (extension, parsedValue) => {
|
|
1087
1068
|
if (extension && typeof extension.name === 'string') {
|
|
1088
1069
|
const extensionNameLower = extension.name.toLowerCase();
|
|
@@ -1107,7 +1088,7 @@ const sortExtensions = extensions => {
|
|
|
1107
1088
|
return toSorted(extensions, compareExtension);
|
|
1108
1089
|
};
|
|
1109
1090
|
|
|
1110
|
-
const getExtensions = async (extensions, parsedValue) => {
|
|
1091
|
+
const getExtensions = async (extensions, parsedValue, platform) => {
|
|
1111
1092
|
const filteredExtensions = [];
|
|
1112
1093
|
for (const extension of extensions) {
|
|
1113
1094
|
if (matchesParsedValue(extension, parsedValue)) {
|
|
@@ -1115,7 +1096,7 @@ const getExtensions = async (extensions, parsedValue) => {
|
|
|
1115
1096
|
name: getName(extension),
|
|
1116
1097
|
id: getId(extension),
|
|
1117
1098
|
publisher: getPublisher(extension),
|
|
1118
|
-
icon: getIcon(extension),
|
|
1099
|
+
icon: getIcon(extension, platform),
|
|
1119
1100
|
description: getDescription(extension)
|
|
1120
1101
|
});
|
|
1121
1102
|
}
|
|
@@ -1124,10 +1105,10 @@ const getExtensions = async (extensions, parsedValue) => {
|
|
|
1124
1105
|
return sortedExtensions;
|
|
1125
1106
|
};
|
|
1126
1107
|
|
|
1127
|
-
const searchExtensions = async (extensions, value) => {
|
|
1108
|
+
const searchExtensions = async (extensions, value, platform$1) => {
|
|
1128
1109
|
try {
|
|
1129
1110
|
const parsedValue = parseValue(value);
|
|
1130
|
-
const filteredExtensions = await getExtensions(extensions, parsedValue);
|
|
1111
|
+
const filteredExtensions = await getExtensions(extensions, parsedValue, platform$1 || platform);
|
|
1131
1112
|
return filteredExtensions;
|
|
1132
1113
|
} catch (error) {
|
|
1133
1114
|
throw new VError(error, 'Failed to search for extensions');
|
|
@@ -1141,11 +1122,12 @@ const handleInput = async (state, value) => {
|
|
|
1141
1122
|
allExtensions,
|
|
1142
1123
|
itemHeight,
|
|
1143
1124
|
minimumSliderSize,
|
|
1144
|
-
height
|
|
1125
|
+
height,
|
|
1126
|
+
platform: platform$1
|
|
1145
1127
|
} = state;
|
|
1146
1128
|
// TODO cancel ongoing requests
|
|
1147
1129
|
// TODO handle errors
|
|
1148
|
-
const items = await searchExtensions(allExtensions, value);
|
|
1130
|
+
const items = await searchExtensions(allExtensions, value, platform$1 || platform);
|
|
1149
1131
|
if (items.length === 0) {
|
|
1150
1132
|
return {
|
|
1151
1133
|
...state,
|
|
@@ -1186,7 +1168,7 @@ const handleInput = async (state, value) => {
|
|
|
1186
1168
|
// TODO handle out of order responses (a bit complicated)
|
|
1187
1169
|
// for now just assume everything comes back in order
|
|
1188
1170
|
} catch (error) {
|
|
1189
|
-
|
|
1171
|
+
handleError(error);
|
|
1190
1172
|
return {
|
|
1191
1173
|
...state,
|
|
1192
1174
|
searchValue: value,
|
|
@@ -1458,6 +1440,7 @@ const getVisibleItem = (item, setSize, itemHeight, minLineY, relative, i, focuse
|
|
|
1458
1440
|
focused: i === focusedIndex
|
|
1459
1441
|
};
|
|
1460
1442
|
};
|
|
1443
|
+
|
|
1461
1444
|
const getVisible = state => {
|
|
1462
1445
|
const {
|
|
1463
1446
|
minLineY,
|
|
@@ -1491,6 +1474,12 @@ const SetMessage = 'setMessage';
|
|
|
1491
1474
|
const SetScrollBar = 'setScrollBar';
|
|
1492
1475
|
const SetSearchValue = 'setSearchValue';
|
|
1493
1476
|
|
|
1477
|
+
const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
|
|
1478
|
+
const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
|
|
1479
|
+
return scrollBarOffset;
|
|
1480
|
+
};
|
|
1481
|
+
const getScrollBarY = getScrollBarOffset;
|
|
1482
|
+
|
|
1494
1483
|
const getListHeight = state => {
|
|
1495
1484
|
const {
|
|
1496
1485
|
height,
|
|
@@ -1576,11 +1565,21 @@ const doRender = (oldState, newState) => {
|
|
|
1576
1565
|
return commands;
|
|
1577
1566
|
};
|
|
1578
1567
|
|
|
1568
|
+
const saveState = state => {
|
|
1569
|
+
const {
|
|
1570
|
+
searchValue
|
|
1571
|
+
} = state;
|
|
1572
|
+
return {
|
|
1573
|
+
searchValue
|
|
1574
|
+
};
|
|
1575
|
+
};
|
|
1576
|
+
|
|
1579
1577
|
const commandMap = {
|
|
1580
1578
|
'SearchExtensions.clearSearchResults': clearSearchResults,
|
|
1581
1579
|
'SearchExtensions.getKeyBindings': getKeyBindings,
|
|
1582
1580
|
'SearchExtensions.render': doRender,
|
|
1583
|
-
'SearchExtensions.searchExtensions': searchExtensions
|
|
1581
|
+
'SearchExtensions.searchExtensions': searchExtensions,
|
|
1582
|
+
'SearchExtensions.saveState': saveState
|
|
1584
1583
|
};
|
|
1585
1584
|
|
|
1586
1585
|
const RendererWorker = 1;
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/extension-search-view",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Extension Search View Worker",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Lvce Editor",
|
|
6
7
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
"author": "",
|
|
9
|
-
"license": "MIT"
|
|
8
|
+
"main": "dist/extensionSearchViewWorkerMain.js"
|
|
10
9
|
}
|