@tiptap/core 2.5.9 → 2.6.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 +24 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -8
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +24 -8
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/Editor.d.ts +4 -0
- package/dist/packages/core/src/Extension.d.ts +4 -3
- package/dist/packages/core/src/Mark.d.ts +4 -3
- package/dist/packages/core/src/Node.d.ts +4 -3
- package/dist/packages/core/src/commands/setMeta.d.ts +2 -1
- package/dist/packages/core/src/commands/splitListItem.d.ts +2 -1
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +2 -1
- package/package.json +3 -3
- package/src/Editor.ts +6 -0
- package/src/Extension.ts +4 -3
- package/src/Mark.ts +4 -3
- package/src/Node.ts +4 -3
- package/src/commands/setMeta.ts +3 -1
- package/src/commands/splitListItem.ts +27 -17
- package/src/pasteRules/nodePasteRule.ts +14 -5
package/dist/index.js
CHANGED
|
@@ -3108,7 +3108,7 @@ const splitBlock = ({ keepMarks = true } = {}) => ({ tr, state, dispatch, editor
|
|
|
3108
3108
|
return can;
|
|
3109
3109
|
};
|
|
3110
3110
|
|
|
3111
|
-
const splitListItem = typeOrName => ({ tr, state, dispatch, editor, }) => {
|
|
3111
|
+
const splitListItem = (typeOrName, overrideAttrs = {}) => ({ tr, state, dispatch, editor, }) => {
|
|
3112
3112
|
var _a;
|
|
3113
3113
|
const type = getNodeType(typeOrName, state.schema);
|
|
3114
3114
|
const { $from, $to } = state.selection;
|
|
@@ -3144,7 +3144,10 @@ const splitListItem = typeOrName => ({ tr, state, dispatch, editor, }) => {
|
|
|
3144
3144
|
// eslint-disable-next-line
|
|
3145
3145
|
const depthAfter = $from.indexAfter(-1) < $from.node(-2).childCount ? 1 : $from.indexAfter(-2) < $from.node(-3).childCount ? 2 : 3;
|
|
3146
3146
|
// Add a second list item with an empty default start node
|
|
3147
|
-
const newNextTypeAttributes =
|
|
3147
|
+
const newNextTypeAttributes = {
|
|
3148
|
+
...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),
|
|
3149
|
+
...overrideAttrs,
|
|
3150
|
+
};
|
|
3148
3151
|
const nextType = ((_a = type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.createAndFill(newNextTypeAttributes)) || undefined;
|
|
3149
3152
|
wrap = wrap.append(Fragment.from(type.createAndFill(null, nextType) || undefined));
|
|
3150
3153
|
const start = $from.before($from.depth - (depthBefore - 1));
|
|
@@ -3166,8 +3169,14 @@ const splitListItem = typeOrName => ({ tr, state, dispatch, editor, }) => {
|
|
|
3166
3169
|
return true;
|
|
3167
3170
|
}
|
|
3168
3171
|
const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null;
|
|
3169
|
-
const newTypeAttributes =
|
|
3170
|
-
|
|
3172
|
+
const newTypeAttributes = {
|
|
3173
|
+
...getSplittedAttributes(extensionAttributes, grandParent.type.name, grandParent.attrs),
|
|
3174
|
+
...overrideAttrs,
|
|
3175
|
+
};
|
|
3176
|
+
const newNextTypeAttributes = {
|
|
3177
|
+
...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),
|
|
3178
|
+
...overrideAttrs,
|
|
3179
|
+
};
|
|
3171
3180
|
tr.delete($from.pos, $to.pos);
|
|
3172
3181
|
const types = nextType
|
|
3173
3182
|
? [
|
|
@@ -3969,6 +3978,10 @@ class Editor extends EventEmitter {
|
|
|
3969
3978
|
constructor(options = {}) {
|
|
3970
3979
|
super();
|
|
3971
3980
|
this.isFocused = false;
|
|
3981
|
+
/**
|
|
3982
|
+
* The editor is considered initialized after the `create` event has been emitted.
|
|
3983
|
+
*/
|
|
3984
|
+
this.isInitialized = false;
|
|
3972
3985
|
this.extensionStorage = {};
|
|
3973
3986
|
this.options = {
|
|
3974
3987
|
element: document.createElement('div'),
|
|
@@ -4019,6 +4032,7 @@ class Editor extends EventEmitter {
|
|
|
4019
4032
|
}
|
|
4020
4033
|
this.commands.focus(this.options.autofocus);
|
|
4021
4034
|
this.emit('create', { editor: this });
|
|
4035
|
+
this.isInitialized = true;
|
|
4022
4036
|
}, 0);
|
|
4023
4037
|
}
|
|
4024
4038
|
/**
|
|
@@ -4986,14 +5000,16 @@ function nodePasteRule(config) {
|
|
|
4986
5000
|
find: config.find,
|
|
4987
5001
|
handler({ match, chain, range, pasteEvent, }) {
|
|
4988
5002
|
const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent);
|
|
5003
|
+
const content = callOrReturn(config.getContent, undefined, attributes);
|
|
4989
5004
|
if (attributes === false || attributes === null) {
|
|
4990
5005
|
return null;
|
|
4991
5006
|
}
|
|
5007
|
+
const node = { type: config.type.name, attrs: attributes };
|
|
5008
|
+
if (content) {
|
|
5009
|
+
node.content = content;
|
|
5010
|
+
}
|
|
4992
5011
|
if (match.input) {
|
|
4993
|
-
chain().deleteRange(range).insertContentAt(range.from,
|
|
4994
|
-
type: config.type.name,
|
|
4995
|
-
attrs: attributes,
|
|
4996
|
-
});
|
|
5012
|
+
chain().deleteRange(range).insertContentAt(range.from, node);
|
|
4997
5013
|
}
|
|
4998
5014
|
},
|
|
4999
5015
|
});
|