@lvce-editor/extension-search-view 2.2.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.
@@ -923,36 +923,6 @@ const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
923
923
  return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
924
924
  };
925
925
 
926
- const Web = 1;
927
- const Electron = 2;
928
- const Remote = 3;
929
- const Test = 4;
930
-
931
- // TODO treeshake this function out
932
-
933
- /**
934
- * @returns {number}
935
- */
936
- const getPlatform = () => {
937
- // @ts-ignore
938
- if (typeof PLATFORM !== 'undefined') {
939
- // @ts-ignore
940
- return PLATFORM;
941
- }
942
- if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
943
- return Test;
944
- }
945
- // TODO find a better way to pass runtime environment
946
- if (typeof name !== 'undefined' && name.endsWith('(Electron)')) {
947
- return Electron;
948
- }
949
- if (typeof name !== 'undefined' && name.endsWith('(Web)')) {
950
- return Web;
951
- }
952
- return Remote;
953
- };
954
- const platform = getPlatform();
955
-
956
926
  const Installed = '@installed';
957
927
  const Enabled = '@enabled';
958
928
  const Disabled = '@disabled';
@@ -1001,9 +971,11 @@ const parseValue = value => {
1001
971
  };
1002
972
  };
1003
973
 
1004
- const assetDir = '';
974
+ const Web = 1;
975
+ const Electron = 2;
976
+ const Remote = 3;
1005
977
 
