annotations: rename content to data

This commit is contained in:
Hans Pagel 2021-02-12 13:29:12 +01:00
parent b7f25e131c
commit 370d8deff7
4 changed files with 22 additions and 22 deletions

View File

@ -17,8 +17,8 @@ export class AnnotationItem {
return this.decoration.to
}
get content() {
return this.decoration.type.spec.content
get data() {
return this.decoration.type.spec.data
}
get HTMLAttributes() {
@ -28,7 +28,7 @@ export class AnnotationItem {
toString() {
return JSON.stringify({
id: this.id,
content: this.content,
data: this.data,
from: this.from,
to: this.to,
HTMLAttributes: this.HTMLAttributes,

View File

@ -41,14 +41,14 @@ export class AnnotationState {
const ystate = ySyncPluginKey.getState(state)
const { type, binding } = ystate
const { map } = this.options
const { from, to, content } = action
const { from, to, data } = action
const absoluteFrom = absolutePositionToRelativePosition(from, type, binding.mapping)
const absoluteTo = absolutePositionToRelativePosition(to, type, binding.mapping)
map.set(this.randomId(), {
from: absoluteFrom,
to: absoluteTo,
content,
data,
})
}
@ -73,16 +73,16 @@ export class AnnotationState {
Array
.from(map.keys())
.forEach(id => {
const decoration = map.get(id)
const from = relativePositionToAbsolutePosition(doc, type, decoration.from, binding.mapping)
const to = relativePositionToAbsolutePosition(doc, type, decoration.to, binding.mapping)
const annotation = map.get(id)
const from = relativePositionToAbsolutePosition(doc, type, annotation.from, binding.mapping)
const to = relativePositionToAbsolutePosition(doc, type, annotation.to, binding.mapping)
if (!from || !to) {
return
}
return decorations.push(
Decoration.inline(from, to, HTMLAttributes, { id, content: decoration.content }),
Decoration.inline(from, to, HTMLAttributes, { id, data: annotation.data }),
)
})

View File

@ -4,7 +4,7 @@ import { AnnotationPlugin, AnnotationPluginKey } from './AnnotationPlugin'
export interface AddAnnotationAction {
type: 'addAnnotation',
content: any,
data: any,
from: number,
to: number,
}
@ -12,7 +12,7 @@ export interface AddAnnotationAction {
export interface UpdateAnnotationAction {
type: 'updateAnnotation',
id: string,
content: any,
data: any,
}
export interface DeleteAnnotationAction {
@ -77,29 +77,29 @@ export const Annotation = Extension.create({
addCommands() {
return {
addAnnotation: (content: any): Command => ({ dispatch, state }) => {
addAnnotation: (data: any): Command => ({ dispatch, state }) => {
const { selection } = state
if (selection.empty) {
return false
}
if (dispatch && content) {
if (dispatch && data) {
state.tr.setMeta(AnnotationPluginKey, <AddAnnotationAction>{
type: 'addAnnotation',
from: selection.from,
to: selection.to,
content,
data,
})
}
return true
},
updateAnnotation: (id: string, content: any): Command => ({ dispatch, state }) => {
updateAnnotation: (id: string, data: any): Command => ({ dispatch, state }) => {
if (dispatch) {
state.tr.setMeta(AnnotationPluginKey, <UpdateAnnotationAction>{
type: 'updateAnnotation',
content,
data,
})
}

View File

@ -103,26 +103,26 @@ export default {
methods: {
addComment() {
const content = prompt('Comment', '')
const data = prompt('Comment', '')
this.editor.commands.addAnnotation(content)
this.editor.commands.addAnnotation(data)
},
updateComment(id) {
const comment = this.comments.find(item => {
return id === item.id
})
const content = prompt('Comment', comment.content)
const data = prompt('Comment', comment.data)
this.editor.commands.updateAnnotation(id, content)
this.editor.commands.updateAnnotation(id, data)
},
deleteComment(id) {
this.editor.commands.deleteAnnotation(id)
},
addAnotherComment() {
const content = prompt('Comment', '')
const data = prompt('Comment', '')
this.anotherEditor.commands.addAnnotation(content)
this.anotherEditor.commands.addAnnotation(data)
},
},