mirror of
https://github.com/cudr/slate-collaborative.git
synced 2024-10-27 20:34:06 +00:00
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>
This commit is contained in:
parent
1a536f2fa4
commit
a67986995d
@ -38,7 +38,7 @@ export default class SocketIOCollaboration {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
constructor(options: SocketIOCollaborationOptions) {
|
constructor(options: SocketIOCollaborationOptions) {
|
||||||
this.io = io(options.entry, options.connectOpts)
|
this.io = io(options.entry as Server, options.connectOpts)
|
||||||
|
|
||||||
this.backend = new AutomergeBackend()
|
this.backend = new AutomergeBackend()
|
||||||
|
|
||||||
|
@ -5,24 +5,25 @@ import { toSlatePath, toJS } from '../utils'
|
|||||||
import { getTarget } from '../path'
|
import { getTarget } from '../path'
|
||||||
|
|
||||||
const removeTextOp = (op: Automerge.Diff) => (map: any, doc: Element) => {
|
const removeTextOp = (op: Automerge.Diff) => (map: any, doc: Element) => {
|
||||||
|
try {
|
||||||
const { index, path, obj } = op
|
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 {
|
try {
|
||||||
node = getTarget(doc, slatePath) || map[obj]
|
node = getTarget(doc, slatePath)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e, op, doc)
|
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) {
|
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 {
|
return {
|
||||||
@ -32,26 +33,43 @@ const removeTextOp = (op: Automerge.Diff) => (map: any, doc: Element) => {
|
|||||||
text,
|
text,
|
||||||
marks: []
|
marks: []
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e, op, map, toJS(doc))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeNodeOp = ({ index, obj, path }: Automerge.Diff) => (
|
const removeNodeOp = (op: Automerge.Diff) => (
|
||||||
map: any,
|
map: any,
|
||||||
doc: Element
|
doc: Element
|
||||||
) => {
|
) => {
|
||||||
|
try {
|
||||||
|
const { index, obj, path } = op
|
||||||
|
|
||||||
const slatePath = toSlatePath(path)
|
const slatePath = toSlatePath(path)
|
||||||
|
|
||||||
const parent = getTarget(doc, slatePath)
|
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)) {
|
if (!map.hasOwnProperty(obj)) {
|
||||||
map[obj] = target
|
map[obj] = target
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Number.isInteger(index)) {
|
||||||
|
throw new TypeError('Index is not a number')
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'remove_node',
|
type: 'remove_node',
|
||||||
path: slatePath.length ? slatePath.concat(index) : [index],
|
path: slatePath.length ? slatePath.concat(index) : [index],
|
||||||
node: target
|
node: target
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e, op, map, toJS(doc))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const opRemove = (op: Automerge.Diff, [map, ops]: any) => {
|
const opRemove = (op: Automerge.Diff, [map, ops]: any) => {
|
||||||
@ -61,7 +79,8 @@ const opRemove = (op: Automerge.Diff, [map, ops]: any) => {
|
|||||||
if (
|
if (
|
||||||
map.hasOwnProperty(obj) &&
|
map.hasOwnProperty(obj) &&
|
||||||
typeof map[obj] !== 'string' &&
|
typeof map[obj] !== 'string' &&
|
||||||
type !== 'text'
|
type !== 'text' &&
|
||||||
|
map?.obj?.length
|
||||||
) {
|
) {
|
||||||
map[obj].splice(index, 1)
|
map[obj].splice(index, 1)
|
||||||
|
|
||||||
@ -72,7 +91,7 @@ const opRemove = (op: Automerge.Diff, [map, ops]: any) => {
|
|||||||
|
|
||||||
const key = path[path.length - 1]
|
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
|
const fn = key === 'text' ? removeTextOp : removeNodeOp
|
||||||
|
|
||||||
|
@ -10,10 +10,10 @@ const setDataOp = (
|
|||||||
type: 'set_node',
|
type: 'set_node',
|
||||||
path: toSlatePath(path),
|
path: toSlatePath(path),
|
||||||
properties: {
|
properties: {
|
||||||
[key]: Automerge.getObjectById(doc, obj)?.[key]
|
[key]: toJS(Automerge.getObjectById(doc, obj)?.[key])
|
||||||
},
|
},
|
||||||
newProperties: {
|
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
|
const { link, value, path, obj, key } = op
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (path && path[0] !== 'cursors') {
|
if (path && path.length && path[0] !== 'cursors') {
|
||||||
ops.push(setDataOp(op, doc))
|
ops.push(setDataOp(op, doc))
|
||||||
} else if (map[obj]) {
|
} else if (map[obj]) {
|
||||||
map[obj][key as any] = link ? map[value] : value
|
map[obj][key as any] = link ? map[value] : value
|
||||||
|
@ -130,7 +130,9 @@ export const AutomergeEditor = {
|
|||||||
Editor.withoutNormalizing(e, () => {
|
Editor.withoutNormalizing(e, () => {
|
||||||
if (HistoryEditor.isHistoryEditor(e) && !preserveExternalHistory) {
|
if (HistoryEditor.isHistoryEditor(e) && !preserveExternalHistory) {
|
||||||
HistoryEditor.withoutSaving(e, () => {
|
HistoryEditor.withoutSaving(e, () => {
|
||||||
slateOps.forEach((o: Operation) => e.apply(o))
|
slateOps.forEach((o: Operation) => {
|
||||||
|
e.apply(o)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
slateOps.forEach((o: Operation) => e.apply(o))
|
slateOps.forEach((o: Operation) => e.apply(o))
|
||||||
|
@ -7,16 +7,9 @@
|
|||||||
"@emotion/styled": "^10.0.17",
|
"@emotion/styled": "^10.0.17",
|
||||||
"@slate-collaborative/backend": "^0.7.1",
|
"@slate-collaborative/backend": "^0.7.1",
|
||||||
"@slate-collaborative/client": "^0.7.0",
|
"@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",
|
"concurrently": "^4.1.2",
|
||||||
"cross-env": "^6.0.3",
|
"cross-env": "^6.0.3",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"faker": "^5.1.0",
|
|
||||||
"is-url": "^1.2.4",
|
"is-url": "^1.2.4",
|
||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.15",
|
||||||
"nodemon": "^2.0.6",
|
"nodemon": "^2.0.6",
|
||||||
@ -26,8 +19,7 @@
|
|||||||
"react-scripts": "3.1.2",
|
"react-scripts": "3.1.2",
|
||||||
"slate": "0.59.0",
|
"slate": "0.59.0",
|
||||||
"slate-history": "0.58.3",
|
"slate-history": "0.58.3",
|
||||||
"slate-react": "0.59.0",
|
"slate-react": "0.59.0"
|
||||||
"typescript": "^3.8.3"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "nodemon server.js",
|
"start": "nodemon server.js",
|
||||||
@ -54,5 +46,15 @@
|
|||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "12.x"
|
"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…
Reference in New Issue
Block a user