@hocuspocus/common 2.13.7 → 2.15.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.
@@ -88,6 +88,8 @@ export declare class HocuspocusProvider extends EventEmitter {
88
88
  intervals: any;
89
89
  isConnected: boolean;
90
90
  constructor(configuration: HocuspocusProviderConfiguration);
91
+ boundDocumentUpdateHandler: (update: Uint8Array, origin: any) => void;
92
+ boundAwarenessUpdateHandler: ({ added, updated, removed }: any, origin: any) => void;
91
93
  boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
92
94
  boundPageHide: () => void;
93
95
  boundOnOpen: (event: Event) => Promise<void>;
@@ -2,8 +2,13 @@ import type { AbstractType, YArrayEvent } from 'yjs';
2
2
  import * as Y from 'yjs';
3
3
  import { HocuspocusProvider, HocuspocusProviderConfiguration } from './HocuspocusProvider.js';
4
4
  import { TiptapCollabProviderWebsocket } from './TiptapCollabProviderWebsocket.js';
5
- import type { TCollabComment, TCollabThread, THistoryVersion } from './types.js';
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'>;
5
+ import { type DeleteCommentOptions, type DeleteThreadOptions, type GetThreadsOptions, type TCollabComment, type TCollabThread, type THistoryVersion } from './types.js';
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'> & {
7
+ /**
8
+ * Pass `true` if you want to delete a thread when the first comment is deleted.
9
+ */
10
+ deleteThreadOnFirstCommentDelete?: boolean;
11
+ };
7
12
  export interface AdditionalTiptapCollabProviderConfiguration {
8
13
  /**
9
14
  * A Hocuspocus Cloud App ID, get one here: https://cloud.tiptap.dev
@@ -43,21 +48,114 @@ export declare class TiptapCollabProvider extends HocuspocusProvider {
43
48
  isAutoVersioning(): boolean;
44
49
  enableAutoVersioning(): 1;
45
50
  disableAutoVersioning(): 0;
51
+ /**
52
+ * Returns all users in the document as Y.Map objects
53
+ * @returns An array of Y.Map objects
54
+ */
46
55
  private getYThreads;
47
- getThreads<Data, CommentData>(): TCollabThread<Data, CommentData>[];
56
+ /**
57
+ * Finds all threads in the document and returns them as JSON objects
58
+ * @options Options to control the output of the threads (e.g. include deleted threads)
59
+ * @returns An array of threads as JSON objects
60
+ */
61
+ getThreads<Data, CommentData>(options?: GetThreadsOptions): TCollabThread<Data, CommentData>[];
62
+ /**
63
+ * Find the index of a thread by its id
64
+ * @param id The thread id
65
+ * @returns The index of the thread or null if not found
66
+ */
48
67
  private getThreadIndex;
68
+ /**
69
+ * Gets a single thread by its id
70
+ * @param id The thread id
71
+ * @returns The thread as a JSON object or null if not found
72
+ */
49
73
  getThread<Data, CommentData>(id: string): TCollabThread<Data, CommentData> | null;
74
+ /**
75
+ * Gets a single thread by its id as a Y.Map object
76
+ * @param id The thread id
77
+ * @returns The thread as a Y.Map object or null if not found
78
+ */
50
79
  private getYThread;
51
- createThread(data: Omit<TCollabThread, 'id' | 'createdAt' | 'updatedAt' | 'comments'>): TCollabThread;
80
+ /**
81
+ * Create a new thread
82
+ * @param data The thread data
83
+ * @returns The created thread
84
+ */
85
+ createThread(data: Omit<TCollabThread, 'id' | 'createdAt' | 'updatedAt' | 'deletedAt' | 'comments' | 'deletedComments'>): TCollabThread;
86
+ /**
87
+ * Update a specific thread
88
+ * @param id The thread id
89
+ * @param data New data for the thread
90
+ * @returns The updated thread or null if the thread is not found
91
+ */
52
92
  updateThread(id: TCollabThread['id'], data: Partial<Pick<TCollabThread, 'data'> & {
53
93
  resolvedAt: TCollabThread['resolvedAt'] | null;
54
94
  }>): TCollabThread;
55
- deleteThread(id: TCollabThread['id']): void;
56
- getThreadComments(threadId: TCollabThread['id']): TCollabComment[] | null;
57
- getThreadComment(threadId: TCollabThread['id'], commentId: TCollabComment['id']): TCollabComment | null;
95
+ /**
96
+ * Handle the deletion of a thread. By default, the thread and it's comments are not deleted, but marked as deleted
97
+ * via the `deletedAt` property. Forceful deletion can be enabled by setting the `force` option to `true`.
98
+ *
99
+ * If you only want to delete the comments of a thread, you can set the `deleteComments` option to `true`.
100
+ * @param id The thread id
101
+ * @param options A set of options that control how the thread is deleted
102
+ * @returns The deleted thread or null if the thread is not found
103
+ */
104
+ deleteThread(id: TCollabThread['id'], options?: DeleteThreadOptions): TCollabThread | null | undefined;
105
+ /**
106
+ * Tries to restore a deleted thread
107
+ * @param id The thread id
108
+ * @returns The restored thread or null if the thread is not found
109
+ */
110
+ restoreThread(id: TCollabThread['id']): TCollabThread | null;
111
+ /**
112
+ * Returns comments from a thread, either deleted or not
113
+ * @param threadId The thread id
114
+ * @param includeDeleted If you want to include deleted comments, defaults to `false`
115
+ * @returns The comments or null if the thread is not found
116
+ */
117
+ getThreadComments(threadId: TCollabThread['id'], includeDeleted?: boolean): TCollabComment[] | null;
118
+ /**
119
+ * Get a single comment from a specific thread
120
+ * @param threadId The thread id
121
+ * @param commentId The comment id
122
+ * @param includeDeleted If you want to include deleted comments in the search
123
+ * @returns The comment or null if not found
124
+ */
125
+ getThreadComment(threadId: TCollabThread['id'], commentId: TCollabComment['id'], includeDeleted?: boolean): TCollabComment | null;
126
+ /**
127
+ * Adds a comment to a thread
128
+ * @param threadId The thread id
129
+ * @param data The comment data
130
+ * @returns The updated thread or null if the thread is not found
131
+ * @example addComment('123', { content: 'Hello world', data: { author: 'Maria Doe' } })
132
+ */
58
133
  addComment(threadId: TCollabThread['id'], data: Omit<TCollabComment, 'id' | 'updatedAt' | 'createdAt'>): TCollabThread;
134
+ /**
135
+ * Update a comment in a thread
136
+ * @param threadId The thread id
137
+ * @param commentId The comment id
138
+ * @param data The new comment data
139
+ * @returns The updated thread or null if the thread or comment is not found
140
+ * @example updateComment('123', { content: 'The new content', data: { attachments: ['file1.jpg'] }})
141
+ */
59
142
  updateComment(threadId: TCollabThread['id'], commentId: TCollabComment['id'], data: Partial<Pick<TCollabComment, 'data' | 'content'>>): TCollabThread;
60
- deleteComment(threadId: TCollabThread['id'], commentId: TCollabComment['id']): TCollabThread | null | undefined;
143
+ /**
144
+ * Deletes a comment from a thread
145
+ * @param threadId The thread id
146
+ * @param commentId The comment id
147
+ * @param options A set of options that control how the comment is deleted
148
+ * @returns The updated thread or null if the thread or comment is not found
149
+ */
150
+ deleteComment(threadId: TCollabThread['id'], commentId: TCollabComment['id'], options: DeleteCommentOptions): TCollabThread | null | undefined;
151
+ /**
152
+ * Start watching threads for changes
153
+ * @param callback The callback function to be called when a thread changes
154
+ */
61
155
  watchThreads(callback: () => void): void;
156
+ /**
157
+ * Stop watching threads for changes
158
+ * @param callback The callback function to be removed
159
+ */
62
160
  unwatchThreads(callback: () => void): void;
63
161
  }
