@tiptap/core 2.0.0-beta.182 → 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/tiptap-core.cjs.js +47 -46
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +47 -46
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +47 -46
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +2 -2
- 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 +1 -1
- package/src/commands/setNodeSelection.ts +3 -5
- package/src/commands/splitBlock.ts +1 -12
- package/src/helpers/isNodeSelection.ts +1 -3
- package/src/helpers/isTextSelection.ts +1 -3
- 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,
|
|
@@ -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) {
|
|
@@ -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 {
|