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.
29 lines
617 B
29 lines
617 B
import * as Automerge from 'automerge'
|
|
|
|
import { toSync } from '../'
|
|
|
|
import { Node } from 'slate'
|
|
|
|
export const createText = (text: string = '') => ({
|
|
text
|
|
})
|
|
|
|
export const createNode = (
|
|
type: string = 'paragraph',
|
|
text: string = '',
|
|
data?: { [key: string]: any }
|
|
) => ({
|
|
type,
|
|
children: [createText(text)],
|
|
...data
|
|
})
|
|
|
|
export const createValue = (children?: any): { children: Node[] } => ({
|
|
children: children || [createNode()]
|
|
})
|
|
|
|
export const createDoc = (children?: any) =>
|
|
Automerge.from(toSync(createValue(children)))
|
|
|
|
export const cloneDoc = (doc: any) => Automerge.change(doc, '', d => d)
|