Skip to content

Commit d4363e3

Browse files
authored
Merge pull request #7121 from ueberdosis/hotfix/add-option-to-disable-unique-id-document-updates-cherrypick
Cherry-pick: Add `updateDocument` option to disable document updates caused by the Unique ID extension.
2 parents d7543db + 1df8901 commit d4363e3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

.changeset/nine-eyes-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tiptap/extension-unique-id': minor
3+
---
4+
5+
Add `updateDocument` option to disable document updates caused by the Unique ID extension.

packages/extension-unique-id/src/unique-id.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ export interface UniqueIDOptions {
3535
* @default null
3636
*/
3737
filterTransaction: ((transaction: Transaction) => boolean) | null
38+
/**
39+
* Whether to update the document by adding unique IDs to the nodes. Set this
40+
* property to `false` if the document is in `readonly` mode, is immutable, or
41+
* you don't want it to be modified.
42+
*
43+
* @default true
44+
*/
45+
updateDocument: boolean
3846
}
3947

4048
export const UniqueID = Extension.create<UniqueIDOptions>({
@@ -50,6 +58,7 @@ export const UniqueID = Extension.create<UniqueIDOptions>({
5058
types: [],
5159
generateID: () => uuidv4(),
5260
filterTransaction: null,
61+
updateDocument: true,
5362
}
5463
},
5564

@@ -78,6 +87,10 @@ export const UniqueID = Extension.create<UniqueIDOptions>({
7887

7988
// check initial content for missing ids
8089
onCreate() {
90+
if (!this.options.updateDocument) {
91+
return
92+
}
93+
8194
const collaboration = this.editor.extensionManager.extensions.find(ext => ext.name === 'collaboration')
8295
const collaborationCaret = this.editor.extensionManager.extensions.find(ext => ext.name === 'collaborationCaret')
8396

@@ -126,6 +139,10 @@ export const UniqueID = Extension.create<UniqueIDOptions>({
126139
},
127140

128141
addProseMirrorPlugins() {
142+
if (!this.options.updateDocument) {
143+
return []
144+
}
145+
129146
let dragSourceElement: Element | null = null
130147
let transformPasted = false
131148

0 commit comments

Comments
 (0)