2020-05-10 13:50:12 +00:00
|
|
|
# slate-collaborative. Check [demo](https://slate-collaborative.herokuapp.com/)
|
2019-10-19 19:40:15 +00:00
|
|
|
slatejs collaborative plugin & microservice
|
|
|
|
|
2019-10-28 17:10:46 +00:00
|
|
|
![screencast2019-10-2820-06-10](https://user-images.githubusercontent.com/23132107/67700384-ebff7280-f9be-11e9-9005-6ddadcafec47.gif)
|
|
|
|
|
2019-10-19 19:40:15 +00:00
|
|
|
A little experiment for co-editing.
|
|
|
|
|
2019-10-19 19:44:39 +00:00
|
|
|
Based on idea of https://github.com/humandx/slate-automerge
|
2019-10-19 19:40:15 +00:00
|
|
|
|
|
|
|
# API
|
|
|
|
|
|
|
|
## Client
|
|
|
|
|
|
|
|
Use it as a simple slatejs plugin
|
|
|
|
|
2020-05-10 13:50:12 +00:00
|
|
|
```ts
|
|
|
|
import { withIOCollaboration } from '@slate-collaborative/client'
|
2019-10-19 19:48:09 +00:00
|
|
|
|
2020-05-10 13:50:12 +00:00
|
|
|
const collaborationEditor = withIOCollaboration(editor, options)
|
2019-10-19 19:40:15 +00:00
|
|
|
```
|
|
|
|
|
2020-05-10 13:50:12 +00:00
|
|
|
Check [detailed example](https://github.com/cudr/slate-collaborative/blob/master/packages/example/src/Client.tsx)
|
2019-10-19 19:40:15 +00:00
|
|
|
|
2020-05-10 13:50:12 +00:00
|
|
|
### Options:
|
|
|
|
```ts
|
2019-10-19 19:40:15 +00:00
|
|
|
{
|
2020-05-10 13:50:12 +00:00
|
|
|
docId?: // document id
|
2019-10-19 19:40:15 +00:00
|
|
|
url?: string // url to open connection
|
|
|
|
connectOpts?: SocketIOClient.ConnectOpts // socket.io-client options
|
2020-05-10 13:50:12 +00:00
|
|
|
cursorData?: any // any data passed to cursor
|
|
|
|
onConnect?: () => void // connect callback
|
|
|
|
onDisconnect?: () => void // disconnect callback
|
2020-06-07 20:04:23 +00:00
|
|
|
onError?: (reason: string) => void // error callback
|
2019-10-19 19:40:15 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-05-10 13:50:12 +00:00
|
|
|
You need to attach the useCursor decorator to provide custom cursor data in renderLeaf function
|
|
|
|
|
|
|
|
```ts
|
|
|
|
import { useCursor } from '@slate-collaborative/client'
|
|
|
|
|
|
|
|
const decorator = useCursor(editor)
|
2019-10-19 19:40:15 +00:00
|
|
|
```
|
|
|
|
|
2020-05-10 13:50:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Backend
|
|
|
|
```ts
|
|
|
|
const { SocketIOConnection } = require('@slate-collaborative/backend')
|
|
|
|
|
|
|
|
const connection = new SocketIOConnection(options)
|
2019-10-19 19:40:15 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### options:
|
2020-05-10 13:50:12 +00:00
|
|
|
```ts
|
2019-10-19 19:40:15 +00:00
|
|
|
{
|
2020-05-10 13:50:12 +00:00
|
|
|
entry: Server // or specify port to start io server
|
|
|
|
defaultValue: Node[] // default value
|
|
|
|
saveFrequency: number // frequency of onDocumentSave callback execution in ms
|
|
|
|
onAuthRequest: ( // auth callback
|
2019-10-19 19:40:15 +00:00
|
|
|
query: Object,
|
|
|
|
socket?: SocketIO.Socket
|
|
|
|
) => Promise<boolean> | boolean
|
2020-05-10 13:50:12 +00:00
|
|
|
onDocumentLoad: ( // request slate document callback
|
2019-10-19 19:40:15 +00:00
|
|
|
pathname: string,
|
|
|
|
query?: Object
|
2020-05-15 19:16:28 +00:00
|
|
|
) => Promise<Node[]> | Node[]
|
2020-05-10 13:50:12 +00:00
|
|
|
onDocumentSave: (pathname: string, doc: Node[]) => Promise<void> | void // save document callback
|
2019-10-19 19:40:15 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-10-28 17:14:04 +00:00
|
|
|
# Contribute
|
|
|
|
|
|
|
|
You welcome to contribute!
|
|
|
|
|
|
|
|
start it ease:
|
|
|
|
```
|
|
|
|
yarn
|
|
|
|
yarn dev
|
|
|
|
```
|
|
|
|
|