@@ -88,14 +88,17 @@ export type TCollabThread<Data = any, CommentData = any> = {
88
88
  id: string;
89
89
  createdAt: number;
90
90
  updatedAt: number;
91
+ deletedAt: number | null;
91
92
  resolvedAt?: string;
92
93
  comments: TCollabComment<CommentData>[];
94
+ deletedComments: TCollabComment<CommentData>[];
93
95
  data: Data;
94
96
  };
95
97
  export type TCollabComment<Data = any> = {
96
98
  id: string;
97
- createdAt: number;
98
- updatedAt: number;
99
+ createdAt: string;
100
+ updatedAt: string;
101
+ deletedAt?: string;
99
102
  data: Data;
100
103
  content: any;
101
104
  };
@@ -144,3 +147,40 @@ export type THistoryDocumentRevertedEvent = {
144
147
  event: 'document.reverted';
145
148
  version: number;
146
149
  };
150
+ export type DeleteCommentOptions = {
151
+ /**
152
+ * If `true`, the thread will also be deleted if the deleted comment was the first comment in the thread.
153
+ */
154
+ deleteThread?: boolean;
155
+ /**
156
+ * If `true`, will remove the content of the deleted comment
157
+ */
158
+ deleteContent?: boolean;
159
+ };
160
+ export type DeleteThreadOptions = {
161
+ /**
162
+ * If `true`, will remove the comments on the thread,
163
+ * otherwise will only mark the thread as deleted
164
+ * and keep the comments
165
+ * @default false
166
+ */
167
+ deleteComments?: boolean;
168
+ /**
169
+ * If `true`, will forcefully remove the thread and all comments,
170
+ * otherwise will only mark the thread as deleted
171
+ * and keep the comments
172
+ * @default false
173
+ */
174
+ force?: boolean;
175
+ };
176
+ /**
177
+ * The type of thread
178
+ */
179
+ export type ThreadType = 'archived' | 'unarchived';
180
+ export type GetThreadsOptions = {
181
+ /**
182
+ * The types of threads to get
183
+ * @default ['unarchived']
184
+ */
185
+ types?: Array<ThreadType>;
186
+ };
@@ -8,6 +8,6 @@ export declare class MessageReceiver {
8
8
  defaultTransactionOrigin?: string;
9
9
  constructor(message: IncomingMessage, logger: Debugger, defaultTransactionOrigin?: string);
10
10
  apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void;
11
- readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 1 | 2;
11
+ readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 2 | 1;
12
12
  applyQueryAwarenessMessage(document: Document, reply?: (message: Uint8Array) => void): void;
13
13
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hocuspocus/common",
3
3
  "description": "shared code for multiple Hocuspocus packages",
4
- "version": "2.13.7",
4
+ "version": "2.15.0",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
7
7
  "hocuspocus"