@univerjs/thread-comment 0.1.17 → 0.2.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/lib/cjs/index.js +1 -1
- package/lib/es/index.js +411 -387
- package/lib/types/commands/commands/comment.command.d.ts +3 -10
- package/lib/types/commands/mutations/comment.mutation.d.ts +1 -0
- package/lib/types/index.d.ts +4 -4
- package/lib/types/models/thread-comment.model.d.ts +18 -8
- package/lib/types/services/tc-datasource.service.d.ts +62 -13
- package/lib/types/types/interfaces/i-thread-comment.d.ts +9 -5
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
|
@@ -14,16 +14,6 @@ export interface IUpdateCommentCommandParams {
|
|
|
14
14
|
payload: IUpdateCommentPayload;
|
|
15
15
|
}
|
|
16
16
|
export declare const UpdateCommentCommand: ICommand<IUpdateCommentCommandParams>;
|
|
17
|
-
export interface IUpdateCommentRefPayload {
|
|
18
|
-
commentId: string;
|
|
19
|
-
ref: string;
|
|
20
|
-
}
|
|
21
|
-
export interface IUpdateCommentRefCommandParams {
|
|
22
|
-
unitId: string;
|
|
23
|
-
subUnitId: string;
|
|
24
|
-
payload: IUpdateCommentRefPayload;
|
|
25
|
-
}
|
|
26
|
-
export declare const UpdateCommentRefCommand: ICommand<IUpdateCommentRefCommandParams>;
|
|
27
17
|
export interface IResolveCommentCommandParams {
|
|
28
18
|
unitId: string;
|
|
29
19
|
subUnitId: string;
|
|
@@ -36,6 +26,9 @@ export interface IDeleteCommentCommandParams {
|
|
|
36
26
|
subUnitId: string;
|
|
37
27
|
commentId: string;
|
|
38
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Delete Reply
|
|
31
|
+
*/
|
|
39
32
|
export declare const DeleteCommentCommand: ICommand<IDeleteCommentCommandParams>;
|
|
40
33
|
export interface IDeleteCommentTreeCommandParams {
|
|
41
34
|
unitId: string;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
export { ThreadCommentModel, type CommentUpdate } from './models/thread-comment.model';
|
|
17
17
|
export { ThreadCommentResourceController } from './controllers/tc-resource.controller';
|
|
18
18
|
export { TC_PLUGIN_NAME } from './types/const';
|
|
19
|
+
export type { IThreadComment, IThreadCommentMention, IBaseComment } from './types/interfaces/i-thread-comment';
|
|
20
|
+
export { UniverThreadCommentPlugin } from './plugin';
|
|
21
|
+
export { IThreadCommentDataSourceService, ThreadCommentDataSourceService, type IThreadCommentDataSource, type ThreadCommentJSON, } from './services/tc-datasource.service';
|
|
19
22
|
export { AddCommentMutation, DeleteCommentMutation, ResolveCommentMutation, UpdateCommentMutation, UpdateCommentRefMutation, } from './commands/mutations/comment.mutation';
|
|
20
23
|
export type { IAddCommentMutationParams, IDeleteCommentMutationParams, IResolveCommentMutationParams, IUpdateCommentMutationParams, IUpdateCommentPayload, IUpdateCommentRefMutationParams, } from './commands/mutations/comment.mutation';
|
|
21
|
-
export type { IThreadComment, IThreadCommentMention } from './types/interfaces/i-thread-comment';
|
|
22
24
|
export { AddCommentCommand, DeleteCommentCommand, ResolveCommentCommand, UpdateCommentCommand, DeleteCommentTreeCommand, } from './commands/commands/comment.command';
|
|
23
|
-
export type { IAddCommentCommandParams, IDeleteCommentCommandParams, IResolveCommentCommandParams, IUpdateCommentCommandParams, IDeleteCommentTreeCommandParams,
|
|
24
|
-
export { UniverThreadCommentPlugin } from './plugin';
|
|
25
|
-
export { IThreadCommentDataSourceService, ThreadCommentDataSourceService } from './services/tc-datasource.service';
|
|
25
|
+
export type { IAddCommentCommandParams, IDeleteCommentCommandParams, IResolveCommentCommandParams, IUpdateCommentCommandParams, IDeleteCommentTreeCommandParams, } from './commands/commands/comment.command';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ICommandService } from '@univerjs/core';
|
|
2
|
+
import { IBaseComment, IThreadComment } from '../types/interfaces/i-thread-comment';
|
|
2
3
|
import { IUpdateCommentPayload, IUpdateCommentRefPayload } from '../commands/mutations/comment.mutation';
|
|
4
|
+
import { IThreadCommentDataSourceService } from '../services/tc-datasource.service';
|
|
3
5
|
|
|
4
6
|
export type CommentUpdate = {
|
|
5
7
|
unitId: string;
|
|
@@ -8,6 +10,7 @@ export type CommentUpdate = {
|
|
|
8
10
|
} & ({
|
|
9
11
|
type: 'add';
|
|
10
12
|
payload: IThreadComment;
|
|
13
|
+
isRoot: boolean;
|
|
11
14
|
} | {
|
|
12
15
|
type: 'update';
|
|
13
16
|
payload: IUpdateCommentPayload;
|
|
@@ -27,25 +30,32 @@ export type CommentUpdate = {
|
|
|
27
30
|
commentId: string;
|
|
28
31
|
resolved: boolean;
|
|
29
32
|
};
|
|
33
|
+
} | {
|
|
34
|
+
type: 'syncUpdate';
|
|
35
|
+
payload: IThreadComment;
|
|
30
36
|
});
|
|
31
37
|
export declare class ThreadCommentModel {
|
|
38
|
+
private readonly _dataSourceService;
|
|
39
|
+
private readonly _commandService;
|
|
32
40
|
private _commentsMap;
|
|
33
41
|
private _commentsTreeMap;
|
|
42
|
+
private _threadMap;
|
|
34
43
|
private _commentUpdate$;
|
|
35
|
-
private _commentsTreeMap$;
|
|
36
44
|
private _commentsMap$;
|
|
37
45
|
commentUpdate$: import('rxjs').Observable<CommentUpdate>;
|
|
38
|
-
commentTreeMap$: import('rxjs').Observable<Record<string, Record<string, Record<string, string[]>>>>;
|
|
39
46
|
commentMap$: import('rxjs').Observable<Record<string, Record<string, Record<string, IThreadComment>>>>;
|
|
47
|
+
constructor(_dataSourceService: IThreadCommentDataSourceService, _commandService: ICommandService);
|
|
40
48
|
private _ensureCommentMap;
|
|
41
49
|
private _ensureCommentChildrenMap;
|
|
50
|
+
private _ensureThreadMap;
|
|
42
51
|
private _refreshCommentsMap$;
|
|
43
|
-
private _refreshCommentsTreeMap$;
|
|
44
52
|
ensureMap(unitId: string, subUnitId: string): {
|
|
45
53
|
commentMap: Record<string, IThreadComment>;
|
|
46
|
-
commentChildrenMap: Map<string,
|
|
54
|
+
commentChildrenMap: Map<string, IThreadComment>;
|
|
47
55
|
};
|
|
48
|
-
|
|
56
|
+
private _replaceComment;
|
|
57
|
+
syncThreadComments(unitId: string, subUnitId: string, threadIds: string[]): Promise<void>;
|
|
58
|
+
addComment(unitId: string, subUnitId: string, origin: IThreadComment, shouldSync?: boolean): boolean;
|
|
49
59
|
updateComment(unitId: string, subUnitId: string, payload: IUpdateCommentPayload, silent?: boolean): boolean;
|
|
50
60
|
updateCommentRef(unitId: string, subUnitId: string, payload: IUpdateCommentRefPayload, silent?: boolean): boolean;
|
|
51
61
|
resolveComment(unitId: string, subUnitId: string, commentId: string, resolved: boolean): boolean;
|
|
@@ -53,13 +63,13 @@ export declare class ThreadCommentModel {
|
|
|
53
63
|
getComment$(unitId: string, subUnitId: string, commentId: string): import('rxjs').Observable<IThreadComment>;
|
|
54
64
|
getCommentWithChildren(unitId: string, subUnitId: string, commentId: string): {
|
|
55
65
|
root: IThreadComment;
|
|
56
|
-
children:
|
|
66
|
+
children: IBaseComment[];
|
|
57
67
|
relativeUsers: Set<string>;
|
|
58
68
|
} | undefined;
|
|
59
69
|
deleteComment(unitId: string, subUnitId: string, commentId: string): boolean;
|
|
60
70
|
getUnit(unitId: string): (readonly [string, IThreadComment[]])[];
|
|
61
71
|
deleteUnit(unitId: string): void;
|
|
62
72
|
getRootCommentIds(unitId: string, subUnitId: string): string[];
|
|
63
|
-
getRootCommentIds$(unitId: string, subUnitId: string): import('rxjs').Observable<string[]>;
|
|
64
73
|
getAll(): Record<string, Record<string, Record<string, IThreadComment>>>;
|
|
74
|
+
getThread(unitId: string, threadId: string): IThreadComment | undefined;
|
|
65
75
|
}
|
|
@@ -1,25 +1,74 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Nullable, Disposable } from '@univerjs/core';
|
|
2
|
+
import { IBaseComment, IThreadComment } from '../types/interfaces/i-thread-comment';
|
|
2
3
|
|
|
3
4
|
export type ThreadCommentJSON = {
|
|
4
5
|
id: string;
|
|
5
|
-
|
|
6
|
+
threadId: string;
|
|
7
|
+
ref: string;
|
|
8
|
+
} & Partial<Omit<IThreadComment, 'id' | 'threadId' | 'ref'>>;
|
|
9
|
+
type Success = boolean;
|
|
10
|
+
export interface IThreadCommentDataSource {
|
|
11
|
+
/**
|
|
12
|
+
* handler for add-comment, throw error means fail and stop the process.
|
|
13
|
+
*/
|
|
14
|
+
addComment: (comment: IThreadComment) => Promise<IThreadComment>;
|
|
15
|
+
/**
|
|
16
|
+
* handler for update-comment, throw error means fail and stop the process.
|
|
17
|
+
*/
|
|
18
|
+
updateComment: (comment: IThreadComment) => Promise<Success>;
|
|
19
|
+
resolveComment: (comment: IThreadComment) => Promise<Success>;
|
|
20
|
+
/**
|
|
21
|
+
* handler for delete-comment, throw error means fail and stop the process.
|
|
22
|
+
*/
|
|
23
|
+
deleteComment: (unitId: string, subUnitId: string, threadId: string, commentId: string) => Promise<Success>;
|
|
24
|
+
/**
|
|
25
|
+
* handler for batch-fetch-comment, throw error means fail and stop the process.
|
|
26
|
+
*/
|
|
27
|
+
listComments: (unitId: string, subUnitId: string, threadId: string[]) => Promise<IBaseComment[]>;
|
|
28
|
+
saveCommentToSnapshot: (comment: IThreadComment) => ThreadCommentJSON;
|
|
29
|
+
}
|
|
6
30
|
export interface IThreadCommentDataSourceService {
|
|
31
|
+
dataSource: Nullable<IThreadCommentDataSource>;
|
|
32
|
+
/**
|
|
33
|
+
* should sync update mutations to collaboration-server
|
|
34
|
+
*/
|
|
35
|
+
syncUpdateMutationToColla: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* handler for add-comment, throw error means fail and stop the process.
|
|
38
|
+
*/
|
|
7
39
|
addComment: (comment: IThreadComment) => Promise<IThreadComment>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
40
|
+
/**
|
|
41
|
+
* handler for update-comment, throw error means fail and stop the process.
|
|
42
|
+
*/
|
|
43
|
+
updateComment: (comment: IThreadComment) => Promise<Success>;
|
|
44
|
+
/**
|
|
45
|
+
* handler for resolve-comment, throw error means fail and stop the process.
|
|
46
|
+
*/
|
|
47
|
+
resolveComment: (comment: IThreadComment) => Promise<Success>;
|
|
48
|
+
/**
|
|
49
|
+
* handler for delete-comment, throw error means fail and stop the process.
|
|
50
|
+
*/
|
|
51
|
+
deleteComment: (unitId: string, subUnitId: string, threadId: string, commentId: string) => Promise<Success>;
|
|
52
|
+
saveToSnapshot: (unitComments: Record<string, IThreadComment[]>, unitId: string) => Record<string, ThreadCommentJSON[]>;
|
|
53
|
+
getThreadComment: (unitId: string, subUnitId: string, threadId: string) => Promise<Nullable<IBaseComment>>;
|
|
54
|
+
listThreadComments: (unitId: string, subUnitId: string, threadId: string[]) => Promise<IBaseComment[]>;
|
|
13
55
|
}
|
|
14
56
|
/**
|
|
15
57
|
* Preserve for import async comment system
|
|
16
58
|
*/
|
|
17
|
-
export declare class ThreadCommentDataSourceService implements IThreadCommentDataSourceService {
|
|
59
|
+
export declare class ThreadCommentDataSourceService extends Disposable implements IThreadCommentDataSourceService {
|
|
60
|
+
private _dataSource;
|
|
61
|
+
syncUpdateMutationToColla: boolean;
|
|
62
|
+
set dataSource(dataSource: Nullable<IThreadCommentDataSource>);
|
|
63
|
+
get dataSource(): Nullable<IThreadCommentDataSource>;
|
|
64
|
+
constructor();
|
|
65
|
+
getThreadComment(unitId: string, subUnitId: string, threadId: string): Promise<Nullable<IBaseComment>>;
|
|
18
66
|
addComment(comment: IThreadComment): Promise<IThreadComment>;
|
|
19
|
-
updateComment(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
saveToSnapshot(unitComments: Record<string, IThreadComment[]
|
|
67
|
+
updateComment(comment: IThreadComment): Promise<boolean>;
|
|
68
|
+
resolveComment(comment: IThreadComment): Promise<boolean>;
|
|
69
|
+
deleteComment(unitId: string, subUnitId: string, threadId: string, commentId: string): Promise<boolean>;
|
|
70
|
+
listThreadComments(unitId: string, subUnitId: string, threadIds: string[]): Promise<IBaseComment[]>;
|
|
71
|
+
saveToSnapshot(unitComments: Record<string, IThreadComment[]>, unitId: string): Record<string, ThreadCommentJSON[]>;
|
|
24
72
|
}
|
|
25
73
|
export declare const IThreadCommentDataSourceService: import('@wendellhu/redi').IdentifierDecorator<IThreadCommentDataSourceService>;
|
|
74
|
+
export {};
|
|
@@ -5,18 +5,22 @@ export interface IThreadCommentMention {
|
|
|
5
5
|
id: string;
|
|
6
6
|
icon?: string;
|
|
7
7
|
}
|
|
8
|
-
export interface
|
|
8
|
+
export interface IBaseComment {
|
|
9
9
|
id: string;
|
|
10
|
-
|
|
10
|
+
threadId: string;
|
|
11
11
|
dT: string;
|
|
12
12
|
updateT?: string;
|
|
13
13
|
personId: string;
|
|
14
|
-
parentId?: string;
|
|
15
14
|
text: IDocumentBody;
|
|
16
15
|
attachments?: string[];
|
|
17
|
-
resolved?: boolean;
|
|
18
16
|
updated?: boolean;
|
|
17
|
+
mentions?: string[];
|
|
18
|
+
parentId?: string;
|
|
19
|
+
resolved?: boolean;
|
|
19
20
|
unitId: string;
|
|
20
21
|
subUnitId: string;
|
|
21
|
-
|
|
22
|
+
children?: IBaseComment[];
|
|
23
|
+
}
|
|
24
|
+
export interface IThreadComment extends IBaseComment {
|
|
25
|
+
ref: string;
|
|
22
26
|
}
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("rxjs"),require("@univerjs/core"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","rxjs","@univerjs/core","@wendellhu/redi"],h):(s=typeof globalThis<"u"?globalThis:s||self,h(s.UniverThreadComment={},s.rxjs,s.UniverCore,s["@wendellhu/redi"]))})(this,function(s,h,d,U){"use strict";var B=Object.defineProperty;var K=(s,h,d)=>h in s?B(s,h,{enumerable:!0,configurable:!0,writable:!0,value:d}):s[h]=d;var f=(s,h,d)=>K(s,typeof h!="symbol"?h+"":h,d);var y;class p{constructor(){f(this,"_commentsMap",{});f(this,"_commentsTreeMap",new Map);f(this,"_commentUpdate$",new h.Subject);f(this,"_commentsTreeMap$",new h.BehaviorSubject({}));f(this,"_commentsMap$",new h.BehaviorSubject({}));f(this,"commentUpdate$",this._commentUpdate$.asObservable());f(this,"commentTreeMap$",this._commentsTreeMap$.asObservable());f(this,"commentMap$",this._commentsMap$.asObservable())}_ensureCommentMap(t,m){let e=this._commentsMap[t];e||(e={},this._commentsMap[t]=e);let n=e[m];return n||(n={},e[m]=n),n}_ensureCommentChildrenMap(t,m){let e=this._commentsTreeMap.get(t);e||(e=new Map,this._commentsTreeMap.set(t,e));let n=e.get(m);return n||(n=new Map,e.set(m,n)),n}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}_refreshCommentsTreeMap$(){const t={};this._commentsTreeMap.forEach((m,e)=>{t[e]={};const n=t[e];m.forEach((a,o)=>{n[o]={};const i=n[o];a.forEach((c,u)=>{i[u]=c})})}),this._commentsTreeMap$.next(t)}ensureMap(t,m){const e=this._ensureCommentMap(t,m),n=this._ensureCommentChildrenMap(t,m);return{commentMap:e,commentChildrenMap:n}}addComment(t,m,e){const{commentMap:n,commentChildrenMap:a}=this.ensureMap(t,m);let o=e.parentId;if(o){let i=n[o];for(;i!=null&&i.parentId;)i=n[i.parentId],o=i.parentId;if(i){let c=a.get(o);c||(c=[]),c.push(e.id),a.set(o,c)}}else a.set(e.id,[]);return n[e.id]=e,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"add",payload:e}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}updateComment(t,m,e,n){const{commentMap:a}=this.ensureMap(t,m),o=a[e.commentId];return o?(o.updated=!0,o.text=e.text,o.attachments=e.attachments,o.updateT=e.updateT,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"update",payload:e,silent:n}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}updateCommentRef(t,m,e,n){const{commentMap:a}=this.ensureMap(t,m),o=a[e.commentId];return o?(o.ref=e.ref,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"updateRef",payload:e,silent:n}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}resolveComment(t,m,e,n){const{commentMap:a}=this.ensureMap(t,m),o=a[e];return o?(o.resolved=n,this._commentUpdate$.next({unitId:t,subUnitId:m,type:"resolve",payload:{commentId:e,resolved:n}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0):!1}getComment(t,m,e){const{commentMap:n}=this.ensureMap(t,m);return n[e]}getComment$(t,m,e){return this._commentsMap$.pipe(h.map(n=>n[t][m][e]))}getCommentWithChildren(t,m,e){var l;const{commentMap:n,commentChildrenMap:a}=this.ensureMap(t,m),o=n[e];if(!o)return;const i=new Set,c=(l=a.get(e))!=null?l:[],u=c==null?void 0:c.map(C=>n[C]);return[o,...u].forEach(C=>{var _;i.add(C.personId),(_=C.text.customRanges)==null||_.forEach(I=>{I.rangeType===d.CustomRangeType.MENTION&&i.add(I.rangeId)})}),{root:o,children:u,relativeUsers:i}}deleteComment(t,m,e){const{commentMap:n,commentChildrenMap:a}=this.ensureMap(t,m),o=n[e];if(!o)return!1;if(o.parentId){const i=a.get(o.parentId);if(i){const c=i.indexOf(e);i.splice(c,1)}delete n[e]}else delete n[e],a.delete(e);return this._commentUpdate$.next({unitId:t,subUnitId:m,type:"delete",payload:{commentId:e,isRoot:!o.parentId,comment:o}}),this._refreshCommentsMap$(),this._refreshCommentsTreeMap$(),!0}getUnit(t){const m=this._commentsMap[t];return m?Array.from(Object.entries(m)).map(([e,n])=>[e,Array.from(Object.values(n))]):[]}deleteUnit(t){const m=this._commentsMap[t];m&&Object.entries(m).forEach(([e,n])=>{Object.values(n).forEach(a=>{this.deleteComment(t,e,a.id)})})}getRootCommentIds(t,m){const e=this._ensureCommentChildrenMap(t,m);return Array.from(e.keys())}getRootCommentIds$(t,m){return this._commentsTreeMap$.pipe(h.map(e=>{var n;return Object.keys((n=e[t])==null?void 0:n[m])}))}getAll(){return this._commentsMap}}var D=(r=>(r[r.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",r[r.UNIVER_DOC=1]="UNIVER_DOC",r[r.UNIVER_SHEET=2]="UNIVER_SHEET",r[r.UNIVER_SLIDE=3]="UNIVER_SLIDE",r[r.UNRECOGNIZED=-1]="UNRECOGNIZED",r))(D||{});const R="THREAD_COMMENT_PLUGIN";class ${async addComment(t){return t}async updateComment(t){return!0}async deleteComment(t){return!0}async deleteCommentBatch(t){return!0}async loadFormSnapshot(t){return t}saveToSnapshot(t){return t}}const M=U.createIdentifier("univer.thread-comment.data-source-service");var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,J=(r,t,m,e)=>{for(var n=e>1?void 0:e?W(t,m):t,a=r.length-1,o;a>=0;a--)(o=r[a])&&(n=(e?o(t,m,n):o(n))||n);return e&&n&&V(t,m,n),n},N=(r,t)=>(m,e)=>t(m,e,r);s.ThreadCommentResourceController=class extends d.Disposable{constructor(t,m,e){super(),this._resourceManagerService=t,this._threadCommentModel=m,this._threadCommentDataSourceService=e,this._initSnapshot()}_initSnapshot(){const t=e=>{const n=this._threadCommentModel.getUnit(e),a={};return n?(n.forEach(([o,i])=>{a[o]=i}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(a))):""},m=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${R}`,businesses:[D.UNIVER_SHEET],toJson:e=>t(e),parseJson:e=>m(e),onUnLoad:e=>{this._threadCommentModel.deleteUnit(e)},onLoad:async(e,n)=>{const a=await this._threadCommentDataSourceService.loadFormSnapshot(n);Object.keys(a).forEach(o=>{n[o].forEach(c=>{this._threadCommentModel.addComment(e,o,c)})})}}))}},s.ThreadCommentResourceController=J([d.OnLifecycle(d.LifecycleStages.Starting,s.ThreadCommentResourceController),N(0,d.IResourceManagerService),N(1,U.Inject(p)),N(2,M)],s.ThreadCommentResourceController);const S={id:"thread-comment.mutation.add-comment",type:d.CommandType.MUTATION,handler(r,t){if(!t)return!1;const m=r.get(p),{unitId:e,subUnitId:n,comment:a}=t;return m.addComment(e,n,a)}},v={id:"thread-comment.mutation.update-comment",type:d.CommandType.MUTATION,handler(r,t){if(!t)return!1;const m=r.get(p),{unitId:e,subUnitId:n,payload:a,silent:o}=t;return m.updateComment(e,n,a,o)}},E={id:"thread-comment.mutation.update-comment-ref",type:d.CommandType.MUTATION,handler(r,t){if(!t)return!1;const m=r.get(p),{unitId:e,subUnitId:n,payload:a,silent:o}=t;return m.updateCommentRef(e,n,a,o)}},O={id:"thread-comment.mutation.resolve-comment",type:d.CommandType.MUTATION,handler(r,t){if(!t)return!1;const m=r.get(p),{unitId:e,subUnitId:n,resolved:a,commentId:o}=t;return m.resolveComment(e,n,o,a)}},T={id:"thread-comment.mutation.delete-comment",type:d.CommandType.MUTATION,handler(r,t){if(!t)return!1;const m=r.get(p),{unitId:e,subUnitId:n,commentId:a}=t;return m.deleteComment(e,n,a)}},b={id:"thread-comment.command.add-comment",type:d.CommandType.COMMAND,async handler(r,t){if(!t)return!1;const m=r.get(d.ICommandService),e=r.get(d.IUndoRedoService),n=r.get(M),{unitId:a,subUnitId:o,comment:i}=t,c=await n.addComment(i),u={id:S.id,params:t},l={id:T.id,params:{unitId:a,subUnitId:o,commentId:c.id}};return e.pushUndoRedo({undoMutations:[l],redoMutations:[u],unitID:a}),m.executeCommand(u.id,u.params),!0}},w={id:"thread-comment.command.update-comment",type:d.CommandType.COMMAND,async handler(r,t){if(!t)return!1;const{unitId:m,subUnitId:e,payload:n}=t,a=r.get(d.ICommandService),o=r.get(d.IUndoRedoService),i=r.get(p),c=r.get(M),u=i.getComment(m,e,n.commentId);if(!u||!await c.updateComment({...u,...n}))return!1;const C={id:v.id,params:t},_={id:v.id,params:{unitId:m,subUnitId:e,payload:{commentId:n.commentId,text:u.text,attachments:u.attachments,updateT:u.updateT,updated:u.updated}}};return o.pushUndoRedo({undoMutations:[_],redoMutations:[C],unitID:m}),a.executeCommand(C.id,C.params),!0}};d.CommandType.COMMAND;const A={id:"thread-comment.command.resolve-comment",type:d.CommandType.COMMAND,async handler(r,t){if(!t)return!1;const{unitId:m,subUnitId:e,resolved:n,commentId:a}=t,o=r.get(M),c=r.get(p).getComment(m,e,a);return!c||!await o.updateComment({...c,resolved:n})?!1:(r.get(d.ICommandService).executeCommand(O.id,t),!0)}},P={id:"thread-comment.command.delete-comment",type:d.CommandType.COMMAND,async handler(r,t){if(!t)return!1;const m=r.get(p),e=r.get(M),n=r.get(d.ICommandService),a=r.get(d.IUndoRedoService),{unitId:o,subUnitId:i,commentId:c}=t,u=m.getComment(o,i,c);if(!u||!await e.deleteComment(c))return!1;const l={id:T.id,params:t},C={id:S.id,params:{unitId:o,subUnitId:i,comment:u}};return a.pushUndoRedo({undoMutations:[C],redoMutations:[l],unitID:o}),n.executeCommand(l.id,l.params)}},j={id:"thread-comment.command.delete-comment-tree",type:d.CommandType.COMMAND,async handler(r,t){if(!t)return!1;const m=r.get(p),e=r.get(d.ICommandService),n=r.get(M),a=r.get(d.IUndoRedoService),{unitId:o,subUnitId:i,commentId:c}=t,u=m.getCommentWithChildren(o,i,c);if(!u)return!1;const l=[u.root,...u.children];if(!await n.deleteCommentBatch(l.map(g=>g.id)))return!1;const C=l.map(g=>({id:T.id,params:{unitId:o,subUnitId:i,commentId:g.id}})),_=l.map(g=>({id:S.id,params:{unitId:o,subUnitId:i,comment:g}})),I=d.sequenceExecute(C,e);return I.result&&a.pushUndoRedo({undoMutations:_,redoMutations:C,unitID:o}),I.result}};var G=Object.defineProperty,H=Object.getOwnPropertyDescriptor,q=(r,t,m,e)=>{for(var n=e>1?void 0:e?H(t,m):t,a=r.length-1,o;a>=0;a--)(o=r[a])&&(n=(e?o(t,m,n):o(n))||n);return e&&n&&G(t,m,n),n},L=(r,t)=>(m,e)=>t(m,e,r);s.UniverThreadCommentPlugin=(y=class extends d.Plugin{constructor(m,e,n){super();f(this,"_config");this._injector=e,this._commandService=n,this._config=m}onStarting(m){var e;d.mergeOverrideWithDependencies([[p],[s.ThreadCommentResourceController],[M,{useClass:$}]],(e=this._config)==null?void 0:e.overrides).forEach(n=>{m.add(n)}),[b,w,P,A,j,S,v,E,T,O].forEach(n=>{this._commandService.registerCommand(n)})}},f(y,"pluginName",R),f(y,"type",d.UniverInstanceType.UNIVER_UNKNOWN),y),s.UniverThreadCommentPlugin=q([L(1,U.Inject(U.Injector)),L(2,d.ICommandService)],s.UniverThreadCommentPlugin),s.AddCommentCommand=b,s.AddCommentMutation=S,s.DeleteCommentCommand=P,s.DeleteCommentMutation=T,s.DeleteCommentTreeCommand=j,s.IThreadCommentDataSourceService=M,s.ResolveCommentCommand=A,s.ResolveCommentMutation=O,s.TC_PLUGIN_NAME=R,s.ThreadCommentDataSourceService=$,s.ThreadCommentModel=p,s.UpdateCommentCommand=w,s.UpdateCommentMutation=v,s.UpdateCommentRefMutation=E,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(d,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("rxjs"),require("@univerjs/core"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","rxjs","@univerjs/core","@wendellhu/redi"],l):(d=typeof globalThis<"u"?globalThis:d||self,l(d.UniverThreadComment={},d.rxjs,d.UniverCore,d["@wendellhu/redi"]))})(this,function(d,l,i,v){"use strict";var Z=Object.defineProperty;var z=(d,l,i)=>l in d?Z(d,l,{enumerable:!0,configurable:!0,writable:!0,value:i}):d[l]=i;var C=(d,l,i)=>z(d,typeof l!="symbol"?l+"":l,i);var S;class R extends i.Disposable{constructor(){super();C(this,"_dataSource",null);C(this,"syncUpdateMutationToColla",!0)}set dataSource(t){this._dataSource=t}get dataSource(){return this._dataSource}async getThreadComment(t,e,o){return this._dataSource?(await this._dataSource.listComments(t,e,[o]))[0]:null}async addComment(t){return this._dataSource?this._dataSource.addComment(t):t}async updateComment(t){return this._dataSource?this._dataSource.updateComment(t):!0}async resolveComment(t){return this._dataSource?this._dataSource.resolveComment(t):!0}async deleteComment(t,e,o,a){return this._dataSource?this._dataSource.deleteComment(t,e,o,a):!0}async listThreadComments(t,e,o){return this.dataSource?this.dataSource.listComments(t,e,o):[]}saveToSnapshot(t,e){if(this._dataSource){const o={};return Object.keys(t).forEach(a=>{const r=t[a];o[a]=r.map(this.dataSource.saveCommentToSnapshot)}),o}return t}}const M=v.createIdentifier("univer.thread-comment.data-source-service");var L=Object.defineProperty,V=Object.getOwnPropertyDescriptor,W=(m,n,t,e)=>{for(var o=e>1?void 0:e?V(n,t):n,a=m.length-1,r;a>=0;a--)(r=m[a])&&(o=(e?r(n,t,o):r(o))||o);return e&&o&&L(n,t,o),o},E=(m,n)=>(t,e)=>n(t,e,m);d.ThreadCommentModel=class{constructor(n,t){C(this,"_commentsMap",{});C(this,"_commentsTreeMap",new Map);C(this,"_threadMap",new Map);C(this,"_commentUpdate$",new l.Subject);C(this,"_commentsMap$",new l.BehaviorSubject({}));C(this,"commentUpdate$",this._commentUpdate$.asObservable());C(this,"commentMap$",this._commentsMap$.asObservable());this._dataSourceService=n,this._commandService=t}_ensureCommentMap(n,t){let e=this._commentsMap[n];e||(e={},this._commentsMap[n]=e);let o=e[t];return o||(o={},e[t]=o),o}_ensureCommentChildrenMap(n,t){let e=this._commentsTreeMap.get(n);e||(e=new Map,this._commentsTreeMap.set(n,e));let o=e.get(t);return o||(o=new Map,e.set(t,o)),o}_ensureThreadMap(n){let t=this._threadMap.get(n);return t||(t=new Map,this._threadMap.set(n,t)),t}_refreshCommentsMap$(){this._commentsMap$.next({...this._commentsMap})}ensureMap(n,t){const e=this._ensureCommentMap(n,t),o=this._ensureCommentChildrenMap(n,t);return{commentMap:e,commentChildrenMap:o}}_replaceComment(n,t,e){var s;const{commentMap:o,commentChildrenMap:a}=this.ensureMap(n,t),r=o[e.id];if(r){const c={...e,ref:r.ref};o[e.id]=c,(s=e.children)==null||s.forEach(h=>{o[h.id]={...h,ref:""}}),a.set(e.id,c),this._commentUpdate$.next({unitId:n,subUnitId:t,type:"syncUpdate",payload:c}),!!e.resolved!=!!r.resolved&&this._commentUpdate$.next({unitId:n,subUnitId:t,type:"resolve",payload:{commentId:e.id,resolved:!!e.resolved}})}}async syncThreadComments(n,t,e){const o=await this._dataSourceService.listThreadComments(n,t,e);if(!o.length)return;const a=new Set(e);o.forEach(r=>{this._replaceComment(n,t,r),a.delete(r.threadId)}),a.forEach(r=>{const s=this.getThread(n,r);s&&this.deleteComment(s.unitId,s.subUnitId,s.id)}),this._refreshCommentsMap$()}addComment(n,t,e,o){var u,f;const{commentMap:a,commentChildrenMap:r}=this.ensureMap(n,t),s=e,c=p=>{a[p.id]=p,this._commentUpdate$.next({unitId:n,subUnitId:t,type:"add",payload:p,isRoot:!p.parentId})},h=s.parentId;if(h){const p=a[h];p.children=[...(u=p.children)!=null?u:[],s],c(s)}else r.set(s.id,s),this._ensureThreadMap(n).set(s.threadId,s),c(s),(f=s.children)==null||f.forEach(_=>c({..._,ref:""}));return this._refreshCommentsMap$(),o&&this.syncThreadComments(n,t,[s.threadId]),!0}updateComment(n,t,e,o){const{commentMap:a}=this.ensureMap(n,t),r=a[e.commentId];return r?(r.updated=!0,r.text=e.text,r.attachments=e.attachments,r.updateT=e.updateT,this._commentUpdate$.next({unitId:n,subUnitId:t,type:"update",payload:e,silent:o}),this._refreshCommentsMap$(),!0):!1}updateCommentRef(n,t,e,o){const{commentMap:a}=this.ensureMap(n,t),r=a[e.commentId];return r?(r.ref=e.ref,this._commentUpdate$.next({unitId:n,subUnitId:t,type:"updateRef",payload:e,silent:o}),this._refreshCommentsMap$(),!0):!1}resolveComment(n,t,e,o){const{commentMap:a}=this.ensureMap(n,t),r=a[e];return r?(r.resolved=o,this._commentUpdate$.next({unitId:n,subUnitId:t,type:"resolve",payload:{commentId:e,resolved:o}}),this._refreshCommentsMap$(),!0):!1}getComment(n,t,e){const{commentMap:o}=this.ensureMap(n,t);return o[e]}getComment$(n,t,e){return this._commentsMap$.pipe(l.map(o=>o[n][t][e]))}getCommentWithChildren(n,t,e){var h,u;const{commentMap:o,commentChildrenMap:a}=this.ensureMap(n,t),r=o[e];if(!r)return;const s=new Set,c=a.get(e);if(c)return[c,...(h=c.children)!=null?h:[]].forEach(f=>{var p;s.add(f.personId),(p=f.text.customRanges)==null||p.forEach(_=>{_.rangeType===i.CustomRangeType.MENTION&&s.add(_.rangeId)})}),{root:r,children:(u=c.children)!=null?u:[],relativeUsers:s}}deleteComment(n,t,e){var s;const{commentMap:o,commentChildrenMap:a}=this.ensureMap(n,t),r=o[e];if(!r)return!0;if(r.parentId){const c=a.get(r.parentId);if(c&&c.children){const h=c.children.findIndex(u=>u.id=e);c.children.splice(h,1)}delete o[e]}else{delete o[e];const c=a.get(e);a.delete(e),this._ensureThreadMap(n).delete(r.threadId),(s=c==null?void 0:c.children)==null||s.forEach(u=>{delete o[u.id],this._commentUpdate$.next({unitId:n,subUnitId:t,type:"delete",payload:{commentId:u.id,isRoot:!1,comment:u}})})}return this._commentUpdate$.next({unitId:n,subUnitId:t,type:"delete",payload:{commentId:e,isRoot:!r.parentId,comment:r}}),this._refreshCommentsMap$(),!0}getUnit(n){const t=this._commentsMap[n];return t?Array.from(Object.entries(t)).map(([e,o])=>[e,Array.from(Object.values(o))]):[]}deleteUnit(n){const t=this._commentsMap[n];t&&Object.entries(t).forEach(([e,o])=>{Object.values(o).forEach(a=>{this.deleteComment(n,e,a.id)})})}getRootCommentIds(n,t){const e=this._ensureCommentChildrenMap(n,t);return Array.from(e.keys())}getAll(){return this._commentsMap}getThread(n,t){return this._ensureThreadMap(n).get(t)}},d.ThreadCommentModel=W([E(0,v.Inject(M)),E(1,i.ICommandService)],d.ThreadCommentModel);var y=(m=>(m[m.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",m[m.UNIVER_DOC=1]="UNIVER_DOC",m[m.UNIVER_SHEET=2]="UNIVER_SHEET",m[m.UNIVER_SLIDE=3]="UNIVER_SLIDE",m[m.UNRECOGNIZED=-1]="UNRECOGNIZED",m))(y||{});const g="THREAD_COMMENT_PLUGIN";var J=Object.defineProperty,G=Object.getOwnPropertyDescriptor,H=(m,n,t,e)=>{for(var o=e>1?void 0:e?G(n,t):n,a=m.length-1,r;a>=0;a--)(r=m[a])&&(o=(e?r(n,t,o):r(o))||o);return e&&o&&J(n,t,o),o},U=(m,n)=>(t,e)=>n(t,e,m);d.ThreadCommentResourceController=class extends i.Disposable{constructor(n,t,e){super(),this._resourceManagerService=n,this._threadCommentModel=t,this._threadCommentDataSourceService=e,this._initSnapshot()}_initSnapshot(){const n=e=>{const o=this._threadCommentModel.getUnit(e),a={};return o?(o.forEach(([r,s])=>{a[r]=s}),JSON.stringify(this._threadCommentDataSourceService.saveToSnapshot(a,e))):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_${g}`,businesses:[y.UNIVER_SHEET,y.UNIVER_DOC],toJson:e=>n(e),parseJson:e=>t(e),onUnLoad:e=>{this._threadCommentModel.deleteUnit(e)},onLoad:async(e,o)=>{Object.keys(o).forEach(a=>{const r=o[a];r.forEach(s=>{this._threadCommentModel.addComment(e,a,s)}),this._threadCommentModel.syncThreadComments(e,a,r.map(s=>s.threadId))})}}))}},d.ThreadCommentResourceController=H([i.OnLifecycle(i.LifecycleStages.Starting,d.ThreadCommentResourceController),U(0,i.IResourceManagerService),U(1,v.Inject(d.ThreadCommentModel)),U(2,M)],d.ThreadCommentResourceController);const I={id:"thread-comment.mutation.add-comment",type:i.CommandType.MUTATION,handler(m,n,t){if(!n)return!1;const e=m.get(d.ThreadCommentModel),{unitId:o,subUnitId:a,comment:r,sync:s}=n,c=s||(t==null?void 0:t.fromChangeset)&&!r.parentId;return e.addComment(o,a,r,c)}},N={id:"thread-comment.mutation.update-comment",type:i.CommandType.MUTATION,handler(m,n){if(!n)return!1;const t=m.get(d.ThreadCommentModel),{unitId:e,subUnitId:o,payload:a,silent:r}=n;return t.updateComment(e,o,a,r)}},$={id:"thread-comment.mutation.update-comment-ref",type:i.CommandType.MUTATION,handler(m,n){if(!n)return!1;const t=m.get(d.ThreadCommentModel),{unitId:e,subUnitId:o,payload:a,silent:r}=n;return t.updateCommentRef(e,o,a,r)}},O={id:"thread-comment.mutation.resolve-comment",type:i.CommandType.MUTATION,handler(m,n){if(!n)return!1;const t=m.get(d.ThreadCommentModel),{unitId:e,subUnitId:o,resolved:a,commentId:r}=n;return t.resolveComment(e,o,r,a)}},T={id:"thread-comment.mutation.delete-comment",type:i.CommandType.MUTATION,handler(m,n){if(!n)return!1;const t=m.get(d.ThreadCommentModel),{unitId:e,subUnitId:o,commentId:a}=n;return t.deleteComment(e,o,a)}},D={id:"thread-comment.command.add-comment",type:i.CommandType.COMMAND,async handler(m,n){if(!n)return!1;const t=m.get(i.ICommandService),e=m.get(M),{comment:o}=n,a=await e.addComment(o),r=e.syncUpdateMutationToColla,s=!o.parentId,c={id:I.id,params:{...n,comment:a}};return s?await t.executeCommand(c.id,c.params):t.executeCommand(c.id,c.params,{onlyLocal:!r})}},w={id:"thread-comment.command.update-comment",type:i.CommandType.COMMAND,async handler(m,n){if(!n)return!1;const{unitId:t,subUnitId:e,payload:o}=n,a=m.get(i.ICommandService),r=m.get(d.ThreadCommentModel),s=m.get(M),c=s.syncUpdateMutationToColla,h=r.getComment(t,e,o.commentId);if(!h)return!1;const{children:u,...f}=h;if(!await s.updateComment({...f,...o}))return!1;const _={id:N.id,params:n};return a.executeCommand(_.id,_.params,{onlyLocal:!c}),!0}},P={id:"thread-comment.command.resolve-comment",type:i.CommandType.COMMAND,async handler(m,n){if(!n)return!1;const{unitId:t,subUnitId:e,resolved:o,commentId:a}=n,r=m.get(M),c=m.get(d.ThreadCommentModel).getComment(t,e,a),h=r.syncUpdateMutationToColla;return!c||!await r.resolveComment({...c,resolved:o})?!1:m.get(i.ICommandService).executeCommand(O.id,n,{onlyLocal:!h})}},j={id:"thread-comment.command.delete-comment",type:i.CommandType.COMMAND,async handler(m,n){if(!n)return!1;const t=m.get(d.ThreadCommentModel),e=m.get(M),o=m.get(i.ICommandService),{unitId:a,subUnitId:r,commentId:s}=n,c=e.syncUpdateMutationToColla,h=t.getComment(a,r,s);if(!h||!await e.deleteComment(a,r,h.threadId,s))return!1;const u={id:T.id,params:n};return o.executeCommand(u.id,u.params,{onlyLocal:!c})}},A={id:"thread-comment.command.delete-comment-tree",type:i.CommandType.COMMAND,async handler(m,n){if(!n)return!1;const t=m.get(d.ThreadCommentModel),e=m.get(i.ICommandService),o=m.get(M),{unitId:a,subUnitId:r,commentId:s}=n,c=t.getCommentWithChildren(a,r,s);return!c||!await o.deleteComment(a,r,c.root.threadId,s)?!1:await e.executeCommand(T.id,{unitId:a,subUnitId:r,commentId:c.root.id})}};var B=Object.defineProperty,q=Object.getOwnPropertyDescriptor,K=(m,n,t,e)=>{for(var o=e>1?void 0:e?q(n,t):n,a=m.length-1,r;a>=0;a--)(r=m[a])&&(o=(e?r(n,t,o):r(o))||o);return e&&o&&B(n,t,o),o},b=(m,n)=>(t,e)=>n(t,e,m);d.UniverThreadCommentPlugin=(S=class extends i.Plugin{constructor(t,e,o){super();C(this,"_config");this._injector=e,this._commandService=o,this._config=t}onStarting(t){var e;i.mergeOverrideWithDependencies([[M,{useClass:R}],[d.ThreadCommentModel],[d.ThreadCommentResourceController]],(e=this._config)==null?void 0:e.overrides).forEach(o=>{t.add(o)}),[D,w,j,P,A,I,N,$,T,O].forEach(o=>{this._commandService.registerCommand(o)})}},C(S,"pluginName",g),C(S,"type",i.UniverInstanceType.UNIVER_UNKNOWN),S),d.UniverThreadCommentPlugin=K([b(1,v.Inject(v.Injector)),b(2,i.ICommandService)],d.UniverThreadCommentPlugin),d.AddCommentCommand=D,d.AddCommentMutation=I,d.DeleteCommentCommand=j,d.DeleteCommentMutation=T,d.DeleteCommentTreeCommand=A,d.IThreadCommentDataSourceService=M,d.ResolveCommentCommand=P,d.ResolveCommentMutation=O,d.TC_PLUGIN_NAME=g,d.ThreadCommentDataSourceService=R,d.UpdateCommentCommand=w,d.UpdateCommentMutation=N,d.UpdateCommentRefMutation=$,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/thread-comment",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer thread comment core plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -47,21 +47,21 @@
|
|
|
47
47
|
"lib"
|
|
48
48
|
],
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@wendellhu/redi": "0.15.
|
|
50
|
+
"@wendellhu/redi": "0.15.5",
|
|
51
51
|
"rxjs": ">=7.0.0",
|
|
52
|
-
"@univerjs/core": "0.
|
|
52
|
+
"@univerjs/core": "0.2.0"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@univerjs/protocol": "0.1.38-alpha.
|
|
55
|
+
"@univerjs/protocol": "0.1.38-alpha.11"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@wendellhu/redi": "0.15.
|
|
58
|
+
"@wendellhu/redi": "0.15.5",
|
|
59
59
|
"rxjs": "^7.8.1",
|
|
60
|
-
"typescript": "^5.
|
|
61
|
-
"vite": "^5.3.
|
|
60
|
+
"typescript": "^5.5.3",
|
|
61
|
+
"vite": "^5.3.3",
|
|
62
62
|
"vitest": "^1.6.0",
|
|
63
|
-
"@univerjs/core": "0.
|
|
64
|
-
"@univerjs/shared": "0.
|
|
63
|
+
"@univerjs/core": "0.2.0",
|
|
64
|
+
"@univerjs/shared": "0.2.0"
|
|
65
65
|
},
|
|
66
66
|
"univerSpace": {
|
|
67
67
|
".": {
|