fix dependency update (#50)

* Always call external onChange.

* Fix split_node missing properties bug.

* fix: dependency update build

Co-authored-by: Ulion <ulion2002@gmail.com>
master
George 3 years ago committed by GitHub
parent 1a536f2fa4
commit a67986995d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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()

@ -5,52 +5,70 @@ import { toSlatePath, toJS } from '../utils'
import { getTarget } from '../path'
const removeTextOp = (op: Automerge.Diff) => (map: any, doc: Element) => {
const { index, path, obj } = op
try {
const { index, path, obj } = op
const slatePath = toSlatePath(path).slice(0, path?.length)
const slatePath = toSlatePath(path).slice(0, path?.length)
let node
let node = map[obj]
try {
node = getTarget(doc, slatePath) || map[obj]
} catch (e) {
console.error(e, op, doc)
}
try {
node = getTarget(doc, slatePath)
} catch (e) {
console.error(e, slatePath, op, map, toJS(doc))
}
if (typeof index !== 'number') return
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)
}
if (node) {
node.text = node?.text ? (node.text.slice(0, index) + node.text.slice(index + 1)) : ''
}
return {
type: 'remove_text',
path: slatePath,
offset: index,
text,
marks: []
return {
type: 'remove_text',
path: slatePath,
offset: index,
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
) => {
const slatePath = toSlatePath(path)
try {
const { index, obj, path } = op
const parent = getTarget(doc, slatePath)
const target = parent?.children[index as number] || { children: [] }
const slatePath = toSlatePath(path)
if (!map.hasOwnProperty(obj)) {
map[obj] = target
}
const parent = getTarget(doc, slatePath)
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
}
return {
type: 'remove_node',
path: slatePath.length ? slatePath.concat(index) : [index],
node: 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))
}
}
@ -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

@ -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

@ -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))

@ -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"
}
}

Loading…
Cancel
Save