@lvce-editor/hover-worker 2.17.0 → 2.18.1

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.
@@ -1537,6 +1537,7 @@ const {
1537
1537
  const create = (uid, x, y, width, height, editorUid, editorLanguageId) => {
1538
1538
  const state = {
1539
1539
  documentation: '',
1540
+ documentationVirtualDom: [],
1540
1541
  editorLanguageId,
1541
1542
  editorUid,
1542
1543
  fallbackDisplayStringLanguageId: 'typescript',
@@ -1577,7 +1578,7 @@ const isEqual$2 = (oldState, newState) => {
1577
1578
  };
1578
1579
 
1579
1580
  const isEqual$1 = (oldState, newState) => {
1580
- return oldState.leadingWord === newState.leadingWord && oldState.x === newState.x && oldState.y === newState.y;
1581
+ return oldState.documentation === newState.documentation && oldState.leadingWord === newState.leadingWord && oldState.x === newState.x && oldState.y === newState.y;
1581
1582
  };
1582
1583
 
1583
1584
  const isEqual = (oldState, newState) => {
@@ -1897,9 +1898,11 @@ const loadContent = async state => {
1897
1898
  if (!documentation && lineInfos.length === 0 && matchingDiagnostics.length === 0) {
1898
1899
  return close(state);
1899
1900
  }
1901
+ const documentationVirtualDom = documentation ? await invoke('Markdown.getVirtualDomFromMarkdown', documentation) : [];
1900
1902
  return {
1901
1903
  ...state,
1902
1904
  documentation,
1905
+ documentationVirtualDom,
1903
1906
  leadingWord: wordAtOffset,
1904
1907
  lineInfos,
1905
1908
  matchingDiagnostics,
@@ -2007,6 +2010,7 @@ const getLineInfosVirtualDom = lineInfos => {
2007
2010
 
2008
2011
  const hoverClassName = mergeClassNames(Viewlet, EditorHover);
2009
2012
  const problemClassName = mergeClassNames(HoverDisplayString, HoverProblem);
2013
+ const hoverDocumentationClassName = mergeClassNames(HoverDocumentation, 'Markdown');
2010
2014
  const hoverProblemMessage = {
2011
2015
  childCount: 1,
2012
2016
  className: HoverProblemMessage,
@@ -2017,30 +2021,36 @@ const hoverProblemDetail = {
2017
2021
  className: HoverProblemDetail,
2018
2022
  type: Span
2019
2023
  };
2020
- const hoverDocumentation = {
2021
- childCount: 1,
2022
- className: HoverDocumentation,
2023
- type: Div
2024
- };
2025
2024
  const sash = {
2026
2025
  childCount: 0,
2027
2026
  className: mergeClassNames('Sash', 'SashVertical', 'SashResize'),
2028
2027
  onPointerDown: HandleSashPointerDown,
2029
2028
  type: Div
2030
2029
  };
2031
- const getChildCount = (lineInfos, documentation, diagnostics) => {
2030
+ const getChildCount = (lineInfos, documentationVirtualDom, diagnostics) => {
2032
2031
  const diagnosticsCount = diagnostics && diagnostics.length > 0 ? 1 : 0;
2033
2032
  const lineInfosCount = lineInfos.length > 0 ? 1 : 0;
2034
- const documentationCount = documentation ? 1 : 0;
2033
+ const documentationCount = documentationVirtualDom.length > 0 ? 1 : 0;
2035
2034
  return lineInfosCount + documentationCount + diagnosticsCount;
2036
2035
  };
2037
- const getHoverVirtualDom = (lineInfos, documentation, diagnostics) => {
2038
- if (lineInfos.length === 0 && !documentation && diagnostics.length === 0) {
2036
+ const getDocumentationChildCount = documentationVirtualDom => {
2037
+ let stack = [];
2038
+ for (let i = documentationVirtualDom.length - 1; i >= 0; i--) {
2039
+ const node = documentationVirtualDom[i];
2040
+ if (node.childCount > 0) {
2041
+ stack = stack.slice(node.childCount);
2042
+ }
2043
+ stack.unshift(node);
2044
+ }
2045
+ return stack.length;
2046
+ };
2047
+ const getHoverVirtualDom = (lineInfos, documentationVirtualDom, diagnostics) => {
2048
+ if (lineInfos.length === 0 && documentationVirtualDom.length === 0 && diagnostics.length === 0) {
2039
2049
  return [];
2040
2050
  }
2041
2051
  const dom = [];
2042
2052
  dom.push({
2043
- childCount: getChildCount(lineInfos, documentation, diagnostics) + 1,
2053
+ childCount: getChildCount(lineInfos, documentationVirtualDom, diagnostics) + 1,
2044
2054
  className: hoverClassName,
2045
2055
  type: Div
2046
2056
  });
@@ -2062,8 +2072,12 @@ const getHoverVirtualDom = (lineInfos, documentation, diagnostics) => {
2062
2072
  type: Div
2063
2073
  }, ...lineInfosDom);
2064
2074
  }
2065
- if (documentation) {
2066
- dom.push(hoverDocumentation, text(documentation));
2075
+ if (documentationVirtualDom.length > 0) {
2076
+ dom.push({
2077
+ childCount: getDocumentationChildCount(documentationVirtualDom),
2078
+ className: hoverDocumentationClassName,
2079
+ type: Div
2080
+ }, ...documentationVirtualDom);
2067
2081
  }
2068
2082
  dom.push(sash);
2069
2083
  return dom;
@@ -2071,12 +2085,12 @@ const getHoverVirtualDom = (lineInfos, documentation, diagnostics) => {
2071
2085
 
2072
2086
  const renderItems = (oldState, newState) => {
2073
2087
  const {
2074
- documentation,
2088
+ documentationVirtualDom,
2075
2089
  lineInfos,
2076
2090
  matchingDiagnostics,
2077
2091
  uid
2078
2092
  } = newState;
2079
- const dom = getHoverVirtualDom(lineInfos, documentation, matchingDiagnostics);
2093
+ const dom = getHoverVirtualDom(lineInfos, documentationVirtualDom, matchingDiagnostics);
2080
2094
  return [/* method */'Viewlet.setDom2', uid, dom];
2081
2095
  };
2082
2096
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/hover-worker",
3
- "version": "2.17.0",
3
+ "version": "2.18.1",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",