@tiptap/extension-text-style
Advanced tools
Comparing version 3.0.0-next.1 to 3.0.0-next.2
@@ -10,2 +10,10 @@ import { Mark } from '@tiptap/core'; | ||
HTMLAttributes: Record<string, any>; | ||
/** | ||
* When enabled, merges the styles of nested spans into the child span during HTML parsing. | ||
* This prioritizes the style of the child span. | ||
* Used when parsing content created in other editors. | ||
* (Fix for ProseMirror's default behavior.) | ||
* @default false | ||
*/ | ||
mergeNestedSpanStyles: boolean; | ||
} | ||
@@ -12,0 +20,0 @@ declare module '@tiptap/core' { |
@@ -7,2 +7,17 @@ // src/text-style.ts | ||
} from "@tiptap/core"; | ||
var mergeNestedSpanStyles = (element) => { | ||
if (!element.children.length) { | ||
return; | ||
} | ||
const childSpans = element.querySelectorAll("span"); | ||
if (!childSpans) { | ||
return; | ||
} | ||
childSpans.forEach((childSpan) => { | ||
var _a, _b; | ||
const childStyle = childSpan.getAttribute("style"); | ||
const closestParentSpanStyleOfChild = (_b = (_a = childSpan.parentElement) == null ? void 0 : _a.closest("span")) == null ? void 0 : _b.getAttribute("style"); | ||
childSpan.setAttribute("style", `${closestParentSpanStyleOfChild};${childStyle}`); | ||
}); | ||
}; | ||
var TextStyle = Mark.create({ | ||
@@ -13,3 +28,4 @@ name: "textStyle", | ||
return { | ||
HTMLAttributes: {} | ||
HTMLAttributes: {}, | ||
mergeNestedSpanStyles: false | ||
}; | ||
@@ -26,2 +42,5 @@ }, | ||
} | ||
if (this.options.mergeNestedSpanStyles) { | ||
mergeNestedSpanStyles(element); | ||
} | ||
return {}; | ||
@@ -28,0 +47,0 @@ } |
{ | ||
"name": "@tiptap/extension-text-style", | ||
"description": "text style extension for tiptap", | ||
"version": "3.0.0-next.1", | ||
"version": "3.0.0-next.2", | ||
"homepage": "https://tiptap.dev", | ||
@@ -31,3 +31,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@tiptap/core": "^3.0.0-next.1" | ||
"@tiptap/core": "^3.0.0-next.2" | ||
}, | ||
@@ -34,0 +34,0 @@ "peerDependencies": { |
@@ -14,2 +14,10 @@ import { | ||
HTMLAttributes: Record<string, any>, | ||
/** | ||
* When enabled, merges the styles of nested spans into the child span during HTML parsing. | ||
* This prioritizes the style of the child span. | ||
* Used when parsing content created in other editors. | ||
* (Fix for ProseMirror's default behavior.) | ||
* @default false | ||
*/ | ||
mergeNestedSpanStyles: boolean, | ||
} | ||
@@ -29,2 +37,17 @@ | ||
const mergeNestedSpanStyles = (element: HTMLElement) => { | ||
if (!element.children.length) { return } | ||
const childSpans = element.querySelectorAll('span') | ||
if (!childSpans) { return } | ||
childSpans.forEach(childSpan => { | ||
const childStyle = childSpan.getAttribute('style') | ||
const closestParentSpanStyleOfChild = childSpan.parentElement?.closest('span')?.getAttribute('style') | ||
childSpan.setAttribute('style', `${closestParentSpanStyleOfChild};${childStyle}`) | ||
}) | ||
} | ||
/** | ||
@@ -43,2 +66,3 @@ * This extension allows you to create text styles. It is required by default | ||
HTMLAttributes: {}, | ||
mergeNestedSpanStyles: false, | ||
} | ||
@@ -57,2 +81,3 @@ }, | ||
} | ||
if (this.options.mergeNestedSpanStyles) { mergeNestedSpanStyles(element) } | ||
@@ -59,0 +84,0 @@ return {} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
20016
284
0