@hocuspocus/provider 2.9.2-rc.0 → 2.11.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.
@@ -121,7 +121,7 @@ export declare class HocuspocusProvider extends EventEmitter {
121
121
  set synced(state: boolean);
122
122
  receiveStateless(payload: string): void;
123
123
  get isAuthenticationRequired(): boolean;
124
- connect(): Promise<unknown>;
124
+ connect(): Promise<any>;
125
125
  disconnect(): void;
126
126
  onOpen(event: Event): Promise<void>;
127
127
  getToken(): Promise<string | null>;
@@ -102,7 +102,7 @@ export declare class HocuspocusProviderWebsocket extends EventEmitter {
102
102
  receivedOnStatusPayload?: onStatusParameters | undefined;
103
103
  onOpen(event: Event): Promise<void>;
104
104
  onStatus(data: onStatusParameters): Promise<void>;
105
- attach(provider: HocuspocusProvider): void;
105
+ attach(provider: HocuspocusProvider): Promise<any> | undefined;
106
106
  detach(provider: HocuspocusProvider): void;
107
107
  setConfiguration(configuration?: Partial<HocuspocusProviderWebsocketConfiguration>): void;
108
108
  cancelWebsocketRetry?: () => void;
@@ -45,13 +45,13 @@ export declare class TiptapCollabProvider extends HocuspocusProvider {
45
45
  private getThreadIndex;
46
46
  getThread<Data, CommentData>(id: string): TCollabThread<Data, CommentData> | null;
47
47
  private getYThread;
48
- createThread(data: TCollabThread): TCollabThread | null;
49
- updateThread(id: TCollabThread['id'], data: Pick<TCollabThread, 'data'>): TCollabThread | null;
48
+ createThread(data: Omit<TCollabThread, 'id' | 'createdAt' | 'updatedAt' | 'comments'>): TCollabThread | null;
49
+ updateThread(id: TCollabThread['id'], data: Partial<Pick<TCollabThread, 'data' | 'resolvedAt'>>): TCollabThread | null;
50
50
  deleteThread(id: TCollabThread['id']): void;
51
51
  getThreadComments(threadId: TCollabThread['id']): TCollabComment[] | null;
52
52
  getThreadComment(threadId: TCollabThread['id'], commentId: TCollabComment['id']): TCollabComment | null;
53
- addComment(threadId: TCollabThread['id'], data: TCollabComment): TCollabThread | null;
54
- updateComment(threadId: TCollabThread['id'], commentId: TCollabComment['id'], data: TCollabComment): TCollabThread | null;
53
+ addComment(threadId: TCollabThread['id'], data: Omit<TCollabComment, 'id' | 'updatedAt' | 'createdAt'>): TCollabThread | null;
54
+ updateComment(threadId: TCollabThread['id'], commentId: TCollabComment['id'], data: Partial<Pick<TCollabComment, 'data' | 'content'>>): TCollabThread | null;
55
55
  deleteComment(threadId: TCollabThread['id'], commentId: TCollabComment['id']): TCollabThread | null;
56
56
  watchThreads(callback: () => void): void;
57
57
  unwatchThreads(callback: () => void): void;
@@ -88,6 +88,7 @@ export type TCollabThread<Data = any, CommentData = any> = {
88
88
  id: string;
89
89
  createdAt: number;
90
90
  updatedAt: number;
91
+ resolvedAt?: string;
91
92
  comments: TCollabComment<CommentData>[];
92
93
  data: Data;
93
94
  };
@@ -87,7 +87,7 @@ export declare class Document extends Doc {
87
87
  /**
88
88
  * Broadcast stateless message to all connections
89
89
  */
90
- broadcastStateless(payload: string): void;
90
+ broadcastStateless(payload: string, filter?: (conn: Connection) => boolean): void;
91
91
  destroy(): void;
92
92
  }
93
93
  export default Document;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hocuspocus/provider",
3
- "version": "2.9.2-rc.0",
3
+ "version": "2.11.0",
4
4
  "description": "hocuspocus provider",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
@@ -29,10 +29,9 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@hocuspocus/common": "^2.9.2-rc.0",
32
+ "@hocuspocus/common": "^2.11.0",
33
33
  "@lifeomic/attempt": "^3.0.2",
34
34
  "lib0": "^0.2.87",
35
- "uuid": "^9.0.0",
36
35
  "ws": "^8.14.2"
37
36
  },
38
37
  "peerDependencies": {
@@ -367,7 +367,9 @@ export class HocuspocusProvider extends EventEmitter {
367
367
  this.subscribeToBroadcastChannel()
368
368
  }
369
369
 
370
- return this.configuration.websocketProvider.connect()
370
+ this.configuration.websocketProvider.shouldConnect = true
371
+
372
+ return this.configuration.websocketProvider.attach(this)
371
373
  }
372
374
 
373
375
  disconnect() {
@@ -217,10 +217,11 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
217
217
  }
218
218
 
219
219
  attach(provider: HocuspocusProvider) {
220
+ let connectPromise: Promise<any> | undefined
220
221
  this.configuration.providerMap.set(provider.configuration.name, provider)
221
222
 
222
223
  if (this.status === WebSocketStatus.Disconnected && this.shouldConnect) {
223
- this.connect()
224
+ connectPromise = this.connect()
224
225
  }
225
226
 
226
227
  if (this.receivedOnOpenPayload) {
@@ -230,6 +231,8 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
230
231
  if (this.receivedOnStatusPayload) {
231
232
  provider.onStatus(this.receivedOnStatusPayload)
232
233
  }
234
+
235
+ return connectPromise
233
236
  }
234
237
 
235
238
  detach(provider: HocuspocusProvider) {
@@ -141,7 +141,7 @@ export class TiptapCollabProvider extends HocuspocusProvider {
141
141
  return this.getYThreads().get(index)
142
142
  }
143
143
 
144
- createThread(data: TCollabThread) {
144
+ createThread(data: Omit<TCollabThread, 'id' | 'createdAt' | 'updatedAt' | 'comments'>) {
145
145
  const thread = new Y.Map()
146
146
  thread.set('id', uuidv4())
147
147
  thread.set('createdAt', (new Date()).toISOString())
@@ -151,7 +151,7 @@ export class TiptapCollabProvider extends HocuspocusProvider {
151
151
  return this.updateThread(String(thread.get('id')), data)
152
152
  }
153
153
 
154
- updateThread(id: TCollabThread['id'], data: Pick<TCollabThread, 'data'>) {
154
+ updateThread(id: TCollabThread['id'], data: Partial<Pick<TCollabThread, 'data' | 'resolvedAt'>>) {
155
155
  const thread = this.getYThread(id)
156
156
 
157
157
  if (thread === null) {
@@ -159,7 +159,14 @@ export class TiptapCollabProvider extends HocuspocusProvider {
159
159
  }
160
160
 
161
161
  thread.set('updatedAt', (new Date()).toISOString())
162
- thread.set('data', data.data)
162
+
163
+ if (data.data) {
164
+ thread.set('data', data.data)
165
+ }
166
+
167
+ if (data.resolvedAt || data.resolvedAt === null) {
168
+ thread.set('resolvedAt', data.resolvedAt)
169
+ }
163
170
 
164
171
  return thread.toJSON() as TCollabThread
165
172
  }
@@ -194,7 +201,7 @@ export class TiptapCollabProvider extends HocuspocusProvider {
194
201
  return this.getThread(threadId)?.comments.find(comment => comment.id === commentId) ?? null
195
202
  }
196
203
 
197
- addComment(threadId: TCollabThread['id'], data: TCollabComment) {
204
+ addComment(threadId: TCollabThread['id'], data: Omit<TCollabComment, 'id' | 'updatedAt' | 'createdAt'>) {
198
205
  const thread = this.getYThread(threadId)
199
206
 
200
207
  if (thread === null) return null
@@ -209,7 +216,7 @@ export class TiptapCollabProvider extends HocuspocusProvider {
209
216
  return thread.toJSON() as TCollabThread
210
217
  }
211
218
 
212
- updateComment(threadId: TCollabThread['id'], commentId: TCollabComment['id'], data: TCollabComment) {
219
+ updateComment(threadId: TCollabThread['id'], commentId: TCollabComment['id'], data: Partial<Pick<TCollabComment, 'data' | 'content'>>) {
213
220
  const thread = this.getYThread(threadId)
214
221
 
215
222
  if (thread === null) return null
@@ -226,8 +233,14 @@ export class TiptapCollabProvider extends HocuspocusProvider {
226
233
  if (comment === null) return null
227
234
 
228
235
  comment.set('updatedAt', (new Date()).toISOString())
229
- comment.set('data', data.data)
230
- comment.set('content', data.content)
236
+
237
+ if (data.data) {
238
+ comment.set('data', data.data)
239
+ }
240
+
241
+ if (data.content) {
242
+ comment.set('content', data.content)
243
+ }
231
244
 
232
245
  return thread.toJSON() as TCollabThread
233
246
  }
package/src/types.ts CHANGED
@@ -110,6 +110,7 @@ export type TCollabThread<Data = any, CommentData = any> = {
110
110
  id: string;
111
111
  createdAt: number;
112
112
  updatedAt: number;
113
+ resolvedAt?: string; // (new Date()).toISOString()
113
114
  comments: TCollabComment<CommentData>[];
114
115
  data: Data
115
116
  }