@tiptap/core 3.19.0 → 3.20.0
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 +56 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -2
- package/dist/index.d.ts +38 -2
- package/dist/index.js +56 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/Editor.ts +8 -3
- package/src/Extendable.ts +24 -0
- package/src/ExtensionManager.ts +42 -1
- package/src/__tests__/transformPastedHTML.test.ts +575 -0
- package/src/helpers/getAttributesFromExtensions.ts +20 -1
- package/src/helpers/isMarkActive.ts +5 -0
- package/src/types.ts +11 -1
package/dist/index.cjs
CHANGED
|
@@ -1481,6 +1481,9 @@ function getAttributesFromExtensions(extensions) {
|
|
|
1481
1481
|
keepOnSplit: true,
|
|
1482
1482
|
isRequired: false
|
|
1483
1483
|
};
|
|
1484
|
+
const nodeExtensionTypes = nodeExtensions.filter((ext) => ext.name !== "text").map((ext) => ext.name);
|
|
1485
|
+
const markExtensionTypes = markExtensions.map((ext) => ext.name);
|
|
1486
|
+
const allExtensionTypes = [...nodeExtensionTypes, ...markExtensionTypes];
|
|
1484
1487
|
extensions.forEach((extension) => {
|
|
1485
1488
|
const context = {
|
|
1486
1489
|
name: extension.name,
|
|
@@ -1498,7 +1501,19 @@ function getAttributesFromExtensions(extensions) {
|
|
|
1498
1501
|
}
|
|
1499
1502
|
const globalAttributes = addGlobalAttributes();
|
|
1500
1503
|
globalAttributes.forEach((globalAttribute) => {
|
|
1501
|
-
|
|
1504
|
+
let resolvedTypes;
|
|
1505
|
+
if (Array.isArray(globalAttribute.types)) {
|
|
1506
|
+
resolvedTypes = globalAttribute.types;
|
|
1507
|
+
} else if (globalAttribute.types === "*") {
|
|
1508
|
+
resolvedTypes = allExtensionTypes;
|
|
1509
|
+
} else if (globalAttribute.types === "nodes") {
|
|
1510
|
+
resolvedTypes = nodeExtensionTypes;
|
|
1511
|
+
} else if (globalAttribute.types === "marks") {
|
|
1512
|
+
resolvedTypes = markExtensionTypes;
|
|
1513
|
+
} else {
|
|
1514
|
+
resolvedTypes = [];
|
|
1515
|
+
}
|
|
1516
|
+
resolvedTypes.forEach((type) => {
|
|
1502
1517
|
Object.entries(globalAttribute.attributes).forEach(([name, attribute]) => {
|
|
1503
1518
|
extensionAttributes.push({
|
|
1504
1519
|
type,
|
|
@@ -2116,6 +2131,9 @@ function isMarkActive(state, typeOrName, attributes = {}) {
|
|
|
2116
2131
|
const from = $from.pos;
|
|
2117
2132
|
const to = $to.pos;
|
|
2118
2133
|
state.doc.nodesBetween(from, to, (node, pos) => {
|
|
2134
|
+
if (type && node.inlineContent && !node.type.allowsMarkType(type)) {
|
|
2135
|
+
return false;
|
|
2136
|
+
}
|
|
2119
2137
|
if (!node.isText && !node.marks.length) {
|
|
2120
2138
|
return;
|
|
2121
2139
|
}
|
|
@@ -3816,6 +3834,39 @@ var ExtensionManager = class {
|
|
|
3816
3834
|
};
|
|
3817
3835
|
}, baseDispatch);
|
|
3818
3836
|
}
|
|
3837
|
+
/**
|
|
3838
|
+
* Get the composed transformPastedHTML function from all extensions.
|
|
3839
|
+
* @param baseTransform The base transform function (e.g. from the editor props)
|
|
3840
|
+
* @returns A composed transform function that chains all extension transforms
|
|
3841
|
+
*/
|
|
3842
|
+
transformPastedHTML(baseTransform) {
|
|
3843
|
+
const { editor } = this;
|
|
3844
|
+
const extensions = sortExtensions([...this.extensions]);
|
|
3845
|
+
return extensions.reduce(
|
|
3846
|
+
(transform, extension) => {
|
|
3847
|
+
const context = {
|
|
3848
|
+
name: extension.name,
|
|
3849
|
+
options: extension.options,
|
|
3850
|
+
storage: this.editor.extensionStorage[extension.name],
|
|
3851
|
+
editor,
|
|
3852
|
+
type: getSchemaTypeByName(extension.name, this.schema)
|
|
3853
|
+
};
|
|
3854
|
+
const extensionTransform = getExtensionField(
|
|
3855
|
+
extension,
|
|
3856
|
+
"transformPastedHTML",
|
|
3857
|
+
context
|
|
3858
|
+
);
|
|
3859
|
+
if (!extensionTransform) {
|
|
3860
|
+
return transform;
|
|
3861
|
+
}
|
|
3862
|
+
return (html, view) => {
|
|
3863
|
+
const transformedHtml = transform(html, view);
|
|
3864
|
+
return extensionTransform.call(context, transformedHtml);
|
|
3865
|
+
};
|
|
3866
|
+
},
|
|
3867
|
+
baseTransform || ((html) => html)
|
|
3868
|
+
);
|
|
3869
|
+
}
|
|
3819
3870
|
get markViews() {
|
|
3820
3871
|
const { editor } = this;
|
|
3821
3872
|
const { markExtensions } = splitExtensions(this.extensions);
|
|
@@ -4838,7 +4889,7 @@ var Editor = class extends EventEmitter {
|
|
|
4838
4889
|
return this.options.editable && this.view && this.view.editable;
|
|
4839
4890
|
}
|
|
4840
4891
|
/**
|
|
4841
|
-
* Returns the editor
|
|
4892
|
+
* Returns the editor view.
|
|
4842
4893
|
*/
|
|
4843
4894
|
get view() {
|
|
4844
4895
|
if (this.editorView) {
|
|
@@ -5007,6 +5058,8 @@ var Editor = class extends EventEmitter {
|
|
|
5007
5058
|
const { editorProps, enableExtensionDispatchTransaction } = this.options;
|
|
5008
5059
|
const baseDispatch = editorProps.dispatchTransaction || this.dispatchTransaction.bind(this);
|
|
5009
5060
|
const dispatch = enableExtensionDispatchTransaction ? this.extensionManager.dispatchTransaction(baseDispatch) : baseDispatch;
|
|
5061
|
+
const baseTransformPastedHTML = editorProps.transformPastedHTML;
|
|
5062
|
+
const transformPastedHTML = this.extensionManager.transformPastedHTML(baseTransformPastedHTML);
|
|
5010
5063
|
this.editorView = new import_view.EditorView(element, {
|
|
5011
5064
|
...editorProps,
|
|
5012
5065
|
attributes: {
|
|
@@ -5015,6 +5068,7 @@ var Editor = class extends EventEmitter {
|
|
|
5015
5068
|
...editorProps == null ? void 0 : editorProps.attributes
|
|
5016
5069
|
},
|
|
5017
5070
|
dispatchTransaction: dispatch,
|
|
5071
|
+
transformPastedHTML,
|
|
5018
5072
|
state: this.editorState,
|
|
5019
5073
|
markViews: this.extensionManager.markViews,
|
|
5020
5074
|
nodeViews: this.extensionManager.nodeViews
|