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.
20 lines
482 B
20 lines
482 B
import { InsertNodeOperation } from 'slate'
|
|
|
|
import { SyncDoc } from '../../model'
|
|
import { getParent, getChildren } from '../../path'
|
|
import { toSync } from '../../utils'
|
|
|
|
const insertNode = (doc: SyncDoc, op: InsertNodeOperation): SyncDoc => {
|
|
const [parent, index] = getParent(doc, op.path)
|
|
|
|
if (parent.text) {
|
|
throw new TypeError("Can't insert node into text node")
|
|
}
|
|
|
|
getChildren(parent).splice(index, 0, toSync(op.node))
|
|
|
|
return doc
|
|
}
|
|
|
|
export default insertNode
|