@tiptap/core 2.0.0-beta.141 → 2.0.0-beta.145

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.
@@ -5,7 +5,9 @@ declare module '@tiptap/core' {
5
5
  /**
6
6
  * Focus the editor at the given position.
7
7
  */
8
- focus: (position?: FocusPosition) => ReturnType;
8
+ focus: (position?: FocusPosition, options?: {
9
+ scrollIntoView?: boolean;
10
+ }) => ReturnType;
9
11
  };
10
12
  }
11
13
  }
@@ -0,0 +1,2 @@
1
+ import { ContentMatch, NodeType } from 'prosemirror-model';
2
+ export default function defaultBlockAt(match: ContentMatch): NodeType | null;
@@ -19,6 +19,7 @@ export { default as markPasteRule } from './pasteRules/markPasteRule';
19
19
  export { default as textPasteRule } from './pasteRules/textPasteRule';
20
20
  export { default as callOrReturn } from './utilities/callOrReturn';
21
21
  export { default as mergeAttributes } from './utilities/mergeAttributes';
22
+ export { default as defaultBlockAt } from './helpers/defaultBlockAt';
22
23
  export { default as getExtensionField } from './helpers/getExtensionField';
23
24
  export { default as findChildren } from './helpers/findChildren';
24
25
  export { default as findChildrenInRange } from './helpers/findChildrenInRange';
@@ -15,8 +15,9 @@ function getType(value) {
15
15
  return Object.prototype.toString.call(value).slice(8, -1);
16
16
  }
17
17
  function isPlainObject(value) {
18
- if (getType(value) !== 'Object')
18
+ if (getType(value) !== 'Object') {
19
19
  return false;
20
+ }
20
21
  return value.constructor === Object && Object.getPrototypeOf(value) === Object.prototype;
21
22
  }
22
23
 
@@ -131,15 +132,9 @@ class Extension {
131
132
  if (extendedConfig.defaultOptions) {
132
133
  console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`);
133
134
  }
134
- // TODO: remove `addOptions` fallback
135
- extension.options = extendedConfig.defaultOptions
136
- ? extendedConfig.defaultOptions
137
- : extension.parent.options;
138
- if (extendedConfig.addOptions) {
139
- extension.options = callOrReturn(getExtensionField(extension, 'addOptions', {
140
- name: extension.name,
141
- }));
142
- }
135
+ extension.options = callOrReturn(getExtensionField(extension, 'addOptions', {
136
+ name: extension.name,
137
+ }));
143
138
  extension.storage = callOrReturn(getExtensionField(extension, 'addStorage', {
144
139
  name: extension.name,
145
140
  options: extension.options,
@@ -531,7 +526,11 @@ function resolveSelection(state, position = null) {
531
526
  to: position,
532
527
  };
533
528
  }
534
- const focus = (position = null) => ({ editor, view, tr, dispatch, }) => {
529
+ const focus = (position = null, options) => ({ editor, view, tr, dispatch, }) => {
530
+ options = {
531
+ scrollIntoView: true,
532
+ ...options,
533
+ };
535
534
  const delayedFocus = () => {
536
535
  // focus within `requestAnimationFrame` breaks focus on iOS
537
536
  // so we have to call this
@@ -543,7 +542,9 @@ const focus = (position = null) => ({ editor, view, tr, dispatch, }) => {
543
542
  requestAnimationFrame(() => {
544
543
  if (!editor.isDestroyed) {
545
544
  view.focus();
546
- editor.commands.scrollIntoView();
545
+ if (options === null || options === void 0 ? void 0 : options.scrollIntoView) {
546
+ editor.commands.scrollIntoView();
547
+ }
547
548
  }
548
549
  });
549
550
  };
@@ -1183,7 +1184,7 @@ function getSplittedAttributes(extensionAttributes, typeName, attributes) {
1183
1184
  }));
1184
1185
  }
1185
1186
 
1186
- function defaultBlockAt(match) {
1187
+ function defaultBlockAt$1(match) {
1187
1188
  for (let i = 0; i < match.edgeCount; i += 1) {
1188
1189
  const { type } = match.edge(i);
1189
1190
  if (type.isTextblock && !type.hasRequiredAttrs()) {
@@ -1227,7 +1228,7 @@ const splitBlock = ({ keepMarks = true } = {}) => ({ tr, state, dispatch, editor
1227
1228
  }
1228
1229
  const deflt = $from.depth === 0
1229
1230
  ? undefined
1230
- : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)));
1231
+ : defaultBlockAt$1($from.node(-1).contentMatchAt($from.indexAfter(-1)));
1231
1232
  let types = atEnd && deflt
1232
1233
  ? [{
1233
1234
  type: deflt,
@@ -3421,15 +3422,9 @@ class Node {
3421
3422
  if (extendedConfig.defaultOptions) {
3422
3423
  console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`);
3423
3424
  }
3424
- // TODO: remove `addOptions` fallback
3425
- extension.options = extendedConfig.defaultOptions
3426
- ? extendedConfig.defaultOptions
3427
- : extension.parent.options;
3428
- if (extendedConfig.addOptions) {
3429
- extension.options = callOrReturn(getExtensionField(extension, 'addOptions', {
3430
- name: extension.name,
3431
- }));
3432
- }
3425
+ extension.options = callOrReturn(getExtensionField(extension, 'addOptions', {
3426
+ name: extension.name,
3427
+ }));
3433
3428
  extension.storage = callOrReturn(getExtensionField(extension, 'addStorage', {
3434
3429
  name: extension.name,
3435
3430
  options: extension.options,
@@ -3492,15 +3487,9 @@ class Mark {
3492
3487
  if (extendedConfig.defaultOptions) {
3493
3488
  console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${extension.name}".`);
3494
3489
  }
3495
- // TODO: remove `addOptions` fallback
3496
- extension.options = extendedConfig.defaultOptions
3497
- ? extendedConfig.defaultOptions
3498
- : extension.parent.options;
3499
- if (extendedConfig.addOptions) {
3500
- extension.options = callOrReturn(getExtensionField(extension, 'addOptions', {
3501
- name: extension.name,
3502
- }));
3503
- }
3490
+ extension.options = callOrReturn(getExtensionField(extension, 'addOptions', {
3491
+ name: extension.name,
3492
+ }));
3504
3493
  extension.storage = callOrReturn(getExtensionField(extension, 'addStorage', {
3505
3494
  name: extension.name,
3506
3495
  options: extension.options,
@@ -3964,6 +3953,16 @@ function textPasteRule(config) {
3964
3953
  });
3965
3954
  }
3966
3955
 
3956
+ function defaultBlockAt(match) {
3957
+ for (let i = 0; i < match.edgeCount; i += 1) {
3958
+ const { type } = match.edge(i);
3959
+ if (type.isTextblock && !type.hasRequiredAttrs()) {
3960
+ return type;
3961
+ }
3962
+ }
3963
+ return null;
3964
+ }
3965
+
3967
3966
  function findChildren(node, predicate) {
3968
3967
  const nodesWithPos = [];
3969
3968
  node.descendants((child, pos) => {
@@ -4112,6 +4111,7 @@ exports.NodeView = NodeView;
4112
4111
  exports.PasteRule = PasteRule;
4113
4112
  exports.Tracker = Tracker;
4114
4113
  exports.callOrReturn = callOrReturn;
4114
+ exports.defaultBlockAt = defaultBlockAt;
4115
4115
  exports.extensions = extensions;
4116
4116
  exports.findChildren = findChildren;
4117
4117
  exports.findChildrenInRange = findChildrenInRange;