mirror of
https://github.com/cudr/slate-collaborative.git
synced 2024-10-27 20:34:06 +00:00
process remove property case properly.
This commit is contained in:
parent
56b1902577
commit
e7648b083d
@ -9,15 +9,24 @@ export const setDataOp = (
|
|||||||
) => (map: any, tmpDoc: Element) => {
|
) => (map: any, tmpDoc: Element) => {
|
||||||
const slatePath = toSlatePath(path)
|
const slatePath = toSlatePath(path)
|
||||||
const node = Node.get(tmpDoc, slatePath)
|
const node = Node.get(tmpDoc, slatePath)
|
||||||
node[key] = toJS(map?.[value] || value)
|
const oldValue = node[key]
|
||||||
|
const newValue = toJS(map?.[value] || value)
|
||||||
|
map[obj] = node // node from tmpDoc is the newest value at the moment, keep map sync
|
||||||
|
|
||||||
|
if (newValue == null) {
|
||||||
|
// slate does this check.
|
||||||
|
delete node[key]
|
||||||
|
} else {
|
||||||
|
node[key] = newValue
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
type: 'set_node',
|
type: 'set_node',
|
||||||
path: slatePath,
|
path: slatePath,
|
||||||
properties: {
|
properties: {
|
||||||
[key]: toJS(Automerge.getObjectById(doc, obj)?.[key])
|
[key]: toJS(oldValue)
|
||||||
},
|
},
|
||||||
newProperties: {
|
newProperties: {
|
||||||
[key]: toJS(node[key])
|
[key]: toJS(newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26,7 +35,7 @@ const opSet = (op: Automerge.Diff, [map, ops]: any, doc: any, tmpDoc: any) => {
|
|||||||
const { link, value, path, obj, key } = op
|
const { link, value, path, obj, key } = op
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (path && path.length && path[0] !== 'cursors') {
|
if (path && path.length && path[0] === 'children') {
|
||||||
ops.push(setDataOp(op, doc)(map, tmpDoc))
|
ops.push(setDataOp(op, doc)(map, tmpDoc))
|
||||||
} else if (map[obj]) {
|
} else if (map[obj]) {
|
||||||
map[obj][key as any] = link ? map[value] : value
|
map[obj][key as any] = link ? map[value] : value
|
||||||
|
Loading…
Reference in New Issue
Block a user