cudr_slate-collaborative/README.md

75 lines
2.1 KiB
Markdown
Raw Normal View History

2019-10-28 17:14:04 +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
2019-10-19 19:48:09 +00:00
check [example](https://github.com/cudr/slate-collaborative/blob/master/packages/example/src/Client.tsx)
2019-10-19 19:40:15 +00:00
```
import ColaborativeClient from '@slate-collaborative/client'
const plugins = [ColaborativeClient(options)]
```
### options:
```
{
url?: string // url to open connection
connectOpts?: SocketIOClient.ConnectOpts // socket.io-client options
cursorAnnotationType?: string // type string for cursor annotations
annotationDataMixin?: Data // any data passed to cursor annotation
renderPreloader?: () => ReactNode // optional preloader render
2019-10-19 19:53:29 +00:00
renderCursor?: (data: Data) => ReactNode | any // custom cursor render
2019-10-19 19:40:15 +00:00
onConnect?: (connection: Connection) => void // connect callback
onDisconnect?: (connection: Connection) => void // disconnect callback
}
```
## Backend
```
const CollaborativeBackend = require('@slate-collaborative/backend')
const connection = new CollaborativeBackend(options)
```
### options:
```
{
2019-10-28 17:02:33 +00:00
entry: number | Server // port or Server for listen io connection
2019-10-19 19:40:15 +00:00
connectOpts?: SocketIO.ServerOptions
2019-10-19 19:43:55 +00:00
defaultValue?: ValueJSON // default value
saveTreshold?: number // theshold of onDocumentSave callback execution
cursorAnnotationType?: string // type string for cursor annotations
onAuthRequest?: ( // auth callback
2019-10-19 19:40:15 +00:00
query: Object,
socket?: SocketIO.Socket
) => Promise<boolean> | boolean
2019-10-19 19:43:55 +00:00
onDocumentLoad?: ( // request slatejs document callback
2019-10-19 19:40:15 +00:00
pathname: string,
query?: Object
) => ValueJSON | null | false | undefined
2019-10-19 19:43:55 +00:00
onDocumentSave?: (pathname: string, json: ValueJSON) => 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
```