@tiptap/core 2.8.0 → 2.9.1

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/index.umd.js CHANGED
@@ -1666,12 +1666,16 @@
1666
1666
  return;
1667
1667
  }
1668
1668
  let start = $pos.parent.childAfter($pos.parentOffset);
1669
- if ($pos.parentOffset === start.offset && start.offset !== 0) {
1669
+ // If the cursor is at the start of a text node that does not have the mark, look backward
1670
+ if (!start.node || !start.node.marks.some(mark => mark.type === type)) {
1670
1671
  start = $pos.parent.childBefore($pos.parentOffset);
1671
1672
  }
1672
- if (!start.node) {
1673
+ // If there is no text node with the mark even backward, return undefined
1674
+ if (!start.node || !start.node.marks.some(mark => mark.type === type)) {
1673
1675
  return;
1674
1676
  }
1677
+ // We now know that the cursor is either at the start, middle or end of a text node with the specified mark
1678
+ // so we can look it up on the targeted mark
1675
1679
  const mark = findMarkInSet([...start.node.marks], type, attributes);
1676
1680
  if (!mark) {
1677
1681
  return;
@@ -1961,7 +1965,7 @@
1961
1965
  var _a;
1962
1966
  if (dispatch) {
1963
1967
  options = {
1964
- parseOptions: {},
1968
+ parseOptions: editor.options.parseOptions,
1965
1969
  updateSelection: true,
1966
1970
  applyInputRules: false,
1967
1971
  applyPasteRules: false,
@@ -1982,7 +1986,9 @@
1982
1986
  editor,
1983
1987
  error: e,
1984
1988
  disableCollaboration: () => {
1985
- console.error('[tiptap error]: Unable to disable collaboration at this point in time');
1989
+ if (editor.storage.collaboration) {
1990
+ editor.storage.collaboration.isDisabled = true;
1991
+ }
1986
1992
  },
1987
1993
  });
1988
1994
  return false;
@@ -3961,7 +3967,8 @@
3961
3967
  const children = [];
3962
3968
  this.node.content.forEach((node, offset) => {
3963
3969
  const isBlock = node.isBlock && !node.isTextblock;
3964
- const targetPos = this.pos + offset + 1;
3970
+ const isNonTextAtom = node.isAtom && !node.isText;
3971
+ const targetPos = this.pos + offset + (isNonTextAtom ? 0 : 1);
3965
3972
  const $pos = this.resolvedPos.doc.resolve(targetPos);
3966
3973
  if (!isBlock && $pos.depth <= this.depth) {
3967
3974
  return;
@@ -4037,9 +4044,12 @@
4037
4044
  return nodes;
4038
4045
  }
4039
4046
  setAttribute(attributes) {
4040
- const oldSelection = this.editor.state.selection;
4041
- this.editor.chain().setTextSelection(this.from).updateAttributes(this.node.type.name, attributes).setTextSelection(oldSelection.from)
4042
- .run();
4047
+ const { tr } = this.editor.state;
4048
+ tr.setNodeMarkup(this.from, undefined, {
4049
+ ...this.node.attrs,
4050
+ ...attributes,
4051
+ });
4052
+ this.editor.view.dispatch(tr);
4043
4053
  }
4044
4054
  }
4045
4055
 
@@ -4291,18 +4301,27 @@ img.ProseMirror-separator {
4291
4301
  /**
4292
4302
  * Unregister a ProseMirror plugin.
4293
4303
  *
4294
- * @param nameOrPluginKey The plugins name
4304
+ * @param nameOrPluginKeyToRemove The plugins name
4295
4305
  * @returns The new editor state or undefined if the editor is destroyed
4296
4306
  */
4297
- unregisterPlugin(nameOrPluginKey) {
4307
+ unregisterPlugin(nameOrPluginKeyToRemove) {
4298
4308
  if (this.isDestroyed) {
4299
4309
  return undefined;
4300
4310
  }
4301
- // @ts-ignore
4302
- const name = typeof nameOrPluginKey === 'string' ? `${nameOrPluginKey}$` : nameOrPluginKey.key;
4303
- const state = this.state.reconfigure({
4311
+ const prevPlugins = this.state.plugins;
4312
+ let plugins = prevPlugins;
4313
+ [].concat(nameOrPluginKeyToRemove).forEach(nameOrPluginKey => {
4314
+ // @ts-ignore
4315
+ const name = typeof nameOrPluginKey === 'string' ? `${nameOrPluginKey}$` : nameOrPluginKey.key;
4304
4316
  // @ts-ignore
4305
- plugins: this.state.plugins.filter(plugin => !plugin.key.startsWith(name)),
4317
+ plugins = prevPlugins.filter(plugin => !plugin.key.startsWith(name));
4318
+ });
4319
+ if (prevPlugins.length === plugins.length) {
4320
+ // No plugin was removed, so we don’t need to update the state
4321
+ return undefined;
4322
+ }
4323
+ const state = this.state.reconfigure({
4324
+ plugins,
4306
4325
  });
4307
4326
  this.view.updateState(state);
4308
4327
  return state;
@@ -4365,6 +4384,9 @@ img.ProseMirror-separator {
4365
4384
  editor: this,
4366
4385
  error: e,
4367
4386
  disableCollaboration: () => {
4387
+ if (this.storage.collaboration) {
4388
+ this.storage.collaboration.isDisabled = true;
4389
+ }
4368
4390
  // To avoid syncing back invalid content, reinitialize the extensions without the collaboration extension
4369
4391
  this.options.extensions = this.options.extensions.filter(extension => extension.name !== 'collaboration');
4370
4392
  // Restart the initialization process by recreating the extension manager with the new set of extensions
@@ -4383,6 +4405,12 @@ img.ProseMirror-separator {
4383
4405
  selection: selection || undefined,
4384
4406
  }),
4385
4407
  });
4408
+ // add `role="textbox"` to the editor element
4409
+ this.view.dom.setAttribute('role', 'textbox');
4410
+ // add aria-label to the editor element
4411
+ if (!this.view.dom.getAttribute('aria-label')) {
4412
+ this.view.dom.setAttribute('aria-label', 'Rich-Text Editor');
4413
+ }
4386
4414
  // `editor.view` is not yet available at this time.
4387
4415
  // Therefore we will add all plugins and node views directly afterwards.
4388
4416
  const newState = this.state.reconfigure({