initial commit

This commit is contained in:
cudr
2019-10-05 11:44:49 +03:00
commit a817eb1ceb
63 changed files with 1769 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
import toSync from './toSync'
export const toJS = node => JSON.parse(JSON.stringify(node))
export const cloneNode = node => toSync(toJS(node))
const toSlatePath = path => (path ? path.filter(d => Number.isInteger(d)) : [])
export { toSync, toSlatePath }

View File

@@ -0,0 +1,33 @@
import * as Automerge from 'automerge'
const toSync = (node: any): any => {
if (!node) {
return
}
if (node.hasOwnProperty('text')) {
return {
...node,
text: new Automerge.Text(node.text)
}
} else if (node.nodes) {
return {
...node,
nodes: node.nodes.map(toSync)
}
} else if (node.leaves) {
return {
...node,
leaves: node.leaves.map(toSync)
}
} else if (node.document) {
return {
...node,
document: toSync(node.document)
}
}
return node
}
export default toSync