@hocuspocus/provider 2.2.2 → 2.2.3
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 +37 -0
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +37 -0
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/provider/src/TiptapCollabProvider.d.ts +15 -0
- package/dist/packages/provider/src/types.d.ts +6 -5
- package/package.json +2 -2
- package/src/MessageReceiver.ts +4 -0
- package/src/TiptapCollabProvider.ts +50 -0
- package/src/types.ts +5 -4
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AbstractType, YArrayEvent } from 'yjs';
|
|
1
2
|
import { HocuspocusProvider, HocuspocusProviderConfiguration } from './HocuspocusProvider.js';
|
|
2
3
|
import { TiptapCollabProviderWebsocket } from './TiptapCollabProviderWebsocket.js';
|
|
3
4
|
export type TiptapCollabProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & (Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'websocketProvider'>> | Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'appId'>>);
|
|
@@ -8,6 +9,20 @@ export interface AdditionalTiptapCollabProviderConfiguration {
|
|
|
8
9
|
appId?: string;
|
|
9
10
|
websocketProvider?: TiptapCollabProviderWebsocket;
|
|
10
11
|
}
|
|
12
|
+
export type AuditHistoryVersion = {
|
|
13
|
+
name?: string;
|
|
14
|
+
version: number;
|
|
15
|
+
date: number;
|
|
16
|
+
};
|
|
11
17
|
export declare class TiptapCollabProvider extends HocuspocusProvider {
|
|
18
|
+
tiptapCollabConfigurationPrefix: string;
|
|
12
19
|
constructor(configuration: TiptapCollabProviderConfiguration);
|
|
20
|
+
createVersion(name?: string): void;
|
|
21
|
+
revertToVersion(targetVersion: number): void;
|
|
22
|
+
getVersions(): AuditHistoryVersion[];
|
|
23
|
+
watchVersions(callback: Parameters<AbstractType<YArrayEvent<AuditHistoryVersion>>['observe']>[0]): void;
|
|
24
|
+
unwatchVersions(callback: Parameters<AbstractType<YArrayEvent<AuditHistoryVersion>>['unobserve']>[0]): void;
|
|
25
|
+
isAutoVersioning(): boolean;
|
|
26
|
+
enableAutoVersioning(): number;
|
|
27
|
+
disableAutoVersioning(): number;
|
|
13
28
|
}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
+
import { Encoder } from 'lib0/encoding';
|
|
2
|
+
import type { CloseEvent, Event, MessageEvent } from 'ws';
|
|
1
3
|
import { Awareness } from 'y-protocols/awareness';
|
|
2
4
|
import * as Y from 'yjs';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
+
import { IncomingMessage } from './IncomingMessage.js';
|
|
6
|
+
import { OutgoingMessage } from './OutgoingMessage.js';
|
|
5
7
|
import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.js';
|
|
6
8
|
import { AwarenessMessage } from './OutgoingMessages/AwarenessMessage.js';
|
|
7
9
|
import { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage.js';
|
|
8
10
|
import { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage.js';
|
|
9
11
|
import { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage.js';
|
|
10
12
|
import { UpdateMessage } from './OutgoingMessages/UpdateMessage.js';
|
|
11
|
-
import { IncomingMessage } from './IncomingMessage.js';
|
|
12
|
-
import { OutgoingMessage } from './OutgoingMessage.js';
|
|
13
13
|
export declare enum MessageType {
|
|
14
14
|
Sync = 0,
|
|
15
15
|
Awareness = 1,
|
|
16
16
|
Auth = 2,
|
|
17
17
|
QueryAwareness = 3,
|
|
18
18
|
Stateless = 5,
|
|
19
|
-
CLOSE = 7
|
|
19
|
+
CLOSE = 7,
|
|
20
|
+
SyncStatus = 8
|
|
20
21
|
}
|
|
21
22
|
export declare enum WebSocketStatus {
|
|
22
23
|
Connecting = "connecting",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/provider",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
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.2.
|
|
32
|
+
"@hocuspocus/common": "^2.2.3",
|
|
33
33
|
"@lifeomic/attempt": "^3.0.2",
|
|
34
34
|
"lib0": "^0.2.47",
|
|
35
35
|
"ws": "^7.5.9"
|
package/src/MessageReceiver.ts
CHANGED
|
@@ -50,6 +50,10 @@ export class MessageReceiver {
|
|
|
50
50
|
provider.receiveStateless(readVarString(message.decoder))
|
|
51
51
|
break
|
|
52
52
|
|
|
53
|
+
case MessageType.SyncStatus:
|
|
54
|
+
// nothing for now; forward-compatability
|
|
55
|
+
break
|
|
56
|
+
|
|
53
57
|
default:
|
|
54
58
|
throw new Error(`Can’t apply message of unknown type: ${type}`)
|
|
55
59
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AbstractType, YArrayEvent } from 'yjs'
|
|
1
2
|
import {
|
|
2
3
|
HocuspocusProvider,
|
|
3
4
|
HocuspocusProviderConfiguration,
|
|
@@ -20,7 +21,15 @@ export interface AdditionalTiptapCollabProviderConfiguration {
|
|
|
20
21
|
websocketProvider?: TiptapCollabProviderWebsocket
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
export type AuditHistoryVersion = {
|
|
25
|
+
name?: string;
|
|
26
|
+
version: number;
|
|
27
|
+
date: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
export class TiptapCollabProvider extends HocuspocusProvider {
|
|
31
|
+
tiptapCollabConfigurationPrefix = '__tiptapcollab__'
|
|
32
|
+
|
|
24
33
|
constructor(configuration: TiptapCollabProviderConfiguration) {
|
|
25
34
|
if (!configuration.websocketProvider) {
|
|
26
35
|
configuration.websocketProvider = new TiptapCollabProviderWebsocket({ appId: (configuration as Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'appId'>>).appId })
|
|
@@ -32,4 +41,45 @@ export class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
32
41
|
|
|
33
42
|
super(configuration as HocuspocusProviderConfiguration)
|
|
34
43
|
}
|
|
44
|
+
|
|
45
|
+
createVersion(name?: string) {
|
|
46
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
|
|
47
|
+
return this.sendStateless(JSON.stringify({ action: 'version.create', name }))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
revertToVersion(targetVersion: number) {
|
|
51
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
|
|
52
|
+
return this.sendStateless(JSON.stringify({ action: 'version.revert', version: targetVersion }))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getVersions(): AuditHistoryVersion[] {
|
|
56
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
|
|
57
|
+
return this.configuration.document.getArray<AuditHistoryVersion>(`${this.tiptapCollabConfigurationPrefix}versions`).toArray()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
watchVersions(callback: Parameters<AbstractType<YArrayEvent<AuditHistoryVersion>>['observe']>[0]) {
|
|
61
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
|
|
62
|
+
return this.configuration.document.getArray<AuditHistoryVersion>('__tiptapcollab__versions').observe(callback)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
unwatchVersions(callback: Parameters<AbstractType<YArrayEvent<AuditHistoryVersion>>['unobserve']>[0]) {
|
|
66
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
|
|
67
|
+
return this.configuration.document.getArray<AuditHistoryVersion>('__tiptapcollab__versions').unobserve(callback)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
isAutoVersioning(): boolean {
|
|
71
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
|
|
72
|
+
return !!this.configuration.document.getMap<number>(`${this.tiptapCollabConfigurationPrefix}config`).get('autoVersioning')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
enableAutoVersioning() {
|
|
76
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
|
|
77
|
+
return this.configuration.document.getMap<number>(`${this.tiptapCollabConfigurationPrefix}config`).set('autoVersioning', 1)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
disableAutoVersioning() {
|
|
81
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
|
|
82
|
+
return this.configuration.document.getMap<number>(`${this.tiptapCollabConfigurationPrefix}config`).set('autoVersioning', 0)
|
|
83
|
+
}
|
|
84
|
+
|
|
35
85
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { Encoder } from 'lib0/encoding'
|
|
2
|
+
import type { CloseEvent, Event, MessageEvent } from 'ws'
|
|
1
3
|
import { Awareness } from 'y-protocols/awareness'
|
|
2
4
|
import * as Y from 'yjs'
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
+
import { IncomingMessage } from './IncomingMessage.js'
|
|
6
|
+
import { OutgoingMessage } from './OutgoingMessage.js'
|
|
5
7
|
import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.js'
|
|
6
8
|
import { AwarenessMessage } from './OutgoingMessages/AwarenessMessage.js'
|
|
7
9
|
import { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage.js'
|
|
8
10
|
import { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage.js'
|
|
9
11
|
import { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage.js'
|
|
10
12
|
import { UpdateMessage } from './OutgoingMessages/UpdateMessage.js'
|
|
11
|
-
import { IncomingMessage } from './IncomingMessage.js'
|
|
12
|
-
import { OutgoingMessage } from './OutgoingMessage.js'
|
|
13
13
|
|
|
14
14
|
export enum MessageType {
|
|
15
15
|
Sync = 0,
|
|
@@ -18,6 +18,7 @@ export enum MessageType {
|
|
|
18
18
|
QueryAwareness = 3,
|
|
19
19
|
Stateless = 5,
|
|
20
20
|
CLOSE = 7,
|
|
21
|
+
SyncStatus = 8,
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export enum WebSocketStatus {
|