@lvce-editor/extension-search-view 3.8.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -967,7 +967,7 @@ const Disable = 'Disable';
967
967
  const InstallAnotherVersion = 'Install Another Version';
968
968
  const SearchExtensionsInMarketplace = 'Search Extensions in Marketplace';
969
969
  const ViewsAndMoreActions = 'Views and more Actions...';
970
- const Extensions = 'Extensions';
970
+ const Extensions$2 = 'Extensions';
971
971
  const Copy = 'Copy';
972
972
  const CopyExtensionId = 'CopyExtensionId';
973
973
 
@@ -981,7 +981,7 @@ const refresh = () => {
981
981
  return i18nString(Refresh$1);
982
982
  };
983
983
  const extensions = () => {
984
- return i18nString(Extensions);
984
+ return i18nString(Extensions$2);
985
985
  };
986
986
  const clearExtensionSearchResults = () => {
987
987
  return i18nString(ClearExtensionSearchResults);
@@ -1008,6 +1008,10 @@ const viewsAndMoreActions = () => {
1008
1008
  return i18nString(ViewsAndMoreActions);
1009
1009
  };
1010
1010
 
1011
+ const None$3 = 0;
1012
+ const Input = 1;
1013
+ const List$2 = 2;
1014
+
1011
1015
  const getFinalDeltaY = (height, itemHeight, itemsLength) => {
1012
1016
  const contentHeight = itemsLength * itemHeight;
1013
1017
  const finalDeltaY = Math.max(contentHeight - height, 0);
@@ -1039,6 +1043,12 @@ const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
1039
1043
  return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
1040
1044
  };
1041
1045
 
1046
+ const getScrollBarOffset$1 = (delta, finalDelta, size, scrollBarSize) => {
1047
+ const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
1048
+ return scrollBarOffset;
1049
+ };
1050
+ const getScrollBarY$1 = getScrollBarOffset$1;
1051
+
1042
1052
  const Installed = '@installed';
1043
1053
  const Enabled = '@enabled';
1044
1054
  const Disabled = '@disabled';
@@ -1159,7 +1169,8 @@ const handleInput = async (state, value) => {
1159
1169
  minimumSliderSize,
1160
1170
  height,
1161
1171
  platform,
1162
- assetDir
1172
+ assetDir,
1173
+ headerHeight
1163
1174
  } = state;
1164
1175
  // TODO cancel ongoing requests
1165
1176
  // TODO handle errors
@@ -1167,16 +1178,17 @@ const handleInput = async (state, value) => {
1167
1178
  if (items.length === 0) {
1168
1179
  return {
1169
1180
  ...state,
1170
- items,
1171
- minLineY: 0,
1172
- deltaY: 0,
1173
1181
  allExtensions,
1174
- maxLineY: 0,
1175
- scrollBarHeight: 0,
1182
+ deltaY: 0,
1176
1183
  finalDeltaY: 0,
1184
+ focus: Input,
1185
+ items,
1186
+ maxLineY: 0,
1177
1187
  message: noExtensionsFound(),
1178
- searchValue: value,
1179
- placeholder: searchExtensionsInMarketPlace()
1188
+ minLineY: 0,
1189
+ placeholder: searchExtensionsInMarketPlace(),
1190
+ scrollBarHeight: 0,
1191
+ searchValue: value
1180
1192
  };
1181
1193
  }
1182
1194
  const total = items.length;
@@ -1186,18 +1198,20 @@ const handleInput = async (state, value) => {
1186
1198
  const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
1187
1199
  const maxLineY = Math.min(numberOfVisible, total);
1188
1200
  const finalDeltaY = getFinalDeltaY(listHeight, itemHeight, total);
1201
+ const scrollBarY = getScrollBarY$1(0, finalDeltaY, height - headerHeight, scrollBarHeight);
1189
1202
  return {
1190
1203
  ...state,
1191
- items,
1192
- minLineY: 0,
1193
- deltaY: 0,
1194
1204
  allExtensions,
1195
- maxLineY,
1196
- scrollBarHeight,
1205
+ deltaY: 0,
1197
1206
  finalDeltaY,
1207
+ items,
1208
+ maxLineY,
1198
1209
  message: '',
1199
- searchValue: value,
1200
- placeholder: searchExtensionsInMarketPlace()
1210
+ minLineY: 0,
1211
+ placeholder: searchExtensionsInMarketPlace(),
1212
+ scrollBarHeight,
1213
+ scrollBarY,
1214
+ searchValue: value
1201
1215
  };
1202
1216
 
1203
1217
  // TODO handle out of order responses (a bit complicated)
@@ -1234,10 +1248,14 @@ const create$1 = (id, uri, x, y, width, height, platform, assetDir) => {
1234
1248
  assetDir,
1235
1249
  deltaY: 0,
1236
1250
  finalDeltaY: 0,
1251
+ focus: 0,
1252
+ focused: false,
1237
1253
  focusedIndex: 0,
1238
1254
  handleOffset: 0,
1239
1255
  headerHeight: 41,
1240
1256
  height,
1257
+ inputActions: [],
1258
+ inputSource: 0,
1241
1259
  itemHeight: 72,
1242
1260
  items: [],
1243
1261
  maxLineY: 0,
@@ -1249,58 +1267,45 @@ const create$1 = (id, uri, x, y, width, height, platform, assetDir) => {
1249
1267
  platform,
1250
1268
  scrollBarActive: false,
1251
1269
  scrollBarHeight: 0,
1270
+ scrollBarY: 0,
1252
1271
  searchValue: '',
1253
1272
  size: 0,
1273
+ uid: id,
1254
1274
  width,
1255
1275
  x,
1256
- y,
1257
- focused: false,
1258
- inputSource: 0
1276
+ y
1259
1277
  };
1260
1278
  set$1(id, state, state);
1261
1279
  };
1262
1280
 
1263
- const RenderHeader = 1;
1264
- const RenderItems = 4;
1265
- const RenderScrollBar = 5;
1266
- const RenderMessage = 6;
1267
- const RenderSearchValue = 7;
1268
-
1269
- const diffType$5 = RenderItems;
1270
- const isEqual$5 = (oldState, newState) => {
1271
- return true;
1272
- };
1273
-
1274
- const diffType$4 = RenderHeader;
1275
- const isEqual$4 = (oldState, newState) => {
1276
- return oldState.placeholder === newState.placeholder;
1277
- };
1278
-
1279
- const diffType$3 = RenderItems;
1280
- const isEqual$3 = (oldState, newState) => {
1281
- return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.deltaY === newState.deltaY && oldState.focusedIndex === newState.focusedIndex;
1282
- };
1283
-
1284
- const diffType$2 = RenderMessage;
1285
1281
  const isEqual$2 = (oldState, newState) => {
1286
- return oldState.message === newState.message;
1282
+ if (!newState.focus) {
1283
+ return true;
1284
+ }
1285
+ return oldState.focus === newState.focus;
1287
1286
  };
1288
1287
 
1289
- const diffType$1 = RenderScrollBar;
1290
1288
  const isEqual$1 = (oldState, newState) => {
1291
- 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;
1289
+ return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.deltaY === newState.deltaY && oldState.focusedIndex === newState.focusedIndex && oldState.message === newState.message && oldState.inputActions === newState.inputActions && oldState.placeholder === newState.placeholder;
1292
1290
  };
1293
1291
 
1294
1292
  const User = 1;
1295
1293
  const Script = 2;
1296
1294
 
1297
- const diffType = RenderSearchValue;
1298
1295
  const isEqual = (oldState, newState) => {
1299
1296
  return newState.inputSource === User || oldState.searchValue === newState.searchValue;
1300
1297
  };
1301
1298
 
1302
- const modules = [isEqual$1, isEqual$2, isEqual$4, isEqual$3, isEqual$5, isEqual];
1303
- const numbers = [diffType$1, diffType$2, diffType$4, diffType$3, diffType$5, diffType];
1299
+ const RenderHeader = 1;
1300
+ const RenderFocus = 2;
1301
+ const RenderItems = 4;
1302
+ const RenderScrollBar = 5;
1303
+ const RenderMessage = 6;
1304
+ const RenderSearchValue = 7;
1305
+ const RenderFocusContext = 8;
1306
+
1307
+ const modules = [isEqual$1, isEqual$2, isEqual, isEqual$2];
1308
+ const numbers = [RenderItems, RenderFocus, RenderSearchValue, RenderFocusContext];
1304
1309
 
1305
1310
  const diff2 = uid => {
1306
1311
  const {
@@ -1327,32 +1332,53 @@ const dispose = uid => {
1327
1332
  const getNumberOfVisibleItems = (listHeight, itemHeight) => {
1328
1333
  return Math.ceil(listHeight / itemHeight) + 1;
1329
1334
  };
1335
+ const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
1336
+ const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
1337
+ return scrollBarOffset;
1338
+ };
1339
+ const getScrollBarY = getScrollBarOffset;
1330
1340
  const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength) => {
1341
+ const {
1342
+ finalDeltaY,
1343
+ height,
1344
+ headerHeight,
1345
+ scrollBarHeight
1346
+ } = state;
1331
1347
  const newMaxLineY = Math.min(index + 1, itemsLength);
1332
1348
  const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
1333
1349
  const newMinLineY = Math.max(newMaxLineY - fittingItems, 0);
1334
1350
  const newDeltaY = itemsLength < fittingItems ? 0 : newMinLineY * itemHeight - listHeight % itemHeight + itemHeight;
1351
+ const scrollBarY = getScrollBarY(newDeltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
1335
1352
  return {
1336
1353
  ...state,
1337
1354
  focusedIndex: index,
1338
1355
  minLineY: newMinLineY,
1339
1356
  maxLineY: newMaxLineY,
1340
1357
  focused: true,
1341
- deltaY: newDeltaY
1358
+ deltaY: newDeltaY,
1359
+ scrollBarY
1342
1360
  };
1343
1361
  };
1344
1362
  const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) => {
1363
+ const {
1364
+ finalDeltaY,
1365
+ height,
1366
+ headerHeight,
1367
+ scrollBarHeight
1368
+ } = state;
1345
1369
  const newMinLineY = index;
1346
1370
  const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
1347
1371
  const newMaxLineY = Math.min(newMinLineY + fittingItems, itemsLength);
1348
1372
  const newDeltaY = newMinLineY * itemHeight;
1373
+ const scrollBarY = getScrollBarY(newDeltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
1349
1374
  return {
1350
1375
  ...state,
1351
1376
  focusedIndex: index,
1352
1377
  minLineY: newMinLineY,
1353
1378
  maxLineY: newMaxLineY,
1354
1379
  focused: true,
1355
- deltaY: newDeltaY
1380
+ deltaY: newDeltaY,
1381
+ scrollBarY
1356
1382
  };
1357
1383
  };
1358
1384
  const focusIndex = (state, index) => {
@@ -1487,10 +1513,16 @@ const getActions = () => {
1487
1513
  }];
1488
1514
  };
1489
1515
 
1490
- const commandIds = ['clearSearchResults', 'closeSuggest', 'focusFirst', 'focusLast', 'focusNext', 'focusNextPage', 'focusPrevious', 'focusPreviousPage', 'handleBlur', 'handleClick', 'handleClickFilter', 'handleContextMenu', 'handleDisable', 'handleFocus', 'handleInput', 'handleInstall', 'handleScrollBarCaptureLost', 'handleScrollBarClick', 'handleScrollBarMove', 'handleScrollBarThumbPointerMove', 'handleUninstall', 'handleWheel', 'openSuggest', 'render', 'saveState', 'scrollDown', 'selectIndex', 'setDeltaY', 'toggleSuggest'];
1516
+ const commandMapRef = {};
1491
1517
 
1518
+ const toCommandId = key => {
1519
+ const dotIndex = key.indexOf('.');
1520
+ return key.slice(dotIndex + 1);
1521
+ };
1492
1522
  const getCommandIds = () => {
1493
- return commandIds;
1523
+ const keys = Object.keys(commandMapRef);
1524
+ const ids = keys.map(toCommandId);
1525
+ return ids;
1494
1526
  };
1495
1527
 
1496
1528
  const Enter = 3;
@@ -1505,6 +1537,7 @@ const DownArrow = 16;
1505
1537
  const CtrlCmd = 1 << 11 >>> 0;
1506
1538
 
1507
1539
  const FocusExtensions = 15;
1540
+ const FocusExtensionsInput = 7000;
1508
1541
 
1509
1542
  const getKeyBindings = () => {
1510
1543
  return [{
@@ -1550,39 +1583,46 @@ const getKeyBindings = () => {
1550
1583
  }];
1551
1584
  };
1552
1585
 
1553
- const None$1 = 0;
1586
+ const None$2 = 0;
1554
1587
 
1555
1588
  const getMenuEntries = () => {
1556
1589
  return [{
1557
1590
  id: 'enable',
1558
1591
  label: enable(),
1559
- flags: None$1,
1592
+ flags: None$2,
1560
1593
  command: 'SearchExtensions.enable'
1561
1594
  }, {
1562
1595
  id: 'disable',
1563
1596
  label: disable(),
1564
- flags: None$1,
1597
+ flags: None$2,
1565
1598
  command: 'SearchExtensions.disable'
1566
1599
  }, {
1567
1600
  id: 'installAnotherVersion',
1568
1601
  label: installAnotherVersion(),
1569
- flags: None$1,
1602
+ flags: None$2,
1570
1603
  command: 'SearchExtensions.installAnotherVersion'
1571
1604
  }, {
1572
1605
  id: 'copy',
1573
1606
  label: copy(),
1574
- flags: None$1,
1607
+ flags: None$2,
1575
1608
  command: 'SearchExtensions.copy'
1576
1609
  }, {
1577
1610
  id: 'copyExtensionId',
1578
1611
  label: copyExtensionId(),
1579
- flags: None$1,
1612
+ flags: None$2,
1580
1613
  command: 'SearchExtensions.copyExtensionId'
1581
1614
  }];
1582
1615
  };
1583
1616
 
1584
1617
  const handleBlur = state => {
1585
- return state;
1618
+ return {
1619
+ ...state,
1620
+ focus: None$3
1621
+ };
1622
+ };
1623
+
1624
+ const getExtensionDetailUri = extensionId => {
1625
+ return `extension-detail://${extensionId}`;
1586
1626
  };
1587
1627
 
1588
1628
  const rpcs = Object.create(null);
@@ -1625,36 +1665,22 @@ const {
1625
1665
  const showContextMenu$1 = async (x, y, id, ...args) => {
1626
1666
  return invoke$3('ContextMenu.show', x, y, id, ...args);
1627
1667
  };
1628
- const setFocus$2 = key => {
1629
- return invoke$3('Focus.setFocus', key);
1630
- };
1631
1668
  const openUri$2 = async (uri, focus, options) => {
1632
1669
  await invoke$3('Main.openUri', uri, focus, options);
1633
1670
  };
1634
- const RendererWorker$2 = {
1671
+ const RendererWorker = {
1635
1672
  __proto__: null,
1636
1673
  invoke: invoke$3,
1637
1674
  openUri: openUri$2,
1638
1675
  set: set$3,
1639
- setFocus: setFocus$2,
1640
1676
  showContextMenu: showContextMenu$1};
1641
1677
 
1642
1678
  const {
1643
1679
  invoke,
1644
1680
  set,
1645
1681
  showContextMenu,
1646
- setFocus: setFocus$1,
1647
1682
  openUri: openUri$1
1648
- } = RendererWorker$2;
1649
-
1650
- const RendererWorker = {
1651
- __proto__: null,
1652
- invoke,
1653
- openUri: openUri$1,
1654
- set,
1655
- setFocus: setFocus$1,
1656
- showContextMenu
1657
- };
1683
+ } = RendererWorker;
1658
1684
 
1659
1685
  const openUri = async uri => {
1660
1686
  return openUri$1(uri);
@@ -1667,33 +1693,33 @@ const handleClick = async (state, index) => {
1667
1693
  } = state;
1668
1694
  const actualIndex = index + minLineY;
1669
1695
  const extension = items[actualIndex];
1670
- const uri = `extension-detail://${extension.id}`;
1696
+ const uri = getExtensionDetailUri(extension.id);
1671
1697
  await openUri(uri);
1672
- return focusIndex(state, actualIndex);
1698
+ const partialNewState = focusIndex(state, actualIndex);
1699
+ const newState = {
1700
+ ...partialNewState,
1701
+ focus: List$2
1702
+ };
1703
+ return newState;
1673
1704
  };
1674
1705
 
1675
- const getListIndex = (eventX, eventY, x, y, deltaY, itemHeight) => {
1676
- const relativeY = eventY - y + deltaY;
1706
+ const getListIndex = (eventX, eventY, x, y, deltaY, itemHeight, headerHeight) => {
1707
+ const relativeDeltaY = deltaY % itemHeight;
1708
+ const relativeY = eventY - y - headerHeight + relativeDeltaY;
1677
1709
  const index = Math.floor(relativeY / itemHeight);
1678
1710
  return index;
1679
1711
  };
1680
1712
 
1681
- const selectIndex = (state, index) => {
1682
- return {
1683
- ...state,
1684
- focusedIndex: index
1685
- };
1686
- };
1687
-
1688
1713
  const handleClickAt = async (state, eventX, eventY) => {
1689
1714
  const {
1690
1715
  x,
1691
1716
  y,
1692
1717
  itemHeight,
1693
- deltaY
1718
+ deltaY,
1719
+ headerHeight
1694
1720
  } = state;
1695
- const index = getListIndex(eventX, eventY, x, y, deltaY, itemHeight);
1696
- return selectIndex(state, index);
1721
+ const index = getListIndex(eventX, eventY, x, y, deltaY, itemHeight, headerHeight);
1722
+ return handleClick(state, index);
1697
1723
  };
1698
1724
 
1699
1725
  const handleClickCurrent = state => {
@@ -1734,13 +1760,11 @@ const handleEnable = (state, id) => {
1734
1760
  return state;
1735
1761
  };
1736
1762
 
1737
- const {
1738
- setFocus
1739
- } = RendererWorker;
1740
-
1741
1763
  const handleFocus = async state => {
1742
- await setFocus(FocusExtensions);
1743
- return state;
1764
+ return {
1765
+ ...state,
1766
+ focus: List$2
1767
+ };
1744
1768
  };
1745
1769
 
1746
1770
  // TODO show error / warning when installment fails / times out
@@ -1779,12 +1803,6 @@ const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
1779
1803
  };
1780
1804
  };
1781
1805
 
1782
- const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
1783
- const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
1784
- return scrollBarOffset;
1785
- };
1786
- const getScrollBarY = getScrollBarOffset;
1787
-
1788
1806
  const clamp = (num, min, max) => {
1789
1807
  number(num);
1790
1808
  number(min);
@@ -1800,7 +1818,9 @@ const setDeltaY = (state, value) => {
1800
1818
  finalDeltaY,
1801
1819
  deltaY,
1802
1820
  height,
1803
- headerHeight
1821
+ headerHeight,
1822
+ items,
1823
+ minimumSliderSize
1804
1824
  } = state;
1805
1825
  const listHeight = height - headerHeight;
1806
1826
  const newDeltaY = clamp(value, 0, finalDeltaY);
@@ -1810,15 +1830,21 @@ const setDeltaY = (state, value) => {
1810
1830
  // TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
1811
1831
  const minLineY = Math.floor(newDeltaY / itemHeight);
1812
1832
  const maxLineY = minLineY + getNumberOfVisibleItems$1(listHeight, itemHeight);
1833
+ const total = items.length;
1834
+ const contentHeight = total * itemHeight;
1835
+ const scrollBarHeight = getScrollBarSize(listHeight, contentHeight, minimumSliderSize);
1836
+ const scrollBarY = getScrollBarY$1(newDeltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
1813
1837
  return {
1814
1838
  ...state,
1815
1839
  deltaY: newDeltaY,
1816
1840
  minLineY,
1817
- maxLineY
1841
+ maxLineY,
1842
+ scrollBarY
1818
1843
  };
1819
1844
  };
1820
1845
 
1821
1846
  const handleScrollBarClick = (state, eventY) => {
1847
+ // TODO move this to list
1822
1848
  const {
1823
1849
  y,
1824
1850
  deltaY,
@@ -1829,7 +1855,7 @@ const handleScrollBarClick = (state, eventY) => {
1829
1855
  } = state;
1830
1856
  const contentHeight = height - headerHeight;
1831
1857
  const relativeY = eventY - y - headerHeight;
1832
- const currentScrollBarY = getScrollBarY(deltaY, finalDeltaY, contentHeight, scrollBarHeight);
1858
+ const currentScrollBarY = getScrollBarY$1(deltaY, finalDeltaY, contentHeight, scrollBarHeight);
1833
1859
  const diff = relativeY - currentScrollBarY;
1834
1860
  if (diff >= 0 && diff < scrollBarHeight) {
1835
1861
  return {
@@ -1901,6 +1927,38 @@ const getAllExtensions = platform => {
1901
1927
  return getAllExtensions$1(platform);
1902
1928
  };
1903
1929
 
1930
+ const HandleClearSearchResults = 'handleClearSearchResults';
1931
+ const HandleClickFilter = 'handleClickFilter';
1932
+ const HandleContextMenu = 'handleContextMenu';
1933
+ const HandleExtensionsInput = 'handleExtensionsInput';
1934
+ const HandleFocus = 'handleFocus';
1935
+ const HandlePointerDown = 'handlePointerDown';
1936
+ const HandleScrollBarMove = 'handleScrollBarMove';
1937
+ const HandleScrollBarPointerCaptureLost = 'handleScrollBarPointerCaptureLost';
1938
+ const HandleScrollBarPointerDown = 'handleScrollBarPointerDown';
1939
+ const HandleTouchEnd = 'handleTouchEnd';
1940
+ const HandleTouchMove = 'handleTouchMove';
1941
+ const HandleTouchStart = 'handleTouchStart';
1942
+ const HandleWheel = 'handleWheel';
1943
+
1944
+ const getInputActions = newState => {
1945
+ const clearEnabled = newState.searchValue.length > 0;
1946
+ const actions = [{
1947
+ onClick: HandleClearSearchResults,
1948
+ icon: `MaskIcon${ClearAll}`,
1949
+ title: clearExtensionSearchResults(),
1950
+ type: Button$1,
1951
+ enabled: clearEnabled
1952
+ }, {
1953
+ icon: `MaskIcon${Filter}`,
1954
+ title: filter(),
1955
+ type: Button$1,
1956
+ onClick: HandleClickFilter,
1957
+ enabled: true
1958
+ }];
1959
+ return actions;
1960
+ };
1961
+
1904
1962
  const Small = 1;
1905
1963
  const Normal = 2;
1906
1964
  const Large = 3;
@@ -2018,43 +2076,86 @@ const getSavedValue = savedState => {
2018
2076
  }
2019
2077
  return '';
2020
2078
  };
2079
+ const getSavedDeltaY = savedState => {
2080
+ if (savedState && typeof savedState === 'object' && 'deltaY' in savedState && typeof savedState.deltaY === 'number' && !Number.isNaN(savedState.deltaY)) {
2081
+ return savedState.deltaY;
2082
+ }
2083
+ return 0;
2084
+ };
2021
2085
 
2022
2086
  const restoreState = savedState => {
2023
2087
  const searchValue = getSavedValue(savedState);
2088
+ const savedDeltaY = getSavedDeltaY(savedState);
2024
2089
  return {
2025
- searchValue
2090
+ searchValue,
2091
+ deltaY: savedDeltaY
2026
2092
  };
2027
2093
  };
2028
2094
 
2029
- const loadContent = async (uid, savedState) => {
2030
- const {
2031
- newState
2032
- } = get$1(uid);
2095
+ const loadContent = async (state, savedState) => {
2033
2096
  const {
2034
2097
  width,
2035
2098
  platform,
2036
2099
  assetDir
2037
- } = newState;
2100
+ } = state;
2038
2101
  const {
2039
- searchValue
2102
+ searchValue,
2103
+ deltaY
2040
2104
  } = restoreState(savedState);
2041
2105
  // TODO just get local extensions on demand (not when query string is already different)
2042
2106
  const allExtensions = await getAllExtensions(platform);
2043
2107
  const size = getViewletSize(width);
2044
2108
  const normalized = normalizeExtension(allExtensions, platform, assetDir);
2109
+ const inputActions = getInputActions(state);
2045
2110
  const updatedState = await handleInput({
2046
- ...newState,
2111
+ ...state,
2047
2112
  allExtensions: normalized,
2048
2113
  size,
2049
- inputSource: Script
2114
+ inputSource: Script,
2115
+ inputActions,
2116
+ deltaY
2050
2117
  }, searchValue);
2051
- set$1(uid, newState, updatedState);
2118
+ return updatedState;
2052
2119
  };
2053
2120
 
2054
2121
  const openSuggest = state => {
2055
2122
  return state;
2056
2123
  };
2057
2124
 
2125
+ const Extensions$1 = 'extensions';
2126
+
2127
+ const getSelector = focus => {
2128
+ switch (focus) {
2129
+ case Input:
2130
+ return `[name="${Extensions$1}"]`;
2131
+ case List$2:
2132
+ return '.ListItems';
2133
+ default:
2134
+ return '';
2135
+ }
2136
+ };
2137
+ const renderFocus = newState => {
2138
+ const {
2139
+ uid,
2140
+ focus
2141
+ } = newState;
2142
+ if (!focus) {
2143
+ return [];
2144
+ }
2145
+ const selector = getSelector(focus);
2146
+ return ['Viewlet.focusSelector', uid, selector];
2147
+ };
2148
+
2149
+ const renderFocusContext = newState => {
2150
+ if (newState.focus === Input) {
2151
+ return ['Viewlet.setFocusContext', FocusExtensionsInput];
2152
+ }
2153
+ if (newState.focus === List$2) {
2154
+ return ['Viewlet.setFocusContext', FocusExtensions];
2155
+ }
2156
+ return [];
2157
+ };
2158
+
2058
2159
  const Actions = 'Actions';
2059
2160
  const ExtensionActions = 'ExtensionActions';
2060
2161
  const ExtensionActive = 'ExtensionActive';
@@ -2066,10 +2167,14 @@ const ExtensionListItemDetail = 'ExtensionListItemDetail';
2066
2167
  const ExtensionListItemFooter = 'ExtensionListItemFooter';
2067
2168
  const ExtensionListItemIcon = 'ExtensionListItemIcon';
2068
2169
  const ExtensionListItemName = 'ExtensionListItemName';
2170
+ const Extensions = 'Extensions';
2069
2171
  const IconButton = 'IconButton';
2172
+ const List$1 = 'List';
2070
2173
  const ListItems = 'ListItems';
2071
2174
  const MaskIcon = 'MaskIcon';
2072
2175
  const MultilineInputBox = 'MultilineInputBox';
2176
+ const ScrollBar = 'ScrollBar';
2177
+ const ScrollBarSmall = 'ScrollBarSmall';
2073
2178
  const ScrollBarThumb = 'ScrollBarThumb';
2074
2179
  const ScrollBarThumbActive = 'ScrollBarThumbActive';
2075
2180
  const SearchField = 'SearchField';
@@ -2077,24 +2182,25 @@ const SearchFieldButton = 'SearchFieldButton';
2077
2182
  const SearchFieldButtons = 'SearchFieldButtons';
2078
2183
  const SearchFieldContainer = 'SearchFieldContainer';
2079
2184
  const SearchFieldDisabled = 'SearchFieldDisabled';
2080
-
2081
- const HandleContextMenu = 'handleContextMenu';
2082
- const HandlePointerDown = 'handlePointerDown';
2083
- const HandleTouchStart = 'handleTouchStart';
2084
- const HandleWheel = 'handleWheel';
2085
- const HandleExtensionsInput = 'handleExtensionsInput';
2086
- const HandleClearSearchResults = 'handleClearSearchResults';
2087
- const HandleClickFilter = 'handleClickFilter';
2185
+ const Viewlet = 'Viewlet';
2088
2186
 
2089
2187
  const List = 'list';
2090
2188
  const ListItem = 'listitem';
2091
- const None = 'none';
2189
+ const None$1 = 'none';
2092
2190
  const ToolBar = 'toolbar';
2093
2191
 
2192
+ const None = 'none';
2193
+ const AriaRoles = {
2194
+ __proto__: null,
2195
+ None};
2094
2196
  const mergeClassNames = (...classNames) => {
2095
2197
  return classNames.filter(Boolean).join(' ');
2096
2198
  };
2199
+ const Div$1 = 4;
2097
2200
  const Text = 12;
2201
+ const VirtualDomElements = {
2202
+ __proto__: null,
2203
+ Div: Div$1};
2098
2204
  const text = data => {
2099
2205
  return {
2100
2206
  type: Text,
@@ -2140,7 +2246,7 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
2140
2246
  const dom = [{
2141
2247
  type: Div,
2142
2248
  className: SearchField,
2143
- role: None,
2249
+ role: None$1,
2144
2250
  childCount: 2
2145
2251
  }, {
2146
2252
  type: TextArea,
@@ -2162,7 +2268,7 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
2162
2268
  dom.unshift({
2163
2269
  type: Div,
2164
2270
  className: SearchFieldContainer,
2165
- role: None,
2271
+ role: None$1,
2166
2272
  childCount: 1 + outsideButtons.length
2167
2273
  });
2168
2274
  dom.push(...outsideButtons.flatMap(getSearchFieldButtonVirtualDom));
@@ -2179,24 +2285,6 @@ const getExtensionHeaderVirtualDom = (placeholder, actions) => {
2179
2285
  return [parentNode, ...getSearchFieldVirtualDom('extensions', placeholder, HandleExtensionsInput, actions, [])];
2180
2286
  };
2181
2287
 
2182
- const getInputActions = newState => {
2183
- const clearEnabled = newState.searchValue.length > 0;
2184
- const actions = [{
2185
- onClick: HandleClearSearchResults,
2186
- icon: `MaskIcon${ClearAll}`,
2187
- title: clearExtensionSearchResults(),
2188
- type: Button$1,
2189
- enabled: clearEnabled
2190
- }, {
2191
- icon: `MaskIcon${Filter}`,
2192
- title: filter(),
2193
- type: Button$1,
2194
- onClick: HandleClickFilter,
2195
- enabled: true
2196
- }];
2197
- return actions;
2198
- };
2199
-
2200
2288
  const renderHeader = newState => {
2201
2289
  const actions = getInputActions(newState);
2202
2290
  const dom = getExtensionHeaderVirtualDom(newState.placeholder, actions);
@@ -2267,7 +2355,7 @@ const getExtensionListItemVirtualDom = extension => {
2267
2355
  type: Img,
2268
2356
  src: icon,
2269
2357
  className: ExtensionListItemIcon,
2270
- role: None,
2358
+ role: None$1,
2271
2359
  childCount: 0
2272
2360
  }, listItemDetail, listItemName, text(name), listItemDescription, text(description), listItemFooter, listItemAuthorName, text(publisher), {
2273
2361
  type: Div,
@@ -2284,10 +2372,14 @@ const getExtensionsListVirtualDom = visibleExtensions => {
2284
2372
  tabIndex: 0,
2285
2373
  ariaLabel: extensions(),
2286
2374
  role: List,
2287
- oncontextmenu: HandleContextMenu,
2288
- onpointerdown: HandlePointerDown,
2289
- ontouchstart: HandleTouchStart,
2290
- onwheelpassive: HandleWheel,
2375
+ onContextmenu: HandleContextMenu,
2376
+ onContextMenu: HandleContextMenu,
2377
+ onFocus: HandleFocus,
2378
+ onPointerDown: HandlePointerDown,
2379
+ onTouchEnd: HandleTouchEnd,
2380
+ onTouchMove: HandleTouchMove,
2381
+ onTouchStart: HandleTouchStart,
2382
+ onWheel: HandleWheel,
2291
2383
  childCount: visibleExtensions.length
2292
2384
  }, ...visibleExtensions.flatMap(getExtensionListItemVirtualDom)];
2293
2385
  return dom;
@@ -2299,6 +2391,36 @@ const getExtensionsVirtualDom = visibleExtensions => {
2299
2391
  return dom;
2300
2392
  };
2301
2393
 
2394
+ const px = value => {
2395
+ return `${value}px`;
2396
+ };
2397
+ const position = (x, y) => {
2398
+ return `${x}px ${y}px`;
2399
+ };
2400
+
2401
+ const getScrollBarVirtualDom = (scrollBarHeight, scrollBarTop) => {
2402
+ const shouldShowScrollbar = scrollBarHeight > 0;
2403
+ if (!shouldShowScrollbar) {
2404
+ return [];
2405
+ }
2406
+ // TODO move the dynamic css into a css adopted stylesheet
2407
+ const heightString = px(scrollBarHeight);
2408
+ const translateString = position(0, scrollBarTop);
2409
+ return [{
2410
+ type: Div,
2411
+ className: mergeClassNames(ScrollBar, ScrollBarSmall),
2412
+ onPointerDown: HandleScrollBarPointerDown,
2413
+ // TODO support pointercapture event
2414
+ childCount: 1
2415
+ }, {
2416
+ type: Div,
2417
+ className: ScrollBarThumb,
2418
+ childCount: 0,
2419
+ height: heightString,
2420
+ translate: translateString
2421
+ }];
2422
+ };
2423
+
2302
2424
  const getVisibleItem = (item, setSize, itemHeight, minLineY, relative, i, focusedIndex) => {
2303
2425
  // TODO use normal parameters
2304
2426
  const {
@@ -2340,34 +2462,56 @@ const getVisible = state => {
2340
2462
  return visible;
2341
2463
  };
2342
2464
 
2343
- const renderItems = newState => {
2344
- // TODO render extensions incrementally when scrolling
2345
- const visibleExtensions = getVisible(newState);
2346
- const dom = getExtensionsVirtualDom(visibleExtensions);
2347
- return ['setExtensionsDom', dom];
2465
+ const getContentVirtualDom = (visibleExtensions, message, scrollBarHeight, scrollBarY) => {
2466
+ if (message) {
2467
+ return [{
2468
+ type: VirtualDomElements.Div,
2469
+ childCount: 1
2470
+ }, text(message)];
2471
+ }
2472
+ return [{
2473
+ type: VirtualDomElements.Div,
2474
+ className: mergeClassNames(Viewlet, List$1),
2475
+ childCount: 2
2476
+ }, ...getExtensionsVirtualDom(visibleExtensions), ...getScrollBarVirtualDom(scrollBarHeight, scrollBarY)];
2477
+ };
2478
+ const getExtensionsViewVirtualDom = state => {
2479
+ const visibleExtensions = getVisible(state);
2480
+ const {
2481
+ placeholder,
2482
+ inputActions,
2483
+ message,
2484
+ scrollBarHeight,
2485
+ scrollBarY
2486
+ } = state;
2487
+ return [{
2488
+ type: VirtualDomElements.Div,
2489
+ className: mergeClassNames(Viewlet, Extensions),
2490
+ childCount: 2,
2491
+ ariaLive: 'polite',
2492
+ ariaBusy: false,
2493
+ role: AriaRoles.None
2494
+ }, ...getExtensionHeaderVirtualDom(placeholder, inputActions), ...getContentVirtualDom(visibleExtensions, message, scrollBarHeight, scrollBarY)];
2495
+ };
2496
+
2497
+ const renderItems2 = newState => {
2498
+ const dom = getExtensionsViewVirtualDom(newState);
2499
+ return ['Viewlet.setDom2', newState.uid, dom];
2348
2500
  };
2349
2501
 
2350
2502
  const SetMessage = 'setMessage';
2351
2503
  const SetScrollBar = 'setScrollBar';
2352
- const SetSearchValue = 'setSearchValue';
2353
2504
 
2354
2505
  const renderMessage = newState => {
2355
2506
  return [/* method */SetMessage, /* message */newState.message];
2356
2507
  };
2357
2508
 
2358
- const px = value => {
2359
- return `${value}px`;
2360
- };
2361
- const position = (x, y) => {
2362
- return `${x}px ${y}px`;
2363
- };
2364
-
2365
2509
  const renderScrollBar = newState => {
2366
2510
  const listHeight = getListHeight(newState.items.length, newState.itemHeight, newState.height);
2367
2511
  const total = newState.items.length;
2368
2512
  const contentHeight = total * newState.itemHeight;
2369
2513
  const scrollBarHeight = getScrollBarSize(listHeight, contentHeight, newState.minimumSliderSize);
2370
- const scrollBarY = getScrollBarY(newState.deltaY, newState.finalDeltaY, newState.height - newState.headerHeight, scrollBarHeight);
2514
+ const scrollBarY = getScrollBarY$1(newState.deltaY, newState.finalDeltaY, newState.height - newState.headerHeight, scrollBarHeight);
2371
2515
  const roundedScrollBarY = Math.round(scrollBarY);
2372
2516
  const heightString = px(scrollBarHeight);
2373
2517
  const translateString = position(0, roundedScrollBarY);
@@ -2379,13 +2523,13 @@ const renderScrollBar = newState => {
2379
2523
  };
2380
2524
 
2381
2525
  const renderSearchValue = newState => {
2382
- return [/* method */SetSearchValue, '', newState.searchValue];
2526
+ return [/* method */'Viewlet.setValueByName', newState.uid, Extensions$1, newState.searchValue];
2383
2527
  };
2384
2528
 
2385
2529
  const getRenderer = diffType => {
2386
2530
  switch (diffType) {
2387
2531
  case RenderItems:
2388
- return renderItems;
2532
+ return renderItems2;
2389
2533
  case RenderMessage:
2390
2534
  return renderMessage;
2391
2535
  case RenderScrollBar:
@@ -2394,6 +2538,10 @@ const getRenderer = diffType => {
2394
2538
  return renderSearchValue;
2395
2539
  case RenderHeader:
2396
2540
  return renderHeader;
2541
+ case RenderFocus:
2542
+ return renderFocus;
2543
+ case RenderFocusContext:
2544
+ return renderFocusContext;
2397
2545
  default:
2398
2546
  throw new Error('unknown renderer');
2399
2547
  }
@@ -2403,7 +2551,7 @@ const applyRender = (oldState, newState, diffResult) => {
2403
2551
  const commands = [];
2404
2552
  for (const item of diffResult) {
2405
2553
  const fn = getRenderer(item);
2406
- commands.push(fn(newState));
2554
+ commands.push(fn(newState, oldState));
2407
2555
  }
2408
2556
  return commands;
2409
2557
  };
@@ -2422,7 +2570,7 @@ const getIconVirtualDom = (icon, type = Div) => {
2422
2570
  return {
2423
2571
  type,
2424
2572
  className: mergeClassNames(MaskIcon, `MaskIcon${icon}`),
2425
- role: None,
2573
+ role: None$1,
2426
2574
  childCount: 0
2427
2575
  };
2428
2576
  };
@@ -2478,19 +2626,37 @@ const renderEventListeners = () => {
2478
2626
  name: HandleContextMenu,
2479
2627
  params: ['handleContextMenu', 'event.button', 'event.clientX', 'event.clientY'],
2480
2628
  preventDefault: true
2629
+ }, {
2630
+ name: HandlePointerDown,
2631
+ params: ['handleClickAt', 'event.clientX', 'event.clientY'],
2632
+ preventDefault: true
2633
+ }, {
2634
+ name: HandleScrollBarPointerDown,
2635
+ params: ['handleScrollBarClick', 'event.clientY'],
2636
+ preventDefault: true,
2637
+ trackPointerEvents: [HandleScrollBarMove, HandleScrollBarPointerCaptureLost]
2638
+ }, {
2639
+ name: HandleScrollBarMove,
2640
+ params: ['handleScrollBarMove', 'event.clientY']
2641
+ }, {
2642
+ name: HandleScrollBarPointerCaptureLost,
2643
+ params: ['handleScrollBarCaptureLost']
2481
2644
  }, {
2482
2645
  name: HandleWheel,
2483
2646
  params: ['handleWheel', 'event.deltaMode', 'event.deltaY'],
2484
2647
  passive: true
2485
2648
  }, {
2486
2649
  name: HandleExtensionsInput,
2487
- params: ['handleExtensionsInput', 'event.target.value', User]
2650
+ params: ['handleInput', 'event.target.value', User]
2488
2651
  }, {
2489
2652
  name: HandleClearSearchResults,
2490
2653
  params: ['clearSearchResults']
2491
2654
  }, {
2492
2655
  name: HandleClickFilter,
2493
2656
  params: ['handleClickFilter']
2657
+ }, {
2658
+ name: HandleFocus,
2659
+ params: ['handleFocus']
2494
2660
  }];
2495
2661
  };
2496
2662
 
@@ -2499,10 +2665,12 @@ const saveState = uid => {
2499
2665
  newState
2500
2666
  } = get$1(uid);
2501
2667
  const {
2502
- searchValue
2668
+ searchValue,
2669
+ deltaY
2503
2670
  } = newState;
2504
2671
  return {
2505
- searchValue
2672
+ searchValue,
2673
+ deltaY
2506
2674
  };
2507
2675
  };
2508
2676
 
@@ -2515,6 +2683,13 @@ const scrollDown = state => {
2515
2683
  return setDeltaY(state, newDeltaY);
2516
2684
  };
2517
2685
 
2686
+ const selectIndex = (state, index) => {
2687
+ return {
2688
+ ...state,
2689
+ focusedIndex: index
2690
+ };
2691
+ };
2692
+
2518
2693
  const toggleSuggest = state => {
2519
2694
  return state;
2520
2695
  };
@@ -2553,7 +2728,7 @@ const commandMap = {
2553
2728
  'SearchExtensions.handleScrollBarThumbPointerMove': wrapCommand(handleScrollBarMove),
2554
2729
  'SearchExtensions.handleUninstall': wrapCommand(handleUninstall),
2555
2730
  'SearchExtensions.handleWheel': wrapCommand(handleWheel),
2556
- 'SearchExtensions.loadContent': loadContent,
2731
+ 'SearchExtensions.loadContent': wrapCommand(loadContent),
2557
2732
  'SearchExtensions.openSuggest': wrapCommand(openSuggest),
2558
2733
  'SearchExtensions.render3': render3,
2559
2734
  'SearchExtensions.renderActions': renderActions,
@@ -2569,8 +2744,9 @@ const commandMap = {
2569
2744
  };
2570
2745
 
2571
2746
  const listen = async () => {
2747
+ Object.assign(commandMapRef, commandMap);
2572
2748
  const rpc = await WebWorkerRpcClient.create({
2573
- commandMap: commandMap
2749
+ commandMap: commandMapRef
2574
2750
  });
2575
2751
  set(rpc);
2576
2752
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-search-view",
3
- "version": "3.8.0",
3
+ "version": "4.0.0",
4
4
  "description": "Extension Search View Worker",
5
5
  "license": "MIT",
6
6
  "author": "Lvce Editor",