@trafica/editor 1.0.34 → 1.0.36
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 +24 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1633,47 +1633,38 @@ 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
|
-
}
|
|
1643
1636
|
function serializeBlock(node, idCounts = /* @__PURE__ */ new Map(), inCell = false) {
|
|
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
|
|
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;
|
|
1645
1638
|
switch (node.type) {
|
|
1646
1639
|
case "paragraph": {
|
|
1647
|
-
const align = (_a = node.attrs) == null ? void 0 : _a.align;
|
|
1648
|
-
const
|
|
1649
|
-
return `<p${
|
|
1640
|
+
const align = ((_a = node.attrs) == null ? void 0 : _a.align) ? ` data-align="${node.attrs.align}"` : "";
|
|
1641
|
+
const style = inCell ? ` style="margin:0;min-height:1.2em;"` : "";
|
|
1642
|
+
return `<p${align}${style}>${serializeChildren(node.children)}</p>`;
|
|
1650
1643
|
}
|
|
1651
1644
|
case "heading": {
|
|
1652
1645
|
const l = (_c = (_b = node.attrs) == null ? void 0 : _b.level) != null ? _c : 1;
|
|
1653
|
-
const align = (_d = node.attrs) == null ? void 0 : _d.align;
|
|
1646
|
+
const align = ((_d = node.attrs) == null ? void 0 : _d.align) ? ` data-align="${node.attrs.align}"` : "";
|
|
1654
1647
|
const rawText = node.children.filter((c) => "text" in c).map((c) => c.text).join("");
|
|
1655
1648
|
const base = slugify(rawText) || `heading-${l}`;
|
|
1656
1649
|
const count = (_e = idCounts.get(base)) != null ? _e : 0;
|
|
1657
1650
|
idCounts.set(base, count + 1);
|
|
1658
1651
|
const id = count === 0 ? base : `${base}-${count}`;
|
|
1659
|
-
return `<h${l} id="${id}"${
|
|
1652
|
+
return `<h${l} id="${id}"${align}>${serializeChildren(node.children)}</h${l}>`;
|
|
1660
1653
|
}
|
|
1661
1654
|
case "blockquote": {
|
|
1662
|
-
const align = (_f = node.attrs) == null ? void 0 : _f.align;
|
|
1663
|
-
return `<blockquote${
|
|
1655
|
+
const align = ((_f = node.attrs) == null ? void 0 : _f.align) ? ` data-align="${node.attrs.align}"` : "";
|
|
1656
|
+
return `<blockquote${align}>${serializeChildren(node.children)}</blockquote>`;
|
|
1664
1657
|
}
|
|
1665
1658
|
case "bullet_list":
|
|
1666
1659
|
return `<ul>${serializeChildren(node.children)}</ul>`;
|
|
1667
1660
|
case "ordered_list":
|
|
1668
1661
|
return `<ol>${serializeChildren(node.children)}</ol>`;
|
|
1669
|
-
case "list_item":
|
|
1670
|
-
|
|
1671
|
-
return `<li${alignAttrs(align)}>${serializeChildren(node.children)}</li>`;
|
|
1672
|
-
}
|
|
1662
|
+
case "list_item":
|
|
1663
|
+
return `<li>${serializeChildren(node.children)}</li>`;
|
|
1673
1664
|
case "check_list":
|
|
1674
1665
|
return `<ul class="todo-list" data-type="checklist">${serializeChildren(node.children)}</ul>`;
|
|
1675
1666
|
case "check_list_item": {
|
|
1676
|
-
const checked = !!((
|
|
1667
|
+
const checked = !!((_g = node.attrs) == null ? void 0 : _g.checked);
|
|
1677
1668
|
const dataChecked = checked ? ' data-checked="true"' : "";
|
|
1678
1669
|
const itemClass = `todo-list__item${checked ? " todo-list__item_checked" : ""}`;
|
|
1679
1670
|
const checkedAttr = checked ? ' checked="checked"' : "";
|
|
@@ -1681,16 +1672,16 @@ function serializeBlock(node, idCounts = /* @__PURE__ */ new Map(), inCell = fal
|
|
|
1681
1672
|
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>`;
|
|
1682
1673
|
}
|
|
1683
1674
|
case "code_block": {
|
|
1684
|
-
const lang = ((
|
|
1675
|
+
const lang = ((_h = node.attrs) == null ? void 0 : _h.language) ? ` class="language-${node.attrs.language}"` : "";
|
|
1685
1676
|
const raw = node.children.map((c) => isTextNode(c) ? escapeHTML(c.text) : "").join("");
|
|
1686
1677
|
return `<pre><code${lang}>${raw}</code></pre>`;
|
|
1687
1678
|
}
|
|
1688
1679
|
case "image": {
|
|
1689
|
-
const src = escapeAttr((
|
|
1690
|
-
const alt = escapeAttr((
|
|
1691
|
-
const width = ((
|
|
1692
|
-
const align = ((
|
|
1693
|
-
const caption = ((
|
|
1680
|
+
const src = escapeAttr((_j = (_i = node.attrs) == null ? void 0 : _i.src) != null ? _j : "");
|
|
1681
|
+
const alt = escapeAttr((_l = (_k = node.attrs) == null ? void 0 : _k.alt) != null ? _l : "");
|
|
1682
|
+
const width = ((_m = node.attrs) == null ? void 0 : _m.width) ? ` width="${node.attrs.width}"` : "";
|
|
1683
|
+
const align = ((_n = node.attrs) == null ? void 0 : _n.align) ? ` data-align="${node.attrs.align}"` : "";
|
|
1684
|
+
const caption = ((_o = node.attrs) == null ? void 0 : _o.caption) ? escapeHTML(node.attrs.caption) : "";
|
|
1694
1685
|
if (caption) {
|
|
1695
1686
|
return `<figure${align}><img src="${src}" alt="${alt}"${width} /><figcaption>${caption}</figcaption></figure>`;
|
|
1696
1687
|
}
|
|
@@ -1700,7 +1691,7 @@ function serializeBlock(node, idCounts = /* @__PURE__ */ new Map(), inCell = fal
|
|
|
1700
1691
|
return "<hr />";
|
|
1701
1692
|
case "table": {
|
|
1702
1693
|
const rows = node.children.map((c) => serializeBlock(c)).join("");
|
|
1703
|
-
const colWidths = (
|
|
1694
|
+
const colWidths = (_q = (_p = node.attrs) == null ? void 0 : _p.colWidths) != null ? _q : [];
|
|
1704
1695
|
let colgroup = "";
|
|
1705
1696
|
if (colWidths.length > 0) {
|
|
1706
1697
|
const total = colWidths.reduce((s, w) => s + w, 0) || colWidths.length * 120;
|
|
@@ -1713,15 +1704,15 @@ function serializeBlock(node, idCounts = /* @__PURE__ */ new Map(), inCell = fal
|
|
|
1713
1704
|
return `<tr>${cells}</tr>`;
|
|
1714
1705
|
}
|
|
1715
1706
|
case "table_cell": {
|
|
1716
|
-
if ((
|
|
1717
|
-
const cs = ((
|
|
1718
|
-
const rs = ((
|
|
1707
|
+
if ((_r = node.attrs) == null ? void 0 : _r.covered) return "";
|
|
1708
|
+
const cs = ((_s = node.attrs) == null ? void 0 : _s.colspan) > 1 ? ` colspan="${(_t = node.attrs) == null ? void 0 : _t.colspan}"` : "";
|
|
1709
|
+
const rs = ((_u = node.attrs) == null ? void 0 : _u.rowspan) > 1 ? ` rowspan="${(_v = node.attrs) == null ? void 0 : _v.rowspan}"` : "";
|
|
1719
1710
|
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>`;
|
|
1720
1711
|
}
|
|
1721
1712
|
case "table_header": {
|
|
1722
|
-
if ((
|
|
1723
|
-
const cs = ((
|
|
1724
|
-
const rs = ((
|
|
1713
|
+
if ((_w = node.attrs) == null ? void 0 : _w.covered) return "";
|
|
1714
|
+
const cs = ((_x = node.attrs) == null ? void 0 : _x.colspan) > 1 ? ` colspan="${(_y = node.attrs) == null ? void 0 : _y.colspan}"` : "";
|
|
1715
|
+
const rs = ((_z = node.attrs) == null ? void 0 : _z.rowspan) > 1 ? ` rowspan="${(_A = node.attrs) == null ? void 0 : _A.rowspan}"` : "";
|
|
1725
1716
|
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>`;
|
|
1726
1717
|
}
|
|
1727
1718
|
default:
|
|
@@ -7852,7 +7843,6 @@ function Editor({
|
|
|
7852
7843
|
}) {
|
|
7853
7844
|
const containerRef = useRef(null);
|
|
7854
7845
|
const isRenderingRef = useRef(false);
|
|
7855
|
-
const skipRestoreSelectionRef = useRef(false);
|
|
7856
7846
|
const scrollCaretIntoView = useCallback(() => {
|
|
7857
7847
|
var _a, _b;
|
|
7858
7848
|
const sel = window.getSelection();
|
|
@@ -7965,14 +7955,8 @@ function Editor({
|
|
|
7965
7955
|
useLayoutEffect(() => {
|
|
7966
7956
|
const container = containerRef.current;
|
|
7967
7957
|
if (!container || !state.selection) return;
|
|
7968
|
-
if (skipRestoreSelectionRef.current) {
|
|
7969
|
-
skipRestoreSelectionRef.current = false;
|
|
7970
|
-
return;
|
|
7971
|
-
}
|
|
7972
|
-
isRenderingRef.current = true;
|
|
7973
7958
|
restoreSelection(container, state.selection);
|
|
7974
7959
|
scrollCaretIntoView();
|
|
7975
|
-
isRenderingRef.current = false;
|
|
7976
7960
|
}, [state.selection]);
|
|
7977
7961
|
useEffect(() => {
|
|
7978
7962
|
const container = containerRef.current;
|
|
@@ -8037,7 +8021,6 @@ function Editor({
|
|
|
8037
8021
|
if (currentSelection && JSON.stringify(currentSelection.anchor) === JSON.stringify(captured.anchor) && JSON.stringify(currentSelection.focus) === JSON.stringify(captured.focus)) {
|
|
8038
8022
|
return;
|
|
8039
8023
|
}
|
|
8040
|
-
skipRestoreSelectionRef.current = true;
|
|
8041
8024
|
const tr = createTransaction();
|
|
8042
8025
|
tr.steps.push(tr_setSelection(captured));
|
|
8043
8026
|
engine.dispatch(tr);
|
|
@@ -8416,7 +8399,6 @@ function Editor({
|
|
|
8416
8399
|
if (!container) return;
|
|
8417
8400
|
const selection = captureSelection(container);
|
|
8418
8401
|
if (!selection) return;
|
|
8419
|
-
skipRestoreSelectionRef.current = true;
|
|
8420
8402
|
const tr = createTransaction();
|
|
8421
8403
|
tr.steps.push(
|
|
8422
8404
|
tr_setSelection(selection)
|