@hocuspocus/common 2.14.0 → 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.
@@ -2,7 +2,7 @@ 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 { DeleteCommentOptions, TCollabComment, TCollabThread, THistoryVersion } from './types.js';
5
+ import { type DeleteCommentOptions, type DeleteThreadOptions, type GetThreadsOptions, type TCollabComment, type TCollabThread, type THistoryVersion } from './types.js';
6
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
7
  /**
8
8
  * Pass `true` if you want to delete a thread when the first comment is deleted.
@@ -55,9 +55,10 @@ export declare class TiptapCollabProvider extends HocuspocusProvider {
55
55
  private getYThreads;
56
56
  /**
57
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)
58
59
  * @returns An array of threads as JSON objects
59
60
  */
60
- getThreads<Data, CommentData>(): TCollabThread<Data, CommentData>[];
61
+ getThreads<Data, CommentData>(options?: GetThreadsOptions): TCollabThread<Data, CommentData>[];
61
62
  /**
62
63
  * Find the index of a thread by its id
63
64
  * @param id The thread id
@@ -81,7 +82,7 @@ export declare class TiptapCollabProvider extends HocuspocusProvider {
81
82
  * @param data The thread data
82
83
  * @returns The created thread
83
84
  */
84
- createThread(data: Omit<TCollabThread, 'id' | 'createdAt' | 'updatedAt' | 'comments' | 'deletedComments'>): TCollabThread;
85
+ createThread(data: Omit<TCollabThread, 'id' | 'createdAt' | 'updatedAt' | 'deletedAt' | 'comments' | 'deletedComments'>): TCollabThread;
85
86
  /**
86
87
  * Update a specific thread
87
88
  * @param id The thread id
@@ -92,11 +93,21 @@ export declare class TiptapCollabProvider extends HocuspocusProvider {
92
93
  resolvedAt: TCollabThread['resolvedAt'] | null;
93
94
  }>): TCollabThread;
94
95
  /**
95
- * Delete a specific thread and all its comments
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
96
107
  * @param id The thread id
97
- * @returns void
108
+ * @returns The restored thread or null if the thread is not found
98
109
  */
99
- deleteThread(id: TCollabThread['id']): void;
110
+ restoreThread(id: TCollabThread['id']): TCollabThread | null;
100
111
  /**
101
112
  * Returns comments from a thread, either deleted or not
102
113
  * @param threadId The thread id
@@ -88,6 +88,7 @@ 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>[];
93
94
  deletedComments: TCollabComment<CommentData>[];
@@ -156,3 +157,30 @@ export type DeleteCommentOptions = {
156
157
  */
157
158
  deleteContent?: boolean;
158
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.14.0",
4
+ "version": "2.15.0",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
7
7
  "hocuspocus"