@tiptap/core 2.1.2 → 2.1.4
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 +5 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -27
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +5 -29
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -10
- package/package.json +2 -2
- package/src/inputRules/nodeInputRule.ts +6 -40
package/dist/index.cjs
CHANGED
|
@@ -3986,14 +3986,12 @@ function markInputRule(config) {
|
|
|
3986
3986
|
function nodeInputRule(config) {
|
|
3987
3987
|
return new InputRule({
|
|
3988
3988
|
find: config.find,
|
|
3989
|
-
handler: ({ state
|
|
3990
|
-
var _a, _b;
|
|
3989
|
+
handler: ({ state, range, match }) => {
|
|
3991
3990
|
const attributes = callOrReturn(config.getAttributes, undefined, match) || {};
|
|
3992
|
-
const { tr } = state
|
|
3993
|
-
const start =
|
|
3991
|
+
const { tr } = state;
|
|
3992
|
+
const start = range.from;
|
|
3994
3993
|
let end = range.to;
|
|
3995
3994
|
const newNode = config.type.create(attributes);
|
|
3996
|
-
const { $to } = tr.selection;
|
|
3997
3995
|
if (match[1]) {
|
|
3998
3996
|
const offset = match[0].lastIndexOf(match[1]);
|
|
3999
3997
|
let matchStart = start + offset;
|
|
@@ -4010,31 +4008,9 @@ function nodeInputRule(config) {
|
|
|
4010
4008
|
tr.replaceWith(matchStart, end, newNode);
|
|
4011
4009
|
}
|
|
4012
4010
|
else if (match[0]) {
|
|
4013
|
-
tr.
|
|
4014
|
-
}
|
|
4015
|
-
if (config.blockReplace && config.addExtraNewline) {
|
|
4016
|
-
if ($to.nodeAfter) {
|
|
4017
|
-
if ($to.nodeAfter.isTextblock) {
|
|
4018
|
-
tr.setSelection(state.TextSelection.create(tr.doc, $to.pos + 1));
|
|
4019
|
-
}
|
|
4020
|
-
else if ($to.nodeAfter.isBlock) {
|
|
4021
|
-
tr.setSelection(state.NodeSelection.create(tr.doc, $to.pos));
|
|
4022
|
-
}
|
|
4023
|
-
else {
|
|
4024
|
-
tr.setSelection(state.TextSelection.create(tr.doc, $to.pos - 1));
|
|
4025
|
-
}
|
|
4026
|
-
}
|
|
4027
|
-
else {
|
|
4028
|
-
// add node after horizontal rule if it’s the end of the document
|
|
4029
|
-
const defaultNode = ((_a = $to.parent.type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.create()) || ((_b = state$1.doc.type.contentMatch.defaultType) === null || _b === void 0 ? void 0 : _b.create());
|
|
4030
|
-
if (defaultNode) {
|
|
4031
|
-
const newPos = start + newNode.nodeSize;
|
|
4032
|
-
tr.insert(newPos, defaultNode);
|
|
4033
|
-
tr.setSelection(state.TextSelection.create(tr.doc, newPos));
|
|
4034
|
-
}
|
|
4035
|
-
}
|
|
4036
|
-
tr.scrollIntoView();
|
|
4011
|
+
tr.insert(start - 1, config.type.create(attributes)).delete(tr.mapping.map(start), tr.mapping.map(end));
|
|
4037
4012
|
}
|
|
4013
|
+
tr.scrollIntoView();
|
|
4038
4014
|
},
|
|
4039
4015
|
});
|
|
4040
4016
|
}
|