2019-10-05 08:44:49 +00:00
|
|
|
import toSync from './toSync'
|
2019-10-06 20:56:27 +00:00
|
|
|
import hexGen from './hexGen'
|
2019-10-05 08:44:49 +00:00
|
|
|
|
2020-05-10 13:50:12 +00:00
|
|
|
import { CollabAction } from '../model'
|
|
|
|
|
2019-10-21 21:05:46 +00:00
|
|
|
export * from './testUtils'
|
|
|
|
|
2020-05-10 13:50:12 +00:00
|
|
|
const toJS = (node: any) => {
|
2019-10-10 19:45:31 +00:00
|
|
|
try {
|
|
|
|
return JSON.parse(JSON.stringify(node))
|
|
|
|
} catch (e) {
|
2019-10-13 16:37:56 +00:00
|
|
|
console.error('Convert to js failed!!! Return null')
|
2019-10-10 19:45:31 +00:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
2019-10-05 08:44:49 +00:00
|
|
|
|
2020-05-10 13:50:12 +00:00
|
|
|
const cloneNode = (node: any) => toSync(toJS(node))
|
|
|
|
|
|
|
|
const toSlatePath = (path: any) =>
|
|
|
|
path ? path.filter((d: any) => Number.isInteger(d)) : []
|
2019-10-05 08:44:49 +00:00
|
|
|
|
2020-05-10 13:50:12 +00:00
|
|
|
const toCollabAction = (type: any, fn: (action: CollabAction) => void) => (
|
|
|
|
payload: any
|
|
|
|
) => fn({ type, payload })
|
2019-10-05 08:44:49 +00:00
|
|
|
|
2020-05-10 13:50:12 +00:00
|
|
|
export { toSync, toJS, toSlatePath, hexGen, cloneNode, toCollabAction }
|