mirror of
https://github.com/cudr/slate-collaborative.git
synced 2024-10-27 20:34:06 +00:00
25 lines
588 B
TypeScript
25 lines
588 B
TypeScript
import * as Automerge from 'automerge'
|
|
import { ValueJSON, TextJSON, NodeJSON } from 'slate'
|
|
|
|
export const createTextJSON = (text: string = ''): TextJSON => ({
|
|
object: 'text',
|
|
marks: [],
|
|
text
|
|
})
|
|
|
|
export const createParagraphJSON = (text: string = ''): NodeJSON => ({
|
|
object: 'block',
|
|
type: 'paragraph',
|
|
nodes: [createTextJSON(text)]
|
|
})
|
|
|
|
export const createValueJSON = (): ValueJSON => ({
|
|
document: {
|
|
nodes: [createParagraphJSON()]
|
|
}
|
|
})
|
|
|
|
export const createDoc = () => Automerge.from(createValueJSON())
|
|
|
|
export const cloneDoc = doc => Automerge.change(doc, '', d => d)
|