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