mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 06:03:22 +08:00
Merge branch 'main' of github.com:ueberdosis/tiptap-next into main
This commit is contained in:
commit
e2c9148c4a
@ -1,10 +1,17 @@
|
||||
// @ts-nocheck
|
||||
import { Plugin, PluginKey } from 'prosemirror-state'
|
||||
import { AnnotationState } from './AnnotationState'
|
||||
|
||||
export const AnnotationPluginKey = new PluginKey('annotation')
|
||||
|
||||
export const AnnotationPlugin = (options: any) => new Plugin({
|
||||
export interface AnnotationPluginOptions {
|
||||
HTMLAttributes: {
|
||||
[key: string]: any
|
||||
},
|
||||
onUpdate: (items: [any?]) => {},
|
||||
map: any,
|
||||
}
|
||||
|
||||
export const AnnotationPlugin = (options: AnnotationPluginOptions) => new Plugin({
|
||||
key: AnnotationPluginKey,
|
||||
state: {
|
||||
init(_, state) {
|
||||
|
@ -11,6 +11,18 @@ export interface AnnotationOptions {
|
||||
[key: string]: any
|
||||
},
|
||||
onUpdate: (items: [any?]) => {},
|
||||
/**
|
||||
* An initialized Y.js document.
|
||||
*/
|
||||
document: any,
|
||||
/**
|
||||
* Name of a Y.js fragment, can be changed to sync multiple fields with one Y.js document.
|
||||
*/
|
||||
field: string,
|
||||
/**
|
||||
* A raw Y.js map, can be used instead of `document` and `field`.
|
||||
*/
|
||||
map: any,
|
||||
}
|
||||
|
||||
export const Annotation = Extension.create({
|
||||
@ -21,6 +33,9 @@ export const Annotation = Extension.create({
|
||||
class: 'annotation',
|
||||
},
|
||||
onUpdate: decorations => decorations,
|
||||
document: null,
|
||||
field: 'annotations',
|
||||
map: null,
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
@ -57,8 +72,16 @@ export const Annotation = Extension.create({
|
||||
},
|
||||
|
||||
addProseMirrorPlugins() {
|
||||
const map = this.options.map
|
||||
? this.options.map
|
||||
: this.options.document.getMap(this.options.field)
|
||||
|
||||
return [
|
||||
AnnotationPlugin(this.options),
|
||||
AnnotationPlugin({
|
||||
HTMLAttributes: this.options.HTMLAttributes,
|
||||
onUpdate: this.options.onUpdate,
|
||||
map,
|
||||
}),
|
||||
]
|
||||
},
|
||||
})
|
||||
|
@ -68,6 +68,7 @@ export default {
|
||||
Bold,
|
||||
Heading,
|
||||
Annotation.configure({
|
||||
document: this.ydoc,
|
||||
onUpdate: items => { this.comments = items },
|
||||
}),
|
||||
Collaboration.configure({
|
||||
@ -91,7 +92,9 @@ export default {
|
||||
Text,
|
||||
Bold,
|
||||
Heading,
|
||||
Annotation,
|
||||
Annotation.configure({
|
||||
document: this.ydoc,
|
||||
}),
|
||||
Collaboration.configure({
|
||||
document: this.ydoc,
|
||||
}),
|
||||
@ -123,6 +126,7 @@ export default {
|
||||
|
||||
beforeDestroy() {
|
||||
this.editor.destroy()
|
||||
this.anotherEditor.destroy()
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user