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.
19 lines
435 B
19 lines
435 B
import { RemoveNodeOperation } from 'slate'
|
|
|
|
import { SyncDoc } from '../../model'
|
|
import { getParent, getChildren } from '../../path'
|
|
|
|
export const removeNode = (doc: SyncDoc, op: RemoveNodeOperation): SyncDoc => {
|
|
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
|