Merge branch 'main' of github.com:ueberdosis/tiptap-next into main
This commit is contained in:
@@ -1,10 +1,17 @@
|
|||||||
// @ts-nocheck
|
|
||||||
import { Plugin, PluginKey } from 'prosemirror-state'
|
import { Plugin, PluginKey } from 'prosemirror-state'
|
||||||
import { AnnotationState } from './AnnotationState'
|
import { AnnotationState } from './AnnotationState'
|
||||||
|
|
||||||
export const AnnotationPluginKey = new PluginKey('annotation')
|
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,
|
key: AnnotationPluginKey,
|
||||||
state: {
|
state: {
|
||||||
init(_, state) {
|
init(_, state) {
|
||||||
|
|||||||
@@ -11,6 +11,18 @@ export interface AnnotationOptions {
|
|||||||
[key: string]: any
|
[key: string]: any
|
||||||
},
|
},
|
||||||
onUpdate: (items: [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({
|
export const Annotation = Extension.create({
|
||||||
@@ -21,6 +33,9 @@ export const Annotation = Extension.create({
|
|||||||
class: 'annotation',
|
class: 'annotation',
|
||||||
},
|
},
|
||||||
onUpdate: decorations => decorations,
|
onUpdate: decorations => decorations,
|
||||||
|
document: null,
|
||||||
|
field: 'annotations',
|
||||||
|
map: null,
|
||||||
},
|
},
|
||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
@@ -57,8 +72,16 @@ export const Annotation = Extension.create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addProseMirrorPlugins() {
|
addProseMirrorPlugins() {
|
||||||
|
const map = this.options.map
|
||||||
|
? this.options.map
|
||||||
|
: this.options.document.getMap(this.options.field)
|
||||||
|
|
||||||
return [
|
return [
|
||||||
AnnotationPlugin(this.options),
|
AnnotationPlugin({
|
||||||
|
HTMLAttributes: this.options.HTMLAttributes,
|
||||||
|
onUpdate: this.options.onUpdate,
|
||||||
|
map,
|
||||||
|
}),
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ export default {
|
|||||||
Bold,
|
Bold,
|
||||||
Heading,
|
Heading,
|
||||||
Annotation.configure({
|
Annotation.configure({
|
||||||
|
document: this.ydoc,
|
||||||
onUpdate: items => { this.comments = items },
|
onUpdate: items => { this.comments = items },
|
||||||
}),
|
}),
|
||||||
Collaboration.configure({
|
Collaboration.configure({
|
||||||
@@ -91,7 +92,9 @@ export default {
|
|||||||
Text,
|
Text,
|
||||||
Bold,
|
Bold,
|
||||||
Heading,
|
Heading,
|
||||||
Annotation,
|
Annotation.configure({
|
||||||
|
document: this.ydoc,
|
||||||
|
}),
|
||||||
Collaboration.configure({
|
Collaboration.configure({
|
||||||
document: this.ydoc,
|
document: this.ydoc,
|
||||||
}),
|
}),
|
||||||
@@ -123,6 +126,7 @@ export default {
|
|||||||
|
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.editor.destroy()
|
this.editor.destroy()
|
||||||
|
this.anotherEditor.destroy()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user