mirror of
https://github.com/cudr/slate-collaborative.git
synced 2024-10-27 20:34:06 +00:00
fix: opRemove on reconnect
This commit is contained in:
parent
528fd3ab08
commit
24a7f917fe
1
packages/bridge/src/convert/constants.ts
Normal file
1
packages/bridge/src/convert/constants.ts
Normal file
@ -0,0 +1 @@
|
||||
export const rootKey = '00000000-0000-0000-0000-000000000000'
|
@ -8,6 +8,7 @@ import opCreate from './create'
|
||||
import { toJS } from '../utils'
|
||||
|
||||
import { SyncDoc } from '../model'
|
||||
import { rootKey } from './constants'
|
||||
|
||||
const byAction = {
|
||||
create: opCreate,
|
||||
@ -16,8 +17,6 @@ const byAction = {
|
||||
insert: opInsert
|
||||
}
|
||||
|
||||
const rootKey = '00000000-0000-0000-0000-000000000000'
|
||||
|
||||
const toSlateOp = (ops: Automerge.Diff[], doc: SyncDoc) => {
|
||||
const iterate = (acc: [any, any[]], op: Automerge.Diff): any => {
|
||||
const action = byAction[op.action]
|
||||
|
@ -3,6 +3,7 @@ import { Element } from 'slate'
|
||||
|
||||
import { toSlatePath, toJS } from '../utils'
|
||||
import { getTarget } from '../path'
|
||||
import { rootKey } from './constants'
|
||||
|
||||
const removeTextOp = (op: Automerge.Diff) => (map: any, doc: Element) => {
|
||||
const { index, path, obj } = op
|
||||
@ -73,6 +74,8 @@ const opRemove = (op: Automerge.Diff, [map, ops]: any) => {
|
||||
const key = path[path.length - 1]
|
||||
|
||||
if (key === 'cursors') return [map, ops]
|
||||
// if we don't have a valid key and this is the root obj no slate op is needed
|
||||
if (key === undefined && obj === rootKey) return [map, ops]
|
||||
|
||||
const fn = key === 'text' ? removeTextOp : removeNodeOp
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user