@hocuspocus/provider-react 4.0.0-rc.7 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -4,11 +4,67 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/@hocuspocus/provider-react)
|
|
5
5
|
[](https://github.com/sponsors/ueberdosis)
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
React bindings for the [Hocuspocus provider](https://www.npmjs.com/package/@hocuspocus/provider). Exposes hooks to subscribe to provider state (connection, sync, awareness) and keep React components in sync with collaborative [Y.js](https://github.com/yjs/yjs) documents.
|
|
7
|
+
React bindings for the [Hocuspocus provider](../provider). Wraps the provider in components and hooks so React handles the lifecycle — including StrictMode double-mounts. Built on `useSyncExternalStore`.
|
|
9
8
|
|
|
10
|
-
##
|
|
11
|
-
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @hocuspocus/provider @hocuspocus/provider-react yjs
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires React 18 or 19.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Wrap your collaborative subtree with `HocuspocusProviderWebsocketComponent` (shared WebSocket) and one or more `HocuspocusRoom`s (one per document). Inside the room, hooks give you the provider and its state:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import {
|
|
23
|
+
HocuspocusProviderWebsocketComponent,
|
|
24
|
+
HocuspocusRoom,
|
|
25
|
+
useHocuspocusProvider,
|
|
26
|
+
useHocuspocusConnectionStatus,
|
|
27
|
+
} from "@hocuspocus/provider-react"
|
|
28
|
+
|
|
29
|
+
function Editor() {
|
|
30
|
+
const provider = useHocuspocusProvider()
|
|
31
|
+
const status = useHocuspocusConnectionStatus()
|
|
32
|
+
// wire provider.document / provider.awareness into your editor
|
|
33
|
+
return <div>{status}</div>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function App() {
|
|
37
|
+
return (
|
|
38
|
+
<HocuspocusProviderWebsocketComponent url="ws://127.0.0.1:1234">
|
|
39
|
+
<HocuspocusRoom name="example-document" token="super-secret-token">
|
|
40
|
+
<Editor />
|
|
41
|
+
</HocuspocusRoom>
|
|
42
|
+
</HocuspocusProviderWebsocketComponent>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
To use with Tiptap, pass `provider.document` into the `Collaboration` extension and `provider` into `CollaborationCaret` — see the [collaborative editing guide](https://tiptap.dev/docs/hocuspocus/guides/collaborative-editing) for a full example.
|
|
48
|
+
|
|
49
|
+
## Exports
|
|
50
|
+
|
|
51
|
+
**Components**
|
|
52
|
+
|
|
53
|
+
- `HocuspocusProviderWebsocketComponent` — manages the shared WebSocket
|
|
54
|
+
- `HocuspocusRoom` — creates a per-document provider on the shared socket; StrictMode-safe
|
|
55
|
+
|
|
56
|
+
**Hooks** (must be used inside a `HocuspocusRoom`)
|
|
57
|
+
|
|
58
|
+
- `useHocuspocusProvider()` — the `HocuspocusProvider` instance
|
|
59
|
+
- `useHocuspocusConnectionStatus()` — `'connecting' | 'connected' | 'disconnected'`
|
|
60
|
+
- `useHocuspocusSyncStatus()` — `'synced' | 'syncing'`
|
|
61
|
+
- `useHocuspocusAwareness()` — array of connected users' awareness state
|
|
62
|
+
- `useHocuspocusEvent(name, handler)` — subscribe to any provider event
|
|
63
|
+
|
|
64
|
+
## Documentation
|
|
65
|
+
|
|
66
|
+
Full components, hooks, and patterns reference: [tiptap.dev/docs/hocuspocus/provider/react](https://tiptap.dev/docs/hocuspocus/provider/react).
|
|
12
67
|
|
|
13
68
|
## License
|
|
14
|
-
|
|
69
|
+
|
|
70
|
+
MIT — see [LICENSE.md](https://github.com/ueberdosis/hocuspocus/blob/main/LICENSE.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/provider-react",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "React bindings for Hocuspocus provider",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@hocuspocus/provider": "^4.0.0
|
|
33
|
+
"@hocuspocus/provider": "^4.0.0",
|
|
34
34
|
"react": "^18.0.0 || ^19.0.0",
|
|
35
35
|
"yjs": "^13.6.8"
|
|
36
36
|
},
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "1c1b34800f702a06e1ce236e8a175c82876bff42"
|
|
48
48
|
}
|