@examind/block-sdk 0.1.11 → 0.1.12

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,27 +1724,15 @@ 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
1733
  let childResult = null;
1745
1734
  for (const childNode of node.childNodes) {
1746
- const processedChildren = traverse2(childNode);
1747
- for (const child of processedChildren) {
1735
+ for (const child of traverse2(childNode)) {
1748
1736
  if (child.type !== "text") continue;
1749
1737
  const textNode = child;
1750
1738
  if (!childResult) {
@@ -1755,39 +1743,32 @@ var SpanNodeHandler = class extends NodeHandler2 {
1755
1743
  } else {
1756
1744
  childResult.text += textNode.text;
1757
1745
  childResult.format |= textNode.format || 0;
1758
- if (textNode.style) {
1759
- childResult.style = this.mergeStyles(
1760
- childResult.style,
1761
- textNode.style
1762
- );
1763
- }
1746
+ childResult.style = this.mergeStyles(
1747
+ childResult.style,
1748
+ textNode.style
1749
+ );
1764
1750
  }
1765
1751
  }
1766
1752
  }
1767
- if (childResult) {
1768
- childResult.style = this.mergeStyles(
1769
- childResult.style,
1770
- styleAttr
1771
- );
1772
- return childResult;
1773
- }
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
- };
1785
- }
1786
- return null;
1753
+ if (childResult) return childResult;
1754
+ const textContent = node.text.trim();
1755
+ return textContent ? this.createTextNode(node.text, styleAttr) : null;
1756
+ }
1757
+ createTextNode(text, style) {
1758
+ return {
1759
+ detail: 0,
1760
+ format: 0,
1761
+ mode: "normal",
1762
+ style,
1763
+ text,
1764
+ type: "text",
1765
+ version: 1
1766
+ };
1787
1767
  }
1788
1768
  mergeStyles(existingStyle, newStyle) {
1789
- if (!existingStyle) return newStyle;
1790
- if (!newStyle) return existingStyle;
1769
+ if (!existingStyle && !newStyle) return "";
1770
+ if (!existingStyle) return newStyle ?? "";
1771
+ if (!newStyle) return existingStyle ?? "";
1791
1772
  return `${existingStyle};${newStyle}`.replace(/;;/g, ";").replace(/^;/, "").replace(/;$/, "");
1792
1773
  }
1793
1774
  };
package/dist/index.mjs CHANGED
@@ -1697,27 +1697,15 @@ 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
1706
  let childResult = null;
1718
1707
  for (const childNode of node.childNodes) {
1719
- const processedChildren = traverse2(childNode);
1720
- for (const child of processedChildren) {
1708
+ for (const child of traverse2(childNode)) {
1721
1709
  if (child.type !== "text") continue;
1722
1710
  const textNode = child;
1723
1711
  if (!childResult) {
@@ -1728,39 +1716,32 @@ var SpanNodeHandler = class extends NodeHandler2 {
1728
1716
  } else {
1729
1717
  childResult.text += textNode.text;
1730
1718
  childResult.format |= textNode.format || 0;
1731
- if (textNode.style) {
1732
- childResult.style = this.mergeStyles(
1733
- childResult.style,
1734
- textNode.style
1735
- );
1736
- }
1719
+ childResult.style = this.mergeStyles(
1720
+ childResult.style,
1721
+ textNode.style
1722
+ );
1737
1723
  }
1738
1724
  }
1739
1725
  }
1740
- if (childResult) {
1741
- childResult.style = this.mergeStyles(
1742
- childResult.style,
1743
- styleAttr
1744
- );
1745
- return childResult;
1746
- }
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
- };
1758
- }
1759
- return null;
1726
+ if (childResult) return childResult;
1727
+ const textContent = node.text.trim();
1728
+ return textContent ? this.createTextNode(node.text, styleAttr) : null;
1729
+ }
1730
+ createTextNode(text, style) {
1731
+ return {
1732
+ detail: 0,
1733
+ format: 0,
1734
+ mode: "normal",
1735
+ style,
1736
+ text,
1737
+ type: "text",
1738
+ version: 1
1739
+ };
1760
1740
  }
1761
1741
  mergeStyles(existingStyle, newStyle) {
1762
- if (!existingStyle) return newStyle;
1763
- if (!newStyle) return existingStyle;
1742
+ if (!existingStyle && !newStyle) return "";
1743
+ if (!existingStyle) return newStyle ?? "";
1744
+ if (!newStyle) return existingStyle ?? "";
1764
1745
  return `${existingStyle};${newStyle}`.replace(/;;/g, ";").replace(/^;/, "").replace(/;$/, "");
1765
1746
  }
1766
1747
  };
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.12",
4
4
  "@comment version": [
5
5
  "Don't specify package version here. It will be injected by publish workflow."
6
6
  ],