@examind/block-sdk 0.1.11 → 0.1.13

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.
package/dist/index.js CHANGED
@@ -1724,70 +1724,61 @@ var import_node_html_parser20 = require("node-html-parser");
1724
1724
  var TextNode = import_node_html_parser20.parse.TextNode;
1725
1725
  var SpanNodeHandler = class extends NodeHandler2 {
1726
1726
  processNode(node) {
1727
- if (!(node instanceof import_node_html_parser20.HTMLElement)) return null;
1728
- if (node.tagName !== "SPAN") return null;
1729
- if (!node.hasAttribute("style")) return null;
1730
- const styleAttr = node.getAttribute("style");
1731
- if (!styleAttr) return null;
1727
+ if (!(node instanceof import_node_html_parser20.HTMLElement) || node.tagName !== "SPAN")
1728
+ return null;
1729
+ const styleAttr = node.getAttribute("style") || "";
1732
1730
  if (node.childNodes.length === 1 && node.childNodes[0] instanceof TextNode) {
1733
- const textContent2 = node.text;
1734
- return {
1735
- detail: 0,
1736
- format: 0,
1737
- mode: "normal",
1738
- style: styleAttr,
1739
- text: textContent2,
1740
- type: "text",
1741
- version: 1
1742
- };
1731
+ return this.createTextNode(node.text, styleAttr);
1743
1732
  }
1744
- let childResult = null;
1733
+ const results = [];
1734
+ const textNodes = [];
1745
1735
  for (const childNode of node.childNodes) {
1746
- const processedChildren = traverse2(childNode);
1747
- for (const child of processedChildren) {
1748
- if (child.type !== "text") continue;
1749
- const textNode = child;
1750
- if (!childResult) {
1751
- childResult = {
1752
- ...textNode,
1753
- style: this.mergeStyles(textNode.style, styleAttr)
1754
- };
1736
+ for (const child of traverse2(childNode)) {
1737
+ if (child.type === "text") {
1738
+ const textNode = child;
1739
+ textNodes.push(textNode);
1755
1740
  } else {
1756
- childResult.text += textNode.text;
1757
- childResult.format |= textNode.format || 0;
1758
- if (textNode.style) {
1759
- childResult.style = this.mergeStyles(
1760
- childResult.style,
1761
- textNode.style
1762
- );
1763
- }
1741
+ results.push(child);
1764
1742
  }
1765
1743
  }
1766
1744
  }
1767
- if (childResult) {
1768
- childResult.style = this.mergeStyles(
1769
- childResult.style,
1745
+ if (textNodes.length > 0) {
1746
+ const mergedTextNode = this.mergeTextNodes(
1747
+ textNodes,
1770
1748
  styleAttr
1771
1749
  );
1772
- return childResult;
1750
+ results.push(mergedTextNode);
1751
+ } else if (node.text.trim()) {
1752
+ results.push(this.createTextNode(node.text, styleAttr));
1773
1753
  }
1774
- const textContent = node.text;
1775
- if (textContent.trim() !== "") {
1776
- return {
1777
- detail: 0,
1778
- format: 0,
1779
- mode: "normal",
1780
- style: styleAttr,
1781
- text: textContent,
1782
- type: "text",
1783
- version: 1
1784
- };
1754
+ return results;
1755
+ }
1756
+ mergeTextNodes(textNodes, spanStyle) {
1757
+ const result = { ...textNodes[0] };
1758
+ result.style = this.mergeStyles(result.style, spanStyle);
1759
+ for (let i = 1; i < textNodes.length; i++) {
1760
+ const node = textNodes[i];
1761
+ result.text += node.text;
1762
+ result.format |= node.format || 0;
1763
+ result.style = this.mergeStyles(result.style, node.style);
1785
1764
  }
1786
- return null;
1765
+ return result;
1766
+ }
1767
+ createTextNode(text, style) {
1768
+ return {
1769
+ detail: 0,
1770
+ format: 0,
1771
+ mode: "normal",
1772
+ style,
1773
+ text,
1774
+ type: "text",
1775
+ version: 1
1776
+ };
1787
1777
  }
1788
1778
  mergeStyles(existingStyle, newStyle) {
1789
- if (!existingStyle) return newStyle;
1790
- if (!newStyle) return existingStyle;
1779
+ if (!existingStyle && !newStyle) return "";
1780
+ if (!existingStyle) return newStyle ?? "";
1781
+ if (!newStyle) return existingStyle ?? "";
1791
1782
  return `${existingStyle};${newStyle}`.replace(/;;/g, ";").replace(/^;/, "").replace(/;$/, "");
1792
1783
  }
1793
1784
  };
package/dist/index.mjs CHANGED
@@ -1697,70 +1697,61 @@ import { HTMLElement as HTMLElement20, parse } from "node-html-parser";
1697
1697
  var TextNode = parse.TextNode;
1698
1698
  var SpanNodeHandler = class extends NodeHandler2 {
1699
1699
  processNode(node) {
1700
- if (!(node instanceof HTMLElement20)) return null;
1701
- if (node.tagName !== "SPAN") return null;
1702
- if (!node.hasAttribute("style")) return null;
1703
- const styleAttr = node.getAttribute("style");
1704
- if (!styleAttr) return null;
1700
+ if (!(node instanceof HTMLElement20) || node.tagName !== "SPAN")
1701
+ return null;
1702
+ const styleAttr = node.getAttribute("style") || "";
1705
1703
  if (node.childNodes.length === 1 && node.childNodes[0] instanceof TextNode) {
1706
- const textContent2 = node.text;
1707
- return {
1708
- detail: 0,
1709
- format: 0,
1710
- mode: "normal",
1711
- style: styleAttr,
1712
- text: textContent2,
1713
- type: "text",
1714
- version: 1
1715
- };
1704
+ return this.createTextNode(node.text, styleAttr);
1716
1705
  }
1717
- let childResult = null;
1706
+ const results = [];
1707
+ const textNodes = [];
1718
1708
  for (const childNode of node.childNodes) {
1719
- const processedChildren = traverse2(childNode);
1720
- for (const child of processedChildren) {
1721
- if (child.type !== "text") continue;
1722
- const textNode = child;
1723
- if (!childResult) {
1724
- childResult = {
1725
- ...textNode,
1726
- style: this.mergeStyles(textNode.style, styleAttr)
1727
- };
1709
+ for (const child of traverse2(childNode)) {
1710
+ if (child.type === "text") {
1711
+ const textNode = child;
1712
+ textNodes.push(textNode);
1728
1713
  } else {
1729
- childResult.text += textNode.text;
1730
- childResult.format |= textNode.format || 0;
1731
- if (textNode.style) {
1732
- childResult.style = this.mergeStyles(
1733
- childResult.style,
1734
- textNode.style
1735
- );
1736
- }
1714
+ results.push(child);
1737
1715
  }
1738
1716
  }
1739
1717
  }
1740
- if (childResult) {
1741
- childResult.style = this.mergeStyles(
1742
- childResult.style,
1718
+ if (textNodes.length > 0) {
1719
+ const mergedTextNode = this.mergeTextNodes(
1720
+ textNodes,
1743
1721
  styleAttr
1744
1722
  );
1745
- return childResult;
1723
+ results.push(mergedTextNode);
1724
+ } else if (node.text.trim()) {
1725
+ results.push(this.createTextNode(node.text, styleAttr));
1746
1726
  }
1747
- const textContent = node.text;
1748
- if (textContent.trim() !== "") {
1749
- return {
1750
- detail: 0,
1751
- format: 0,
1752
- mode: "normal",
1753
- style: styleAttr,
1754
- text: textContent,
1755
- type: "text",
1756
- version: 1
1757
- };
1727
+ return results;
1728
+ }
1729
+ mergeTextNodes(textNodes, spanStyle) {
1730
+ const result = { ...textNodes[0] };
1731
+ result.style = this.mergeStyles(result.style, spanStyle);
1732
+ for (let i = 1; i < textNodes.length; i++) {
1733
+ const node = textNodes[i];
1734
+ result.text += node.text;
1735
+ result.format |= node.format || 0;
1736
+ result.style = this.mergeStyles(result.style, node.style);
1758
1737
  }
1759
- return null;
1738
+ return result;
1739
+ }
1740
+ createTextNode(text, style) {
1741
+ return {
1742
+ detail: 0,
1743
+ format: 0,
1744
+ mode: "normal",
1745
+ style,
1746
+ text,
1747
+ type: "text",
1748
+ version: 1
1749
+ };
1760
1750
  }
1761
1751
  mergeStyles(existingStyle, newStyle) {
1762
- if (!existingStyle) return newStyle;
1763
- if (!newStyle) return existingStyle;
1752
+ if (!existingStyle && !newStyle) return "";
1753
+ if (!existingStyle) return newStyle ?? "";
1754
+ if (!newStyle) return existingStyle ?? "";
1764
1755
  return `${existingStyle};${newStyle}`.replace(/;;/g, ";").replace(/^;/, "").replace(/;$/, "");
1765
1756
  }
1766
1757
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@examind/block-sdk",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "@comment version": [
5
5
  "Don't specify package version here. It will be injected by publish workflow."
6
6
  ],