@lvce-editor/extension-search-view 1.5.0 → 2.0.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 = async (error, notify = true, prefix = '') => {
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
- ViewsAndMoreActions: 'Views and more Actions...',
873
- Extensions: 'Extensions',
874
- Installed: 'Installed'
875
- };
867
+ Extensions: 'Extensions'};
876
868
  const noExtensionsFound = () => {
877
869
  return i18nString(UiStrings.NoExtensionsFound);
878
870
  };
@@ -913,19 +905,43 @@ const getNumberOfVisibleItems = (listHeight, itemHeight) => {
913
905
  return Math.ceil(listHeight / itemHeight) + 1;
914
906
  };
915
907
 
908
+ const Web = 1;
909
+ const Electron = 2;
910
+ const Remote = 3;
911
+ const Test = 4;
912
+
913
+ // TODO treeshake this function out
914
+
916
915
  /**
917
- *
918
- * @param {number} size
919
- * @param {number} contentSize
920
- * @param {number} minimumSliderSize
921
- * @returns
916
+ * @returns {number}
922
917
  */
918
+ const getPlatform = () => {
919
+ // @ts-ignore
920
+ if (typeof PLATFORM !== 'undefined') {
921
+ // @ts-ignore
922
+ return PLATFORM;
923
+ }
924
+ if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
925
+ return Test;
926
+ }
927
+ // TODO find a better way to pass runtime environment
928
+ if (typeof name !== 'undefined' && name.endsWith('(Electron)')) {
929
+ return Electron;
930
+ }
931
+ if (typeof name !== 'undefined' && name.endsWith('(Web)')) {
932
+ return Web;
933
+ }
934
+ return Remote;
935
+ };
936
+ const platform = getPlatform();
937
+
923
938
  const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
924
939
  if (size >= contentSize) {
925
940
  return 0;
926
941
  }
927
942
  return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
928
943
  };
944
+
929
945
  const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
930
946
  const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
931
947
  return scrollBarOffset;
@@ -982,37 +998,7 @@ const parseValue = value => {
982
998
 
983
999
  const assetDir = '';
984
1000
 
985
- const Web = 1;
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 => {
1001
+ const getRemoteUrl = (extension, platform$1) => {
1016
1002
  if (platform === Remote || platform === Electron) {
1017
1003
  if (extension.builtin) {
1018
1004
  return `${assetDir}/extensions/${extension.id}/${extension.icon}`;
@@ -1032,7 +1018,7 @@ const isLanguageBasicsExtension = extension => {
1032
1018
  const isThemeExtension = extension => {
1033
1019
  return extension.name && extension.name.endsWith(' Theme');
1034
1020
  };
1035
- const getIcon = extension => {
1021
+ const getIcon = (extension, platform) => {
1036
1022
  if (!extension) {
1037
1023
  return ExtensionDefaultIcon;
1038
1024
  }
@@ -1047,7 +1033,7 @@ const getIcon = extension => {
1047
1033
  }
1048
1034
  return getRemoteUrl(extension);
1049
1035
  };
1050
- const RE_PUBLISHER = /^[a-z\d\-]+/;
1036
+ const RE_PUBLISHER = /^[a-z\d-]+/;
1051
1037
 
1052
1038
  // TODO handle case when extension is of type number|array|null|string
1053
1039
  const getPublisher = extension => {
@@ -1107,7 +1093,7 @@ const sortExtensions = extensions => {
1107
1093
  return toSorted(extensions, compareExtension);
1108
1094
  };
1109
1095
 
1110
- const getExtensions = async (extensions, parsedValue) => {
1096
+ const getExtensions = async (extensions, parsedValue, platform) => {
1111
1097
  const filteredExtensions = [];
1112
1098
  for (const extension of extensions) {
1113
1099
  if (matchesParsedValue(extension, parsedValue)) {
@@ -1124,10 +1110,10 @@ const getExtensions = async (extensions, parsedValue) => {
1124
1110
  return sortedExtensions;
1125
1111
  };
1126
1112
 
1127
- const searchExtensions = async (extensions, value) => {
1113
+ const searchExtensions = async (extensions, value, platform$1) => {
1128
1114
  try {
1129
1115
  const parsedValue = parseValue(value);
1130
- const filteredExtensions = await getExtensions(extensions, parsedValue);
1116
+ const filteredExtensions = await getExtensions(extensions, parsedValue, platform$1 || platform);
1131
1117
  return filteredExtensions;
1132
1118
  } catch (error) {
1133
1119
  throw new VError(error, 'Failed to search for extensions');
@@ -1141,11 +1127,12 @@ const handleInput = async (state, value) => {
1141
1127
  allExtensions,
1142
1128
  itemHeight,
1143
1129
  minimumSliderSize,
1144
- height
1130
+ height,
1131
+ platform: platform$1
1145
1132
  } = state;
1146
1133
  // TODO cancel ongoing requests
1147
1134
  // TODO handle errors
1148
- const items = await searchExtensions(allExtensions, value);
1135
+ const items = await searchExtensions(allExtensions, value, platform$1 || platform);
1149
1136
  if (items.length === 0) {
1150
1137
  return {
1151
1138
  ...state,
@@ -1186,7 +1173,7 @@ const handleInput = async (state, value) => {
1186
1173
  // TODO handle out of order responses (a bit complicated)
1187
1174
  // for now just assume everything comes back in order
1188
1175
  } catch (error) {
1189
- await handleError(error);
1176
+ handleError(error);
1190
1177
  return {
1191
1178
  ...state,
1192
1179
  searchValue: value,
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-search-view",
3
- "version": "1.5.0",
4
- "description": "",
5
- "main": "dist/extensionSearchViewWorkerMain.js",
3
+ "version": "2.0.0",
4
+ "description": "Extension Search View Worker",
5
+ "license": "MIT",
6
+ "author": "Lvce Editor",
6
7
  "type": "module",
7
- "keywords": [],
8
- "author": "",
9
- "license": "MIT"
8
+ "main": "dist/extensionSearchViewWorkerMain.js"
10
9
  }