@hocuspocus/provider 2.12.0-rc.0 → 2.12.2-rc.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/dist/hocuspocus-provider.cjs +5 -1
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +5 -1
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +2 -1
- package/dist/packages/provider/src/TiptapCollabProvider.d.ts +4 -1
- package/dist/packages/server/src/types.d.ts +13 -1
- package/package.json +2 -2
- package/src/HocuspocusProviderWebsocket.ts +3 -2
- package/src/TiptapCollabProvider.ts +11 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { MessageEvent } from 'ws';
|
|
2
|
+
import { Event } from 'ws';
|
|
2
3
|
import EventEmitter from './EventEmitter.js';
|
|
3
4
|
import { HocuspocusProvider } from './HocuspocusProvider.js';
|
|
4
5
|
import { WebSocketStatus, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters } from './types.js';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { AbstractType, YArrayEvent } from 'yjs';
|
|
2
|
+
import * as Y from 'yjs';
|
|
2
3
|
import { HocuspocusProvider, HocuspocusProviderConfiguration } from './HocuspocusProvider.js';
|
|
3
4
|
import { TiptapCollabProviderWebsocket } from './TiptapCollabProviderWebsocket.js';
|
|
4
5
|
import type { TCollabComment, TCollabThread, THistoryVersion } from './types.js';
|
|
5
|
-
export type TiptapCollabProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & (Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'websocketProvider'>> | Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'appId'>> | Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'baseUrl'>>)
|
|
6
|
+
export type TiptapCollabProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & (Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'websocketProvider'>> | Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'appId'>> | Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'baseUrl'>>) & Pick<AdditionalTiptapCollabProviderConfiguration, 'user'>;
|
|
6
7
|
export interface AdditionalTiptapCollabProviderConfiguration {
|
|
7
8
|
/**
|
|
8
9
|
* A Hocuspocus Cloud App ID, get one here: https://cloud.tiptap.dev
|
|
@@ -13,9 +14,11 @@ export interface AdditionalTiptapCollabProviderConfiguration {
|
|
|
13
14
|
*/
|
|
14
15
|
baseUrl?: string;
|
|
15
16
|
websocketProvider?: TiptapCollabProviderWebsocket;
|
|
17
|
+
user?: string;
|
|
16
18
|
}
|
|
17
19
|
export declare class TiptapCollabProvider extends HocuspocusProvider {
|
|
18
20
|
tiptapCollabConfigurationPrefix: string;
|
|
21
|
+
userData?: Y.PermanentUserData;
|
|
19
22
|
constructor(configuration: TiptapCollabProviderConfiguration);
|
|
20
23
|
/**
|
|
21
24
|
* note: this will only work if your server loaded @hocuspocus-pro/extension-history, or if you are on a Tiptap business plan.
|
|
@@ -38,6 +38,7 @@ export interface Extension {
|
|
|
38
38
|
onConnect?(data: onConnectPayload): Promise<any>;
|
|
39
39
|
connected?(data: connectedPayload): Promise<any>;
|
|
40
40
|
onAuthenticate?(data: onAuthenticatePayload): Promise<any>;
|
|
41
|
+
onCreateDocument?(data: onCreateDocumentPayload): Promise<any>;
|
|
41
42
|
onLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
|
|
42
43
|
afterLoadDocument?(data: afterLoadDocumentPayload): Promise<any>;
|
|
43
44
|
beforeHandleMessage?(data: beforeHandleMessagePayload): Promise<any>;
|
|
@@ -52,7 +53,7 @@ export interface Extension {
|
|
|
52
53
|
afterUnloadDocument?(data: afterUnloadDocumentPayload): Promise<any>;
|
|
53
54
|
onDestroy?(data: onDestroyPayload): Promise<any>;
|
|
54
55
|
}
|
|
55
|
-
export type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'beforeBroadcastStateless' | 'onStateless' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'afterUnloadDocument' | 'onDestroy';
|
|
56
|
+
export type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' | 'onCreateDocument' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'beforeBroadcastStateless' | 'onStateless' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'afterUnloadDocument' | 'onDestroy';
|
|
56
57
|
export type HookPayloadByName = {
|
|
57
58
|
onConfigure: onConfigurePayload;
|
|
58
59
|
onListen: onListenPayload;
|
|
@@ -60,6 +61,7 @@ export type HookPayloadByName = {
|
|
|
60
61
|
onConnect: onConnectPayload;
|
|
61
62
|
connected: connectedPayload;
|
|
62
63
|
onAuthenticate: onAuthenticatePayload;
|
|
64
|
+
onCreateDocument: onCreateDocumentPayload;
|
|
63
65
|
onLoadDocument: onLoadDocumentPayload;
|
|
64
66
|
afterLoadDocument: afterLoadDocumentPayload;
|
|
65
67
|
beforeHandleMessage: beforeHandleMessagePayload;
|
|
@@ -142,10 +144,20 @@ export interface onAuthenticatePayload {
|
|
|
142
144
|
instance: Hocuspocus;
|
|
143
145
|
requestHeaders: IncomingHttpHeaders;
|
|
144
146
|
requestParameters: URLSearchParams;
|
|
147
|
+
request: IncomingMessage;
|
|
145
148
|
socketId: string;
|
|
146
149
|
token: string;
|
|
147
150
|
connection: ConnectionConfiguration;
|
|
148
151
|
}
|
|
152
|
+
export interface onCreateDocumentPayload {
|
|
153
|
+
context: any;
|
|
154
|
+
documentName: string;
|
|
155
|
+
instance: Hocuspocus;
|
|
156
|
+
requestHeaders: IncomingHttpHeaders;
|
|
157
|
+
requestParameters: URLSearchParams;
|
|
158
|
+
socketId: string;
|
|
159
|
+
connection: ConnectionConfiguration;
|
|
160
|
+
}
|
|
149
161
|
export interface onConnectPayload {
|
|
150
162
|
context: any;
|
|
151
163
|
documentName: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/provider",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.2-rc.0",
|
|
4
4
|
"description": "hocuspocus provider",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@hocuspocus/common": "^2.12.
|
|
32
|
+
"@hocuspocus/common": "^2.12.2-rc.0",
|
|
33
33
|
"@lifeomic/attempt": "^3.0.2",
|
|
34
34
|
"lib0": "^0.2.87",
|
|
35
35
|
"ws": "^8.14.2"
|
|
@@ -4,7 +4,8 @@ import {
|
|
|
4
4
|
import { retry } from '@lifeomic/attempt'
|
|
5
5
|
import * as time from 'lib0/time'
|
|
6
6
|
import * as url from 'lib0/url'
|
|
7
|
-
import {
|
|
7
|
+
import type { MessageEvent } from 'ws'
|
|
8
|
+
import { Event } from 'ws'
|
|
8
9
|
import EventEmitter from './EventEmitter.js'
|
|
9
10
|
import { HocuspocusProvider } from './HocuspocusProvider.js'
|
|
10
11
|
import {
|
|
@@ -348,7 +349,7 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
348
349
|
this.identifier += 1
|
|
349
350
|
|
|
350
351
|
// Init the WebSocket connection
|
|
351
|
-
const ws = new this.configuration.WebSocketPolyfill(this.url
|
|
352
|
+
const ws = new this.configuration.WebSocketPolyfill(this.url)
|
|
352
353
|
ws.binaryType = 'arraybuffer'
|
|
353
354
|
ws.identifier = this.identifier
|
|
354
355
|
|
|
@@ -16,7 +16,8 @@ export type TiptapCollabProviderConfiguration =
|
|
|
16
16
|
Partial<HocuspocusProviderConfiguration> &
|
|
17
17
|
(Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'websocketProvider'>> |
|
|
18
18
|
Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'appId'>>|
|
|
19
|
-
Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'baseUrl'>>)
|
|
19
|
+
Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'baseUrl'>>) &
|
|
20
|
+
Pick<AdditionalTiptapCollabProviderConfiguration, 'user'>
|
|
20
21
|
|
|
21
22
|
export interface AdditionalTiptapCollabProviderConfiguration {
|
|
22
23
|
/**
|
|
@@ -30,11 +31,15 @@ export interface AdditionalTiptapCollabProviderConfiguration {
|
|
|
30
31
|
baseUrl?: string
|
|
31
32
|
|
|
32
33
|
websocketProvider?: TiptapCollabProviderWebsocket
|
|
34
|
+
|
|
35
|
+
user?: string
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
export class TiptapCollabProvider extends HocuspocusProvider {
|
|
36
39
|
tiptapCollabConfigurationPrefix = '__tiptapcollab__'
|
|
37
40
|
|
|
41
|
+
userData?: Y.PermanentUserData
|
|
42
|
+
|
|
38
43
|
constructor(configuration: TiptapCollabProviderConfiguration) {
|
|
39
44
|
if (!configuration.websocketProvider) {
|
|
40
45
|
configuration.websocketProvider = new TiptapCollabProviderWebsocket({ appId: (configuration as Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'appId'>>).appId, baseUrl: (configuration as Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'baseUrl'>>).baseUrl })
|
|
@@ -45,6 +50,11 @@ export class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
super(configuration as HocuspocusProviderConfiguration)
|
|
53
|
+
|
|
54
|
+
if (configuration.user) {
|
|
55
|
+
this.userData = new Y.PermanentUserData(this.document, this.document.getMap('__tiptapcollab__users'))
|
|
56
|
+
this.userData.setUserMapping(this.document, this.document.clientID, configuration.user)
|
|
57
|
+
}
|
|
48
58
|
}
|
|
49
59
|
|
|
50
60
|
/**
|