annotations: rename content to data
This commit is contained in:
@@ -17,8 +17,8 @@ export class AnnotationItem {
|
|||||||
return this.decoration.to
|
return this.decoration.to
|
||||||
}
|
}
|
||||||
|
|
||||||
get content() {
|
get data() {
|
||||||
return this.decoration.type.spec.content
|
return this.decoration.type.spec.data
|
||||||
}
|
}
|
||||||
|
|
||||||
get HTMLAttributes() {
|
get HTMLAttributes() {
|
||||||
@@ -28,7 +28,7 @@ export class AnnotationItem {
|
|||||||
toString() {
|
toString() {
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
id: this.id,
|
id: this.id,
|
||||||
content: this.content,
|
data: this.data,
|
||||||
from: this.from,
|
from: this.from,
|
||||||
to: this.to,
|
to: this.to,
|
||||||
HTMLAttributes: this.HTMLAttributes,
|
HTMLAttributes: this.HTMLAttributes,
|
||||||
|
|||||||
@@ -41,14 +41,14 @@ export class AnnotationState {
|
|||||||
const ystate = ySyncPluginKey.getState(state)
|
const ystate = ySyncPluginKey.getState(state)
|
||||||
const { type, binding } = ystate
|
const { type, binding } = ystate
|
||||||
const { map } = this.options
|
const { map } = this.options
|
||||||
const { from, to, content } = action
|
const { from, to, data } = action
|
||||||
const absoluteFrom = absolutePositionToRelativePosition(from, type, binding.mapping)
|
const absoluteFrom = absolutePositionToRelativePosition(from, type, binding.mapping)
|
||||||
const absoluteTo = absolutePositionToRelativePosition(to, type, binding.mapping)
|
const absoluteTo = absolutePositionToRelativePosition(to, type, binding.mapping)
|
||||||
|
|
||||||
map.set(this.randomId(), {
|
map.set(this.randomId(), {
|
||||||
from: absoluteFrom,
|
from: absoluteFrom,
|
||||||
to: absoluteTo,
|
to: absoluteTo,
|
||||||
content,
|
data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,16 +73,16 @@ export class AnnotationState {
|
|||||||
Array
|
Array
|
||||||
.from(map.keys())
|
.from(map.keys())
|
||||||
.forEach(id => {
|
.forEach(id => {
|
||||||
const decoration = map.get(id)
|
const annotation = map.get(id)
|
||||||
const from = relativePositionToAbsolutePosition(doc, type, decoration.from, binding.mapping)
|
const from = relativePositionToAbsolutePosition(doc, type, annotation.from, binding.mapping)
|
||||||
const to = relativePositionToAbsolutePosition(doc, type, decoration.to, binding.mapping)
|
const to = relativePositionToAbsolutePosition(doc, type, annotation.to, binding.mapping)
|
||||||
|
|
||||||
if (!from || !to) {
|
if (!from || !to) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return decorations.push(
|
return decorations.push(
|
||||||
Decoration.inline(from, to, HTMLAttributes, { id, content: decoration.content }),
|
Decoration.inline(from, to, HTMLAttributes, { id, data: annotation.data }),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { AnnotationPlugin, AnnotationPluginKey } from './AnnotationPlugin'
|
|||||||
|
|
||||||
export interface AddAnnotationAction {
|
export interface AddAnnotationAction {
|
||||||
type: 'addAnnotation',
|
type: 'addAnnotation',
|
||||||
content: any,
|
data: any,
|
||||||
from: number,
|
from: number,
|
||||||
to: number,
|
to: number,
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@ export interface AddAnnotationAction {
|
|||||||
export interface UpdateAnnotationAction {
|
export interface UpdateAnnotationAction {
|
||||||
type: 'updateAnnotation',
|
type: 'updateAnnotation',
|
||||||
id: string,
|
id: string,
|
||||||
content: any,
|
data: any,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeleteAnnotationAction {
|
export interface DeleteAnnotationAction {
|
||||||
@@ -77,29 +77,29 @@ export const Annotation = Extension.create({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
addAnnotation: (content: any): Command => ({ dispatch, state }) => {
|
addAnnotation: (data: any): Command => ({ dispatch, state }) => {
|
||||||
const { selection } = state
|
const { selection } = state
|
||||||
|
|
||||||
if (selection.empty) {
|
if (selection.empty) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dispatch && content) {
|
if (dispatch && data) {
|
||||||
state.tr.setMeta(AnnotationPluginKey, <AddAnnotationAction>{
|
state.tr.setMeta(AnnotationPluginKey, <AddAnnotationAction>{
|
||||||
type: 'addAnnotation',
|
type: 'addAnnotation',
|
||||||
from: selection.from,
|
from: selection.from,
|
||||||
to: selection.to,
|
to: selection.to,
|
||||||
content,
|
data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
updateAnnotation: (id: string, content: any): Command => ({ dispatch, state }) => {
|
updateAnnotation: (id: string, data: any): Command => ({ dispatch, state }) => {
|
||||||
if (dispatch) {
|
if (dispatch) {
|
||||||
state.tr.setMeta(AnnotationPluginKey, <UpdateAnnotationAction>{
|
state.tr.setMeta(AnnotationPluginKey, <UpdateAnnotationAction>{
|
||||||
type: 'updateAnnotation',
|
type: 'updateAnnotation',
|
||||||
content,
|
data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,26 +103,26 @@ export default {
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
addComment() {
|
addComment() {
|
||||||
const content = prompt('Comment', '')
|
const data = prompt('Comment', '')
|
||||||
|
|
||||||
this.editor.commands.addAnnotation(content)
|
this.editor.commands.addAnnotation(data)
|
||||||
},
|
},
|
||||||
updateComment(id) {
|
updateComment(id) {
|
||||||
const comment = this.comments.find(item => {
|
const comment = this.comments.find(item => {
|
||||||
return id === item.id
|
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) {
|
deleteComment(id) {
|
||||||
this.editor.commands.deleteAnnotation(id)
|
this.editor.commands.deleteAnnotation(id)
|
||||||
},
|
},
|
||||||
addAnotherComment() {
|
addAnotherComment() {
|
||||||
const content = prompt('Comment', '')
|
const data = prompt('Comment', '')
|
||||||
|
|
||||||
this.anotherEditor.commands.addAnnotation(content)
|
this.anotherEditor.commands.addAnnotation(data)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user