Add isEmpty extension to remove on:content event from collaborator editor (#3774)

* Add validation extension to remove on content event from collaborator editor

Signed-off-by: Anna No <anna.no@xored.com>

* Add validation extension to remove on content event from collaborator editor

Signed-off-by: Anna No <anna.no@xored.com>

* Add validation extension to remove on content event from collaborator editor

Signed-off-by: Anna No <anna.no@xored.com>

* Add isEmpty extension to remove on:content event from collaborator editor

Signed-off-by: Anna No <anna.no@xored.com>

* Add isEmpty extension to remove on:content event from collaborator editor

Signed-off-by: Anna No <anna.no@xored.com>

* Add isEmpty extension to remove on:content event from collaborator editor

Signed-off-by: Anna No <anna.no@xored.com>

* Add isEmpty extension to remove on:content event from collaborator editor

Signed-off-by: Anna No <anna.no@xored.com>

---------

Signed-off-by: Anna No <anna.no@xored.com>
This commit is contained in:
Anna No 2023-10-02 22:18:11 +07:00 committed by GitHub
parent 56f0dc573d
commit 152c858c1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,34 @@
import { Extension } from '@tiptap/core'
export interface IsEmptyContentOptions {
onChange: (isEmpty: boolean) => void
}
export interface IsEmptyContentStorage {
isEmpty: boolean
}
export const IsEmptyContentExtension: Extension<IsEmptyContentOptions, IsEmptyContentStorage> =
Extension.create<IsEmptyContentOptions>({
name: 'is-empty-content-extension',
addStorage () {
return {
isEmpty: true
}
},
onCreate () {
this.parent?.()
this.storage.isEmpty = this.editor.isEmpty
this.options.onChange(this.storage.isEmpty)
},
onUpdate () {
this.parent?.()
if (this.storage.isEmpty !== this.editor.isEmpty) {
this.storage.isEmpty = this.editor.isEmpty
this.options.onChange(this.storage.isEmpty)
}
}
})

View File

@ -31,6 +31,11 @@ export * from './types'
export { default as Collaboration } from './components/Collaboration.svelte'
export { default as StyleButton } from './components/StyleButton.svelte'
export {
IsEmptyContentExtension,
IsEmptyContentOptions,
IsEmptyContentStorage
} from './components/extension/isEmptyContent'
export {
NodeHighlightExtension,
NodeHighlightExtensionOptions,