@hocuspocus/provider 2.2.2 → 2.3.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 +797 -689
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +799 -691
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/extension-redis/src/Redis.d.ts +1 -1
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +23 -8
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +2 -1
- package/dist/packages/provider/src/MessageReceiver.d.ts +2 -1
- package/dist/packages/provider/src/TiptapCollabProvider.d.ts +15 -0
- package/dist/packages/provider/src/types.d.ts +6 -5
- package/dist/packages/server/src/Hocuspocus.d.ts +3 -2
- package/dist/packages/server/src/MessageReceiver.d.ts +1 -1
- package/dist/packages/server/src/OutgoingMessage.d.ts +1 -0
- package/dist/packages/server/src/types.d.ts +30 -6
- package/dist/tests/provider/hasUnsyncedChanges.d.ts +1 -0
- package/dist/tests/server/afterUnloadDocument.d.ts +1 -0
- package/package.json +3 -3
- package/src/HocuspocusProvider.ts +60 -31
- package/src/HocuspocusProviderWebsocket.ts +23 -7
- package/src/MessageReceiver.ts +12 -9
- package/src/TiptapCollabProvider.ts +50 -0
- package/src/types.ts +5 -4
package/src/MessageReceiver.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as awarenessProtocol from 'y-protocols/awareness'
|
|
2
|
-
import { readSyncMessage, messageYjsSyncStep2, messageYjsUpdate } from 'y-protocols/sync'
|
|
3
1
|
import { readAuthMessage } from '@hocuspocus/common'
|
|
4
|
-
import { readVarString } from 'lib0/decoding'
|
|
5
|
-
import
|
|
2
|
+
import { readVarInt, readVarString } from 'lib0/decoding'
|
|
3
|
+
import * as awarenessProtocol from 'y-protocols/awareness'
|
|
4
|
+
import { messageYjsSyncStep2, readSyncMessage } from 'y-protocols/sync'
|
|
6
5
|
import { HocuspocusProvider } from './HocuspocusProvider.js'
|
|
7
6
|
import { IncomingMessage } from './IncomingMessage.js'
|
|
8
7
|
import { OutgoingMessage } from './OutgoingMessage.js'
|
|
8
|
+
import { MessageType } from './types.js'
|
|
9
9
|
|
|
10
10
|
export class MessageReceiver {
|
|
11
11
|
|
|
@@ -23,7 +23,7 @@ export class MessageReceiver {
|
|
|
23
23
|
return this
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
public apply(provider: HocuspocusProvider, emitSynced
|
|
26
|
+
public apply(provider: HocuspocusProvider, emitSynced: boolean) {
|
|
27
27
|
const { message } = this
|
|
28
28
|
const type = message.readVarUint()
|
|
29
29
|
|
|
@@ -50,6 +50,9 @@ export class MessageReceiver {
|
|
|
50
50
|
provider.receiveStateless(readVarString(message.decoder))
|
|
51
51
|
break
|
|
52
52
|
|
|
53
|
+
case MessageType.SyncStatus:
|
|
54
|
+
this.applySyncStatusMessage(provider, readVarInt(message.decoder) === 1)
|
|
55
|
+
break
|
|
53
56
|
default:
|
|
54
57
|
throw new Error(`Can’t apply message of unknown type: ${type}`)
|
|
55
58
|
}
|
|
@@ -85,11 +88,11 @@ export class MessageReceiver {
|
|
|
85
88
|
if (emitSynced && syncMessageType === messageYjsSyncStep2) {
|
|
86
89
|
provider.synced = true
|
|
87
90
|
}
|
|
91
|
+
}
|
|
88
92
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
+
applySyncStatusMessage(provider: HocuspocusProvider, applied: boolean) {
|
|
94
|
+
if (applied) {
|
|
95
|
+
provider.decrementUnsyncedChanges()
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
|
|
@@ -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 {
|