@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
|
@@ -92,7 +92,7 @@ export declare class Editor extends EventEmitter<EditorEvents> {
|
|
|
92
92
|
createNodeViews(): void;
|
|
93
93
|
isCapturingTransaction: boolean;
|
|
94
94
|
private capturedTransaction;
|
|
95
|
-
captureTransaction(fn: Function): Transaction
|
|
95
|
+
captureTransaction(fn: Function): Transaction | null;
|
|
96
96
|
/**
|
|
97
97
|
* The callback over which to send transactions (state updates) produced by the view.
|
|
98
98
|
*
|
|
@@ -14,8 +14,8 @@ export declare class NodeView<Component, Editor extends CoreEditor = CoreEditor,
|
|
|
14
14
|
isDragging: boolean;
|
|
15
15
|
constructor(component: Component, props: NodeViewRendererProps, options?: Partial<Options>);
|
|
16
16
|
mount(): void;
|
|
17
|
-
get dom():
|
|
18
|
-
get contentDOM():
|
|
17
|
+
get dom(): HTMLElement;
|
|
18
|
+
get contentDOM(): HTMLElement | null;
|
|
19
19
|
onDragStart(event: DragEvent): void;
|
|
20
20
|
stopEvent(event: Event): boolean;
|
|
21
21
|
ignoreMutation(mutation: MutationRecord | {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
/// <reference types="prosemirror-model" />
|
|
2
1
|
import { Selection } from 'prosemirror-state';
|
|
3
2
|
import { Predicate } from '../types';
|
|
4
3
|
export declare function findParentNode(predicate: Predicate): (selection: Selection) => {
|
|
5
4
|
pos: number;
|
|
6
5
|
start: number;
|
|
7
6
|
depth: number;
|
|
8
|
-
node: import("prosemirror-model").Node
|
|
7
|
+
node: import("prosemirror-model").Node;
|
|
9
8
|
} | undefined;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ResolvedPos } from 'prosemirror-model';
|
|
2
|
-
export declare const getTextContentFromNodes: ($from: ResolvedPos
|
|
2
|
+
export declare const getTextContentFromNodes: ($from: ResolvedPos, maxMatch?: number) => string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NodeType } from 'prosemirror-model';
|
|
2
|
+
import { PasteRule } from '../PasteRule';
|
|
3
|
+
import { ExtendedRegExpMatchArray } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Build an paste rule that adds a node when the
|
|
6
|
+
* matched text is pasted into it.
|
|
7
|
+
*/
|
|
8
|
+
export declare function nodePasteRule(config: {
|
|
9
|
+
find: RegExp;
|
|
10
|
+
type: NodeType;
|
|
11
|
+
getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null;
|
|
12
|
+
}): PasteRule;
|
package/dist/tiptap-core.cjs.js
CHANGED
|
@@ -17,10 +17,11 @@ function createChainableState(config) {
|
|
|
17
17
|
let { storedMarks } = transaction;
|
|
18
18
|
return {
|
|
19
19
|
...state,
|
|
20
|
-
schema: state.schema,
|
|
21
|
-
plugins: state.plugins,
|
|
22
20
|
apply: state.apply.bind(state),
|
|
23
21
|
applyTransaction: state.applyTransaction.bind(state),
|
|
22
|
+
filterTransaction: state.filterTransaction,
|
|
23
|
+
plugins: state.plugins,
|
|
24
|
+
schema: state.schema,
|
|
24
25
|
reconfigure: state.reconfigure.bind(state),
|
|
25
26
|
toJSON: state.toJSON.bind(state),
|
|
26
27
|
get storedMarks() {
|
|
@@ -660,7 +661,7 @@ function inputRulesPlugin(props) {
|
|
|
660
661
|
return null;
|
|
661
662
|
},
|
|
662
663
|
apply(tr, prev) {
|
|
663
|
-
const stored = tr.getMeta(
|
|
664
|
+
const stored = tr.getMeta(plugin);
|
|
664
665
|
if (stored) {
|
|
665
666
|
return stored;
|
|
666
667
|
}
|
|
@@ -1202,13 +1203,15 @@ function getTextBetween(startNode, range, options) {
|
|
|
1202
1203
|
text += blockSeparator;
|
|
1203
1204
|
separated = true;
|
|
1204
1205
|
}
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1206
|
+
if (parent) {
|
|
1207
|
+
text += textSerializer({
|
|
1208
|
+
node,
|
|
1209
|
+
pos,
|
|
1210
|
+
parent,
|
|
1211
|
+
index,
|
|
1212
|
+
range,
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1212
1215
|
}
|
|
1213
1216
|
else if (node.isText) {
|
|
1214
1217
|
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
|
|
@@ -1388,7 +1391,7 @@ function getMarkRange($pos, type, attributes = {}) {
|
|
|
1388
1391
|
if (!start.node) {
|
|
1389
1392
|
return;
|
|
1390
1393
|
}
|
|
1391
|
-
const mark = findMarkInSet(start.node.marks, type, attributes);
|
|
1394
|
+
const mark = findMarkInSet([...start.node.marks], type, attributes);
|
|
1392
1395
|
if (!mark) {
|
|
1393
1396
|
return;
|
|
1394
1397
|
}
|
|
@@ -1396,13 +1399,13 @@ function getMarkRange($pos, type, attributes = {}) {
|
|
|
1396
1399
|
let startPos = $pos.start() + start.offset;
|
|
1397
1400
|
let endIndex = startIndex + 1;
|
|
1398
1401
|
let endPos = startPos + start.node.nodeSize;
|
|
1399
|
-
findMarkInSet(start.node.marks, type, attributes);
|
|
1402
|
+
findMarkInSet([...start.node.marks], type, attributes);
|
|
1400
1403
|
while (startIndex > 0 && mark.isInSet($pos.parent.child(startIndex - 1).marks)) {
|
|
1401
1404
|
startIndex -= 1;
|
|
1402
1405
|
startPos -= $pos.parent.child(startIndex).nodeSize;
|
|
1403
1406
|
}
|
|
1404
1407
|
while (endIndex < $pos.parent.childCount
|
|
1405
|
-
&& isMarkInSet(
|
|
1408
|
+
&& isMarkInSet([...$pos.parent.child(endIndex).marks], type, attributes)) {
|
|
1406
1409
|
endPos += $pos.parent.child(endIndex).nodeSize;
|
|
1407
1410
|
endIndex += 1;
|
|
1408
1411
|
}
|
|
@@ -1534,7 +1537,9 @@ const focus = (position = null, options = {}) => ({ editor, view, tr, dispatch,
|
|
|
1534
1537
|
delayedFocus();
|
|
1535
1538
|
return true;
|
|
1536
1539
|
}
|
|
1537
|
-
|
|
1540
|
+
// pass through tr.doc instead of editor.state.doc
|
|
1541
|
+
// since transactions could change the editors state before this command has been run
|
|
1542
|
+
const selection = resolveFocusPosition(tr.doc, position) || editor.state.selection;
|
|
1538
1543
|
const isSameSelection = editor.state.selection.eq(selection);
|
|
1539
1544
|
if (dispatch) {
|
|
1540
1545
|
if (!isSameSelection) {
|
|
@@ -2807,13 +2812,7 @@ const Tabindex = Extension.create({
|
|
|
2807
2812
|
new prosemirrorState.Plugin({
|
|
2808
2813
|
key: new prosemirrorState.PluginKey('tabindex'),
|
|
2809
2814
|
props: {
|
|
2810
|
-
attributes:
|
|
2811
|
-
if (this.editor.isEditable) {
|
|
2812
|
-
return {
|
|
2813
|
-
tabindex: '0',
|
|
2814
|
-
};
|
|
2815
|
-
}
|
|
2816
|
-
},
|
|
2815
|
+
attributes: this.editor.isEditable ? { tabindex: '0' } : {},
|
|
2817
2816
|
},
|
|
2818
2817
|
}),
|
|
2819
2818
|
];
|
|
@@ -3122,7 +3121,7 @@ class Editor extends EventEmitter {
|
|
|
3122
3121
|
*/
|
|
3123
3122
|
registerPlugin(plugin, handlePlugins) {
|
|
3124
3123
|
const plugins = isFunction(handlePlugins)
|
|
3125
|
-
? handlePlugins(plugin, this.state.plugins)
|
|
3124
|
+
? handlePlugins(plugin, [...this.state.plugins])
|
|
3126
3125
|
: [...this.state.plugins, plugin];
|
|
3127
3126
|
const state = this.state.reconfigure({ plugins });
|
|
3128
3127
|
this.view.updateState(state);
|
|
@@ -3183,7 +3182,7 @@ class Editor extends EventEmitter {
|
|
|
3183
3182
|
dispatchTransaction: this.dispatchTransaction.bind(this),
|
|
3184
3183
|
state: prosemirrorState.EditorState.create({
|
|
3185
3184
|
doc,
|
|
3186
|
-
selection,
|
|
3185
|
+
selection: selection || undefined,
|
|
3187
3186
|
}),
|
|
3188
3187
|
});
|
|
3189
3188
|
// `editor.view` is not yet available at this time.
|
|
@@ -3929,7 +3928,7 @@ class NodeView {
|
|
|
3929
3928
|
return;
|
|
3930
3929
|
}
|
|
3931
3930
|
get dom() {
|
|
3932
|
-
return
|
|
3931
|
+
return this.editor.view.dom;
|
|
3933
3932
|
}
|
|
3934
3933
|
get contentDOM() {
|
|
3935
3934
|
return null;
|
|
@@ -4139,6 +4138,35 @@ function markPasteRule(config) {
|
|
|
4139
4138
|
});
|
|
4140
4139
|
}
|
|
4141
4140
|
|
|
4141
|
+
// source: https://stackoverflow.com/a/6969486
|
|
4142
|
+
function escapeForRegEx(string) {
|
|
4143
|
+
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
4144
|
+
}
|
|
4145
|
+
|
|
4146
|
+
/**
|
|
4147
|
+
* Build an paste rule that adds a node when the
|
|
4148
|
+
* matched text is pasted into it.
|
|
4149
|
+
*/
|
|
4150
|
+
function nodePasteRule(config) {
|
|
4151
|
+
return new PasteRule({
|
|
4152
|
+
find: config.find,
|
|
4153
|
+
handler({ match, chain, range }) {
|
|
4154
|
+
const attributes = callOrReturn(config.getAttributes, undefined, match);
|
|
4155
|
+
if (attributes === false || attributes === null) {
|
|
4156
|
+
return null;
|
|
4157
|
+
}
|
|
4158
|
+
if (match.input) {
|
|
4159
|
+
chain()
|
|
4160
|
+
.deleteRange(range)
|
|
4161
|
+
.insertContent({
|
|
4162
|
+
type: config.type.name,
|
|
4163
|
+
attrs: attributes,
|
|
4164
|
+
});
|
|
4165
|
+
}
|
|
4166
|
+
},
|
|
4167
|
+
});
|
|
4168
|
+
}
|
|
4169
|
+
|
|
4142
4170
|
/**
|
|
4143
4171
|
* Build an paste rule that replaces text when the
|
|
4144
4172
|
* matched text is pasted into it.
|
|
@@ -4190,11 +4218,6 @@ class Tracker {
|
|
|
4190
4218
|
}
|
|
4191
4219
|
}
|
|
4192
4220
|
|
|
4193
|
-
// source: https://stackoverflow.com/a/6969486
|
|
4194
|
-
function escapeForRegEx(string) {
|
|
4195
|
-
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
4196
|
-
}
|
|
4197
|
-
|
|
4198
4221
|
exports.CommandManager = CommandManager;
|
|
4199
4222
|
exports.Editor = Editor;
|
|
4200
4223
|
exports.Extension = Extension;
|
|
@@ -4244,6 +4267,7 @@ exports.markInputRule = markInputRule;
|
|
|
4244
4267
|
exports.markPasteRule = markPasteRule;
|
|
4245
4268
|
exports.mergeAttributes = mergeAttributes;
|
|
4246
4269
|
exports.nodeInputRule = nodeInputRule;
|
|
4270
|
+
exports.nodePasteRule = nodePasteRule;
|
|
4247
4271
|
exports.pasteRulesPlugin = pasteRulesPlugin;
|
|
4248
4272
|
exports.posToDOMRect = posToDOMRect;
|
|
4249
4273
|
exports.textInputRule = textInputRule;
|