@trafica/editor 1.0.39 → 1.0.41

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.mjs CHANGED
@@ -1637,23 +1637,27 @@ function serializeBlock(node, idCounts = /* @__PURE__ */ new Map(), inCell = fal
1637
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;
1638
1638
  switch (node.type) {
1639
1639
  case "paragraph": {
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>`;
1640
+ const alignVal = (_a = node.attrs) == null ? void 0 : _a.align;
1641
+ const alignAttrs = alignVal ? ` data-align="${alignVal}" style="text-align:${alignVal};"` : "";
1642
+ const cellStyle = inCell ? ` style="margin:0;min-height:1.2em;${alignVal ? `text-align:${alignVal};` : ""}"` : "";
1643
+ const attrs = inCell ? alignVal ? ` data-align="${alignVal}"${cellStyle}` : cellStyle : alignAttrs;
1644
+ return `<p${attrs}>${serializeChildren(node.children)}</p>`;
1643
1645
  }
1644
1646
  case "heading": {
1645
1647
  const l = (_c = (_b = node.attrs) == null ? void 0 : _b.level) != null ? _c : 1;
1646
- const align = ((_d = node.attrs) == null ? void 0 : _d.align) ? ` data-align="${node.attrs.align}"` : "";
1648
+ const alignVal = (_d = node.attrs) == null ? void 0 : _d.align;
1649
+ const alignAttrs = alignVal ? ` data-align="${alignVal}" style="text-align:${alignVal};"` : "";
1647
1650
  const rawText = node.children.filter((c) => "text" in c).map((c) => c.text).join("");
1648
1651
  const base = slugify(rawText) || `heading-${l}`;
1649
1652
  const count = (_e = idCounts.get(base)) != null ? _e : 0;
1650
1653
  idCounts.set(base, count + 1);
1651
1654
  const id = count === 0 ? base : `${base}-${count}`;
1652
- return `<h${l} id="${id}"${align}>${serializeChildren(node.children)}</h${l}>`;
1655
+ return `<h${l} id="${id}"${alignAttrs}>${serializeChildren(node.children)}</h${l}>`;
1653
1656
  }
1654
1657
  case "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>`;
1658
+ const alignVal = (_f = node.attrs) == null ? void 0 : _f.align;
1659
+ const alignAttrs = alignVal ? ` data-align="${alignVal}" style="text-align:${alignVal};"` : "";
1660
+ return `<blockquote${alignAttrs}>${serializeChildren(node.children)}</blockquote>`;
1657
1661
  }
1658
1662
  case "bullet_list":
1659
1663
  return `<ul>${serializeChildren(node.children)}</ul>`;
@@ -1769,6 +1773,14 @@ function escapeHTML(str) {
1769
1773
  function escapeAttr(str) {
1770
1774
  return str.replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1771
1775
  }
1776
+ var VALID_ALIGNS = /* @__PURE__ */ new Set(["left", "center", "right", "justify"]);
1777
+ function getAlign(el) {
1778
+ const da = el.getAttribute("data-align");
1779
+ if (da && VALID_ALIGNS.has(da)) return da;
1780
+ const ta = el.style.textAlign;
1781
+ if (ta && VALID_ALIGNS.has(ta)) return ta;
1782
+ return null;
1783
+ }
1772
1784
  function parseHTMLBody(body) {
1773
1785
  const children = [];
1774
1786
  for (const child of Array.from(body.childNodes)) {
@@ -1789,35 +1801,35 @@ function parseHTMLNode(node) {
1789
1801
  switch (tag) {
1790
1802
  case "p":
1791
1803
  case "div": {
1792
- const align = el.getAttribute("data-align");
1804
+ const align = getAlign(el);
1793
1805
  return { type: "paragraph", attrs: align ? { align } : {}, children: parseInlineChildren(el) };
1794
1806
  }
1795
1807
  case "h1": {
1796
- const align = el.getAttribute("data-align");
1808
+ const align = getAlign(el);
1797
1809
  return { type: "heading", attrs: { level: 1, ...align ? { align } : {} }, children: parseInlineChildren(el) };
1798
1810
  }
1799
1811
  case "h2": {
1800
- const align = el.getAttribute("data-align");
1812
+ const align = getAlign(el);
1801
1813
  return { type: "heading", attrs: { level: 2, ...align ? { align } : {} }, children: parseInlineChildren(el) };
1802
1814
  }
1803
1815
  case "h3": {
1804
- const align = el.getAttribute("data-align");
1816
+ const align = getAlign(el);
1805
1817
  return { type: "heading", attrs: { level: 3, ...align ? { align } : {} }, children: parseInlineChildren(el) };
1806
1818
  }
1807
1819
  case "h4": {
1808
- const align = el.getAttribute("data-align");
1820
+ const align = getAlign(el);
1809
1821
  return { type: "heading", attrs: { level: 4, ...align ? { align } : {} }, children: parseInlineChildren(el) };
1810
1822
  }
1811
1823
  case "h5": {
1812
- const align = el.getAttribute("data-align");
1824
+ const align = getAlign(el);
1813
1825
  return { type: "heading", attrs: { level: 5, ...align ? { align } : {} }, children: parseInlineChildren(el) };
1814
1826
  }
1815
1827
  case "h6": {
1816
- const align = el.getAttribute("data-align");
1828
+ const align = getAlign(el);
1817
1829
  return { type: "heading", attrs: { level: 6, ...align ? { align } : {} }, children: parseInlineChildren(el) };
1818
1830
  }
1819
1831
  case "blockquote": {
1820
- const align = el.getAttribute("data-align");
1832
+ const align = getAlign(el);
1821
1833
  return { type: "blockquote", attrs: align ? { align } : {}, children: parseInlineChildren(el) };
1822
1834
  }
1823
1835
  case "ul": {
@@ -2493,6 +2505,30 @@ var toggleListOfType = (listType) => (engine) => {
2493
2505
  engine.dispatch(tr);
2494
2506
  return true;
2495
2507
  }
2508
+ if (block.type === "list_item" && (parentType === "bullet_list" || parentType === "ordered_list")) {
2509
+ tr.steps.push(tr_setNodeType(parentPath, listType, {}));
2510
+ engine.dispatch(tr);
2511
+ return true;
2512
+ }
2513
+ if (block.type === "check_list_item" && parentType === "check_list") {
2514
+ const checkList = parent;
2515
+ const grandParentPath = parentPath.slice(0, -1);
2516
+ const listIdx = parentPath[parentPath.length - 1];
2517
+ const convertedList = {
2518
+ type: listType,
2519
+ attrs: {},
2520
+ children: checkList.children.map((item) => ({
2521
+ type: "list_item",
2522
+ attrs: {},
2523
+ children: item.children
2524
+ }))
2525
+ };
2526
+ tr.steps.push({ type: "delete_node", path: parentPath });
2527
+ tr.steps.push({ type: "insert_node", parentPath: grandParentPath, index: listIdx, node: convertedList });
2528
+ tr.steps.push(tr_setSelection(makeCollapsedSelection(makePosition([...grandParentPath, listIdx, blockIdx, 0], 0))));
2529
+ engine.dispatch(tr);
2530
+ return true;
2531
+ }
2496
2532
  const listItem = {
2497
2533
  type: "list_item",
2498
2534
  attrs: {},
@@ -2651,6 +2687,25 @@ var toggleCheckList = (engine) => {
2651
2687
  engine.dispatch(tr);
2652
2688
  return true;
2653
2689
  }
2690
+ if (block.type === "list_item" && (parentType === "bullet_list" || parentType === "ordered_list")) {
2691
+ const listNode = parent;
2692
+ const grandParentPath = parentPath.slice(0, -1);
2693
+ const listIdx = parentPath[parentPath.length - 1];
2694
+ const convertedList = {
2695
+ type: "check_list",
2696
+ attrs: {},
2697
+ children: listNode.children.map((item) => ({
2698
+ type: "check_list_item",
2699
+ attrs: { checked: false },
2700
+ children: item.children
2701
+ }))
2702
+ };
2703
+ tr.steps.push({ type: "delete_node", path: parentPath });
2704
+ tr.steps.push({ type: "insert_node", parentPath: grandParentPath, index: listIdx, node: convertedList });
2705
+ tr.steps.push(tr_setSelection(makeCollapsedSelection(makePosition([...grandParentPath, listIdx, blockIdx, 0], 0))));
2706
+ engine.dispatch(tr);
2707
+ return true;
2708
+ }
2654
2709
  const checkListItem = { type: "check_list_item", attrs: { checked: false }, children: block.children };
2655
2710
  const checkListNode = { type: "check_list", attrs: {}, children: [checkListItem] };
2656
2711
  tr.steps.push({ type: "delete_node", path: blockPath });