@lvce-editor/extension-search-view 2.9.0 → 2.11.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/extensionSearchViewWorkerMain.js +161 -111
- package/package.json +1 -1
|
@@ -935,132 +935,68 @@ const RE_PARAM = /@\w+/g;
|
|
|
935
935
|
|
|
936
936
|
// TODO test sorting and filtering
|
|
937
937
|
const parseValue = value => {
|
|
938
|
-
|
|
938
|
+
let installed = false;
|
|
939
|
+
let enabled = false;
|
|
940
|
+
let disabled = false;
|
|
941
|
+
let builtin = false;
|
|
942
|
+
let sort = '';
|
|
943
|
+
let id = '';
|
|
944
|
+
let outdated = false;
|
|
939
945
|
// TODO this is not very functional code (assignment)
|
|
940
946
|
const replaced = value.replaceAll(RE_PARAM, (match, by, order) => {
|
|
941
947
|
if (match.startsWith(Installed)) {
|
|
942
|
-
|
|
948
|
+
installed = true;
|
|
943
949
|
}
|
|
944
950
|
if (match.startsWith(Enabled)) {
|
|
945
|
-
|
|
951
|
+
enabled = true;
|
|
946
952
|
}
|
|
947
953
|
if (match.startsWith(Disabled)) {
|
|
948
|
-
|
|
954
|
+
disabled = true;
|
|
949
955
|
}
|
|
950
956
|
if (match.startsWith(Builtin)) {
|
|
951
|
-
|
|
957
|
+
builtin = true;
|
|
952
958
|
}
|
|
953
959
|
if (match.startsWith(Sort)) {
|
|
954
960
|
// TODO
|
|
955
|
-
|
|
961
|
+
sort = 'installs';
|
|
956
962
|
}
|
|
957
963
|
if (match.startsWith(Id)) {
|
|
958
964
|
// TODO
|
|
959
|
-
|
|
965
|
+
id = 'abc';
|
|
960
966
|
}
|
|
961
967
|
if (match.startsWith(Outdated)) {
|
|
962
|
-
|
|
968
|
+
outdated = true;
|
|
963
969
|
}
|
|
964
970
|
return '';
|
|
965
971
|
});
|
|
966
|
-
const isLocal =
|
|
972
|
+
const isLocal = enabled || builtin || disabled || outdated || installed;
|
|
967
973
|
return {
|
|
968
974
|
query: replaced,
|
|
969
|
-
|
|
975
|
+
enabled,
|
|
976
|
+
builtin,
|
|
977
|
+
disabled,
|
|
978
|
+
outdated,
|
|
979
|
+
installed,
|
|
980
|
+
id,
|
|
981
|
+
sort,
|
|
970
982
|
isLocal
|
|
971
983
|
};
|
|
972
984
|
};
|
|
973
985
|
|
|
974
|
-
const
|
|
975
|
-
const
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
const getRemoteUrl = (extension, platform, assetDir) => {
|
|
979
|
-
if (platform === Remote || platform === Electron) {
|
|
980
|
-
if (extension.builtin) {
|
|
981
|
-
return `${assetDir}/extensions/${extension.id}/${extension.icon}`;
|
|
982
|
-
}
|
|
983
|
-
return `/remote/${extension.path}/${extension.icon}`; // TODO support windows paths
|
|
984
|
-
}
|
|
985
|
-
return '';
|
|
986
|
-
};
|
|
987
|
-
|
|
988
|
-
const getExtensionDefaultIcon = assetDir => {
|
|
989
|
-
return `${assetDir}/icons/extensionDefaultIcon.png`;
|
|
990
|
-
};
|
|
991
|
-
const getExtensionLanguageBasicsIcon = assetDir => {
|
|
992
|
-
return `${assetDir}/icons/language-icon.svg`;
|
|
993
|
-
};
|
|
994
|
-
const getExtensionThemeIcon = assetDir => {
|
|
995
|
-
return `${assetDir}/icons/theme-icon.png`;
|
|
996
|
-
};
|
|
997
|
-
|
|
998
|
-
const isLanguageBasicsExtension = extension => {
|
|
999
|
-
return extension.name && extension.name.startsWith('Language Basics');
|
|
1000
|
-
};
|
|
1001
|
-
const isThemeExtension = extension => {
|
|
1002
|
-
return extension.name && extension.name.endsWith(' Theme');
|
|
1003
|
-
};
|
|
1004
|
-
const getIcon = (extension, platform, assetDir) => {
|
|
1005
|
-
if (!extension) {
|
|
1006
|
-
return getExtensionDefaultIcon(assetDir);
|
|
1007
|
-
}
|
|
1008
|
-
if (!extension.path || !extension.icon) {
|
|
1009
|
-
if (isLanguageBasicsExtension(extension)) {
|
|
1010
|
-
return getExtensionLanguageBasicsIcon(assetDir);
|
|
1011
|
-
}
|
|
1012
|
-
if (isThemeExtension(extension)) {
|
|
1013
|
-
return getExtensionThemeIcon(assetDir);
|
|
1014
|
-
}
|
|
1015
|
-
return getExtensionDefaultIcon(assetDir);
|
|
1016
|
-
}
|
|
1017
|
-
return getRemoteUrl(extension, platform, assetDir);
|
|
1018
|
-
};
|
|
1019
|
-
const getName = extension => {
|
|
1020
|
-
if (extension && extension.name) {
|
|
1021
|
-
return extension.name;
|
|
1022
|
-
}
|
|
1023
|
-
if (extension && extension.id) {
|
|
1024
|
-
return extension.id;
|
|
1025
|
-
}
|
|
1026
|
-
return 'n/a';
|
|
986
|
+
const matchesName = (extension, query) => {
|
|
987
|
+
const extensionNameLower = extension.name.toLowerCase();
|
|
988
|
+
return extensionNameLower.includes(query);
|
|
1027
989
|
};
|
|
1028
|
-
const
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
}
|
|
1032
|
-
return extension.description;
|
|
1033
|
-
};
|
|
1034
|
-
const getId = extension => {
|
|
1035
|
-
if (!extension || !extension.id) {
|
|
1036
|
-
return 'n/a';
|
|
1037
|
-
}
|
|
1038
|
-
return extension.id;
|
|
1039
|
-
};
|
|
1040
|
-
|
|
1041
|
-
const RE_PUBLISHER = /^[a-z\d-]+/;
|
|
1042
|
-
|
|
1043
|
-
// TODO handle case when extension is of type number|array|null|string
|
|
1044
|
-
const getPublisher = extension => {
|
|
1045
|
-
if (!extension || !extension.id) {
|
|
1046
|
-
return 'n/a';
|
|
1047
|
-
}
|
|
1048
|
-
// TODO handle case when id is not of type string -> should not crash application
|
|
1049
|
-
const match = extension.id.match(RE_PUBLISHER);
|
|
1050
|
-
if (!match) {
|
|
1051
|
-
return 'n/a';
|
|
1052
|
-
}
|
|
1053
|
-
return match[0];
|
|
990
|
+
const matchesId = (extension, query) => {
|
|
991
|
+
const extensionIdLower = extension.id.toLowerCase();
|
|
992
|
+
return extensionIdLower.includes(query);
|
|
1054
993
|
};
|
|
1055
|
-
|
|
1056
994
|
const matchesParsedValue = (extension, parsedValue) => {
|
|
1057
|
-
if (extension
|
|
1058
|
-
|
|
1059
|
-
return extensionNameLower.includes(parsedValue.query);
|
|
995
|
+
if (extension.name) {
|
|
996
|
+
return matchesName(extension, parsedValue.query);
|
|
1060
997
|
}
|
|
1061
|
-
if (extension
|
|
1062
|
-
|
|
1063
|
-
return extensionIdLower.includes(parsedValue.query);
|
|
998
|
+
if (extension.id) {
|
|
999
|
+
return matchesId(extension, parsedValue.query);
|
|
1064
1000
|
}
|
|
1065
1001
|
return false;
|
|
1066
1002
|
};
|
|
@@ -1083,17 +1019,11 @@ const sortExtensions = extensions => {
|
|
|
1083
1019
|
return toSorted(extensions, compareExtension);
|
|
1084
1020
|
};
|
|
1085
1021
|
|
|
1086
|
-
const getExtensions = async (extensions, parsedValue
|
|
1022
|
+
const getExtensions = async (extensions, parsedValue) => {
|
|
1087
1023
|
const filteredExtensions = [];
|
|
1088
1024
|
for (const extension of extensions) {
|
|
1089
1025
|
if (matchesParsedValue(extension, parsedValue)) {
|
|
1090
|
-
filteredExtensions.push(
|
|
1091
|
-
name: getName(extension),
|
|
1092
|
-
id: getId(extension),
|
|
1093
|
-
publisher: getPublisher(extension),
|
|
1094
|
-
icon: getIcon(extension, platform, assetDir),
|
|
1095
|
-
description: getDescription(extension)
|
|
1096
|
-
});
|
|
1026
|
+
filteredExtensions.push(extension);
|
|
1097
1027
|
}
|
|
1098
1028
|
}
|
|
1099
1029
|
const sortedExtensions = sortExtensions(filteredExtensions);
|
|
@@ -1103,7 +1033,7 @@ const getExtensions = async (extensions, parsedValue, platform, assetDir) => {
|
|
|
1103
1033
|
const searchExtensions = async (extensions, value, platform, assetDir) => {
|
|
1104
1034
|
try {
|
|
1105
1035
|
const parsedValue = parseValue(value);
|
|
1106
|
-
const filteredExtensions = await getExtensions(extensions, parsedValue
|
|
1036
|
+
const filteredExtensions = await getExtensions(extensions, parsedValue);
|
|
1107
1037
|
return filteredExtensions;
|
|
1108
1038
|
} catch (error) {
|
|
1109
1039
|
throw new VError(error, 'Failed to search for extensions');
|
|
@@ -1412,7 +1342,7 @@ const getActions = () => {
|
|
|
1412
1342
|
}];
|
|
1413
1343
|
};
|
|
1414
1344
|
|
|
1415
|
-
const commandIds = ['clearSearchResults', 'closeSuggest', 'focusFirst', 'focusLast', 'focusNext', 'focusNextPage', 'focusPrevious', 'focusPreviousPage', 'handleBlur', 'handleClick', 'handleContextMenu', 'handleDisable', 'handleFocus', 'handleInput', 'handleInstall', 'handleScrollBarCaptureLost', 'handleScrollBarClick', 'handleScrollBarMove', 'handleUninstall', 'handleWheel', 'openSuggest', 'render', 'saveState', 'scrollDown', 'selectIndex', 'setDeltaY', 'toggleSuggest'];
|
|
1345
|
+
const commandIds = ['clearSearchResults', 'closeSuggest', 'focusFirst', 'focusLast', 'focusNext', 'focusNextPage', 'focusPrevious', 'focusPreviousPage', 'handleBlur', 'handleClick', 'handleContextMenu', 'handleDisable', 'handleFocus', 'handleInput', 'handleInstall', 'handleScrollBarCaptureLost', 'handleScrollBarClick', 'handleScrollBarMove', 'handleUninstall', 'handleWheel', 'openSuggest', 'render', 'saveState', 'scrollDown', 'selectIndex', 'setDeltaY', 'toggleSuggest', 'handleScrollBarThumbPointerMove'];
|
|
1416
1346
|
|
|
1417
1347
|
const getCommandIds = () => {
|
|
1418
1348
|
return commandIds;
|
|
@@ -1724,13 +1654,21 @@ const handleWheel = (state, deltaMode, deltaY) => {
|
|
|
1724
1654
|
return setDeltaY(state, state.deltaY + deltaY);
|
|
1725
1655
|
};
|
|
1726
1656
|
|
|
1727
|
-
const
|
|
1657
|
+
const Web = 1;
|
|
1658
|
+
const Electron = 2;
|
|
1659
|
+
const Remote = 3;
|
|
1660
|
+
|
|
1661
|
+
const getAllExtensions$1 = async platform => {
|
|
1728
1662
|
if (platform === Web) {
|
|
1729
1663
|
return [];
|
|
1730
1664
|
}
|
|
1731
1665
|
return invoke('ExtensionManagement.getAllExtensions');
|
|
1732
1666
|
};
|
|
1733
1667
|
|
|
1668
|
+
const getAllExtensions = platform => {
|
|
1669
|
+
return getAllExtensions$1(platform);
|
|
1670
|
+
};
|
|
1671
|
+
|
|
1734
1672
|
const Small = 1;
|
|
1735
1673
|
const Normal = 2;
|
|
1736
1674
|
const Large = 3;
|
|
@@ -1748,6 +1686,103 @@ const getViewletSize = width => {
|
|
|
1748
1686
|
const User = 1;
|
|
1749
1687
|
const Script = 2;
|
|
1750
1688
|
|
|
1689
|
+
const getRemoteUrl = (extension, platform, assetDir) => {
|
|
1690
|
+
if (platform === Remote || platform === Electron) {
|
|
1691
|
+
if (extension.builtin) {
|
|
1692
|
+
return `${assetDir}/extensions/${extension.id}/${extension.icon}`;
|
|
1693
|
+
}
|
|
1694
|
+
return `/remote/${extension.path}/${extension.icon}`; // TODO support windows paths
|
|
1695
|
+
}
|
|
1696
|
+
return '';
|
|
1697
|
+
};
|
|
1698
|
+
|
|
1699
|
+
const getExtensionDefaultIcon = assetDir => {
|
|
1700
|
+
return `${assetDir}/icons/extensionDefaultIcon.png`;
|
|
1701
|
+
};
|
|
1702
|
+
const getExtensionLanguageBasicsIcon = assetDir => {
|
|
1703
|
+
return `${assetDir}/icons/language-icon.svg`;
|
|
1704
|
+
};
|
|
1705
|
+
const getExtensionThemeIcon = assetDir => {
|
|
1706
|
+
return `${assetDir}/icons/theme-icon.png`;
|
|
1707
|
+
};
|
|
1708
|
+
|
|
1709
|
+
const isLanguageBasicsExtension = extension => {
|
|
1710
|
+
return extension.name && extension.name.startsWith('Language Basics');
|
|
1711
|
+
};
|
|
1712
|
+
const isThemeExtension = extension => {
|
|
1713
|
+
return extension.name && extension.name.endsWith(' Theme');
|
|
1714
|
+
};
|
|
1715
|
+
const getIcon = (extension, platform, assetDir) => {
|
|
1716
|
+
if (!extension) {
|
|
1717
|
+
return getExtensionDefaultIcon(assetDir);
|
|
1718
|
+
}
|
|
1719
|
+
if (!extension.path || !extension.icon) {
|
|
1720
|
+
if (isLanguageBasicsExtension(extension)) {
|
|
1721
|
+
return getExtensionLanguageBasicsIcon(assetDir);
|
|
1722
|
+
}
|
|
1723
|
+
if (isThemeExtension(extension)) {
|
|
1724
|
+
return getExtensionThemeIcon(assetDir);
|
|
1725
|
+
}
|
|
1726
|
+
return getExtensionDefaultIcon(assetDir);
|
|
1727
|
+
}
|
|
1728
|
+
return getRemoteUrl(extension, platform, assetDir);
|
|
1729
|
+
};
|
|
1730
|
+
const getName = extension => {
|
|
1731
|
+
if (extension && extension.name) {
|
|
1732
|
+
return extension.name;
|
|
1733
|
+
}
|
|
1734
|
+
if (extension && extension.id) {
|
|
1735
|
+
return extension.id;
|
|
1736
|
+
}
|
|
1737
|
+
return 'n/a';
|
|
1738
|
+
};
|
|
1739
|
+
const getDescription = extension => {
|
|
1740
|
+
if (!extension || !extension.description) {
|
|
1741
|
+
return 'n/a';
|
|
1742
|
+
}
|
|
1743
|
+
return extension.description;
|
|
1744
|
+
};
|
|
1745
|
+
const getId = extension => {
|
|
1746
|
+
if (!extension || !extension.id) {
|
|
1747
|
+
return 'n/a';
|
|
1748
|
+
}
|
|
1749
|
+
return extension.id;
|
|
1750
|
+
};
|
|
1751
|
+
|
|
1752
|
+
const RE_PUBLISHER = /^[a-z\d-]+/;
|
|
1753
|
+
|
|
1754
|
+
// TODO handle case when extension is of type number|array|null|string
|
|
1755
|
+
const getPublisher = extension => {
|
|
1756
|
+
if (!extension || !extension.id) {
|
|
1757
|
+
return 'n/a';
|
|
1758
|
+
}
|
|
1759
|
+
// TODO handle case when id is not of type string -> should not crash application
|
|
1760
|
+
const match = extension.id.match(RE_PUBLISHER);
|
|
1761
|
+
if (!match) {
|
|
1762
|
+
return 'n/a';
|
|
1763
|
+
}
|
|
1764
|
+
return match[0];
|
|
1765
|
+
};
|
|
1766
|
+
|
|
1767
|
+
const normalizeExtension$1 = (extension, platform, assetDir) => {
|
|
1768
|
+
return {
|
|
1769
|
+
id: getId(extension),
|
|
1770
|
+
name: getName(extension),
|
|
1771
|
+
description: getDescription(extension),
|
|
1772
|
+
uri: '',
|
|
1773
|
+
publisher: getPublisher(extension),
|
|
1774
|
+
icon: getIcon(extension, platform, assetDir)
|
|
1775
|
+
};
|
|
1776
|
+
};
|
|
1777
|
+
|
|
1778
|
+
const normalizeExtension = (extensions, platform, assetDir) => {
|
|
1779
|
+
const normalized = [];
|
|
1780
|
+
for (const extension of extensions) {
|
|
1781
|
+
normalized.push(normalizeExtension$1(extension, platform, assetDir));
|
|
1782
|
+
}
|
|
1783
|
+
return normalized;
|
|
1784
|
+
};
|
|
1785
|
+
|
|
1751
1786
|
const getSavedValue = savedState => {
|
|
1752
1787
|
if (savedState && typeof savedState === 'object' && 'searchValue' in savedState && typeof savedState.searchValue === 'string') {
|
|
1753
1788
|
return savedState.searchValue;
|
|
@@ -1768,7 +1803,8 @@ const loadContent = async (uid, savedState) => {
|
|
|
1768
1803
|
} = get$1(uid);
|
|
1769
1804
|
const {
|
|
1770
1805
|
width,
|
|
1771
|
-
platform
|
|
1806
|
+
platform,
|
|
1807
|
+
assetDir
|
|
1772
1808
|
} = newState;
|
|
1773
1809
|
const {
|
|
1774
1810
|
searchValue
|
|
@@ -1776,9 +1812,10 @@ const loadContent = async (uid, savedState) => {
|
|
|
1776
1812
|
// TODO just get local extensions on demand (not when query string is already different)
|
|
1777
1813
|
const allExtensions = await getAllExtensions(platform);
|
|
1778
1814
|
const size = getViewletSize(width);
|
|
1815
|
+
const normalized = normalizeExtension(allExtensions, platform, assetDir);
|
|
1779
1816
|
const updatedState = await handleInput({
|
|
1780
1817
|
...newState,
|
|
1781
|
-
allExtensions,
|
|
1818
|
+
allExtensions: normalized,
|
|
1782
1819
|
size,
|
|
1783
1820
|
inputSource: Script
|
|
1784
1821
|
}, searchValue);
|
|
@@ -2131,12 +2168,24 @@ const getExtensionsVirtualDom = visibleExtensions => {
|
|
|
2131
2168
|
};
|
|
2132
2169
|
|
|
2133
2170
|
const getVisibleItem = (item, setSize, itemHeight, minLineY, relative, i, focusedIndex) => {
|
|
2171
|
+
// TODO use normal parameters
|
|
2172
|
+
const {
|
|
2173
|
+
publisher,
|
|
2174
|
+
description,
|
|
2175
|
+
icon,
|
|
2176
|
+
id,
|
|
2177
|
+
name
|
|
2178
|
+
} = item;
|
|
2134
2179
|
return {
|
|
2135
|
-
...item,
|
|
2136
2180
|
setSize,
|
|
2137
2181
|
posInSet: i + 1,
|
|
2138
2182
|
top: (i - minLineY) * itemHeight - relative,
|
|
2139
|
-
focused: i === focusedIndex
|
|
2183
|
+
focused: i === focusedIndex,
|
|
2184
|
+
publisher,
|
|
2185
|
+
description,
|
|
2186
|
+
icon,
|
|
2187
|
+
id,
|
|
2188
|
+
name
|
|
2140
2189
|
};
|
|
2141
2190
|
};
|
|
2142
2191
|
|
|
@@ -2382,6 +2431,7 @@ const commandMap = {
|
|
|
2382
2431
|
'SearchExtensions.handleScrollBarCaptureLost': wrapCommand(handleScrollBarCaptureLost),
|
|
2383
2432
|
'SearchExtensions.handleScrollBarClick': wrapCommand(handleScrollBarClick),
|
|
2384
2433
|
'SearchExtensions.handleScrollBarMove': wrapCommand(handleScrollBarMove),
|
|
2434
|
+
'SearchExtensions.handleScrollBarThumbPointerMove': wrapCommand(handleScrollBarMove),
|
|
2385
2435
|
'SearchExtensions.handleUninstall': wrapCommand(handleUninstall),
|
|
2386
2436
|
'SearchExtensions.handleWheel': wrapCommand(handleWheel),
|
|
2387
2437
|
'SearchExtensions.loadContent': loadContent,
|