@tiptap/core 2.0.0-beta.90 → 2.0.0-beta.94

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.90",
4
+ "version": "2.0.0-beta.94",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -45,5 +45,5 @@
45
45
  "url": "https://github.com/ueberdosis/tiptap",
46
46
  "directory": "packages/core"
47
47
  },
48
- "gitHead": "c3d04cef604564c2159b0c28703bb0247d3d9bee"
48
+ "gitHead": "937f6a1682f586a2ee9761d1630acc90eb505a09"
49
49
  }
package/src/Editor.ts CHANGED
@@ -132,7 +132,20 @@ export class Editor extends EventEmitter {
132
132
  * @param options A list of options
133
133
  */
134
134
  public setOptions(options: Partial<EditorOptions> = {}): void {
135
- this.options = { ...this.options, ...options }
135
+ this.options = {
136
+ ...this.options,
137
+ ...options,
138
+ }
139
+
140
+ if (!this.view || !this.state || this.isDestroyed) {
141
+ return
142
+ }
143
+
144
+ if (this.options.editorProps) {
145
+ this.view.setProps(this.options.editorProps)
146
+ }
147
+
148
+ this.view.updateState(this.state)
136
149
  }
137
150
 
138
151
  /**
@@ -140,17 +153,18 @@ export class Editor extends EventEmitter {
140
153
  */
141
154
  public setEditable(editable: boolean): void {
142
155
  this.setOptions({ editable })
143
-
144
- if (this.view && this.state && !this.isDestroyed) {
145
- this.view.updateState(this.state)
146
- }
147
156
  }
148
157
 
149
158
  /**
150
159
  * Returns whether the editor is editable.
151
160
  */
152
161
  public get isEditable(): boolean {
153
- return this.view && this.view.editable
162
+ // since plugins are applied after creating the view
163
+ // `editable` is always `true` for one tick.
164
+ // that’s why we also have to check for `options.editable`
165
+ return this.options.editable
166
+ && this.view
167
+ && this.view.editable
154
168
  }
155
169
 
156
170
  /**
@@ -1,3 +1,4 @@
1
+ import { CreateNodeFromContentOptions } from '../helpers/createNodeFromContent'
1
2
  import { RawCommands, Content } from '../types'
2
3
 
3
4
  declare module '@tiptap/core' {
@@ -6,11 +7,11 @@ declare module '@tiptap/core' {
6
7
  /**
7
8
  * Insert a node or string of HTML at the current position.
8
9
  */
9
- insertContent: (value: Content) => ReturnType,
10
+ insertContent: (value: Content, options?: CreateNodeFromContentOptions) => ReturnType,
10
11
  }
11
12
  }
12
13
  }
13
14
 
14
- export const insertContent: RawCommands['insertContent'] = value => ({ tr, commands }) => {
15
- return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value)
15
+ export const insertContent: RawCommands['insertContent'] = (value, options) => ({ tr, commands }) => {
16
+ return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options)
16
17
  }
@@ -1,4 +1,4 @@
1
- import createNodeFromContent from '../helpers/createNodeFromContent'
1
+ import createNodeFromContent, { CreateNodeFromContentOptions } from '../helpers/createNodeFromContent'
2
2
  import selectionToInsertionEnd from '../helpers/selectionToInsertionEnd'
3
3
  import {
4
4
  RawCommands,
@@ -12,17 +12,18 @@ declare module '@tiptap/core' {
12
12
  /**
13
13
  * Insert a node or string of HTML at a specific position.
14
14
  */
15
- insertContentAt: (position: number | Range, value: Content) => ReturnType,
15
+ insertContentAt: (position: number | Range, value: Content, options?: CreateNodeFromContentOptions) => ReturnType,
16
16
  }
17
17
  }
18
18
  }
19
19
 
20
- export const insertContentAt: RawCommands['insertContentAt'] = (position, value) => ({ tr, dispatch, editor }) => {
20
+ export const insertContentAt: RawCommands['insertContentAt'] = (position, value, options) => ({ tr, dispatch, editor }) => {
21
21
  if (dispatch) {
22
22
  const content = createNodeFromContent(value, editor.schema, {
23
23
  parseOptions: {
24
24
  preserveWhitespace: 'full',
25
25
  },
26
+ ...(options || {}),
26
27
  })
27
28
 
28
29
  // don’t dispatch an empty fragment because this can lead to strange errors
@@ -35,7 +35,7 @@ export default function (
35
35
  ? getAttributes(match)
36
36
  : getAttributes
37
37
 
38
- if (!attrs) {
38
+ if (!attrs && attrs !== undefined) {
39
39
  continue
40
40
  }
41
41