fix: dependency update build

This commit is contained in:
curd 2021-01-18 19:41:46 +03:00
parent b5f4b5642b
commit f5648255c1
5 changed files with 74 additions and 51 deletions

View File

@ -38,7 +38,7 @@ export default class SocketIOCollaboration {
*/
constructor(options: SocketIOCollaborationOptions) {
this.io = io(options.entry, options.connectOpts)
this.io = io(options.entry as Server, options.connectOpts)
this.backend = new AutomergeBackend()

View File

@ -5,24 +5,25 @@ import { toSlatePath, toJS } from '../utils'
import { getTarget } from '../path'
const removeTextOp = (op: Automerge.Diff) => (map: any, doc: Element) => {
try {
const { index, path, obj } = op
const slatePath = toSlatePath(path).slice(0, path?.length)
let node
let node = map[obj]
try {
node = getTarget(doc, slatePath) || map[obj]
node = getTarget(doc, slatePath)
} catch (e) {
console.error(e, op, doc)
console.error(e, slatePath, op, map, toJS(doc))
}
if (typeof index !== 'number') return
const text = node?.text[index] || '*'
const text = node?.text?.[index] || '*'
if (node) {
node.text = node.text?.slice(0, index) + node.text?.slice(index + 1)
node.text = node?.text ? (node.text.slice(0, index) + node.text.slice(index + 1)) : ''
}
return {
@ -32,26 +33,43 @@ const removeTextOp = (op: Automerge.Diff) => (map: any, doc: Element) => {
text,
marks: []
}
} catch (e) {
console.error(e, op, map, toJS(doc))
}
}
const removeNodeOp = ({ index, obj, path }: Automerge.Diff) => (
const removeNodeOp = (op: Automerge.Diff) => (
map: any,
doc: Element
) => {
try {
const { index, obj, path } = op
const slatePath = toSlatePath(path)
const parent = getTarget(doc, slatePath)
const target = parent?.children[index as number] || { children: [] }
const target = parent?.children?.[index as number] || parent?.[index as number] || { children: [] }
if (!target) {
throw new TypeError('Target is not found!')
}
if (!map.hasOwnProperty(obj)) {
map[obj] = target
}
if (!Number.isInteger(index)) {
throw new TypeError('Index is not a number')
}
return {
type: 'remove_node',
path: slatePath.length ? slatePath.concat(index) : [index],
node: target
}
} catch (e) {
console.error(e, op, map, toJS(doc))
}
}
const opRemove = (op: Automerge.Diff, [map, ops]: any) => {
@ -61,7 +79,8 @@ const opRemove = (op: Automerge.Diff, [map, ops]: any) => {
if (
map.hasOwnProperty(obj) &&
typeof map[obj] !== 'string' &&
type !== 'text'
type !== 'text' &&
map?.obj?.length
) {
map[obj].splice(index, 1)
@ -72,7 +91,7 @@ const opRemove = (op: Automerge.Diff, [map, ops]: any) => {
const key = path[path.length - 1]
if (key === 'cursors') return [map, ops]
if (key === 'cursors' || op.key === 'cursors') return [map, ops]
const fn = key === 'text' ? removeTextOp : removeNodeOp

View File

@ -10,10 +10,10 @@ const setDataOp = (
type: 'set_node',
path: toSlatePath(path),
properties: {
[key]: Automerge.getObjectById(doc, obj)?.[key]
[key]: toJS(Automerge.getObjectById(doc, obj)?.[key])
},
newProperties: {
[key]: value
[key]: map?.[value] || value
}
}
}
@ -22,7 +22,7 @@ const opSet = (op: Automerge.Diff, [map, ops]: any, doc: any) => {
const { link, value, path, obj, key } = op
try {
if (path && path[0] !== 'cursors') {
if (path && path.length && path[0] !== 'cursors') {
ops.push(setDataOp(op, doc))
} else if (map[obj]) {
map[obj][key as any] = link ? map[value] : value

View File

@ -130,7 +130,9 @@ export const AutomergeEditor = {
Editor.withoutNormalizing(e, () => {
if (HistoryEditor.isHistoryEditor(e) && !preserveExternalHistory) {
HistoryEditor.withoutSaving(e, () => {
slateOps.forEach((o: Operation) => e.apply(o))
slateOps.forEach((o: Operation) => {
e.apply(o)
})
})
} else {
slateOps.forEach((o: Operation) => e.apply(o))

View File

@ -7,16 +7,9 @@
"@emotion/styled": "^10.0.17",
"@slate-collaborative/backend": "^0.7.1",
"@slate-collaborative/client": "^0.7.0",
"@types/faker": "^4.1.5",
"@types/is-url": "^1.2.28",
"@types/jest": "24.0.18",
"@types/node": "14.14.6",
"@types/randomcolor": "^0.5.4",
"@types/react-dom": "^16.9.6",
"concurrently": "^4.1.2",
"cross-env": "^6.0.3",
"express": "^4.17.1",
"faker": "^5.1.0",
"is-url": "^1.2.4",
"lodash": "^4.17.15",
"nodemon": "^2.0.6",
@ -26,8 +19,7 @@
"react-scripts": "3.1.2",
"slate": "0.59.0",
"slate-history": "0.58.3",
"slate-react": "0.59.0",
"typescript": "^3.8.3"
"slate-react": "0.59.0"
},
"scripts": {
"start": "nodemon server.js",
@ -54,5 +46,15 @@
},
"engines": {
"node": "12.x"
},
"devDependencies": {
"@types/faker": "^4.1.5",
"@types/is-url": "^1.2.28",
"@types/jest": "24.0.18",
"@types/node": "14.14.6",
"@types/randomcolor": "^0.5.4",
"@types/react-dom": "^16.9.6",
"faker": "^5.1.0",
"typescript": "^3.8.3"
}
}