@univerjs/sheets-thread-comment 0.5.3 → 0.5.4
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/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +502 -102
- package/lib/es/index.js +117 -117
- package/lib/types/facade/f-event.d.ts +247 -0
- package/lib/types/facade/f-range.d.ts +15 -3
- package/lib/types/facade/f-thread-comment.d.ts +255 -8
- package/lib/types/facade/f-univer.d.ts +41 -0
- package/lib/types/facade/f-workbook.d.ts +28 -12
- package/lib/types/facade/f-worksheet.d.ts +26 -0
- package/lib/types/facade/index.d.ts +4 -1
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
|
@@ -1,39 +1,55 @@
|
|
|
1
1
|
import { IDisposable, IExecutionOptions } from '@univerjs/core';
|
|
2
2
|
import { CommentUpdate, IAddCommentCommandParams, IDeleteCommentCommandParams, ThreadCommentModel } from '@univerjs/thread-comment';
|
|
3
3
|
import { FWorkbook } from '@univerjs/sheets/facade';
|
|
4
|
+
import { FThreadComment } from './f-thread-comment';
|
|
4
5
|
type IUpdateCommandParams = any;
|
|
5
6
|
export interface IFWorkbookThreadCommentMixin {
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
9
|
-
|
|
8
|
+
* Get all comments in the current sheet
|
|
9
|
+
* @returns all comments in the current sheet
|
|
10
|
+
*/
|
|
11
|
+
getComments(): FThreadComment[];
|
|
12
|
+
/**
|
|
13
|
+
* Clear all comments in the current sheet
|
|
14
|
+
*/
|
|
15
|
+
clearComments(): Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated use `univerAPI.addEvent(univerAPI.event.CommentUpdated, () => {})` as instead
|
|
10
18
|
*/
|
|
11
19
|
onThreadCommentChange(callback: (commentUpdate: CommentUpdate) => void | false): IDisposable;
|
|
12
20
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @param callback Callback function that will be called when the event is fired
|
|
15
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
21
|
+
* @deprecated use `univerAPI.addEvent(univerAPI.event.BeforeCommentAdd, () => {})` as instead
|
|
16
22
|
*/
|
|
17
23
|
onBeforeAddThreadComment(this: FWorkbook, callback: (params: IAddCommentCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
18
24
|
/**
|
|
19
|
-
*
|
|
20
|
-
* @param callback Callback function that will be called when the event is fired
|
|
21
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
25
|
+
* @deprecated use `univerAPI.addEvent(univerAPI.event.BeforeCommentUpdate, () => {})` as instead
|
|
22
26
|
*/
|
|
23
27
|
onBeforeUpdateThreadComment(this: FWorkbook, callback: (params: IUpdateCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
24
28
|
/**
|
|
25
|
-
*
|
|
26
|
-
* @param callback Callback function that will be called when the event is fired
|
|
27
|
-
* @returns A disposable object that can be used to unsubscribe from the event
|
|
29
|
+
* @deprecated use `univerAPI.addEvent(univerAPI.event.BeforeCommentDelete, () => {})` as instead
|
|
28
30
|
*/
|
|
29
31
|
onBeforeDeleteThreadComment(this: FWorkbook, callback: (params: IDeleteCommentCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
30
32
|
}
|
|
31
33
|
export declare class FWorkbookThreadCommentMixin extends FWorkbook implements IFWorkbookThreadCommentMixin {
|
|
32
34
|
_threadCommentModel: ThreadCommentModel;
|
|
33
35
|
_initialize(): void;
|
|
36
|
+
getComments(): FThreadComment[];
|
|
37
|
+
clearComments(): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated
|
|
40
|
+
*/
|
|
34
41
|
onThreadCommentChange(callback: (commentUpdate: CommentUpdate) => void | false): IDisposable;
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated
|
|
44
|
+
*/
|
|
35
45
|
onBeforeAddThreadComment(callback: (params: IAddCommentCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated
|
|
48
|
+
*/
|
|
36
49
|
onBeforeUpdateThreadComment(callback: (params: IUpdateCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated
|
|
52
|
+
*/
|
|
37
53
|
onBeforeDeleteThreadComment(callback: (params: IDeleteCommentCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable;
|
|
38
54
|
}
|
|
39
55
|
declare module '@univerjs/sheets/facade' {
|
|
@@ -6,16 +6,42 @@ export interface IFWorksheetCommentMixin {
|
|
|
6
6
|
/**
|
|
7
7
|
* Get all comments in the current sheet
|
|
8
8
|
* @returns all comments in the current sheet
|
|
9
|
+
* ```ts
|
|
10
|
+
* const workbook = univerAPI.getActiveWorkbook();
|
|
11
|
+
* const worksheet = workbook.getSheetById(sheetId);
|
|
12
|
+
* const comments = worksheet.getComments();
|
|
13
|
+
* ```
|
|
9
14
|
*/
|
|
10
15
|
getComments(): FThreadComment[];
|
|
16
|
+
/**
|
|
17
|
+
* Clear all comments in the current sheet
|
|
18
|
+
* ```ts
|
|
19
|
+
* const workbook = univerAPI.getActiveWorkbook();
|
|
20
|
+
* const worksheet = workbook.getSheetById(sheetId);
|
|
21
|
+
* await worksheet.clearComments();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
clearComments(): Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* get comment by comment id
|
|
27
|
+
* @param {string} commentId comment id
|
|
28
|
+
* ```ts
|
|
29
|
+
* const workbook = univerAPI.getActiveWorkbook();
|
|
30
|
+
* const worksheet = workbook.getSheetById(sheetId);
|
|
31
|
+
* const comment = worksheet.getCommentById(commentId);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
getCommentById(commentId: string): FThreadComment | undefined;
|
|
11
35
|
}
|
|
12
36
|
export declare class FWorksheetCommentMixin extends FWorksheet implements IFWorksheetCommentMixin {
|
|
13
37
|
getComments(): FThreadComment[];
|
|
38
|
+
clearComments(): Promise<boolean>;
|
|
14
39
|
/**
|
|
15
40
|
* Subscribe to comment events.
|
|
16
41
|
* @param callback Callback function, param contains comment info and target cell.
|
|
17
42
|
*/
|
|
18
43
|
onCommented(callback: (params: IAddCommentCommandParams) => void): IDisposable;
|
|
44
|
+
getCommentById(commentId: string): FThreadComment | undefined;
|
|
19
45
|
}
|
|
20
46
|
declare module '@univerjs/sheets/facade' {
|
|
21
47
|
interface FWorksheet extends IFWorksheetCommentMixin {
|
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
import './f-range';
|
|
17
17
|
import './f-workbook';
|
|
18
18
|
import './f-worksheet';
|
|
19
|
-
|
|
19
|
+
import './f-event';
|
|
20
|
+
export type * from './f-event';
|
|
20
21
|
export type * from './f-range';
|
|
22
|
+
export type * from './f-thread-comment';
|
|
23
|
+
export { FThreadComment } from './f-thread-comment';
|
|
21
24
|
export type * from './f-workbook';
|
|
22
25
|
export type * from './f-worksheet';
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(s,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/sheets-thread-comment"),require("@univerjs/sheets/facade"),require("@univerjs/thread-comment"),require("@univerjs/engine-formula"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-thread-comment","@univerjs/sheets/facade","@univerjs/thread-comment","@univerjs/engine-formula","rxjs"],r):(s=typeof globalThis<"u"?globalThis:s||self,r(s.UniverSheetsThreadCommentFacade={},s.UniverCore,s.UniverSheetsThreadComment,s.UniverSheetsFacade,s.UniverThreadComment,s.UniverEngineFormula,s.rxjs))})(this,function(s,r,a,u,m,U,b){"use strict";var w=Object.defineProperty;var B=(s,r,a)=>r in s?w(s,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[r]=a;var T=(s,r,a)=>B(s,typeof r!="symbol"?r+"":r,a);var S=Object.defineProperty,j=Object.getOwnPropertyDescriptor,k=(h,e,t,n)=>{for(var o=n>1?void 0:n?j(e,t):e,i=h.length-1,d;i>=0;i--)(d=h[i])&&(o=(n?d(e,t,o):d(o))||o);return n&&o&&S(e,t,o),o},I=(h,e)=>(t,n)=>e(t,n,h);class p{constructor(e){T(this,"_comment",{id:r.generateRandomId(),ref:"",threadId:"",dT:"",personId:"",text:r.RichTextBuilder.newEmptyData().body,attachments:[],unitId:"",subUnitId:""});e&&(this._comment=e)}static create(e){return new p(e)}get personId(){return this._comment.personId}get dateTime(){return this._comment.dT}get content(){return r.RichTextValue.createByBody(this._comment.text)}get id(){return this._comment.id}get threadId(){return this._comment.threadId}copy(){return _.create(r.Tools.deepClone(this._comment))}}class _ extends p{static create(e){return new _(e)}setContent(e){return e instanceof r.RichTextValue?this._comment.text=e.getData().body:this._comment.text=e,this}setPersonId(e){return this._comment.personId=e,this}setDateTime(e){return this._comment.dT=m.getDT(e),this}setId(e){return this._comment.id=e,this}setThreadId(e){return this._comment.threadId=e,this}build(){return this._comment}}s.FThreadComment=class{constructor(e,t,n,o,i,d,C){this._thread=e,this._parent=t,this._injector=n,this._commandService=o,this._univerInstanceService=i,this._threadCommentModel=d,this._userManagerService=C}_getRef(){var n;const e=((n=this._parent)==null?void 0:n.ref)||this._thread.ref;return U.deserializeRangeWithSheet(e).range}getIsRoot(){return!this._parent}getCommentData(){const{children:e,...t}=this._thread;return t}getReplies(){var n;const e=this._getRef(),t=this._threadCommentModel.getCommentWithChildren(this._thread.unitId,this._thread.subUnitId,e.startRow,e.startColumn);return(n=t==null?void 0:t.children)==null?void 0:n.map(o=>this._injector.createInstance(s.FThreadComment,o))}getRange(){const e=this._univerInstanceService.getUnit(this._thread.unitId,r.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const t=e.getSheetBySheetId(this._thread.subUnitId);if(!t)return null;const n=this._getRef();return this._injector.createInstance(u.FRange,e,t,n)}getContent(){return this._thread.text}getRichText(){const e=this._thread.text;return r.RichTextValue.create({body:e,documentStyle:{},id:"d"})}deleteAsync(){return this._commandService.executeCommand(this.getIsRoot()?m.DeleteCommentTreeCommand.id:m.DeleteCommentCommand.id,{commentId:this._thread.id,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId})}delete(){return this.deleteAsync()}async update(e){return this.updateAsync(e)}async updateAsync(e){const t=e instanceof r.RichTextValue?e.getData().body:e,n=m.getDT();return await this._commandService.executeCommand(m.UpdateCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,payload:{commentId:this._thread.id,text:t,updated:!0,updateT:n}})}resolve(e){return this.resolveAsync(e)}resolveAsync(e){return this._commandService.executeCommand(m.ResolveCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,commentId:this._thread.id,resolved:e!=null?e:!this._thread.resolved})}async replyAsync(e){var n;const t=e.build();return this._commandService.executeCommand(m.AddCommentCommand.id,{unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,comment:{id:r.generateRandomId(),parentId:this._thread.id,threadId:this._thread.threadId,ref:(n=this._parent)==null?void 0:n.ref,unitId:this._thread.unitId,subUnitId:this._thread.subUnitId,text:t.text,attachments:t.attachments,dT:t.dT||m.getDT(),personId:t.personId||this._userManagerService.getCurrentUser().userID}})}},s.FThreadComment=k([I(2,r.Inject(r.Injector)),I(3,r.ICommandService),I(4,r.IUniverInstanceService),I(5,r.Inject(a.SheetsThreadCommentModel)),I(6,r.Inject(r.UserManagerService))],s.FThreadComment);class y extends u.FRange{getComment(){const t=this._injector.get(a.SheetsThreadCommentModel),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),i=t.getByLocation(n,o,this._range.startRow,this._range.startColumn);if(!i)return null;const d=t.getComment(n,o,i);return d?this._injector.createInstance(s.FThreadComment,d):null}getComments(){const t=this._injector.get(a.SheetsThreadCommentModel),n=this._workbook.getUnitId(),o=this._worksheet.getSheetId(),i=[];return r.Range.foreach(this._range,(d,C)=>{const l=t.getByLocation(n,o,d,C);if(l){const g=t.getComment(n,o,l);g&&i.push(this._injector.createInstance(s.FThreadComment,g))}}),i}addComment(e){var v;const t=this._injector,n=(v=this.getComment())==null?void 0:v.getCommentData(),o=t.get(r.ICommandService),i=t.get(r.UserManagerService),d=this._workbook.getUnitId(),C=this._worksheet.getSheetId(),l=`${r.Tools.chatAtABC(this._range.startColumn)}${this._range.startRow+1}`,g=i.getCurrentUser(),f=e instanceof _?e.build():{text:e};return o.executeCommand(m.AddCommentCommand.id,{unitId:d,subUnitId:C,comment:{text:f.text,dT:f.dT||m.getDT(),attachments:[],id:f.id||r.generateRandomId(),ref:l,personId:f.personId||g.userID,parentId:n==null?void 0:n.id,unitId:d,subUnitId:C,threadId:(n==null?void 0:n.threadId)||r.generateRandomId()}})}clearComment(){var d;const e=this._injector,t=(d=this.getComment())==null?void 0:d.getCommentData(),n=e.get(r.ICommandService),o=this._workbook.getUnitId(),i=this._worksheet.getSheetId();return t?n.executeCommand(m.DeleteCommentTreeCommand.id,{unitId:o,subUnitId:i,threadId:t.threadId,commentId:t.id}):Promise.resolve(!0)}clearComments(){const t=this.getComments().map(n=>n.deleteAsync());return Promise.all(t).then(()=>!0)}}u.FRange.extend(y);class x extends u.FWorkbook{_initialize(){Object.defineProperty(this,"_threadCommentModel",{get(){return this._injector.get(m.ThreadCommentModel)}})}getComments(){return this._threadCommentModel.getUnit(this._workbook.getUnitId()).map(e=>this._injector.createInstance(s.FThreadComment,e.root))}clearComments(){const t=this.getComments().map(n=>n.deleteAsync());return Promise.all(t).then(()=>!0)}onThreadCommentChange(e){return r.toDisposable(this._threadCommentModel.commentUpdate$.pipe(b.filter(t=>t.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddThreadComment(e){return r.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===m.AddCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeAddThreadComment")}}))}onBeforeUpdateThreadComment(e){return r.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===m.UpdateCommentCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment")}}))}onBeforeDeleteThreadComment(e){return r.toDisposable(this._commandService.beforeCommandExecuted((t,n)=>{const o=t.params;if(t.id===m.DeleteCommentCommand.id||t.id===m.DeleteCommentTreeCommand.id){if(o.unitId!==this._workbook.getUnitId())return;if(e(o,n)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment")}}))}}u.FWorkbook.extend(x);class D extends u.FWorksheet{getComments(){return this._injector.get(a.SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(n=>this._injector.createInstance(s.FThreadComment,n))}clearComments(){const t=this.getComments().map(n=>n.deleteAsync());return Promise.all(t).then(()=>!0)}onCommented(e){return this._injector.get(r.ICommandService).onCommandExecuted(n=>{if(n.id===m.AddCommentCommand.id){const o=n.params;e(o)}})}getCommentById(e){const n=this._injector.get(a.SheetsThreadCommentModel).getComment(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);if(n)return this._injector.createInstance(s.FThreadComment,n)}}u.FWorksheet.extend(D);const c={CommentAdded:"CommentAdded",BeforeCommentAdd:"BeforeCommentAdd",CommentUpdated:"CommentUpdated",BeforeCommentUpdate:"BeforeCommentUpdate",CommentDeleted:"CommentDeleted",BeforeCommentDeleted:"BeforeCommentDeleted",CommentResolved:"CommentResolved",BeforeCommentResolve:"BeforeCommentResolve"};class R extends r.FEventName{get CommentAdded(){return c.CommentAdded}get BeforeCommentAdd(){return c.BeforeCommentAdd}get CommentUpdated(){return c.CommentUpdated}get BeforeCommentUpdate(){return c.BeforeCommentUpdate}get CommentDeleted(){return c.CommentDeleted}get BeforeCommentDeleted(){return c.BeforeCommentDeleted}get CommentResolved(){return c.CommentResolved}get BeforeCommentResolve(){return c.BeforeCommentResolve}}r.FEventName.extend(R),Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(m,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("@univerjs/thread-comment"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-formula","@univerjs/sheets","@univerjs/thread-comment","rxjs"],o):(m=typeof globalThis<"u"?globalThis:m||self,o(m.UniverSheetsThreadComment={},m.UniverCore,m.UniverEngineFormula,m.UniverSheets,m.UniverThreadComment,m.rxjs))})(this,function(m,o,l,g,p,S){"use strict";var O=Object.defineProperty;var x=(m,o,l)=>o in m?O(m,o,{enumerable:!0,configurable:!0,writable:!0,value:l}):m[o]=l;var f=(m,o,l)=>x(m,typeof o!="symbol"?o+"":o,l);var T=Object.defineProperty,y=Object.getOwnPropertyDescriptor,U=(h,i,e,n)=>{for(var t=n>1?void 0:n?y(i,e):i,r=h.length-1,s;r>=0;r--)(s=h[r])&&(t=(n?s(i,e,t):s(t))||t);return n&&t&&T(i,e,t),t},M=(h,i)=>(e,n)=>i(e,n,h);m.SheetsThreadCommentModel=class extends o.Disposable{constructor(e,n){super();f(this,"_matrixMap",new Map);f(this,"_locationMap",new Map);f(this,"_commentUpdate$",new S.Subject);f(this,"commentUpdate$",this._commentUpdate$.asObservable());this._threadCommentModel=e,this._univerInstanceService=n,this._init(),this.disposeWithMe(()=>{this._commentUpdate$.complete()})}_init(){this._initData(),this._initUpdateTransform()}_ensureCommentMatrix(e,n){let t=this._matrixMap.get(e);t||(t=new Map,this._matrixMap.set(e,t));let r=t.get(n);return r||(r=new o.ObjectMatrix,t.set(n,r)),r}_ensureCommentLocationMap(e,n){let t=this._locationMap.get(e);t||(t=new Map,this._locationMap.set(e,t));let r=t.get(n);return r||(r=new Map,t.set(n,r)),r}_addCommentToMatrix(e,n,t,r){var a;const s=(a=e.getValue(n,t))!=null?a:new Set;s.add(r),e.setValue(n,t,s)}_deleteCommentFromMatrix(e,n,t,r){if(n>=0&&t>=0){const s=e.getValue(n,t);s&&s.has(r)&&(s.delete(r),s.size===0&&e.realDeleteValue(n,t))}}_ensure(e,n){const t=this._ensureCommentMatrix(e,n),r=this._ensureCommentLocationMap(e,n);return{matrix:t,locationMap:r}}_initData(){const e=this._threadCommentModel.getAll();for(const n of e)for(const t of n.threads){const{unitId:r,subUnitId:s,root:a}=t;this._addComment(r,s,a)}}_addComment(e,n,t){const r=l.singleReferenceToGrid(t.ref),s=t.parentId,{row:a,column:d}=r,c=t.id,{matrix:_,locationMap:u}=this._ensure(e,n);!s&&a>=0&&d>=0&&(this._addCommentToMatrix(_,a,d,c),u.set(c,{row:a,column:d})),s||this._commentUpdate$.next({unitId:e,subUnitId:n,payload:t,type:"add",isRoot:!s,...r})}_initUpdateTransform(){this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t}=e;try{if(this._univerInstanceService.getUnitType(n)!==o.UniverInstanceType.UNIVER_SHEET)return}catch{}const{matrix:r,locationMap:s}=this._ensure(n,t);switch(e.type){case"add":{this._addComment(e.unitId,e.subUnitId,e.payload);break}case"delete":{const{isRoot:a,comment:d}=e.payload;if(a){const c=l.singleReferenceToGrid(d.ref),{row:_,column:u}=c;this._deleteCommentFromMatrix(r,_,u,d.id),this._commentUpdate$.next({...e,...c})}break}case"update":{const{commentId:a}=e.payload,d=this._threadCommentModel.getComment(n,t,a);if(!d)return;const c=l.singleReferenceToGrid(d.ref);this._commentUpdate$.next({...e,...c});break}case"updateRef":{const a=l.singleReferenceToGrid(e.payload.ref),{commentId:d}=e.payload,c=s.get(d);if(!c)return;const{row:_,column:u}=c;this._deleteCommentFromMatrix(r,_,u,d),s.delete(d),a.row>=0&&a.column>=0&&(this._addCommentToMatrix(r,a.row,a.column,d),s.set(d,{row:a.row,column:a.column})),this._commentUpdate$.next({...e,...a});break}case"resolve":{const{unitId:a,subUnitId:d,payload:c}=e,{locationMap:_}=this._ensure(a,d),u=_.get(c.commentId);u&&this._commentUpdate$.next({...e,...u});break}}}))}getByLocation(e,n,t,r){var d;return(d=this.getAllByLocation(e,n,t,r).filter(c=>!c.resolved)[0])==null?void 0:d.id}getAllByLocation(e,n,t,r){const a=this._ensureCommentMatrix(e,n).getValue(t,r);return a?Array.from(a).map(d=>this.getComment(e,n,d)).filter(Boolean):[]}getComment(e,n,t){return this._threadCommentModel.getComment(e,n,t)}getCommentWithChildren(e,n,t,r){const s=this.getByLocation(e,n,t,r);if(!s)return;const a=this.getComment(e,n,s);if(a)return this._threadCommentModel.getThread(e,n,a.threadId)}showCommentMarker(e,n,t,r){const s=this.getByLocation(e,n,t,r);if(!s)return!1;const a=this.getComment(e,n,s);return!!(a&&!a.resolved)}getSubUnitAll(e,n){return this._threadCommentModel.getUnit(e).filter(t=>t.subUnitId===n).map(t=>t.root)}},m.SheetsThreadCommentModel=U([M(0,o.Inject(p.ThreadCommentModel)),M(1,o.IUniverInstanceService)],m.SheetsThreadCommentModel);var I=Object.defineProperty,b=Object.getOwnPropertyDescriptor,j=(h,i,e,n)=>{for(var t=n>1?void 0:n?b(i,e):i,r=h.length-1,s;r>=0;r--)(s=h[r])&&(t=(n?s(i,e,t):s(t))||t);return n&&t&&I(i,e,t),t},C=(h,i)=>(e,n)=>i(e,n,h);m.SheetsThreadCommentRefRangeController=class extends o.Disposable{constructor(e,n,t,r,s){super();f(this,"_disposableMap",new Map);f(this,"_watcherMap",new Map);f(this,"_handleRangeChange",(e,n,t,r,s)=>{const a=t.id,d={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};return r?{redos:[{id:p.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:l.serializeRange(r),commentId:a},silent:s}}],undos:[{id:p.UpdateCommentRefMutation.id,params:{unitId:e,subUnitId:n,payload:{ref:l.serializeRange(d),commentId:a},silent:s}}]}:{redos:[{id:p.DeleteCommentMutation.id,params:{unitId:e,subUnitId:n,commentId:a}}],undos:[{id:p.AddCommentMutation.id,params:{unitId:e,subUnitId:n,comment:t,sync:!0}}]}});this._refRangeService=e,this._sheetsThreadCommentModel=n,this._threadCommentModel=t,this._selectionManagerService=r,this._commandService=s,this._initData(),this._initRefRange()}_getIdWithUnitId(e,n,t){return`${e}-${n}-${t}`}_register(e,n,t){const r=t.id,s={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._disposableMap.set(this._getIdWithUnitId(e,n,r),this._refRangeService.registerRefRange(s,a=>{const d=g.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,a,{selectionManagerService:this._selectionManagerService}),c=Array.isArray(d)?d[0]:d;return c&&c.startColumn===s.startColumn&&c.startRow===s.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,n,t,c,!1)},e,n))}_watch(e,n,t){const r=t.id,s={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._watcherMap.set(this._getIdWithUnitId(e,n,r),this._refRangeService.watchRange(e,n,s,(a,d)=>{const{redos:c}=this._handleRangeChange(e,n,t,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,n,t){var s;const r=this._getIdWithUnitId(e,n,t);(s=this._watcherMap.get(r))==null||s.dispose(),this._watcherMap.delete(r)}_unregister(e,n,t){var s;const r=this._getIdWithUnitId(e,n,t);(s=this._disposableMap.get(r))==null||s.dispose(),this._disposableMap.delete(r)}_initData(){const e=this._threadCommentModel.getAll();for(const n of e)for(const t of n.threads){const{unitId:r,subUnitId:s,root:a}=t,d=l.singleReferenceToGrid(a.ref),c={...a,...d};this._register(r,s,c),this._watch(r,s,c)}}_initRefRange(){this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.subscribe(e=>{const{unitId:n,subUnitId:t}=e;switch(e.type){case"add":{if(e.payload.parentId)return;const r={...e.payload,row:e.row,column:e.column};this._register(e.unitId,e.subUnitId,r),this._watch(e.unitId,e.subUnitId,r);break}case"delete":{this._unregister(n,t,e.payload.commentId),this._unwatch(n,t,e.payload.commentId);break}case"updateRef":{const r=this._sheetsThreadCommentModel.getComment(n,t,e.payload.commentId);if(!r)return;this._unregister(n,t,e.payload.commentId);const s={...r,row:e.row,column:e.column};e.silent||(this._unwatch(n,t,e.payload.commentId),this._watch(n,t,s)),this._register(e.unitId,e.subUnitId,s);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}},m.SheetsThreadCommentRefRangeController=j([C(0,o.Inject(g.RefRangeService)),C(1,o.Inject(m.SheetsThreadCommentModel)),C(2,o.Inject(p.ThreadCommentModel)),C(3,o.Inject(g.SheetsSelectionsService)),C(4,o.ICommandService)],m.SheetsThreadCommentRefRangeController);const P="SHEET_THREAD_COMMENT_BASE_PLUGIN";var v=Object.defineProperty,$=Object.getOwnPropertyDescriptor,E=(h,i,e)=>i in h?v(h,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[i]=e,D=(h,i,e,n)=>{for(var t=n>1?void 0:n?$(i,e):i,r=h.length-1,s;r>=0;r--)(s=h[r])&&(t=(n?s(i,e,t):s(t))||t);return n&&t&&v(i,e,t),t},R=(h,i)=>(e,n)=>i(e,n,h),w=(h,i,e)=>E(h,typeof i!="symbol"?i+"":i,e);m.UniverSheetsThreadCommentPlugin=class extends o.Plugin{constructor(i,e,n){super(),this._injector=e,this._commandService=n}onStarting(){[[m.SheetsThreadCommentModel],[m.SheetsThreadCommentRefRangeController]].forEach(i=>{this._injector.add(i)}),this._injector.get(m.SheetsThreadCommentRefRangeController)}},w(m.UniverSheetsThreadCommentPlugin,"pluginName",P),w(m.UniverSheetsThreadCommentPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),m.UniverSheetsThreadCommentPlugin=D([o.DependentOn(p.UniverThreadCommentPlugin),R(1,o.Inject(o.Injector)),R(2,o.Inject(o.ICommandService))],m.UniverSheetsThreadCommentPlugin),Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-thread-comment",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer sheets thread comment base plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -51,17 +51,17 @@
|
|
|
51
51
|
"rxjs": ">=7.0.0"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@univerjs/core": "0.5.
|
|
55
|
-
"@univerjs/
|
|
56
|
-
"@univerjs/thread-comment": "0.5.
|
|
57
|
-
"@univerjs/
|
|
54
|
+
"@univerjs/core": "0.5.4",
|
|
55
|
+
"@univerjs/sheets": "0.5.4",
|
|
56
|
+
"@univerjs/thread-comment": "0.5.4",
|
|
57
|
+
"@univerjs/engine-formula": "0.5.4"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"rxjs": "^7.8.1",
|
|
61
61
|
"typescript": "^5.7.2",
|
|
62
|
-
"vite": "^6.0.
|
|
62
|
+
"vite": "^6.0.7",
|
|
63
63
|
"vitest": "^2.1.8",
|
|
64
|
-
"@univerjs-infra/shared": "0.5.
|
|
64
|
+
"@univerjs-infra/shared": "0.5.4"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
67
|
"test": "vitest run",
|