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