mirror of
https://github.com/cudr/slate-collaborative.git
synced 2026-03-02 03:40:18 +00:00
feat: set_annotation temporary disabled
This commit is contained in:
@@ -17,18 +17,21 @@ const AnnotationSetOp = ({ key, value }: Automerge.Diff) => (map, doc) => {
|
||||
|
||||
let op
|
||||
|
||||
if (!doc.annotations[key]) {
|
||||
op = {
|
||||
type: 'add_annotation',
|
||||
annotation: map[value]
|
||||
}
|
||||
} else {
|
||||
op = {
|
||||
type: 'set_annotation',
|
||||
properties: doc.annotations[key],
|
||||
newProperties: map[value]
|
||||
}
|
||||
/**
|
||||
* Looks like set_annotation option is broken, temporary disabled
|
||||
*/
|
||||
// if (!doc.annotations[key]) {
|
||||
op = {
|
||||
type: 'add_annotation',
|
||||
annotation: map[value]
|
||||
}
|
||||
// } else {
|
||||
// op = {
|
||||
// type: 'set_annotation',
|
||||
// properties: toJS(doc.annotations[key]),
|
||||
// newProperties: map[value]
|
||||
// }
|
||||
// }
|
||||
|
||||
console.log('opSET!!', key, map[value], op)
|
||||
|
||||
|
||||
@@ -3,10 +3,7 @@ import { toJS } from '../utils'
|
||||
import { Operation } from 'slate'
|
||||
import { List } from 'immutable'
|
||||
|
||||
export const setCursor = (
|
||||
doc,
|
||||
{ id, selection, selectionOps, annotationType }
|
||||
) => {
|
||||
export const setCursor = (doc, { id, selection, annotationType }) => {
|
||||
if (!doc.annotations) {
|
||||
doc.annotations = {}
|
||||
}
|
||||
@@ -21,38 +18,31 @@ export const setCursor = (
|
||||
|
||||
const annotation = toJS(doc.annotations[id])
|
||||
|
||||
if (selectionOps.size) {
|
||||
selectionOps.forEach(op => {
|
||||
const { newProperties } = op.toJSON()
|
||||
// if (selectionOps.size) {
|
||||
// selectionOps.forEach(op => {
|
||||
// const { newProperties } = op.toJSON()
|
||||
|
||||
if (newProperties.focus) annotation.focus = newProperties.focus
|
||||
if (newProperties.anchor) annotation.anchor = newProperties.anchor
|
||||
if (newProperties.data) annotation.data = newProperties.data
|
||||
})
|
||||
}
|
||||
// if (newProperties.focus) annotation.focus = newProperties.focus
|
||||
// if (newProperties.anchor) annotation.anchor = newProperties.anchor
|
||||
// if (newProperties.data) annotation.data = newProperties.data
|
||||
// })
|
||||
// }
|
||||
|
||||
const cursorStart = annotation.anchor && annotation.anchor.offset
|
||||
const cursorEnd = annotation.focus && annotation.focus.offset
|
||||
// console.log('cursor!!', cursorStart, cursorEnd)
|
||||
// console.log(
|
||||
// 'selection!!',
|
||||
// selection.toJSON(),
|
||||
// selection.start.offset,
|
||||
// selection.end.offset
|
||||
// )
|
||||
|
||||
console.log('cursor!!', cursorStart, cursorEnd)
|
||||
console.log(
|
||||
'selection!!',
|
||||
annotation,
|
||||
selection.start.offset,
|
||||
selection.end.offset
|
||||
)
|
||||
|
||||
if (selection.start.offset !== cursorStart) {
|
||||
annotation.focus = selection.end.toJS() || {}
|
||||
}
|
||||
|
||||
if (selection.end.offset !== cursorEnd) {
|
||||
annotation.anchor = selection.start.toJS() || {}
|
||||
}
|
||||
annotation.focus = selection.end.toJSON() || {}
|
||||
annotation.anchor = selection.start.toJSON() || {}
|
||||
|
||||
annotation.data.isBackward = selection.isBackward
|
||||
|
||||
console.log('setted cursor', annotation, toJS(doc))
|
||||
annotation.data.targetPath = selection.isBackward
|
||||
? annotation.anchor.path
|
||||
: annotation.focus.path
|
||||
|
||||
doc.annotations[id] = annotation
|
||||
|
||||
@@ -60,7 +50,7 @@ export const setCursor = (
|
||||
}
|
||||
|
||||
export const removeCursor = (doc, { id }) => {
|
||||
console.log('!!!removeCursor', doc, id)
|
||||
// console.log('!!!removeCursor', doc, id)
|
||||
if (doc.annotations && doc.annotations[id]) {
|
||||
delete doc.annotations[id]
|
||||
}
|
||||
@@ -68,20 +58,18 @@ export const removeCursor = (doc, { id }) => {
|
||||
return doc
|
||||
}
|
||||
|
||||
export const cursorOpFilter = (doc, ops: List<Operation>) =>
|
||||
export const cursorOpFilter = (ops: List<Operation>, annotationType) =>
|
||||
ops.filter(op => {
|
||||
const { annotations } = doc
|
||||
|
||||
if (op.type === 'set_annotation') {
|
||||
return !(
|
||||
(op.properties && annotations[op.properties.key]) ||
|
||||
(op.newProperties && annotations[op.newProperties.key])
|
||||
(op.properties && op.properties.type === annotationType) ||
|
||||
(op.newProperties && op.newProperties.type === annotationType)
|
||||
)
|
||||
} else if (
|
||||
op.type === 'add_annotation' ||
|
||||
op.type === 'remove_annotation'
|
||||
) {
|
||||
return !annotations[op.annotation.key]
|
||||
return op.annotation.type !== annotationType
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user