Merge branch 'main' of github.com:ueberdosis/tiptap-next into main

This commit is contained in:
Hans Pagel 2021-02-11 23:11:01 +01:00
commit e2c9148c4a
3 changed files with 38 additions and 4 deletions

View File

@ -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) {

View File

@ -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,
}),
]
},
})

View File

@ -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>