@univerjs/docs-thread-comment-ui 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/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # @univerjs/sheets-thread-comment
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@univerjs/sheets-thread-comment)](https://npmjs.org/packages/@univerjs/sheets-thread-comment )
4
+ [![license](https://img.shields.io/npm/l/@univerjs/sheets-thread-comment)](https://img.shields.io/npm/l/@univerjs/sheets- thread-comment)
5
+
6
+ ## Introduction
7
+
8
+ `@univerjs/sheets-thread-comment` provides the comment/annotation function of Univer Sheets.
9
+
10
+
11
+ ## Usage
12
+
13
+ ### Install
14
+
15
+ ```shell
16
+ # Use npm
17
+ npm install @univerjs/sheets-thread-comment
18
+
19
+ # Use pnpm
20
+ pnpm add @univerjs/sheets-thread-comment
21
+ ```
22
+
23
+ ### use
24
+ ```js
25
+ import { UniverDocsThreadCommentUIPlugin } from '@univerjs/docs-thread-comment-ui';
26
+
27
+ univer.registerPlugin(UniverDocsThreadCommentUIPlugin);
28
+ ```
@@ -0,0 +1,2 @@
1
+ "use strict";var re=Object.defineProperty;var ie=(e,t,n)=>t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var q=(e,t,n)=>ie(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),f=require("@wendellhu/redi"),S=require("@univerjs/thread-comment-ui"),R=require("@univerjs/engine-render"),_=require("@univerjs/ui"),h=require("@univerjs/docs"),F=require("@univerjs/thread-comment"),b=require("@wendellhu/redi/react-bindings"),p=require("react"),N=require("rxjs"),Y=require("@univerjs/docs-ui"),oe="DOC_THREAD_COMMENT_UI_PLUGIN",D="default_doc";var v=function(){return v=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},v.apply(this,arguments)},ce=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n},J=p.forwardRef(function(e,t){var n=e.icon,r=e.id,i=e.className,o=e.extend,c=ce(e,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(r," ").concat(i||"").trim(),l=p.useRef("_".concat(de()));return Q(n,"".concat(r),{defIds:n.defIds,idSuffix:l.current},v({ref:t,className:a},c),o)});function Q(e,t,n,r,i){return p.createElement(e.tag,v(v({key:t},se(e,n,i)),r),(ae(e,n).children||[]).map(function(o,c){return Q(o,"".concat(t,"-").concat(e.tag,"-").concat(c),n,void 0,i)}))}function se(e,t,n){var r=v({},e.attrs);n!=null&&n.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=n.colorChannel1);var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+t.idSuffix),Object.entries(r).forEach(function(o){var c=o[0],a=o[1];typeof a=="string"&&(r[c]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),r}function ae(e,t){var n,r=t.defIds;return!r||r.length===0?e:e.tag==="defs"&&(!((n=e.children)===null||n===void 0)&&n.length)?v(v({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&r&&r.indexOf(i.attrs.id)>-1?v(v({},i),{attrs:v(v({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function de(){return Math.random().toString(36).substring(2,8)}J.displayName="UniverIcon";var me={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345ZM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345ZM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521 5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345zM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521 8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345zM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521 11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.84351 3.41861C1.84351 3.01861 2.15531 2.69434 2.53993 2.69434H14.9381C15.3228 2.69434 15.6346 3.01861 15.6346 3.41861V12.4611C15.6346 12.8612 15.3228 13.1854 14.9381 13.1854H8.82117L6.06643 14.6179C5.85054 14.7301 5.59416 14.7181 5.38884 14.5862C5.18352 14.4542 5.05855 14.2211 5.05855 13.9701V13.1854H2.53993C2.15531 13.1854 1.84351 12.8612 1.84351 12.4611L1.84351 3.41861ZM6.45141 12.7982L8.34531 12.0135C8.44201 11.9632 8.54864 11.9371 8.65676 11.9371H14.2417C14.3522 11.9371 14.4417 11.8475 14.4417 11.7371V4.14271C14.4417 4.03225 14.3522 3.94271 14.2417 3.94271H3.23636C3.12591 3.94271 3.03636 4.03225 3.03636 4.14271L3.03636 11.7371C3.03636 11.8475 3.12591 11.9371 3.23636 11.9371L5.75498 11.9371C6.1396 11.9371 6.45141 12.0611 6.45141 12.4611V12.7982Z",fillRule:"evenodd",clipRule:"evenodd"}}]},k=p.forwardRef(function(e,t){return p.createElement(J,Object.assign({},e,{id:"comment-single",ref:t,icon:me}))});k.displayName="CommentSingle";const H={id:"docs.command.add-comment",type:s.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{comment:n,unitId:r}=t,o=await e.get(F.IThreadCommentDataSourceService).addComment(n),c=e.get(s.ICommandService),a=h.addCustomDecorationBySelectionFactory(e,{id:o.id,type:s.CustomDecorationType.COMMENT});if(a){const l={id:F.AddCommentMutation.id,params:{unitId:r,subUnitId:D,comment:o}},m={id:S.SetActiveCommentOperation.id,params:{unitId:r,subUnitId:D,commentId:o.id}};return(await s.sequenceExecuteAsync([l,a,m],c)).result}return!1}};var le=Object.defineProperty,ue=Object.getOwnPropertyDescriptor,ve=(e,t,n,r)=>{for(var i=r>1?void 0:r?ue(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=(r?c(t,n,i):c(i))||i);return r&&i&&le(t,n,i),i},K=(e,t)=>(n,r)=>t(n,r,e);let T=class{constructor(e,t){q(this,"_addingComment$",new N.BehaviorSubject(void 0));q(this,"addingComment$",this._addingComment$.asObservable());this._sidebarService=e,this._threadCommentPanelService=t}get addingComment(){return this._addingComment$.getValue()}startAdd(e){this._addingComment$.next(e)}endAdd(){this._addingComment$.next(void 0)}};T=ve([K(0,_.ISidebarService),K(1,f.Inject(S.ThreadCommentPanelService))],T);const x={id:"docs.operation.show-comment-panel",type:s.CommandType.OPERATION,handler(e,t){const n=e.get(S.ThreadCommentPanelService),r=e.get(_.ISidebarService);return n.panelVisible||(r.open({header:{title:"threadCommentUI.panel.title"},children:{label:Z.componentKey},width:320,onClose:()=>n.setPanelVisible(!1)}),n.setPanelVisible(!0)),t&&n.setActiveComment(t==null?void 0:t.activeComment),!0}},L={id:"docs.operation.start-add-comment",type:s.CommandType.OPERATION,handler(e){var g,A;const t=e.get(S.ThreadCommentPanelService),r=e.get(s.IUniverInstanceService).getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC),i=e.get(h.TextSelectionManagerService),o=e.get(s.UserManagerService),c=e.get(T),a=e.get(s.ICommandService),l=e.get(_.ISidebarService),m=i.getActiveRange();if(!r||!m)return!1;if(m.collapsed)return t.panelVisible?(t.setPanelVisible(!1),l.close()):a.executeCommand(x.id),!0;t.panelVisible||a.executeCommand(x.id);const C=r.getUnitId(),O=h.getSelectionText((A=(g=r.getBody())==null?void 0:g.dataStream)!=null?A:"",m.startOffset,m.endOffset),I=D,u="",d={unitId:C,subUnitId:I,id:u,ref:O,dT:S.getDT(),personId:o.getCurrentUser().userID,text:{dataStream:`\r
2
+ `},startOffset:m.startOffset,endOffset:m.endOffset,collapsed:!0,threadId:u};return c.startAdd(d),t.setActiveComment({unitId:C,subUnitId:I,commentId:u}),!0}},W={id:"docs.command.delete-comment",type:s.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{commentId:n,unitId:r}=t,i=e.get(s.ICommandService),o=h.deleteCustomDecorationFactory(e,{id:n,unitId:r});return o?(await s.sequenceExecute([o],i)).result:!1}},Z=()=>{var u;const e=b.useDependency(s.IUniverInstanceService),t=p.useMemo(()=>e.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_DOC),[e]),n=b.useObservable(t),r=p.useMemo(()=>new N.Observable(d=>d.next(D)),[]),i=b.useDependency(h.TextSelectionManagerService),o=(u=b.useObservable(i.textSelection$))==null?void 0:u.textRanges[0],c=b.useDependency(s.ICommandService),a=b.useDependency(T),l=b.useObservable(a.addingComment$),[m,C]=p.useState([]);if(p.useEffect(()=>{var z;const d=new Set,g=n==null?void 0:n.getCustomDecorations();C((z=g==null?void 0:g.map(M=>M.id).filter(M=>{const E=d.has(M);return d.add(M),!E}))!=null?z:[]);const A=c.onCommandExecuted(M=>{var E;if(M.id===h.RichTextEditingMutation.id){const G=new Set,B=n==null?void 0:n.getCustomDecorations();C((E=B==null?void 0:B.map(w=>w.id).filter(w=>{const ne=G.has(w);return G.add(w),!ne}))!=null?E:[])}});return()=>{A.dispose()}},[c,n]),!n)return null;const O=o&&o.endOffset===o.startOffset,I=n.getUnitId();return p.createElement(S.ThreadCommentPanel,{unitId:I,subUnitId$:r,type:s.UniverInstanceType.UNIVER_DOC,onAdd:()=>{c.executeCommand(L.id)},getSubUnitName:()=>"",disableAdd:O,tempComment:l,onAddComment:d=>{if(!d.parentId){const g={unitId:I,range:l,comment:d};return c.executeCommand(H.id,g),a.endAdd(),!1}return!0},onDeleteComment:d=>{if(!d.parentId){const g={unitId:I,commentId:d.id};return c.executeCommand(W.id,g),!1}return!0},showComments:m})};Z.componentKey="univer.doc.thread-comment-panel";const fe=e=>{const n=e.get(R.IRenderManagerService).getCurrent(),r=n==null?void 0:n.with(h.DocSkeletonManagerService).getSkeleton(),i=r==null?void 0:r.getViewModel().getEditArea();return i===R.DocumentEditArea.FOOTER||i===R.DocumentEditArea.HEADER};function Ce(e){return{id:L.id,group:_.MenuGroup.TOOLBAR_LAYOUT,type:_.MenuItemType.BUTTON,icon:"CommentSingle",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",positions:[_.MenuPosition.TOOLBAR_START,_.MenuPosition.CONTEXT_MENU],hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_DOC),disabled$:new N.Observable(function(t){const r=e.get(h.TextSelectionManagerService).textSelection$.pipe(N.debounceTime(16)).subscribe(()=>{t.next(fe(e))});return()=>{r.unsubscribe()}})}}var he=Object.defineProperty,Ie=Object.getOwnPropertyDescriptor,ge=(e,t,n,r)=>{for(var i=r>1?void 0:r?Ie(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=(r?c(t,n,i):c(i))||i);return r&&i&&he(t,n,i),i},j=(e,t)=>(n,r)=>t(n,r,e);let P=class extends s.Disposable{constructor(e,t,n,r,i){super(),this._config=e,this._commandService=t,this._menuService=n,this._injector=r,this._componentManager=i,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[H,W,x,L].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){[Ce].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(e(this._injector),this._config.menu))})}_initComponents(){[Z].forEach(e=>{this.disposeWithMe(this._componentManager.register(e.componentKey,e))}),this.disposeWithMe(this._componentManager.register("CommentSingle",k))}};P=ge([s.OnLifecycle(s.LifecycleStages.Rendered,P),j(1,s.ICommandService),j(2,_.IMenuService),j(3,f.Inject(f.Injector)),j(4,f.Inject(_.ComponentManager))],P);var _e=Object.defineProperty,pe=Object.getOwnPropertyDescriptor,Se=(e,t,n,r)=>{for(var i=r>1?void 0:r?pe(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=(r?c(t,n,i):c(i))||i);return r&&i&&_e(t,n,i),i},y=(e,t)=>(n,r)=>t(n,r,e);let V=class extends s.Disposable{constructor(e,t,n,r,i){super(),this._threadCommentPanelService=e,this._univerInstanceService=t,this._commandService=n,this._docThreadCommentService=r,this._renderManagerService=i,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,n,r,i;if(e.id===h.SetTextSelectionsOperation.id){const o=e.params,{unitId:c,ranges:a}=o,l=this._univerInstanceService.getUnit(c,s.UniverInstanceType.UNIVER_DOC),m=a[0];if(m&&l){const{startOffset:C,endOffset:O,collapsed:I}=m;let u;if(I?u=(n=(t=l.getBody())==null?void 0:t.customDecorations)==null?void 0:n.find(d=>d.startIndex<=C&&d.endIndex>=O-1):u=(i=(r=l.getBody())==null?void 0:r.customDecorations)==null?void 0:i.find(d=>d.startIndex<=C&&d.endIndex>=O-1),u){this._commandService.executeCommand(x.id,{activeComment:{unitId:c,subUnitId:D,commentId:u.id}});return}}this._commandService.executeCommand(S.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var t,n,r;if(e){const i=this._univerInstanceService.getUnit(e.unitId);if(i){const o=(t=this._renderManagerService.getRenderById(e.unitId))==null?void 0:t.with(Y.DocBackScrollRenderController),c=(n=i.getCustomRanges())==null?void 0:n.find(a=>a.rangeId===e.commentId);c&&o&&o.scrollToRange(e.unitId,{startOffset:c.startIndex,endOffset:c.endIndex,collapsed:!1})}}(!e||e.commentId!==((r=this._docThreadCommentService.addingComment)==null?void 0:r.id))&&this._docThreadCommentService.endAdd()}))}};V=Se([s.OnLifecycle(s.LifecycleStages.Rendered,V),y(0,f.Inject(S.ThreadCommentPanelService)),y(1,s.IUniverInstanceService),y(2,s.ICommandService),y(3,f.Inject(T)),y(4,R.IRenderManagerService)],V);var Oe=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Me=(e,t,n,r)=>{for(var i=r>1?void 0:r?be(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=(r?c(t,n,i):c(i))||i);return r&&i&&Oe(t,n,i),i},U=(e,t)=>(n,r)=>t(n,r,e);let $=class extends s.Disposable{constructor(e,t,n,r,i,o){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=n,this._docRenderController=r,this._univerInstanceService=i,this._threadCommentModel=o,this._interceptorViewModel(),this._initReRender()}_initReRender(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var n;if(e){this._docRenderController.reRender(e.unitId);return}const t=(n=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_DOC))==null?void 0:n.getUnitId();t&&this._docRenderController.reRender(t)})),this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{e.type==="resolve"&&this._docRenderController.reRender(e.unitId)}))}_interceptorViewModel(){this._docInterceptorService.intercept(h.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION,{handler:(e,t,n)=>{if(!e)return n(e);const{unitId:r,index:i,customDecorations:o}=t,c=this._threadCommentPanelService.activeCommentId,{commentId:a,unitId:l}=c||{},m=o.find(u=>u.id===a),C=this._threadCommentModel.getComment(r,D,e.id);if(!C)return n({...e,show:!1});const O=m&&i>=m.startIndex&&i<=m.endIndex,I=l===r&&e.id===a;return n({...e,active:I||O,show:!C.resolved})}})}};$=Me([s.OnLifecycle(s.LifecycleStages.Starting,$),U(1,f.Inject(h.DocInterceptorService)),U(2,f.Inject(S.ThreadCommentPanelService)),U(3,f.Inject(Y.DocRenderController)),U(4,s.IUniverInstanceService),U(5,f.Inject(F.ThreadCommentModel))],$);var ee=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Te=(e,t,n)=>t in e?ee(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ye=(e,t,n,r)=>{for(var i=r>1?void 0:r?De(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=(r?c(t,n,i):c(i))||i);return r&&i&&ee(t,n,i),i},X=(e,t)=>(n,r)=>t(n,r,e),te=(e,t,n)=>Te(e,typeof t!="symbol"?t+"":t,n);exports.UniverDocsThreadCommentUIPlugin=class extends s.Plugin{constructor(t={menu:{}},n,r){super(),this._config=t,this._injector=n,this._renderManagerSrv=r}onStarting(t){[[P,{useFactory:()=>this._injector.createInstance(P,this._config)}],[V],[T]].forEach(n=>{t.add(n)})}onRendered(){this._initRenderModule()}_initRenderModule(){[$].forEach(t=>{this._renderManagerSrv.registerRenderModule(s.UniverInstanceType.UNIVER_DOC,t)})}};te(exports.UniverDocsThreadCommentUIPlugin,"pluginName",oe);te(exports.UniverDocsThreadCommentUIPlugin,"type",s.UniverInstanceType.UNIVER_DOC);exports.UniverDocsThreadCommentUIPlugin=ye([s.DependentOn(S.UniverThreadCommentUIPlugin),X(1,f.Inject(f.Injector)),X(2,R.IRenderManagerService)],exports.UniverDocsThreadCommentUIPlugin);exports.AddDocCommentComment=H;exports.DeleteDocCommentComment=W;exports.ShowCommentPanelOperation=x;exports.StartAddCommentOperation=L;
@@ -0,0 +1,464 @@
1
+ var he = Object.defineProperty;
2
+ var ve = (e, t, n) => t in e ? he(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var B = (e, t, n) => ve(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { CommandType as $, ICommandService as O, CustomDecorationType as _e, sequenceExecuteAsync as pe, IUniverInstanceService as N, UniverInstanceType as p, UserManagerService as ge, sequenceExecute as Se, OnLifecycle as F, LifecycleStages as H, Disposable as W, DependentOn as Ie, Plugin as Oe } from "@univerjs/core";
5
+ import { Inject as v, Injector as ne } from "@wendellhu/redi";
6
+ import { SetActiveCommentOperation as re, ThreadCommentPanelService as R, getDT as Me, ThreadCommentPanel as be, UniverThreadCommentUIPlugin as De } from "@univerjs/thread-comment-ui";
7
+ import { IRenderManagerService as Z, DocumentEditArea as J } from "@univerjs/engine-render";
8
+ import { ISidebarService as z, MenuGroup as Re, MenuItemType as xe, MenuPosition as Q, getMenuHiddenObservable as ye, ComponentManager as Te, IMenuService as Pe } from "@univerjs/ui";
9
+ import { addCustomDecorationBySelectionFactory as Ue, TextSelectionManagerService as G, getSelectionText as Ee, deleteCustomDecorationFactory as Ae, RichTextEditingMutation as we, DocSkeletonManagerService as Ve, SetTextSelectionsOperation as $e, DocInterceptorService as Ne, DOC_INTERCEPTOR_POINT as je } from "@univerjs/docs";
10
+ import { IThreadCommentDataSourceService as Be, AddCommentMutation as Le, ThreadCommentModel as Fe } from "@univerjs/thread-comment";
11
+ import { useDependency as P, useObservable as L } from "@wendellhu/redi/react-bindings";
12
+ import He, { forwardRef as ie, useRef as We, createElement as oe, useMemo as k, useState as Ze, useEffect as ze } from "react";
13
+ import { BehaviorSubject as Ge, Observable as ce, debounceTime as Ke } from "rxjs";
14
+ import { DocBackScrollRenderController as qe, DocRenderController as Xe } from "@univerjs/docs-ui";
15
+ const Ye = "DOC_THREAD_COMMENT_UI_PLUGIN", S = "default_doc";
16
+ var u = function() {
17
+ return u = Object.assign || function(e) {
18
+ for (var t, n = 1, r = arguments.length; n < r; n++) {
19
+ t = arguments[n];
20
+ for (var i in t) Object.prototype.hasOwnProperty.call(t, i) && (e[i] = t[i]);
21
+ }
22
+ return e;
23
+ }, u.apply(this, arguments);
24
+ }, Je = function(e, t) {
25
+ var n = {};
26
+ for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && t.indexOf(r) < 0 && (n[r] = e[r]);
27
+ if (e != null && typeof Object.getOwnPropertySymbols == "function")
28
+ for (var i = 0, r = Object.getOwnPropertySymbols(e); i < r.length; i++)
29
+ t.indexOf(r[i]) < 0 && Object.prototype.propertyIsEnumerable.call(e, r[i]) && (n[r[i]] = e[r[i]]);
30
+ return n;
31
+ }, se = ie(function(e, t) {
32
+ var n = e.icon, r = e.id, i = e.className, o = e.extend, c = Je(e, ["icon", "id", "className", "extend"]), s = "univerjs-icon univerjs-icon-".concat(r, " ").concat(i || "").trim(), m = We("_".concat(et()));
33
+ return ae(n, "".concat(r), { defIds: n.defIds, idSuffix: m.current }, u({ ref: t, className: s }, c), o);
34
+ });
35
+ function ae(e, t, n, r, i) {
36
+ return oe(e.tag, u(u({ key: t }, Qe(e, n, i)), r), (ke(e, n).children || []).map(function(o, c) {
37
+ return ae(o, "".concat(t, "-").concat(e.tag, "-").concat(c), n, void 0, i);
38
+ }));
39
+ }
40
+ function Qe(e, t, n) {
41
+ var r = u({}, e.attrs);
42
+ n != null && n.colorChannel1 && r.fill === "colorChannel1" && (r.fill = n.colorChannel1);
43
+ var i = t.defIds;
44
+ return !i || i.length === 0 || (e.tag === "use" && r["xlink:href"] && (r["xlink:href"] = r["xlink:href"] + t.idSuffix), Object.entries(r).forEach(function(o) {
45
+ var c = o[0], s = o[1];
46
+ typeof s == "string" && (r[c] = s.replace(/url\(#(.*)\)/, "url(#$1".concat(t.idSuffix, ")")));
47
+ })), r;
48
+ }
49
+ function ke(e, t) {
50
+ var n, r = t.defIds;
51
+ return !r || r.length === 0 ? e : e.tag === "defs" && (!((n = e.children) === null || n === void 0) && n.length) ? u(u({}, e), { children: e.children.map(function(i) {
52
+ return typeof i.attrs.id == "string" && r && r.indexOf(i.attrs.id) > -1 ? u(u({}, i), { attrs: u(u({}, i.attrs), { id: i.attrs.id + t.idSuffix }) }) : i;
53
+ }) }) : e;
54
+ }
55
+ function et() {
56
+ return Math.random().toString(36).substring(2, 8);
57
+ }
58
+ se.displayName = "UniverIcon";
59
+ var tt = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 17", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345ZM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345ZM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "path", attrs: { fill: "currentColor", d: "M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521 5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345zM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521 8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345zM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521 11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345z" } }, { tag: "path", attrs: { fill: "currentColor", d: "M1.84351 3.41861C1.84351 3.01861 2.15531 2.69434 2.53993 2.69434H14.9381C15.3228 2.69434 15.6346 3.01861 15.6346 3.41861V12.4611C15.6346 12.8612 15.3228 13.1854 14.9381 13.1854H8.82117L6.06643 14.6179C5.85054 14.7301 5.59416 14.7181 5.38884 14.5862C5.18352 14.4542 5.05855 14.2211 5.05855 13.9701V13.1854H2.53993C2.15531 13.1854 1.84351 12.8612 1.84351 12.4611L1.84351 3.41861ZM6.45141 12.7982L8.34531 12.0135C8.44201 11.9632 8.54864 11.9371 8.65676 11.9371H14.2417C14.3522 11.9371 14.4417 11.8475 14.4417 11.7371V4.14271C14.4417 4.03225 14.3522 3.94271 14.2417 3.94271H3.23636C3.12591 3.94271 3.03636 4.03225 3.03636 4.14271L3.03636 11.7371C3.03636 11.8475 3.12591 11.9371 3.23636 11.9371L5.75498 11.9371C6.1396 11.9371 6.45141 12.0611 6.45141 12.4611V12.7982Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, de = ie(function(e, t) {
60
+ return oe(se, Object.assign({}, e, {
61
+ id: "comment-single",
62
+ ref: t,
63
+ icon: tt
64
+ }));
65
+ });
66
+ de.displayName = "CommentSingle";
67
+ const me = {
68
+ id: "docs.command.add-comment",
69
+ type: $.COMMAND,
70
+ async handler(e, t) {
71
+ if (!t)
72
+ return !1;
73
+ const { comment: n, unitId: r } = t, o = await e.get(Be).addComment(n), c = e.get(O), s = Ue(
74
+ e,
75
+ {
76
+ id: o.id,
77
+ type: _e.COMMENT
78
+ }
79
+ );
80
+ if (s) {
81
+ const m = {
82
+ id: Le.id,
83
+ params: {
84
+ unitId: r,
85
+ subUnitId: S,
86
+ comment: o
87
+ }
88
+ }, d = {
89
+ id: re.id,
90
+ params: {
91
+ unitId: r,
92
+ subUnitId: S,
93
+ commentId: o.id
94
+ }
95
+ };
96
+ return (await pe([m, s, d], c)).result;
97
+ }
98
+ return !1;
99
+ }
100
+ };
101
+ var nt = Object.defineProperty, rt = Object.getOwnPropertyDescriptor, it = (e, t, n, r) => {
102
+ for (var i = r > 1 ? void 0 : r ? rt(t, n) : t, o = e.length - 1, c; o >= 0; o--)
103
+ (c = e[o]) && (i = (r ? c(t, n, i) : c(i)) || i);
104
+ return r && i && nt(t, n, i), i;
105
+ }, ee = (e, t) => (n, r) => t(n, r, e);
106
+ let I = class {
107
+ constructor(e, t) {
108
+ B(this, "_addingComment$", new Ge(void 0));
109
+ B(this, "addingComment$", this._addingComment$.asObservable());
110
+ this._sidebarService = e, this._threadCommentPanelService = t;
111
+ }
112
+ get addingComment() {
113
+ return this._addingComment$.getValue();
114
+ }
115
+ startAdd(e) {
116
+ this._addingComment$.next(e);
117
+ }
118
+ endAdd() {
119
+ this._addingComment$.next(void 0);
120
+ }
121
+ };
122
+ I = it([
123
+ ee(0, z),
124
+ ee(1, v(R))
125
+ ], I);
126
+ const w = {
127
+ id: "docs.operation.show-comment-panel",
128
+ type: $.OPERATION,
129
+ handler(e, t) {
130
+ const n = e.get(R), r = e.get(z);
131
+ return n.panelVisible || (r.open({
132
+ header: { title: "threadCommentUI.panel.title" },
133
+ children: { label: q.componentKey },
134
+ width: 320,
135
+ onClose: () => n.setPanelVisible(!1)
136
+ }), n.setPanelVisible(!0)), t && n.setActiveComment(t == null ? void 0 : t.activeComment), !0;
137
+ }
138
+ }, K = {
139
+ id: "docs.operation.start-add-comment",
140
+ type: $.OPERATION,
141
+ handler(e) {
142
+ var h, x;
143
+ const t = e.get(R), r = e.get(N).getCurrentUnitForType(p.UNIVER_DOC), i = e.get(G), o = e.get(ge), c = e.get(I), s = e.get(O), m = e.get(z), d = i.getActiveRange();
144
+ if (!r || !d)
145
+ return !1;
146
+ if (d.collapsed)
147
+ return t.panelVisible ? (t.setPanelVisible(!1), m.close()) : s.executeCommand(w.id), !0;
148
+ t.panelVisible || s.executeCommand(w.id);
149
+ const f = r.getUnitId(), _ = Ee((x = (h = r.getBody()) == null ? void 0 : h.dataStream) != null ? x : "", d.startOffset, d.endOffset), C = S, l = "", a = {
150
+ unitId: f,
151
+ subUnitId: C,
152
+ id: l,
153
+ ref: _,
154
+ dT: Me(),
155
+ personId: o.getCurrentUser().userID,
156
+ text: {
157
+ dataStream: `\r
158
+ `
159
+ },
160
+ startOffset: d.startOffset,
161
+ endOffset: d.endOffset,
162
+ collapsed: !0,
163
+ threadId: l
164
+ };
165
+ return c.startAdd(a), t.setActiveComment({
166
+ unitId: f,
167
+ subUnitId: C,
168
+ commentId: l
169
+ }), !0;
170
+ }
171
+ }, le = {
172
+ id: "docs.command.delete-comment",
173
+ type: $.COMMAND,
174
+ async handler(e, t) {
175
+ if (!t)
176
+ return !1;
177
+ const { commentId: n, unitId: r } = t, i = e.get(O), o = Ae(e, {
178
+ id: n,
179
+ unitId: r
180
+ });
181
+ return o ? (await Se([o], i)).result : !1;
182
+ }
183
+ }, q = () => {
184
+ var l;
185
+ const e = P(N), t = k(() => e.getCurrentTypeOfUnit$(p.UNIVER_DOC), [e]), n = L(t), r = k(() => new ce((a) => a.next(S)), []), i = P(G), o = (l = L(i.textSelection$)) == null ? void 0 : l.textRanges[0], c = P(O), s = P(I), m = L(s.addingComment$), [d, f] = Ze([]);
186
+ if (ze(() => {
187
+ var X;
188
+ const a = /* @__PURE__ */ new Set(), h = n == null ? void 0 : n.getCustomDecorations();
189
+ f((X = h == null ? void 0 : h.map((g) => g.id).filter((g) => {
190
+ const y = a.has(g);
191
+ return a.add(g), !y;
192
+ })) != null ? X : []);
193
+ const x = c.onCommandExecuted((g) => {
194
+ var y;
195
+ if (g.id === we.id) {
196
+ const Y = /* @__PURE__ */ new Set(), j = n == null ? void 0 : n.getCustomDecorations();
197
+ f((y = j == null ? void 0 : j.map((T) => T.id).filter((T) => {
198
+ const Ce = Y.has(T);
199
+ return Y.add(T), !Ce;
200
+ })) != null ? y : []);
201
+ }
202
+ });
203
+ return () => {
204
+ x.dispose();
205
+ };
206
+ }, [c, n]), !n)
207
+ return null;
208
+ const _ = o && o.endOffset === o.startOffset, C = n.getUnitId();
209
+ return /* @__PURE__ */ He.createElement(
210
+ be,
211
+ {
212
+ unitId: C,
213
+ subUnitId$: r,
214
+ type: p.UNIVER_DOC,
215
+ onAdd: () => {
216
+ c.executeCommand(K.id);
217
+ },
218
+ getSubUnitName: () => "",
219
+ disableAdd: _,
220
+ tempComment: m,
221
+ onAddComment: (a) => {
222
+ if (!a.parentId) {
223
+ const h = {
224
+ unitId: C,
225
+ range: m,
226
+ comment: a
227
+ };
228
+ return c.executeCommand(me.id, h), s.endAdd(), !1;
229
+ }
230
+ return !0;
231
+ },
232
+ onDeleteComment: (a) => {
233
+ if (!a.parentId) {
234
+ const h = {
235
+ unitId: C,
236
+ commentId: a.id
237
+ };
238
+ return c.executeCommand(le.id, h), !1;
239
+ }
240
+ return !0;
241
+ },
242
+ showComments: d
243
+ }
244
+ );
245
+ };
246
+ q.componentKey = "univer.doc.thread-comment-panel";
247
+ const ot = (e) => {
248
+ const n = e.get(Z).getCurrent(), r = n == null ? void 0 : n.with(Ve).getSkeleton(), i = r == null ? void 0 : r.getViewModel().getEditArea();
249
+ return i === J.FOOTER || i === J.HEADER;
250
+ };
251
+ function ct(e) {
252
+ return {
253
+ id: K.id,
254
+ group: Re.TOOLBAR_LAYOUT,
255
+ type: xe.BUTTON,
256
+ icon: "CommentSingle",
257
+ title: "threadCommentUI.panel.addComment",
258
+ tooltip: "threadCommentUI.panel.addComment",
259
+ positions: [Q.TOOLBAR_START, Q.CONTEXT_MENU],
260
+ hidden$: ye(e, p.UNIVER_DOC),
261
+ disabled$: new ce(function(t) {
262
+ const r = e.get(G).textSelection$.pipe(Ke(16)).subscribe(() => {
263
+ t.next(ot(e));
264
+ });
265
+ return () => {
266
+ r.unsubscribe();
267
+ };
268
+ })
269
+ };
270
+ }
271
+ var st = Object.defineProperty, at = Object.getOwnPropertyDescriptor, dt = (e, t, n, r) => {
272
+ for (var i = r > 1 ? void 0 : r ? at(t, n) : t, o = e.length - 1, c; o >= 0; o--)
273
+ (c = e[o]) && (i = (r ? c(t, n, i) : c(i)) || i);
274
+ return r && i && st(t, n, i), i;
275
+ }, U = (e, t) => (n, r) => t(n, r, e);
276
+ let D = class extends W {
277
+ constructor(e, t, n, r, i) {
278
+ super(), this._config = e, this._commandService = t, this._menuService = n, this._injector = r, this._componentManager = i, this._initCommands(), this._initMenus(), this._initComponents();
279
+ }
280
+ _initCommands() {
281
+ [
282
+ me,
283
+ le,
284
+ w,
285
+ K
286
+ ].forEach((e) => {
287
+ this.disposeWithMe(this._commandService.registerCommand(e));
288
+ });
289
+ }
290
+ _initMenus() {
291
+ [ct].forEach((e) => {
292
+ this.disposeWithMe(this._menuService.addMenuItem(e(this._injector), this._config.menu));
293
+ });
294
+ }
295
+ _initComponents() {
296
+ [q].forEach((e) => {
297
+ this.disposeWithMe(this._componentManager.register(e.componentKey, e));
298
+ }), this.disposeWithMe(this._componentManager.register("CommentSingle", de));
299
+ }
300
+ };
301
+ D = dt([
302
+ F(H.Rendered, D),
303
+ U(1, O),
304
+ U(2, Pe),
305
+ U(3, v(ne)),
306
+ U(4, v(Te))
307
+ ], D);
308
+ var mt = Object.defineProperty, lt = Object.getOwnPropertyDescriptor, ut = (e, t, n, r) => {
309
+ for (var i = r > 1 ? void 0 : r ? lt(t, n) : t, o = e.length - 1, c; o >= 0; o--)
310
+ (c = e[o]) && (i = (r ? c(t, n, i) : c(i)) || i);
311
+ return r && i && mt(t, n, i), i;
312
+ }, M = (e, t) => (n, r) => t(n, r, e);
313
+ let E = class extends W {
314
+ constructor(e, t, n, r, i) {
315
+ super(), this._threadCommentPanelService = e, this._univerInstanceService = t, this._commandService = n, this._docThreadCommentService = r, this._renderManagerService = i, this._initSelectionChange(), this._initActiveCommandChange();
316
+ }
317
+ _initSelectionChange() {
318
+ this.disposeWithMe(
319
+ this._commandService.onCommandExecuted((e) => {
320
+ var t, n, r, i;
321
+ if (e.id === $e.id) {
322
+ const o = e.params, { unitId: c, ranges: s } = o, m = this._univerInstanceService.getUnit(c, p.UNIVER_DOC), d = s[0];
323
+ if (d && m) {
324
+ const { startOffset: f, endOffset: _, collapsed: C } = d;
325
+ let l;
326
+ if (C ? l = (n = (t = m.getBody()) == null ? void 0 : t.customDecorations) == null ? void 0 : n.find((a) => a.startIndex <= f && a.endIndex >= _ - 1) : l = (i = (r = m.getBody()) == null ? void 0 : r.customDecorations) == null ? void 0 : i.find((a) => a.startIndex <= f && a.endIndex >= _ - 1), l) {
327
+ this._commandService.executeCommand(w.id, {
328
+ activeComment: {
329
+ unitId: c,
330
+ subUnitId: S,
331
+ commentId: l.id
332
+ }
333
+ });
334
+ return;
335
+ }
336
+ }
337
+ this._commandService.executeCommand(re.id);
338
+ }
339
+ })
340
+ );
341
+ }
342
+ _initActiveCommandChange() {
343
+ this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe((e) => {
344
+ var t, n, r;
345
+ if (e) {
346
+ const i = this._univerInstanceService.getUnit(e.unitId);
347
+ if (i) {
348
+ const o = (t = this._renderManagerService.getRenderById(e.unitId)) == null ? void 0 : t.with(qe), c = (n = i.getCustomRanges()) == null ? void 0 : n.find((s) => s.rangeId === e.commentId);
349
+ c && o && o.scrollToRange(e.unitId, {
350
+ startOffset: c.startIndex,
351
+ endOffset: c.endIndex,
352
+ collapsed: !1
353
+ });
354
+ }
355
+ }
356
+ (!e || e.commentId !== ((r = this._docThreadCommentService.addingComment) == null ? void 0 : r.id)) && this._docThreadCommentService.endAdd();
357
+ }));
358
+ }
359
+ };
360
+ E = ut([
361
+ F(H.Rendered, E),
362
+ M(0, v(R)),
363
+ M(1, N),
364
+ M(2, O),
365
+ M(3, v(I)),
366
+ M(4, Z)
367
+ ], E);
368
+ var ft = Object.defineProperty, Ct = Object.getOwnPropertyDescriptor, ht = (e, t, n, r) => {
369
+ for (var i = r > 1 ? void 0 : r ? Ct(t, n) : t, o = e.length - 1, c; o >= 0; o--)
370
+ (c = e[o]) && (i = (r ? c(t, n, i) : c(i)) || i);
371
+ return r && i && ft(t, n, i), i;
372
+ }, b = (e, t) => (n, r) => t(n, r, e);
373
+ let A = class extends W {
374
+ constructor(e, t, n, r, i, o) {
375
+ super(), this._context = e, this._docInterceptorService = t, this._threadCommentPanelService = n, this._docRenderController = r, this._univerInstanceService = i, this._threadCommentModel = o, this._interceptorViewModel(), this._initReRender();
376
+ }
377
+ _initReRender() {
378
+ this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe((e) => {
379
+ var n;
380
+ if (e) {
381
+ this._docRenderController.reRender(e.unitId);
382
+ return;
383
+ }
384
+ const t = (n = this._univerInstanceService.getCurrentUnitForType(p.UNIVER_DOC)) == null ? void 0 : n.getUnitId();
385
+ t && this._docRenderController.reRender(t);
386
+ })), this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe((e) => {
387
+ e.type === "resolve" && this._docRenderController.reRender(e.unitId);
388
+ }));
389
+ }
390
+ _interceptorViewModel() {
391
+ this._docInterceptorService.intercept(je.CUSTOM_DECORATION, {
392
+ handler: (e, t, n) => {
393
+ if (!e)
394
+ return n(e);
395
+ const { unitId: r, index: i, customDecorations: o } = t, c = this._threadCommentPanelService.activeCommentId, { commentId: s, unitId: m } = c || {}, d = o.find((l) => l.id === s), f = this._threadCommentModel.getComment(r, S, e.id);
396
+ if (!f)
397
+ return n({
398
+ ...e,
399
+ show: !1
400
+ });
401
+ const _ = d && i >= d.startIndex && i <= d.endIndex, C = m === r && e.id === s;
402
+ return n({
403
+ ...e,
404
+ active: C || _,
405
+ show: !f.resolved
406
+ });
407
+ }
408
+ });
409
+ }
410
+ };
411
+ A = ht([
412
+ F(H.Starting, A),
413
+ b(1, v(Ne)),
414
+ b(2, v(R)),
415
+ b(3, v(Xe)),
416
+ b(4, N),
417
+ b(5, v(Fe))
418
+ ], A);
419
+ var ue = Object.defineProperty, vt = Object.getOwnPropertyDescriptor, _t = (e, t, n) => t in e ? ue(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, pt = (e, t, n, r) => {
420
+ for (var i = r > 1 ? void 0 : r ? vt(t, n) : t, o = e.length - 1, c; o >= 0; o--)
421
+ (c = e[o]) && (i = (r ? c(t, n, i) : c(i)) || i);
422
+ return r && i && ue(t, n, i), i;
423
+ }, te = (e, t) => (n, r) => t(n, r, e), fe = (e, t, n) => _t(e, typeof t != "symbol" ? t + "" : t, n);
424
+ let V = class extends Oe {
425
+ constructor(e = { menu: {} }, t, n) {
426
+ super(), this._config = e, this._injector = t, this._renderManagerSrv = n;
427
+ }
428
+ onStarting(e) {
429
+ [
430
+ [
431
+ D,
432
+ {
433
+ useFactory: () => this._injector.createInstance(D, this._config)
434
+ }
435
+ ],
436
+ [E],
437
+ [I]
438
+ ].forEach((t) => {
439
+ e.add(t);
440
+ });
441
+ }
442
+ onRendered() {
443
+ this._initRenderModule();
444
+ }
445
+ _initRenderModule() {
446
+ [A].forEach((e) => {
447
+ this._renderManagerSrv.registerRenderModule(p.UNIVER_DOC, e);
448
+ });
449
+ }
450
+ };
451
+ fe(V, "pluginName", Ye);
452
+ fe(V, "type", p.UNIVER_DOC);
453
+ V = pt([
454
+ Ie(De),
455
+ te(1, v(ne)),
456
+ te(2, Z)
457
+ ], V);
458
+ export {
459
+ me as AddDocCommentComment,
460
+ le as DeleteDocCommentComment,
461
+ w as ShowCommentPanelOperation,
462
+ K as StartAddCommentOperation,
463
+ V as UniverDocsThreadCommentUIPlugin
464
+ };
@@ -0,0 +1,9 @@
1
+ import { ICommand, ITextRange } from '@univerjs/core';
2
+ import { IThreadComment } from '@univerjs/thread-comment';
3
+
4
+ export interface IAddDocCommentComment {
5
+ unitId: string;
6
+ comment: IThreadComment;
7
+ range: ITextRange;
8
+ }
9
+ export declare const AddDocCommentComment: ICommand<IAddDocCommentComment>;
@@ -0,0 +1,7 @@
1
+ import { ICommand } from '@univerjs/core';
2
+
3
+ export interface IDeleteDocCommentComment {
4
+ unitId: string;
5
+ commentId: string;
6
+ }
7
+ export declare const DeleteDocCommentComment: ICommand<IDeleteDocCommentComment>;
@@ -0,0 +1,8 @@
1
+ import { ICommand } from '@univerjs/core';
2
+ import { ActiveCommentInfo } from '@univerjs/thread-comment-ui';
3
+
4
+ export interface IShowCommentPanelOperationParams {
5
+ activeComment: ActiveCommentInfo;
6
+ }
7
+ export declare const ShowCommentPanelOperation: ICommand<IShowCommentPanelOperationParams>;
8
+ export declare const StartAddCommentOperation: ICommand;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export declare const PLUGIN_NAME = "DOC_THREAD_COMMENT_UI_PLUGIN";
17
+ export declare const DEFAULT_DOC_SUBUNIT_ID = "default_doc";
18
+ export declare const DEFAULT_TEMP_COMMENT_ID = "default_comment";
@@ -0,0 +1,15 @@
1
+ import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
2
+ import { ThreadCommentPanelService } from '@univerjs/thread-comment-ui';
3
+ import { IRenderManagerService } from '@univerjs/engine-render';
4
+ import { DocThreadCommentService } from '../services/doc-thread-comment.service';
5
+
6
+ export declare class DocThreadCommentSelectionController extends Disposable {
7
+ private readonly _threadCommentPanelService;
8
+ private readonly _univerInstanceService;
9
+ private readonly _commandService;
10
+ private readonly _docThreadCommentService;
11
+ private readonly _renderManagerService;
12
+ constructor(_threadCommentPanelService: ThreadCommentPanelService, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService, _docThreadCommentService: DocThreadCommentService, _renderManagerService: IRenderManagerService);
13
+ private _initSelectionChange;
14
+ private _initActiveCommandChange;
15
+ }
@@ -0,0 +1,18 @@
1
+ import { Disposable, ICommandService } from '@univerjs/core';
2
+ import { MenuConfig, ComponentManager, IMenuService } from '@univerjs/ui';
3
+ import { Injector } from '@wendellhu/redi';
4
+
5
+ export interface IDocThreadCommentUIConfig {
6
+ menu: MenuConfig;
7
+ }
8
+ export declare class DocThreadCommentUIController extends Disposable {
9
+ private _config;
10
+ private readonly _commandService;
11
+ private readonly _menuService;
12
+ private readonly _injector;
13
+ private readonly _componentManager;
14
+ constructor(_config: IDocThreadCommentUIConfig, _commandService: ICommandService, _menuService: IMenuService, _injector: Injector, _componentManager: ComponentManager);
15
+ private _initCommands;
16
+ private _initMenus;
17
+ private _initComponents;
18
+ }
@@ -0,0 +1,5 @@
1
+ import { IAccessor } from '@wendellhu/redi';
2
+ import { IMenuButtonItem } from '@univerjs/ui';
3
+
4
+ export declare const shouldDisableAddComment: (accessor: IAccessor) => boolean;
5
+ export declare function AddDocCommentMenuItemFactory(accessor: IAccessor): IMenuButtonItem;
@@ -0,0 +1,18 @@
1
+ import { DocumentDataModel, Disposable, IUniverInstanceService } from '@univerjs/core';
2
+ import { DocInterceptorService } from '@univerjs/docs';
3
+ import { DocRenderController } from '@univerjs/docs-ui';
4
+ import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
5
+ import { ThreadCommentModel } from '@univerjs/thread-comment';
6
+ import { ThreadCommentPanelService } from '@univerjs/thread-comment-ui';
7
+
8
+ export declare class DocThreadCommentRenderController extends Disposable implements IRenderModule {
9
+ private readonly _context;
10
+ private readonly _docInterceptorService;
11
+ private readonly _threadCommentPanelService;
12
+ private readonly _docRenderController;
13
+ private readonly _univerInstanceService;
14
+ private readonly _threadCommentModel;
15
+ constructor(_context: IRenderContext<DocumentDataModel>, _docInterceptorService: DocInterceptorService, _threadCommentPanelService: ThreadCommentPanelService, _docRenderController: DocRenderController, _univerInstanceService: IUniverInstanceService, _threadCommentModel: ThreadCommentModel);
16
+ private _initReRender;
17
+ private _interceptorViewModel;
18
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export { UniverDocsThreadCommentUIPlugin } from './plugin';
17
+ export { AddDocCommentComment } from './commands/commands/add-doc-comment.command';
18
+ export type { IAddDocCommentComment } from './commands/commands/add-doc-comment.command';
19
+ export { ShowCommentPanelOperation, StartAddCommentOperation } from './commands/operations/show-comment-panel.operation';
20
+ export type { IShowCommentPanelOperationParams } from './commands/operations/show-comment-panel.operation';
21
+ export { DeleteDocCommentComment } from './commands/commands/delete-doc-comment.command';
22
+ export type { IDeleteDocCommentComment } from './commands/commands/delete-doc-comment.command';
@@ -0,0 +1,16 @@
1
+ import { Plugin, UniverInstanceType } from '@univerjs/core';
2
+ import { Injector } from '@wendellhu/redi';
3
+ import { IRenderManagerService } from '@univerjs/engine-render';
4
+ import { IDocThreadCommentUIConfig } from './controllers/doc-thread-comment-ui.controller';
5
+
6
+ export declare class UniverDocsThreadCommentUIPlugin extends Plugin {
7
+ private _config;
8
+ protected _injector: Injector;
9
+ private readonly _renderManagerSrv;
10
+ static pluginName: string;
11
+ static type: UniverInstanceType;
12
+ constructor(_config: IDocThreadCommentUIConfig, _injector: Injector, _renderManagerSrv: IRenderManagerService);
13
+ onStarting(injector: Injector): void;
14
+ onRendered(): void;
15
+ private _initRenderModule;
16
+ }
@@ -0,0 +1,15 @@
1
+ import { ITextRange, Nullable } from '@univerjs/core';
2
+ import { IThreadComment } from '@univerjs/thread-comment';
3
+ import { ThreadCommentPanelService } from '@univerjs/thread-comment-ui';
4
+ import { ISidebarService } from '@univerjs/ui';
5
+
6
+ export declare class DocThreadCommentService {
7
+ private readonly _sidebarService;
8
+ private readonly _threadCommentPanelService;
9
+ private _addingComment$;
10
+ readonly addingComment$: import('rxjs').Observable<Nullable<IThreadComment & ITextRange>>;
11
+ get addingComment(): Nullable<IThreadComment & ITextRange>;
12
+ constructor(_sidebarService: ISidebarService, _threadCommentPanelService: ThreadCommentPanelService);
13
+ startAdd(comment: IThreadComment & ITextRange): void;
14
+ endAdd(): void;
15
+ }
@@ -0,0 +1,6 @@
1
+ import { default as React } from 'react';
2
+
3
+ export declare const DocThreadCommentPanel: {
4
+ (): React.JSX.Element | null;
5
+ componentKey: string;
6
+ };
@@ -0,0 +1,2 @@
1
+ (function(a,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/thread-comment-ui"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("@univerjs/docs"),require("@univerjs/thread-comment"),require("@wendellhu/redi/react-bindings"),require("react"),require("rxjs"),require("@univerjs/docs-ui")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/thread-comment-ui","@univerjs/engine-render","@univerjs/ui","@univerjs/docs","@univerjs/thread-comment","@wendellhu/redi/react-bindings","react","rxjs","@univerjs/docs-ui"],o):(a=typeof globalThis<"u"?globalThis:a||self,o(a.UniverDocsThreadCommentUi={},a.UniverCore,a["@wendellhu/redi"],a.UniverThreadCommentUi,a.UniverEngineRender,a.UniverUi,a.UniverDocs,a.UniverThreadComment,a["@wendellhu/redi/react-bindings"],a.React,a.rxjs,a.UniverDocsUi))})(this,function(a,o,u,_,U,S,h,F,T,p,w,G){"use strict";var ye=Object.defineProperty;var Ue=(a,o,u)=>o in a?ye(a,o,{enumerable:!0,configurable:!0,writable:!0,value:u}):a[o]=u;var z=(a,o,u)=>Ue(a,typeof o!="symbol"?o+"":o,u);const re="DOC_THREAD_COMMENT_UI_PLUGIN",M="default_doc";var C=function(){return C=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},C.apply(this,arguments)},ie=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n},K=p.forwardRef(function(e,t){var n=e.icon,r=e.id,i=e.className,s=e.extend,c=ie(e,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(r," ").concat(i||"").trim(),v=p.useRef("_".concat(ce()));return X(n,"".concat(r),{defIds:n.defIds,idSuffix:v.current},C({ref:t,className:d},c),s)});function X(e,t,n,r,i){return p.createElement(e.tag,C(C({key:t},oe(e,n,i)),r),(se(e,n).children||[]).map(function(s,c){return X(s,"".concat(t,"-").concat(e.tag,"-").concat(c),n,void 0,i)}))}function oe(e,t,n){var r=C({},e.attrs);n!=null&&n.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=n.colorChannel1);var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+t.idSuffix),Object.entries(r).forEach(function(s){var c=s[0],d=s[1];typeof d=="string"&&(r[c]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),r}function se(e,t){var n,r=t.defIds;return!r||r.length===0?e:e.tag==="defs"&&(!((n=e.children)===null||n===void 0)&&n.length)?C(C({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&r&&r.indexOf(i.attrs.id)>-1?C(C({},i),{attrs:C(C({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function ce(){return Math.random().toString(36).substring(2,8)}K.displayName="UniverIcon";var ae={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345ZM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345ZM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521 5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345zM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521 8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345zM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521 11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.84351 3.41861C1.84351 3.01861 2.15531 2.69434 2.53993 2.69434H14.9381C15.3228 2.69434 15.6346 3.01861 15.6346 3.41861V12.4611C15.6346 12.8612 15.3228 13.1854 14.9381 13.1854H8.82117L6.06643 14.6179C5.85054 14.7301 5.59416 14.7181 5.38884 14.5862C5.18352 14.4542 5.05855 14.2211 5.05855 13.9701V13.1854H2.53993C2.15531 13.1854 1.84351 12.8612 1.84351 12.4611L1.84351 3.41861ZM6.45141 12.7982L8.34531 12.0135C8.44201 11.9632 8.54864 11.9371 8.65676 11.9371H14.2417C14.3522 11.9371 14.4417 11.8475 14.4417 11.7371V4.14271C14.4417 4.03225 14.3522 3.94271 14.2417 3.94271H3.23636C3.12591 3.94271 3.03636 4.03225 3.03636 4.14271L3.03636 11.7371C3.03636 11.8475 3.12591 11.9371 3.23636 11.9371L5.75498 11.9371C6.1396 11.9371 6.45141 12.0611 6.45141 12.4611V12.7982Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Y=p.forwardRef(function(e,t){return p.createElement(K,Object.assign({},e,{id:"comment-single",ref:t,icon:ae}))});Y.displayName="CommentSingle";const H={id:"docs.command.add-comment",type:o.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{comment:n,unitId:r}=t,s=await e.get(F.IThreadCommentDataSourceService).addComment(n),c=e.get(o.ICommandService),d=h.addCustomDecorationBySelectionFactory(e,{id:s.id,type:o.CustomDecorationType.COMMENT});if(d){const v={id:F.AddCommentMutation.id,params:{unitId:r,subUnitId:M,comment:s}},l={id:_.SetActiveCommentOperation.id,params:{unitId:r,subUnitId:M,commentId:s.id}};return(await o.sequenceExecuteAsync([v,d,l],c)).result}return!1}};var de=Object.defineProperty,me=Object.getOwnPropertyDescriptor,ue=(e,t,n,r)=>{for(var i=r>1?void 0:r?me(t,n):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=(r?c(t,n,i):c(i))||i);return r&&i&&de(t,n,i),i},J=(e,t)=>(n,r)=>t(n,r,e);let b=class{constructor(e,t){z(this,"_addingComment$",new w.BehaviorSubject(void 0));z(this,"addingComment$",this._addingComment$.asObservable());this._sidebarService=e,this._threadCommentPanelService=t}get addingComment(){return this._addingComment$.getValue()}startAdd(e){this._addingComment$.next(e)}endAdd(){this._addingComment$.next(void 0)}};b=ue([J(0,S.ISidebarService),J(1,u.Inject(_.ThreadCommentPanelService))],b);const P={id:"docs.operation.show-comment-panel",type:o.CommandType.OPERATION,handler(e,t){const n=e.get(_.ThreadCommentPanelService),r=e.get(S.ISidebarService);return n.panelVisible||(r.open({header:{title:"threadCommentUI.panel.title"},children:{label:B.componentKey},width:320,onClose:()=>n.setPanelVisible(!1)}),n.setPanelVisible(!0)),t&&n.setActiveComment(t==null?void 0:t.activeComment),!0}},A={id:"docs.operation.start-add-comment",type:o.CommandType.OPERATION,handler(e){var O,N;const t=e.get(_.ThreadCommentPanelService),r=e.get(o.IUniverInstanceService).getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC),i=e.get(h.TextSelectionManagerService),s=e.get(o.UserManagerService),c=e.get(b),d=e.get(o.ICommandService),v=e.get(S.ISidebarService),l=i.getActiveRange();if(!r||!l)return!1;if(l.collapsed)return t.panelVisible?(t.setPanelVisible(!1),v.close()):d.executeCommand(P.id),!0;t.panelVisible||d.executeCommand(P.id);const I=r.getUnitId(),D=h.getSelectionText((N=(O=r.getBody())==null?void 0:O.dataStream)!=null?N:"",l.startOffset,l.endOffset),g=M,f="",m={unitId:I,subUnitId:g,id:f,ref:D,dT:_.getDT(),personId:s.getCurrentUser().userID,text:{dataStream:`\r
2
+ `},startOffset:l.startOffset,endOffset:l.endOffset,collapsed:!0,threadId:f};return c.startAdd(m),t.setActiveComment({unitId:I,subUnitId:g,commentId:f}),!0}},W={id:"docs.command.delete-comment",type:o.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{commentId:n,unitId:r}=t,i=e.get(o.ICommandService),s=h.deleteCustomDecorationFactory(e,{id:n,unitId:r});return s?(await o.sequenceExecute([s],i)).result:!1}},B=()=>{var f;const e=T.useDependency(o.IUniverInstanceService),t=p.useMemo(()=>e.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_DOC),[e]),n=T.useObservable(t),r=p.useMemo(()=>new w.Observable(m=>m.next(M)),[]),i=T.useDependency(h.TextSelectionManagerService),s=(f=T.useObservable(i.textSelection$))==null?void 0:f.textRanges[0],c=T.useDependency(o.ICommandService),d=T.useDependency(b),v=T.useObservable(d.addingComment$),[l,I]=p.useState([]);if(p.useEffect(()=>{var te;const m=new Set,O=n==null?void 0:n.getCustomDecorations();I((te=O==null?void 0:O.map(y=>y.id).filter(y=>{const L=m.has(y);return m.add(y),!L}))!=null?te:[]);const N=c.onCommandExecuted(y=>{var L;if(y.id===h.RichTextEditingMutation.id){const ne=new Set,Z=n==null?void 0:n.getCustomDecorations();I((L=Z==null?void 0:Z.map(q=>q.id).filter(q=>{const be=ne.has(q);return ne.add(q),!be}))!=null?L:[])}});return()=>{N.dispose()}},[c,n]),!n)return null;const D=s&&s.endOffset===s.startOffset,g=n.getUnitId();return p.createElement(_.ThreadCommentPanel,{unitId:g,subUnitId$:r,type:o.UniverInstanceType.UNIVER_DOC,onAdd:()=>{c.executeCommand(A.id)},getSubUnitName:()=>"",disableAdd:D,tempComment:v,onAddComment:m=>{if(!m.parentId){const O={unitId:g,range:v,comment:m};return c.executeCommand(H.id,O),d.endAdd(),!1}return!0},onDeleteComment:m=>{if(!m.parentId){const O={unitId:g,commentId:m.id};return c.executeCommand(W.id,O),!1}return!0},showComments:l})};B.componentKey="univer.doc.thread-comment-panel";const le=e=>{const n=e.get(U.IRenderManagerService).getCurrent(),r=n==null?void 0:n.with(h.DocSkeletonManagerService).getSkeleton(),i=r==null?void 0:r.getViewModel().getEditArea();return i===U.DocumentEditArea.FOOTER||i===U.DocumentEditArea.HEADER};function ve(e){return{id:A.id,group:S.MenuGroup.TOOLBAR_LAYOUT,type:S.MenuItemType.BUTTON,icon:"CommentSingle",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",positions:[S.MenuPosition.TOOLBAR_START,S.MenuPosition.CONTEXT_MENU],hidden$:S.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC),disabled$:new w.Observable(function(t){const r=e.get(h.TextSelectionManagerService).textSelection$.pipe(w.debounceTime(16)).subscribe(()=>{t.next(le(e))});return()=>{r.unsubscribe()}})}}var fe=Object.defineProperty,Ce=Object.getOwnPropertyDescriptor,he=(e,t,n,r)=>{for(var i=r>1?void 0:r?Ce(t,n):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=(r?c(t,n,i):c(i))||i);return r&&i&&fe(t,n,i),i},E=(e,t)=>(n,r)=>t(n,r,e);let j=class extends o.Disposable{constructor(e,t,n,r,i){super(),this._config=e,this._commandService=t,this._menuService=n,this._injector=r,this._componentManager=i,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[H,W,P,A].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){[ve].forEach(e=>{this.disposeWithMe(this._menuService.addMenuItem(e(this._injector),this._config.menu))})}_initComponents(){[B].forEach(e=>{this.disposeWithMe(this._componentManager.register(e.componentKey,e))}),this.disposeWithMe(this._componentManager.register("CommentSingle",Y))}};j=he([o.OnLifecycle(o.LifecycleStages.Rendered,j),E(1,o.ICommandService),E(2,S.IMenuService),E(3,u.Inject(u.Injector)),E(4,u.Inject(S.ComponentManager))],j);var Ie=Object.defineProperty,_e=Object.getOwnPropertyDescriptor,Se=(e,t,n,r)=>{for(var i=r>1?void 0:r?_e(t,n):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=(r?c(t,n,i):c(i))||i);return r&&i&&Ie(t,n,i),i},x=(e,t)=>(n,r)=>t(n,r,e);let V=class extends o.Disposable{constructor(e,t,n,r,i){super(),this._threadCommentPanelService=e,this._univerInstanceService=t,this._commandService=n,this._docThreadCommentService=r,this._renderManagerService=i,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,n,r,i;if(e.id===h.SetTextSelectionsOperation.id){const s=e.params,{unitId:c,ranges:d}=s,v=this._univerInstanceService.getUnit(c,o.UniverInstanceType.UNIVER_DOC),l=d[0];if(l&&v){const{startOffset:I,endOffset:D,collapsed:g}=l;let f;if(g?f=(n=(t=v.getBody())==null?void 0:t.customDecorations)==null?void 0:n.find(m=>m.startIndex<=I&&m.endIndex>=D-1):f=(i=(r=v.getBody())==null?void 0:r.customDecorations)==null?void 0:i.find(m=>m.startIndex<=I&&m.endIndex>=D-1),f){this._commandService.executeCommand(P.id,{activeComment:{unitId:c,subUnitId:M,commentId:f.id}});return}}this._commandService.executeCommand(_.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var t,n,r;if(e){const i=this._univerInstanceService.getUnit(e.unitId);if(i){const s=(t=this._renderManagerService.getRenderById(e.unitId))==null?void 0:t.with(G.DocBackScrollRenderController),c=(n=i.getCustomRanges())==null?void 0:n.find(d=>d.rangeId===e.commentId);c&&s&&s.scrollToRange(e.unitId,{startOffset:c.startIndex,endOffset:c.endIndex,collapsed:!1})}}(!e||e.commentId!==((r=this._docThreadCommentService.addingComment)==null?void 0:r.id))&&this._docThreadCommentService.endAdd()}))}};V=Se([o.OnLifecycle(o.LifecycleStages.Rendered,V),x(0,u.Inject(_.ThreadCommentPanelService)),x(1,o.IUniverInstanceService),x(2,o.ICommandService),x(3,u.Inject(b)),x(4,U.IRenderManagerService)],V);var pe=Object.defineProperty,ge=Object.getOwnPropertyDescriptor,Oe=(e,t,n,r)=>{for(var i=r>1?void 0:r?ge(t,n):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=(r?c(t,n,i):c(i))||i);return r&&i&&pe(t,n,i),i},R=(e,t)=>(n,r)=>t(n,r,e);let $=class extends o.Disposable{constructor(e,t,n,r,i,s){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=n,this._docRenderController=r,this._univerInstanceService=i,this._threadCommentModel=s,this._interceptorViewModel(),this._initReRender()}_initReRender(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var n;if(e){this._docRenderController.reRender(e.unitId);return}const t=(n=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:n.getUnitId();t&&this._docRenderController.reRender(t)})),this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{e.type==="resolve"&&this._docRenderController.reRender(e.unitId)}))}_interceptorViewModel(){this._docInterceptorService.intercept(h.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION,{handler:(e,t,n)=>{if(!e)return n(e);const{unitId:r,index:i,customDecorations:s}=t,c=this._threadCommentPanelService.activeCommentId,{commentId:d,unitId:v}=c||{},l=s.find(f=>f.id===d),I=this._threadCommentModel.getComment(r,M,e.id);if(!I)return n({...e,show:!1});const D=l&&i>=l.startIndex&&i<=l.endIndex,g=v===r&&e.id===d;return n({...e,active:g||D,show:!I.resolved})}})}};$=Oe([o.OnLifecycle(o.LifecycleStages.Starting,$),R(1,u.Inject(h.DocInterceptorService)),R(2,u.Inject(_.ThreadCommentPanelService)),R(3,u.Inject(G.DocRenderController)),R(4,o.IUniverInstanceService),R(5,u.Inject(F.ThreadCommentModel))],$);var Q=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Te=(e,t,n)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Me=(e,t,n,r)=>{for(var i=r>1?void 0:r?De(t,n):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=(r?c(t,n,i):c(i))||i);return r&&i&&Q(t,n,i),i},k=(e,t)=>(n,r)=>t(n,r,e),ee=(e,t,n)=>Te(e,typeof t!="symbol"?t+"":t,n);a.UniverDocsThreadCommentUIPlugin=class extends o.Plugin{constructor(t={menu:{}},n,r){super(),this._config=t,this._injector=n,this._renderManagerSrv=r}onStarting(t){[[j,{useFactory:()=>this._injector.createInstance(j,this._config)}],[V],[b]].forEach(n=>{t.add(n)})}onRendered(){this._initRenderModule()}_initRenderModule(){[$].forEach(t=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,t)})}},ee(a.UniverDocsThreadCommentUIPlugin,"pluginName",re),ee(a.UniverDocsThreadCommentUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC),a.UniverDocsThreadCommentUIPlugin=Me([o.DependentOn(_.UniverThreadCommentUIPlugin),k(1,u.Inject(u.Injector)),k(2,U.IRenderManagerService)],a.UniverDocsThreadCommentUIPlugin),a.AddDocCommentComment=H,a.DeleteDocCommentComment=W,a.ShowCommentPanelOperation=P,a.StartAddCommentOperation=A,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "@univerjs/docs-thread-comment-ui",
3
+ "version": "0.2.0",
4
+ "private": false,
5
+ "description": "Univer thread comment plugin",
6
+ "author": "DreamNum <developer@univer.ai>",
7
+ "license": "Apache-2.0",
8
+ "funding": {
9
+ "type": "opencollective",
10
+ "url": "https://opencollective.com/univer"
11
+ },
12
+ "homepage": "https://univer.ai",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/dream-num/univer"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/dream-num/univer/issues"
19
+ },
20
+ "keywords": [],
21
+ "exports": {
22
+ ".": {
23
+ "import": "./lib/es/index.js",
24
+ "require": "./lib/cjs/index.js",
25
+ "types": "./lib/types/index.d.ts"
26
+ },
27
+ "./*": {
28
+ "import": "./lib/es/*",
29
+ "require": "./lib/cjs/*",
30
+ "types": "./lib/types/index.d.ts"
31
+ },
32
+ "./lib/*": "./lib/*"
33
+ },
34
+ "main": "./lib/cjs/index.js",
35
+ "module": "./lib/es/index.js",
36
+ "types": "./lib/types/index.d.ts",
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "directories": {
41
+ "lib": "lib"
42
+ },
43
+ "files": [
44
+ "lib"
45
+ ],
46
+ "peerDependencies": {
47
+ "@wendellhu/redi": "0.15.5",
48
+ "react": "^16.9.0 || ^17.0.0 || ^18.0.0",
49
+ "rxjs": ">=7.0.0",
50
+ "@univerjs/core": "0.2.0",
51
+ "@univerjs/docs": "0.2.0",
52
+ "@univerjs/docs-ui": "0.2.0",
53
+ "@univerjs/engine-render": "0.2.0",
54
+ "@univerjs/thread-comment": "0.2.0",
55
+ "@univerjs/thread-comment-ui": "0.2.0",
56
+ "@univerjs/ui": "0.2.0"
57
+ },
58
+ "dependencies": {
59
+ "@univerjs/icons": "^0.1.58"
60
+ },
61
+ "devDependencies": {
62
+ "@wendellhu/redi": "0.15.5",
63
+ "clsx": "^2.1.1",
64
+ "react": "18.3.1",
65
+ "rxjs": "^7.8.1",
66
+ "typescript": "^5.5.3",
67
+ "vite": "^5.3.3",
68
+ "vitest": "^1.6.0",
69
+ "@univerjs/core": "0.2.0",
70
+ "@univerjs/design": "0.2.0",
71
+ "@univerjs/engine-formula": "0.2.0",
72
+ "@univerjs/shared": "0.2.0",
73
+ "@univerjs/thread-comment": "0.2.0",
74
+ "@univerjs/ui": "0.2.0",
75
+ "@univerjs/thread-comment-ui": "0.2.0"
76
+ },
77
+ "univerSpace": {
78
+ ".": {
79
+ "import": "./lib/es/index.js",
80
+ "require": "./lib/cjs/index.js",
81
+ "types": "./lib/types/index.d.ts"
82
+ },
83
+ "./*": {
84
+ "import": "./lib/es/*",
85
+ "require": "./lib/cjs/*",
86
+ "types": "./lib/types/index.d.ts"
87
+ },
88
+ "./lib/*": "./lib/*"
89
+ },
90
+ "scripts": {
91
+ "test": "vitest run",
92
+ "test:watch": "vitest",
93
+ "coverage": "vitest run --coverage",
94
+ "lint:types": "tsc --noEmit",
95
+ "build": "tsc && vite build"
96
+ }
97
+ }