|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
import * as Automerge from 'automerge'
|
|
|
|
|
import { toSlatePath, toJS } from '../utils/index'
|
|
|
|
|
import { getTarget } from '../path'
|
|
|
|
|
|
|
|
|
|
const removeTextOp = ({ index, path }) => () => ({
|
|
|
|
|
const removeTextOp = ({ index, path }: Automerge.Diff) => () => ({
|
|
|
|
|
type: 'remove_text',
|
|
|
|
|
path: toSlatePath(path).slice(0, path.length),
|
|
|
|
|
offset: index,
|
|
|
|
@ -8,11 +10,30 @@ const removeTextOp = ({ index, path }) => () => ({
|
|
|
|
|
marks: []
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const removeNodesOp = ({ index, path }) => () => {
|
|
|
|
|
const nPath = toSlatePath(path)
|
|
|
|
|
const removeMarkOp = ({ path, index }: Automerge.Diff) => (map, doc) => {
|
|
|
|
|
const slatePath = toSlatePath(path)
|
|
|
|
|
const target = getTarget(doc, slatePath)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: 'remove_mark',
|
|
|
|
|
path: slatePath,
|
|
|
|
|
mark: {
|
|
|
|
|
type: target.marks[index].type
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const removeNodesOp = ({ index, obj, path }: Automerge.Diff) => (map, doc) => {
|
|
|
|
|
const slatePath = toSlatePath(path)
|
|
|
|
|
if (!map.hasOwnProperty(obj)) {
|
|
|
|
|
const target = getTarget(doc, [...slatePath, index] as any)
|
|
|
|
|
|
|
|
|
|
map[obj] = target
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: 'remove_node',
|
|
|
|
|
path: nPath.length ? nPath.concat(index) : [index],
|
|
|
|
|
path: slatePath.length ? slatePath.concat(index) : [index],
|
|
|
|
|
node: {
|
|
|
|
|
object: 'text'
|
|
|
|
|
}
|
|
|
|
@ -21,10 +42,11 @@ const removeNodesOp = ({ index, path }) => () => {
|
|
|
|
|
|
|
|
|
|
const removeByType = {
|
|
|
|
|
text: removeTextOp,
|
|
|
|
|
nodes: removeNodesOp
|
|
|
|
|
nodes: removeNodesOp,
|
|
|
|
|
marks: removeMarkOp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const opRemove = (op, [map, ops]) => {
|
|
|
|
|
const opRemove = (op: Automerge.Diff, [map, ops]) => {
|
|
|
|
|
try {
|
|
|
|
|
const { index, path, obj } = op
|
|
|
|
|
|
|
|
|
|