1006
- const getRemoteUrl = (extension, platform) => {
978
+ const getRemoteUrl = (extension, platform, assetDir) => {
1007
979
  if (platform === Remote || platform === Electron) {
1008
980
  if (extension.builtin) {
1009
981
  return `${assetDir}/extensions/${extension.id}/${extension.icon}`;
@@ -1013,9 +985,15 @@ const getRemoteUrl = (extension, platform) => {
1013
985
  return '';
1014
986
  };
1015
987
 
1016
- const ExtensionDefaultIcon = `${assetDir}/icons/extensionDefaultIcon.png`;
1017
- const ExtensionLanguageBasics = `${assetDir}/icons/language-icon.svg`;
1018
- 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
+ };
1019
997
 
1020
998
  const isLanguageBasicsExtension = extension => {
1021
999
  return extension.name && extension.name.startsWith('Language Basics');
@@ -1023,20 +1001,20 @@ const isLanguageBasicsExtension = extension => {
1023
1001
  const isThemeExtension = extension => {
1024
1002
  return extension.name && extension.name.endsWith(' Theme');
1025
1003
  };
1026
- const getIcon = (extension, platform) => {
1004
+ const getIcon = (extension, platform, assetDir) => {
1027
1005
  if (!extension) {
1028
- return ExtensionDefaultIcon;
1006
+ return getExtensionDefaultIcon(assetDir);
1029
1007
  }
1030
1008
  if (!extension.path || !extension.icon) {
1031
1009
  if (isLanguageBasicsExtension(extension)) {
1032
- return ExtensionLanguageBasics;
1010
+ return getExtensionLanguageBasicsIcon(assetDir);
1033
1011
  }
1034
1012
  if (isThemeExtension(extension)) {
1035
- return ExtensionTheme;
1013
+ return getExtensionThemeIcon(assetDir);
1036
1014
  }
1037
- return ExtensionDefaultIcon;
1015
+ return getExtensionDefaultIcon(assetDir);
1038
1016
  }
1039
- return getRemoteUrl(extension, platform);
1017
+ return getRemoteUrl(extension, platform, assetDir);
1040
1018
  };
1041
1019
  const getName = extension => {
1042
1020
  if (extension && extension.name) {
@@ -1090,6 +1068,12 @@ const matchesParsedValue = (extension, parsedValue) => {
1090
1068
  const toSorted = (array, compare) => {
1091
1069
  return [...array].sort(compare);
1092
1070
  };
1071
+ const isLastIndex = (array, index) => {
1072
+ return index === array.length - 1;
1073
+ };
1074
+ const lastIndex = array => {
1075
+ return array.length - 1;
1076
+ };
1093
1077
 
1094
1078
  const compareExtension = (extensionA, extensionB) => {
1095
1079
  return extensionA.name.localeCompare(extensionB.name) || extensionA.id.localeCompare(extensionB.id);
@@ -1099,7 +1083,7 @@ const sortExtensions = extensions => {
1099
1083
  return toSorted(extensions, compareExtension);
1100
1084
  };
1101
1085
 
1102
- const getExtensions = async (extensions, parsedValue, platform) => {
1086
+ const getExtensions = async (extensions, parsedValue, platform, assetDir = '') => {
1103
1087
  const filteredExtensions = [];
1104
1088
  for (const extension of extensions) {
1105
1089
  if (matchesParsedValue(extension, parsedValue)) {
@@ -1107,7 +1091,7 @@ const getExtensions = async (extensions, parsedValue, platform) => {
1107
1091
  name: getName(extension),
1108
1092
  id: getId(extension),
1109
1093
  publisher: getPublisher(extension),
1110
- icon: getIcon(extension, platform),
1094
+ icon: getIcon(extension, platform, assetDir),
1111
1095
  description: getDescription(extension)
1112
1096
  });
1113
1097
  }
@@ -1116,10 +1100,10 @@ const getExtensions = async (extensions, parsedValue, platform) => {
1116
1100
  return sortedExtensions;
1117
1101
  };
1118
1102
 
1119
- const searchExtensions = async (extensions, value, platform$1) => {
1103
+ const searchExtensions = async (extensions, value, platform, assetDir) => {
1120
1104
  try {
1121
1105
  const parsedValue = parseValue(value);
1122
- const filteredExtensions = await getExtensions(extensions, parsedValue, platform$1 || platform);
1106
+ const filteredExtensions = await getExtensions(extensions, parsedValue, platform, assetDir);
1123
1107
  return filteredExtensions;
1124
1108
  } catch (error) {
1125
1109
  throw new VError(error, 'Failed to search for extensions');
@@ -1134,11 +1118,12 @@ const handleInput = async (state, value) => {
1134
1118
  itemHeight,
1135
1119
  minimumSliderSize,
1136
1120
  height,
1137
- platform: platform$1
1121
+ platform,
1122
+ assetDir
1138
1123
  } = state;
1139
1124
  // TODO cancel ongoing requests
1140
1125
  // TODO handle errors
1141
- const items = await searchExtensions(allExtensions, value, platform$1 || platform);
1126
+ const items = await searchExtensions(allExtensions, value, platform, assetDir);
1142
1127
  if (items.length === 0) {
1143
1128
  return {
1144
1129
  ...state,
@@ -1228,26 +1213,47 @@ const create = (id, uri, x, y, width, height, platform) => {
1228
1213
  width,
1229
1214
  size: 0,
1230
1215
  negativeMargin: 0,
1231
- scrollBarActive: false
1216
+ scrollBarActive: false,
1217
+ x,
1218
+ y,
1219
+ handleOffset: 0,
1220
+ assetDir: ''
1232
1221
  };
1233
1222
  set$1(id, state, state);
1234
1223
  };
1235
1224
 
1225
+ const RenderHeader = 1;
1236
1226
  const RenderItems = 4;
1237
1227
  const RenderScrollBar = 5;
1228
+ const RenderMessage = 6;
1238
1229
 
1239
- const diffType$1 = RenderItems;
1240
- const isEqual$1 = (oldState, newState) => {
1230
+ const diffType$4 = RenderItems;
1231
+ const isEqual$4 = (oldState, newState) => {
1241
1232
  return true;
1242
1233
  };
1243
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
+
1244
1250
  const diffType = RenderScrollBar;
1245
1251
  const isEqual = (oldState, newState) => {
1246
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;
1247
1253
  };
1248
1254
 
1249
- const modules = [isEqual$1, isEqual];
1250
- const numbers = [diffType$1, diffType];
1255
+ const modules = [isEqual$4, isEqual, isEqual$1, isEqual$3, isEqual$2];
1256
+ const numbers = [diffType$4, diffType, diffType$1, diffType$3, diffType$2];
1251
1257
 
1252
1258
  const diff = (oldState, newState) => {
1253
1259
  const diffResult = [];
@@ -1325,7 +1331,66 @@ const focusIndex = (state, index) => {
1325
1331
  };
1326
1332
  };
1327
1333
 
1328
- const Button = 1;
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;
1329
1394
 
1330
1395
  const ClearAll = 'ClearAll';
1331
1396
  const Filter = 'Filter';
@@ -1334,12 +1399,12 @@ const Ellipsis = 'Ellipsis';
1334
1399
 
1335
1400
  const getActions = () => {
1336
1401
  return [{
1337
- type: Button,
1402
+ type: Button$2,
1338
1403
  id: refresh(),
1339
1404
  icon: Refresh,
1340
1405
  command: ''
1341
1406
  }, {
1342
- type: Button,
1407
+ type: Button$2,
1343
1408
  id: viewsAndMoreActions(),
1344
1409
  icon: Ellipsis,
1345
1410
  command: ''
@@ -1439,6 +1504,20 @@ const handleClick = async (state, index) => {
1439
1504
  return focusIndex(state, actualIndex);
1440
1505
  };
1441
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
+
1442
1521
  const show = async (x, y, id) => {
1443
1522
  number(x);
1444
1523
  number(y);
@@ -1462,8 +1541,12 @@ const handleEnable = (state, id) => {
1462
1541
  // TODO
1463
1542
  };
1464
1543
 
1465
- const handleFocus = () => {
1466
- // TODO
1544
+ const setFocus = async focusId => {
1545
+ await invoke('Focus.setFocus', focusId);
1546
+ };
1547
+
1548
+ const handleFocus = async () => {
1549
+ await setFocus(FocusExtensions);
1467
1550
  };
1468
1551
 
1469
1552
  // TODO show error / warning when installment fails / times out
@@ -1471,6 +1554,142 @@ const handleInstall = async (state, id) => {
1471
1554
  // TODO
1472
1555
  };
1473
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
+
1474
1693
  const getAllExtensions = async platform => {
1475
1694
  if (platform === Web) {
1476
1695
  return [];
@@ -1531,6 +1750,7 @@ const openSuggest = () => {
1531
1750
  // TODO
1532
1751
  };
1533
1752
 
1753
+ const Actions = 'Actions';
1534
1754
  const ExtensionActions = 'ExtensionActions';
1535
1755
  const ExtensionActive = 'ExtensionActive';
1536
1756
  const ExtensionHeader = 'ExtensionHeader';
@@ -1539,8 +1759,10 @@ const ExtensionListItemAuthorName = 'ExtensionListItemAuthorName';
1539
1759
  const ExtensionListItemDescription = 'ExtensionListItemDescription';
1540
1760
  const ExtensionListItemDetail = 'ExtensionListItemDetail';
1541
1761
  const ExtensionListItemFooter = 'ExtensionListItemFooter';
1762
+ const MaskIcon = 'MaskIcon';
1542
1763
  const ExtensionListItemIcon = 'ExtensionListItemIcon';
1543
1764
  const ExtensionListItemName = 'ExtensionListItemName';
1765
+ const IconButton = 'IconButton';
1544
1766
  const ListItems = 'ListItems';
1545
1767
  const MultilineInputBox = 'MultilineInputBox';
1546
1768
  const ScrollBarThumb = 'ScrollBarThumb';
@@ -1553,11 +1775,12 @@ const CheckBox = 'checkbox';
1553
1775
  const List = 'list';
1554
1776
  const ListItem = 'listitem';
1555
1777
  const None = 'none';
1778
+ const ToolBar = 'toolbar';
1556
1779
 
1557
- const Div = 4;
1558
- const Text = 12;
1559
- const Img = 17;
1560
- const TextArea = 62;
1780
+ const Div$1 = 4;
1781
+ const Img$1 = 17;
1782
+ const TextArea$1 = 62;
1783
+ const Button$1 = 1;
1561
1784
 
1562
1785
  const getSearchFieldButtonVirtualDom = button => {
1563
1786
  const {
@@ -1566,7 +1789,7 @@ const getSearchFieldButtonVirtualDom = button => {
1566
1789
  title
1567
1790
  } = button;
1568
1791
  return [{
1569
- type: Div,
1792
+ type: Div$1,
1570
1793
  className: `SearchFieldButton ${checked ? 'SearchFieldButtonChecked' : ''}`,
1571
1794
  title,
1572
1795
  role: CheckBox,
@@ -1574,7 +1797,7 @@ const getSearchFieldButtonVirtualDom = button => {
1574
1797
  tabIndex: 0,
1575
1798
  childCount: 1
1576
1799
  }, {
1577
- type: Div,
1800
+ type: Div$1,
1578
1801
  className: `MaskIcon ${icon}`,
1579
1802
  childCount: 0
1580
1803
  }];
@@ -1582,12 +1805,12 @@ const getSearchFieldButtonVirtualDom = button => {
1582
1805
 
1583
1806
  const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus = '') => {
1584
1807
  const dom = [{
1585
- type: Div,
1808
+ type: Div$1,
1586
1809
  className: SearchField,
1587
1810
  role: None,
1588
1811
  childCount: 2
1589
1812
  }, {
1590
- type: TextArea,
1813
+ type: TextArea$1,
1591
1814
  className: MultilineInputBox,
1592
1815
  spellcheck: false,
1593
1816
  autocapitalize: 'off',
@@ -1598,13 +1821,13 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
1598
1821
  onFocus,
1599
1822
  childCount: 0
1600
1823
  }, {
1601
- type: Div,
1824
+ type: Div$1,
1602
1825
  className: SearchFieldButtons,
1603
1826
  childCount: insideButtons.length
1604
1827
  }, ...insideButtons.flatMap(getSearchFieldButtonVirtualDom)];
1605
1828
  if (outsideButtons.length > 0) {
1606
1829
  dom.unshift({
1607
- type: Div,
1830
+ type: Div$1,
1608
1831
  className: SearchFieldContainer,
1609
1832
  role: None,
1610
1833
  childCount: 1 + outsideButtons.length
@@ -1616,12 +1839,27 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
1616
1839
 
1617
1840
  const getExtensionHeaderVirtualDom = (placeholder, actions) => {
1618
1841
  return [{
1619
- type: Div,
1842
+ type: Div$1,
1620
1843
  className: ExtensionHeader,
1621
1844
  childCount: 1
1622
1845
  }, ...getSearchFieldVirtualDom('extensions', placeholder, 'handleExtensionsInput', actions, [])];
1623
1846
  };
1624
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
+
1625
1863
  const HandleContextMenu = 'handleContextMenu';
1626
1864
  const HandlePointerDown = 'handlePointerDown';
1627
1865
  const HandleTouchStart = 'handleTouchStart';
@@ -1629,7 +1867,134 @@ const HandleWheel = 'handleWheel';
1629
1867
 
1630
1868
  const Extension = 'Extension';
1631
1869
 
1632
- 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 => {
1633
1998
  return {
1634
1999
  type: Text,
1635
2000
  text: data,
@@ -1638,27 +2003,27 @@ const text = data => {
1638
2003
  };
1639
2004
 
1640
2005
  const listItemDetail = {
1641
- type: Div,
2006
+ type: Div$1,
1642
2007
  className: ExtensionListItemDetail,
1643
2008
  childCount: 3
1644
2009
  };
1645
2010
  const listItemName = {
1646
- type: Div,
2011
+ type: Div$1,
1647
2012
  className: ExtensionListItemName,
1648
2013
  childCount: 1
1649
2014
  };
1650
2015
  const listItemDescription = {
1651
- type: Div,
2016
+ type: Div$1,
1652
2017
  className: ExtensionListItemDescription,
1653
2018
  childCount: 1
1654
2019
  };
1655
2020
  const listItemFooter = {
1656
- type: Div,
2021
+ type: Div$1,
1657
2022
  className: ExtensionListItemFooter,
1658
2023
  childCount: 2
1659
2024
  };
1660
2025
  const listItemAuthorName = {
1661
- type: Div,
2026
+ type: Div$1,
1662
2027
  className: ExtensionListItemAuthorName,
1663
2028
  childCount: 1
1664
2029
  };
@@ -1674,7 +2039,7 @@ const getExtensionListItemVirtualDom = extension => {
1674
2039
  focused
1675
2040
  } = extension;
1676
2041
  const dom = [{
1677
- type: Div,
2042
+ type: Div$1,
1678
2043
  role: ListItem,
1679
2044
  ariaRoleDescription: Extension,
1680
2045
  className: ExtensionListItem,
@@ -1683,13 +2048,13 @@ const getExtensionListItemVirtualDom = extension => {
1683
2048
  top,
1684
2049
  childCount: 2
1685
2050
  }, {
1686
- type: Img,
2051
+ type: Img$1,
1687
2052
  src: icon,
1688
2053
  className: ExtensionListItemIcon,
1689
2054
  role: None,
1690
2055
  childCount: 0
1691
2056
  }, listItemDetail, listItemName, text(name), listItemDescription, text(description), listItemFooter, listItemAuthorName, text(publisher), {
1692
- type: Div,
2057
+ type: Div$1,
1693
2058
  className: ExtensionActions,
1694
2059
  childCount: 0
1695
2060
  }];
@@ -1702,7 +2067,7 @@ const getExtensionListItemVirtualDom = extension => {
1702
2067
 
1703
2068
  const getExtensionsListVirtualDom = visibleExtensions => {
1704
2069
  const dom = [{
1705
- type: Div,
2070
+ type: Div$1,
1706
2071
  className: ListItems,
1707
2072
  tabIndex: 0,
1708
2073
  ariaLabel: extensions(),
@@ -1751,68 +2116,61 @@ const getVisible = state => {
1751
2116
  return visible;
1752
2117
  };
1753
2118
 
1754
- const px = value => {
1755
- return `${value}px`;
1756
- };
1757
- const position = (x, y) => {
1758
- return `${x}px ${y}px`;
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];
1759
2124
  };
1760
2125
 
1761
2126
  const SetMessage = 'setMessage';
1762
2127
  const SetScrollBar = 'setScrollBar';
1763
2128
  const SetSearchValue = 'setSearchValue';
1764
2129
 
1765
- const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
1766
- const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
1767
- return scrollBarOffset;
2130
+ const renderMessage$1 = newState => {
2131
+ return [/* method */SetMessage, /* message */newState.message];
1768
2132
  };
1769
- const getScrollBarY = getScrollBarOffset;
1770
2133
 
1771
- const getListHeight = state => {
1772
- const {
1773
- height,
1774
- headerHeight
1775
- } = state;
1776
- return height - headerHeight;
2134
+ const px = value => {
2135
+ return `${value}px`;
2136
+ };
2137
+ const position = (x, y) => {
2138
+ return `${x}px ${y}px`;
2139
+ };
2140
+
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];
1777
2156
  };
2157
+
1778
2158
  const renderExtensions = {
1779
- isEqual(oldState, newState) {
1780
- return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.deltaY === newState.deltaY && oldState.focusedIndex === newState.focusedIndex;
1781
- },
2159
+ isEqual: isEqual$2,
1782
2160
  apply(oldState, newState) {
1783
- // TODO render extensions incrementally when scrolling
1784
- const visibleExtensions = getVisible(newState);
1785
- const dom = getExtensionsVirtualDom(visibleExtensions);
1786
- return ['setExtensionsDom', dom];
2161
+ return renderItems(newState);
1787
2162
  }
1788
2163
  };
1789
2164
  const renderScrollBar = {
1790
- isEqual(oldState, newState) {
1791
- 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;
1792
- },
2165
+ isEqual: isEqual,
1793
2166
  apply(oldState, newState) {
1794
- // @ts-ignore
1795
- const listHeight = getListHeight(newState);
1796
- const total = newState.items.length;
1797
- const contentHeight = total * newState.itemHeight;
1798
- const scrollBarHeight = getScrollBarSize(listHeight, contentHeight, newState.minimumSliderSize);
1799
- const scrollBarY = getScrollBarY(newState.deltaY, newState.finalDeltaY, newState.height - newState.headerHeight, scrollBarHeight);
1800
- const roundedScrollBarY = Math.round(scrollBarY);
1801
- const heightString = px(scrollBarHeight);
1802
- const translateString = position(0, roundedScrollBarY);
1803
- let className = ScrollBarThumb;
1804
- if (newState.scrollBarActive) {
1805
- className += ' ' + ScrollBarThumbActive;
1806
- }
1807
- return [/* method */SetScrollBar, translateString, heightString, className];
2167
+ return renderScrollBar$1(newState);
1808
2168
  }
1809
2169
  };
1810
2170
  const renderMessage = {
1811
- isEqual(oldState, newState) {
1812
- return oldState.message === newState.message;
1813
- },
2171
+ isEqual: isEqual$1,
1814
2172
  apply(oldState, newState) {
1815
- return [/* method */SetMessage, /* message */newState.message];
2173
+ return renderMessage$1(newState);
1816
2174
  }
1817
2175
  };
1818
2176
  const renderSearchValue = {
@@ -1824,22 +2182,9 @@ const renderSearchValue = {
1824
2182
  }
1825
2183
  };
1826
2184
  const renderHeader = {
1827
- isEqual(oldState, newState) {
1828
- return oldState.placeholder === newState.placeholder;
1829
- },
2185
+ isEqual: isEqual$3,
1830
2186
  apply(oldState, newState) {
1831
- const actions = [{
1832
- type: Button,
1833
- title: clearExtensionSearchResults(),
1834
- icon: `MaskIcon${ClearAll}`,
1835
- command: 'Extensions.clearSearchResults'
1836
- }, {
1837
- type: Button,
1838
- title: filter(),
1839
- icon: `MaskIcon${Filter}`
1840
- }];
1841
- const dom = getExtensionHeaderVirtualDom(newState.placeholder, actions);
1842
- return ['setHeaderDom', dom];
2187
+ return renderHeader$1(newState);
1843
2188
  }
1844
2189
  };
1845
2190
  const render = [renderScrollBar, renderMessage, renderExtensions, renderSearchValue, renderHeader];
@@ -1853,6 +2198,73 @@ const doRender = (oldState, newState) => {
1853
2198
  return commands;
1854
2199
  };
1855
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
+
1856
2268
  const saveState = state => {
1857
2269
  const {
1858
2270
  searchValue
@@ -1862,36 +2274,19 @@ const saveState = state => {
1862
2274
  };
1863
2275
  };
1864
2276
 
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);
2277
+ const scrollDown = state => {
1875
2278
  const {
1876
- itemHeight,
1877
2279
  finalDeltaY,
1878
- deltaY,
1879
- height,
1880
- headerHeight
2280
+ deltaY
1881
2281
  } = 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);
2282
+ const newDeltaY = Math.min(deltaY + 20, finalDeltaY);
2283
+ return setDeltaY(state, newDeltaY);
2284
+ };
2285
+
2286
+ const selectIndex = (state, index) => {
1890
2287
  return {
1891
2288
  ...state,
1892
- deltaY: newDeltaY,
1893
- minLineY,
1894
- maxLineY
2289
+ focusedIndex: index
1895
2290
  };
1896
2291
  };
1897
2292
 
@@ -1904,21 +2299,37 @@ const commandMap = {
1904
2299
  'SearchExtensions.closeSuggest': closeSuggest,
1905
2300
  'SearchExtensions.create': create,
1906
2301
  'SearchExtensions.diff': diff,
2302
+ 'SearchExtensions.focusFirst': focusFirst,
1907
2303
  'SearchExtensions.focusIndex': focusIndex,
2304
+ 'SearchExtensions.focusLast': focusLast,
2305
+ 'SearchExtensions.focusNext': focusNext,
2306
+ 'SearchExtensions.focusNextPage': focusNextPage,
2307
+ 'SearchExtensions.focusPreviousPage': focusPreviousPage,
1908
2308
  'SearchExtensions.getActions': getActions,
1909
2309
  'SearchExtensions.getKeyBindings': getKeyBindings,
1910
2310
  'SearchExtensions.handleBlur': handleBlur,
2311
+ 'SearchExtensions.renderEventListeners': renderEventListeners,
1911
2312
  'SearchExtensions.handleClick': handleClick,
2313
+ 'SearchExtensions.handleClickCurrent': handleClickCurrent,
2314
+ 'SearchExtensions.handleClickCurrentButKeepFocus': handleClickCurrentButKeepFocus,
2315
+ 'SearchExtensions.renderActions': renderActions,
1912
2316
  'SearchExtensions.handleContextMenu': handleContextMenu,
1913
2317
  'SearchExtensions.handleDisable': handleDisable,
1914
2318
  'SearchExtensions.handleEnable': handleEnable,
1915
2319
  'SearchExtensions.handleFocus': handleFocus,
1916
2320
  'SearchExtensions.handleInstall': handleInstall,
2321
+ 'SearchExtensions.handleScrollBarCaptureLos': handleScrollBarCaptureLost,
2322
+ 'SearchExtensions.handleScrollBarClick': handleScrollBarClick,
2323
+ 'SearchExtensions.handleScrollBarMove': handleScrollBarMove,
2324
+ 'SearchExtensions.handleUninstall': handleUninstall,
2325
+ 'SearchExtensions.handleWheel': handleWheel,
1917
2326
  'SearchExtensions.loadContent': loadContent,
1918
2327
  'SearchExtensions.openSuggest': openSuggest,
1919
2328
  'SearchExtensions.render': doRender,
1920
2329
  'SearchExtensions.saveState': saveState,
2330
+ 'SearchExtensions.scrollDown': scrollDown,
1921
2331
  'SearchExtensions.searchExtensions': searchExtensions,
2332
+ 'SearchExtensions.selectIndex': selectIndex,
1922
2333
  'SearchExtensions.setDeltaY': setDeltaY,
1923
2334
  'SearchExtensions.toggleSuggest': toggleSuggest
1924
2335
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-search-view",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Extension Search View Worker",
5
5
  "license": "MIT",
6
6
  "author": "Lvce Editor",