From 8b5dfe7c1cbf7a297abae109a3ec9b8ea67df4c8 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Fri, 12 Feb 2021 10:36:58 +0100 Subject: [PATCH 1/3] annotations: update comments --- .../Experiments/Annotation/extension/AnnotationState.ts | 7 +++++-- .../demos/Experiments/Annotation/extension/annotation.ts | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts b/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts index 45c4073aa..41d5d3192 100644 --- a/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts +++ b/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts @@ -89,7 +89,7 @@ export class AnnotationState { } apply(transaction: Transaction, state: EditorState) { - const ystate = ySyncPluginKey.getState(state) + // Add/Remove annotations const action = transaction.getMeta(AnnotationPluginKey) as AddAnnotationAction | DeleteAnnotationAction if (action && action.type) { @@ -104,13 +104,16 @@ export class AnnotationState { return this } + // Use Y.js to update positions + const ystate = ySyncPluginKey.getState(state) + if (ystate.isChangeOrigin) { this.updateDecorations(state) return this } - // Apply ProseMirror mapping + // Use ProseMirror to update positions this.decorations = this.decorations.map(transaction.mapping, transaction.doc) return this diff --git a/docs/src/demos/Experiments/Annotation/extension/annotation.ts b/docs/src/demos/Experiments/Annotation/extension/annotation.ts index 7a6c92c04..47e2905ad 100644 --- a/docs/src/demos/Experiments/Annotation/extension/annotation.ts +++ b/docs/src/demos/Experiments/Annotation/extension/annotation.ts @@ -4,6 +4,7 @@ import { AnnotationItem } from './AnnotationItem' import { AnnotationPlugin, AnnotationPluginKey } from './AnnotationPlugin' function randomId() { + // TODO: That seems … to simple. return Math.floor(Math.random() * 0xffffffff) } @@ -23,13 +24,16 @@ export interface AnnotationOptions { HTMLAttributes: { [key: string]: any }, + /** + * An event listener which receives annotations for the current selection. + */ onUpdate: (items: [any?]) => {}, /** * An initialized Y.js document. */ document: Y.Doc | null, /** - * Name of a Y.js fragment, can be changed to sync multiple fields with one Y.js document. + * Name of a Y.js map, can be changed to sync multiple fields with one Y.js document. */ field: string, /** From 39365c77cbf8ee81f766a3fe4e3081be7998cd01 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Fri, 12 Feb 2021 10:45:41 +0100 Subject: [PATCH 2/3] annotations: remove comment --- .../demos/Experiments/Annotation/extension/AnnotationState.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts b/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts index 6f302127b..af8c7f72d 100644 --- a/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts +++ b/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts @@ -27,9 +27,6 @@ export class AnnotationState { } findAnnotation(id: string) { - // TODO: Get from Y.js? - // this.decorations.get(id) - const current = this.decorations.find() for (let i = 0; i < current.length; i += 1) { From 0697efef30476076efa90af2f5cb62bec58ec419 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Fri, 12 Feb 2021 10:50:21 +0100 Subject: [PATCH 3/3] annotations: refactoring --- .../Experiments/Annotation/extension/AnnotationItem.ts | 6 +++--- .../Experiments/Annotation/extension/AnnotationState.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/src/demos/Experiments/Annotation/extension/AnnotationItem.ts b/docs/src/demos/Experiments/Annotation/extension/AnnotationItem.ts index 8885247c8..f0f0aba46 100644 --- a/docs/src/demos/Experiments/Annotation/extension/AnnotationItem.ts +++ b/docs/src/demos/Experiments/Annotation/extension/AnnotationItem.ts @@ -1,10 +1,10 @@ export class AnnotationItem { public id!: string - public text!: string + public content!: string - constructor(id: string, text: string) { + constructor(id: string, content: string) { this.id = id - this.text = text + this.content = content } } diff --git a/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts b/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts index af8c7f72d..62a53621b 100644 --- a/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts +++ b/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts @@ -69,7 +69,7 @@ export class AnnotationState { } annotationsAt(position: number) { - return this.decorations?.find(position, position) + return this.decorations.find(position, position) } updateDecorations(state: EditorState) { @@ -89,9 +89,9 @@ export class AnnotationState { return } - const decoration = Decoration.inline(from, to, HTMLAttributes, { data: dec.data }) - - return decorations.push(decoration) + return decorations.push( + Decoration.inline(from, to, HTMLAttributes, { data: dec.data }), + ) }) this.decorations = DecorationSet.create(state.doc, decorations)