You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cudr_slate-collaborative/packages/bridge/src/convert/set.ts

36 lines
616 B

import { toSlatePath, toJS } from '../utils/index'
const setDataOp = ({ path, value }) => map => ({
type: 'set_node',
path: toSlatePath(path),
properties: {},
newProperties: {
data: map[value]
}
})
const setByType = {
data: setDataOp
}
5 years ago
const opSet = (op, [map, ops]) => {
const { link, value, path, obj, key } = op
5 years ago
try {
const set = setByType[key]
if (set && path) {
ops.push(set(op))
} else {
map[obj][key] = link ? map[value] : value
}
5 years ago
return [map, ops]
} catch (e) {
console.error(e, op, toJS(map))
return [map, ops]
}
}
export default opSet