@univerjs/docs-thread-comment-ui 0.20.1 → 0.21.0-insiders.20260422-d7fcb4d

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 CHANGED
@@ -1,2 +1,717 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/docs-ui`),n=require(`@univerjs/thread-comment`),r=require(`@univerjs/thread-comment-ui`),i=require(`@univerjs/docs`),a=require(`@univerjs/engine-render`),o=require(`@univerjs/ui`),s=require(`rxjs`),c=require(`@univerjs/icons`),l=require(`react`),u=require(`react/jsx-runtime`);const d=`univer.doc.thread-comment-panel`,f=`default_doc`,p={id:`docs.command.add-comment`,type:e.CommandType.COMMAND,async handler(i,a){if(!a)return!1;let{comment:o,unitId:s}=a,c=await i.get(n.IThreadCommentDataSourceService).addComment(o),l=i.get(e.ICommandService),u=(0,t.addCustomDecorationBySelectionFactory)(i,{id:c.threadId,type:e.CustomDecorationType.COMMENT,unitId:s});return u?(await(0,e.sequenceExecute)([{id:n.AddCommentMutation.id,params:{unitId:s,subUnitId:f,comment:c}},u,{id:r.SetActiveCommentOperation.id,params:{unitId:s,subUnitId:f,commentId:c.id}}],l)).result:!1}},m={id:`docs.command.delete-comment`,type:e.CommandType.COMMAND,async handler(n,r){if(!r)return!1;let{commentId:i,unitId:a}=r,o=n.get(e.ICommandService),s=(0,t.deleteCustomDecorationFactory)(n,{id:i,unitId:a});return s?(await(0,e.sequenceExecute)([s],o)).result:!1}};function h(e){"@babel/helpers - typeof";return h=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},h(e)}function g(e,t){if(h(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(h(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function _(e){var t=g(e,`string`);return h(t)==`symbol`?t:t+``}function v(e,t,n){return(t=_(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function y(e,t){return function(n,r){t(n,r,e)}}function b(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let x=class extends e.Disposable{get addingComment(){return this._addingComment$.getValue()}constructor(e,t){super(),this._sidebarService=e,this._threadCommentPanelService=t,v(this,`_addingComment$`,new s.BehaviorSubject(void 0)),v(this,`addingComment$`,this._addingComment$.asObservable()),this.disposeWithMe(()=>{this._addingComment$.complete()})}startAdd(e){this._addingComment$.next(e)}endAdd(){this._addingComment$.next(void 0)}};x=b([y(0,o.ISidebarService),y(1,(0,e.Inject)(r.ThreadCommentPanelService))],x);const S={id:`docs.operation.show-comment-panel`,type:e.CommandType.OPERATION,handler(e,t){var n;let i=e.get(r.ThreadCommentPanelService),a=e.get(o.ISidebarService);return(!i.panelVisible||((n=a.options.children)==null?void 0:n.label)!==`univer.doc.thread-comment-panel`)&&(a.open({header:{title:`threadCommentUI.panel.title`},children:{label:d},width:320,onClose:()=>i.setPanelVisible(!1)}),i.setPanelVisible(!0)),t&&i.setActiveComment(t==null?void 0:t.activeComment),!0}},C={id:`docs.operation.toggle-comment-panel`,type:e.CommandType.OPERATION,handler(e){var t;let n=e.get(r.ThreadCommentPanelService),i=e.get(o.ISidebarService);return!n.panelVisible||((t=i.options.children)==null?void 0:t.label)!==`univer.doc.thread-comment-panel`?(i.open({header:{title:`threadCommentUI.panel.title`},children:{label:d},width:320,onClose:()=>n.setPanelVisible(!1)}),n.setPanelVisible(!0)):(i.close(),n.setPanelVisible(!1),n.setActiveComment(null)),!0}},w={id:`docs.operation.start-add-comment`,type:e.CommandType.OPERATION,handler(s){var c,l,u;let d=s.get(r.ThreadCommentPanelService),p=s.get(e.IUniverInstanceService).getCurrentUnitForType(e.UniverInstanceType.UNIVER_DOC),m=s.get(i.DocSelectionManagerService),h=s.get(a.IRenderManagerService),g=s.get(e.UserManagerService),_=s.get(x),v=s.get(e.ICommandService),y=s.get(o.ISidebarService),b=m.getActiveTextRange();if(!p||!b)return!1;let C=(c=h.getRenderById(p.getUnitId()))==null?void 0:c.with(t.DocSelectionRenderService);if(C==null||C.setReserveRangesStatus(!0),b.collapsed)return d.panelVisible?(d.setPanelVisible(!1),y.close()):v.executeCommand(S.id),!0;v.executeCommand(S.id);let w=p.getUnitId(),T=((l=(u=p.getBody())==null?void 0:u.dataStream)==null?``:l).slice(b.startOffset,b.endOffset),E=e.BuildTextUtils.transform.getPlainText(T),D=f,O={unitId:w,subUnitId:D,id:``,ref:E,dT:(0,n.getDT)(),personId:g.getCurrentUser().userID,text:{dataStream:`\r
2
- `},startOffset:b.startOffset,endOffset:b.endOffset,collapsed:!0,threadId:``};return C==null||C.blur(),_.startAdd(O),d.setActiveComment({unitId:w,subUnitId:D,commentId:``}),!0}};var T=`@univerjs/docs-thread-comment-ui`,E=`0.20.1`;const D=`docs-thread-comment-ui.config`;Symbol(D);const O={};let k=class extends e.Disposable{constructor(e,t,n,r,i,a){super(),this._threadCommentPanelService=e,this._univerInstanceService=t,this._commandService=n,this._docThreadCommentService=r,this._renderManagerService=i,this._threadCommentModel=a,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){let t;this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===i.SetTextSelectionsOperation.id){let{unitId:i,ranges:s}=n.params;if((0,e.isInternalEditorID)(i))return;let c=this._univerInstanceService.getUnit(i,e.UniverInstanceType.UNIVER_DOC),l=s[0];if((t==null?void 0:t.startOffset)===(l==null?void 0:l.startOffset)&&(t==null?void 0:t.endOffset)===(l==null?void 0:l.endOffset))return;if(t=l,l&&c){let{startOffset:e,endOffset:t,collapsed:n}=l,r;if(n){var a;r=(a=c.getBody())==null||(a=a.customDecorations)==null?void 0:a.find(n=>n.startIndex<=e&&n.endIndex>=t-1)}else{var o;r=(o=c.getBody())==null||(o=o.customDecorations)==null?void 0:o.find(n=>n.startIndex<=e&&n.endIndex>=t-1)}if(r){let e=this._threadCommentModel.getComment(i,f,r.id);e&&!e.resolved&&this._commandService.executeCommand(S.id,{activeComment:{unitId:i,subUnitId:f,commentId:r.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(r.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var n;if(e){let n=this._univerInstanceService.getUnit(e.unitId);if(n){var r,i;let a=(r=this._renderManagerService.getRenderById(e.unitId))==null?void 0:r.with(t.DocBackScrollRenderController),o=(i=n.getBody())==null||(i=i.customDecorations)==null?void 0:i.find(t=>t.id===e.commentId);o&&a&&a.scrollToRange({startOffset:o.startIndex,endOffset:o.endIndex,collapsed:!1})}}(!e||e.commentId!==((n=this._docThreadCommentService.addingComment)==null?void 0:n.id))&&this._docThreadCommentService.endAdd()}))}};k=b([y(0,(0,e.Inject)(r.ThreadCommentPanelService)),y(1,e.IUniverInstanceService),y(2,e.ICommandService),y(3,(0,e.Inject)(x)),y(4,a.IRenderManagerService),y(5,(0,e.Inject)(n.ThreadCommentModel))],k);const A=t=>{var n;let r=t.get(a.IRenderManagerService),o=t.get(i.DocSelectionManagerService),s=(n=(0,a.withCurrentTypeOfRenderer)(e.UniverInstanceType.UNIVER_DOC,i.DocSkeletonManagerService,t.get(e.IUniverInstanceService),r))==null?void 0:n.getSkeleton(),c=s==null?void 0:s.getViewModel().getEditArea();if(c===a.DocumentEditArea.FOOTER||c===a.DocumentEditArea.HEADER)return!0;let l=o.getActiveTextRange();return!!(l==null||l.collapsed)};function j(t){return{id:w.id,type:o.MenuItemType.BUTTON,icon:`CommentIcon`,title:`threadCommentUI.panel.addComment`,tooltip:`threadCommentUI.panel.addComment`,hidden$:(0,o.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_DOC,void 0,e.SHEET_EDITOR_UNITS),disabled$:new s.Observable(function(e){let n=t.get(i.DocSelectionManagerService).textSelection$.pipe((0,s.debounceTime)(16)).subscribe(()=>{e.next(A(t))});return()=>{n.unsubscribe()}})}}function M(t){return{id:C.id,type:o.MenuItemType.BUTTON,icon:`CommentIcon`,title:`threadCommentUI.panel.addComment`,tooltip:`threadCommentUI.panel.addComment`,hidden$:(0,o.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_DOC)}}const N={[o.RibbonInsertGroup.MEDIA]:{[C.id]:{order:3,menuItemFactory:M}},[o.ContextMenuPosition.MAIN_AREA]:{[o.ContextMenuGroup.DATA]:{[w.id]:{order:1,menuItemFactory:j}}}},P=()=>{let t=(0,o.useDependency)(e.IUniverInstanceService),n=(0,o.useDependency)(e.Injector),a=(0,o.useObservable)((0,l.useMemo)(()=>t.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_DOC).pipe((0,s.filter)(t=>!!t&&!(0,e.isInternalEditorID)(t.getUnitId()))),[t])),c=(0,l.useMemo)(()=>new s.Observable(e=>e.next(f)),[]),d=(0,o.useDependency)(i.DocSelectionManagerService);(0,o.useObservable)((0,l.useMemo)(()=>d.textSelection$.pipe((0,s.debounceTime)(16)),[d.textSelection$]));let h=(0,o.useDependency)(e.ICommandService),g=(0,o.useDependency)(x),_=(0,o.useObservable)(g.addingComment$),[v,y]=(0,l.useState)([]);if((0,l.useEffect)(()=>{var e;let t=new Set,n=a==null?void 0:a.getCustomDecorations();y((e=n==null?void 0:n.map(e=>e.id).filter(e=>{let n=t.has(e);return t.add(e),!n}))==null?[]:e);let r=h.onCommandExecuted(e=>{if(e.id===i.RichTextEditingMutation.id){var t;let e=new Set,n=a==null?void 0:a.getCustomDecorations();y((t=n==null?void 0:n.map(e=>e.id).filter(t=>{let n=e.has(t);return e.add(t),!n}))==null?[]:t)}});return()=>{r.dispose()}},[h,a]),!a)return null;let b=A(n),S=a.getUnitId();return(0,u.jsx)(r.ThreadCommentPanel,{unitId:S,subUnitId$:c,type:e.UniverInstanceType.UNIVER_DOC,onAdd:()=>{h.executeCommand(w.id)},getSubUnitName:()=>``,disableAdd:b,tempComment:_,onAddComment:e=>{if(!e.parentId){let t={unitId:S,range:_,comment:e};return h.executeCommand(p.id,t),g.endAdd(),!1}return!0},onDeleteComment:e=>{if(!e.parentId){let t={unitId:S,commentId:e.id};return h.executeCommand(m.id,t),!1}return!0},showComments:v})};let F=class extends e.Disposable{constructor(e,t,n){super(),this._commandService=e,this._menuManagerService=t,this._componentManager=n,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[p,m,S,w,C].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(N)}_initComponents(){[[d,P],[`CommentIcon`,c.CommentIcon]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};F=b([y(0,e.ICommandService),y(1,o.IMenuManagerService),y(2,(0,e.Inject)(o.ComponentManager))],F);let I=class extends e.Disposable{constructor(e,t,n,r,i,a,o){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=n,this._docRenderController=r,this._univerInstanceService=i,this._threadCommentModel=a,this._commandService=o,this._interceptorViewModel(),this._initReRender(),this._initSyncComments()}_initReRender(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(t=>{var n;if(t){this._docRenderController.reRender(t.unitId);return}let r=(n=this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_DOC))==null?void 0:n.getUnitId();r&&this._docRenderController.reRender(r)})),this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{e.type===`resolve`&&this._docRenderController.reRender(e.unitId)}))}_interceptorViewModel(){this._docInterceptorService.intercept(i.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION,{handler:(e,t,n)=>{if(!e)return n(e);let{unitId:r,index:i,customDecorations:a}=t,{commentId:o,unitId:s}=this._threadCommentPanelService.activeCommentId||{},c=a.find(e=>e.id===o),l=this._threadCommentModel.getComment(r,f,e.id);if(!l)return n({...e,show:!1});let u=c&&i>=c.startIndex&&i<=c.endIndex,d=s===r&&e.id===o;return n({...e,active:d||u,show:!l.resolved})}})}_initSyncComments(){var t,n;let r=this._context.unit.getUnitId(),a=f,o=(t=(n=this._context.unit.getBody())==null||(n=n.customDecorations)==null?void 0:n.filter(t=>t.type===e.CustomDecorationType.COMMENT).map(e=>e.id))==null?[]:t;o.forEach(e=>{this._threadCommentModel.getComment(r,a,e)||this._threadCommentModel.addComment(r,a,{id:e,threadId:e,ref:``,dT:``,personId:``,text:{dataStream:``},unitId:r,subUnitId:a})}),o.length&&this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(),`default_doc`,o);let s=o.sort();this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===i.RichTextEditingMutation.id){var n,o;if(t.params.unitId!==this._context.unit.getUnitId())return;let i=(n=(o=this._context.unit.getBody())==null||(o=o.customDecorations)==null?void 0:o.filter(t=>t.type===e.CustomDecorationType.COMMENT).map(e=>e.id))==null?[]:n,c=i.sort();if(JSON.stringify(s)!==JSON.stringify(c)){let e=new Set(s),t=new Set(c),n=new Set,o=new Set;i.forEach(t=>{e.has(t)||n.add(t)}),s.forEach(e=>{t.has(e)||o.add(e)}),s=c,n.forEach(e=>{this._threadCommentModel.getComment(r,a,e)||this._threadCommentModel.addComment(r,a,{id:e,threadId:e,ref:``,dT:``,personId:``,text:{dataStream:``},unitId:r,subUnitId:a})}),this._threadCommentModel.syncThreadComments(r,a,[...n])}}}))}};I=b([y(1,(0,e.Inject)(i.DocInterceptorService)),y(2,(0,e.Inject)(r.ThreadCommentPanelService)),y(3,(0,e.Inject)(t.DocRenderController)),y(4,e.IUniverInstanceService),y(5,(0,e.Inject)(n.ThreadCommentModel)),y(6,e.ICommandService)],I);let L=class extends e.Plugin{constructor(t=O,n,r,i){super(),this._config=t,this._injector=n,this._renderManagerSrv=r,this._configService=i;let{menu:a,...o}=(0,e.merge)({},O,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(D,o)}onStarting(){[[F],[k],[x]].forEach(e=>{this._injector.add(e)})}onRendered(){this._initRenderModule(),this._injector.get(k),this._injector.get(F)}_initRenderModule(){[I].forEach(t=>{this._renderManagerSrv.registerRenderModule(e.UniverInstanceType.UNIVER_DOC,t)})}};v(L,`pluginName`,`DOC_THREAD_COMMENT_UI_PLUGIN`),v(L,`packageName`,T),v(L,`version`,E),v(L,`type`,e.UniverInstanceType.UNIVER_DOC),L=b([(0,e.DependentOn)(r.UniverThreadCommentUIPlugin),y(1,(0,e.Inject)(e.Injector)),y(2,a.IRenderManagerService),y(3,e.IConfigService)],L),exports.AddDocCommentComment=p,exports.DeleteDocCommentComment=m,exports.ShowCommentPanelOperation=S,exports.StartAddCommentOperation=w,Object.defineProperty(exports,`UniverDocsThreadCommentUIPlugin`,{enumerable:!0,get:function(){return L}});
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _univerjs_core = require("@univerjs/core");
3
+ let _univerjs_docs_ui = require("@univerjs/docs-ui");
4
+ let _univerjs_thread_comment = require("@univerjs/thread-comment");
5
+ let _univerjs_thread_comment_ui = require("@univerjs/thread-comment-ui");
6
+ let _univerjs_docs = require("@univerjs/docs");
7
+ let _univerjs_engine_render = require("@univerjs/engine-render");
8
+ let _univerjs_ui = require("@univerjs/ui");
9
+ let rxjs = require("rxjs");
10
+ let _univerjs_icons = require("@univerjs/icons");
11
+ let react = require("react");
12
+ let react_jsx_runtime = require("react/jsx-runtime");
13
+
14
+ //#region src/common/const.ts
15
+ /**
16
+ * Copyright 2023-present DreamNum Co., Ltd.
17
+ *
18
+ * Licensed under the Apache License, Version 2.0 (the "License");
19
+ * you may not use this file except in compliance with the License.
20
+ * You may obtain a copy of the License at
21
+ *
22
+ * http://www.apache.org/licenses/LICENSE-2.0
23
+ *
24
+ * Unless required by applicable law or agreed to in writing, software
25
+ * distributed under the License is distributed on an "AS IS" BASIS,
26
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
+ * See the License for the specific language governing permissions and
28
+ * limitations under the License.
29
+ */
30
+ const DOCS_THREAD_COMMENT_PANEL = "univer.doc.thread-comment-panel";
31
+ const PLUGIN_NAME = "DOC_THREAD_COMMENT_UI_PLUGIN";
32
+ const DEFAULT_DOC_SUBUNIT_ID = "default_doc";
33
+
34
+ //#endregion
35
+ //#region src/commands/commands/add-doc-comment.command.ts
36
+ const AddDocCommentComment = {
37
+ id: "docs.command.add-comment",
38
+ type: _univerjs_core.CommandType.COMMAND,
39
+ async handler(accessor, params) {
40
+ if (!params) return false;
41
+ const { comment: originComment, unitId } = params;
42
+ const comment = await accessor.get(_univerjs_thread_comment.IThreadCommentDataSourceService).addComment(originComment);
43
+ const commandService = accessor.get(_univerjs_core.ICommandService);
44
+ const doMutation = (0, _univerjs_docs_ui.addCustomDecorationBySelectionFactory)(accessor, {
45
+ id: comment.threadId,
46
+ type: _univerjs_core.CustomDecorationType.COMMENT,
47
+ unitId
48
+ });
49
+ if (doMutation) return (await (0, _univerjs_core.sequenceExecute)([
50
+ {
51
+ id: _univerjs_thread_comment.AddCommentMutation.id,
52
+ params: {
53
+ unitId,
54
+ subUnitId: DEFAULT_DOC_SUBUNIT_ID,
55
+ comment
56
+ }
57
+ },
58
+ doMutation,
59
+ {
60
+ id: _univerjs_thread_comment_ui.SetActiveCommentOperation.id,
61
+ params: {
62
+ unitId,
63
+ subUnitId: DEFAULT_DOC_SUBUNIT_ID,
64
+ commentId: comment.id
65
+ }
66
+ }
67
+ ], commandService)).result;
68
+ return false;
69
+ }
70
+ };
71
+
72
+ //#endregion
73
+ //#region src/commands/commands/delete-doc-comment.command.ts
74
+ const DeleteDocCommentComment = {
75
+ id: "docs.command.delete-comment",
76
+ type: _univerjs_core.CommandType.COMMAND,
77
+ async handler(accessor, params) {
78
+ if (!params) return false;
79
+ const { commentId, unitId } = params;
80
+ const commandService = accessor.get(_univerjs_core.ICommandService);
81
+ const doMutation = (0, _univerjs_docs_ui.deleteCustomDecorationFactory)(accessor, {
82
+ id: commentId,
83
+ unitId
84
+ });
85
+ if (doMutation) return (await (0, _univerjs_core.sequenceExecute)([doMutation], commandService)).result;
86
+ return false;
87
+ }
88
+ };
89
+
90
+ //#endregion
91
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
92
+ function _typeof(o) {
93
+ "@babel/helpers - typeof";
94
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
95
+ return typeof o;
96
+ } : function(o) {
97
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
98
+ }, _typeof(o);
99
+ }
100
+
101
+ //#endregion
102
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
103
+ function toPrimitive(t, r) {
104
+ if ("object" != _typeof(t) || !t) return t;
105
+ var e = t[Symbol.toPrimitive];
106
+ if (void 0 !== e) {
107
+ var i = e.call(t, r || "default");
108
+ if ("object" != _typeof(i)) return i;
109
+ throw new TypeError("@@toPrimitive must return a primitive value.");
110
+ }
111
+ return ("string" === r ? String : Number)(t);
112
+ }
113
+
114
+ //#endregion
115
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
116
+ function toPropertyKey(t) {
117
+ var i = toPrimitive(t, "string");
118
+ return "symbol" == _typeof(i) ? i : i + "";
119
+ }
120
+
121
+ //#endregion
122
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
123
+ function _defineProperty(e, r, t) {
124
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
125
+ value: t,
126
+ enumerable: !0,
127
+ configurable: !0,
128
+ writable: !0
129
+ }) : e[r] = t, e;
130
+ }
131
+
132
+ //#endregion
133
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
134
+ function __decorateParam(paramIndex, decorator) {
135
+ return function(target, key) {
136
+ decorator(target, key, paramIndex);
137
+ };
138
+ }
139
+
140
+ //#endregion
141
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
142
+ function __decorate(decorators, target, key, desc) {
143
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
144
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
145
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
146
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
147
+ }
148
+
149
+ //#endregion
150
+ //#region src/services/doc-thread-comment.service.ts
151
+ let DocThreadCommentService = class DocThreadCommentService extends _univerjs_core.Disposable {
152
+ get addingComment() {
153
+ return this._addingComment$.getValue();
154
+ }
155
+ constructor(_sidebarService, _threadCommentPanelService) {
156
+ super();
157
+ this._sidebarService = _sidebarService;
158
+ this._threadCommentPanelService = _threadCommentPanelService;
159
+ _defineProperty(this, "_addingComment$", new rxjs.BehaviorSubject(void 0));
160
+ _defineProperty(this, "addingComment$", this._addingComment$.asObservable());
161
+ this.disposeWithMe(() => {
162
+ this._addingComment$.complete();
163
+ });
164
+ }
165
+ startAdd(comment) {
166
+ this._addingComment$.next(comment);
167
+ }
168
+ endAdd() {
169
+ this._addingComment$.next(void 0);
170
+ }
171
+ };
172
+ DocThreadCommentService = __decorate([__decorateParam(0, _univerjs_ui.ISidebarService), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_thread_comment_ui.ThreadCommentPanelService))], DocThreadCommentService);
173
+
174
+ //#endregion
175
+ //#region src/commands/operations/show-comment-panel.operation.ts
176
+ const ShowCommentPanelOperation = {
177
+ id: "docs.operation.show-comment-panel",
178
+ type: _univerjs_core.CommandType.OPERATION,
179
+ handler(accessor, params) {
180
+ var _sidebarService$optio;
181
+ const panelService = accessor.get(_univerjs_thread_comment_ui.ThreadCommentPanelService);
182
+ const sidebarService = accessor.get(_univerjs_ui.ISidebarService);
183
+ if (!panelService.panelVisible || ((_sidebarService$optio = sidebarService.options.children) === null || _sidebarService$optio === void 0 ? void 0 : _sidebarService$optio.label) !== "univer.doc.thread-comment-panel") {
184
+ sidebarService.open({
185
+ header: { title: "threadCommentUI.panel.title" },
186
+ children: { label: DOCS_THREAD_COMMENT_PANEL },
187
+ width: 320,
188
+ onClose: () => panelService.setPanelVisible(false)
189
+ });
190
+ panelService.setPanelVisible(true);
191
+ }
192
+ if (params) panelService.setActiveComment(params === null || params === void 0 ? void 0 : params.activeComment);
193
+ return true;
194
+ }
195
+ };
196
+ const ToggleCommentPanelOperation = {
197
+ id: "docs.operation.toggle-comment-panel",
198
+ type: _univerjs_core.CommandType.OPERATION,
199
+ handler(accessor) {
200
+ var _sidebarService$optio2;
201
+ const panelService = accessor.get(_univerjs_thread_comment_ui.ThreadCommentPanelService);
202
+ const sidebarService = accessor.get(_univerjs_ui.ISidebarService);
203
+ if (!panelService.panelVisible || ((_sidebarService$optio2 = sidebarService.options.children) === null || _sidebarService$optio2 === void 0 ? void 0 : _sidebarService$optio2.label) !== "univer.doc.thread-comment-panel") {
204
+ sidebarService.open({
205
+ header: { title: "threadCommentUI.panel.title" },
206
+ children: { label: DOCS_THREAD_COMMENT_PANEL },
207
+ width: 320,
208
+ onClose: () => panelService.setPanelVisible(false)
209
+ });
210
+ panelService.setPanelVisible(true);
211
+ } else {
212
+ sidebarService.close();
213
+ panelService.setPanelVisible(false);
214
+ panelService.setActiveComment(null);
215
+ }
216
+ return true;
217
+ }
218
+ };
219
+ const StartAddCommentOperation = {
220
+ id: "docs.operation.start-add-comment",
221
+ type: _univerjs_core.CommandType.OPERATION,
222
+ handler(accessor) {
223
+ var _renderManagerService, _doc$getBody$dataStre, _doc$getBody;
224
+ const panelService = accessor.get(_univerjs_thread_comment_ui.ThreadCommentPanelService);
225
+ const doc = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
226
+ const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
227
+ const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
228
+ const userManagerService = accessor.get(_univerjs_core.UserManagerService);
229
+ const docCommentService = accessor.get(DocThreadCommentService);
230
+ const commandService = accessor.get(_univerjs_core.ICommandService);
231
+ const sidebarService = accessor.get(_univerjs_ui.ISidebarService);
232
+ const textRange = docSelectionManagerService.getActiveTextRange();
233
+ if (!doc || !textRange) return false;
234
+ const docSelectionRenderManager = (_renderManagerService = renderManagerService.getRenderById(doc.getUnitId())) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(_univerjs_docs_ui.DocSelectionRenderService);
235
+ docSelectionRenderManager === null || docSelectionRenderManager === void 0 || docSelectionRenderManager.setReserveRangesStatus(true);
236
+ if (textRange.collapsed) {
237
+ if (panelService.panelVisible) {
238
+ panelService.setPanelVisible(false);
239
+ sidebarService.close();
240
+ } else commandService.executeCommand(ShowCommentPanelOperation.id);
241
+ return true;
242
+ }
243
+ commandService.executeCommand(ShowCommentPanelOperation.id);
244
+ const unitId = doc.getUnitId();
245
+ const dataStream = ((_doc$getBody$dataStre = (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.dataStream) !== null && _doc$getBody$dataStre !== void 0 ? _doc$getBody$dataStre : "").slice(textRange.startOffset, textRange.endOffset);
246
+ const text = _univerjs_core.BuildTextUtils.transform.getPlainText(dataStream);
247
+ const subUnitId = DEFAULT_DOC_SUBUNIT_ID;
248
+ const commentId = "";
249
+ const comment = {
250
+ unitId,
251
+ subUnitId,
252
+ id: commentId,
253
+ ref: text,
254
+ dT: (0, _univerjs_thread_comment.getDT)(),
255
+ personId: userManagerService.getCurrentUser().userID,
256
+ text: { dataStream: "\r\n" },
257
+ startOffset: textRange.startOffset,
258
+ endOffset: textRange.endOffset,
259
+ collapsed: true,
260
+ threadId: commentId
261
+ };
262
+ docSelectionRenderManager === null || docSelectionRenderManager === void 0 || docSelectionRenderManager.blur();
263
+ docCommentService.startAdd(comment);
264
+ panelService.setActiveComment({
265
+ unitId,
266
+ subUnitId,
267
+ commentId
268
+ });
269
+ return true;
270
+ }
271
+ };
272
+
273
+ //#endregion
274
+ //#region package.json
275
+ var name = "@univerjs/docs-thread-comment-ui";
276
+ var version = "0.21.0-insiders.20260422-d7fcb4d";
277
+
278
+ //#endregion
279
+ //#region src/config/config.ts
280
+ const DOCS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY = "docs-thread-comment-ui.config";
281
+ const configSymbol = Symbol(DOCS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY);
282
+ const defaultPluginConfig = {};
283
+
284
+ //#endregion
285
+ //#region src/controllers/doc-thread-comment-selection.controller.ts
286
+ let DocThreadCommentSelectionController = class DocThreadCommentSelectionController extends _univerjs_core.Disposable {
287
+ constructor(_threadCommentPanelService, _univerInstanceService, _commandService, _docThreadCommentService, _renderManagerService, _threadCommentModel) {
288
+ super();
289
+ this._threadCommentPanelService = _threadCommentPanelService;
290
+ this._univerInstanceService = _univerInstanceService;
291
+ this._commandService = _commandService;
292
+ this._docThreadCommentService = _docThreadCommentService;
293
+ this._renderManagerService = _renderManagerService;
294
+ this._threadCommentModel = _threadCommentModel;
295
+ this._initSelectionChange();
296
+ this._initActiveCommandChange();
297
+ }
298
+ _initSelectionChange() {
299
+ let lastSelection;
300
+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
301
+ if (commandInfo.id === _univerjs_docs.SetTextSelectionsOperation.id) {
302
+ const { unitId, ranges } = commandInfo.params;
303
+ if ((0, _univerjs_core.isInternalEditorID)(unitId)) return;
304
+ const doc = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
305
+ const primary = ranges[0];
306
+ if ((lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.startOffset) === (primary === null || primary === void 0 ? void 0 : primary.startOffset) && (lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.endOffset) === (primary === null || primary === void 0 ? void 0 : primary.endOffset)) return;
307
+ lastSelection = primary;
308
+ if (primary && doc) {
309
+ const { startOffset, endOffset, collapsed } = primary;
310
+ let customRange;
311
+ if (collapsed) {
312
+ var _doc$getBody;
313
+ customRange = (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 || (_doc$getBody = _doc$getBody.customDecorations) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1);
314
+ } else {
315
+ var _doc$getBody2;
316
+ customRange = (_doc$getBody2 = doc.getBody()) === null || _doc$getBody2 === void 0 || (_doc$getBody2 = _doc$getBody2.customDecorations) === null || _doc$getBody2 === void 0 ? void 0 : _doc$getBody2.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1);
317
+ }
318
+ if (customRange) {
319
+ const comment = this._threadCommentModel.getComment(unitId, DEFAULT_DOC_SUBUNIT_ID, customRange.id);
320
+ if (comment && !comment.resolved) this._commandService.executeCommand(ShowCommentPanelOperation.id, { activeComment: {
321
+ unitId,
322
+ subUnitId: DEFAULT_DOC_SUBUNIT_ID,
323
+ commentId: customRange.id
324
+ } });
325
+ return;
326
+ }
327
+ }
328
+ if (!this._threadCommentPanelService.activeCommentId) return;
329
+ this._commandService.executeCommand(_univerjs_thread_comment_ui.SetActiveCommentOperation.id);
330
+ }
331
+ }));
332
+ }
333
+ _initActiveCommandChange() {
334
+ this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe((activeComment) => {
335
+ var _this$_docThreadComme;
336
+ if (activeComment) {
337
+ const doc = this._univerInstanceService.getUnit(activeComment.unitId);
338
+ if (doc) {
339
+ var _this$_renderManagerS, _doc$getBody3;
340
+ const backScrollController = (_this$_renderManagerS = this._renderManagerService.getRenderById(activeComment.unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(_univerjs_docs_ui.DocBackScrollRenderController);
341
+ const customRange = (_doc$getBody3 = doc.getBody()) === null || _doc$getBody3 === void 0 || (_doc$getBody3 = _doc$getBody3.customDecorations) === null || _doc$getBody3 === void 0 ? void 0 : _doc$getBody3.find((range) => range.id === activeComment.commentId);
342
+ if (customRange && backScrollController) backScrollController.scrollToRange({
343
+ startOffset: customRange.startIndex,
344
+ endOffset: customRange.endIndex,
345
+ collapsed: false
346
+ });
347
+ }
348
+ }
349
+ if (!activeComment || activeComment.commentId !== ((_this$_docThreadComme = this._docThreadCommentService.addingComment) === null || _this$_docThreadComme === void 0 ? void 0 : _this$_docThreadComme.id)) this._docThreadCommentService.endAdd();
350
+ }));
351
+ }
352
+ };
353
+ DocThreadCommentSelectionController = __decorate([
354
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_thread_comment_ui.ThreadCommentPanelService)),
355
+ __decorateParam(1, _univerjs_core.IUniverInstanceService),
356
+ __decorateParam(2, _univerjs_core.ICommandService),
357
+ __decorateParam(3, (0, _univerjs_core.Inject)(DocThreadCommentService)),
358
+ __decorateParam(4, _univerjs_engine_render.IRenderManagerService),
359
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_thread_comment.ThreadCommentModel))
360
+ ], DocThreadCommentSelectionController);
361
+
362
+ //#endregion
363
+ //#region src/menu/menu.ts
364
+ const shouldDisableAddComment = (accessor) => {
365
+ var _withCurrentTypeOfRen;
366
+ const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
367
+ const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
368
+ const skeleton = (_withCurrentTypeOfRen = (0, _univerjs_engine_render.withCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_DOC, _univerjs_docs.DocSkeletonManagerService, accessor.get(_univerjs_core.IUniverInstanceService), renderManagerService)) === null || _withCurrentTypeOfRen === void 0 ? void 0 : _withCurrentTypeOfRen.getSkeleton();
369
+ const editArea = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getViewModel().getEditArea();
370
+ if (editArea === _univerjs_engine_render.DocumentEditArea.FOOTER || editArea === _univerjs_engine_render.DocumentEditArea.HEADER) return true;
371
+ const range = docSelectionManagerService.getActiveTextRange();
372
+ if (range == null || range.collapsed) return true;
373
+ return false;
374
+ };
375
+ function AddDocCommentMenuItemFactory(accessor) {
376
+ return {
377
+ id: StartAddCommentOperation.id,
378
+ type: _univerjs_ui.MenuItemType.BUTTON,
379
+ icon: "CommentIcon",
380
+ title: "threadCommentUI.panel.addComment",
381
+ tooltip: "threadCommentUI.panel.addComment",
382
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC, void 0, _univerjs_core.SHEET_EDITOR_UNITS),
383
+ disabled$: new rxjs.Observable(function(subscribe) {
384
+ const observer = accessor.get(_univerjs_docs.DocSelectionManagerService).textSelection$.pipe((0, rxjs.debounceTime)(16)).subscribe(() => {
385
+ subscribe.next(shouldDisableAddComment(accessor));
386
+ });
387
+ return () => {
388
+ observer.unsubscribe();
389
+ };
390
+ })
391
+ };
392
+ }
393
+ function ToolbarDocCommentMenuItemFactory(accessor) {
394
+ return {
395
+ id: ToggleCommentPanelOperation.id,
396
+ type: _univerjs_ui.MenuItemType.BUTTON,
397
+ icon: "CommentIcon",
398
+ title: "threadCommentUI.panel.addComment",
399
+ tooltip: "threadCommentUI.panel.addComment",
400
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_DOC)
401
+ };
402
+ }
403
+
404
+ //#endregion
405
+ //#region src/menu/schema.ts
406
+ const menuSchema = {
407
+ [_univerjs_ui.RibbonInsertGroup.MEDIA]: { [ToggleCommentPanelOperation.id]: {
408
+ order: 3,
409
+ menuItemFactory: ToolbarDocCommentMenuItemFactory
410
+ } },
411
+ [_univerjs_ui.ContextMenuPosition.MAIN_AREA]: { [_univerjs_ui.ContextMenuGroup.DATA]: { [StartAddCommentOperation.id]: {
412
+ order: 1,
413
+ menuItemFactory: AddDocCommentMenuItemFactory
414
+ } } }
415
+ };
416
+
417
+ //#endregion
418
+ //#region src/views/doc-thread-comment-panel/index.tsx
419
+ const DocThreadCommentPanel = () => {
420
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
421
+ const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
422
+ const doc = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC).pipe((0, rxjs.filter)((doc) => !!doc && !(0, _univerjs_core.isInternalEditorID)(doc.getUnitId()))), [univerInstanceService]));
423
+ const subUnitId$ = (0, react.useMemo)(() => new rxjs.Observable((sub) => sub.next(DEFAULT_DOC_SUBUNIT_ID)), []);
424
+ const docSelectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocSelectionManagerService);
425
+ (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => docSelectionManagerService.textSelection$.pipe((0, rxjs.debounceTime)(16)), [docSelectionManagerService.textSelection$]));
426
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
427
+ const docCommentService = (0, _univerjs_ui.useDependency)(DocThreadCommentService);
428
+ const tempComment = (0, _univerjs_ui.useObservable)(docCommentService.addingComment$);
429
+ const [commentIds, setCommentIds] = (0, react.useState)([]);
430
+ (0, react.useEffect)(() => {
431
+ var _customRanges$map$fil;
432
+ const set = /* @__PURE__ */ new Set();
433
+ const customRanges = doc === null || doc === void 0 ? void 0 : doc.getCustomDecorations();
434
+ setCommentIds((_customRanges$map$fil = customRanges === null || customRanges === void 0 ? void 0 : customRanges.map((r) => r.id).filter((i) => {
435
+ const hasRepeat = set.has(i);
436
+ set.add(i);
437
+ return !hasRepeat;
438
+ })) !== null && _customRanges$map$fil !== void 0 ? _customRanges$map$fil : []);
439
+ const dispose = commandService.onCommandExecuted((command) => {
440
+ if (command.id === _univerjs_docs.RichTextEditingMutation.id) {
441
+ var _customRanges$map$fil2;
442
+ const set = /* @__PURE__ */ new Set();
443
+ const customRanges = doc === null || doc === void 0 ? void 0 : doc.getCustomDecorations();
444
+ setCommentIds((_customRanges$map$fil2 = customRanges === null || customRanges === void 0 ? void 0 : customRanges.map((r) => r.id).filter((i) => {
445
+ const hasRepeat = set.has(i);
446
+ set.add(i);
447
+ return !hasRepeat;
448
+ })) !== null && _customRanges$map$fil2 !== void 0 ? _customRanges$map$fil2 : []);
449
+ }
450
+ });
451
+ return () => {
452
+ dispose.dispose();
453
+ };
454
+ }, [commandService, doc]);
455
+ if (!doc) return null;
456
+ const isInValidSelection = shouldDisableAddComment(injector);
457
+ const unitId = doc.getUnitId();
458
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_thread_comment_ui.ThreadCommentPanel, {
459
+ unitId,
460
+ subUnitId$,
461
+ type: _univerjs_core.UniverInstanceType.UNIVER_DOC,
462
+ onAdd: () => {
463
+ commandService.executeCommand(StartAddCommentOperation.id);
464
+ },
465
+ getSubUnitName: () => "",
466
+ disableAdd: isInValidSelection,
467
+ tempComment,
468
+ onAddComment: (comment) => {
469
+ if (!comment.parentId) {
470
+ const params = {
471
+ unitId,
472
+ range: tempComment,
473
+ comment
474
+ };
475
+ commandService.executeCommand(AddDocCommentComment.id, params);
476
+ docCommentService.endAdd();
477
+ return false;
478
+ }
479
+ return true;
480
+ },
481
+ onDeleteComment: (comment) => {
482
+ if (!comment.parentId) {
483
+ const params = {
484
+ unitId,
485
+ commentId: comment.id
486
+ };
487
+ commandService.executeCommand(DeleteDocCommentComment.id, params);
488
+ return false;
489
+ }
490
+ return true;
491
+ },
492
+ showComments: commentIds
493
+ });
494
+ };
495
+
496
+ //#endregion
497
+ //#region src/controllers/doc-thread-comment-ui.controller.ts
498
+ /**
499
+ * Copyright 2023-present DreamNum Co., Ltd.
500
+ *
501
+ * Licensed under the Apache License, Version 2.0 (the "License");
502
+ * you may not use this file except in compliance with the License.
503
+ * You may obtain a copy of the License at
504
+ *
505
+ * http://www.apache.org/licenses/LICENSE-2.0
506
+ *
507
+ * Unless required by applicable law or agreed to in writing, software
508
+ * distributed under the License is distributed on an "AS IS" BASIS,
509
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
510
+ * See the License for the specific language governing permissions and
511
+ * limitations under the License.
512
+ */
513
+ let DocThreadCommentUIController = class DocThreadCommentUIController extends _univerjs_core.Disposable {
514
+ constructor(_commandService, _menuManagerService, _componentManager) {
515
+ super();
516
+ this._commandService = _commandService;
517
+ this._menuManagerService = _menuManagerService;
518
+ this._componentManager = _componentManager;
519
+ this._initCommands();
520
+ this._initMenus();
521
+ this._initComponents();
522
+ }
523
+ _initCommands() {
524
+ [
525
+ AddDocCommentComment,
526
+ DeleteDocCommentComment,
527
+ ShowCommentPanelOperation,
528
+ StartAddCommentOperation,
529
+ ToggleCommentPanelOperation
530
+ ].forEach((command) => {
531
+ this.disposeWithMe(this._commandService.registerCommand(command));
532
+ });
533
+ }
534
+ _initMenus() {
535
+ this._menuManagerService.mergeMenu(menuSchema);
536
+ }
537
+ _initComponents() {
538
+ [[DOCS_THREAD_COMMENT_PANEL, DocThreadCommentPanel], ["CommentIcon", _univerjs_icons.CommentIcon]].forEach(([id, comp]) => {
539
+ this.disposeWithMe(this._componentManager.register(id, comp));
540
+ });
541
+ }
542
+ };
543
+ DocThreadCommentUIController = __decorate([
544
+ __decorateParam(0, _univerjs_core.ICommandService),
545
+ __decorateParam(1, _univerjs_ui.IMenuManagerService),
546
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager))
547
+ ], DocThreadCommentUIController);
548
+
549
+ //#endregion
550
+ //#region src/controllers/render-controllers/render.controller.ts
551
+ let DocThreadCommentRenderController = class DocThreadCommentRenderController extends _univerjs_core.Disposable {
552
+ constructor(_context, _docInterceptorService, _threadCommentPanelService, _docRenderController, _univerInstanceService, _threadCommentModel, _commandService) {
553
+ super();
554
+ this._context = _context;
555
+ this._docInterceptorService = _docInterceptorService;
556
+ this._threadCommentPanelService = _threadCommentPanelService;
557
+ this._docRenderController = _docRenderController;
558
+ this._univerInstanceService = _univerInstanceService;
559
+ this._threadCommentModel = _threadCommentModel;
560
+ this._commandService = _commandService;
561
+ this._interceptorViewModel();
562
+ this._initReRender();
563
+ this._initSyncComments();
564
+ }
565
+ _initReRender() {
566
+ this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe((activeComment) => {
567
+ var _this$_univerInstance;
568
+ if (activeComment) {
569
+ this._docRenderController.reRender(activeComment.unitId);
570
+ return;
571
+ }
572
+ const unitId = (_this$_univerInstance = this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_DOC)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getUnitId();
573
+ if (unitId) this._docRenderController.reRender(unitId);
574
+ }));
575
+ this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe((update) => {
576
+ if (update.type === "resolve") this._docRenderController.reRender(update.unitId);
577
+ }));
578
+ }
579
+ _interceptorViewModel() {
580
+ this._docInterceptorService.intercept(_univerjs_docs.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION, { handler: (data, pos, next) => {
581
+ if (!data) return next(data);
582
+ const { unitId, index, customDecorations } = pos;
583
+ const { commentId, unitId: commentUnitID } = this._threadCommentPanelService.activeCommentId || {};
584
+ const activeCustomDecoration = customDecorations.find((i) => i.id === commentId);
585
+ const comment = this._threadCommentModel.getComment(unitId, DEFAULT_DOC_SUBUNIT_ID, data.id);
586
+ if (!comment) return next({
587
+ ...data,
588
+ show: false
589
+ });
590
+ const isActiveIndex = activeCustomDecoration && index >= activeCustomDecoration.startIndex && index <= activeCustomDecoration.endIndex;
591
+ const isActive = commentUnitID === unitId && data.id === commentId;
592
+ return next({
593
+ ...data,
594
+ active: isActive || isActiveIndex,
595
+ show: !comment.resolved
596
+ });
597
+ } });
598
+ }
599
+ _initSyncComments() {
600
+ var _this$_context$unit$g, _this$_context$unit$g2;
601
+ const unitId = this._context.unit.getUnitId();
602
+ const subUnitId = DEFAULT_DOC_SUBUNIT_ID;
603
+ const threadIds = (_this$_context$unit$g = (_this$_context$unit$g2 = this._context.unit.getBody()) === null || _this$_context$unit$g2 === void 0 || (_this$_context$unit$g2 = _this$_context$unit$g2.customDecorations) === null || _this$_context$unit$g2 === void 0 ? void 0 : _this$_context$unit$g2.filter((i) => i.type === _univerjs_core.CustomDecorationType.COMMENT).map((i) => i.id)) !== null && _this$_context$unit$g !== void 0 ? _this$_context$unit$g : [];
604
+ threadIds.forEach((id) => {
605
+ if (!this._threadCommentModel.getComment(unitId, subUnitId, id)) this._threadCommentModel.addComment(unitId, subUnitId, {
606
+ id,
607
+ threadId: id,
608
+ ref: "",
609
+ dT: "",
610
+ personId: "",
611
+ text: { dataStream: "" },
612
+ unitId,
613
+ subUnitId
614
+ });
615
+ });
616
+ threadIds.length && this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(), "default_doc", threadIds);
617
+ let prevThreadIds = threadIds.sort();
618
+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
619
+ if (commandInfo.id === _univerjs_docs.RichTextEditingMutation.id) {
620
+ var _this$_context$unit$g3, _this$_context$unit$g4;
621
+ if (commandInfo.params.unitId !== this._context.unit.getUnitId()) return;
622
+ const currentThreadIds = (_this$_context$unit$g3 = (_this$_context$unit$g4 = this._context.unit.getBody()) === null || _this$_context$unit$g4 === void 0 || (_this$_context$unit$g4 = _this$_context$unit$g4.customDecorations) === null || _this$_context$unit$g4 === void 0 ? void 0 : _this$_context$unit$g4.filter((i) => i.type === _univerjs_core.CustomDecorationType.COMMENT).map((i) => i.id)) !== null && _this$_context$unit$g3 !== void 0 ? _this$_context$unit$g3 : [];
623
+ const currentThreadIdsSorted = currentThreadIds.sort();
624
+ if (JSON.stringify(prevThreadIds) !== JSON.stringify(currentThreadIdsSorted)) {
625
+ const preIds = new Set(prevThreadIds);
626
+ const currentIds = new Set(currentThreadIdsSorted);
627
+ const addIds = /* @__PURE__ */ new Set();
628
+ const deleteIds = /* @__PURE__ */ new Set();
629
+ currentThreadIds.forEach((id) => {
630
+ if (!preIds.has(id)) addIds.add(id);
631
+ });
632
+ prevThreadIds.forEach((id) => {
633
+ if (!currentIds.has(id)) deleteIds.add(id);
634
+ });
635
+ prevThreadIds = currentThreadIdsSorted;
636
+ addIds.forEach((id) => {
637
+ if (!this._threadCommentModel.getComment(unitId, subUnitId, id)) this._threadCommentModel.addComment(unitId, subUnitId, {
638
+ id,
639
+ threadId: id,
640
+ ref: "",
641
+ dT: "",
642
+ personId: "",
643
+ text: { dataStream: "" },
644
+ unitId,
645
+ subUnitId
646
+ });
647
+ });
648
+ this._threadCommentModel.syncThreadComments(unitId, subUnitId, [...addIds]);
649
+ }
650
+ }
651
+ }));
652
+ }
653
+ };
654
+ DocThreadCommentRenderController = __decorate([
655
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs.DocInterceptorService)),
656
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_thread_comment_ui.ThreadCommentPanelService)),
657
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocRenderController)),
658
+ __decorateParam(4, _univerjs_core.IUniverInstanceService),
659
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_thread_comment.ThreadCommentModel)),
660
+ __decorateParam(6, _univerjs_core.ICommandService)
661
+ ], DocThreadCommentRenderController);
662
+
663
+ //#endregion
664
+ //#region src/plugin.ts
665
+ let UniverDocsThreadCommentUIPlugin = class UniverDocsThreadCommentUIPlugin extends _univerjs_core.Plugin {
666
+ constructor(_config = defaultPluginConfig, _injector, _renderManagerSrv, _configService) {
667
+ super();
668
+ this._config = _config;
669
+ this._injector = _injector;
670
+ this._renderManagerSrv = _renderManagerSrv;
671
+ this._configService = _configService;
672
+ const { menu, ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
673
+ if (menu) this._configService.setConfig("menu", menu, { merge: true });
674
+ this._configService.setConfig(DOCS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY, rest);
675
+ }
676
+ onStarting() {
677
+ [
678
+ [DocThreadCommentUIController],
679
+ [DocThreadCommentSelectionController],
680
+ [DocThreadCommentService]
681
+ ].forEach((dep) => {
682
+ this._injector.add(dep);
683
+ });
684
+ }
685
+ onRendered() {
686
+ this._initRenderModule();
687
+ this._injector.get(DocThreadCommentSelectionController);
688
+ this._injector.get(DocThreadCommentUIController);
689
+ }
690
+ _initRenderModule() {
691
+ [DocThreadCommentRenderController].forEach((dep) => {
692
+ this._renderManagerSrv.registerRenderModule(_univerjs_core.UniverInstanceType.UNIVER_DOC, dep);
693
+ });
694
+ }
695
+ };
696
+ _defineProperty(UniverDocsThreadCommentUIPlugin, "pluginName", PLUGIN_NAME);
697
+ _defineProperty(UniverDocsThreadCommentUIPlugin, "packageName", name);
698
+ _defineProperty(UniverDocsThreadCommentUIPlugin, "version", version);
699
+ _defineProperty(UniverDocsThreadCommentUIPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_DOC);
700
+ UniverDocsThreadCommentUIPlugin = __decorate([
701
+ (0, _univerjs_core.DependentOn)(_univerjs_thread_comment_ui.UniverThreadCommentUIPlugin),
702
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
703
+ __decorateParam(2, _univerjs_engine_render.IRenderManagerService),
704
+ __decorateParam(3, _univerjs_core.IConfigService)
705
+ ], UniverDocsThreadCommentUIPlugin);
706
+
707
+ //#endregion
708
+ exports.AddDocCommentComment = AddDocCommentComment;
709
+ exports.DeleteDocCommentComment = DeleteDocCommentComment;
710
+ exports.ShowCommentPanelOperation = ShowCommentPanelOperation;
711
+ exports.StartAddCommentOperation = StartAddCommentOperation;
712
+ Object.defineProperty(exports, 'UniverDocsThreadCommentUIPlugin', {
713
+ enumerable: true,
714
+ get: function () {
715
+ return UniverDocsThreadCommentUIPlugin;
716
+ }
717
+ });