@tiptap/core 3.20.0 → 3.20.1
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 +62 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +62 -11
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/utilities/mergeAttributes.ts +74 -26
package/dist/index.js
CHANGED
|
@@ -1431,6 +1431,67 @@ function getAttributesFromExtensions(extensions) {
|
|
|
1431
1431
|
}
|
|
1432
1432
|
|
|
1433
1433
|
// src/utilities/mergeAttributes.ts
|
|
1434
|
+
function splitStyleDeclarations(styles) {
|
|
1435
|
+
const result = [];
|
|
1436
|
+
let current = "";
|
|
1437
|
+
let inSingleQuote = false;
|
|
1438
|
+
let inDoubleQuote = false;
|
|
1439
|
+
let parenDepth = 0;
|
|
1440
|
+
const length = styles.length;
|
|
1441
|
+
for (let i = 0; i < length; i += 1) {
|
|
1442
|
+
const char = styles[i];
|
|
1443
|
+
if (char === "'" && !inDoubleQuote) {
|
|
1444
|
+
inSingleQuote = !inSingleQuote;
|
|
1445
|
+
current += char;
|
|
1446
|
+
continue;
|
|
1447
|
+
}
|
|
1448
|
+
if (char === '"' && !inSingleQuote) {
|
|
1449
|
+
inDoubleQuote = !inDoubleQuote;
|
|
1450
|
+
current += char;
|
|
1451
|
+
continue;
|
|
1452
|
+
}
|
|
1453
|
+
if (!inSingleQuote && !inDoubleQuote) {
|
|
1454
|
+
if (char === "(") {
|
|
1455
|
+
parenDepth += 1;
|
|
1456
|
+
current += char;
|
|
1457
|
+
continue;
|
|
1458
|
+
}
|
|
1459
|
+
if (char === ")" && parenDepth > 0) {
|
|
1460
|
+
parenDepth -= 1;
|
|
1461
|
+
current += char;
|
|
1462
|
+
continue;
|
|
1463
|
+
}
|
|
1464
|
+
if (char === ";" && parenDepth === 0) {
|
|
1465
|
+
result.push(current);
|
|
1466
|
+
current = "";
|
|
1467
|
+
continue;
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
current += char;
|
|
1471
|
+
}
|
|
1472
|
+
if (current) {
|
|
1473
|
+
result.push(current);
|
|
1474
|
+
}
|
|
1475
|
+
return result;
|
|
1476
|
+
}
|
|
1477
|
+
function parseStyleEntries(styles) {
|
|
1478
|
+
const pairs = [];
|
|
1479
|
+
const declarations = splitStyleDeclarations(styles || "");
|
|
1480
|
+
const numDeclarations = declarations.length;
|
|
1481
|
+
for (let i = 0; i < numDeclarations; i += 1) {
|
|
1482
|
+
const declaration = declarations[i];
|
|
1483
|
+
const firstColonIndex = declaration.indexOf(":");
|
|
1484
|
+
if (firstColonIndex === -1) {
|
|
1485
|
+
continue;
|
|
1486
|
+
}
|
|
1487
|
+
const property = declaration.slice(0, firstColonIndex).trim();
|
|
1488
|
+
const value = declaration.slice(firstColonIndex + 1).trim();
|
|
1489
|
+
if (property && value) {
|
|
1490
|
+
pairs.push([property, value]);
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
return pairs;
|
|
1494
|
+
}
|
|
1434
1495
|
function mergeAttributes(...objects) {
|
|
1435
1496
|
return objects.filter((item) => !!item).reduce((items, item) => {
|
|
1436
1497
|
const mergedAttributes = { ...items };
|
|
@@ -1446,17 +1507,7 @@ function mergeAttributes(...objects) {
|
|
|
1446
1507
|
const insertClasses = valueClasses.filter((valueClass) => !existingClasses.includes(valueClass));
|
|
1447
1508
|
mergedAttributes[key] = [...existingClasses, ...insertClasses].join(" ");
|
|
1448
1509
|
} else if (key === "style") {
|
|
1449
|
-
const
|
|
1450
|
-
const existingStyles = mergedAttributes[key] ? mergedAttributes[key].split(";").map((style2) => style2.trim()).filter(Boolean) : [];
|
|
1451
|
-
const styleMap = /* @__PURE__ */ new Map();
|
|
1452
|
-
existingStyles.forEach((style2) => {
|
|
1453
|
-
const [property, val] = style2.split(":").map((part) => part.trim());
|
|
1454
|
-
styleMap.set(property, val);
|
|
1455
|
-
});
|
|
1456
|
-
newStyles.forEach((style2) => {
|
|
1457
|
-
const [property, val] = style2.split(":").map((part) => part.trim());
|
|
1458
|
-
styleMap.set(property, val);
|
|
1459
|
-
});
|
|
1510
|
+
const styleMap = new Map([...parseStyleEntries(mergedAttributes[key]), ...parseStyleEntries(value)]);
|
|
1460
1511
|
mergedAttributes[key] = Array.from(styleMap.entries()).map(([property, val]) => `${property}: ${val}`).join("; ");
|
|
1461
1512
|
} else {
|
|
1462
1513
|
mergedAttributes[key] = value;
|