@tiptap/core 2.0.0-beta.180 → 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.
@@ -1,2 +1,3 @@
1
1
  export * from './markPasteRule';
2
+ export * from './nodePasteRule';
2
3
  export * from './textPasteRule';
@@ -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;
@@ -1537,7 +1537,9 @@ const focus = (position = null, options = {}) => ({ editor, view, tr, dispatch,
1537
1537
  delayedFocus();
1538
1538
  return true;
1539
1539
  }
1540
- const selection = resolveFocusPosition(editor.state.doc, position) || editor.state.selection;
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;
1541
1543
  const isSameSelection = editor.state.selection.eq(selection);
1542
1544
  if (dispatch) {
1543
1545
  if (!isSameSelection) {
@@ -4136,6 +4138,35 @@ function markPasteRule(config) {
4136
4138
  });
4137
4139
  }
4138
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
+
4139
4170
  /**
4140
4171
  * Build an paste rule that replaces text when the
4141
4172
  * matched text is pasted into it.
@@ -4187,11 +4218,6 @@ class Tracker {
4187
4218
  }
4188
4219
  }
4189
4220
 
4190
- // source: https://stackoverflow.com/a/6969486
4191
- function escapeForRegEx(string) {
4192
- return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
4193
- }
4194
-
4195
4221
  exports.CommandManager = CommandManager;
4196
4222
  exports.Editor = Editor;
4197
4223
  exports.Extension = Extension;
@@ -4241,6 +4267,7 @@ exports.markInputRule = markInputRule;
4241
4267
  exports.markPasteRule = markPasteRule;
4242
4268
  exports.mergeAttributes = mergeAttributes;
4243
4269
  exports.nodeInputRule = nodeInputRule;
4270
+ exports.nodePasteRule = nodePasteRule;
4244
4271
  exports.pasteRulesPlugin = pasteRulesPlugin;
4245
4272
  exports.posToDOMRect = posToDOMRect;
4246
4273
  exports.textInputRule = textInputRule;