@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.
@@ -11,10 +11,11 @@
11
11
  let { storedMarks } = transaction;
12
12
  return {
13
13
  ...state,
14
- schema: state.schema,
15
- plugins: state.plugins,
16
14
  apply: state.apply.bind(state),
17
15
  applyTransaction: state.applyTransaction.bind(state),
16
+ filterTransaction: state.filterTransaction,
17
+ plugins: state.plugins,
18
+ schema: state.schema,
18
19
  reconfigure: state.reconfigure.bind(state),
19
20
  toJSON: state.toJSON.bind(state),
20
21
  get storedMarks() {
@@ -654,7 +655,7 @@
654
655
  return null;
655
656
  },
656
657
  apply(tr, prev) {
657
- const stored = tr.getMeta(this);
658
+ const stored = tr.getMeta(plugin);
658
659
  if (stored) {
659
660
  return stored;
660
661
  }
@@ -1196,13 +1197,15 @@
1196
1197
  text += blockSeparator;
1197
1198
  separated = true;
1198
1199
  }
1199
- text += textSerializer({
1200
- node,
1201
- pos,
1202
- parent,
1203
- index,
1204
- range,
1205
- });
1200
+ if (parent) {
1201
+ text += textSerializer({
1202
+ node,
1203
+ pos,
1204
+ parent,
1205
+ index,
1206
+ range,
1207
+ });
1208
+ }
1206
1209
  }
1207
1210
  else if (node.isText) {
1208
1211
  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
@@ -1382,7 +1385,7 @@
1382
1385
  if (!start.node) {
1383
1386
  return;
1384
1387
  }
1385
- const mark = findMarkInSet(start.node.marks, type, attributes);
1388
+ const mark = findMarkInSet([...start.node.marks], type, attributes);
1386
1389
  if (!mark) {
1387
1390
  return;
1388
1391
  }
@@ -1390,13 +1393,13 @@
1390
1393
  let startPos = $pos.start() + start.offset;
1391
1394
  let endIndex = startIndex + 1;
1392
1395
  let endPos = startPos + start.node.nodeSize;
1393
- findMarkInSet(start.node.marks, type, attributes);
1396
+ findMarkInSet([...start.node.marks], type, attributes);
1394
1397
  while (startIndex > 0 && mark.isInSet($pos.parent.child(startIndex - 1).marks)) {
1395
1398
  startIndex -= 1;
1396
1399
  startPos -= $pos.parent.child(startIndex).nodeSize;
1397
1400
  }
1398
1401
  while (endIndex < $pos.parent.childCount
1399
- && isMarkInSet($pos.parent.child(endIndex).marks, type, attributes)) {
1402
+ && isMarkInSet([...$pos.parent.child(endIndex).marks], type, attributes)) {
1400
1403
  endPos += $pos.parent.child(endIndex).nodeSize;
1401
1404
  endIndex += 1;
1402
1405
  }
@@ -1528,7 +1531,9 @@
1528
1531
  delayedFocus();
1529
1532
  return true;
1530
1533
  }
1531
- const selection = resolveFocusPosition(editor.state.doc, position) || editor.state.selection;
1534
+ // pass through tr.doc instead of editor.state.doc
1535
+ // since transactions could change the editors state before this command has been run
1536
+ const selection = resolveFocusPosition(tr.doc, position) || editor.state.selection;
1532
1537
  const isSameSelection = editor.state.selection.eq(selection);
1533
1538
  if (dispatch) {
1534
1539
  if (!isSameSelection) {
@@ -2801,13 +2806,7 @@
2801
2806
  new prosemirrorState.Plugin({
2802
2807
  key: new prosemirrorState.PluginKey('tabindex'),
2803
2808
  props: {
2804
- attributes: () => {
2805
- if (this.editor.isEditable) {
2806
- return {
2807
- tabindex: '0',
2808
- };
2809
- }
2810
- },
2809
+ attributes: this.editor.isEditable ? { tabindex: '0' } : {},
2811
2810
  },
2812
2811
  }),
2813
2812
  ];
@@ -3116,7 +3115,7 @@ img.ProseMirror-separator {
3116
3115
  */
3117
3116
  registerPlugin(plugin, handlePlugins) {
3118
3117
  const plugins = isFunction(handlePlugins)
3119
- ? handlePlugins(plugin, this.state.plugins)
3118
+ ? handlePlugins(plugin, [...this.state.plugins])
3120
3119
  : [...this.state.plugins, plugin];
3121
3120
  const state = this.state.reconfigure({ plugins });
3122
3121
  this.view.updateState(state);
@@ -3177,7 +3176,7 @@ img.ProseMirror-separator {
3177
3176
  dispatchTransaction: this.dispatchTransaction.bind(this),
3178
3177
  state: prosemirrorState.EditorState.create({
3179
3178
  doc,
3180
- selection,
3179
+ selection: selection || undefined,
3181
3180
  }),
3182
3181
  });
3183
3182
  // `editor.view` is not yet available at this time.
@@ -3923,7 +3922,7 @@ img.ProseMirror-separator {
3923
3922
  return;
3924
3923
  }
3925
3924
  get dom() {
3926
- return null;
3925
+ return this.editor.view.dom;
3927
3926
  }
3928
3927
  get contentDOM() {
3929
3928
  return null;
@@ -4133,6 +4132,35 @@ img.ProseMirror-separator {
4133
4132
  });
4134
4133
  }
4135
4134
 
4135
+ // source: https://stackoverflow.com/a/6969486
4136
+ function escapeForRegEx(string) {
4137
+ return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
4138
+ }
4139
+
4140
+ /**
4141
+ * Build an paste rule that adds a node when the
4142
+ * matched text is pasted into it.
4143
+ */
4144
+ function nodePasteRule(config) {
4145
+ return new PasteRule({
4146
+ find: config.find,
4147
+ handler({ match, chain, range }) {
4148
+ const attributes = callOrReturn(config.getAttributes, undefined, match);
4149
+ if (attributes === false || attributes === null) {
4150
+ return null;
4151
+ }
4152
+ if (match.input) {
4153
+ chain()
4154
+ .deleteRange(range)
4155
+ .insertContent({
4156
+ type: config.type.name,
4157
+ attrs: attributes,
4158
+ });
4159
+ }
4160
+ },
4161
+ });
4162
+ }
4163
+
4136
4164
  /**
4137
4165
  * Build an paste rule that replaces text when the
4138
4166
  * matched text is pasted into it.
@@ -4184,11 +4212,6 @@ img.ProseMirror-separator {
4184
4212
  }
4185
4213
  }
4186
4214
 
4187
- // source: https://stackoverflow.com/a/6969486
4188
- function escapeForRegEx(string) {
4189
- return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
4190
- }
4191
-
4192
4215
  exports.CommandManager = CommandManager;
4193
4216
  exports.Editor = Editor;
4194
4217
  exports.Extension = Extension;
@@ -4238,6 +4261,7 @@ img.ProseMirror-separator {
4238
4261
  exports.markPasteRule = markPasteRule;
4239
4262
  exports.mergeAttributes = mergeAttributes;
4240
4263
  exports.nodeInputRule = nodeInputRule;
4264
+ exports.nodePasteRule = nodePasteRule;
4241
4265
  exports.pasteRulesPlugin = pasteRulesPlugin;
4242
4266
  exports.posToDOMRect = posToDOMRect;
4243
4267
  exports.textInputRule = textInputRule;