@tiptap/core 3.20.0 → 3.20.2
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.cjs +73 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +73 -18
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/types.ts +6 -0
- package/src/utilities/markdown/renderNestedMarkdownContent.ts +9 -7
- package/src/utilities/mergeAttributes.ts +74 -26
package/dist/index.cjs
CHANGED
|
@@ -1564,6 +1564,67 @@ function getAttributesFromExtensions(extensions) {
|
|
|
1564
1564
|
}
|
|
1565
1565
|
|
|
1566
1566
|
// src/utilities/mergeAttributes.ts
|
|
1567
|
+
function splitStyleDeclarations(styles) {
|
|
1568
|
+
const result = [];
|
|
1569
|
+
let current = "";
|
|
1570
|
+
let inSingleQuote = false;
|
|
1571
|
+
let inDoubleQuote = false;
|
|
1572
|
+
let parenDepth = 0;
|
|
1573
|
+
const length = styles.length;
|
|
1574
|
+
for (let i = 0; i < length; i += 1) {
|
|
1575
|
+
const char = styles[i];
|
|
1576
|
+
if (char === "'" && !inDoubleQuote) {
|
|
1577
|
+
inSingleQuote = !inSingleQuote;
|
|
1578
|
+
current += char;
|
|
1579
|
+
continue;
|
|
1580
|
+
}
|
|
1581
|
+
if (char === '"' && !inSingleQuote) {
|
|
1582
|
+
inDoubleQuote = !inDoubleQuote;
|
|
1583
|
+
current += char;
|
|
1584
|
+
continue;
|
|
1585
|
+
}
|
|
1586
|
+
if (!inSingleQuote && !inDoubleQuote) {
|
|
1587
|
+
if (char === "(") {
|
|
1588
|
+
parenDepth += 1;
|
|
1589
|
+
current += char;
|
|
1590
|
+
continue;
|
|
1591
|
+
}
|
|
1592
|
+
if (char === ")" && parenDepth > 0) {
|
|
1593
|
+
parenDepth -= 1;
|
|
1594
|
+
current += char;
|
|
1595
|
+
continue;
|
|
1596
|
+
}
|
|
1597
|
+
if (char === ";" && parenDepth === 0) {
|
|
1598
|
+
result.push(current);
|
|
1599
|
+
current = "";
|
|
1600
|
+
continue;
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
current += char;
|
|
1604
|
+
}
|
|
1605
|
+
if (current) {
|
|
1606
|
+
result.push(current);
|
|
1607
|
+
}
|
|
1608
|
+
return result;
|
|
1609
|
+
}
|
|
1610
|
+
function parseStyleEntries(styles) {
|
|
1611
|
+
const pairs = [];
|
|
1612
|
+
const declarations = splitStyleDeclarations(styles || "");
|
|
1613
|
+
const numDeclarations = declarations.length;
|
|
1614
|
+
for (let i = 0; i < numDeclarations; i += 1) {
|
|
1615
|
+
const declaration = declarations[i];
|
|
1616
|
+
const firstColonIndex = declaration.indexOf(":");
|
|
1617
|
+
if (firstColonIndex === -1) {
|
|
1618
|
+
continue;
|
|
1619
|
+
}
|
|
1620
|
+
const property = declaration.slice(0, firstColonIndex).trim();
|
|
1621
|
+
const value = declaration.slice(firstColonIndex + 1).trim();
|
|
1622
|
+
if (property && value) {
|
|
1623
|
+
pairs.push([property, value]);
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
return pairs;
|
|
1627
|
+
}
|
|
1567
1628
|
function mergeAttributes(...objects) {
|
|
1568
1629
|
return objects.filter((item) => !!item).reduce((items, item) => {
|
|
1569
1630
|
const mergedAttributes = { ...items };
|
|
@@ -1579,17 +1640,7 @@ function mergeAttributes(...objects) {
|
|
|
1579
1640
|
const insertClasses = valueClasses.filter((valueClass) => !existingClasses.includes(valueClass));
|
|
1580
1641
|
mergedAttributes[key] = [...existingClasses, ...insertClasses].join(" ");
|
|
1581
1642
|
} else if (key === "style") {
|
|
1582
|
-
const
|
|
1583
|
-
const existingStyles = mergedAttributes[key] ? mergedAttributes[key].split(";").map((style2) => style2.trim()).filter(Boolean) : [];
|
|
1584
|
-
const styleMap = /* @__PURE__ */ new Map();
|
|
1585
|
-
existingStyles.forEach((style2) => {
|
|
1586
|
-
const [property, val] = style2.split(":").map((part) => part.trim());
|
|
1587
|
-
styleMap.set(property, val);
|
|
1588
|
-
});
|
|
1589
|
-
newStyles.forEach((style2) => {
|
|
1590
|
-
const [property, val] = style2.split(":").map((part) => part.trim());
|
|
1591
|
-
styleMap.set(property, val);
|
|
1592
|
-
});
|
|
1643
|
+
const styleMap = new Map([...parseStyleEntries(mergedAttributes[key]), ...parseStyleEntries(value)]);
|
|
1593
1644
|
mergedAttributes[key] = Array.from(styleMap.entries()).map(([property, val]) => `${property}: ${val}`).join("; ");
|
|
1594
1645
|
} else {
|
|
1595
1646
|
mergedAttributes[key] = value;
|
|
@@ -6510,17 +6561,21 @@ function renderNestedMarkdownContent(node, h2, prefixOrGenerator, ctx) {
|
|
|
6510
6561
|
const prefix = typeof prefixOrGenerator === "function" ? prefixOrGenerator(ctx) : prefixOrGenerator;
|
|
6511
6562
|
const [content, ...children] = node.content;
|
|
6512
6563
|
const mainContent = h2.renderChildren([content]);
|
|
6513
|
-
|
|
6564
|
+
let output = `${prefix}${mainContent}`;
|
|
6514
6565
|
if (children && children.length > 0) {
|
|
6515
|
-
children.forEach((child) => {
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
|
|
6519
|
-
|
|
6566
|
+
children.forEach((child, index) => {
|
|
6567
|
+
var _a, _b;
|
|
6568
|
+
const childContent = (_b = (_a = h2.renderChild) == null ? void 0 : _a.call(h2, child, index + 1)) != null ? _b : h2.renderChildren([child]);
|
|
6569
|
+
if (childContent !== void 0 && childContent !== null) {
|
|
6570
|
+
const indentedChild = childContent.split("\n").map((line) => line ? h2.indent(line) : h2.indent("")).join("\n");
|
|
6571
|
+
output += child.type === "paragraph" ? `
|
|
6572
|
+
|
|
6573
|
+
${indentedChild}` : `
|
|
6574
|
+
${indentedChild}`;
|
|
6520
6575
|
}
|
|
6521
6576
|
});
|
|
6522
6577
|
}
|
|
6523
|
-
return output
|
|
6578
|
+
return output;
|
|
6524
6579
|
}
|
|
6525
6580
|
|
|
6526
6581
|
// src/MarkView.ts
|