@hocuspocus/provider 2.11.0 → 2.11.2
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 +7 -5
- package/package.json +2 -2
- package/src/TiptapCollabProvider.ts +79 -46
|
@@ -2893,26 +2893,34 @@ class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
2893
2893
|
return this.getYThreads().get(index);
|
|
2894
2894
|
}
|
|
2895
2895
|
createThread(data) {
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2896
|
+
let createdThread = {};
|
|
2897
|
+
this.document.transact(() => {
|
|
2898
|
+
const thread = new Y.Map();
|
|
2899
|
+
thread.set('id', uuidv4());
|
|
2900
|
+
thread.set('createdAt', (new Date()).toISOString());
|
|
2901
|
+
thread.set('comments', new Y.Array());
|
|
2902
|
+
this.getYThreads().push([thread]);
|
|
2903
|
+
createdThread = this.updateThread(String(thread.get('id')), data);
|
|
2904
|
+
});
|
|
2905
|
+
return createdThread;
|
|
2902
2906
|
}
|
|
2903
2907
|
updateThread(id, data) {
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
thread.set('
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2908
|
+
let updatedThread = {};
|
|
2909
|
+
this.document.transact(() => {
|
|
2910
|
+
const thread = this.getYThread(id);
|
|
2911
|
+
if (thread === null) {
|
|
2912
|
+
return null;
|
|
2913
|
+
}
|
|
2914
|
+
thread.set('updatedAt', (new Date()).toISOString());
|
|
2915
|
+
if (data.data) {
|
|
2916
|
+
thread.set('data', data.data);
|
|
2917
|
+
}
|
|
2918
|
+
if (data.resolvedAt || data.resolvedAt === null) {
|
|
2919
|
+
thread.set('resolvedAt', data.resolvedAt);
|
|
2920
|
+
}
|
|
2921
|
+
updatedThread = thread.toJSON();
|
|
2922
|
+
});
|
|
2923
|
+
return updatedThread;
|
|
2916
2924
|
}
|
|
2917
2925
|
deleteThread(id) {
|
|
2918
2926
|
const index = this.getThreadIndex(id);
|
|
@@ -2938,38 +2946,46 @@ class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
2938
2946
|
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;
|
|
2939
2947
|
}
|
|
2940
2948
|
addComment(threadId, data) {
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2949
|
+
let updatedThread = {};
|
|
2950
|
+
this.document.transact(() => {
|
|
2951
|
+
const thread = this.getYThread(threadId);
|
|
2952
|
+
if (thread === null)
|
|
2953
|
+
return null;
|
|
2954
|
+
const commentMap = new Y.Map();
|
|
2955
|
+
commentMap.set('id', uuidv4());
|
|
2956
|
+
commentMap.set('createdAt', (new Date()).toISOString());
|
|
2957
|
+
thread.get('comments').push([commentMap]);
|
|
2958
|
+
this.updateComment(threadId, String(commentMap.get('id')), data);
|
|
2959
|
+
updatedThread = thread.toJSON();
|
|
2960
|
+
});
|
|
2961
|
+
return updatedThread;
|
|
2950
2962
|
}
|
|
2951
2963
|
updateComment(threadId, commentId, data) {
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2964
|
+
let updatedThread = {};
|
|
2965
|
+
this.document.transact(() => {
|
|
2966
|
+
const thread = this.getYThread(threadId);
|
|
2967
|
+
if (thread === null)
|
|
2968
|
+
return null;
|
|
2969
|
+
let comment = null;
|
|
2970
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
2971
|
+
for (const c of thread.get('comments')) {
|
|
2972
|
+
if (c.get('id') === commentId) {
|
|
2973
|
+
comment = c;
|
|
2974
|
+
break;
|
|
2975
|
+
}
|
|
2961
2976
|
}
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2977
|
+
if (comment === null)
|
|
2978
|
+
return null;
|
|
2979
|
+
comment.set('updatedAt', (new Date()).toISOString());
|
|
2980
|
+
if (data.data) {
|
|
2981
|
+
comment.set('data', data.data);
|
|
2982
|
+
}
|
|
2983
|
+
if (data.content) {
|
|
2984
|
+
comment.set('content', data.content);
|
|
2985
|
+
}
|
|
2986
|
+
updatedThread = thread.toJSON();
|
|
2987
|
+
});
|
|
2988
|
+
return updatedThread;
|
|
2973
2989
|
}
|
|
2974
2990
|
deleteComment(threadId, commentId) {
|
|
2975
2991
|
const thread = this.getYThread(threadId);
|
|
@@ -2983,7 +2999,13 @@ class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
2983
2999
|
}
|
|
2984
3000
|
commentIndex += 1;
|
|
2985
3001
|
}
|
|
2986
|
-
if
|
|
3002
|
+
// if the first comment of a thread is deleted we also
|
|
3003
|
+
// delete the thread itself as the source comment is gone
|
|
3004
|
+
if (commentIndex === 0) {
|
|
3005
|
+
this.deleteThread(threadId);
|
|
3006
|
+
return;
|
|
3007
|
+
}
|
|
3008
|
+
if (commentIndex > 0) {
|
|
2987
3009
|
thread.get('comments').delete(commentIndex);
|
|
2988
3010
|
}
|
|
2989
3011
|
return thread.toJSON();
|