@univerjs/docs-thread-comment-ui 0.17.0 → 0.18.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.
@@ -1,5 +1,20 @@
1
- import { ICommand } from '@univerjs/core';
2
- import { ActiveCommentInfo } from '@univerjs/thread-comment-ui';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { ICommand } from '@univerjs/core';
17
+ import type { ActiveCommentInfo } from '@univerjs/thread-comment-ui';
3
18
  export interface IShowCommentPanelOperationParams {
4
19
  activeComment: ActiveCommentInfo;
5
20
  }
@@ -1,4 +1,19 @@
1
- import { MenuConfig } from '@univerjs/ui';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { MenuConfig } from '@univerjs/ui';
2
17
  export declare const DOCS_THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY = "docs-thread-comment-ui.config";
3
18
  export declare const configSymbol: unique symbol;
4
19
  export interface IUniverDocsThreadCommentUIConfig {
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
2
17
  import { IRenderManagerService } from '@univerjs/engine-render';
3
18
  import { ThreadCommentModel } from '@univerjs/thread-comment';
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { Disposable, ICommandService } from '@univerjs/core';
2
17
  import { ComponentManager, IMenuManagerService } from '@univerjs/ui';
3
18
  export declare class DocThreadCommentUIController extends Disposable {
@@ -1,5 +1,21 @@
1
- import { DocumentDataModel, Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
2
- import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { DocumentDataModel } from '@univerjs/core';
17
+ import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
18
+ import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
3
19
  import { DocInterceptorService } from '@univerjs/docs';
4
20
  import { DocRenderController } from '@univerjs/docs-ui';
5
21
  import { ThreadCommentModel } from '@univerjs/thread-comment';
@@ -1,5 +1,20 @@
1
- import { IAccessor } from '@univerjs/core';
2
- import { IMenuButtonItem } from '@univerjs/ui';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { IAccessor } from '@univerjs/core';
17
+ import type { IMenuButtonItem } from '@univerjs/ui';
3
18
  export declare const shouldDisableAddComment: (accessor: IAccessor) => boolean;
4
19
  export declare function AddDocCommentMenuItemFactory(accessor: IAccessor): IMenuButtonItem;
5
20
  export declare function ToolbarDocCommentMenuItemFactory(accessor: IAccessor): IMenuButtonItem;
@@ -1,2 +1,17 @@
1
- import { MenuSchemaType } from '@univerjs/ui';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { MenuSchemaType } from '@univerjs/ui';
2
17
  export declare const menuSchema: MenuSchemaType;
@@ -1,4 +1,19 @@
1
- import { IUniverDocsThreadCommentUIConfig } from './config/config';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { IUniverDocsThreadCommentUIConfig } from './config/config';
2
17
  import { IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
3
18
  import { IRenderManagerService } from '@univerjs/engine-render';
4
19
  export declare class UniverDocsThreadCommentUIPlugin extends Plugin {
@@ -1,12 +1,28 @@
1
- import { ITextRange, Nullable, Disposable } from '@univerjs/core';
2
- import { IThreadComment } from '@univerjs/thread-comment';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { ITextRange, Nullable } from '@univerjs/core';
17
+ import type { IThreadComment } from '@univerjs/thread-comment';
18
+ import { Disposable } from '@univerjs/core';
3
19
  import { ThreadCommentPanelService } from '@univerjs/thread-comment-ui';
4
20
  import { ISidebarService } from '@univerjs/ui';
5
21
  export declare class DocThreadCommentService extends Disposable {
6
22
  private readonly _sidebarService;
7
23
  private readonly _threadCommentPanelService;
8
24
  private _addingComment$;
9
- readonly addingComment$: import('rxjs').Observable<Nullable<IThreadComment & ITextRange>>;
25
+ readonly addingComment$: import("rxjs").Observable<Nullable<IThreadComment & ITextRange>>;
10
26
  get addingComment(): Nullable<IThreadComment & ITextRange>;
11
27
  constructor(_sidebarService: ISidebarService, _threadCommentPanelService: ThreadCommentPanelService);
12
28
  startAdd(comment: IThreadComment & ITextRange): void;
package/lib/umd/index.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/docs-ui"),require("@univerjs/thread-comment"),require("@univerjs/thread-comment-ui"),require("@univerjs/docs"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("rxjs"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-ui","@univerjs/thread-comment","@univerjs/thread-comment-ui","@univerjs/docs","@univerjs/engine-render","@univerjs/ui","rxjs","react/jsx-runtime","react"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.UniverDocsThreadCommentUi={},c.UniverCore,c.UniverDocsUi,c.UniverThreadComment,c.UniverThreadCommentUi,c.UniverDocs,c.UniverEngineRender,c.UniverUi,c.rxjs,c.React,c.React))})(this,(function(c,o,S,j,_,T,y,u,E,ie,D){"use strict";var Ue=Object.defineProperty;var ye=(c,o,S)=>o in c?Ue(c,o,{enumerable:!0,configurable:!0,writable:!0,value:S}):c[o]=S;var k=(c,o,S)=>ye(c,typeof o!="symbol"?o+"":o,S);const re="DOC_THREAD_COMMENT_UI_PLUGIN",M="default_doc",H={id:"docs.command.add-comment",type:o.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{comment:i,unitId:n}=t,s=await e.get(j.IThreadCommentDataSourceService).addComment(i),d=e.get(o.ICommandService),a=S.addCustomDecorationBySelectionFactory(e,{id:s.threadId,type:o.CustomDecorationType.COMMENT,unitId:n});if(a){const h={id:j.AddCommentMutation.id,params:{unitId:n,subUnitId:M,comment:s}},f={id:_.SetActiveCommentOperation.id,params:{unitId:n,subUnitId:M,commentId:s.id}};return(await o.sequenceExecute([h,a,f],d)).result}return!1}},L={id:"docs.command.delete-comment",type:o.CommandType.COMMAND,async handler(e,t){if(!t)return!1;const{commentId:i,unitId:n}=t,r=e.get(o.ICommandService),s=S.deleteCustomDecorationFactory(e,{id:i,unitId:n});return s?(await o.sequenceExecute([s],r)).result:!1}};var oe=Object.getOwnPropertyDescriptor,se=(e,t,i,n)=>{for(var r=n>1?void 0:n?oe(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},Y=(e,t)=>(i,n)=>t(i,n,e);let R=class extends o.Disposable{constructor(t,i){super();k(this,"_addingComment$",new E.BehaviorSubject(void 0));k(this,"addingComment$",this._addingComment$.asObservable());this._sidebarService=t,this._threadCommentPanelService=i,this.disposeWithMe(()=>{this._addingComment$.complete()})}get addingComment(){return this._addingComment$.getValue()}startAdd(t){this._addingComment$.next(t)}endAdd(){this._addingComment$.next(void 0)}};R=se([Y(0,u.ISidebarService),Y(1,o.Inject(_.ThreadCommentPanelService))],R);const z=e=>{var d;const t=e.get(y.IRenderManagerService),i=e.get(T.DocSelectionManagerService),n=(d=y.withCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_DOC,T.DocSkeletonManagerService,e.get(o.IUniverInstanceService),t))==null?void 0:d.getSkeleton(),r=n==null?void 0:n.getViewModel().getEditArea();if(r===y.DocumentEditArea.FOOTER||r===y.DocumentEditArea.HEADER)return!0;const s=i.getActiveTextRange();return!!(s==null||s.collapsed)};function de(e){return{id:w.id,type:u.MenuItemType.BUTTON,icon:"CommentIcon",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:u.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC,void 0,o.SHEET_EDITOR_UNITS),disabled$:new E.Observable(function(t){const n=e.get(T.DocSelectionManagerService).textSelection$.pipe(E.debounceTime(16)).subscribe(()=>{t.next(z(e))});return()=>{n.unsubscribe()}})}}function ae(e){return{id:W.id,type:u.MenuItemType.BUTTON,icon:"CommentIcon",title:"threadCommentUI.panel.addComment",tooltip:"threadCommentUI.panel.addComment",hidden$:u.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC)}}const b=()=>{const e=u.useDependency(o.IUniverInstanceService),t=u.useDependency(o.Injector),i=D.useMemo(()=>e.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_DOC).pipe(E.filter(m=>!!m&&!o.isInternalEditorID(m.getUnitId()))),[e]),n=u.useObservable(i),r=D.useMemo(()=>new E.Observable(m=>m.next(M)),[]),s=u.useDependency(T.DocSelectionManagerService),d=D.useMemo(()=>s.textSelection$.pipe(E.debounceTime(16)),[s.textSelection$]);u.useObservable(d);const a=u.useDependency(o.ICommandService),h=u.useDependency(R),f=u.useObservable(h.addingComment$),[l,I]=D.useState([]);if(D.useEffect(()=>{var A;const m=new Set,C=n==null?void 0:n.getCustomDecorations();I((A=C==null?void 0:C.map(v=>v.id).filter(v=>{const U=m.has(v);return m.add(v),!U}))!=null?A:[]);const O=a.onCommandExecuted(v=>{var U;if(v.id===T.RichTextEditingMutation.id){const N=new Set,J=n==null?void 0:n.getCustomDecorations();I((U=J==null?void 0:J.map(F=>F.id).filter(F=>{const Oe=N.has(F);return N.add(F),!Oe}))!=null?U:[])}});return()=>{O.dispose()}},[a,n]),!n)return null;const p=z(t),g=n.getUnitId();return ie.jsx(_.ThreadCommentPanel,{unitId:g,subUnitId$:r,type:o.UniverInstanceType.UNIVER_DOC,onAdd:()=>{a.executeCommand(w.id)},getSubUnitName:()=>"",disableAdd:p,tempComment:f,onAddComment:m=>{if(!m.parentId){const C={unitId:g,range:f,comment:m};return a.executeCommand(H.id,C),h.endAdd(),!1}return!0},onDeleteComment:m=>{if(!m.parentId){const C={unitId:g,commentId:m.id};return a.executeCommand(L.id,C),!1}return!0},showComments:l})};b.componentKey="univer.doc.thread-comment-panel";const $={id:"docs.operation.show-comment-panel",type:o.CommandType.OPERATION,handler(e,t){var r;const i=e.get(_.ThreadCommentPanelService),n=e.get(u.ISidebarService);return(!i.panelVisible||((r=n.options.children)==null?void 0:r.label)!==b.componentKey)&&(n.open({header:{title:"threadCommentUI.panel.title"},children:{label:b.componentKey},width:320,onClose:()=>i.setPanelVisible(!1)}),i.setPanelVisible(!0)),t&&i.setActiveComment(t==null?void 0:t.activeComment),!0}},W={id:"docs.operation.toggle-comment-panel",type:o.CommandType.OPERATION,handler(e){var n;const t=e.get(_.ThreadCommentPanelService),i=e.get(u.ISidebarService);return!t.panelVisible||((n=i.options.children)==null?void 0:n.label)!==b.componentKey?(i.open({header:{title:"threadCommentUI.panel.title"},children:{label:b.componentKey},width:320,onClose:()=>t.setPanelVisible(!1)}),t.setPanelVisible(!0)):(i.close(),t.setPanelVisible(!1),t.setActiveComment(null)),!0}},w={id:"docs.operation.start-add-comment",type:o.CommandType.OPERATION,handler(e){var v,U,N;const t=e.get(_.ThreadCommentPanelService),n=e.get(o.IUniverInstanceService).getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC),r=e.get(T.DocSelectionManagerService),s=e.get(y.IRenderManagerService),d=e.get(o.UserManagerService),a=e.get(R),h=e.get(o.ICommandService),f=e.get(u.ISidebarService),l=r.getActiveTextRange();if(!n||!l)return!1;const I=(v=s.getRenderById(n.getUnitId()))==null?void 0:v.with(S.DocSelectionRenderService);if(I==null||I.setReserveRangesStatus(!0),l.collapsed)return t.panelVisible?(t.setPanelVisible(!1),f.close()):h.executeCommand($.id),!0;h.executeCommand($.id);const p=n.getUnitId(),g=((N=(U=n.getBody())==null?void 0:U.dataStream)!=null?N:"").slice(l.startOffset,l.endOffset),m=o.BuildTextUtils.transform.getPlainText(g),C=M,O="",A={unitId:p,subUnitId:C,id:O,ref:m,dT:j.getDT(),personId:d.getCurrentUser().userID,text:{dataStream:`\r
2
- `},startOffset:l.startOffset,endOffset:l.endOffset,collapsed:!0,threadId:O};return I==null||I.blur(),a.startAdd(A),t.setActiveComment({unitId:p,subUnitId:C,commentId:O}),!0}},Q={name:"@univerjs/docs-thread-comment-ui",version:"0.17.0"},ce="docs-thread-comment-ui.config",X={};var me=Object.getOwnPropertyDescriptor,le=(e,t,i,n)=>{for(var r=n>1?void 0:n?me(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},P=(e,t)=>(i,n)=>t(i,n,e);let V=class extends o.Disposable{constructor(e,t,i,n,r,s){super(),this._threadCommentPanelService=e,this._univerInstanceService=t,this._commandService=i,this._docThreadCommentService=n,this._renderManagerService=r,this._threadCommentModel=s,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){let e;this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var i,n,r,s;if(t.id===T.SetTextSelectionsOperation.id){const d=t.params,{unitId:a,ranges:h}=d;if(o.isInternalEditorID(a))return;const f=this._univerInstanceService.getUnit(a,o.UniverInstanceType.UNIVER_DOC),l=h[0];if((e==null?void 0:e.startOffset)===(l==null?void 0:l.startOffset)&&(e==null?void 0:e.endOffset)===(l==null?void 0:l.endOffset))return;if(e=l,l&&f){const{startOffset:I,endOffset:p,collapsed:g}=l;let m;if(g?m=(n=(i=f.getBody())==null?void 0:i.customDecorations)==null?void 0:n.find(C=>C.startIndex<=I&&C.endIndex>=p-1):m=(s=(r=f.getBody())==null?void 0:r.customDecorations)==null?void 0:s.find(C=>C.startIndex<=I&&C.endIndex>=p-1),m){const C=this._threadCommentModel.getComment(a,M,m.id);C&&!C.resolved&&this._commandService.executeCommand($.id,{activeComment:{unitId:a,subUnitId:M,commentId:m.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(_.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var t,i,n,r;if(e){const s=this._univerInstanceService.getUnit(e.unitId);if(s){const d=(t=this._renderManagerService.getRenderById(e.unitId))==null?void 0:t.with(S.DocBackScrollRenderController),a=(n=(i=s.getBody())==null?void 0:i.customDecorations)==null?void 0:n.find(h=>h.id===e.commentId);a&&d&&d.scrollToRange({startOffset:a.startIndex,endOffset:a.endIndex,collapsed:!1})}}(!e||e.commentId!==((r=this._docThreadCommentService.addingComment)==null?void 0:r.id))&&this._docThreadCommentService.endAdd()}))}};V=le([P(0,o.Inject(_.ThreadCommentPanelService)),P(1,o.IUniverInstanceService),P(2,o.ICommandService),P(3,o.Inject(R)),P(4,y.IRenderManagerService),P(5,o.Inject(j.ThreadCommentModel))],V);function ee({ref:e,...t}){const{icon:i,id:n,className:r,extend:s,...d}=t,a=`univerjs-icon univerjs-icon-${n} ${r||""}`.trim(),h=D.useRef(`_${he()}`);return te(i,`${n}`,{defIds:i.defIds,idSuffix:h.current},{ref:e,className:a,...d},s)}function te(e,t,i,n,r){return D.createElement(e.tag,{key:t,...ue(e,i,r),...n},(Ce(e,i).children||[]).map((s,d)=>te(s,`${t}-${e.tag}-${d}`,i,void 0,r)))}function ue(e,t,i){const n={...e.attrs};i!=null&&i.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=i.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(([s,d])=>{s==="mask"&&typeof d=="string"&&(n[s]=d.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:r}=t;return!r||r.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(([s,d])=>{typeof d=="string"&&(n[s]=d.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),n}function Ce(e,t){var n;const{defIds:i}=t;return!i||i.length===0?e:e.tag==="defs"&&((n=e.children)!=null&&n.length)?{...e,children:e.children.map(r=>typeof r.attrs.id=="string"&&i&&i.includes(r.attrs.id)?{...r,attrs:{...r.attrs,id:r.attrs.id+t.idSuffix}}:r)}:e}function he(){return Math.random().toString(36).substring(2,8)}ee.displayName="UniverIcon";const ve={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M8.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.78345Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M11.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"}},{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"}}]},ne=D.forwardRef(function(t,i){return D.createElement(ee,Object.assign({},t,{id:"comment-icon",ref:i,icon:ve}))});ne.displayName="CommentIcon";const fe={[u.RibbonInsertGroup.MEDIA]:{[W.id]:{order:3,menuItemFactory:ae}},[u.ContextMenuPosition.MAIN_AREA]:{[u.ContextMenuGroup.DATA]:{[w.id]:{order:1,menuItemFactory:de}}}};var Ie=Object.getOwnPropertyDescriptor,ge=(e,t,i,n)=>{for(var r=n>1?void 0:n?Ie(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},Z=(e,t)=>(i,n)=>t(i,n,e);let B=class extends o.Disposable{constructor(e,t,i){super(),this._commandService=e,this._menuManagerService=t,this._componentManager=i,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[H,L,$,w,W].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(fe)}_initComponents(){[[b.componentKey,b],["CommentIcon",ne]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};B=ge([Z(0,o.ICommandService),Z(1,u.IMenuManagerService),Z(2,o.Inject(u.ComponentManager))],B);var pe=Object.getOwnPropertyDescriptor,Se=(e,t,i,n)=>{for(var r=n>1?void 0:n?pe(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},x=(e,t)=>(i,n)=>t(i,n,e);let K=class extends o.Disposable{constructor(e,t,i,n,r,s,d){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=i,this._docRenderController=n,this._univerInstanceService=r,this._threadCommentModel=s,this._commandService=d,this._interceptorViewModel(),this._initReRender(),this._initSyncComments()}_initReRender(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var i;if(e){this._docRenderController.reRender(e.unitId);return}const t=(i=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:i.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(T.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION,{handler:(e,t,i)=>{if(!e)return i(e);const{unitId:n,index:r,customDecorations:s}=t,d=this._threadCommentPanelService.activeCommentId,{commentId:a,unitId:h}=d||{},f=s.find(g=>g.id===a),l=this._threadCommentModel.getComment(n,M,e.id);if(!l)return i({...e,show:!1});const I=f&&r>=f.startIndex&&r<=f.endIndex,p=h===n&&e.id===a;return i({...e,active:p||I,show:!l.resolved})}})}_initSyncComments(){var r,s,d;const e=this._context.unit.getUnitId(),t=M,i=(d=(s=(r=this._context.unit.getBody())==null?void 0:r.customDecorations)==null?void 0:s.filter(a=>a.type===o.CustomDecorationType.COMMENT).map(a=>a.id))!=null?d:[];i.forEach(a=>{this._threadCommentModel.getComment(e,t,a)||this._threadCommentModel.addComment(e,t,{id:a,threadId:a,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),i.length&&this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(),M,i);let n=i.sort();this.disposeWithMe(this._commandService.onCommandExecuted(a=>{var h,f,l;if(a.id===T.RichTextEditingMutation.id){if(a.params.unitId!==this._context.unit.getUnitId())return;const p=(l=(f=(h=this._context.unit.getBody())==null?void 0:h.customDecorations)==null?void 0:f.filter(m=>m.type===o.CustomDecorationType.COMMENT).map(m=>m.id))!=null?l:[],g=p.sort();if(JSON.stringify(n)!==JSON.stringify(g)){const m=new Set(n),C=new Set(g),O=new Set,A=new Set;p.forEach(v=>{m.has(v)||O.add(v)}),n.forEach(v=>{C.has(v)||A.add(v)}),n=g,O.forEach(v=>{this._threadCommentModel.getComment(e,t,v)||this._threadCommentModel.addComment(e,t,{id:v,threadId:v,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),this._threadCommentModel.syncThreadComments(e,t,[...O])}}}))}};K=Se([x(1,o.Inject(T.DocInterceptorService)),x(2,o.Inject(_.ThreadCommentPanelService)),x(3,o.Inject(S.DocRenderController)),x(4,o.IUniverInstanceService),x(5,o.Inject(j.ThreadCommentModel)),x(6,o.ICommandService)],K);var _e=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,De=(e,t,i)=>t in e?_e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Me=(e,t,i,n)=>{for(var r=n>1?void 0:n?Te(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},G=(e,t)=>(i,n)=>t(i,n,e),q=(e,t,i)=>De(e,typeof t!="symbol"?t+"":t,i);c.UniverDocsThreadCommentUIPlugin=class extends o.Plugin{constructor(t=X,i,n,r){super(),this._config=t,this._injector=i,this._renderManagerSrv=n,this._configService=r;const{menu:s,...d}=o.merge({},X,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(ce,d)}onStarting(){[[B],[V],[R]].forEach(t=>{this._injector.add(t)})}onRendered(){this._initRenderModule(),this._injector.get(V),this._injector.get(B)}_initRenderModule(){[K].forEach(t=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,t)})}},q(c.UniverDocsThreadCommentUIPlugin,"pluginName",re),q(c.UniverDocsThreadCommentUIPlugin,"packageName",Q.name),q(c.UniverDocsThreadCommentUIPlugin,"version",Q.version),q(c.UniverDocsThreadCommentUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC),c.UniverDocsThreadCommentUIPlugin=Me([o.DependentOn(_.UniverThreadCommentUIPlugin),G(1,o.Inject(o.Injector)),G(2,y.IRenderManagerService),G(3,o.IConfigService)],c.UniverDocsThreadCommentUIPlugin),c.AddDocCommentComment=H,c.DeleteDocCommentComment=L,c.ShowCommentPanelOperation=$,c.StartAddCommentOperation=w,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/docs-ui`),require(`@univerjs/thread-comment`),require(`@univerjs/thread-comment-ui`),require(`@univerjs/docs`),require(`@univerjs/engine-render`),require(`@univerjs/ui`),require(`rxjs`),require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs-ui`,`@univerjs/thread-comment`,`@univerjs/thread-comment-ui`,`@univerjs/docs`,`@univerjs/engine-render`,`@univerjs/ui`,`rxjs`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsThreadCommentUi={},e.UniverCore,e.UniverDocsUi,e.UniverThreadComment,e.UniverThreadCommentUi,e.UniverDocs,e.UniverEngineRender,e.UniverUi,e.rxjs,e.React,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let d=`default_doc`,f={id:`docs.command.add-comment`,type:t.CommandType.COMMAND,async handler(e,a){if(!a)return!1;let{comment:o,unitId:s}=a,c=await e.get(r.IThreadCommentDataSourceService).addComment(o),l=e.get(t.ICommandService),u=(0,n.addCustomDecorationBySelectionFactory)(e,{id:c.threadId,type:t.CustomDecorationType.COMMENT,unitId:s});return u?(await(0,t.sequenceExecute)([{id:r.AddCommentMutation.id,params:{unitId:s,subUnitId:d,comment:c}},u,{id:i.SetActiveCommentOperation.id,params:{unitId:s,subUnitId:d,commentId:c.id}}],l)).result:!1}},p={id:`docs.command.delete-comment`,type:t.CommandType.COMMAND,async handler(e,r){if(!r)return!1;let{commentId:i,unitId:a}=r,o=e.get(t.ICommandService),s=(0,n.deleteCustomDecorationFactory)(e,{id:i,unitId:a});return s?(await(0,t.sequenceExecute)([s],o)).result:!1}};function m(e){"@babel/helpers - typeof";return m=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},m(e)}function h(e,t){if(m(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(m(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function g(e){var t=h(e,`string`);return m(t)==`symbol`?t:t+``}function _(e,t,n){return(t=g(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function v(e,t){return function(n,r){t(n,r,e)}}function y(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 b=class extends t.Disposable{get addingComment(){return this._addingComment$.getValue()}constructor(e,t){super(),this._sidebarService=e,this._threadCommentPanelService=t,_(this,`_addingComment$`,new c.BehaviorSubject(void 0)),_(this,`addingComment$`,this._addingComment$.asObservable()),this.disposeWithMe(()=>{this._addingComment$.complete()})}startAdd(e){this._addingComment$.next(e)}endAdd(){this._addingComment$.next(void 0)}};b=y([v(0,s.ISidebarService),v(1,(0,t.Inject)(i.ThreadCommentPanelService))],b);let x=e=>{var n;let r=e.get(o.IRenderManagerService),i=e.get(a.DocSelectionManagerService),s=(n=(0,o.withCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_DOC,a.DocSkeletonManagerService,e.get(t.IUniverInstanceService),r))==null?void 0:n.getSkeleton(),c=s==null?void 0:s.getViewModel().getEditArea();if(c===o.DocumentEditArea.FOOTER||c===o.DocumentEditArea.HEADER)return!0;let l=i.getActiveTextRange();return!!(l==null||l.collapsed)};function S(e){return{id:D.id,type:s.MenuItemType.BUTTON,icon:`CommentIcon`,title:`threadCommentUI.panel.addComment`,tooltip:`threadCommentUI.panel.addComment`,hidden$:(0,s.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_DOC,void 0,t.SHEET_EDITOR_UNITS),disabled$:new c.Observable(function(t){let n=e.get(a.DocSelectionManagerService).textSelection$.pipe((0,c.debounceTime)(16)).subscribe(()=>{t.next(x(e))});return()=>{n.unsubscribe()}})}}function C(e){return{id:E.id,type:s.MenuItemType.BUTTON,icon:`CommentIcon`,title:`threadCommentUI.panel.addComment`,tooltip:`threadCommentUI.panel.addComment`,hidden$:(0,s.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_DOC)}}let w=()=>{let e=(0,s.useDependency)(t.IUniverInstanceService),n=(0,s.useDependency)(t.Injector),r=(0,s.useObservable)((0,l.useMemo)(()=>e.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).pipe((0,c.filter)(e=>!!e&&!(0,t.isInternalEditorID)(e.getUnitId()))),[e])),o=(0,l.useMemo)(()=>new c.Observable(e=>e.next(d)),[]),m=(0,s.useDependency)(a.DocSelectionManagerService);(0,s.useObservable)((0,l.useMemo)(()=>m.textSelection$.pipe((0,c.debounceTime)(16)),[m.textSelection$]));let h=(0,s.useDependency)(t.ICommandService),g=(0,s.useDependency)(b),_=(0,s.useObservable)(g.addingComment$),[v,y]=(0,l.useState)([]);if((0,l.useEffect)(()=>{var e;let t=new Set,n=r==null?void 0:r.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 i=h.onCommandExecuted(e=>{if(e.id===a.RichTextEditingMutation.id){var t;let e=new Set,n=r==null?void 0:r.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()=>{i.dispose()}},[h,r]),!r)return null;let S=x(n),C=r.getUnitId();return(0,u.jsx)(i.ThreadCommentPanel,{unitId:C,subUnitId$:o,type:t.UniverInstanceType.UNIVER_DOC,onAdd:()=>{h.executeCommand(D.id)},getSubUnitName:()=>``,disableAdd:S,tempComment:_,onAddComment:e=>{if(!e.parentId){let t={unitId:C,range:_,comment:e};return h.executeCommand(f.id,t),g.endAdd(),!1}return!0},onDeleteComment:e=>{if(!e.parentId){let t={unitId:C,commentId:e.id};return h.executeCommand(p.id,t),!1}return!0},showComments:v})};w.componentKey=`univer.doc.thread-comment-panel`;let T={id:`docs.operation.show-comment-panel`,type:t.CommandType.OPERATION,handler(e,t){var n;let r=e.get(i.ThreadCommentPanelService),a=e.get(s.ISidebarService);return(!r.panelVisible||((n=a.options.children)==null?void 0:n.label)!==w.componentKey)&&(a.open({header:{title:`threadCommentUI.panel.title`},children:{label:w.componentKey},width:320,onClose:()=>r.setPanelVisible(!1)}),r.setPanelVisible(!0)),t&&r.setActiveComment(t==null?void 0:t.activeComment),!0}},E={id:`docs.operation.toggle-comment-panel`,type:t.CommandType.OPERATION,handler(e){var t;let n=e.get(i.ThreadCommentPanelService),r=e.get(s.ISidebarService);return!n.panelVisible||((t=r.options.children)==null?void 0:t.label)!==w.componentKey?(r.open({header:{title:`threadCommentUI.panel.title`},children:{label:w.componentKey},width:320,onClose:()=>n.setPanelVisible(!1)}),n.setPanelVisible(!0)):(r.close(),n.setPanelVisible(!1),n.setActiveComment(null)),!0}},D={id:`docs.operation.start-add-comment`,type:t.CommandType.OPERATION,handler(e){var c,l,u;let f=e.get(i.ThreadCommentPanelService),p=e.get(t.IUniverInstanceService).getCurrentUnitForType(t.UniverInstanceType.UNIVER_DOC),m=e.get(a.DocSelectionManagerService),h=e.get(o.IRenderManagerService),g=e.get(t.UserManagerService),_=e.get(b),v=e.get(t.ICommandService),y=e.get(s.ISidebarService),x=m.getActiveTextRange();if(!p||!x)return!1;let S=(c=h.getRenderById(p.getUnitId()))==null?void 0:c.with(n.DocSelectionRenderService);if(S==null||S.setReserveRangesStatus(!0),x.collapsed)return f.panelVisible?(f.setPanelVisible(!1),y.close()):v.executeCommand(T.id),!0;v.executeCommand(T.id);let C=p.getUnitId(),w=((l=(u=p.getBody())==null?void 0:u.dataStream)==null?``:l).slice(x.startOffset,x.endOffset),E=t.BuildTextUtils.transform.getPlainText(w),D=d,O={unitId:C,subUnitId:D,id:``,ref:E,dT:(0,r.getDT)(),personId:g.getCurrentUser().userID,text:{dataStream:`\r
2
+ `},startOffset:x.startOffset,endOffset:x.endOffset,collapsed:!0,threadId:``};return S==null||S.blur(),_.startAdd(O),f.setActiveComment({unitId:C,subUnitId:D,commentId:``}),!0}};var O=`@univerjs/docs-thread-comment-ui`,k=`0.18.0`;let A=`docs-thread-comment-ui.config`;Symbol(A);let j={},M=class extends t.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 e;this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===a.SetTextSelectionsOperation.id){let{unitId:a,ranges:s}=n.params;if((0,t.isInternalEditorID)(a))return;let c=this._univerInstanceService.getUnit(a,t.UniverInstanceType.UNIVER_DOC),l=s[0];if((e==null?void 0:e.startOffset)===(l==null?void 0:l.startOffset)&&(e==null?void 0:e.endOffset)===(l==null?void 0:l.endOffset))return;if(e=l,l&&c){let{startOffset:e,endOffset:t,collapsed:n}=l,i;if(n){var r;i=(r=c.getBody())==null||(r=r.customDecorations)==null?void 0:r.find(n=>n.startIndex<=e&&n.endIndex>=t-1)}else{var o;i=(o=c.getBody())==null||(o=o.customDecorations)==null?void 0:o.find(n=>n.startIndex<=e&&n.endIndex>=t-1)}if(i){let e=this._threadCommentModel.getComment(a,d,i.id);e&&!e.resolved&&this._commandService.executeCommand(T.id,{activeComment:{unitId:a,subUnitId:d,commentId:i.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(i.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var t;if(e){let t=this._univerInstanceService.getUnit(e.unitId);if(t){var r,i;let a=(r=this._renderManagerService.getRenderById(e.unitId))==null?void 0:r.with(n.DocBackScrollRenderController),o=(i=t.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!==((t=this._docThreadCommentService.addingComment)==null?void 0:t.id))&&this._docThreadCommentService.endAdd()}))}};M=y([v(0,(0,t.Inject)(i.ThreadCommentPanelService)),v(1,t.IUniverInstanceService),v(2,t.ICommandService),v(3,(0,t.Inject)(b)),v(4,o.IRenderManagerService),v(5,(0,t.Inject)(r.ThreadCommentModel))],M);function N({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),c=(0,l.useRef)(`_${L()}`);return P(n,`${r}`,{defIds:n.defIds,idSuffix:c.current},{ref:e,className:s,...o},a)}function P(e,t,n,r,i){return(0,l.createElement)(e.tag,{key:t,...F(e,n,i),...r},(I(e,n).children||[]).map((r,a)=>P(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function F(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function I(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function L(){return Math.random().toString(36).substring(2,8)}N.displayName=`UniverIcon`;let R={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,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.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.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.78345Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M11.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`}},{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`}}]},z=(0,l.forwardRef)(function(e,t){return(0,l.createElement)(N,Object.assign({},e,{id:`comment-icon`,ref:t,icon:R}))});z.displayName=`CommentIcon`;let B={[s.RibbonInsertGroup.MEDIA]:{[E.id]:{order:3,menuItemFactory:C}},[s.ContextMenuPosition.MAIN_AREA]:{[s.ContextMenuGroup.DATA]:{[D.id]:{order:1,menuItemFactory:S}}}},V=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._menuManagerService=t,this._componentManager=n,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[f,p,T,D,E].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(B)}_initComponents(){[[w.componentKey,w],[`CommentIcon`,z]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};V=y([v(0,t.ICommandService),v(1,s.IMenuManagerService),v(2,(0,t.Inject)(s.ComponentManager))],V);let H=class extends t.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(e=>{var n;if(e){this._docRenderController.reRender(e.unitId);return}let r=(n=this._univerInstanceService.getCurrentUnitForType(t.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(a.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,d,e.id);if(!l)return n({...e,show:!1});let u=c&&i>=c.startIndex&&i<=c.endIndex,f=s===r&&e.id===o;return n({...e,active:f||u,show:!l.resolved})}})}_initSyncComments(){var e,n;let r=this._context.unit.getUnitId(),i=d,o=(e=(n=this._context.unit.getBody())==null||(n=n.customDecorations)==null?void 0:n.filter(e=>e.type===t.CustomDecorationType.COMMENT).map(e=>e.id))==null?[]:e;o.forEach(e=>{this._threadCommentModel.getComment(r,i,e)||this._threadCommentModel.addComment(r,i,{id:e,threadId:e,ref:``,dT:``,personId:``,text:{dataStream:``},unitId:r,subUnitId:i})}),o.length&&this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(),`default_doc`,o);let s=o.sort();this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===a.RichTextEditingMutation.id){var n,o;if(e.params.unitId!==this._context.unit.getUnitId())return;let a=(n=(o=this._context.unit.getBody())==null||(o=o.customDecorations)==null?void 0:o.filter(e=>e.type===t.CustomDecorationType.COMMENT).map(e=>e.id))==null?[]:n,c=a.sort();if(JSON.stringify(s)!==JSON.stringify(c)){let e=new Set(s),t=new Set(c),n=new Set,o=new Set;a.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,i,e)||this._threadCommentModel.addComment(r,i,{id:e,threadId:e,ref:``,dT:``,personId:``,text:{dataStream:``},unitId:r,subUnitId:i})}),this._threadCommentModel.syncThreadComments(r,i,[...n])}}}))}};H=y([v(1,(0,t.Inject)(a.DocInterceptorService)),v(2,(0,t.Inject)(i.ThreadCommentPanelService)),v(3,(0,t.Inject)(n.DocRenderController)),v(4,t.IUniverInstanceService),v(5,(0,t.Inject)(r.ThreadCommentModel)),v(6,t.ICommandService)],H);let U=class extends t.Plugin{constructor(e=j,n,r,i){super(),this._config=e,this._injector=n,this._renderManagerSrv=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},j,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(A,o)}onStarting(){[[V],[M],[b]].forEach(e=>{this._injector.add(e)})}onRendered(){this._initRenderModule(),this._injector.get(M),this._injector.get(V)}_initRenderModule(){[H].forEach(e=>{this._renderManagerSrv.registerRenderModule(t.UniverInstanceType.UNIVER_DOC,e)})}};_(U,`pluginName`,`DOC_THREAD_COMMENT_UI_PLUGIN`),_(U,`packageName`,O),_(U,`version`,k),_(U,`type`,t.UniverInstanceType.UNIVER_DOC),U=y([(0,t.DependentOn)(i.UniverThreadCommentUIPlugin),v(1,(0,t.Inject)(t.Injector)),v(2,o.IRenderManagerService),v(3,t.IConfigService)],U),e.AddDocCommentComment=f,e.DeleteDocCommentComment=p,e.ShowCommentPanelOperation=T,e.StartAddCommentOperation=D,Object.defineProperty(e,`UniverDocsThreadCommentUIPlugin`,{enumerable:!0,get:function(){return U}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/docs-thread-comment-ui",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "private": false,
5
5
  "description": "Univer thread comment plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -48,13 +48,13 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@univerjs/icons": "^1.1.1",
51
- "@univerjs/core": "0.17.0",
52
- "@univerjs/docs": "0.17.0",
53
- "@univerjs/docs-ui": "0.17.0",
54
- "@univerjs/engine-render": "0.17.0",
55
- "@univerjs/thread-comment": "0.17.0",
56
- "@univerjs/thread-comment-ui": "0.17.0",
57
- "@univerjs/ui": "0.17.0"
51
+ "@univerjs/core": "0.18.0",
52
+ "@univerjs/docs": "0.18.0",
53
+ "@univerjs/docs-ui": "0.18.0",
54
+ "@univerjs/thread-comment": "0.18.0",
55
+ "@univerjs/engine-render": "0.18.0",
56
+ "@univerjs/ui": "0.18.0",
57
+ "@univerjs/thread-comment-ui": "0.18.0"
58
58
  },
59
59
  "devDependencies": {
60
60
  "postcss": "^8.5.8",
@@ -62,16 +62,17 @@
62
62
  "rxjs": "^7.8.2",
63
63
  "tailwindcss": "3.4.18",
64
64
  "typescript": "^5.9.3",
65
- "vite": "^7.3.1",
66
- "vitest": "^4.0.18",
67
- "@univerjs-infra/shared": "0.17.0"
65
+ "vitest": "^4.1.0",
66
+ "@univerjs-infra/shared": "0.18.0"
68
67
  },
69
68
  "scripts": {
70
69
  "test": "vitest run",
71
70
  "test:watch": "vitest",
72
71
  "coverage": "vitest run --coverage",
73
72
  "typecheck": "tsc --noEmit",
74
- "build": "univer-cli build"
73
+ "build:bundle": "univer-cli build",
74
+ "build:types": "tsc -p tsconfig.node.json",
75
+ "build": "pnpm run build:bundle && pnpm run build:types"
75
76
  },
76
77
  "module": "./lib/es/index.js"
77
78
  }