cudr_slate-collaborative/packages/bridge/src/utils/index.ts
George 0fd9390a99
feat: update to slate 0.5x (#10)
Update Slate-Collaboration to be compatible with Slate 0.5x versions.
2020-05-10 16:50:12 +03:00

27 lines
648 B
TypeScript

import toSync from './toSync'
import hexGen from './hexGen'
import { CollabAction } from '../model'
export * from './testUtils'
const toJS = (node: any) => {
try {
return JSON.parse(JSON.stringify(node))
} catch (e) {
console.error('Convert to js failed!!! Return null')
return null
}
}
const cloneNode = (node: any) => toSync(toJS(node))
const toSlatePath = (path: any) =>
path ? path.filter((d: any) => Number.isInteger(d)) : []
const toCollabAction = (type: any, fn: (action: CollabAction) => void) => (
payload: any
) => fn({ type, payload })
export { toSync, toJS, toSlatePath, hexGen, cloneNode, toCollabAction }