@tiptap/react 2.11.1 → 2.11.3
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.cjs +35 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -6
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +35 -6
- package/dist/index.umd.js.map +1 -1
- package/dist/useEditor.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/useEditor.ts +36 -6
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/react",
|
|
3
3
|
"description": "React components for tiptap",
|
|
4
|
-
"version": "2.11.
|
|
4
|
+
"version": "2.11.3",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@tiptap/extension-bubble-menu": "^2.11.
|
|
33
|
-
"@tiptap/extension-floating-menu": "^2.11.
|
|
32
|
+
"@tiptap/extension-bubble-menu": "^2.11.3",
|
|
33
|
+
"@tiptap/extension-floating-menu": "^2.11.3",
|
|
34
34
|
"@types/use-sync-external-store": "^0.0.6",
|
|
35
35
|
"fast-deep-equal": "^3",
|
|
36
36
|
"use-sync-external-store": "^1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@tiptap/core": "^2.11.
|
|
40
|
-
"@tiptap/pm": "^2.11.
|
|
39
|
+
"@tiptap/core": "^2.11.3",
|
|
40
|
+
"@tiptap/pm": "^2.11.3",
|
|
41
41
|
"@types/react": "^18.0.0",
|
|
42
42
|
"@types/react-dom": "^18.0.0",
|
|
43
43
|
"react": "^18.0.0",
|
package/src/useEditor.ts
CHANGED
|
@@ -184,6 +184,33 @@ class EditorInstanceManager {
|
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
static compareOptions(a: UseEditorOptions, b: UseEditorOptions) {
|
|
188
|
+
return (Object.keys(a) as (keyof UseEditorOptions)[]).every(key => {
|
|
189
|
+
if (['onCreate', 'onBeforeCreate', 'onDestroy', 'onUpdate', 'onTransaction', 'onFocus', 'onBlur', 'onSelectionUpdate', 'onContentError', 'onDrop', 'onPaste'].includes(key)) {
|
|
190
|
+
// we don't want to compare callbacks, they are always different and only registered once
|
|
191
|
+
return true
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// We often encourage putting extensions inlined in the options object, so we will do a slightly deeper comparison here
|
|
195
|
+
if (key === 'extensions' && a.extensions && b.extensions) {
|
|
196
|
+
if (a.extensions.length !== b.extensions.length) {
|
|
197
|
+
return false
|
|
198
|
+
}
|
|
199
|
+
return a.extensions.every((extension, index) => {
|
|
200
|
+
if (extension !== b.extensions?.[index]) {
|
|
201
|
+
return false
|
|
202
|
+
}
|
|
203
|
+
return true
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
if (a[key] !== b[key]) {
|
|
207
|
+
// if any of the options have changed, we should update the editor options
|
|
208
|
+
return false
|
|
209
|
+
}
|
|
210
|
+
return true
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
|
|
187
214
|
/**
|
|
188
215
|
* On each render, we will create, update, or destroy the editor instance.
|
|
189
216
|
* @param deps The dependencies to watch for changes
|
|
@@ -197,12 +224,15 @@ class EditorInstanceManager {
|
|
|
197
224
|
clearTimeout(this.scheduledDestructionTimeout)
|
|
198
225
|
|
|
199
226
|
if (this.editor && !this.editor.isDestroyed && deps.length === 0) {
|
|
200
|
-
// if the editor does exist & deps are empty, we don't need to re-initialize the editor
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
227
|
+
// if the editor does exist & deps are empty, we don't need to re-initialize the editor generally
|
|
228
|
+
if (!EditorInstanceManager.compareOptions(this.options.current, this.editor.options)) {
|
|
229
|
+
// But, the options are different, so we need to update the editor options
|
|
230
|
+
// Still, this is faster than re-creating the editor
|
|
231
|
+
this.editor.setOptions({
|
|
232
|
+
...this.options.current,
|
|
233
|
+
editable: this.editor.isEditable,
|
|
234
|
+
})
|
|
235
|
+
}
|
|
206
236
|
} else {
|
|
207
237
|
// When the editor:
|
|
208
238
|
// - does not yet exist
|