@tiptap/core 2.0.0-beta.180 → 2.0.0-beta.183
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/packages/core/src/Mark.d.ts +8 -0
- package/dist/packages/core/src/pasteRules/index.d.ts +1 -0
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +12 -0
- package/dist/tiptap-core.cjs.js +83 -57
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +83 -58
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +83 -57
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +9 -9
- package/src/CommandManager.ts +2 -2
- package/src/Editor.ts +1 -0
- package/src/ExtensionManager.ts +13 -4
- package/src/Mark.ts +39 -0
- package/src/PasteRule.ts +2 -2
- package/src/commands/focus.ts +3 -1
- package/src/commands/setContent.ts +1 -4
- package/src/commands/setNodeSelection.ts +3 -5
- package/src/commands/splitBlock.ts +1 -12
- package/src/extensions/focusEvents.ts +2 -2
- package/src/helpers/getTextContentFromNodes.ts +1 -1
- package/src/helpers/isNodeSelection.ts +1 -3
- package/src/helpers/isTextSelection.ts +1 -3
- package/src/pasteRules/index.ts +1 -0
- package/src/pasteRules/nodePasteRule.ts +39 -0
- package/dist/packages/core/src/utilities/isClass.d.ts +0 -1
- package/dist/packages/core/src/utilities/isObject.d.ts +0 -1
- package/src/utilities/isClass.ts +0 -7
- package/src/utilities/isObject.ts +0 -10
package/dist/tiptap-core.umd.js
CHANGED
|
@@ -103,13 +103,13 @@
|
|
|
103
103
|
}
|
|
104
104
|
createCan(startTr) {
|
|
105
105
|
const { rawCommands, state } = this;
|
|
106
|
-
const dispatch =
|
|
106
|
+
const dispatch = false;
|
|
107
107
|
const tr = startTr || state.tr;
|
|
108
108
|
const props = this.buildProps(tr, dispatch);
|
|
109
109
|
const formattedCommands = Object.fromEntries(Object
|
|
110
110
|
.entries(rawCommands)
|
|
111
111
|
.map(([name, command]) => {
|
|
112
|
-
return [name, (...args) => command(...args)({ ...props, dispatch })];
|
|
112
|
+
return [name, (...args) => command(...args)({ ...props, dispatch: undefined })];
|
|
113
113
|
}));
|
|
114
114
|
return {
|
|
115
115
|
...formattedCommands,
|
|
@@ -540,10 +540,10 @@
|
|
|
540
540
|
const getTextContentFromNodes = ($from, maxMatch = 500) => {
|
|
541
541
|
let textBefore = '';
|
|
542
542
|
$from.parent.nodesBetween(Math.max(0, $from.parentOffset - maxMatch), $from.parentOffset, (node, pos, parent, index) => {
|
|
543
|
-
var _a, _b;
|
|
543
|
+
var _a, _b, _c;
|
|
544
544
|
textBefore += ((_b = (_a = node.type.spec).toText) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
545
545
|
node, pos, parent, index,
|
|
546
|
-
})) ||
|
|
546
|
+
})) || ((_c = $from.nodeBefore) === null || _c === void 0 ? void 0 : _c.text) || '%leaf%';
|
|
547
547
|
});
|
|
548
548
|
return textBefore;
|
|
549
549
|
};
|
|
@@ -856,7 +856,7 @@
|
|
|
856
856
|
editor,
|
|
857
857
|
state: chainableState,
|
|
858
858
|
from: Math.max(from - 1, 0),
|
|
859
|
-
to: to.b,
|
|
859
|
+
to: to.b - 1,
|
|
860
860
|
rule,
|
|
861
861
|
});
|
|
862
862
|
// stop if there are no changes
|
|
@@ -1014,15 +1014,21 @@
|
|
|
1014
1014
|
};
|
|
1015
1015
|
const plugins = [];
|
|
1016
1016
|
const addKeyboardShortcuts = getExtensionField(extension, 'addKeyboardShortcuts', context);
|
|
1017
|
+
let defaultBindings = {};
|
|
1018
|
+
// bind exit handling
|
|
1019
|
+
if (extension.type === 'mark' && extension.config.exitable) {
|
|
1020
|
+
defaultBindings.ArrowRight = () => Mark.handleExit({ editor, mark: extension });
|
|
1021
|
+
}
|
|
1017
1022
|
if (addKeyboardShortcuts) {
|
|
1018
1023
|
const bindings = Object.fromEntries(Object
|
|
1019
1024
|
.entries(addKeyboardShortcuts())
|
|
1020
1025
|
.map(([shortcut, method]) => {
|
|
1021
1026
|
return [shortcut, () => method({ editor })];
|
|
1022
1027
|
}));
|
|
1023
|
-
|
|
1024
|
-
plugins.push(keyMapPlugin);
|
|
1028
|
+
defaultBindings = { ...defaultBindings, ...bindings };
|
|
1025
1029
|
}
|
|
1030
|
+
const keyMapPlugin = prosemirrorKeymap.keymap(defaultBindings);
|
|
1031
|
+
plugins.push(keyMapPlugin);
|
|
1026
1032
|
const addInputRules = getExtensionField(extension, 'addInputRules', context);
|
|
1027
1033
|
if (isExtensionRulesEnabled(extension, editor.options.enableInputRules) && addInputRules) {
|
|
1028
1034
|
inputRules.push(...addInputRules());
|
|
@@ -1445,23 +1451,8 @@
|
|
|
1445
1451
|
return false;
|
|
1446
1452
|
};
|
|
1447
1453
|
|
|
1448
|
-
function isClass(value) {
|
|
1449
|
-
var _a;
|
|
1450
|
-
if (((_a = value.constructor) === null || _a === void 0 ? void 0 : _a.toString().substring(0, 5)) !== 'class') {
|
|
1451
|
-
return false;
|
|
1452
|
-
}
|
|
1453
|
-
return true;
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
function isObject(value) {
|
|
1457
|
-
return (value
|
|
1458
|
-
&& typeof value === 'object'
|
|
1459
|
-
&& !Array.isArray(value)
|
|
1460
|
-
&& !isClass(value));
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
1454
|
function isTextSelection(value) {
|
|
1464
|
-
return
|
|
1455
|
+
return value instanceof prosemirrorState.TextSelection;
|
|
1465
1456
|
}
|
|
1466
1457
|
|
|
1467
1458
|
function minMax(value = 0, min = 0, max = 0) {
|
|
@@ -1531,7 +1522,9 @@
|
|
|
1531
1522
|
delayedFocus();
|
|
1532
1523
|
return true;
|
|
1533
1524
|
}
|
|
1534
|
-
|
|
1525
|
+
// pass through tr.doc instead of editor.state.doc
|
|
1526
|
+
// since transactions could change the editors state before this command has been run
|
|
1527
|
+
const selection = resolveFocusPosition(tr.doc, position) || editor.state.selection;
|
|
1535
1528
|
const isSameSelection = editor.state.selection.eq(selection);
|
|
1536
1529
|
if (dispatch) {
|
|
1537
1530
|
if (!isSameSelection) {
|
|
@@ -1930,10 +1923,8 @@
|
|
|
1930
1923
|
const setContent = (content, emitUpdate = false, parseOptions = {}) => ({ tr, editor, dispatch }) => {
|
|
1931
1924
|
const { doc } = tr;
|
|
1932
1925
|
const document = createDocument(content, editor.schema, parseOptions);
|
|
1933
|
-
const selection = prosemirrorState.TextSelection.create(doc, 0, doc.content.size);
|
|
1934
1926
|
if (dispatch) {
|
|
1935
|
-
tr.
|
|
1936
|
-
.replaceSelectionWith(document, false)
|
|
1927
|
+
tr.replaceWith(0, doc.content.size, document)
|
|
1937
1928
|
.setMeta('preventUpdate', !emitUpdate);
|
|
1938
1929
|
}
|
|
1939
1930
|
return true;
|
|
@@ -2034,10 +2025,8 @@
|
|
|
2034
2025
|
const setNodeSelection = position => ({ tr, dispatch }) => {
|
|
2035
2026
|
if (dispatch) {
|
|
2036
2027
|
const { doc } = tr;
|
|
2037
|
-
const
|
|
2038
|
-
const
|
|
2039
|
-
const resolvedPos = minMax(position, minPos, maxPos);
|
|
2040
|
-
const selection = prosemirrorState.NodeSelection.create(doc, resolvedPos);
|
|
2028
|
+
const from = minMax(position, 0, doc.content.size);
|
|
2029
|
+
const selection = prosemirrorState.NodeSelection.create(doc, from);
|
|
2041
2030
|
tr.setSelection(selection);
|
|
2042
2031
|
}
|
|
2043
2032
|
return true;
|
|
@@ -2064,6 +2053,16 @@
|
|
|
2064
2053
|
return prosemirrorSchemaList.sinkListItem(type)(state, dispatch);
|
|
2065
2054
|
};
|
|
2066
2055
|
|
|
2056
|
+
function defaultBlockAt(match) {
|
|
2057
|
+
for (let i = 0; i < match.edgeCount; i += 1) {
|
|
2058
|
+
const { type } = match.edge(i);
|
|
2059
|
+
if (type.isTextblock && !type.hasRequiredAttrs()) {
|
|
2060
|
+
return type;
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
return null;
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2067
2066
|
function getSplittedAttributes(extensionAttributes, typeName, attributes) {
|
|
2068
2067
|
return Object.fromEntries(Object
|
|
2069
2068
|
.entries(attributes)
|
|
@@ -2078,15 +2077,6 @@
|
|
|
2078
2077
|
}));
|
|
2079
2078
|
}
|
|
2080
2079
|
|
|
2081
|
-
function defaultBlockAt$1(match) {
|
|
2082
|
-
for (let i = 0; i < match.edgeCount; i += 1) {
|
|
2083
|
-
const { type } = match.edge(i);
|
|
2084
|
-
if (type.isTextblock && !type.hasRequiredAttrs()) {
|
|
2085
|
-
return type;
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
return null;
|
|
2089
|
-
}
|
|
2090
2080
|
function ensureMarks(state, splittableMarks) {
|
|
2091
2081
|
const marks = state.storedMarks
|
|
2092
2082
|
|| (state.selection.$to.parentOffset && state.selection.$from.marks());
|
|
@@ -2122,7 +2112,7 @@
|
|
|
2122
2112
|
}
|
|
2123
2113
|
const deflt = $from.depth === 0
|
|
2124
2114
|
? undefined
|
|
2125
|
-
: defaultBlockAt
|
|
2115
|
+
: defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)));
|
|
2126
2116
|
let types = atEnd && deflt
|
|
2127
2117
|
? [{
|
|
2128
2118
|
type: deflt,
|
|
@@ -3087,6 +3077,7 @@ img.ProseMirror-separator {
|
|
|
3087
3077
|
*/
|
|
3088
3078
|
setEditable(editable) {
|
|
3089
3079
|
this.setOptions({ editable });
|
|
3080
|
+
this.emit('update', { editor: this, transaction: this.state.tr });
|
|
3090
3081
|
}
|
|
3091
3082
|
/**
|
|
3092
3083
|
* Returns whether the editor is editable.
|
|
@@ -3344,16 +3335,6 @@ img.ProseMirror-separator {
|
|
|
3344
3335
|
return transform;
|
|
3345
3336
|
}
|
|
3346
3337
|
|
|
3347
|
-
function defaultBlockAt(match) {
|
|
3348
|
-
for (let i = 0; i < match.edgeCount; i += 1) {
|
|
3349
|
-
const { type } = match.edge(i);
|
|
3350
|
-
if (type.isTextblock && !type.hasRequiredAttrs()) {
|
|
3351
|
-
return type;
|
|
3352
|
-
}
|
|
3353
|
-
}
|
|
3354
|
-
return null;
|
|
3355
|
-
}
|
|
3356
|
-
|
|
3357
3338
|
function findChildren(node, predicate) {
|
|
3358
3339
|
const nodesWithPos = [];
|
|
3359
3340
|
node.descendants((child, pos) => {
|
|
@@ -3571,7 +3552,7 @@ img.ProseMirror-separator {
|
|
|
3571
3552
|
}
|
|
3572
3553
|
|
|
3573
3554
|
function isNodeSelection(value) {
|
|
3574
|
-
return
|
|
3555
|
+
return value instanceof prosemirrorState.NodeSelection;
|
|
3575
3556
|
}
|
|
3576
3557
|
|
|
3577
3558
|
function posToDOMRect(view, from, to) {
|
|
@@ -3832,6 +3813,26 @@ img.ProseMirror-separator {
|
|
|
3832
3813
|
}));
|
|
3833
3814
|
return extension;
|
|
3834
3815
|
}
|
|
3816
|
+
static handleExit({ editor, mark, }) {
|
|
3817
|
+
const { tr } = editor.state;
|
|
3818
|
+
const currentPos = editor.state.selection.$from;
|
|
3819
|
+
const isAtEnd = currentPos.pos === currentPos.end();
|
|
3820
|
+
if (isAtEnd) {
|
|
3821
|
+
const currentMarks = currentPos.marks();
|
|
3822
|
+
const isInMark = !!currentMarks.find(m => (m === null || m === void 0 ? void 0 : m.type.name) === mark.name);
|
|
3823
|
+
if (!isInMark) {
|
|
3824
|
+
return false;
|
|
3825
|
+
}
|
|
3826
|
+
const removeMark = currentMarks.find(m => (m === null || m === void 0 ? void 0 : m.type.name) === mark.name);
|
|
3827
|
+
if (removeMark) {
|
|
3828
|
+
tr.removeStoredMark(removeMark);
|
|
3829
|
+
}
|
|
3830
|
+
tr.insertText(' ', currentPos.pos);
|
|
3831
|
+
editor.view.dispatch(tr);
|
|
3832
|
+
return true;
|
|
3833
|
+
}
|
|
3834
|
+
return false;
|
|
3835
|
+
}
|
|
3835
3836
|
}
|
|
3836
3837
|
|
|
3837
3838
|
class Node {
|
|
@@ -4130,6 +4131,35 @@ img.ProseMirror-separator {
|
|
|
4130
4131
|
});
|
|
4131
4132
|
}
|
|
4132
4133
|
|
|
4134
|
+
// source: https://stackoverflow.com/a/6969486
|
|
4135
|
+
function escapeForRegEx(string) {
|
|
4136
|
+
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
4137
|
+
}
|
|
4138
|
+
|
|
4139
|
+
/**
|
|
4140
|
+
* Build an paste rule that adds a node when the
|
|
4141
|
+
* matched text is pasted into it.
|
|
4142
|
+
*/
|
|
4143
|
+
function nodePasteRule(config) {
|
|
4144
|
+
return new PasteRule({
|
|
4145
|
+
find: config.find,
|
|
4146
|
+
handler({ match, chain, range }) {
|
|
4147
|
+
const attributes = callOrReturn(config.getAttributes, undefined, match);
|
|
4148
|
+
if (attributes === false || attributes === null) {
|
|
4149
|
+
return null;
|
|
4150
|
+
}
|
|
4151
|
+
if (match.input) {
|
|
4152
|
+
chain()
|
|
4153
|
+
.deleteRange(range)
|
|
4154
|
+
.insertContent({
|
|
4155
|
+
type: config.type.name,
|
|
4156
|
+
attrs: attributes,
|
|
4157
|
+
});
|
|
4158
|
+
}
|
|
4159
|
+
},
|
|
4160
|
+
});
|
|
4161
|
+
}
|
|
4162
|
+
|
|
4133
4163
|
/**
|
|
4134
4164
|
* Build an paste rule that replaces text when the
|
|
4135
4165
|
* matched text is pasted into it.
|
|
@@ -4181,11 +4211,6 @@ img.ProseMirror-separator {
|
|
|
4181
4211
|
}
|
|
4182
4212
|
}
|
|
4183
4213
|
|
|
4184
|
-
// source: https://stackoverflow.com/a/6969486
|
|
4185
|
-
function escapeForRegEx(string) {
|
|
4186
|
-
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
4187
|
-
}
|
|
4188
|
-
|
|
4189
4214
|
exports.CommandManager = CommandManager;
|
|
4190
4215
|
exports.Editor = Editor;
|
|
4191
4216
|
exports.Extension = Extension;
|
|
@@ -4235,6 +4260,7 @@ img.ProseMirror-separator {
|
|
|
4235
4260
|
exports.markPasteRule = markPasteRule;
|
|
4236
4261
|
exports.mergeAttributes = mergeAttributes;
|
|
4237
4262
|
exports.nodeInputRule = nodeInputRule;
|
|
4263
|
+
exports.nodePasteRule = nodePasteRule;
|
|
4238
4264
|
exports.pasteRulesPlugin = pasteRulesPlugin;
|
|
4239
4265
|
exports.posToDOMRect = posToDOMRect;
|
|
4240
4266
|
exports.textInputRule = textInputRule;
|