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.
28 lines
559 B
28 lines
559 B
import * as Automerge from 'automerge'
|
|
import { TextJSON } from 'slate'
|
|
|
|
export const createTextJSON = (text: string = ''): TextJSON => ({
|
|
object: 'text',
|
|
marks: [],
|
|
text
|
|
})
|
|
|
|
export const createBlockJSON = (
|
|
type: string = 'paragraph',
|
|
text: string = ''
|
|
) => ({
|
|
object: 'block',
|
|
type,
|
|
nodes: [createTextJSON(text)]
|
|
})
|
|
|
|
export const createValueJSON = () => ({
|
|
document: {
|
|
nodes: [createBlockJSON()]
|
|
}
|
|
})
|
|
|
|
export const createDoc = () => Automerge.from(createValueJSON())
|
|
|
|
export const cloneDoc = doc => Automerge.change(doc, '', d => d)
|