cudr_slate-collaborative/README.md

66 lines
1.8 KiB
Markdown
Raw Normal View History

2019-10-19 19:40:15 +00:00
# slate-collaborative
slatejs collaborative plugin & microservice
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
Watch the demo
# 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-19 19:54:24 +00:00
port: number // port to start 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
}
```