@tiptap/core 2.0.0-beta.179 → 2.0.0-beta.181
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/Editor.d.ts +1 -1
- package/dist/packages/core/src/NodeView.d.ts +2 -2
- package/dist/packages/core/src/helpers/findParentNode.d.ts +1 -2
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +1 -1
- 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 +53 -29
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +53 -30
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +53 -29
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +9 -16
- package/src/Editor.ts +2 -2
- package/src/InputRule.ts +1 -1
- package/src/NodeView.ts +3 -3
- package/src/PasteRule.ts +2 -2
- package/src/commands/focus.ts +3 -1
- package/src/extensions/focusEvents.ts +2 -2
- package/src/extensions/tabindex.ts +1 -7
- package/src/helpers/createChainableState.ts +3 -2
- package/src/helpers/getMarkRange.ts +3 -3
- package/src/helpers/getTextBetween.ts +9 -7
- package/src/helpers/getTextContentFromNodes.ts +1 -1
- package/src/pasteRules/index.ts +1 -0
- package/src/pasteRules/nodePasteRule.ts +39 -0
package/dist/tiptap-core.esm.js
CHANGED
|
@@ -13,10 +13,11 @@ function createChainableState(config) {
|
|
|
13
13
|
let { storedMarks } = transaction;
|
|
14
14
|
return {
|
|
15
15
|
...state,
|
|
16
|
-
schema: state.schema,
|
|
17
|
-
plugins: state.plugins,
|
|
18
16
|
apply: state.apply.bind(state),
|
|
19
17
|
applyTransaction: state.applyTransaction.bind(state),
|
|
18
|
+
filterTransaction: state.filterTransaction,
|
|
19
|
+
plugins: state.plugins,
|
|
20
|
+
schema: state.schema,
|
|
20
21
|
reconfigure: state.reconfigure.bind(state),
|
|
21
22
|
toJSON: state.toJSON.bind(state),
|
|
22
23
|
get storedMarks() {
|
|
@@ -656,7 +657,7 @@ function inputRulesPlugin(props) {
|
|
|
656
657
|
return null;
|
|
657
658
|
},
|
|
658
659
|
apply(tr, prev) {
|
|
659
|
-
const stored = tr.getMeta(
|
|
660
|
+
const stored = tr.getMeta(plugin);
|
|
660
661
|
if (stored) {
|
|
661
662
|
return stored;
|
|
662
663
|
}
|
|
@@ -1198,13 +1199,15 @@ function getTextBetween(startNode, range, options) {
|
|
|
1198
1199
|
text += blockSeparator;
|
|
1199
1200
|
separated = true;
|
|
1200
1201
|
}
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1202
|
+
if (parent) {
|
|
1203
|
+
text += textSerializer({
|
|
1204
|
+
node,
|
|
1205
|
+
pos,
|
|
1206
|
+
parent,
|
|
1207
|
+
index,
|
|
1208
|
+
range,
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1208
1211
|
}
|
|
1209
1212
|
else if (node.isText) {
|
|
1210
1213
|
text += (_a = node === null || node === void 0 ? void 0 : node.text) === null || _a === void 0 ? void 0 : _a.slice(Math.max(from, pos) - pos, to - pos); // eslint-disable-line
|
|
@@ -1384,7 +1387,7 @@ function getMarkRange($pos, type, attributes = {}) {
|
|
|
1384
1387
|
if (!start.node) {
|
|
1385
1388
|
return;
|
|
1386
1389
|
}
|
|
1387
|
-
const mark = findMarkInSet(start.node.marks, type, attributes);
|
|
1390
|
+
const mark = findMarkInSet([...start.node.marks], type, attributes);
|
|
1388
1391
|
if (!mark) {
|
|
1389
1392
|
return;
|
|
1390
1393
|
}
|
|
@@ -1392,13 +1395,13 @@ function getMarkRange($pos, type, attributes = {}) {
|
|
|
1392
1395
|
let startPos = $pos.start() + start.offset;
|
|
1393
1396
|
let endIndex = startIndex + 1;
|
|
1394
1397
|
let endPos = startPos + start.node.nodeSize;
|
|
1395
|
-
findMarkInSet(start.node.marks, type, attributes);
|
|
1398
|
+
findMarkInSet([...start.node.marks], type, attributes);
|
|
1396
1399
|
while (startIndex > 0 && mark.isInSet($pos.parent.child(startIndex - 1).marks)) {
|
|
1397
1400
|
startIndex -= 1;
|
|
1398
1401
|
startPos -= $pos.parent.child(startIndex).nodeSize;
|
|
1399
1402
|
}
|
|
1400
1403
|
while (endIndex < $pos.parent.childCount
|
|
1401
|
-
&& isMarkInSet(
|
|
1404
|
+
&& isMarkInSet([...$pos.parent.child(endIndex).marks], type, attributes)) {
|
|
1402
1405
|
endPos += $pos.parent.child(endIndex).nodeSize;
|
|
1403
1406
|
endIndex += 1;
|
|
1404
1407
|
}
|
|
@@ -1530,7 +1533,9 @@ const focus = (position = null, options = {}) => ({ editor, view, tr, dispatch,
|
|
|
1530
1533
|
delayedFocus();
|
|
1531
1534
|
return true;
|
|
1532
1535
|
}
|
|
1533
|
-
|
|
1536
|
+
// pass through tr.doc instead of editor.state.doc
|
|
1537
|
+
// since transactions could change the editors state before this command has been run
|
|
1538
|
+
const selection = resolveFocusPosition(tr.doc, position) || editor.state.selection;
|
|
1534
1539
|
const isSameSelection = editor.state.selection.eq(selection);
|
|
1535
1540
|
if (dispatch) {
|
|
1536
1541
|
if (!isSameSelection) {
|
|
@@ -2803,13 +2808,7 @@ const Tabindex = Extension.create({
|
|
|
2803
2808
|
new Plugin({
|
|
2804
2809
|
key: new PluginKey('tabindex'),
|
|
2805
2810
|
props: {
|
|
2806
|
-
attributes:
|
|
2807
|
-
if (this.editor.isEditable) {
|
|
2808
|
-
return {
|
|
2809
|
-
tabindex: '0',
|
|
2810
|
-
};
|
|
2811
|
-
}
|
|
2812
|
-
},
|
|
2811
|
+
attributes: this.editor.isEditable ? { tabindex: '0' } : {},
|
|
2813
2812
|
},
|
|
2814
2813
|
}),
|
|
2815
2814
|
];
|
|
@@ -3118,7 +3117,7 @@ class Editor extends EventEmitter {
|
|
|
3118
3117
|
*/
|
|
3119
3118
|
registerPlugin(plugin, handlePlugins) {
|
|
3120
3119
|
const plugins = isFunction(handlePlugins)
|
|
3121
|
-
? handlePlugins(plugin, this.state.plugins)
|
|
3120
|
+
? handlePlugins(plugin, [...this.state.plugins])
|
|
3122
3121
|
: [...this.state.plugins, plugin];
|
|
3123
3122
|
const state = this.state.reconfigure({ plugins });
|
|
3124
3123
|
this.view.updateState(state);
|
|
@@ -3179,7 +3178,7 @@ class Editor extends EventEmitter {
|
|
|
3179
3178
|
dispatchTransaction: this.dispatchTransaction.bind(this),
|
|
3180
3179
|
state: EditorState.create({
|
|
3181
3180
|
doc,
|
|
3182
|
-
selection,
|
|
3181
|
+
selection: selection || undefined,
|
|
3183
3182
|
}),
|
|
3184
3183
|
});
|
|
3185
3184
|
// `editor.view` is not yet available at this time.
|
|
@@ -3925,7 +3924,7 @@ class NodeView {
|
|
|
3925
3924
|
return;
|
|
3926
3925
|
}
|
|
3927
3926
|
get dom() {
|
|
3928
|
-
return
|
|
3927
|
+
return this.editor.view.dom;
|
|
3929
3928
|
}
|
|
3930
3929
|
get contentDOM() {
|
|
3931
3930
|
return null;
|
|
@@ -4135,6 +4134,35 @@ function markPasteRule(config) {
|
|
|
4135
4134
|
});
|
|
4136
4135
|
}
|
|
4137
4136
|
|
|
4137
|
+
// source: https://stackoverflow.com/a/6969486
|
|
4138
|
+
function escapeForRegEx(string) {
|
|
4139
|
+
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
4140
|
+
}
|
|
4141
|
+
|
|
4142
|
+
/**
|
|
4143
|
+
* Build an paste rule that adds a node when the
|
|
4144
|
+
* matched text is pasted into it.
|
|
4145
|
+
*/
|
|
4146
|
+
function nodePasteRule(config) {
|
|
4147
|
+
return new PasteRule({
|
|
4148
|
+
find: config.find,
|
|
4149
|
+
handler({ match, chain, range }) {
|
|
4150
|
+
const attributes = callOrReturn(config.getAttributes, undefined, match);
|
|
4151
|
+
if (attributes === false || attributes === null) {
|
|
4152
|
+
return null;
|
|
4153
|
+
}
|
|
4154
|
+
if (match.input) {
|
|
4155
|
+
chain()
|
|
4156
|
+
.deleteRange(range)
|
|
4157
|
+
.insertContent({
|
|
4158
|
+
type: config.type.name,
|
|
4159
|
+
attrs: attributes,
|
|
4160
|
+
});
|
|
4161
|
+
}
|
|
4162
|
+
},
|
|
4163
|
+
});
|
|
4164
|
+
}
|
|
4165
|
+
|
|
4138
4166
|
/**
|
|
4139
4167
|
* Build an paste rule that replaces text when the
|
|
4140
4168
|
* matched text is pasted into it.
|
|
@@ -4186,10 +4214,5 @@ class Tracker {
|
|
|
4186
4214
|
}
|
|
4187
4215
|
}
|
|
4188
4216
|
|
|
4189
|
-
|
|
4190
|
-
function escapeForRegEx(string) {
|
|
4191
|
-
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
4192
|
-
}
|
|
4193
|
-
|
|
4194
|
-
export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, defaultBlockAt, escapeForRegEx, extensions, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, inputRulesPlugin, isActive, isList, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isTextSelection, markInputRule, markPasteRule, mergeAttributes, nodeInputRule, pasteRulesPlugin, posToDOMRect, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
|
|
4217
|
+
export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, defaultBlockAt, escapeForRegEx, extensions, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, inputRulesPlugin, isActive, isList, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isTextSelection, markInputRule, markPasteRule, mergeAttributes, nodeInputRule, nodePasteRule, pasteRulesPlugin, posToDOMRect, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
|
|
4195
4218
|
//# sourceMappingURL=tiptap-core.esm.js.map
|