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