@lvce-editor/extension-search-view 2.1.0 → 2.3.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$1 = (id, fn) => {
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$1(id, resolve);
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
- * @enum {string}
861
- */
862
- const UiStrings = {
863
- NoExtensionsFound: 'No extensions found.',
864
- Filter: 'Filter',
865
- ClearExtensionSearchResults: 'Clear extension search results',
866
- SearchExtensionsInMarketplace: 'Search Extensions in Marketplace',
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(UiStrings.NoExtensionsFound);
874
+ return i18nString(NoExtensionsFound);
870
875
  };
871
876
  const filter = () => {
872
- return i18nString(UiStrings.Filter);
877
+ return i18nString(Filter$1);
878
+ };
879
+ const refresh = () => {
880
+ return i18nString(Refresh$1);
873
881
  };
874
882
  const extensions = () => {
875
- return i18nString(UiStrings.Extensions);
883
+ return i18nString(Extensions);
876
884
  };
877
885
  const clearExtensionSearchResults = () => {
878
- return i18nString(UiStrings.ClearExtensionSearchResults);
886
+ return i18nString(ClearExtensionSearchResults);
879
887
  };
880
888
  const searchExtensionsInMarketPlace = () => {
881
- return i18nString(UiStrings.SearchExtensionsInMarketplace);
889
+ return i18nString(SearchExtensionsInMarketplace);
890
+ };
891
+ const viewsAndMoreActions = () => {
892
+ return i18nString(ViewsAndMoreActions);
882
893
  };
883
894
 
884
895
  const getFinalDeltaY = (height, itemHeight, itemsLength) => {
@@ -912,36 +923,6 @@ const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
912
923
  return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
913
924
  };
914
925
 
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;
942
- };
943
- const platform = getPlatform();
944
-
945
926
  const Installed = '@installed';
946
927
  const Enabled = '@enabled';
947
928
  const Disabled = '@disabled';
@@ -990,9 +971,11 @@ const parseValue = value => {
990
971
  };
991
972
  };
992
973
 
993
- const assetDir = '';
974
+ const Web = 1;
975
+ const Electron = 2;
976
+ const Remote = 3;
994
977
 
