@lvce-editor/extension-search-view 2.1.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$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) => {
@@ -1181,6 +1192,160 @@ const clearSearchResults = state => {
1181
1192
  return handleInput(state, '');
1182
1193
  };
1183
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
+
1184
1349
  const Enter = 3;
1185
1350
  const Space = 9;
1186
1351
  const PageUp = 10;
@@ -1238,7 +1403,133 @@ const getKeyBindings = () => {
1238
1403
  }];
1239
1404
  };
1240
1405
 
1241
- const Button = 1;
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
+ };
1242
1533
 
1243
1534
  const ExtensionActions = 'ExtensionActions';
1244
1535
  const ExtensionActive = 'ExtensionActive';
@@ -1460,9 +1751,6 @@ const getVisible = state => {
1460
1751
  return visible;
1461
1752
  };
1462
1753
 
1463
- const ClearAll = 'ClearAll';
1464
- const Filter = 'Filter';
1465
-
1466
1754
  const px = value => {
1467
1755
  return `${value}px`;
1468
1756
  };
@@ -1574,19 +1862,65 @@ const saveState = state => {
1574
1862
  };
1575
1863
  };
1576
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
+
1577
1902
  const commandMap = {
1578
1903
  'SearchExtensions.clearSearchResults': clearSearchResults,
1904
+ 'SearchExtensions.closeSuggest': closeSuggest,
1905
+ 'SearchExtensions.create': create,
1906
+ 'SearchExtensions.diff': diff,
1907
+ 'SearchExtensions.focusIndex': focusIndex,
1908
+ 'SearchExtensions.getActions': getActions,
1579
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,
1580
1919
  'SearchExtensions.render': doRender,
1920
+ 'SearchExtensions.saveState': saveState,
1581
1921
  '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;
1922
+ 'SearchExtensions.setDeltaY': setDeltaY,
1923
+ 'SearchExtensions.toggleSuggest': toggleSuggest
1590
1924
  };
1591
1925
 
1592
1926
  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.2.0",
4
4
  "description": "Extension Search View Worker",
5
5
  "license": "MIT",
6
6
  "author": "Lvce Editor",