@univerjs/docs-thread-comment-ui 0.10.12 → 0.10.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +311 -261
- package/lib/index.js +311 -261
- package/lib/umd/index.js +2 -2
- package/package.json +10 -10
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,_,
|
|
2
|
-
`},startOffset:l.startOffset,endOffset:l.endOffset,collapsed:!0,threadId:y};return I==null||I.blur(),d.startAdd(w),t.setActiveComment({unitId:S,subUnitId:v,commentId:y}),!0}},ce="docs-thread-comment-ui.config",Q={};var me=Object.getOwnPropertyDescriptor,le=(e,t,r,n)=>{for(var i=n>1?void 0:n?me(t,r):t,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=a(i)||i);return i},P=(e,t)=>(r,n)=>t(r,n,e);let B=class extends o.Disposable{constructor(e,t,r,n,i,s){super(),this._threadCommentPanelService=e,this._univerInstanceService=t,this._commandService=r,this._docThreadCommentService=n,this._renderManagerService=i,this._threadCommentModel=s,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){let e;this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var r,n,i,s;if(t.id===T.SetTextSelectionsOperation.id){const a=t.params,{unitId:d,ranges:C}=a;if(o.isInternalEditorID(d))return;const h=this._univerInstanceService.getUnit(d,o.UniverInstanceType.UNIVER_DOC),l=C[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&&h){const{startOffset:I,endOffset:S,collapsed:g}=l;let m;if(g?m=(n=(r=h.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(v=>v.startIndex<=I&&v.endIndex>=S-1):m=(s=(i=h.getBody())==null?void 0:i.customDecorations)==null?void 0:s.find(v=>v.startIndex<=I&&v.endIndex>=S-1),m){const v=this._threadCommentModel.getComment(d,M,m.id);v&&!v.resolved&&this._commandService.executeCommand(N.id,{activeComment:{unitId:d,subUnitId:M,commentId:m.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(O.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var t,r,n,i;if(e){const s=this._univerInstanceService.getUnit(e.unitId);if(s){const a=(t=this._renderManagerService.getRenderById(e.unitId))==null?void 0:t.with(_.DocBackScrollRenderController),d=(n=(r=s.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(C=>C.id===e.commentId);d&&a&&a.scrollToRange({startOffset:d.startIndex,endOffset:d.endIndex,collapsed:!1})}}(!e||e.commentId!==((i=this._docThreadCommentService.addingComment)==null?void 0:i.id))&&this._docThreadCommentService.endAdd()}))}};B=le([P(0,o.Inject(O.ThreadCommentPanelService)),P(1,o.IUniverInstanceService),P(2,o.ICommandService),P(3,o.Inject(R)),P(4,U.IRenderManagerService),P(5,o.Inject(A.ThreadCommentModel))],B);var p=function(){return p=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},p.apply(this,arguments)},ue=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r},X=D.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,s=e.extend,a=ue(e,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),C=D.useRef("_".concat(fe()));return ee(r,"".concat(n),{defIds:r.defIds,idSuffix:C.current},p({ref:t,className:d},a),s)});function ee(e,t,r,n,i){return D.createElement(e.tag,p(p({key:t},ve(e,r,i)),n),(Ce(e,r).children||[]).map(function(s,a){return ee(s,"".concat(t,"-").concat(e.tag,"-").concat(a),r,void 0,i)}))}function ve(e,t,r){var n=p({},e.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(s){var a=s[0],d=s[1];a==="mask"&&typeof d=="string"&&(n[a]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(s){var a=s[0],d=s[1];typeof d=="string"&&(n[a]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Ce(e,t){var r,n=t.defIds;return!n||n.length===0?e:e.tag==="defs"&&(!((r=e.children)===null||r===void 0)&&r.length)?p(p({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.includes(i.attrs.id)?p(p({},i),{attrs:p(p({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function fe(){return Math.random().toString(36).substring(2,8)}X.displayName="UniverIcon";var he={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"}}]},te=D.forwardRef(function(e,t){return D.createElement(X,Object.assign({},e,{id:"comment-icon",ref:t,icon:he}))});te.displayName="CommentIcon";const Ie={[u.RibbonInsertGroup.MEDIA]:{[W.id]:{order:3,menuItemFactory:de}},[u.ContextMenuPosition.MAIN_AREA]:{[u.ContextMenuGroup.DATA]:{[V.id]:{order:1,menuItemFactory:ae}}}};var ge=Object.getOwnPropertyDescriptor,pe=(e,t,r,n)=>{for(var i=n>1?void 0:n?ge(t,r):t,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=a(i)||i);return i},Z=(e,t)=>(r,n)=>t(r,n,e);let q=class extends o.Disposable{constructor(e,t,r){super(),this._commandService=e,this._menuManagerService=t,this._componentManager=r,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[H,L,N,V,W].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(Ie)}_initComponents(){[[x.componentKey,x],["CommentIcon",te]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};q=pe([Z(0,o.ICommandService),Z(1,u.IMenuManagerService),Z(2,o.Inject(u.ComponentManager))],q);var Se=Object.getOwnPropertyDescriptor,_e=(e,t,r,n)=>{for(var i=n>1?void 0:n?Se(t,r):t,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=a(i)||i);return i},j=(e,t)=>(r,n)=>t(r,n,e);let K=class extends o.Disposable{constructor(e,t,r,n,i,s,a){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=r,this._docRenderController=n,this._univerInstanceService=i,this._threadCommentModel=s,this._commandService=a,this._interceptorViewModel(),this._initReRender(),this._initSyncComments()}_initReRender(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var r;if(e){this._docRenderController.reRender(e.unitId);return}const t=(r=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:r.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,r)=>{if(!e)return r(e);const{unitId:n,index:i,customDecorations:s}=t,a=this._threadCommentPanelService.activeCommentId,{commentId:d,unitId:C}=a||{},h=s.find(g=>g.id===d),l=this._threadCommentModel.getComment(n,M,e.id);if(!l)return r({...e,show:!1});const I=h&&i>=h.startIndex&&i<=h.endIndex,S=C===n&&e.id===d;return r({...e,active:S||I,show:!l.resolved})}})}_initSyncComments(){var i,s,a;const e=this._context.unit.getUnitId(),t=M,r=(a=(s=(i=this._context.unit.getBody())==null?void 0:i.customDecorations)==null?void 0:s.filter(d=>d.type===o.CustomDecorationType.COMMENT).map(d=>d.id))!=null?a:[];r.forEach(d=>{this._threadCommentModel.getComment(e,t,d)||this._threadCommentModel.addComment(e,t,{id:d,threadId:d,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),r.length&&this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(),M,r);let n=r.sort();this.disposeWithMe(this._commandService.onCommandExecuted(d=>{var C,h,l;if(d.id===T.RichTextEditingMutation.id){if(d.params.unitId!==this._context.unit.getUnitId())return;const S=(l=(h=(C=this._context.unit.getBody())==null?void 0:C.customDecorations)==null?void 0:h.filter(m=>m.type===o.CustomDecorationType.COMMENT).map(m=>m.id))!=null?l:[],g=S.sort();if(JSON.stringify(n)!==JSON.stringify(g)){const m=new Set(n),v=new Set(g),y=new Set,w=new Set;S.forEach(f=>{m.has(f)||y.add(f)}),n.forEach(f=>{v.has(f)||w.add(f)}),n=g,y.forEach(f=>{this._threadCommentModel.getComment(e,t,f)||this._threadCommentModel.addComment(e,t,{id:f,threadId:f,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),this._threadCommentModel.syncThreadComments(e,t,[...y])}}}))}};K=_e([j(1,o.Inject(T.DocInterceptorService)),j(2,o.Inject(O.ThreadCommentPanelService)),j(3,o.Inject(_.DocRenderController)),j(4,o.IUniverInstanceService),j(5,o.Inject(A.ThreadCommentModel)),j(6,o.ICommandService)],K);var Oe=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,De=(e,t,r)=>t in e?Oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Me=(e,t,r,n)=>{for(var i=n>1?void 0:n?Te(t,r):t,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=a(i)||i);return i},G=(e,t)=>(r,n)=>t(r,n,e),ne=(e,t,r)=>De(e,typeof t!="symbol"?t+"":t,r);c.UniverDocsThreadCommentUIPlugin=class extends o.Plugin{constructor(t=Q,r,n,i){super(),this._config=t,this._injector=r,this._renderManagerSrv=n,this._configService=i;const{menu:s,...a}=o.merge({},Q,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(ce,a)}onStarting(){[[q],[B],[R]].forEach(t=>{this._injector.add(t)})}onRendered(){this._initRenderModule(),this._injector.get(B),this._injector.get(q)}_initRenderModule(){[K].forEach(t=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,t)})}},ne(c.UniverDocsThreadCommentUIPlugin,"pluginName",ie),ne(c.UniverDocsThreadCommentUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC),c.UniverDocsThreadCommentUIPlugin=Me([o.DependentOn(O.UniverThreadCommentUIPlugin),G(1,o.Inject(o.Injector)),G(2,U.IRenderManagerService),G(3,o.IConfigService)],c.UniverDocsThreadCommentUIPlugin),c.AddDocCommentComment=H,c.DeleteDocCommentComment=L,c.ShowCommentPanelOperation=N,c.StartAddCommentOperation=V,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
|
|
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,$,_,T,y,u,E,ne,D){"use strict";var Oe=Object.defineProperty;var Ue=(c,o,S)=>o in c?Oe(c,o,{enumerable:!0,configurable:!0,writable:!0,value:S}):c[o]=S;var J=(c,o,S)=>Ue(c,typeof o!="symbol"?o+"":o,S);const ie="DOC_THREAD_COMMENT_UI_PLUGIN",M="default_doc",F={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($.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:$.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}},H={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 re=Object.getOwnPropertyDescriptor,oe=(e,t,i,n)=>{for(var r=n>1?void 0:n?re(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();J(this,"_addingComment$",new E.BehaviorSubject(void 0));J(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=oe([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 se(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 de(e){return{id:L.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,G=n==null?void 0:n.getCustomDecorations();I((U=G==null?void 0:G.map(q=>q.id).filter(q=>{const Me=N.has(q);return N.add(q),!Me}))!=null?U:[])}});return()=>{O.dispose()}},[a,n]),!n)return null;const g=z(t),p=n.getUnitId();return ne.jsx(_.ThreadCommentPanel,{unitId:p,subUnitId$:r,type:o.UniverInstanceType.UNIVER_DOC,onAdd:()=>{a.executeCommand(w.id)},getSubUnitName:()=>"",disableAdd:g,tempComment:f,onAddComment:m=>{if(!m.parentId){const C={unitId:p,range:f,comment:m};return a.executeCommand(F.id,C),h.endAdd(),!1}return!0},onDeleteComment:m=>{if(!m.parentId){const C={unitId:p,commentId:m.id};return a.executeCommand(H.id,C),!1}return!0},showComments:l})};b.componentKey="univer.doc.thread-comment-panel";const j={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}},L={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(j.id),!0;h.executeCommand(j.id);const g=n.getUnitId(),p=((N=(U=n.getBody())==null?void 0:U.dataStream)!=null?N:"").slice(l.startOffset,l.endOffset),m=o.BuildTextUtils.transform.getPlainText(p),C=M,O="",A={unitId:g,subUnitId:C,id:O,ref:m,dT:$.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:g,subUnitId:C,commentId:O}),!0}},ae="docs-thread-comment-ui.config",Q={};var ce=Object.getOwnPropertyDescriptor,me=(e,t,i,n)=>{for(var r=n>1?void 0:n?ce(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 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:g,collapsed:p}=l;let m;if(p?m=(n=(i=f.getBody())==null?void 0:i.customDecorations)==null?void 0:n.find(C=>C.startIndex<=I&&C.endIndex>=g-1):m=(s=(r=f.getBody())==null?void 0:r.customDecorations)==null?void 0:s.find(C=>C.startIndex<=I&&C.endIndex>=g-1),m){const C=this._threadCommentModel.getComment(a,M,m.id);C&&!C.resolved&&this._commandService.executeCommand(j.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=me([x(0,o.Inject(_.ThreadCommentPanelService)),x(1,o.IUniverInstanceService),x(2,o.ICommandService),x(3,o.Inject(R)),x(4,y.IRenderManagerService),x(5,o.Inject($.ThreadCommentModel))],V);function X({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(`_${Ce()}`);return k(i,`${n}`,{defIds:i.defIds,idSuffix:h.current},{ref:e,className:a,...d},s)}function k(e,t,i,n,r){return D.createElement(e.tag,{key:t,...le(e,i,r),...n},(ue(e,i).children||[]).map((s,d)=>k(s,`${t}-${e.tag}-${d}`,i,void 0,r)))}function le(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 ue(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 Ce(){return Math.random().toString(36).substring(2,8)}X.displayName="UniverIcon";const he={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"}}]},ee=D.forwardRef(function(t,i){return D.createElement(X,Object.assign({},t,{id:"comment-icon",ref:i,icon:he}))});ee.displayName="CommentIcon";const ve={[u.RibbonInsertGroup.MEDIA]:{[L.id]:{order:3,menuItemFactory:de}},[u.ContextMenuPosition.MAIN_AREA]:{[u.ContextMenuGroup.DATA]:{[w.id]:{order:1,menuItemFactory:se}}}};var fe=Object.getOwnPropertyDescriptor,Ie=(e,t,i,n)=>{for(var r=n>1?void 0:n?fe(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},W=(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(){[F,H,j,w,L].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(ve)}_initComponents(){[[b.componentKey,b],["CommentIcon",ee]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};B=Ie([W(0,o.ICommandService),W(1,u.IMenuManagerService),W(2,o.Inject(u.ComponentManager))],B);var pe=Object.getOwnPropertyDescriptor,ge=(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},P=(e,t)=>(i,n)=>t(i,n,e);let Z=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(p=>p.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,g=h===n&&e.id===a;return i({...e,active:g||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 g=(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:[],p=g.sort();if(JSON.stringify(n)!==JSON.stringify(p)){const m=new Set(n),C=new Set(p),O=new Set,A=new Set;g.forEach(v=>{m.has(v)||O.add(v)}),n.forEach(v=>{C.has(v)||A.add(v)}),n=p,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])}}}))}};Z=ge([P(1,o.Inject(T.DocInterceptorService)),P(2,o.Inject(_.ThreadCommentPanelService)),P(3,o.Inject(S.DocRenderController)),P(4,o.IUniverInstanceService),P(5,o.Inject($.ThreadCommentModel)),P(6,o.ICommandService)],Z);var Se=Object.defineProperty,_e=Object.getOwnPropertyDescriptor,Te=(e,t,i)=>t in e?Se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,De=(e,t,i,n)=>{for(var r=n>1?void 0:n?_e(t,i):t,s=e.length-1,d;s>=0;s--)(d=e[s])&&(r=d(r)||r);return r},K=(e,t)=>(i,n)=>t(i,n,e),te=(e,t,i)=>Te(e,typeof t!="symbol"?t+"":t,i);c.UniverDocsThreadCommentUIPlugin=class extends o.Plugin{constructor(t=Q,i,n,r){super(),this._config=t,this._injector=i,this._renderManagerSrv=n,this._configService=r;const{menu:s,...d}=o.merge({},Q,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(ae,d)}onStarting(){[[B],[V],[R]].forEach(t=>{this._injector.add(t)})}onRendered(){this._initRenderModule(),this._injector.get(V),this._injector.get(B)}_initRenderModule(){[Z].forEach(t=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,t)})}},te(c.UniverDocsThreadCommentUIPlugin,"pluginName",ie),te(c.UniverDocsThreadCommentUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC),c.UniverDocsThreadCommentUIPlugin=De([o.DependentOn(_.UniverThreadCommentUIPlugin),K(1,o.Inject(o.Injector)),K(2,y.IRenderManagerService),K(3,o.IConfigService)],c.UniverDocsThreadCommentUIPlugin),c.AddDocCommentComment=F,c.DeleteDocCommentComment=H,c.ShowCommentPanelOperation=j,c.StartAddCommentOperation=w,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs-thread-comment-ui",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer thread comment plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
"rxjs": ">=7.0.0"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@univerjs/icons": "^0.
|
|
51
|
-
"@univerjs/
|
|
52
|
-
"@univerjs/
|
|
53
|
-
"@univerjs/
|
|
54
|
-
"@univerjs/
|
|
55
|
-
"@univerjs/thread-comment": "0.10.
|
|
56
|
-
"@univerjs/thread-comment-ui": "0.10.
|
|
57
|
-
"@univerjs/ui": "0.10.
|
|
50
|
+
"@univerjs/icons": "^1.0.2",
|
|
51
|
+
"@univerjs/docs": "0.10.13",
|
|
52
|
+
"@univerjs/engine-render": "0.10.13",
|
|
53
|
+
"@univerjs/core": "0.10.13",
|
|
54
|
+
"@univerjs/docs-ui": "0.10.13",
|
|
55
|
+
"@univerjs/thread-comment": "0.10.13",
|
|
56
|
+
"@univerjs/thread-comment-ui": "0.10.13",
|
|
57
|
+
"@univerjs/ui": "0.10.13"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"postcss": "^8.5.6",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"typescript": "^5.9.3",
|
|
65
65
|
"vite": "^7.1.10",
|
|
66
66
|
"vitest": "^3.2.4",
|
|
67
|
-
"@univerjs-infra/shared": "0.10.
|
|
67
|
+
"@univerjs-infra/shared": "0.10.13"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
|
70
70
|
"test": "vitest run",
|