@lvce-editor/extension-search-view 2.0.0 → 2.2.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.
|
@@ -82,6 +82,12 @@ const getType = value => {
|
|
|
82
82
|
return 'unknown';
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
+
const object = value => {
|
|
86
|
+
const type = getType(value);
|
|
87
|
+
if (type !== 'object') {
|
|
88
|
+
throw new AssertionError('expected value to be of type object');
|
|
89
|
+
}
|
|
90
|
+
};
|
|
85
91
|
const number = value => {
|
|
86
92
|
const type = getType(value);
|
|
87
93
|
if (type !== 'number') {
|
|
@@ -424,10 +430,10 @@ const create$4 = (method, params) => {
|
|
|
424
430
|
};
|
|
425
431
|
};
|
|
426
432
|
const callbacks = Object.create(null);
|
|
427
|
-
const set$
|
|
433
|
+
const set$2 = (id, fn) => {
|
|
428
434
|
callbacks[id] = fn;
|
|
429
435
|
};
|
|
430
|
-
const get = id => {
|
|
436
|
+
const get$2 = id => {
|
|
431
437
|
return callbacks[id];
|
|
432
438
|
};
|
|
433
439
|
const remove = id => {
|
|
@@ -443,7 +449,7 @@ const registerPromise = () => {
|
|
|
443
449
|
resolve,
|
|
444
450
|
promise
|
|
445
451
|
} = Promise.withResolvers();
|
|
446
|
-
set$
|
|
452
|
+
set$2(id, resolve);
|
|
447
453
|
return {
|
|
448
454
|
id,
|
|
449
455
|
promise
|
|
@@ -600,7 +606,7 @@ const warn = (...args) => {
|
|
|
600
606
|
console.warn(...args);
|
|
601
607
|
};
|
|
602
608
|
const resolve = (id, response) => {
|
|
603
|
-
const fn = get(id);
|
|
609
|
+
const fn = get$2(id);
|
|
604
610
|
if (!fn) {
|
|
605
611
|
console.log(response);
|
|
606
612
|
warn(`callback ${id} may already be disposed`);
|
|
@@ -639,7 +645,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
639
645
|
}
|
|
640
646
|
};
|
|
641
647
|
};
|
|
642
|
-
const create$1 = (message, error) => {
|
|
648
|
+
const create$1$1 = (message, error) => {
|
|
643
649
|
return {
|
|
644
650
|
jsonrpc: Two,
|
|
645
651
|
id: message.id,
|
|
@@ -650,7 +656,7 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
|
650
656
|
const prettyError = preparePrettyError(error);
|
|
651
657
|
logError(error, prettyError);
|
|
652
658
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
653
|
-
return create$1(message, errorProperty);
|
|
659
|
+
return create$1$1(message, errorProperty);
|
|
654
660
|
};
|
|
655
661
|
const create$5 = (message, result) => {
|
|
656
662
|
return {
|
|
@@ -754,7 +760,7 @@ const send = (transport, method, ...params) => {
|
|
|
754
760
|
const message = create$4(method, params);
|
|
755
761
|
transport.send(message);
|
|
756
762
|
};
|
|
757
|
-
const invoke = (ipc, method, ...params) => {
|
|
763
|
+
const invoke$1 = (ipc, method, ...params) => {
|
|
758
764
|
return invokeHelper(ipc, method, params, false);
|
|
759
765
|
};
|
|
760
766
|
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
@@ -787,7 +793,7 @@ const createRpc = ipc => {
|
|
|
787
793
|
send(ipc, method, ...params);
|
|
788
794
|
},
|
|
789
795
|
invoke(method, ...params) {
|
|
790
|
-
return invoke(ipc, method, ...params);
|
|
796
|
+
return invoke$1(ipc, method, ...params);
|
|
791
797
|
},
|
|
792
798
|
invokeAndTransfer(method, ...params) {
|
|
793
799
|
return invokeAndTransfer(ipc, method, ...params);
|
|
@@ -825,7 +831,7 @@ const listen$1 = async (module, options) => {
|
|
|
825
831
|
const ipc = module.wrap(rawIpc);
|
|
826
832
|
return ipc;
|
|
827
833
|
};
|
|
828
|
-
const create = async ({
|
|
834
|
+
const create$1 = async ({
|
|
829
835
|
commandMap
|
|
830
836
|
}) => {
|
|
831
837
|
// TODO create a commandMap per rpc instance
|
|
@@ -837,7 +843,7 @@ const create = async ({
|
|
|
837
843
|
};
|
|
838
844
|
const WebWorkerRpcClient = {
|
|
839
845
|
__proto__: null,
|
|
840
|
-
create
|
|
846
|
+
create: create$1
|
|
841
847
|
};
|
|
842
848
|
|
|
843
849
|
const handleError = (error, notify = true, prefix = '') => {
|
|
@@ -856,29 +862,34 @@ const i18nString = (key, placeholders = emptyObject) => {
|
|
|
856
862
|
return key.replaceAll(RE_PLACEHOLDER, replacer);
|
|
857
863
|
};
|
|
858
864
|
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
const
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
Extensions: 'Extensions'};
|
|
865
|
+
const NoExtensionsFound = 'No extensions found.';
|
|
866
|
+
const Filter$1 = 'Filter';
|
|
867
|
+
const Refresh$1 = 'Refresh';
|
|
868
|
+
const ClearExtensionSearchResults = 'Clear extension search results';
|
|
869
|
+
const SearchExtensionsInMarketplace = 'Search Extensions in Marketplace';
|
|
870
|
+
const ViewsAndMoreActions = 'Views and more Actions...';
|
|
871
|
+
const Extensions = 'Extensions';
|
|
872
|
+
|
|
868
873
|
const noExtensionsFound = () => {
|
|
869
|
-
return i18nString(
|
|
874
|
+
return i18nString(NoExtensionsFound);
|
|
870
875
|
};
|
|
871
876
|
const filter = () => {
|
|
872
|
-
return i18nString(
|
|
877
|
+
return i18nString(Filter$1);
|
|
878
|
+
};
|
|
879
|
+
const refresh = () => {
|
|
880
|
+
return i18nString(Refresh$1);
|
|
873
881
|
};
|
|
874
882
|
const extensions = () => {
|
|
875
|
-
return i18nString(
|
|
883
|
+
return i18nString(Extensions);
|
|
876
884
|
};
|
|
877
885
|
const clearExtensionSearchResults = () => {
|
|
878
|
-
return i18nString(
|
|
886
|
+
return i18nString(ClearExtensionSearchResults);
|
|
879
887
|
};
|
|
880
888
|
const searchExtensionsInMarketPlace = () => {
|
|
881
|
-
return i18nString(
|
|
889
|
+
return i18nString(SearchExtensionsInMarketplace);
|
|
890
|
+
};
|
|
891
|
+
const viewsAndMoreActions = () => {
|
|
892
|
+
return i18nString(ViewsAndMoreActions);
|
|
882
893
|
};
|
|
883
894
|
|
|
884
895
|
const getFinalDeltaY = (height, itemHeight, itemsLength) => {
|
|
@@ -905,6 +916,13 @@ const getNumberOfVisibleItems = (listHeight, itemHeight) => {
|
|
|
905
916
|
return Math.ceil(listHeight / itemHeight) + 1;
|
|
906
917
|
};
|
|
907
918
|
|
|
919
|
+
const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
|
|
920
|
+
if (size >= contentSize) {
|
|
921
|
+
return 0;
|
|
922
|
+
}
|
|
923
|
+
return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
|
|
924
|
+
};
|
|
925
|
+
|
|
908
926
|
const Web = 1;
|
|
909
927
|
const Electron = 2;
|
|
910
928
|
const Remote = 3;
|
|
@@ -935,19 +953,6 @@ const getPlatform = () => {
|
|
|
935
953
|
};
|
|
936
954
|
const platform = getPlatform();
|
|
937
955
|
|
|
938
|
-
const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
|
|
939
|
-
if (size >= contentSize) {
|
|
940
|
-
return 0;
|
|
941
|
-
}
|
|
942
|
-
return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
|
|
943
|
-
};
|
|
944
|
-
|
|
945
|
-
const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
|
|
946
|
-
const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
|
|
947
|
-
return scrollBarOffset;
|
|
948
|
-
};
|
|
949
|
-
const getScrollBarY = getScrollBarOffset;
|
|
950
|
-
|
|
951
956
|
const Installed = '@installed';
|
|
952
957
|
const Enabled = '@enabled';
|
|
953
958
|
const Disabled = '@disabled';
|
|
@@ -998,7 +1003,7 @@ const parseValue = value => {
|
|
|
998
1003
|
|
|
999
1004
|
const assetDir = '';
|
|
1000
1005
|
|
|
1001
|
-
const getRemoteUrl = (extension, platform
|
|
1006
|
+
const getRemoteUrl = (extension, platform) => {
|
|
1002
1007
|
if (platform === Remote || platform === Electron) {
|
|
1003
1008
|
if (extension.builtin) {
|
|
1004
1009
|
return `${assetDir}/extensions/${extension.id}/${extension.icon}`;
|
|
@@ -1031,21 +1036,7 @@ const getIcon = (extension, platform) => {
|
|
|
1031
1036
|
}
|
|
1032
1037
|
return ExtensionDefaultIcon;
|
|
1033
1038
|
}
|
|
1034
|
-
return getRemoteUrl(extension);
|
|
1035
|
-
};
|
|
1036
|
-
const RE_PUBLISHER = /^[a-z\d-]+/;
|
|
1037
|
-
|
|
1038
|
-
// TODO handle case when extension is of type number|array|null|string
|
|
1039
|
-
const getPublisher = extension => {
|
|
1040
|
-
if (!extension || !extension.id) {
|
|
1041
|
-
return 'n/a';
|
|
1042
|
-
}
|
|
1043
|
-
// TODO handle case when id is not of type string -> should not crash application
|
|
1044
|
-
const match = extension.id.match(RE_PUBLISHER);
|
|
1045
|
-
if (!match) {
|
|
1046
|
-
return 'n/a';
|
|
1047
|
-
}
|
|
1048
|
-
return match[0];
|
|
1039
|
+
return getRemoteUrl(extension, platform);
|
|
1049
1040
|
};
|
|
1050
1041
|
const getName = extension => {
|
|
1051
1042
|
if (extension && extension.name) {
|
|
@@ -1069,6 +1060,21 @@ const getId = extension => {
|
|
|
1069
1060
|
return extension.id;
|
|
1070
1061
|
};
|
|
1071
1062
|
|
|
1063
|
+
const RE_PUBLISHER = /^[a-z\d-]+/;
|
|
1064
|
+
|
|
1065
|
+
// TODO handle case when extension is of type number|array|null|string
|
|
1066
|
+
const getPublisher = extension => {
|
|
1067
|
+
if (!extension || !extension.id) {
|
|
1068
|
+
return 'n/a';
|
|
1069
|
+
}
|
|
1070
|
+
// TODO handle case when id is not of type string -> should not crash application
|
|
1071
|
+
const match = extension.id.match(RE_PUBLISHER);
|
|
1072
|
+
if (!match) {
|
|
1073
|
+
return 'n/a';
|
|
1074
|
+
}
|
|
1075
|
+
return match[0];
|
|
1076
|
+
};
|
|
1077
|
+
|
|
1072
1078
|
const matchesParsedValue = (extension, parsedValue) => {
|
|
1073
1079
|
if (extension && typeof extension.name === 'string') {
|
|
1074
1080
|
const extensionNameLower = extension.name.toLowerCase();
|
|
@@ -1101,7 +1107,7 @@ const getExtensions = async (extensions, parsedValue, platform) => {
|
|
|
1101
1107
|
name: getName(extension),
|
|
1102
1108
|
id: getId(extension),
|
|
1103
1109
|
publisher: getPublisher(extension),
|
|
1104
|
-
icon: getIcon(extension),
|
|
1110
|
+
icon: getIcon(extension, platform),
|
|
1105
1111
|
description: getDescription(extension)
|
|
1106
1112
|
});
|
|
1107
1113
|
}
|
|
@@ -1186,6 +1192,160 @@ const clearSearchResults = state => {
|
|
|
1186
1192
|
return handleInput(state, '');
|
|
1187
1193
|
};
|
|
1188
1194
|
|
|
1195
|
+
const closeSuggest = () => {
|
|
1196
|
+
// TODO
|
|
1197
|
+
};
|
|
1198
|
+
|
|
1199
|
+
const states = Object.create(null);
|
|
1200
|
+
const get$1 = uid => {
|
|
1201
|
+
return states[uid];
|
|
1202
|
+
};
|
|
1203
|
+
const set$1 = (uid, oldState, newState) => {
|
|
1204
|
+
states[uid] = {
|
|
1205
|
+
oldState,
|
|
1206
|
+
newState
|
|
1207
|
+
};
|
|
1208
|
+
};
|
|
1209
|
+
|
|
1210
|
+
const create = (id, uri, x, y, width, height, platform) => {
|
|
1211
|
+
const state = {
|
|
1212
|
+
searchValue: '',
|
|
1213
|
+
minLineY: 0,
|
|
1214
|
+
maxLineY: 0,
|
|
1215
|
+
itemHeight: 0,
|
|
1216
|
+
items: [],
|
|
1217
|
+
height,
|
|
1218
|
+
message: '',
|
|
1219
|
+
allExtensions: [],
|
|
1220
|
+
placeholder: '',
|
|
1221
|
+
platform,
|
|
1222
|
+
finalDeltaY: 0,
|
|
1223
|
+
focusedIndex: 0,
|
|
1224
|
+
minimumSliderSize: 0,
|
|
1225
|
+
deltaY: 0,
|
|
1226
|
+
headerHeight: 0,
|
|
1227
|
+
scrollBarHeight: 0,
|
|
1228
|
+
width,
|
|
1229
|
+
size: 0,
|
|
1230
|
+
negativeMargin: 0,
|
|
1231
|
+
scrollBarActive: false
|
|
1232
|
+
};
|
|
1233
|
+
set$1(id, state, state);
|
|
1234
|
+
};
|
|
1235
|
+
|
|
1236
|
+
const RenderItems = 4;
|
|
1237
|
+
const RenderScrollBar = 5;
|
|
1238
|
+
|
|
1239
|
+
const diffType$1 = RenderItems;
|
|
1240
|
+
const isEqual$1 = (oldState, newState) => {
|
|
1241
|
+
return true;
|
|
1242
|
+
};
|
|
1243
|
+
|
|
1244
|
+
const diffType = RenderScrollBar;
|
|
1245
|
+
const isEqual = (oldState, newState) => {
|
|
1246
|
+
return oldState.negativeMargin === newState.negativeMargin && oldState.deltaY === newState.deltaY && oldState.height === newState.height && oldState.finalDeltaY === newState.finalDeltaY && oldState.items.length === newState.items.length && oldState.scrollBarActive === newState.scrollBarActive;
|
|
1247
|
+
};
|
|
1248
|
+
|
|
1249
|
+
const modules = [isEqual$1, isEqual];
|
|
1250
|
+
const numbers = [diffType$1, diffType];
|
|
1251
|
+
|
|
1252
|
+
const diff = (oldState, newState) => {
|
|
1253
|
+
const diffResult = [];
|
|
1254
|
+
for (let i = 0; i < modules.length; i++) {
|
|
1255
|
+
const fn = modules[i];
|
|
1256
|
+
if (!fn(oldState, newState)) {
|
|
1257
|
+
diffResult.push(numbers[i]);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
return diffResult;
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1263
|
+
const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength) => {
|
|
1264
|
+
const newMaxLineY = Math.min(index + 1, itemsLength);
|
|
1265
|
+
const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
1266
|
+
const newMinLineY = Math.max(newMaxLineY - fittingItems, 0);
|
|
1267
|
+
const newDeltaY = itemsLength < fittingItems ? 0 : newMinLineY * itemHeight - listHeight % itemHeight + itemHeight;
|
|
1268
|
+
return {
|
|
1269
|
+
...state,
|
|
1270
|
+
focusedIndex: index,
|
|
1271
|
+
minLineY: newMinLineY,
|
|
1272
|
+
maxLineY: newMaxLineY,
|
|
1273
|
+
focused: true,
|
|
1274
|
+
deltaY: newDeltaY
|
|
1275
|
+
};
|
|
1276
|
+
};
|
|
1277
|
+
|
|
1278
|
+
const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) => {
|
|
1279
|
+
const newMinLineY = index;
|
|
1280
|
+
const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
1281
|
+
const newMaxLineY = Math.min(newMinLineY + fittingItems, itemsLength);
|
|
1282
|
+
const newDeltaY = newMinLineY * itemHeight;
|
|
1283
|
+
return {
|
|
1284
|
+
...state,
|
|
1285
|
+
focusedIndex: index,
|
|
1286
|
+
minLineY: newMinLineY,
|
|
1287
|
+
maxLineY: newMaxLineY,
|
|
1288
|
+
focused: true,
|
|
1289
|
+
deltaY: newDeltaY
|
|
1290
|
+
};
|
|
1291
|
+
};
|
|
1292
|
+
|
|
1293
|
+
const focusIndex = (state, index) => {
|
|
1294
|
+
const {
|
|
1295
|
+
itemHeight,
|
|
1296
|
+
minLineY,
|
|
1297
|
+
maxLineY,
|
|
1298
|
+
headerHeight,
|
|
1299
|
+
height,
|
|
1300
|
+
items
|
|
1301
|
+
} = state;
|
|
1302
|
+
const itemsLength = items.length;
|
|
1303
|
+
if (itemsLength === 0) {
|
|
1304
|
+
return state;
|
|
1305
|
+
}
|
|
1306
|
+
number(itemHeight);
|
|
1307
|
+
if (index === -1) {
|
|
1308
|
+
return {
|
|
1309
|
+
...state,
|
|
1310
|
+
focusedIndex: -1,
|
|
1311
|
+
focused: true
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
const listHeight = height - headerHeight;
|
|
1315
|
+
if (index < minLineY + 1) {
|
|
1316
|
+
return focusIndexScrollUp(state, index, listHeight, itemHeight, itemsLength);
|
|
1317
|
+
}
|
|
1318
|
+
if (index >= maxLineY - 1) {
|
|
1319
|
+
return focusIndexScrollDown(state, index, listHeight, itemHeight, itemsLength);
|
|
1320
|
+
}
|
|
1321
|
+
return {
|
|
1322
|
+
...state,
|
|
1323
|
+
focusedIndex: index,
|
|
1324
|
+
focused: true
|
|
1325
|
+
};
|
|
1326
|
+
};
|
|
1327
|
+
|
|
1328
|
+
const Button = 1;
|
|
1329
|
+
|
|
1330
|
+
const ClearAll = 'ClearAll';
|
|
1331
|
+
const Filter = 'Filter';
|
|
1332
|
+
const Refresh = 'Refresh';
|
|
1333
|
+
const Ellipsis = 'Ellipsis';
|
|
1334
|
+
|
|
1335
|
+
const getActions = () => {
|
|
1336
|
+
return [{
|
|
1337
|
+
type: Button,
|
|
1338
|
+
id: refresh(),
|
|
1339
|
+
icon: Refresh,
|
|
1340
|
+
command: ''
|
|
1341
|
+
}, {
|
|
1342
|
+
type: Button,
|
|
1343
|
+
id: viewsAndMoreActions(),
|
|
1344
|
+
icon: Ellipsis,
|
|
1345
|
+
command: ''
|
|
1346
|
+
}];
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1189
1349
|
const Enter = 3;
|
|
1190
1350
|
const Space = 9;
|
|
1191
1351
|
const PageUp = 10;
|
|
@@ -1243,7 +1403,133 @@ const getKeyBindings = () => {
|
|
|
1243
1403
|
}];
|
|
1244
1404
|
};
|
|
1245
1405
|
|
|
1246
|
-
const
|
|
1406
|
+
const handleBlur = () => {
|
|
1407
|
+
// TODO
|
|
1408
|
+
};
|
|
1409
|
+
|
|
1410
|
+
const RendererWorker = 1;
|
|
1411
|
+
|
|
1412
|
+
const rpcs = Object.create(null);
|
|
1413
|
+
const set = (id, rpc) => {
|
|
1414
|
+
rpcs[id] = rpc;
|
|
1415
|
+
};
|
|
1416
|
+
const get = id => {
|
|
1417
|
+
return rpcs[id];
|
|
1418
|
+
};
|
|
1419
|
+
|
|
1420
|
+
const invoke = (method, ...params) => {
|
|
1421
|
+
const rpc = get(RendererWorker);
|
|
1422
|
+
// @ts-ignore
|
|
1423
|
+
return rpc.invoke(method, ...params);
|
|
1424
|
+
};
|
|
1425
|
+
|
|
1426
|
+
const openUri = async uri => {
|
|
1427
|
+
return invoke('Main.openUri', uri);
|
|
1428
|
+
};
|
|
1429
|
+
|
|
1430
|
+
const handleClick = async (state, index) => {
|
|
1431
|
+
const {
|
|
1432
|
+
items,
|
|
1433
|
+
minLineY
|
|
1434
|
+
} = state;
|
|
1435
|
+
const actualIndex = index + minLineY;
|
|
1436
|
+
const extension = items[actualIndex];
|
|
1437
|
+
const uri = `extension-detail://${extension.id}`;
|
|
1438
|
+
await openUri(uri);
|
|
1439
|
+
return focusIndex(state, actualIndex);
|
|
1440
|
+
};
|
|
1441
|
+
|
|
1442
|
+
const show = async (x, y, id) => {
|
|
1443
|
+
number(x);
|
|
1444
|
+
number(y);
|
|
1445
|
+
number(id);
|
|
1446
|
+
// TODO
|
|
1447
|
+
};
|
|
1448
|
+
|
|
1449
|
+
const ManageExtension = 8;
|
|
1450
|
+
|
|
1451
|
+
const handleContextMenu = async (state, button, x, y) => {
|
|
1452
|
+
// TODO use focused index when when context menu button is -1 (keyboard)
|
|
1453
|
+
await show(x, y, ManageExtension);
|
|
1454
|
+
return state;
|
|
1455
|
+
};
|
|
1456
|
+
|
|
1457
|
+
const handleDisable = (state, id) => {
|
|
1458
|
+
// TODO
|
|
1459
|
+
};
|
|
1460
|
+
|
|
1461
|
+
const handleEnable = (state, id) => {
|
|
1462
|
+
// TODO
|
|
1463
|
+
};
|
|
1464
|
+
|
|
1465
|
+
const handleFocus = () => {
|
|
1466
|
+
// TODO
|
|
1467
|
+
};
|
|
1468
|
+
|
|
1469
|
+
// TODO show error / warning when installment fails / times out
|
|
1470
|
+
const handleInstall = async (state, id) => {
|
|
1471
|
+
// TODO
|
|
1472
|
+
};
|
|
1473
|
+
|
|
1474
|
+
const getAllExtensions = async platform => {
|
|
1475
|
+
if (platform === Web) {
|
|
1476
|
+
return [];
|
|
1477
|
+
}
|
|
1478
|
+
return [];
|
|
1479
|
+
};
|
|
1480
|
+
|
|
1481
|
+
const Small = 1;
|
|
1482
|
+
const Normal = 2;
|
|
1483
|
+
const Large = 3;
|
|
1484
|
+
|
|
1485
|
+
const getViewletSize = width => {
|
|
1486
|
+
if (width < 180) {
|
|
1487
|
+
return Small;
|
|
1488
|
+
}
|
|
1489
|
+
if (width < 768) {
|
|
1490
|
+
return Normal;
|
|
1491
|
+
}
|
|
1492
|
+
return Large;
|
|
1493
|
+
};
|
|
1494
|
+
|
|
1495
|
+
const getSavedValue = savedState => {
|
|
1496
|
+
if (savedState && typeof savedState === 'object' && 'searchValue' in savedState && typeof savedState.searchValue === 'string') {
|
|
1497
|
+
return savedState.searchValue;
|
|
1498
|
+
}
|
|
1499
|
+
return '';
|
|
1500
|
+
};
|
|
1501
|
+
const restoreState = savedState => {
|
|
1502
|
+
const searchValue = getSavedValue(savedState);
|
|
1503
|
+
return {
|
|
1504
|
+
searchValue
|
|
1505
|
+
};
|
|
1506
|
+
};
|
|
1507
|
+
|
|
1508
|
+
const loadContent = async (uid, savedState) => {
|
|
1509
|
+
const {
|
|
1510
|
+
newState
|
|
1511
|
+
} = get$1(uid);
|
|
1512
|
+
const {
|
|
1513
|
+
width,
|
|
1514
|
+
platform
|
|
1515
|
+
} = newState;
|
|
1516
|
+
const {
|
|
1517
|
+
searchValue
|
|
1518
|
+
} = restoreState(savedState);
|
|
1519
|
+
// TODO just get local extensions on demand (not when query string is already different)
|
|
1520
|
+
const allExtensions = await getAllExtensions(platform);
|
|
1521
|
+
const size = getViewletSize(width);
|
|
1522
|
+
const updatedState = await handleInput({
|
|
1523
|
+
...newState,
|
|
1524
|
+
allExtensions,
|
|
1525
|
+
size
|
|
1526
|
+
}, searchValue);
|
|
1527
|
+
set$1(uid, newState, updatedState);
|
|
1528
|
+
};
|
|
1529
|
+
|
|
1530
|
+
const openSuggest = () => {
|
|
1531
|
+
// TODO
|
|
1532
|
+
};
|
|
1247
1533
|
|
|
1248
1534
|
const ExtensionActions = 'ExtensionActions';
|
|
1249
1535
|
const ExtensionActive = 'ExtensionActive';
|
|
@@ -1445,6 +1731,7 @@ const getVisibleItem = (item, setSize, itemHeight, minLineY, relative, i, focuse
|
|
|
1445
1731
|
focused: i === focusedIndex
|
|
1446
1732
|
};
|
|
1447
1733
|
};
|
|
1734
|
+
|
|
1448
1735
|
const getVisible = state => {
|
|
1449
1736
|
const {
|
|
1450
1737
|
minLineY,
|
|
@@ -1464,9 +1751,6 @@ const getVisible = state => {
|
|
|
1464
1751
|
return visible;
|
|
1465
1752
|
};
|
|
1466
1753
|
|
|
1467
|
-
const ClearAll = 'ClearAll';
|
|
1468
|
-
const Filter = 'Filter';
|
|
1469
|
-
|
|
1470
1754
|
const px = value => {
|
|
1471
1755
|
return `${value}px`;
|
|
1472
1756
|
};
|
|
@@ -1478,6 +1762,12 @@ const SetMessage = 'setMessage';
|
|
|
1478
1762
|
const SetScrollBar = 'setScrollBar';
|
|
1479
1763
|
const SetSearchValue = 'setSearchValue';
|
|
1480
1764
|
|
|
1765
|
+
const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
|
|
1766
|
+
const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
|
|
1767
|
+
return scrollBarOffset;
|
|
1768
|
+
};
|
|
1769
|
+
const getScrollBarY = getScrollBarOffset;
|
|
1770
|
+
|
|
1481
1771
|
const getListHeight = state => {
|
|
1482
1772
|
const {
|
|
1483
1773
|
height,
|
|
@@ -1563,18 +1853,74 @@ const doRender = (oldState, newState) => {
|
|
|
1563
1853
|
return commands;
|
|
1564
1854
|
};
|
|
1565
1855
|
|
|
1856
|
+
const saveState = state => {
|
|
1857
|
+
const {
|
|
1858
|
+
searchValue
|
|
1859
|
+
} = state;
|
|
1860
|
+
return {
|
|
1861
|
+
searchValue
|
|
1862
|
+
};
|
|
1863
|
+
};
|
|
1864
|
+
|
|
1865
|
+
const clamp = (num, min, max) => {
|
|
1866
|
+
number(num);
|
|
1867
|
+
number(min);
|
|
1868
|
+
number(max);
|
|
1869
|
+
return Math.min(Math.max(num, min), max);
|
|
1870
|
+
};
|
|
1871
|
+
|
|
1872
|
+
const setDeltaY = (state, value) => {
|
|
1873
|
+
object(state);
|
|
1874
|
+
number(value);
|
|
1875
|
+
const {
|
|
1876
|
+
itemHeight,
|
|
1877
|
+
finalDeltaY,
|
|
1878
|
+
deltaY,
|
|
1879
|
+
height,
|
|
1880
|
+
headerHeight
|
|
1881
|
+
} = state;
|
|
1882
|
+
const listHeight = height - headerHeight;
|
|
1883
|
+
const newDeltaY = clamp(value, 0, finalDeltaY);
|
|
1884
|
+
if (deltaY === newDeltaY) {
|
|
1885
|
+
return state;
|
|
1886
|
+
}
|
|
1887
|
+
// TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
|
|
1888
|
+
const minLineY = Math.floor(newDeltaY / itemHeight);
|
|
1889
|
+
const maxLineY = minLineY + getNumberOfVisibleItems(listHeight, itemHeight);
|
|
1890
|
+
return {
|
|
1891
|
+
...state,
|
|
1892
|
+
deltaY: newDeltaY,
|
|
1893
|
+
minLineY,
|
|
1894
|
+
maxLineY
|
|
1895
|
+
};
|
|
1896
|
+
};
|
|
1897
|
+
|
|
1898
|
+
const toggleSuggest = () => {
|
|
1899
|
+
// TODO
|
|
1900
|
+
};
|
|
1901
|
+
|
|
1566
1902
|
const commandMap = {
|
|
1567
1903
|
'SearchExtensions.clearSearchResults': clearSearchResults,
|
|
1904
|
+
'SearchExtensions.closeSuggest': closeSuggest,
|
|
1905
|
+
'SearchExtensions.create': create,
|
|
1906
|
+
'SearchExtensions.diff': diff,
|
|
1907
|
+
'SearchExtensions.focusIndex': focusIndex,
|
|
1908
|
+
'SearchExtensions.getActions': getActions,
|
|
1568
1909
|
'SearchExtensions.getKeyBindings': getKeyBindings,
|
|
1910
|
+
'SearchExtensions.handleBlur': handleBlur,
|
|
1911
|
+
'SearchExtensions.handleClick': handleClick,
|
|
1912
|
+
'SearchExtensions.handleContextMenu': handleContextMenu,
|
|
1913
|
+
'SearchExtensions.handleDisable': handleDisable,
|
|
1914
|
+
'SearchExtensions.handleEnable': handleEnable,
|
|
1915
|
+
'SearchExtensions.handleFocus': handleFocus,
|
|
1916
|
+
'SearchExtensions.handleInstall': handleInstall,
|
|
1917
|
+
'SearchExtensions.loadContent': loadContent,
|
|
1918
|
+
'SearchExtensions.openSuggest': openSuggest,
|
|
1569
1919
|
'SearchExtensions.render': doRender,
|
|
1570
|
-
'SearchExtensions.
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
const rpcs = Object.create(null);
|
|
1576
|
-
const set = (id, rpc) => {
|
|
1577
|
-
rpcs[id] = rpc;
|
|
1920
|
+
'SearchExtensions.saveState': saveState,
|
|
1921
|
+
'SearchExtensions.searchExtensions': searchExtensions,
|
|
1922
|
+
'SearchExtensions.setDeltaY': setDeltaY,
|
|
1923
|
+
'SearchExtensions.toggleSuggest': toggleSuggest
|
|
1578
1924
|
};
|
|
1579
1925
|
|
|
1580
1926
|
const listen = async () => {
|