From c13db6bc8e83cdac0b231aa3b61b09d3d427ba7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Thu, 11 Feb 2021 22:48:04 +0100 Subject: [PATCH] add annotation options --- .../Annotation/extension/AnnotationPlugin.ts | 11 ++++++-- .../Annotation/extension/annotation.ts | 25 ++++++++++++++++++- docs/src/demos/Experiments/Comments/index.vue | 1 + 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/docs/src/demos/Experiments/Annotation/extension/AnnotationPlugin.ts b/docs/src/demos/Experiments/Annotation/extension/AnnotationPlugin.ts index 0806f534..29a382c4 100644 --- a/docs/src/demos/Experiments/Annotation/extension/AnnotationPlugin.ts +++ b/docs/src/demos/Experiments/Annotation/extension/AnnotationPlugin.ts @@ -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) { diff --git a/docs/src/demos/Experiments/Annotation/extension/annotation.ts b/docs/src/demos/Experiments/Annotation/extension/annotation.ts index 06c666b6..019e685d 100644 --- a/docs/src/demos/Experiments/Annotation/extension/annotation.ts +++ b/docs/src/demos/Experiments/Annotation/extension/annotation.ts @@ -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, + }), ] }, }) diff --git a/docs/src/demos/Experiments/Comments/index.vue b/docs/src/demos/Experiments/Comments/index.vue index c2388200..9945c558 100644 --- a/docs/src/demos/Experiments/Comments/index.vue +++ b/docs/src/demos/Experiments/Comments/index.vue @@ -74,6 +74,7 @@ export default { Bold, Heading, Annotation.configure({ + document: this.ydoc, onUpdate: items => { this.comments = items }, }), Collaboration.configure({