995
- const getRemoteUrl = (extension, platform) => {
978
+ const getRemoteUrl = (extension, platform, assetDir) => {
996
979
  if (platform === Remote || platform === Electron) {
997
980
  if (extension.builtin) {
998
981
  return `${assetDir}/extensions/${extension.id}/${extension.icon}`;
@@ -1002,9 +985,15 @@ const getRemoteUrl = (extension, platform) => {
1002
985
  return '';
1003
986
  };
1004
987
 
1005
- const ExtensionDefaultIcon = `${assetDir}/icons/extensionDefaultIcon.png`;
1006
- const ExtensionLanguageBasics = `${assetDir}/icons/language-icon.svg`;
1007
- const ExtensionTheme = `${assetDir}/icons/theme-icon.png`;
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
+ };
1008
997
 
1009
998
  const isLanguageBasicsExtension = extension => {
1010
999
  return extension.name && extension.name.startsWith('Language Basics');
@@ -1012,20 +1001,20 @@ const isLanguageBasicsExtension = extension => {
1012
1001
  const isThemeExtension = extension => {
1013
1002
  return extension.name && extension.name.endsWith(' Theme');
1014
1003
  };
1015
- const getIcon = (extension, platform) => {
1004
+ const getIcon = (extension, platform, assetDir) => {
1016
1005
  if (!extension) {
1017
- return ExtensionDefaultIcon;
1006
+ return getExtensionDefaultIcon(assetDir);
1018
1007
  }
1019
1008
  if (!extension.path || !extension.icon) {
1020
1009
  if (isLanguageBasicsExtension(extension)) {
1021
- return ExtensionLanguageBasics;
1010
+ return getExtensionLanguageBasicsIcon(assetDir);
1022
1011
  }
1023
1012
  if (isThemeExtension(extension)) {
1024
- return ExtensionTheme;
1013
+ return getExtensionThemeIcon(assetDir);
1025
1014
  }
1026
- return ExtensionDefaultIcon;
1015
+ return getExtensionDefaultIcon(assetDir);
1027
1016
  }
1028
- return getRemoteUrl(extension, platform);
1017
+ return getRemoteUrl(extension, platform, assetDir);
1029
1018
  };
1030
1019
  const getName = extension => {
1031
1020
  if (extension && extension.name) {
@@ -1079,6 +1068,12 @@ const matchesParsedValue = (extension, parsedValue) => {
1079
1068
  const toSorted = (array, compare) => {
1080
1069
  return [...array].sort(compare);
1081
1070
  };
1071
+ const isLastIndex = (array, index) => {
1072
+ return index === array.length - 1;
1073
+ };
1074
+ const lastIndex = array => {
1075
+ return array.length - 1;
1076
+ };
1082
1077
 
1083
1078
  const compareExtension = (extensionA, extensionB) => {
1084
1079
  return extensionA.name.localeCompare(extensionB.name) || extensionA.id.localeCompare(extensionB.id);
@@ -1088,7 +1083,7 @@ const sortExtensions = extensions => {
1088
1083
  return toSorted(extensions, compareExtension);
1089
1084
  };
1090
1085
 
1091
- const getExtensions = async (extensions, parsedValue, platform) => {
1086
+ const getExtensions = async (extensions, parsedValue, platform, assetDir = '') => {
1092
1087
  const filteredExtensions = [];
1093
1088
  for (const extension of extensions) {
1094
1089
  if (matchesParsedValue(extension, parsedValue)) {
@@ -1096,7 +1091,7 @@ const getExtensions = async (extensions, parsedValue, platform) => {
1096
1091
  name: getName(extension),
1097
1092
  id: getId(extension),
1098
1093
  publisher: getPublisher(extension),
1099
- icon: getIcon(extension, platform),
1094
+ icon: getIcon(extension, platform, assetDir),
1100
1095
  description: getDescription(extension)
1101
1096
  });
1102
1097
  }
@@ -1105,10 +1100,10 @@ const getExtensions = async (extensions, parsedValue, platform) => {
1105
1100
  return sortedExtensions;
1106
1101
  };
1107
1102
 
1108
- const searchExtensions = async (extensions, value, platform$1) => {
1103
+ const searchExtensions = async (extensions, value, platform, assetDir) => {
1109
1104
  try {
1110
1105
  const parsedValue = parseValue(value);
1111
- const filteredExtensions = await getExtensions(extensions, parsedValue, platform$1 || platform);
1106
+ const filteredExtensions = await getExtensions(extensions, parsedValue, platform, assetDir);
1112
1107
  return filteredExtensions;
1113
1108
  } catch (error) {
1114
1109
  throw new VError(error, 'Failed to search for extensions');
@@ -1123,11 +1118,12 @@ const handleInput = async (state, value) => {
1123
1118
  itemHeight,
1124
1119
  minimumSliderSize,
1125
1120
  height,
1126
- platform: platform$1
1121
+ platform,
1122
+ assetDir
1127
1123
  } = state;
1128
1124
  // TODO cancel ongoing requests
1129
1125
  // TODO handle errors
1130
- const items = await searchExtensions(allExtensions, value, platform$1 || platform);
1126
+ const items = await searchExtensions(allExtensions, value, platform, assetDir);
1131
1127
  if (items.length === 0) {
1132
1128
  return {
1133
1129
  ...state,
@@ -1181,6 +1177,240 @@ const clearSearchResults = state => {
1181
1177
  return handleInput(state, '');
1182
1178
  };
1183
1179
 
1180
+ const closeSuggest = () => {
1181
+ // TODO
1182
+ };
1183
+
1184
+ const states = Object.create(null);
1185
+ const get$1 = uid => {
1186
+ return states[uid];
1187
+ };
1188
+ const set$1 = (uid, oldState, newState) => {
1189
+ states[uid] = {
1190
+ oldState,
1191
+ newState
1192
+ };
1193
+ };
1194
+
1195
+ const create = (id, uri, x, y, width, height, platform) => {
1196
+ const state = {
1197
+ searchValue: '',
1198
+ minLineY: 0,
1199
+ maxLineY: 0,
1200
+ itemHeight: 0,
1201
+ items: [],
1202
+ height,
1203
+ message: '',
1204
+ allExtensions: [],
1205
+ placeholder: '',
1206
+ platform,
1207
+ finalDeltaY: 0,
1208
+ focusedIndex: 0,
1209
+ minimumSliderSize: 0,
1210
+ deltaY: 0,
1211
+ headerHeight: 0,
1212
+ scrollBarHeight: 0,
1213
+ width,
1214
+ size: 0,
1215
+ negativeMargin: 0,
1216
+ scrollBarActive: false,
1217
+ x,
1218
+ y,
1219
+ handleOffset: 0,
1220
+ assetDir: ''
1221
+ };
1222
+ set$1(id, state, state);
1223
+ };
1224
+
1225
+ const RenderHeader = 1;
1226
+ const RenderItems = 4;
1227
+ const RenderScrollBar = 5;
1228
+ const RenderMessage = 6;
1229
+
1230
+ const diffType$4 = RenderItems;
1231
+ const isEqual$4 = (oldState, newState) => {
1232
+ return true;
1233
+ };
1234
+
1235
+ const diffType$3 = RenderHeader;
1236
+ const isEqual$3 = (oldState, newState) => {
1237
+ return oldState.placeholder === newState.placeholder;
1238
+ };
1239
+
1240
+ const diffType$2 = RenderItems;
1241
+ const isEqual$2 = (oldState, newState) => {
1242
+ return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.deltaY === newState.deltaY && oldState.focusedIndex === newState.focusedIndex;
1243
+ };
1244
+
1245
+ const diffType$1 = RenderMessage;
1246
+ const isEqual$1 = (oldState, newState) => {
1247
+ return oldState.message === newState.message;
1248
+ };
1249
+
1250
+ const diffType = RenderScrollBar;
1251
+ const isEqual = (oldState, newState) => {
1252
+ 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;
1253
+ };
1254
+
1255
+ const modules = [isEqual$4, isEqual, isEqual$1, isEqual$3, isEqual$2];
1256
+ const numbers = [diffType$4, diffType, diffType$1, diffType$3, diffType$2];
1257
+
1258
+ const diff = (oldState, newState) => {
1259
+ const diffResult = [];
1260
+ for (let i = 0; i < modules.length; i++) {
1261
+ const fn = modules[i];
1262
+ if (!fn(oldState, newState)) {
1263
+ diffResult.push(numbers[i]);
1264
+ }
1265
+ }
1266
+ return diffResult;
1267
+ };
1268
+
1269
+ const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength) => {
1270
+ const newMaxLineY = Math.min(index + 1, itemsLength);
1271
+ const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
1272
+ const newMinLineY = Math.max(newMaxLineY - fittingItems, 0);
1273
+ const newDeltaY = itemsLength < fittingItems ? 0 : newMinLineY * itemHeight - listHeight % itemHeight + itemHeight;
1274
+ return {
1275
+ ...state,
1276
+ focusedIndex: index,
1277
+ minLineY: newMinLineY,
1278
+ maxLineY: newMaxLineY,
1279
+ focused: true,
1280
+ deltaY: newDeltaY
1281
+ };
1282
+ };
1283
+
1284
+ const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) => {
1285
+ const newMinLineY = index;
1286
+ const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
1287
+ const newMaxLineY = Math.min(newMinLineY + fittingItems, itemsLength);
1288
+ const newDeltaY = newMinLineY * itemHeight;
1289
+ return {
1290
+ ...state,
1291
+ focusedIndex: index,
1292
+ minLineY: newMinLineY,
1293
+ maxLineY: newMaxLineY,
1294
+ focused: true,
1295
+ deltaY: newDeltaY
1296
+ };
1297
+ };
1298
+
1299
+ const focusIndex = (state, index) => {
1300
+ const {
1301
+ itemHeight,
1302
+ minLineY,
1303
+ maxLineY,
1304
+ headerHeight,
1305
+ height,
1306
+ items
1307
+ } = state;
1308
+ const itemsLength = items.length;
1309
+ if (itemsLength === 0) {
1310
+ return state;
1311
+ }
1312
+ number(itemHeight);
1313
+ if (index === -1) {
1314
+ return {
1315
+ ...state,
1316
+ focusedIndex: -1,
1317
+ focused: true
1318
+ };
1319
+ }
1320
+ const listHeight = height - headerHeight;
1321
+ if (index < minLineY + 1) {
1322
+ return focusIndexScrollUp(state, index, listHeight, itemHeight, itemsLength);
1323
+ }
1324
+ if (index >= maxLineY - 1) {
1325
+ return focusIndexScrollDown(state, index, listHeight, itemHeight, itemsLength);
1326
+ }
1327
+ return {
1328
+ ...state,
1329
+ focusedIndex: index,
1330
+ focused: true
1331
+ };
1332
+ };
1333
+
1334
+ const first = () => {
1335
+ return 0;
1336
+ };
1337
+ const last = items => {
1338
+ return items.length - 1;
1339
+ };
1340
+ const next = (items, index) => {
1341
+ return (index + 1) % items.length;
1342
+ };
1343
+
1344
+ const focusFirst = state => {
1345
+ const firstIndex = first();
1346
+ return focusIndex(state, firstIndex);
1347
+ };
1348
+
1349
+ const focusLast = state => {
1350
+ const {
1351
+ items
1352
+ } = state;
1353
+ const lastIndex = last(items);
1354
+ return focusIndex(state, lastIndex);
1355
+ };
1356
+
1357
+ const focusNext = state => {
1358
+ const {
1359
+ focusedIndex,
1360
+ items
1361
+ } = state;
1362
+ const nextIndex = next(items, focusedIndex);
1363
+ return focusIndex(state, nextIndex);
1364
+ };
1365
+
1366
+ const focusNextPage = async state => {
1367
+ const {
1368
+ focusedIndex,
1369
+ items,
1370
+ maxLineY,
1371
+ minLineY
1372
+ } = state;
1373
+ if (isLastIndex(items, focusedIndex)) {
1374
+ return state;
1375
+ }
1376
+ const indexNextPage = Math.min(maxLineY + (maxLineY - minLineY) - 2, lastIndex(items));
1377
+ return focusIndex(state, indexNextPage);
1378
+ };
1379
+
1380
+ const focusPreviousPage = async state => {
1381
+ const {
1382
+ focusedIndex,
1383
+ minLineY,
1384
+ maxLineY
1385
+ } = state;
1386
+ if (focusedIndex === 0 || focusedIndex === -1) {
1387
+ return state;
1388
+ }
1389
+ const indexPreviousPage = Math.max(minLineY - (maxLineY - minLineY) + 1, 0);
1390
+ return focusIndex(state, indexPreviousPage);
1391
+ };
1392
+
1393
+ const Button$2 = 1;
1394
+
1395
+ const ClearAll = 'ClearAll';
1396
+ const Filter = 'Filter';
1397
+ const Refresh = 'Refresh';
1398
+ const Ellipsis = 'Ellipsis';
1399
+
1400
+ const getActions = () => {
1401
+ return [{
1402
+ type: Button$2,
1403
+ id: refresh(),
1404
+ icon: Refresh,
1405
+ command: ''
1406
+ }, {
1407
+ type: Button$2,
1408
+ id: viewsAndMoreActions(),
1409
+ icon: Ellipsis,
1410
+ command: ''
1411
+ }];
1412
+ };
1413
+
1184
1414
  const Enter = 3;
1185
1415
  const Space = 9;
1186
1416
  const PageUp = 10;
@@ -1238,8 +1468,289 @@ const getKeyBindings = () => {
1238
1468
  }];
1239
1469
  };
1240
1470
 
1241
- const Button = 1;
1471
+ const handleBlur = () => {
1472
+ // TODO
1473
+ };
1474
+
1475
+ const RendererWorker = 1;
1476
+
1477
+ const rpcs = Object.create(null);
1478
+ const set = (id, rpc) => {
1479
+ rpcs[id] = rpc;
1480
+ };
1481
+ const get = id => {
1482
+ return rpcs[id];
1483
+ };
1484
+
1485
+ const invoke = (method, ...params) => {
1486
+ const rpc = get(RendererWorker);
1487
+ // @ts-ignore
1488
+ return rpc.invoke(method, ...params);
1489
+ };
1490
+
1491
+ const openUri = async uri => {
1492
+ return invoke('Main.openUri', uri);
1493
+ };
1494
+
1495
+ const handleClick = async (state, index) => {
1496
+ const {
1497
+ items,
1498
+ minLineY
1499
+ } = state;
1500
+ const actualIndex = index + minLineY;
1501
+ const extension = items[actualIndex];
1502
+ const uri = `extension-detail://${extension.id}`;
1503
+ await openUri(uri);
1504
+ return focusIndex(state, actualIndex);
1505
+ };
1506
+
1507
+ const handleClickCurrent = state => {
1508
+ const {
1509
+ focusedIndex
1510
+ } = state;
1511
+ return handleClick(state, focusedIndex);
1512
+ };
1513
+
1514
+ const handleClickCurrentButKeepFocus = state => {
1515
+ const {
1516
+ focusedIndex
1517
+ } = state;
1518
+ return handleClick(state, focusedIndex);
1519
+ };
1520
+
1521
+ const show = async (x, y, id) => {
1522
+ number(x);
1523
+ number(y);
1524
+ number(id);
1525
+ // TODO
1526
+ };
1527
+
1528
+ const ManageExtension = 8;
1529
+
1530
+ const handleContextMenu = async (state, button, x, y) => {
1531
+ // TODO use focused index when when context menu button is -1 (keyboard)
1532
+ await show(x, y, ManageExtension);
1533
+ return state;
1534
+ };
1535
+
1536
+ const handleDisable = (state, id) => {
1537
+ // TODO
1538
+ };
1539
+
1540
+ const handleEnable = (state, id) => {
1541
+ // TODO
1542
+ };
1543
+
1544
+ const setFocus = async focusId => {
1545
+ await invoke('Focus.setFocus', focusId);
1546
+ };
1547
+
1548
+ const handleFocus = async () => {
1549
+ await setFocus(FocusExtensions);
1550
+ };
1551
+
1552
+ // TODO show error / warning when installment fails / times out
1553
+ const handleInstall = async (state, id) => {
1554
+ // TODO
1555
+ };
1242
1556
 
1557
+ const handleScrollBarCaptureLost = state => {
1558
+ return {
1559
+ ...state,
1560
+ scrollBarActive: false
1561
+ };
1562
+ };
1563
+
1564
+ const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
1565
+ const halfScrollBarHeight = scrollBarHeight / 2;
1566
+ if (relativeY <= halfScrollBarHeight) {
1567
+ // clicked at top
1568
+ return {
1569
+ percent: 0,
1570
+ handleOffset: relativeY
1571
+ };
1572
+ }
1573
+ if (relativeY <= height - halfScrollBarHeight) {
1574
+ // clicked in middle
1575
+ return {
1576
+ percent: (relativeY - halfScrollBarHeight) / (height - scrollBarHeight),
1577
+ handleOffset: halfScrollBarHeight
1578
+ };
1579
+ }
1580
+ // clicked at bottom
1581
+ return {
1582
+ percent: 1,
1583
+ handleOffset: scrollBarHeight - height + relativeY
1584
+ };
1585
+ };
1586
+
1587
+ const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
1588
+ const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
1589
+ return scrollBarOffset;
1590
+ };
1591
+ const getScrollBarY = getScrollBarOffset;
1592
+
1593
+ const clamp = (num, min, max) => {
1594
+ number(num);
1595
+ number(min);
1596
+ number(max);
1597
+ return Math.min(Math.max(num, min), max);
1598
+ };
1599
+
1600
+ const setDeltaY = (state, value) => {
1601
+ object(state);
1602
+ number(value);
1603
+ const {
1604
+ itemHeight,
1605
+ finalDeltaY,
1606
+ deltaY,
1607
+ height,
1608
+ headerHeight
1609
+ } = state;
1610
+ const listHeight = height - headerHeight;
1611
+ const newDeltaY = clamp(value, 0, finalDeltaY);
1612
+ if (deltaY === newDeltaY) {
1613
+ return state;
1614
+ }
1615
+ // TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
1616
+ const minLineY = Math.floor(newDeltaY / itemHeight);
1617
+ const maxLineY = minLineY + getNumberOfVisibleItems(listHeight, itemHeight);
1618
+ return {
1619
+ ...state,
1620
+ deltaY: newDeltaY,
1621
+ minLineY,
1622
+ maxLineY
1623
+ };
1624
+ };
1625
+
1626
+ const handleScrollBarClick = (state, eventY) => {
1627
+ const {
1628
+ y,
1629
+ deltaY,
1630
+ headerHeight,
1631
+ finalDeltaY,
1632
+ scrollBarHeight,
1633
+ height
1634
+ } = state;
1635
+ const contentHeight = height - headerHeight;
1636
+ const relativeY = eventY - y - headerHeight;
1637
+ const currentScrollBarY = getScrollBarY(deltaY, finalDeltaY, contentHeight, scrollBarHeight);
1638
+ const diff = relativeY - currentScrollBarY;
1639
+ if (diff >= 0 && diff < scrollBarHeight) {
1640
+ return {
1641
+ ...state,
1642
+ handleOffset: diff,
1643
+ scrollBarActive: true
1644
+ };
1645
+ }
1646
+ const {
1647
+ percent,
1648
+ handleOffset
1649
+ } = getNewDeltaPercent(contentHeight, scrollBarHeight, relativeY);
1650
+ const newDeltaY = percent * finalDeltaY;
1651
+ return {
1652
+ ...setDeltaY(state, newDeltaY),
1653
+ handleOffset,
1654
+ scrollBarActive: true
1655
+ };
1656
+ };
1657
+
1658
+ const getNewPercent = (contentHeight, scrollBarHeight, relativeY) => {
1659
+ if (relativeY <= contentHeight - scrollBarHeight / 2) {
1660
+ // clicked in middle
1661
+ return relativeY / (contentHeight - scrollBarHeight);
1662
+ }
1663
+ // clicked at bottom
1664
+ return 1;
1665
+ };
1666
+ const handleScrollBarMove = (state, eventY) => {
1667
+ const {
1668
+ y,
1669
+ headerHeight,
1670
+ handleOffset,
1671
+ finalDeltaY,
1672
+ height,
1673
+ scrollBarHeight
1674
+ } = state;
1675
+ const relativeY = eventY - y - headerHeight - handleOffset;
1676
+ const contentHeight = height - headerHeight;
1677
+ const newPercent = getNewPercent(contentHeight, scrollBarHeight, relativeY);
1678
+ const newDeltaY = newPercent * finalDeltaY;
1679
+ return setDeltaY(state, newDeltaY);
1680
+ };
1681
+
1682
+ // TODO show error / warning when installment fails / times out
1683
+ const handleUninstall = async (state, id) => {
1684
+ // TODO
1685
+ };
1686
+
1687
+ const handleWheel = (state, deltaMode, deltaY) => {
1688
+ number(deltaMode);
1689
+ number(deltaY);
1690
+ return setDeltaY(state, state.deltaY + deltaY);
1691
+ };
1692
+
1693
+ const getAllExtensions = async platform => {
1694
+ if (platform === Web) {
1695
+ return [];
1696
+ }
1697
+ return [];
1698
+ };
1699
+
1700
+ const Small = 1;
1701
+ const Normal = 2;
1702
+ const Large = 3;
1703
+
1704
+ const getViewletSize = width => {
1705
+ if (width < 180) {
1706
+ return Small;
1707
+ }
1708
+ if (width < 768) {
1709
+ return Normal;
1710
+ }
1711
+ return Large;
1712
+ };
1713
+
1714
+ const getSavedValue = savedState => {
1715
+ if (savedState && typeof savedState === 'object' && 'searchValue' in savedState && typeof savedState.searchValue === 'string') {
1716
+ return savedState.searchValue;
1717
+ }
1718
+ return '';
1719
+ };
1720
+ const restoreState = savedState => {
1721
+ const searchValue = getSavedValue(savedState);
1722
+ return {
1723
+ searchValue
1724
+ };
1725
+ };
1726
+
1727
+ const loadContent = async (uid, savedState) => {
1728
+ const {
1729
+ newState
1730
+ } = get$1(uid);
1731
+ const {
1732
+ width,
1733
+ platform
1734
+ } = newState;
1735
+ const {
1736
+ searchValue
1737
+ } = restoreState(savedState);
1738
+ // TODO just get local extensions on demand (not when query string is already different)
1739
+ const allExtensions = await getAllExtensions(platform);
1740
+ const size = getViewletSize(width);
1741
+ const updatedState = await handleInput({
1742
+ ...newState,
1743
+ allExtensions,
1744
+ size
1745
+ }, searchValue);
1746
+ set$1(uid, newState, updatedState);
1747
+ };
1748
+
1749
+ const openSuggest = () => {
1750
+ // TODO
1751
+ };
1752
+
1753
+ const Actions = 'Actions';
1243
1754
  const ExtensionActions = 'ExtensionActions';
1244
1755
  const ExtensionActive = 'ExtensionActive';
1245
1756
  const ExtensionHeader = 'ExtensionHeader';
@@ -1248,8 +1759,10 @@ const ExtensionListItemAuthorName = 'ExtensionListItemAuthorName';
1248
1759
  const ExtensionListItemDescription = 'ExtensionListItemDescription';
1249
1760
  const ExtensionListItemDetail = 'ExtensionListItemDetail';
1250
1761
  const ExtensionListItemFooter = 'ExtensionListItemFooter';
1762
+ const MaskIcon = 'MaskIcon';
1251
1763
  const ExtensionListItemIcon = 'ExtensionListItemIcon';
1252
1764
  const ExtensionListItemName = 'ExtensionListItemName';
1765
+ const IconButton = 'IconButton';
1253
1766
  const ListItems = 'ListItems';
1254
1767
  const MultilineInputBox = 'MultilineInputBox';
1255
1768
  const ScrollBarThumb = 'ScrollBarThumb';
@@ -1262,11 +1775,12 @@ const CheckBox = 'checkbox';
1262
1775
  const List = 'list';
1263
1776
  const ListItem = 'listitem';
1264
1777
  const None = 'none';
1778
+ const ToolBar = 'toolbar';
1265
1779
 
1266
- const Div = 4;
1267
- const Text = 12;
1268
- const Img = 17;
1269
- const TextArea = 62;
1780
+ const Div$1 = 4;
1781
+ const Img$1 = 17;
1782
+ const TextArea$1 = 62;
1783
+ const Button$1 = 1;
1270
1784
 
1271
1785
  const getSearchFieldButtonVirtualDom = button => {
1272
1786
  const {
@@ -1275,7 +1789,7 @@ const getSearchFieldButtonVirtualDom = button => {
1275
1789
  title
1276
1790
  } = button;
1277
1791
  return [{
1278
- type: Div,
1792
+ type: Div$1,
1279
1793
  className: `SearchFieldButton ${checked ? 'SearchFieldButtonChecked' : ''}`,
1280
1794
  title,
1281
1795
  role: CheckBox,
@@ -1283,7 +1797,7 @@ const getSearchFieldButtonVirtualDom = button => {
1283
1797
  tabIndex: 0,
1284
1798
  childCount: 1
1285
1799
  }, {
1286
- type: Div,
1800
+ type: Div$1,
1287
1801
  className: `MaskIcon ${icon}`,
1288
1802
  childCount: 0
1289
1803
  }];
@@ -1291,12 +1805,12 @@ const getSearchFieldButtonVirtualDom = button => {
1291
1805
 
1292
1806
  const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus = '') => {
1293
1807
  const dom = [{
1294
- type: Div,
1808
+ type: Div$1,
1295
1809
  className: SearchField,
1296
1810
  role: None,
1297
1811
  childCount: 2
1298
1812
  }, {
1299
- type: TextArea,
1813
+ type: TextArea$1,
1300
1814
  className: MultilineInputBox,
1301
1815
  spellcheck: false,
1302
1816
  autocapitalize: 'off',
@@ -1307,13 +1821,13 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
1307
1821
  onFocus,
1308
1822
  childCount: 0
1309
1823
  }, {
1310
- type: Div,
1824
+ type: Div$1,
1311
1825
  className: SearchFieldButtons,
1312
1826
  childCount: insideButtons.length
1313
1827
  }, ...insideButtons.flatMap(getSearchFieldButtonVirtualDom)];
1314
1828
  if (outsideButtons.length > 0) {
1315
1829
  dom.unshift({
1316
- type: Div,
1830
+ type: Div$1,
1317
1831
  className: SearchFieldContainer,
1318
1832
  role: None,
1319
1833
  childCount: 1 + outsideButtons.length
@@ -1325,12 +1839,27 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
1325
1839
 
1326
1840
  const getExtensionHeaderVirtualDom = (placeholder, actions) => {
1327
1841
  return [{
1328
- type: Div,
1842
+ type: Div$1,
1329
1843
  className: ExtensionHeader,
1330
1844
  childCount: 1
1331
1845
  }, ...getSearchFieldVirtualDom('extensions', placeholder, 'handleExtensionsInput', actions, [])];
1332
1846
  };
1333
1847
 
1848
+ const renderHeader$1 = newState => {
1849
+ const actions = [{
1850
+ type: Button$2,
1851
+ title: clearExtensionSearchResults(),
1852
+ icon: `MaskIcon${ClearAll}`,
1853
+ command: 'Extensions.clearSearchResults'
1854
+ }, {
1855
+ type: Button$2,
1856
+ title: filter(),
1857
+ icon: `MaskIcon${Filter}`
1858
+ }];
1859
+ const dom = getExtensionHeaderVirtualDom(newState.placeholder, actions);
1860
+ return ['setHeaderDom', dom];
1861
+ };
1862
+
1334
1863
  const HandleContextMenu = 'handleContextMenu';
1335
1864
  const HandlePointerDown = 'handlePointerDown';
1336
1865
  const HandleTouchStart = 'handleTouchStart';
@@ -1338,7 +1867,134 @@ const HandleWheel = 'handleWheel';
1338
1867
 
1339
1868
  const Extension = 'Extension';
1340
1869
 
1341
- const text = data => {
1870
+ var __defProp = Object.defineProperty;
1871
+ var __export = (target, all) => {
1872
+ for (var name in all) __defProp(target, name, {
1873
+ get: all[name],
1874
+ enumerable: true
1875
+ });
1876
+ };
1877
+
1878
+ // src/parts/MergeClassNames/MergeClassNames.ts
1879
+ var mergeClassNames = (...classNames) => {
1880
+ return classNames.filter(Boolean).join(" ");
1881
+ };
1882
+
1883
+ // src/parts/VirtualDomElements/VirtualDomElements.ts
1884
+ var VirtualDomElements_exports = {};
1885
+ __export(VirtualDomElements_exports, {
1886
+ A: () => A,
1887
+ Abbr: () => Abbr,
1888
+ Article: () => Article,
1889
+ Aside: () => Aside,
1890
+ Audio: () => Audio,
1891
+ Br: () => Br,
1892
+ Button: () => Button,
1893
+ Cite: () => Cite,
1894
+ Col: () => Col,
1895
+ ColGroup: () => ColGroup,
1896
+ Data: () => Data,
1897
+ Dd: () => Dd,
1898
+ Del: () => Del,
1899
+ Div: () => Div,
1900
+ Dl: () => Dl,
1901
+ Figcaption: () => Figcaption,
1902
+ Figure: () => Figure,
1903
+ Footer: () => Footer,
1904
+ H1: () => H1,
1905
+ H2: () => H2,
1906
+ H3: () => H3,
1907
+ H4: () => H4,
1908
+ H5: () => H5,
1909
+ H6: () => H6,
1910
+ Header: () => Header,
1911
+ Hr: () => Hr,
1912
+ I: () => I,
1913
+ Img: () => Img,
1914
+ Input: () => Input,
1915
+ Ins: () => Ins,
1916
+ Kbd: () => Kbd,
1917
+ Li: () => Li,
1918
+ Nav: () => Nav,
1919
+ Ol: () => Ol,
1920
+ Option: () => Option,
1921
+ P: () => P,
1922
+ Pre: () => Pre,
1923
+ Root: () => Root,
1924
+ Search: () => Search,
1925
+ Section: () => Section,
1926
+ Select: () => Select,
1927
+ Span: () => Span,
1928
+ TBody: () => TBody,
1929
+ THead: () => THead,
1930
+ Table: () => Table,
1931
+ Td: () => Td,
1932
+ Text: () => Text,
1933
+ TextArea: () => TextArea,
1934
+ Tfoot: () => Tfoot,
1935
+ Th: () => Th,
1936
+ Time: () => Time,
1937
+ Tr: () => Tr,
1938
+ Ul: () => Ul,
1939
+ Video: () => Video
1940
+ });
1941
+ var Audio = 0;
1942
+ var Button = 1;
1943
+ var Col = 2;
1944
+ var ColGroup = 3;
1945
+ var Div = 4;
1946
+ var H1 = 5;
1947
+ var Input = 6;
1948
+ var Kbd = 7;
1949
+ var Span = 8;
1950
+ var Table = 9;
1951
+ var TBody = 10;
1952
+ var Td = 11;
1953
+ var Text = 12;
1954
+ var Th = 13;
1955
+ var THead = 14;
1956
+ var Tr = 15;
1957
+ var I = 16;
1958
+ var Img = 17;
1959
+ var Root = 0;
1960
+ var Ins = 20;
1961
+ var Del = 21;
1962
+ var H2 = 22;
1963
+ var H3 = 23;
1964
+ var H4 = 24;
1965
+ var H5 = 25;
1966
+ var H6 = 26;
1967
+ var Article = 27;
1968
+ var Aside = 28;
1969
+ var Footer = 29;
1970
+ var Header = 30;
1971
+ var Nav = 40;
1972
+ var Section = 41;
1973
+ var Search = 42;
1974
+ var Dd = 43;
1975
+ var Dl = 44;
1976
+ var Figcaption = 45;
1977
+ var Figure = 46;
1978
+ var Hr = 47;
1979
+ var Li = 48;
1980
+ var Ol = 49;
1981
+ var P = 50;
1982
+ var Pre = 51;
1983
+ var A = 53;
1984
+ var Abbr = 54;
1985
+ var Br = 55;
1986
+ var Cite = 56;
1987
+ var Data = 57;
1988
+ var Time = 58;
1989
+ var Tfoot = 59;
1990
+ var Ul = 60;
1991
+ var Video = 61;
1992
+ var TextArea = 62;
1993
+ var Select = 63;
1994
+ var Option = 64;
1995
+
1996
+ // src/parts/Text/Text.ts
1997
+ var text = data => {
1342
1998
  return {
1343
1999
  type: Text,
1344
2000
  text: data,
@@ -1347,27 +2003,27 @@ const text = data => {
1347
2003
  };
1348
2004
 
1349
2005
  const listItemDetail = {
1350
- type: Div,
2006
+ type: Div$1,
1351
2007
  className: ExtensionListItemDetail,
1352
2008
  childCount: 3
1353
2009
  };
1354
2010
  const listItemName = {
1355
- type: Div,
2011
+ type: Div$1,
1356
2012
  className: ExtensionListItemName,
1357
2013
  childCount: 1
1358
2014
  };
1359
2015
  const listItemDescription = {
1360
- type: Div,
2016
+ type: Div$1,
1361
2017
  className: ExtensionListItemDescription,
1362
2018
  childCount: 1
1363
2019
  };
1364
2020
  const listItemFooter = {
1365
- type: Div,
2021
+ type: Div$1,
1366
2022
  className: ExtensionListItemFooter,
1367
2023
  childCount: 2
1368
2024
  };
1369
2025
  const listItemAuthorName = {
1370
- type: Div,
2026
+ type: Div$1,
1371
2027
  className: ExtensionListItemAuthorName,
1372
2028
  childCount: 1
1373
2029
  };
@@ -1383,7 +2039,7 @@ const getExtensionListItemVirtualDom = extension => {
1383
2039
  focused
1384
2040
  } = extension;
1385
2041
  const dom = [{
1386
- type: Div,
2042
+ type: Div$1,
1387
2043
  role: ListItem,
1388
2044
  ariaRoleDescription: Extension,
1389
2045
  className: ExtensionListItem,
@@ -1392,13 +2048,13 @@ const getExtensionListItemVirtualDom = extension => {
1392
2048
  top,
1393
2049
  childCount: 2
1394
2050
  }, {
1395
- type: Img,
2051
+ type: Img$1,
1396
2052
  src: icon,
1397
2053
  className: ExtensionListItemIcon,
1398
2054
  role: None,
1399
2055
  childCount: 0
1400
2056
  }, listItemDetail, listItemName, text(name), listItemDescription, text(description), listItemFooter, listItemAuthorName, text(publisher), {
1401
- type: Div,
2057
+ type: Div$1,
1402
2058
  className: ExtensionActions,
1403
2059
  childCount: 0
1404
2060
  }];
@@ -1411,7 +2067,7 @@ const getExtensionListItemVirtualDom = extension => {
1411
2067
 
1412
2068
  const getExtensionsListVirtualDom = visibleExtensions => {
1413
2069
  const dom = [{
1414
- type: Div,
2070
+ type: Div$1,
1415
2071
  className: ListItems,
1416
2072
  tabIndex: 0,
1417
2073
  ariaLabel: extensions(),
@@ -1460,8 +2116,20 @@ const getVisible = state => {
1460
2116
  return visible;
1461
2117
  };
1462
2118
 
1463
- const ClearAll = 'ClearAll';
1464
- const Filter = 'Filter';
2119
+ const renderItems = newState => {
2120
+ // TODO render extensions incrementally when scrolling
2121
+ const visibleExtensions = getVisible(newState);
2122
+ const dom = getExtensionsVirtualDom(visibleExtensions);
2123
+ return ['setExtensionsDom', dom];
2124
+ };
2125
+
2126
+ const SetMessage = 'setMessage';
2127
+ const SetScrollBar = 'setScrollBar';
2128
+ const SetSearchValue = 'setSearchValue';
2129
+
2130
+ const renderMessage$1 = newState => {
2131
+ return [/* method */SetMessage, /* message */newState.message];
2132
+ };
1465
2133
 
1466
2134
  const px = value => {
1467
2135
  return `${value}px`;
@@ -1470,61 +2138,39 @@ const position = (x, y) => {
1470
2138
  return `${x}px ${y}px`;
1471
2139
  };
1472
2140
 
1473
- const SetMessage = 'setMessage';
1474
- const SetScrollBar = 'setScrollBar';
1475
- const SetSearchValue = 'setSearchValue';
1476
-
1477
- const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
1478
- const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
1479
- return scrollBarOffset;
2141
+ const renderScrollBar$1 = newState => {
2142
+ // @ts-ignore
2143
+ const listHeight = getListHeight(newState);
2144
+ const total = newState.items.length;
2145
+ const contentHeight = total * newState.itemHeight;
2146
+ const scrollBarHeight = getScrollBarSize(listHeight, contentHeight, newState.minimumSliderSize);
2147
+ const scrollBarY = getScrollBarY(newState.deltaY, newState.finalDeltaY, newState.height - newState.headerHeight, scrollBarHeight);
2148
+ const roundedScrollBarY = Math.round(scrollBarY);
2149
+ const heightString = px(scrollBarHeight);
2150
+ const translateString = position(0, roundedScrollBarY);
2151
+ let className = ScrollBarThumb;
2152
+ if (newState.scrollBarActive) {
2153
+ className += ' ' + ScrollBarThumbActive;
2154
+ }
2155
+ return [/* method */SetScrollBar, translateString, heightString, className];
1480
2156
  };
1481
- const getScrollBarY = getScrollBarOffset;
1482
2157
 
1483
- const getListHeight = state => {
1484
- const {
1485
- height,
1486
- headerHeight
1487
- } = state;
1488
- return height - headerHeight;
1489
- };
1490
2158
  const renderExtensions = {
1491
- isEqual(oldState, newState) {
1492
- return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.deltaY === newState.deltaY && oldState.focusedIndex === newState.focusedIndex;
1493
- },
2159
+ isEqual: isEqual$2,
1494
2160
  apply(oldState, newState) {
1495
- // TODO render extensions incrementally when scrolling
1496
- const visibleExtensions = getVisible(newState);
1497
- const dom = getExtensionsVirtualDom(visibleExtensions);
1498
- return ['setExtensionsDom', dom];
2161
+ return renderItems(newState);
1499
2162
  }
1500
2163
  };
1501
2164
  const renderScrollBar = {
1502
- isEqual(oldState, newState) {
1503
- 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;
1504
- },
2165
+ isEqual: isEqual,
1505
2166
  apply(oldState, newState) {
1506
- // @ts-ignore
1507
- const listHeight = getListHeight(newState);
1508
- const total = newState.items.length;
1509
- const contentHeight = total * newState.itemHeight;
1510
- const scrollBarHeight = getScrollBarSize(listHeight, contentHeight, newState.minimumSliderSize);
1511
- const scrollBarY = getScrollBarY(newState.deltaY, newState.finalDeltaY, newState.height - newState.headerHeight, scrollBarHeight);
1512
- const roundedScrollBarY = Math.round(scrollBarY);
1513
- const heightString = px(scrollBarHeight);
1514
- const translateString = position(0, roundedScrollBarY);
1515
- let className = ScrollBarThumb;
1516
- if (newState.scrollBarActive) {
1517
- className += ' ' + ScrollBarThumbActive;
1518
- }
1519
- return [/* method */SetScrollBar, translateString, heightString, className];
2167
+ return renderScrollBar$1(newState);
1520
2168
  }
1521
2169
  };
1522
2170
  const renderMessage = {
1523
- isEqual(oldState, newState) {
1524
- return oldState.message === newState.message;
1525
- },
2171
+ isEqual: isEqual$1,
1526
2172
  apply(oldState, newState) {
1527
- return [/* method */SetMessage, /* message */newState.message];
2173
+ return renderMessage$1(newState);
1528
2174
  }
1529
2175
  };
1530
2176
  const renderSearchValue = {
@@ -1536,22 +2182,9 @@ const renderSearchValue = {
1536
2182
  }
1537
2183
  };
1538
2184
  const renderHeader = {
1539
- isEqual(oldState, newState) {
1540
- return oldState.placeholder === newState.placeholder;
1541
- },
2185
+ isEqual: isEqual$3,
1542
2186
  apply(oldState, newState) {
1543
- const actions = [{
1544
- type: Button,
1545
- title: clearExtensionSearchResults(),
1546
- icon: `MaskIcon${ClearAll}`,
1547
- command: 'Extensions.clearSearchResults'
1548
- }, {
1549
- type: Button,
1550
- title: filter(),
1551
- icon: `MaskIcon${Filter}`
1552
- }];
1553
- const dom = getExtensionHeaderVirtualDom(newState.placeholder, actions);
1554
- return ['setHeaderDom', dom];
2187
+ return renderHeader$1(newState);
1555
2188
  }
1556
2189
  };
1557
2190
  const render = [renderScrollBar, renderMessage, renderExtensions, renderSearchValue, renderHeader];
@@ -1565,6 +2198,73 @@ const doRender = (oldState, newState) => {
1565
2198
  return commands;
1566
2199
  };
1567
2200
 
2201
+ const getIconVirtualDom = (icon, type = Div$1) => {
2202
+ return {
2203
+ type,
2204
+ className: mergeClassNames(MaskIcon, `MaskIcon${icon}`),
2205
+ role: None,
2206
+ childCount: 0
2207
+ };
2208
+ };
2209
+
2210
+ const getActionButtonVirtualDom = action => {
2211
+ const {
2212
+ id,
2213
+ icon,
2214
+ command
2215
+ } = action;
2216
+ return [{
2217
+ type: Button$1,
2218
+ className: IconButton,
2219
+ title: id,
2220
+ 'data-command': command,
2221
+ childCount: 1
2222
+ }, getIconVirtualDom(icon)];
2223
+ };
2224
+
2225
+ const getActionVirtualDom = action => {
2226
+ switch (action.type) {
2227
+ case Button$2:
2228
+ return getActionButtonVirtualDom(action);
2229
+ default:
2230
+ return [];
2231
+ }
2232
+ };
2233
+
2234
+ const getActionsVirtualDom = actions => {
2235
+ return [{
2236
+ type: Div$1,
2237
+ className: Actions,
2238
+ role: ToolBar,
2239
+ childCount: actions.length
2240
+ }, ...actions.flatMap(getActionVirtualDom)];
2241
+ };
2242
+
2243
+ const renderActions = uid => {
2244
+ const {
2245
+ oldState,
2246
+ newState
2247
+ } = get$1(uid);
2248
+ if (oldState === newState) {
2249
+ return [];
2250
+ }
2251
+ const actions = [];
2252
+ const dom = getActionsVirtualDom(actions);
2253
+ return dom;
2254
+ };
2255
+
2256
+ const renderEventListeners = () => {
2257
+ return [{
2258
+ name: HandleContextMenu,
2259
+ params: ['handleContextMenu', 'event.button', 'event.clientX', 'event.clientY'],
2260
+ preventDefault: true
2261
+ }, {
2262
+ name: HandleWheel,
2263
+ params: ['handleWheel', 'event.deltaMode', 'event.deltaY'],
2264
+ passive: true
2265
+ }];
2266
+ };
2267
+
1568
2268
  const saveState = state => {
1569
2269
  const {
1570
2270
  searchValue
@@ -1574,19 +2274,64 @@ const saveState = state => {
1574
2274
  };
1575
2275
  };
1576
2276
 
2277
+ const scrollDown = state => {
2278
+ const {
2279
+ finalDeltaY,
2280
+ deltaY
2281
+ } = state;
2282
+ const newDeltaY = Math.min(deltaY + 20, finalDeltaY);
2283
+ return setDeltaY(state, newDeltaY);
2284
+ };
2285
+
2286
+ const selectIndex = (state, index) => {
2287
+ return {
2288
+ ...state,
2289
+ focusedIndex: index
2290
+ };
2291
+ };
2292
+
2293
+ const toggleSuggest = () => {
2294
+ // TODO
2295
+ };
2296
+
1577
2297
  const commandMap = {
1578
2298
  'SearchExtensions.clearSearchResults': clearSearchResults,
2299
+ 'SearchExtensions.closeSuggest': closeSuggest,
2300
+ 'SearchExtensions.create': create,
2301
+ 'SearchExtensions.diff': diff,
2302
+ 'SearchExtensions.focusFirst': focusFirst,
2303
+ 'SearchExtensions.focusIndex': focusIndex,
2304
+ 'SearchExtensions.focusLast': focusLast,
2305
+ 'SearchExtensions.focusNext': focusNext,
2306
+ 'SearchExtensions.focusNextPage': focusNextPage,
2307
+ 'SearchExtensions.focusPreviousPage': focusPreviousPage,
2308
+ 'SearchExtensions.getActions': getActions,
1579
2309
  'SearchExtensions.getKeyBindings': getKeyBindings,
2310
+ 'SearchExtensions.handleBlur': handleBlur,
2311
+ 'SearchExtensions.renderEventListeners': renderEventListeners,
2312
+ 'SearchExtensions.handleClick': handleClick,
2313
+ 'SearchExtensions.handleClickCurrent': handleClickCurrent,
2314
+ 'SearchExtensions.handleClickCurrentButKeepFocus': handleClickCurrentButKeepFocus,
2315
+ 'SearchExtensions.renderActions': renderActions,
2316
+ 'SearchExtensions.handleContextMenu': handleContextMenu,
2317
+ 'SearchExtensions.handleDisable': handleDisable,
2318
+ 'SearchExtensions.handleEnable': handleEnable,
2319
+ 'SearchExtensions.handleFocus': handleFocus,
2320
+ 'SearchExtensions.handleInstall': handleInstall,
2321
+ 'SearchExtensions.handleScrollBarCaptureLos': handleScrollBarCaptureLost,
2322
+ 'SearchExtensions.handleScrollBarClick': handleScrollBarClick,
2323
+ 'SearchExtensions.handleScrollBarMove': handleScrollBarMove,
2324
+ 'SearchExtensions.handleUninstall': handleUninstall,
2325
+ 'SearchExtensions.handleWheel': handleWheel,
2326
+ 'SearchExtensions.loadContent': loadContent,
2327
+ 'SearchExtensions.openSuggest': openSuggest,
1580
2328
  'SearchExtensions.render': doRender,
2329
+ 'SearchExtensions.saveState': saveState,
2330
+ 'SearchExtensions.scrollDown': scrollDown,
1581
2331
  'SearchExtensions.searchExtensions': searchExtensions,
1582
- 'SearchExtensions.saveState': saveState
1583
- };
1584
-
1585
- const RendererWorker = 1;
1586
-
1587
- const rpcs = Object.create(null);
1588
- const set = (id, rpc) => {
1589
- rpcs[id] = rpc;
2332
+ 'SearchExtensions.selectIndex': selectIndex,
2333
+ 'SearchExtensions.setDeltaY': setDeltaY,
2334
+ 'SearchExtensions.toggleSuggest': toggleSuggest
1590
2335
  };
1591
2336
 
1592
2337
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-search-view",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "Extension Search View Worker",
5
5
  "license": "MIT",
6
6
  "author": "Lvce Editor",