mirror of
https://github.com/cudr/slate-collaborative.git
synced 2024-10-27 20:34:06 +00:00
27 lines
648 B
TypeScript
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 }
|