@trafica/editor 1.0.33 → 1.0.35
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 +33 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1635,38 +1635,47 @@ var htmlSerializer = {
|
|
|
1635
1635
|
return parseHTMLBody(parsed.body);
|
|
1636
1636
|
}
|
|
1637
1637
|
};
|
|
1638
|
+
function alignAttrs(align, extraStyles = "") {
|
|
1639
|
+
const dataAlign = align ? ` data-align="${align}"` : "";
|
|
1640
|
+
const textAlign = align && align !== "left" ? `text-align:${align};` : "";
|
|
1641
|
+
const combined = textAlign + extraStyles;
|
|
1642
|
+
const style = combined ? ` style="${combined}"` : "";
|
|
1643
|
+
return dataAlign + style;
|
|
1644
|
+
}
|
|
1638
1645
|
function serializeBlock(node, idCounts = /* @__PURE__ */ new Map(), inCell = false) {
|
|
1639
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A;
|
|
1646
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
|
|
1640
1647
|
switch (node.type) {
|
|
1641
1648
|
case "paragraph": {
|
|
1642
|
-
const align = (
|
|
1643
|
-
const
|
|
1644
|
-
return `<p${align}
|
|
1649
|
+
const align = (_a = node.attrs) == null ? void 0 : _a.align;
|
|
1650
|
+
const extra = inCell ? "margin:0;min-height:1.2em;" : "";
|
|
1651
|
+
return `<p${alignAttrs(align, extra)}>${serializeChildren(node.children)}</p>`;
|
|
1645
1652
|
}
|
|
1646
1653
|
case "heading": {
|
|
1647
1654
|
const l = (_c = (_b = node.attrs) == null ? void 0 : _b.level) != null ? _c : 1;
|
|
1648
|
-
const align = (
|
|
1655
|
+
const align = (_d = node.attrs) == null ? void 0 : _d.align;
|
|
1649
1656
|
const rawText = node.children.filter((c) => "text" in c).map((c) => c.text).join("");
|
|
1650
1657
|
const base = slugify(rawText) || `heading-${l}`;
|
|
1651
1658
|
const count = (_e = idCounts.get(base)) != null ? _e : 0;
|
|
1652
1659
|
idCounts.set(base, count + 1);
|
|
1653
1660
|
const id = count === 0 ? base : `${base}-${count}`;
|
|
1654
|
-
return `<h${l} id="${id}"${align}>${serializeChildren(node.children)}</h${l}>`;
|
|
1661
|
+
return `<h${l} id="${id}"${alignAttrs(align)}>${serializeChildren(node.children)}</h${l}>`;
|
|
1655
1662
|
}
|
|
1656
1663
|
case "blockquote": {
|
|
1657
|
-
const align = (
|
|
1658
|
-
return `<blockquote${align}>${serializeChildren(node.children)}</blockquote>`;
|
|
1664
|
+
const align = (_f = node.attrs) == null ? void 0 : _f.align;
|
|
1665
|
+
return `<blockquote${alignAttrs(align)}>${serializeChildren(node.children)}</blockquote>`;
|
|
1659
1666
|
}
|
|
1660
1667
|
case "bullet_list":
|
|
1661
1668
|
return `<ul>${serializeChildren(node.children)}</ul>`;
|
|
1662
1669
|
case "ordered_list":
|
|
1663
1670
|
return `<ol>${serializeChildren(node.children)}</ol>`;
|
|
1664
|
-
case "list_item":
|
|
1665
|
-
|
|
1671
|
+
case "list_item": {
|
|
1672
|
+
const align = (_g = node.attrs) == null ? void 0 : _g.align;
|
|
1673
|
+
return `<li${alignAttrs(align)}>${serializeChildren(node.children)}</li>`;
|
|
1674
|
+
}
|
|
1666
1675
|
case "check_list":
|
|
1667
1676
|
return `<ul class="todo-list" data-type="checklist">${serializeChildren(node.children)}</ul>`;
|
|
1668
1677
|
case "check_list_item": {
|
|
1669
|
-
const checked = !!((
|
|
1678
|
+
const checked = !!((_h = node.attrs) == null ? void 0 : _h.checked);
|
|
1670
1679
|
const dataChecked = checked ? ' data-checked="true"' : "";
|
|
1671
1680
|
const itemClass = `todo-list__item${checked ? " todo-list__item_checked" : ""}`;
|
|
1672
1681
|
const checkedAttr = checked ? ' checked="checked"' : "";
|
|
@@ -1674,16 +1683,16 @@ function serializeBlock(node, idCounts = /* @__PURE__ */ new Map(), inCell = fal
|
|
|
1674
1683
|
return `<li class="${itemClass}"${dataChecked}><label class="todo-list__label"><input type="checkbox" disabled="disabled"${checkedAttr}><span class="todo-list__label__description">${innerContent}</span></label></li>`;
|
|
1675
1684
|
}
|
|
1676
1685
|
case "code_block": {
|
|
1677
|
-
const lang = ((
|
|
1686
|
+
const lang = ((_i = node.attrs) == null ? void 0 : _i.language) ? ` class="language-${node.attrs.language}"` : "";
|
|
1678
1687
|
const raw = node.children.map((c) => isTextNode(c) ? escapeHTML(c.text) : "").join("");
|
|
1679
1688
|
return `<pre><code${lang}>${raw}</code></pre>`;
|
|
1680
1689
|
}
|
|
1681
1690
|
case "image": {
|
|
1682
|
-
const src = escapeAttr((
|
|
1683
|
-
const alt = escapeAttr((
|
|
1684
|
-
const width = ((
|
|
1685
|
-
const align = ((
|
|
1686
|
-
const caption = ((
|
|
1691
|
+
const src = escapeAttr((_k = (_j = node.attrs) == null ? void 0 : _j.src) != null ? _k : "");
|
|
1692
|
+
const alt = escapeAttr((_m = (_l = node.attrs) == null ? void 0 : _l.alt) != null ? _m : "");
|
|
1693
|
+
const width = ((_n = node.attrs) == null ? void 0 : _n.width) ? ` width="${node.attrs.width}"` : "";
|
|
1694
|
+
const align = ((_o = node.attrs) == null ? void 0 : _o.align) ? ` data-align="${node.attrs.align}"` : "";
|
|
1695
|
+
const caption = ((_p = node.attrs) == null ? void 0 : _p.caption) ? escapeHTML(node.attrs.caption) : "";
|
|
1687
1696
|
if (caption) {
|
|
1688
1697
|
return `<figure${align}><img src="${src}" alt="${alt}"${width} /><figcaption>${caption}</figcaption></figure>`;
|
|
1689
1698
|
}
|
|
@@ -1693,7 +1702,7 @@ function serializeBlock(node, idCounts = /* @__PURE__ */ new Map(), inCell = fal
|
|
|
1693
1702
|
return "<hr />";
|
|
1694
1703
|
case "table": {
|
|
1695
1704
|
const rows = node.children.map((c) => serializeBlock(c)).join("");
|
|
1696
|
-
const colWidths = (
|
|
1705
|
+
const colWidths = (_r = (_q = node.attrs) == null ? void 0 : _q.colWidths) != null ? _r : [];
|
|
1697
1706
|
let colgroup = "";
|
|
1698
1707
|
if (colWidths.length > 0) {
|
|
1699
1708
|
const total = colWidths.reduce((s, w) => s + w, 0) || colWidths.length * 120;
|
|
@@ -1706,15 +1715,15 @@ function serializeBlock(node, idCounts = /* @__PURE__ */ new Map(), inCell = fal
|
|
|
1706
1715
|
return `<tr>${cells}</tr>`;
|
|
1707
1716
|
}
|
|
1708
1717
|
case "table_cell": {
|
|
1709
|
-
if ((
|
|
1710
|
-
const cs = ((
|
|
1711
|
-
const rs = ((
|
|
1718
|
+
if ((_s = node.attrs) == null ? void 0 : _s.covered) return "";
|
|
1719
|
+
const cs = ((_t = node.attrs) == null ? void 0 : _t.colspan) > 1 ? ` colspan="${(_u = node.attrs) == null ? void 0 : _u.colspan}"` : "";
|
|
1720
|
+
const rs = ((_v = node.attrs) == null ? void 0 : _v.rowspan) > 1 ? ` rowspan="${(_w = node.attrs) == null ? void 0 : _w.rowspan}"` : "";
|
|
1712
1721
|
return `<td${cs}${rs} style="border:1px solid #d1d5db;padding:0.5em 0.75em;vertical-align:top;min-width:40px;word-break:break-word;">${node.children.map((c) => serializeBlock(c, /* @__PURE__ */ new Map(), true)).join("")}</td>`;
|
|
1713
1722
|
}
|
|
1714
1723
|
case "table_header": {
|
|
1715
|
-
if ((
|
|
1716
|
-
const cs = ((
|
|
1717
|
-
const rs = ((
|
|
1724
|
+
if ((_x = node.attrs) == null ? void 0 : _x.covered) return "";
|
|
1725
|
+
const cs = ((_y = node.attrs) == null ? void 0 : _y.colspan) > 1 ? ` colspan="${(_z = node.attrs) == null ? void 0 : _z.colspan}"` : "";
|
|
1726
|
+
const rs = ((_A = node.attrs) == null ? void 0 : _A.rowspan) > 1 ? ` rowspan="${(_B = node.attrs) == null ? void 0 : _B.rowspan}"` : "";
|
|
1718
1727
|
return `<th${cs}${rs} style="border:1px solid #d1d5db;padding:0.5em 0.75em;vertical-align:top;min-width:40px;word-break:break-word;background:#f9fafb;font-weight:600;text-align:left;">${node.children.map((c) => serializeBlock(c, /* @__PURE__ */ new Map(), true)).join("")}</th>`;
|
|
1719
1728
|
}
|
|
1720
1729
|
default:
|