@tiptap/core 2.0.0-beta.137 → 2.0.0-beta.140

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/core",
3
3
  "description": "headless rich text editor",
4
- "version": "2.0.0-beta.137",
4
+ "version": "2.0.0-beta.140",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -37,12 +37,12 @@
37
37
  "prosemirror-schema-list": "^1.1.6",
38
38
  "prosemirror-state": "^1.3.4",
39
39
  "prosemirror-transform": "^1.3.3",
40
- "prosemirror-view": "^1.22.0"
40
+ "prosemirror-view": "^1.23.1"
41
41
  },
42
42
  "repository": {
43
43
  "type": "git",
44
44
  "url": "https://github.com/ueberdosis/tiptap",
45
45
  "directory": "packages/core"
46
46
  },
47
- "gitHead": "2bbc594ac9369e4f65fe0b7308c8952f7dc0b5b0"
47
+ "gitHead": "5844a8893c1d0b888b3a338ce3fb3994383a9eef"
48
48
  }
package/src/Editor.ts CHANGED
@@ -22,6 +22,7 @@ import {
22
22
  EditorOptions,
23
23
  CanCommands,
24
24
  ChainedCommands,
25
+ JSONContent,
25
26
  SingleCommands,
26
27
  TextSerializer,
27
28
  EditorEvents,
@@ -401,7 +402,7 @@ export class Editor extends EventEmitter<EditorEvents> {
401
402
  /**
402
403
  * Get the document as JSON.
403
404
  */
404
- public getJSON(): Record<string, any> {
405
+ public getJSON(): JSONContent {
405
406
  return this.state.doc.toJSON()
406
407
  }
407
408
 
@@ -13,6 +13,7 @@ import getNodeType from './helpers/getNodeType'
13
13
  import splitExtensions from './helpers/splitExtensions'
14
14
  import getAttributesFromExtensions from './helpers/getAttributesFromExtensions'
15
15
  import getRenderedAttributes from './helpers/getRenderedAttributes'
16
+ import isExtensionRulesEnabled from './helpers/isExtensionRulesEnabled'
16
17
  import callOrReturn from './utilities/callOrReturn'
17
18
  import findDuplicates from './utilities/findDuplicates'
18
19
  import { NodeConfig } from '.'
@@ -270,7 +271,7 @@ export default class ExtensionManager {
270
271
  context,
271
272
  )
272
273
 
273
- if (editor.options.enableInputRules && addInputRules) {
274
+ if (isExtensionRulesEnabled(extension, editor.options.enableInputRules) && addInputRules) {
274
275
  inputRules.push(...addInputRules())
275
276
  }
276
277
 
@@ -280,7 +281,7 @@ export default class ExtensionManager {
280
281
  context,
281
282
  )
282
283
 
283
- if (editor.options.enablePasteRules && addPasteRules) {
284
+ if (isExtensionRulesEnabled(extension, editor.options.enablePasteRules) && addPasteRules) {
284
285
  pasteRules.push(...addPasteRules())
285
286
  }
286
287
 
package/src/NodeView.ts CHANGED
@@ -202,7 +202,12 @@ export class NodeView<
202
202
  // this is because ProseMirror can’t preventDispatch on enter
203
203
  // this will lead to a re-render of the node view on enter
204
204
  // see: https://github.com/ueberdosis/tiptap/issues/1214
205
- if (this.dom.contains(mutation.target) && mutation.type === 'childList' && isiOS()) {
205
+ if (
206
+ this.dom.contains(mutation.target)
207
+ && mutation.type === 'childList'
208
+ && isiOS()
209
+ && this.editor.isFocused
210
+ ) {
206
211
  const changedNodes = [
207
212
  ...Array.from(mutation.addedNodes),
208
213
  ...Array.from(mutation.removedNodes),
@@ -1,4 +1,4 @@
1
- import { ParseOptions } from 'prosemirror-model'
1
+ import { Fragment, Node as ProseMirrorNode, ParseOptions } from 'prosemirror-model'
2
2
  import createNodeFromContent from '../helpers/createNodeFromContent'
3
3
  import selectionToInsertionEnd from '../helpers/selectionToInsertionEnd'
4
4
  import {
@@ -25,6 +25,10 @@ declare module '@tiptap/core' {
25
25
  }
26
26
  }
27
27
 
28
+ const isFragment = (nodeOrFragment: ProseMirrorNode | Fragment): nodeOrFragment is Fragment => {
29
+ return nodeOrFragment.toString().startsWith('<')
30
+ }
31
+
28
32
  export const insertContentAt: RawCommands['insertContentAt'] = (position, value, options) => ({ tr, dispatch, editor }) => {
29
33
  if (dispatch) {
30
34
  options = {
@@ -50,8 +54,11 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value,
50
54
  : position
51
55
 
52
56
  let isOnlyBlockContent = true
57
+ const nodes = isFragment(content)
58
+ ? content
59
+ : [content]
53
60
 
54
- content.forEach(node => {
61
+ nodes.forEach(node => {
55
62
  isOnlyBlockContent = isOnlyBlockContent
56
63
  ? node.isBlock
57
64
  : false
@@ -63,10 +70,10 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value,
63
70
  // replace an empty paragraph by an inserted image
64
71
  // instead of inserting the image below the paragraph
65
72
  if (from === to && isOnlyBlockContent) {
66
- const $from = tr.doc.resolve(from)
67
- const isEmptyTextBlock = $from.parent.isTextblock
68
- && !$from.parent.type.spec.code
69
- && !$from.parent.textContent
73
+ const { parent } = tr.doc.resolve(from)
74
+ const isEmptyTextBlock = parent.isTextblock
75
+ && !parent.type.spec.code
76
+ && !parent.childCount
70
77
 
71
78
  if (isEmptyTextBlock) {
72
79
  from -= 1
@@ -0,0 +1,15 @@
1
+ import { AnyExtension, EnableRules } from '../types'
2
+
3
+ export default function isExtensionRulesEnabled(extension: AnyExtension, enabled: EnableRules): boolean {
4
+ if (Array.isArray(enabled)) {
5
+ return enabled.some(enabledExtension => {
6
+ const name = typeof enabledExtension === 'string'
7
+ ? enabledExtension
8
+ : enabledExtension.name
9
+
10
+ return name === extension.name
11
+ })
12
+ }
13
+
14
+ return enabled
15
+ }
package/src/types.ts CHANGED
@@ -63,6 +63,8 @@ export interface EditorEvents {
63
63
  destroy: void,
64
64
  }
65
65
 
66
+ export type EnableRules = (AnyExtension | string)[] | boolean
67
+
66
68
  export interface EditorOptions {
67
69
  element: Element,
68
70
  content: Content,
@@ -72,8 +74,8 @@ export interface EditorOptions {
72
74
  editable: boolean,
73
75
  editorProps: EditorProps,
74
76
  parseOptions: ParseOptions,
75
- enableInputRules: boolean,
76
- enablePasteRules: boolean,
77
+ enableInputRules: EnableRules,
78
+ enablePasteRules: EnableRules,
77
79
  enableCoreExtensions: boolean,
78
80
  onBeforeCreate: (props: EditorEvents['beforeCreate']) => void,
79
81
  onCreate: (props: EditorEvents['create']) => void,