mirror of
https://github.com/cudr/slate-collaborative.git
synced 2024-10-27 20:34:06 +00:00
commit
8c80a52068
17
.travis.yml
Normal file
17
.travis.yml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
language: node_js
|
||||||
|
|
||||||
|
node_js:
|
||||||
|
- '12'
|
||||||
|
|
||||||
|
env:
|
||||||
|
- workerCount=3 timeout=600000
|
||||||
|
|
||||||
|
script:
|
||||||
|
- npm run test
|
||||||
|
|
||||||
|
install:
|
||||||
|
- npm run bootstrap
|
||||||
|
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- node_modules
|
@ -9,6 +9,7 @@
|
|||||||
"build": "lerna run build --stream",
|
"build": "lerna run build --stream",
|
||||||
"watch": "lerna run --parallel watch",
|
"watch": "lerna run --parallel watch",
|
||||||
"prebuild": "rm -rf ./packages/**/lib/",
|
"prebuild": "rm -rf ./packages/**/lib/",
|
||||||
|
"test": "lerna run test --stream",
|
||||||
"format": "prettier --write"
|
"format": "prettier --write"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
@ -22,7 +23,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"*.{js,jsx,ts,tsx,json,babelrc}": [
|
"*.{js,jsx,ts,tsx,babelrc}": [
|
||||||
"yarn run format",
|
"yarn run format",
|
||||||
"git add"
|
"git add"
|
||||||
]
|
]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@slate-collaborative/backend",
|
"name": "@slate-collaborative/backend",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
@ -25,7 +25,7 @@
|
|||||||
"watch": "yarn build:js -w"
|
"watch": "yarn build:js -w"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@slate-collaborative/bridge": "^0.0.1",
|
"@slate-collaborative/bridge": "^0.0.2",
|
||||||
"automerge": "^0.12.1",
|
"automerge": "^0.12.1",
|
||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.15",
|
||||||
"socket.io": "^2.2.0",
|
"socket.io": "^2.2.0",
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
{
|
{
|
||||||
"presets": ["@babel/env", "@babel/typescript"],
|
"presets": [
|
||||||
|
[
|
||||||
|
"@babel/preset-env",
|
||||||
|
{
|
||||||
|
"targets": {
|
||||||
|
"esmodules": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"@babel/typescript"
|
||||||
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"@babel/proposal-class-properties",
|
"@babel/proposal-class-properties",
|
||||||
"@babel/proposal-object-rest-spread"
|
"@babel/proposal-object-rest-spread"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@slate-collaborative/bridge",
|
"name": "@slate-collaborative/bridge",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
@ -21,7 +21,8 @@
|
|||||||
"build": "yarn run build:types && yarn run build:js",
|
"build": "yarn run build:types && yarn run build:js",
|
||||||
"build:types": "tsc --emitDeclarationOnly",
|
"build:types": "tsc --emitDeclarationOnly",
|
||||||
"build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline",
|
"build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline",
|
||||||
"watch": "yarn build:js -w"
|
"watch": "yarn build:js -w",
|
||||||
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.6.3"
|
||||||
@ -32,7 +33,10 @@
|
|||||||
"@babel/plugin-proposal-class-properties": "^7.5.5",
|
"@babel/plugin-proposal-class-properties": "^7.5.5",
|
||||||
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
|
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
|
||||||
"@babel/preset-env": "^7.6.0",
|
"@babel/preset-env": "^7.6.0",
|
||||||
"@babel/preset-typescript": "^7.6.0"
|
"@babel/preset-typescript": "^7.6.0",
|
||||||
|
"@types/jest": "^24.0.19",
|
||||||
|
"jest": "^24.9.0",
|
||||||
|
"ts-jest": "^24.1.0"
|
||||||
},
|
},
|
||||||
"directories": {
|
"directories": {
|
||||||
"lib": "lib"
|
"lib": "lib"
|
||||||
@ -41,5 +45,14 @@
|
|||||||
"slate",
|
"slate",
|
||||||
"automerge",
|
"automerge",
|
||||||
"bridge"
|
"bridge"
|
||||||
]
|
],
|
||||||
|
"jest": {
|
||||||
|
"roots": [
|
||||||
|
"<rootDir>/src"
|
||||||
|
],
|
||||||
|
"transform": {
|
||||||
|
"^.+\\.ts?$": "ts-jest"
|
||||||
|
},
|
||||||
|
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
import { Operation, SyncDoc } from '../model/index'
|
import { Operation, SyncDoc } from '../model/index'
|
||||||
|
|
||||||
|
// TODO: handle annotation ops
|
||||||
|
|
||||||
export const addAnnotation = (doc: SyncDoc, op: Operation): SyncDoc => {
|
export const addAnnotation = (doc: SyncDoc, op: Operation): SyncDoc => {
|
||||||
console.log('addAnnotation!!!', op.toJS())
|
// console.log('addAnnotation!!!', op.toJS())
|
||||||
return doc
|
return doc
|
||||||
}
|
}
|
||||||
|
|
||||||
export const removeAnnotation = (doc: SyncDoc, op: Operation): SyncDoc => {
|
export const removeAnnotation = (doc: SyncDoc, op: Operation): SyncDoc => {
|
||||||
console.log('removeAnnotation!!!', op.toJS())
|
// console.log('removeAnnotation!!!', op.toJS())
|
||||||
return doc
|
return doc
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setAnnotation = (doc: SyncDoc, op: Operation): SyncDoc => {
|
export const setAnnotation = (doc: SyncDoc, op: Operation): SyncDoc => {
|
||||||
console.log('setAnnotation!!!', op.toJS())
|
// console.log('setAnnotation!!!', op.toJS())
|
||||||
return doc
|
return doc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ const opType: any = {
|
|||||||
// set_value: setValue
|
// set_value: setValue
|
||||||
}
|
}
|
||||||
|
|
||||||
export const applyOperation = (doc: SyncDoc, op: Operation): SyncDoc => {
|
const applyOperation = (doc: SyncDoc, op: Operation): SyncDoc => {
|
||||||
try {
|
try {
|
||||||
const applyOp = opType[op.type]
|
const applyOp = opType[op.type]
|
||||||
|
|
||||||
@ -34,5 +34,7 @@ export const applyOperation = (doc: SyncDoc, op: Operation): SyncDoc => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const applySlateOps = (doc: SyncDoc, operations: Operations) =>
|
const applySlateOps = (doc: SyncDoc, operations: Operations) =>
|
||||||
operations.reduce(applyOperation, doc)
|
operations.reduce(applyOperation, doc)
|
||||||
|
|
||||||
|
export { applyOperation, applySlateOps }
|
||||||
|
34
packages/bridge/src/convert/convert.spec.ts
Normal file
34
packages/bridge/src/convert/convert.spec.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import * as Automerge from 'automerge'
|
||||||
|
import { toSlateOp } from './index'
|
||||||
|
import { createDoc, cloneDoc, createParagraphJSON } from '../utils'
|
||||||
|
|
||||||
|
describe('convert operations to slatejs model', () => {
|
||||||
|
it('convert insert operations', () => {
|
||||||
|
const doc1 = createDoc()
|
||||||
|
const doc2 = cloneDoc(doc1)
|
||||||
|
|
||||||
|
const change = Automerge.change(doc1, 'change', (d: any) => {
|
||||||
|
d.document.nodes.push(createParagraphJSON('hello!'))
|
||||||
|
d.document.nodes[1].nodes[0].text = 'hello!'
|
||||||
|
})
|
||||||
|
|
||||||
|
const operations = Automerge.diff(doc2, change)
|
||||||
|
|
||||||
|
const slateOps = toSlateOp(operations, change)
|
||||||
|
|
||||||
|
const expectedOps = [
|
||||||
|
{
|
||||||
|
type: 'insert_node',
|
||||||
|
path: [1],
|
||||||
|
node: { object: 'block', type: 'paragraph', nodes: [] }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'insert_node',
|
||||||
|
path: [1, 0],
|
||||||
|
node: { object: 'text', marks: [], text: 'hello!' }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
expect(slateOps).toStrictEqual(expectedOps)
|
||||||
|
})
|
||||||
|
})
|
@ -20,6 +20,7 @@ const AnnotationSetOp = ({ key, value }: Automerge.Diff) => (map, doc) => {
|
|||||||
/**
|
/**
|
||||||
* Looks like set_annotation option is broken, temporary disabled
|
* Looks like set_annotation option is broken, temporary disabled
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// if (!doc.annotations[key]) {
|
// if (!doc.annotations[key]) {
|
||||||
op = {
|
op = {
|
||||||
type: 'add_annotation',
|
type: 'add_annotation',
|
||||||
|
@ -51,7 +51,7 @@ export const removeCursor = (doc: SyncDoc, key: CursorKey) => {
|
|||||||
return doc
|
return doc
|
||||||
}
|
}
|
||||||
|
|
||||||
export const cursorOpFilter = (ops: Immutable.List<Operation>, type: string) =>
|
export const cursorOpFilter = (ops: any, type: string): any =>
|
||||||
ops.filter(op => {
|
ops.filter(op => {
|
||||||
if (op.type === 'set_annotation') {
|
if (op.type === 'set_annotation') {
|
||||||
return !(
|
return !(
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import toSync from './toSync'
|
import toSync from './toSync'
|
||||||
import hexGen from './hexGen'
|
import hexGen from './hexGen'
|
||||||
|
|
||||||
export const toJS = node => {
|
export * from './testUtils'
|
||||||
|
|
||||||
|
const toJS = node => {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(JSON.stringify(node))
|
return JSON.parse(JSON.stringify(node))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -10,8 +12,8 @@ export const toJS = node => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const cloneNode = node => toSync(toJS(node))
|
const cloneNode = node => toSync(toJS(node))
|
||||||
|
|
||||||
const toSlatePath = path => (path ? path.filter(d => Number.isInteger(d)) : [])
|
const toSlatePath = path => (path ? path.filter(d => Number.isInteger(d)) : [])
|
||||||
|
|
||||||
export { toSync, toSlatePath, hexGen }
|
export { toSync, toJS, toSlatePath, hexGen, cloneNode }
|
||||||
|
24
packages/bridge/src/utils/testUtils.ts
Normal file
24
packages/bridge/src/utils/testUtils.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import * as Automerge from 'automerge'
|
||||||
|
import { ValueJSON, TextJSON, NodeJSON } from 'slate'
|
||||||
|
|
||||||
|
export const createTextJSON = (text: string = ''): TextJSON => ({
|
||||||
|
object: 'text',
|
||||||
|
marks: [],
|
||||||
|
text
|
||||||
|
})
|
||||||
|
|
||||||
|
export const createParagraphJSON = (text: string = ''): NodeJSON => ({
|
||||||
|
object: 'block',
|
||||||
|
type: 'paragraph',
|
||||||
|
nodes: [createTextJSON(text)]
|
||||||
|
})
|
||||||
|
|
||||||
|
export const createValueJSON = (): ValueJSON => ({
|
||||||
|
document: {
|
||||||
|
nodes: [createParagraphJSON()]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export const createDoc = () => Automerge.from(createValueJSON())
|
||||||
|
|
||||||
|
export const cloneDoc = doc => Automerge.change(doc, '', d => d)
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@slate-collaborative/client",
|
"name": "@slate-collaborative/client",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
@ -25,7 +25,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/preset-react": "^7.0.0",
|
"@babel/preset-react": "^7.0.0",
|
||||||
"@slate-collaborative/bridge": "^0.0.1",
|
"@slate-collaborative/bridge": "^0.0.2",
|
||||||
"automerge": "^0.12.1",
|
"automerge": "^0.12.1",
|
||||||
"immutable": "^4.0.0-rc.12",
|
"immutable": "^4.0.0-rc.12",
|
||||||
"react": "^16.9.0",
|
"react": "^16.9.0",
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/core": "^10.0.17",
|
"@emotion/core": "^10.0.17",
|
||||||
"@emotion/styled": "^10.0.17",
|
"@emotion/styled": "^10.0.17",
|
||||||
"@slate-collaborative/backend": "0.0.1",
|
"@slate-collaborative/backend": "0.0.2",
|
||||||
"@slate-collaborative/client": "0.0.1",
|
"@slate-collaborative/client": "0.0.2",
|
||||||
"@types/faker": "^4.1.5",
|
"@types/faker": "^4.1.5",
|
||||||
"@types/jest": "24.0.18",
|
"@types/jest": "24.0.18",
|
||||||
"@types/node": "12.7.5",
|
"@types/node": "12.7.5",
|
||||||
@ -27,7 +27,6 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
"build": "react-scripts build",
|
|
||||||
"dev": "concurrently \"yarn start\" \"yarn serve\"",
|
"dev": "concurrently \"yarn start\" \"yarn serve\"",
|
||||||
"serve": "nodemon --watch ../backend/lib --inspect server.js"
|
"serve": "nodemon --watch ../backend/lib --inspect server.js"
|
||||||
},
|
},
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
{
|
{
|
||||||
"include": ["src/**/*"],
|
"include": [
|
||||||
|
"src/**/*"
|
||||||
|
],
|
||||||
"extends": "../../tsconfig.base.json",
|
"extends": "../../tsconfig.base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"lib": ["dom", "dom.iterable", "esnext"],
|
"lib": [
|
||||||
|
"dom",
|
||||||
|
"dom.iterable",
|
||||||
|
"esnext"
|
||||||
|
],
|
||||||
"baseUrl": "src",
|
"baseUrl": "src",
|
||||||
"jsx": "react",
|
"jsx": "react",
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
|
Loading…
Reference in New Issue
Block a user