@hocuspocus/provider 2.10.0 → 2.11.1
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 +70 -48
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +70 -48
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/provider/src/TiptapCollabProvider.d.ts +5 -5
- package/dist/packages/server/src/Document.d.ts +1 -1
- package/package.json +2 -2
- package/src/TiptapCollabProvider.ts +78 -47
|
@@ -2917,26 +2917,34 @@ class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
2917
2917
|
return this.getYThreads().get(index);
|
|
2918
2918
|
}
|
|
2919
2919
|
createThread(data) {
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2920
|
+
let createdThread = {};
|
|
2921
|
+
this.document.transact(() => {
|
|
2922
|
+
const thread = new Y__namespace.Map();
|
|
2923
|
+
thread.set('id', uuidv4());
|
|
2924
|
+
thread.set('createdAt', (new Date()).toISOString());
|
|
2925
|
+
thread.set('comments', new Y__namespace.Array());
|
|
2926
|
+
this.getYThreads().push([thread]);
|
|
2927
|
+
createdThread = this.updateThread(String(thread.get('id')), data);
|
|
2928
|
+
});
|
|
2929
|
+
return createdThread;
|
|
2926
2930
|
}
|
|
2927
2931
|
updateThread(id, data) {
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
thread.set('
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2932
|
+
let updatedThread = {};
|
|
2933
|
+
this.document.transact(() => {
|
|
2934
|
+
const thread = this.getYThread(id);
|
|
2935
|
+
if (thread === null) {
|
|
2936
|
+
return null;
|
|
2937
|
+
}
|
|
2938
|
+
thread.set('updatedAt', (new Date()).toISOString());
|
|
2939
|
+
if (data.data) {
|
|
2940
|
+
thread.set('data', data.data);
|
|
2941
|
+
}
|
|
2942
|
+
if (data.resolvedAt || data.resolvedAt === null) {
|
|
2943
|
+
thread.set('resolvedAt', data.resolvedAt);
|
|
2944
|
+
}
|
|
2945
|
+
updatedThread = thread.toJSON();
|
|
2946
|
+
});
|
|
2947
|
+
return updatedThread;
|
|
2940
2948
|
}
|
|
2941
2949
|
deleteThread(id) {
|
|
2942
2950
|
const index = this.getThreadIndex(id);
|
|
@@ -2962,38 +2970,46 @@ class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
2962
2970
|
return (_b = (_a = this.getThread(threadId)) === null || _a === void 0 ? void 0 : _a.comments.find(comment => comment.id === commentId)) !== null && _b !== void 0 ? _b : null;
|
|
2963
2971
|
}
|
|
2964
2972
|
addComment(threadId, data) {
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2973
|
+
let updatedThread = {};
|
|
2974
|
+
this.document.transact(() => {
|
|
2975
|
+
const thread = this.getYThread(threadId);
|
|
2976
|
+
if (thread === null)
|
|
2977
|
+
return null;
|
|
2978
|
+
const commentMap = new Y__namespace.Map();
|
|
2979
|
+
commentMap.set('id', uuidv4());
|
|
2980
|
+
commentMap.set('createdAt', (new Date()).toISOString());
|
|
2981
|
+
thread.get('comments').push([commentMap]);
|
|
2982
|
+
this.updateComment(threadId, String(commentMap.get('id')), data);
|
|
2983
|
+
updatedThread = thread.toJSON();
|
|
2984
|
+
});
|
|
2985
|
+
return updatedThread;
|
|
2974
2986
|
}
|
|
2975
2987
|
updateComment(threadId, commentId, data) {
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2988
|
+
let updatedThread = {};
|
|
2989
|
+
this.document.transact(() => {
|
|
2990
|
+
const thread = this.getYThread(threadId);
|
|
2991
|
+
if (thread === null)
|
|
2992
|
+
return null;
|
|
2993
|
+
let comment = null;
|
|
2994
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
2995
|
+
for (const c of thread.get('comments')) {
|
|
2996
|
+
if (c.get('id') === commentId) {
|
|
2997
|
+
comment = c;
|
|
2998
|
+
break;
|
|
2999
|
+
}
|
|
2985
3000
|
}
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
3001
|
+
if (comment === null)
|
|
3002
|
+
return null;
|
|
3003
|
+
comment.set('updatedAt', (new Date()).toISOString());
|
|
3004
|
+
if (data.data) {
|
|
3005
|
+
comment.set('data', data.data);
|
|
3006
|
+
}
|
|
3007
|
+
if (data.content) {
|
|
3008
|
+
comment.set('content', data.content);
|
|
3009
|
+
}
|
|
3010
|
+
updatedThread = thread.toJSON();
|
|
3011
|
+
});
|
|
3012
|
+
return updatedThread;
|
|
2997
3013
|
}
|
|
2998
3014
|
deleteComment(threadId, commentId) {
|
|
2999
3015
|
const thread = this.getYThread(threadId);
|
|
@@ -3007,7 +3023,13 @@ class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
3007
3023
|
}
|
|
3008
3024
|
commentIndex += 1;
|
|
3009
3025
|
}
|
|
3010
|
-
if
|
|
3026
|
+
// if the first comment of a thread is deleted we also
|
|
3027
|
+
// delete the thread itself as the source comment is gone
|
|
3028
|
+
if (commentIndex === 0) {
|
|
3029
|
+
this.deleteThread(threadId);
|
|
3030
|
+
return;
|
|
3031
|
+
}
|
|
3032
|
+
if (commentIndex > 0) {
|
|
3011
3033
|
thread.get('comments').delete(commentIndex);
|
|
3012
3034
|
}
|
|
3013
3035
|
return thread.toJSON();
|