@hocuspocus/provider 2.14.0 → 2.15.1-rc.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 +61 -7
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +61 -7
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/provider/src/TiptapCollabProvider.d.ts +17 -6
- package/dist/packages/provider/src/types.d.ts +28 -0
- package/dist/packages/server/src/Hocuspocus.d.ts +1 -1
- package/dist/tests/utils/newHocuspocusProvider.d.ts +2 -2
- package/package.json +2 -2
- package/src/TiptapCollabProvider.ts +85 -11
- package/src/types.ts +32 -0
|
@@ -2848,6 +2848,13 @@ const defaultDeleteCommentOptions = {
|
|
|
2848
2848
|
deleteContent: false,
|
|
2849
2849
|
deleteThread: false,
|
|
2850
2850
|
};
|
|
2851
|
+
const defaultGetThreadsOptions = {
|
|
2852
|
+
types: ['unarchived'],
|
|
2853
|
+
};
|
|
2854
|
+
const defaultDeleteThreadOptions = {
|
|
2855
|
+
deleteComments: false,
|
|
2856
|
+
force: false,
|
|
2857
|
+
};
|
|
2851
2858
|
class TiptapCollabProvider extends HocuspocusProvider {
|
|
2852
2859
|
constructor(configuration) {
|
|
2853
2860
|
if (!configuration.websocketProvider) {
|
|
@@ -2913,10 +2920,24 @@ class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
2913
2920
|
}
|
|
2914
2921
|
/**
|
|
2915
2922
|
* Finds all threads in the document and returns them as JSON objects
|
|
2923
|
+
* @options Options to control the output of the threads (e.g. include deleted threads)
|
|
2916
2924
|
* @returns An array of threads as JSON objects
|
|
2917
2925
|
*/
|
|
2918
|
-
getThreads() {
|
|
2919
|
-
|
|
2926
|
+
getThreads(options) {
|
|
2927
|
+
const { types } = { ...defaultGetThreadsOptions, ...options };
|
|
2928
|
+
const threads = this.getYThreads().toJSON();
|
|
2929
|
+
if ((types === null || types === void 0 ? void 0 : types.includes('archived')) && (types === null || types === void 0 ? void 0 : types.includes('unarchived'))) {
|
|
2930
|
+
return threads;
|
|
2931
|
+
}
|
|
2932
|
+
return threads.filter(currentThead => {
|
|
2933
|
+
if ((types === null || types === void 0 ? void 0 : types.includes('archived')) && currentThead.deletedAt) {
|
|
2934
|
+
return true;
|
|
2935
|
+
}
|
|
2936
|
+
if ((types === null || types === void 0 ? void 0 : types.includes('unarchived')) && !currentThead.deletedAt) {
|
|
2937
|
+
return true;
|
|
2938
|
+
}
|
|
2939
|
+
return false;
|
|
2940
|
+
});
|
|
2920
2941
|
}
|
|
2921
2942
|
/**
|
|
2922
2943
|
* Find the index of a thread by its id
|
|
@@ -2927,7 +2948,7 @@ class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
2927
2948
|
let index = null;
|
|
2928
2949
|
let i = 0;
|
|
2929
2950
|
// eslint-disable-next-line no-restricted-syntax
|
|
2930
|
-
for (const thread of this.getThreads()) {
|
|
2951
|
+
for (const thread of this.getThreads({ types: ['archived', 'unarchived'] })) {
|
|
2931
2952
|
if (thread.id === id) {
|
|
2932
2953
|
index = i;
|
|
2933
2954
|
break;
|
|
@@ -2973,6 +2994,7 @@ class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
2973
2994
|
thread.set('createdAt', (new Date()).toISOString());
|
|
2974
2995
|
thread.set('comments', new Y__namespace.Array());
|
|
2975
2996
|
thread.set('deletedComments', new Y__namespace.Array());
|
|
2997
|
+
thread.set('deletedAt', null);
|
|
2976
2998
|
this.getYThreads().push([thread]);
|
|
2977
2999
|
createdThread = this.updateThread(String(thread.get('id')), data);
|
|
2978
3000
|
});
|
|
@@ -3003,16 +3025,45 @@ class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
3003
3025
|
return updatedThread;
|
|
3004
3026
|
}
|
|
3005
3027
|
/**
|
|
3006
|
-
*
|
|
3028
|
+
* Handle the deletion of a thread. By default, the thread and it's comments are not deleted, but marked as deleted
|
|
3029
|
+
* via the `deletedAt` property. Forceful deletion can be enabled by setting the `force` option to `true`.
|
|
3030
|
+
*
|
|
3031
|
+
* If you only want to delete the comments of a thread, you can set the `deleteComments` option to `true`.
|
|
3007
3032
|
* @param id The thread id
|
|
3008
|
-
* @
|
|
3033
|
+
* @param options A set of options that control how the thread is deleted
|
|
3034
|
+
* @returns The deleted thread or null if the thread is not found
|
|
3009
3035
|
*/
|
|
3010
|
-
deleteThread(id) {
|
|
3036
|
+
deleteThread(id, options) {
|
|
3037
|
+
const { deleteComments, force } = { ...defaultDeleteThreadOptions, ...options };
|
|
3011
3038
|
const index = this.getThreadIndex(id);
|
|
3012
3039
|
if (index === null) {
|
|
3040
|
+
return null;
|
|
3041
|
+
}
|
|
3042
|
+
if (force) {
|
|
3043
|
+
this.getYThreads().delete(index, 1);
|
|
3013
3044
|
return;
|
|
3014
3045
|
}
|
|
3015
|
-
this.getYThreads().
|
|
3046
|
+
const thread = this.getYThreads().get(index);
|
|
3047
|
+
thread.set('deletedAt', (new Date()).toISOString());
|
|
3048
|
+
if (deleteComments) {
|
|
3049
|
+
thread.set('comments', new Y__namespace.Array());
|
|
3050
|
+
thread.set('deletedComments', new Y__namespace.Array());
|
|
3051
|
+
}
|
|
3052
|
+
return thread.toJSON();
|
|
3053
|
+
}
|
|
3054
|
+
/**
|
|
3055
|
+
* Tries to restore a deleted thread
|
|
3056
|
+
* @param id The thread id
|
|
3057
|
+
* @returns The restored thread or null if the thread is not found
|
|
3058
|
+
*/
|
|
3059
|
+
restoreThread(id) {
|
|
3060
|
+
const index = this.getThreadIndex(id);
|
|
3061
|
+
if (index === null) {
|
|
3062
|
+
return null;
|
|
3063
|
+
}
|
|
3064
|
+
const thread = this.getYThreads().get(index);
|
|
3065
|
+
thread.set('deletedAt', null);
|
|
3066
|
+
return thread.toJSON();
|
|
3016
3067
|
}
|
|
3017
3068
|
/**
|
|
3018
3069
|
* Returns comments from a thread, either deleted or not
|
|
@@ -3138,6 +3189,9 @@ class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
3138
3189
|
newComment.set('deletedAt', (new Date()).toISOString());
|
|
3139
3190
|
newComment.set('data', comment.get('data'));
|
|
3140
3191
|
newComment.set('content', deleteContent ? null : comment.get('content'));
|
|
3192
|
+
if (!thread.get('deletedComments')) {
|
|
3193
|
+
thread.set('deletedComments', new Y__namespace.Array());
|
|
3194
|
+
}
|
|
3141
3195
|
thread.get('deletedComments').push([newComment]);
|
|
3142
3196
|
thread.get('comments').delete(commentIndex);
|
|
3143
3197
|
return thread.toJSON();
|