@lvce-editor/completion-worker 1.3.0 → 1.4.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.
@@ -1506,7 +1506,6 @@ const getFinalDeltaY = (height, itemHeight, itemsLength) => {
1506
1506
  };
1507
1507
 
1508
1508
  const getWordAtOffset = async editorUid => {
1509
- // @ts-ignore
1510
1509
  return invoke$1('Editor.getWordAtOffset2', editorUid);
1511
1510
  };
1512
1511
 
@@ -1552,6 +1551,7 @@ const loadContent = async state => {
1552
1551
 
1553
1552
  const SetBounds = 'Viewlet.setBounds';
1554
1553
  const SetDom2 = 'Viewlet.setDom2';
1554
+ const SetUid = 'Viewlet.setUid';
1555
1555
  const SetEventListeners = 'Viewlet.registerEventListeners';
1556
1556
 
1557
1557
  const renderBounds = (oldState, newState) => {
@@ -1585,34 +1585,18 @@ const renderEventListeners = state => {
1585
1585
  return [SetEventListeners, uid, eventListeners];
1586
1586
  };
1587
1587
 
1588
- const emptyObject = {};
1589
- const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1590
- const i18nString = (key, placeholders = emptyObject) => {
1591
- if (placeholders === emptyObject) {
1592
- return key;
1593
- }
1594
- const replacer = (match, rest) => {
1595
- return placeholders[rest];
1596
- };
1597
- return key.replaceAll(RE_PLACEHOLDER, replacer);
1598
- };
1599
-
1600
- const NoResults = 'No Results';
1601
-
1602
- const noResults = () => {
1603
- return i18nString(NoResults);
1604
- };
1605
-
1606
- const None = 'none';
1607
- const Option = 'option';
1608
-
1609
1588
  const ColoredMaskIcon = 'ColoredMaskIcon';
1589
+ const EditorCompletion = 'EditorCompletion';
1610
1590
  const EditorCompletionItem = 'EditorCompletionItem';
1611
1591
  const EditorCompletionItemDeprecated = 'EditorCompletionItemDeprecated';
1612
1592
  const EditorCompletionItemFocused = 'EditorCompletionItemFocused';
1613
1593
  const EditorCompletionItemHighlight = 'EditorCompletionItemHighlight';
1614
1594
  const FileIcon = 'FileIcon';
1615
1595
  const Label = 'Label';
1596
+ const Viewlet = 'Viewlet';
1597
+
1598
+ const None = 'none';
1599
+ const Option = 'option';
1616
1600
 
1617
1601
  const Div = 4;
1618
1602
  const Span = 8;
@@ -1639,6 +1623,9 @@ const getIconDom = (fileIcon, symbolName) => {
1639
1623
  };
1640
1624
  };
1641
1625
 
1626
+ const mergeClassNames = (...classNames) => {
1627
+ return classNames.filter(Boolean).join(' ');
1628
+ };
1642
1629
  const Text = 12;
1643
1630
  const text = data => {
1644
1631
  return {
@@ -1717,12 +1704,34 @@ const getCompletionItemVirtualDom = visibleItem => {
1717
1704
  }, getIconDom(fileIcon, symbolName), ...getHighlightedLabelDom(label, highlights)];
1718
1705
  };
1719
1706
 
1707
+ const emptyObject = {};
1708
+ const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1709
+ const i18nString = (key, placeholders = emptyObject) => {
1710
+ if (placeholders === emptyObject) {
1711
+ return key;
1712
+ }
1713
+ const replacer = (match, rest) => {
1714
+ return placeholders[rest];
1715
+ };
1716
+ return key.replaceAll(RE_PLACEHOLDER, replacer);
1717
+ };
1718
+
1719
+ const NoResults = 'No Results';
1720
+
1721
+ const noResults = () => {
1722
+ return i18nString(NoResults);
1723
+ };
1724
+
1725
+ const getNoResultsVirtualDom = () => {
1726
+ return [{
1727
+ type: Div,
1728
+ childCount: 1
1729
+ }, text(noResults())];
1730
+ };
1731
+
1720
1732
  const getCompletionItemsVirtualDom = visibleItems => {
1721
1733
  if (visibleItems.length === 0) {
1722
- return [{
1723
- type: Div,
1724
- childCount: 1
1725
- }, text(noResults())];
1734
+ return getNoResultsVirtualDom();
1726
1735
  }
1727
1736
  const root = {
1728
1737
  type: Div,
@@ -1732,6 +1741,24 @@ const getCompletionItemsVirtualDom = visibleItems => {
1732
1741
  return dom;
1733
1742
  };
1734
1743
 
1744
+ const getCompletionVirtualDom = visibleItems => {
1745
+ return [{
1746
+ type: Div,
1747
+ className: mergeClassNames(Viewlet, EditorCompletion),
1748
+ id: 'Completions',
1749
+ childCount: 1
1750
+ }, {
1751
+ type: Div,
1752
+ className: 'ListItems',
1753
+ role: 'listbox',
1754
+ ariaLabel: 'Suggest',
1755
+ childCount: 1
1756
+ }, ...getCompletionItemsVirtualDom(visibleItems)
1757
+
1758
+ // TODO render scrollbar
1759
+ ];
1760
+ };
1761
+
1735
1762
  const Property = 1;
1736
1763
  const Value = 2;
1737
1764
  const Function = 3;
@@ -1819,10 +1846,18 @@ const renderItems = (oldState, newState) => {
1819
1846
  uid
1820
1847
  } = newState;
1821
1848
  const visibleItems = getVisibleItems(newState.items, newState.itemHeight, newState.leadingWord, newState.minLineY, newState.maxLineY, newState.focusedIndex);
1822
- const dom = getCompletionItemsVirtualDom(visibleItems);
1849
+ const dom = getCompletionVirtualDom(visibleItems);
1823
1850
  return [SetDom2, uid, dom];
1824
1851
  };
1825
1852
 
1853
+ const renderUid = (oldState, newState) => {
1854
+ const {
1855
+ uid,
1856
+ editorUid
1857
+ } = newState;
1858
+ return [SetUid, uid, editorUid];
1859
+ };
1860
+
1826
1861
  const getRenderer = diffType => {
1827
1862
  switch (diffType) {
1828
1863
  case RenderContent:
@@ -1831,6 +1866,8 @@ const getRenderer = diffType => {
1831
1866
  return renderBounds;
1832
1867
  case RenderEventListeners:
1833
1868
  return renderEventListeners;
1869
+ case RenderUid:
1870
+ return renderUid;
1834
1871
  case RenderItems:
1835
1872
  return renderItems;
1836
1873
  default:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/completion-worker",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",