@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.
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +2 -615
- package/lib/index.css +1 -0
- package/lib/index.js +2 -615
- package/lib/types/commands/commands/add-doc-comment.command.d.ts +17 -2
- package/lib/types/commands/commands/delete-doc-comment.command.d.ts +16 -1
- package/lib/types/commands/operations/show-comment-panel.operation.d.ts +17 -2
- package/lib/types/config/config.d.ts +16 -1
- package/lib/types/controllers/doc-thread-comment-selection.controller.d.ts +15 -0
- package/lib/types/controllers/doc-thread-comment-ui.controller.d.ts +15 -0
- package/lib/types/controllers/render-controllers/render.controller.d.ts +18 -2
- package/lib/types/menu/menu.d.ts +17 -2
- package/lib/types/menu/schema.d.ts +16 -1
- package/lib/types/plugin.d.ts +16 -1
- package/lib/types/services/doc-thread-comment.service.d.ts +19 -3
- package/lib/umd/index.js +2 -2
- package/package.json +13 -12
package/lib/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
`},startOffset:m.startOffset,endOffset:m.endOffset,collapsed:!0,threadId:_};return I==null||I.blur(),d.startAdd(b),t.setActiveComment({unitId:g,subUnitId:l,commentId:_}),!0}},le="@univerjs/docs-thread-comment-ui",ue="0.17.0",Q={name:le,version:ue},Ce="docs-thread-comment-ui.config",Y={};var he=Object.getOwnPropertyDescriptor,ve=(e,t,r,n)=>{for(var i=n>1?void 0:n?he(t,r):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},y=(e,t)=>(r,n)=>t(r,n,e);let j=class extends s.Disposable{constructor(e,t,r,n,i,o){super(),this._threadCommentPanelService=e,this._univerInstanceService=t,this._commandService=r,this._docThreadCommentService=n,this._renderManagerService=i,this._threadCommentModel=o,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){let e;this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var r,n,i,o;if(t.id===p.SetTextSelectionsOperation.id){const c=t.params,{unitId:d,ranges:C}=c;if(s.isInternalEditorID(d))return;const v=this._univerInstanceService.getUnit(d,s.UniverInstanceType.UNIVER_DOC),m=C[0];if((e==null?void 0:e.startOffset)===(m==null?void 0:m.startOffset)&&(e==null?void 0:e.endOffset)===(m==null?void 0:m.endOffset))return;if(e=m,m&&v){const{startOffset:I,endOffset:g,collapsed:f}=m;let a;if(f?a=(n=(r=v.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(l=>l.startIndex<=I&&l.endIndex>=g-1):a=(o=(i=v.getBody())==null?void 0:i.customDecorations)==null?void 0:o.find(l=>l.startIndex<=I&&l.endIndex>=g-1),a){const l=this._threadCommentModel.getComment(d,T,a.id);l&&!l.resolved&&this._commandService.executeCommand($.id,{activeComment:{unitId:d,subUnitId:T,commentId:a.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(S.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var t,r,n,i;if(e){const o=this._univerInstanceService.getUnit(e.unitId);if(o){const c=(t=this._renderManagerService.getRenderById(e.unitId))==null?void 0:t.with(w.DocBackScrollRenderController),d=(n=(r=o.getBody())==null?void 0:r.customDecorations)==null?void 0:n.find(C=>C.id===e.commentId);d&&c&&c.scrollToRange({startOffset:d.startIndex,endOffset:d.endIndex,collapsed:!1})}}(!e||e.commentId!==((i=this._docThreadCommentService.addingComment)==null?void 0:i.id))&&this._docThreadCommentService.endAdd()}))}};j=ve([y(0,s.Inject(S.ThreadCommentPanelService)),y(1,s.IUniverInstanceService),y(2,s.ICommandService),y(3,s.Inject(E)),y(4,O.IRenderManagerService),y(5,s.Inject(A.ThreadCommentModel))],j);function X({ref:e,...t}){const{icon:r,id:n,className:i,extend:o,...c}=t,d=`univerjs-icon univerjs-icon-${n} ${i||""}`.trim(),C=D.useRef(`_${ge()}`);return ee(r,`${n}`,{defIds:r.defIds,idSuffix:C.current},{ref:e,className:d,...c},o)}function ee(e,t,r,n,i){return D.createElement(e.tag,{key:t,...Ie(e,r,i),...n},(fe(e,r).children||[]).map((o,c)=>ee(o,`${t}-${e.tag}-${c}`,r,void 0,i)))}function Ie(e,t,r){const n={...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(([o,c])=>{o==="mask"&&typeof c=="string"&&(n[o]=c.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:i}=t;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(([o,c])=>{typeof c=="string"&&(n[o]=c.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),n}function fe(e,t){var n;const{defIds:r}=t;return!r||r.length===0?e:e.tag==="defs"&&((n=e.children)!=null&&n.length)?{...e,children:e.children.map(i=>typeof i.attrs.id=="string"&&r&&r.includes(i.attrs.id)?{...i,attrs:{...i.attrs,id:i.attrs.id+t.idSuffix}}:i)}:e}function ge(){return Math.random().toString(36).substring(2,8)}X.displayName="UniverIcon";const pe={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(t,r){return D.createElement(X,Object.assign({},t,{id:"comment-icon",ref:r,icon:pe}))});te.displayName="CommentIcon";const Se={[u.RibbonInsertGroup.MEDIA]:{[J.id]:{order:3,menuItemFactory:me}},[u.ContextMenuPosition.MAIN_AREA]:{[u.ContextMenuGroup.DATA]:{[N.id]:{order:1,menuItemFactory:ae}}}};var _e=Object.getOwnPropertyDescriptor,De=(e,t,r,n)=>{for(var i=n>1?void 0:n?_e(t,r):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},L=(e,t)=>(r,n)=>t(r,n,e);let B=class extends s.Disposable{constructor(e,t,r){super(),this._commandService=e,this._menuManagerService=t,this._componentManager=r,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[K,G,$,N,J].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(Se)}_initComponents(){[[U.componentKey,U],["CommentIcon",te]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};B=De([L(0,s.ICommandService),L(1,u.IMenuManagerService),L(2,s.Inject(u.ComponentManager))],B);var Te=Object.getOwnPropertyDescriptor,Me=(e,t,r,n)=>{for(var i=n>1?void 0:n?Te(t,r):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},R=(e,t)=>(r,n)=>t(r,n,e);let Z=class extends s.Disposable{constructor(e,t,r,n,i,o,c){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=r,this._docRenderController=n,this._univerInstanceService=i,this._threadCommentModel=o,this._commandService=c,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(s.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(p.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION,{handler:(e,t,r)=>{if(!e)return r(e);const{unitId:n,index:i,customDecorations:o}=t,c=this._threadCommentPanelService.activeCommentId,{commentId:d,unitId:C}=c||{},v=o.find(f=>f.id===d),m=this._threadCommentModel.getComment(n,T,e.id);if(!m)return r({...e,show:!1});const I=v&&i>=v.startIndex&&i<=v.endIndex,g=C===n&&e.id===d;return r({...e,active:g||I,show:!m.resolved})}})}_initSyncComments(){var i,o,c;const e=this._context.unit.getUnitId(),t=T,r=(c=(o=(i=this._context.unit.getBody())==null?void 0:i.customDecorations)==null?void 0:o.filter(d=>d.type===s.CustomDecorationType.COMMENT).map(d=>d.id))!=null?c:[];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(),T,r);let n=r.sort();this.disposeWithMe(this._commandService.onCommandExecuted(d=>{var C,v,m;if(d.id===p.RichTextEditingMutation.id){if(d.params.unitId!==this._context.unit.getUnitId())return;const g=(m=(v=(C=this._context.unit.getBody())==null?void 0:C.customDecorations)==null?void 0:v.filter(a=>a.type===s.CustomDecorationType.COMMENT).map(a=>a.id))!=null?m:[],f=g.sort();if(JSON.stringify(n)!==JSON.stringify(f)){const a=new Set(n),l=new Set(f),_=new Set,b=new Set;g.forEach(h=>{a.has(h)||_.add(h)}),n.forEach(h=>{l.has(h)||b.add(h)}),n=f,_.forEach(h=>{this._threadCommentModel.getComment(e,t,h)||this._threadCommentModel.addComment(e,t,{id:h,threadId:h,ref:"",dT:"",personId:"",text:{dataStream:""},unitId:e,subUnitId:t})}),this._threadCommentModel.syncThreadComments(e,t,[..._])}}}))}};Z=Me([R(1,s.Inject(p.DocInterceptorService)),R(2,s.Inject(S.ThreadCommentPanelService)),R(3,s.Inject(w.DocRenderController)),R(4,s.IUniverInstanceService),R(5,s.Inject(A.ThreadCommentModel)),R(6,s.ICommandService)],Z);var Oe=Object.defineProperty,Ue=Object.getOwnPropertyDescriptor,be=(e,t,r)=>t in e?Oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ye=(e,t,r,n)=>{for(var i=n>1?void 0:n?Ue(t,r):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},W=(e,t)=>(r,n)=>t(r,n,e),q=(e,t,r)=>be(e,typeof t!="symbol"?t+"":t,r);exports.UniverDocsThreadCommentUIPlugin=class extends s.Plugin{constructor(t=Y,r,n,i){super(),this._config=t,this._injector=r,this._renderManagerSrv=n,this._configService=i;const{menu:o,...c}=s.merge({},Y,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Ce,c)}onStarting(){[[B],[j],[E]].forEach(t=>{this._injector.add(t)})}onRendered(){this._initRenderModule(),this._injector.get(j),this._injector.get(B)}_initRenderModule(){[Z].forEach(t=>{this._renderManagerSrv.registerRenderModule(s.UniverInstanceType.UNIVER_DOC,t)})}};q(exports.UniverDocsThreadCommentUIPlugin,"pluginName",se);q(exports.UniverDocsThreadCommentUIPlugin,"packageName",Q.name);q(exports.UniverDocsThreadCommentUIPlugin,"version",Q.version);q(exports.UniverDocsThreadCommentUIPlugin,"type",s.UniverInstanceType.UNIVER_DOC);exports.UniverDocsThreadCommentUIPlugin=ye([s.DependentOn(S.UniverThreadCommentUIPlugin),W(1,s.Inject(s.Injector)),W(2,O.IRenderManagerService),W(3,s.IConfigService)],exports.UniverDocsThreadCommentUIPlugin);exports.AddDocCommentComment=K;exports.DeleteDocCommentComment=G;exports.ShowCommentPanelOperation=$;exports.StartAddCommentOperation=N;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/docs-ui`),n=require(`@univerjs/thread-comment`),r=require(`@univerjs/thread-comment-ui`),i=require(`@univerjs/docs`),a=require(`@univerjs/engine-render`),o=require(`@univerjs/ui`),s=require(`rxjs`),c=require(`react`),l=require(`react/jsx-runtime`),u=require(`@univerjs/icons`);const d=`default_doc`,f={id:`docs.command.add-comment`,type:e.CommandType.COMMAND,async handler(i,a){if(!a)return!1;let{comment:o,unitId:s}=a,c=await i.get(n.IThreadCommentDataSourceService).addComment(o),l=i.get(e.ICommandService),u=(0,t.addCustomDecorationBySelectionFactory)(i,{id:c.threadId,type:e.CustomDecorationType.COMMENT,unitId:s});return u?(await(0,e.sequenceExecute)([{id:n.AddCommentMutation.id,params:{unitId:s,subUnitId:d,comment:c}},u,{id:r.SetActiveCommentOperation.id,params:{unitId:s,subUnitId:d,commentId:c.id}}],l)).result:!1}},p={id:`docs.command.delete-comment`,type:e.CommandType.COMMAND,async handler(n,r){if(!r)return!1;let{commentId:i,unitId:a}=r,o=n.get(e.ICommandService),s=(0,t.deleteCustomDecorationFactory)(n,{id:i,unitId:a});return s?(await(0,e.sequenceExecute)([s],o)).result:!1}};function 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 e.Disposable{get addingComment(){return this._addingComment$.getValue()}constructor(e,t){super(),this._sidebarService=e,this._threadCommentPanelService=t,_(this,`_addingComment$`,new s.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,o.ISidebarService),v(1,(0,e.Inject)(r.ThreadCommentPanelService))],b);const x=t=>{var n;let r=t.get(a.IRenderManagerService),o=t.get(i.DocSelectionManagerService),s=(n=(0,a.withCurrentTypeOfRenderer)(e.UniverInstanceType.UNIVER_DOC,i.DocSkeletonManagerService,t.get(e.IUniverInstanceService),r))==null?void 0:n.getSkeleton(),c=s==null?void 0:s.getViewModel().getEditArea();if(c===a.DocumentEditArea.FOOTER||c===a.DocumentEditArea.HEADER)return!0;let l=o.getActiveTextRange();return!!(l==null||l.collapsed)};function S(t){return{id:D.id,type:o.MenuItemType.BUTTON,icon:`CommentIcon`,title:`threadCommentUI.panel.addComment`,tooltip:`threadCommentUI.panel.addComment`,hidden$:(0,o.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_DOC,void 0,e.SHEET_EDITOR_UNITS),disabled$:new s.Observable(function(e){let n=t.get(i.DocSelectionManagerService).textSelection$.pipe((0,s.debounceTime)(16)).subscribe(()=>{e.next(x(t))});return()=>{n.unsubscribe()}})}}function C(t){return{id:E.id,type:o.MenuItemType.BUTTON,icon:`CommentIcon`,title:`threadCommentUI.panel.addComment`,tooltip:`threadCommentUI.panel.addComment`,hidden$:(0,o.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_DOC)}}const w=()=>{let t=(0,o.useDependency)(e.IUniverInstanceService),n=(0,o.useDependency)(e.Injector),a=(0,o.useObservable)((0,c.useMemo)(()=>t.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_DOC).pipe((0,s.filter)(t=>!!t&&!(0,e.isInternalEditorID)(t.getUnitId()))),[t])),u=(0,c.useMemo)(()=>new s.Observable(e=>e.next(d)),[]),m=(0,o.useDependency)(i.DocSelectionManagerService);(0,o.useObservable)((0,c.useMemo)(()=>m.textSelection$.pipe((0,s.debounceTime)(16)),[m.textSelection$]));let h=(0,o.useDependency)(e.ICommandService),g=(0,o.useDependency)(b),_=(0,o.useObservable)(g.addingComment$),[v,y]=(0,c.useState)([]);if((0,c.useEffect)(()=>{var e;let t=new Set,n=a==null?void 0:a.getCustomDecorations();y((e=n==null?void 0:n.map(e=>e.id).filter(e=>{let n=t.has(e);return t.add(e),!n}))==null?[]:e);let r=h.onCommandExecuted(e=>{if(e.id===i.RichTextEditingMutation.id){var t;let e=new Set,n=a==null?void 0:a.getCustomDecorations();y((t=n==null?void 0:n.map(e=>e.id).filter(t=>{let n=e.has(t);return e.add(t),!n}))==null?[]:t)}});return()=>{r.dispose()}},[h,a]),!a)return null;let S=x(n),C=a.getUnitId();return(0,l.jsx)(r.ThreadCommentPanel,{unitId:C,subUnitId$:u,type:e.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`;const T={id:`docs.operation.show-comment-panel`,type:e.CommandType.OPERATION,handler(e,t){var n;let i=e.get(r.ThreadCommentPanelService),a=e.get(o.ISidebarService);return(!i.panelVisible||((n=a.options.children)==null?void 0:n.label)!==w.componentKey)&&(a.open({header:{title:`threadCommentUI.panel.title`},children:{label:w.componentKey},width:320,onClose:()=>i.setPanelVisible(!1)}),i.setPanelVisible(!0)),t&&i.setActiveComment(t==null?void 0:t.activeComment),!0}},E={id:`docs.operation.toggle-comment-panel`,type:e.CommandType.OPERATION,handler(e){var t;let n=e.get(r.ThreadCommentPanelService),i=e.get(o.ISidebarService);return!n.panelVisible||((t=i.options.children)==null?void 0:t.label)!==w.componentKey?(i.open({header:{title:`threadCommentUI.panel.title`},children:{label:w.componentKey},width:320,onClose:()=>n.setPanelVisible(!1)}),n.setPanelVisible(!0)):(i.close(),n.setPanelVisible(!1),n.setActiveComment(null)),!0}},D={id:`docs.operation.start-add-comment`,type:e.CommandType.OPERATION,handler(s){var c,l,u;let f=s.get(r.ThreadCommentPanelService),p=s.get(e.IUniverInstanceService).getCurrentUnitForType(e.UniverInstanceType.UNIVER_DOC),m=s.get(i.DocSelectionManagerService),h=s.get(a.IRenderManagerService),g=s.get(e.UserManagerService),_=s.get(b),v=s.get(e.ICommandService),y=s.get(o.ISidebarService),x=m.getActiveTextRange();if(!p||!x)return!1;let S=(c=h.getRenderById(p.getUnitId()))==null?void 0:c.with(t.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=e.BuildTextUtils.transform.getPlainText(w),D=d,O={unitId:C,subUnitId:D,id:``,ref:E,dT:(0,n.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`;const A=`docs-thread-comment-ui.config`;Symbol(A);const j={};let M=class extends e.Disposable{constructor(e,t,n,r,i,a){super(),this._threadCommentPanelService=e,this._univerInstanceService=t,this._commandService=n,this._docThreadCommentService=r,this._renderManagerService=i,this._threadCommentModel=a,this._initSelectionChange(),this._initActiveCommandChange()}_initSelectionChange(){let t;this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===i.SetTextSelectionsOperation.id){let{unitId:i,ranges:s}=n.params;if((0,e.isInternalEditorID)(i))return;let c=this._univerInstanceService.getUnit(i,e.UniverInstanceType.UNIVER_DOC),l=s[0];if((t==null?void 0:t.startOffset)===(l==null?void 0:l.startOffset)&&(t==null?void 0:t.endOffset)===(l==null?void 0:l.endOffset))return;if(t=l,l&&c){let{startOffset:e,endOffset:t,collapsed:n}=l,r;if(n){var a;r=(a=c.getBody())==null||(a=a.customDecorations)==null?void 0:a.find(n=>n.startIndex<=e&&n.endIndex>=t-1)}else{var o;r=(o=c.getBody())==null||(o=o.customDecorations)==null?void 0:o.find(n=>n.startIndex<=e&&n.endIndex>=t-1)}if(r){let e=this._threadCommentModel.getComment(i,d,r.id);e&&!e.resolved&&this._commandService.executeCommand(T.id,{activeComment:{unitId:i,subUnitId:d,commentId:r.id}});return}}if(!this._threadCommentPanelService.activeCommentId)return;this._commandService.executeCommand(r.SetActiveCommentOperation.id)}}))}_initActiveCommandChange(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(e=>{var n;if(e){let n=this._univerInstanceService.getUnit(e.unitId);if(n){var r,i;let a=(r=this._renderManagerService.getRenderById(e.unitId))==null?void 0:r.with(t.DocBackScrollRenderController),o=(i=n.getBody())==null||(i=i.customDecorations)==null?void 0:i.find(t=>t.id===e.commentId);o&&a&&a.scrollToRange({startOffset:o.startIndex,endOffset:o.endIndex,collapsed:!1})}}(!e||e.commentId!==((n=this._docThreadCommentService.addingComment)==null?void 0:n.id))&&this._docThreadCommentService.endAdd()}))}};M=y([v(0,(0,e.Inject)(r.ThreadCommentPanelService)),v(1,e.IUniverInstanceService),v(2,e.ICommandService),v(3,(0,e.Inject)(b)),v(4,a.IRenderManagerService),v(5,(0,e.Inject)(n.ThreadCommentModel))],M);const N={[o.RibbonInsertGroup.MEDIA]:{[E.id]:{order:3,menuItemFactory:C}},[o.ContextMenuPosition.MAIN_AREA]:{[o.ContextMenuGroup.DATA]:{[D.id]:{order:1,menuItemFactory:S}}}};let P=class extends e.Disposable{constructor(e,t,n){super(),this._commandService=e,this._menuManagerService=t,this._componentManager=n,this._initCommands(),this._initMenus(),this._initComponents()}_initCommands(){[f,p,T,D,E].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenus(){this._menuManagerService.mergeMenu(N)}_initComponents(){[[w.componentKey,w],[`CommentIcon`,u.CommentIcon]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};P=y([v(0,e.ICommandService),v(1,o.IMenuManagerService),v(2,(0,e.Inject)(o.ComponentManager))],P);let F=class extends e.Disposable{constructor(e,t,n,r,i,a,o){super(),this._context=e,this._docInterceptorService=t,this._threadCommentPanelService=n,this._docRenderController=r,this._univerInstanceService=i,this._threadCommentModel=a,this._commandService=o,this._interceptorViewModel(),this._initReRender(),this._initSyncComments()}_initReRender(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(t=>{var n;if(t){this._docRenderController.reRender(t.unitId);return}let r=(n=this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_DOC))==null?void 0:n.getUnitId();r&&this._docRenderController.reRender(r)})),this.disposeWithMe(this._threadCommentModel.commentUpdate$.subscribe(e=>{e.type===`resolve`&&this._docRenderController.reRender(e.unitId)}))}_interceptorViewModel(){this._docInterceptorService.intercept(i.DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION,{handler:(e,t,n)=>{if(!e)return n(e);let{unitId:r,index:i,customDecorations:a}=t,{commentId:o,unitId:s}=this._threadCommentPanelService.activeCommentId||{},c=a.find(e=>e.id===o),l=this._threadCommentModel.getComment(r,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 t,n;let r=this._context.unit.getUnitId(),a=d,o=(t=(n=this._context.unit.getBody())==null||(n=n.customDecorations)==null?void 0:n.filter(t=>t.type===e.CustomDecorationType.COMMENT).map(e=>e.id))==null?[]:t;o.forEach(e=>{this._threadCommentModel.getComment(r,a,e)||this._threadCommentModel.addComment(r,a,{id:e,threadId:e,ref:``,dT:``,personId:``,text:{dataStream:``},unitId:r,subUnitId:a})}),o.length&&this._threadCommentModel.syncThreadComments(this._context.unit.getUnitId(),`default_doc`,o);let s=o.sort();this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===i.RichTextEditingMutation.id){var n,o;if(t.params.unitId!==this._context.unit.getUnitId())return;let i=(n=(o=this._context.unit.getBody())==null||(o=o.customDecorations)==null?void 0:o.filter(t=>t.type===e.CustomDecorationType.COMMENT).map(e=>e.id))==null?[]:n,c=i.sort();if(JSON.stringify(s)!==JSON.stringify(c)){let e=new Set(s),t=new Set(c),n=new Set,o=new Set;i.forEach(t=>{e.has(t)||n.add(t)}),s.forEach(e=>{t.has(e)||o.add(e)}),s=c,n.forEach(e=>{this._threadCommentModel.getComment(r,a,e)||this._threadCommentModel.addComment(r,a,{id:e,threadId:e,ref:``,dT:``,personId:``,text:{dataStream:``},unitId:r,subUnitId:a})}),this._threadCommentModel.syncThreadComments(r,a,[...n])}}}))}};F=y([v(1,(0,e.Inject)(i.DocInterceptorService)),v(2,(0,e.Inject)(r.ThreadCommentPanelService)),v(3,(0,e.Inject)(t.DocRenderController)),v(4,e.IUniverInstanceService),v(5,(0,e.Inject)(n.ThreadCommentModel)),v(6,e.ICommandService)],F);let I=class extends e.Plugin{constructor(t=j,n,r,i){super(),this._config=t,this._injector=n,this._renderManagerSrv=r,this._configService=i;let{menu:a,...o}=(0,e.merge)({},j,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(A,o)}onStarting(){[[P],[M],[b]].forEach(e=>{this._injector.add(e)})}onRendered(){this._initRenderModule(),this._injector.get(M),this._injector.get(P)}_initRenderModule(){[F].forEach(t=>{this._renderManagerSrv.registerRenderModule(e.UniverInstanceType.UNIVER_DOC,t)})}};_(I,`pluginName`,`DOC_THREAD_COMMENT_UI_PLUGIN`),_(I,`packageName`,O),_(I,`version`,k),_(I,`type`,e.UniverInstanceType.UNIVER_DOC),I=y([(0,e.DependentOn)(r.UniverThreadCommentUIPlugin),v(1,(0,e.Inject)(e.Injector)),v(2,a.IRenderManagerService),v(3,e.IConfigService)],I),exports.AddDocCommentComment=f,exports.DeleteDocCommentComment=p,exports.ShowCommentPanelOperation=T,exports.StartAddCommentOperation=D,Object.defineProperty(exports,`UniverDocsThreadCommentUIPlugin`,{enumerable:!0,get:function(){return I}});
|