You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cudr_slate-collaborative/README.md

83 lines
2.1 KiB

# slate-collaborative. Check [demo](https://slate-collaborative.herokuapp.com/)
5 years ago
slatejs collaborative plugin & microservice
5 years ago
![screencast2019-10-2820-06-10](https://user-images.githubusercontent.com/23132107/67700384-ebff7280-f9be-11e9-9005-6ddadcafec47.gif)
5 years ago
A little experiment for co-editing.
5 years ago
Based on idea of https://github.com/humandx/slate-automerge
5 years ago
# API
## Client
Use it as a simple slatejs plugin
```ts
import { withIOCollaboration } from '@slate-collaborative/client'
5 years ago
const collaborationEditor = withIOCollaboration(editor, options)
5 years ago
```
Check [detailed example](https://github.com/cudr/slate-collaborative/blob/master/packages/example/src/Client.tsx)
5 years ago
### Options:
```ts
5 years ago
{
docId?: // document id
5 years ago
url?: string // url to open connection
connectOpts?: SocketIOClient.ConnectOpts // socket.io-client options
cursorData?: any // any data passed to cursor
onConnect?: () => void // connect callback
onDisconnect?: () => void // disconnect callback
onError?: (reason: string) => void // error callback
preserveExternalHistory?: boolean // preserve slate-history operations form other clients
5 years ago
}
```
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)
5 years ago
```
## Backend
```ts
const { SocketIOConnection } = require('@slate-collaborative/backend')
const connection = new SocketIOConnection(options)
5 years ago
```
### options:
```ts
5 years ago
{
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
5 years ago
query: Object,
socket?: SocketIO.Socket
) => Promise<boolean> | boolean
onDocumentLoad: ( // request slate document callback
5 years ago
pathname: string,
query?: Object
) => Promise<Node[]> | Node[]
onDocumentSave: (pathname: string, doc: Node[]) => Promise<void> | void // save document callback
5 years ago
}
```
5 years ago
# Contribute
You welcome to contribute!
start it ease:
```
yarn
yarn dev
```