You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cudr_slate-collaborative/packages/bridge/src/apply/node/removeNode.ts

22 lines
447 B

import { RemoveNodeOperation } from 'slate'
import { SyncValue } from '../../model'
import { getParent, getChildren } from '../../path'
export const removeNode = (
doc: SyncValue,
op: RemoveNodeOperation
): SyncValue => {
const [parent, index] = getParent(doc, op.path)
if (parent.text) {
throw new TypeError("Can't remove node from text node")
}
getChildren(parent).splice(index, 1)
return doc
}
export default removeNode