mirror of
https://github.com/cudr/slate-collaborative.git
synced 2026-03-02 03:40:18 +00:00
feat: success show cursor position
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import { Operation, SyncDoc } from '../model'
|
||||
|
||||
export const addAnnotation = (doc: SyncDoc, op: Operation): SyncDoc => {
|
||||
console.log('addAnnotation!!!', op)
|
||||
console.log('addAnnotation!!!', op.toJS())
|
||||
return doc
|
||||
}
|
||||
|
||||
export const removeAnnotation = (doc: SyncDoc, op: Operation): SyncDoc => {
|
||||
console.log('removeAnnotation!!!', op)
|
||||
console.log('removeAnnotation!!!', op.toJS())
|
||||
return doc
|
||||
}
|
||||
|
||||
export const setAnnotation = (doc: SyncDoc, op: Operation): SyncDoc => {
|
||||
console.log('setAnnotation!!!', op)
|
||||
console.log('setAnnotation!!!', op.toJS())
|
||||
return doc
|
||||
}
|
||||
|
||||
|
||||
@@ -3,43 +3,19 @@ import { Operation, Operations, SyncDoc } from '../model'
|
||||
import node from './node'
|
||||
import mark from './mark'
|
||||
import text from './text'
|
||||
import selection from './selection'
|
||||
import annotation from './annotation'
|
||||
|
||||
const setSelection = (doc, op, { id, selection }) => {
|
||||
console.log('selection', selection.toJSON())
|
||||
if (!doc.cursors) {
|
||||
doc.cursors = {}
|
||||
}
|
||||
|
||||
// console.log('setSelection', op.toJSON(), id)
|
||||
const operation = op.toJSON()
|
||||
|
||||
if (!doc.cursors[id]) {
|
||||
doc.cursors[id] = {
|
||||
key: id,
|
||||
type: 'collaborative_selection'
|
||||
}
|
||||
}
|
||||
|
||||
const cursor = doc.cursors[id]
|
||||
const { focus, anchor } = operation.newProperties
|
||||
|
||||
if (focus) cursor.focus = focus
|
||||
if (anchor) cursor.anchor = anchor
|
||||
|
||||
return doc
|
||||
}
|
||||
|
||||
const setValue = (doc, op) => doc
|
||||
const setSelection = doc => doc
|
||||
const setValue = doc => doc
|
||||
|
||||
const opType: any = {
|
||||
...text,
|
||||
...annotation,
|
||||
...node,
|
||||
...mark,
|
||||
|
||||
set_selection: setSelection,
|
||||
set_value: setValue
|
||||
...selection
|
||||
// set_value: setValue
|
||||
}
|
||||
|
||||
export const applyOperation = meta => (
|
||||
@@ -49,7 +25,7 @@ export const applyOperation = meta => (
|
||||
try {
|
||||
const applyOp = opType[op.type]
|
||||
|
||||
if (!applyOp) throw new TypeError('Invalid operation type!')
|
||||
if (!applyOp) throw new TypeError('Unsupported operation type!')
|
||||
|
||||
return applyOp(doc, op, meta)
|
||||
} catch (e) {
|
||||
|
||||
35
packages/bridge/src/apply/selection.ts
Normal file
35
packages/bridge/src/apply/selection.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { toJS } from '../utils'
|
||||
|
||||
const setSelection = (doc, op, { id, selection, annotationType }) => {
|
||||
if (!doc.cursors) {
|
||||
doc.cursors = {}
|
||||
}
|
||||
|
||||
const operation = op.toJS()
|
||||
|
||||
if (!doc.cursors[id]) {
|
||||
doc.cursors[id] = {
|
||||
key: id,
|
||||
type: annotationType,
|
||||
data: {}
|
||||
}
|
||||
}
|
||||
|
||||
const cursor = doc.cursors[id]
|
||||
const { focus, anchor } = operation.newProperties
|
||||
|
||||
if (focus) cursor.focus = focus
|
||||
if (anchor) cursor.anchor = anchor
|
||||
|
||||
const cursorPath = (anchor && anchor.path) || (focus && focus.path)
|
||||
|
||||
if (cursorPath) cursor.data.cursorPath = toJS(cursorPath)
|
||||
|
||||
cursor.data.isBackward = selection.isBackward
|
||||
|
||||
return doc
|
||||
}
|
||||
|
||||
export default {
|
||||
set_selection: setSelection
|
||||
}
|
||||
Reference in New Issue
Block a user