@univerjs/thread-comment-ui 0.20.1 → 0.21.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.
Files changed (41) hide show
  1. package/lib/cjs/index.js +844 -4
  2. package/lib/cjs/locale/ca-ES.js +37 -1
  3. package/lib/cjs/locale/en-US.js +52 -1
  4. package/lib/cjs/locale/es-ES.js +37 -1
  5. package/lib/cjs/locale/fa-IR.js +37 -1
  6. package/lib/cjs/locale/fr-FR.js +37 -1
  7. package/lib/cjs/locale/ja-JP.js +37 -1
  8. package/lib/cjs/locale/ko-KR.js +37 -1
  9. package/lib/cjs/locale/ru-RU.js +37 -1
  10. package/lib/cjs/locale/sk-SK.js +37 -1
  11. package/lib/cjs/locale/vi-VN.js +37 -1
  12. package/lib/cjs/locale/zh-CN.js +37 -1
  13. package/lib/cjs/locale/zh-TW.js +37 -1
  14. package/lib/es/index.js +828 -4
  15. package/lib/es/locale/ca-ES.js +36 -1
  16. package/lib/es/locale/en-US.js +51 -1
  17. package/lib/es/locale/es-ES.js +36 -1
  18. package/lib/es/locale/fa-IR.js +36 -1
  19. package/lib/es/locale/fr-FR.js +36 -1
  20. package/lib/es/locale/ja-JP.js +36 -1
  21. package/lib/es/locale/ko-KR.js +36 -1
  22. package/lib/es/locale/ru-RU.js +36 -1
  23. package/lib/es/locale/sk-SK.js +36 -1
  24. package/lib/es/locale/vi-VN.js +36 -1
  25. package/lib/es/locale/zh-CN.js +36 -1
  26. package/lib/es/locale/zh-TW.js +36 -1
  27. package/lib/index.js +828 -4
  28. package/lib/locale/ca-ES.js +36 -1
  29. package/lib/locale/en-US.js +51 -1
  30. package/lib/locale/es-ES.js +36 -1
  31. package/lib/locale/fa-IR.js +36 -1
  32. package/lib/locale/fr-FR.js +36 -1
  33. package/lib/locale/ja-JP.js +36 -1
  34. package/lib/locale/ko-KR.js +36 -1
  35. package/lib/locale/ru-RU.js +36 -1
  36. package/lib/locale/sk-SK.js +36 -1
  37. package/lib/locale/vi-VN.js +36 -1
  38. package/lib/locale/zh-CN.js +36 -1
  39. package/lib/locale/zh-TW.js +36 -1
  40. package/lib/umd/index.js +1 -1
  41. package/package.json +9 -9
package/lib/index.js CHANGED
@@ -1,4 +1,828 @@
1
- import{BuildTextUtils as e,CommandType as t,CustomRangeType as n,DOCS_COMMENT_EDITOR_UNIT_ID_KEY as r,DOCS_NORMAL_EDITOR_UNIT_ID_KEY as i,DependentOn as a,Disposable as o,ICommandService as s,IConfigService as c,IUniverInstanceService as l,Inject as u,Injector as d,LocaleService as f,Plugin as p,Tools as m,UniverInstanceType as h,UserManagerService as g,generateRandomId as _,getBodySlice as v,merge as y,mergeOverrideWithDependencies as b}from"@univerjs/core";import{ISidebarService as x,KeyCode as S,UI_PLUGIN_CONFIG_KEY as C,useConfigValue as w,useDependency as T,useObservable as E}from"@univerjs/ui";import{BehaviorSubject as D,debounceTime as O,filter as k}from"rxjs";import{AddCommentCommand as A,DeleteCommentCommand as j,DeleteCommentTreeCommand as ee,ResolveCommentCommand as te,ThreadCommentModel as ne,UniverThreadCommentPlugin as M,UpdateCommentCommand as N,getDT as P}from"@univerjs/thread-comment";import{Button as F,Dropdown as I,Select as L,Tooltip as R,borderClassName as re,clsx as z,scrollbarClassName as ie}from"@univerjs/design";import{DeleteIcon as ae,IncreaseIcon as B,MoreHorizontalIcon as oe,ReplyToCommentIcon as V,ResolvedIcon as se,SolveIcon as ce}from"@univerjs/icons";import{forwardRef as H,useEffect as le,useImperativeHandle as ue,useMemo as U,useRef as de,useState as W}from"react";import{BreakLineCommand as fe,IEditorService as G,RichTextEditor as pe}from"@univerjs/docs-ui";import{jsx as K,jsxs as q}from"react/jsx-runtime";function J(e){"@babel/helpers - typeof";return J=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},J(e)}function me(e,t){if(J(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(J(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function he(e){var t=me(e,`string`);return J(t)==`symbol`?t:t+``}function Y(e,t,n){return(t=he(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function X(e,t){return function(n,r){t(n,r,e)}}function ge(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 Z=class extends o{constructor(e,t){super(),this._sidebarService=e,this._univerInstanceService=t,Y(this,`_panelVisible`,!1),Y(this,`_panelVisible$`,new D(!1)),Y(this,`_activeCommentId`,void 0),Y(this,`_activeCommentId$`,new D(void 0)),Y(this,`panelVisible$`,this._panelVisible$.asObservable()),Y(this,`activeCommentId$`,this._activeCommentId$.asObservable()),this._init(),this.disposeWithMe(()=>{this._activeCommentId$.complete(),this._panelVisible$.complete()})}_init(){this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{e.visible||this.setPanelVisible(!1)})),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(h.UNIVER_SHEET).pipe(k(e=>!e)).subscribe(()=>{this._sidebarService.close()}))}get panelVisible(){return this._panelVisible}get activeCommentId(){return this._activeCommentId}setPanelVisible(e){this._panelVisible=e,this._panelVisible$.next(e)}setActiveComment(e){this._activeCommentId=e,this._activeCommentId$.next(e)}};Z=ge([X(0,u(x)),X(1,l)],Z);const Q={id:`thread-comment-ui.operation.set-active-comment`,type:t.OPERATION,handler(e,t){return e.get(Z).setActiveComment(t),!0}};var _e=`@univerjs/thread-comment-ui`,ve=`0.20.1`;const ye=`thread-comment-ui.config`;Symbol(ye);const be={};let $=class extends p{constructor(e=be,t,n,r){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r;let{menu:i,...a}=y({},be,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(ye,a)}onStarting(){var e;b([[Z]],(e=this._config)==null?void 0:e.overrides).forEach(e=>{this._injector.add(e)}),[Q].forEach(e=>{this._commandService.registerCommand(e)})}};Y($,`pluginName`,`UNIVER_THREAD_COMMENT_UI_PLUGIN`),Y($,`packageName`,_e),Y($,`version`,ve),Y($,`type`,h.UNIVER_UNKNOWN),$=ge([a(M),X(1,u(d)),X(2,s),X(3,c)],$);function xe(e){return{id:`d`,body:e,documentStyle:{}}}const Se=H((t,n)=>{var r;let{comment:a,onSave:o,id:c,onCancel:l,autoFocus:u,unitId:d,type:p,editorId:g}=t,_=T(s),v=T(f),[y,b]=W(!1),x=T(G),C=de(null),w=p===h.UNIVER_DOC?i:d,[E,D]=W(()=>{var t,n;return e.transform.getPlainText((t=(n=C.current)==null||(n=n.getDocumentData().body)==null?void 0:n.dataStream)==null?``:t)});le(()=>{var t,n,r;D(e.transform.getPlainText((t=(n=C.current)==null||(n=n.getDocumentData().body)==null?void 0:n.dataStream)==null?``:t));let i=(r=C.current)==null?void 0:r.selectionChange$.subscribe(()=>{var t,n;D(e.transform.getPlainText((t=(n=C.current)==null||(n=n.getDocumentData().body)==null?void 0:n.dataStream)==null?``:t))});return()=>i==null?void 0:i.unsubscribe()},[(r=C.current)==null?void 0:r.selectionChange$]);let O=U(()=>({keyCodes:[{keyCode:S.ENTER}],handler:e=>{e===S.ENTER&&_.executeCommand(fe.id)}}),[_]);return ue(n,()=>({reply(e){var t,n;if(!C.current)return;x.focus((t=C.current.getEditorId())==null?``:t);let r=xe(e);(n=C.current)==null||n.setDocumentData(r,[{startOffset:r.body.dataStream.length-2,endOffset:r.body.dataStream.length-2,collapsed:!0}])}})),q(`div`,{onClick:e=>e.preventDefault(),children:[K(pe,{className:`univer-w-full`,editorRef:C,editorId:g,autoFocus:u,keyboardEventConfig:O,placeholder:v.t(`threadCommentUI.editor.placeholder`),initialValue:(a==null?void 0:a.text)&&xe(a.text),onFocusChange:e=>e&&b(e),isSingle:!1,maxHeight:64,onClickOutside:()=>{setTimeout(()=>{x.focus(w)},30)}}),y?q(`div`,{className:`univer-mt-3 univer-flex univer-flex-row univer-justify-end univer-gap-2`,children:[K(F,{onClick:()=>{var e;l==null||l(),b(!1),(e=C.current)==null||e.replaceText(``,!0),_.executeCommand(Q.id)},children:v.t(`threadCommentUI.editor.cancel`)}),K(F,{variant:`primary`,disabled:!E,onClick:()=>{if(C.current){let e=m.deepClone(C.current.getDocumentData().body);b(!1),o==null||o({...a,text:e}),C.current.replaceText(``),setTimeout(()=>{var e,t;(e=C.current)==null||e.setSelectionRanges([]),(t=C.current)==null||t.blur()},10)}},children:v.t(c?`threadCommentUI.editor.save`:`threadCommentUI.editor.reply`)})]}):null]})}),Ce=e=>{let{dataStream:t,customRanges:n}=e,r=t.endsWith(`\r
2
- `)?t.length-2:t.length,i=[],a=0;return n==null||n.forEach(e=>{a<e.startIndex&&i.push({type:`text`,content:t.slice(a,e.startIndex)}),i.push({type:`mention`,content:{label:t.slice(e.startIndex,e.endIndex+1),id:e.rangeId}}),a=e.endIndex+1}),i.push({type:`text`,content:t.slice(a,r)}),i},we=e=>{if(!e)return[];let{paragraphs:t=[]}=e;return t.map((n,r)=>Ce(v(e,r===0?0:t[r-1].startIndex+1,n.startIndex)))},Te=e=>{let t=``,r=[];return e.forEach(e=>{switch(e.type){case`text`:t+=e.content;break;case`mention`:{let i=t.length;t+=e.content.label;let a=t.length-1;r.push({rangeId:e.content.id,rangeType:n.MENTION,startIndex:i,endIndex:a,properties:{},wholeEntity:!0});break}default:break}}),t+=`\r
3
- `,{textRuns:[],paragraphs:[{startIndex:t.length-2,paragraphStyle:{}}],sectionBreaks:[{startIndex:t.length-1}],dataStream:t,customRanges:r}};let Ee=function(e){return e.CELL=`CELL`,e.PANEL=`PANEL`,e}({});const De=`__mock__`,Oe=e=>{let{item:t,unitId:n,subUnitId:r,editing:i,onEditingChange:a,onReply:o,resolved:c,isRoot:l,onClose:u,onDeleteComment:d,type:p,threadCommentEditorId:m}=e,h=T(s),_=T(f),v=T(g),y=v.getUser(t.personId),b=E(v.currentUser$),x=(b==null?void 0:b.userID)===t.personId,S=t.id===De,[D,O]=W(!1),k=w(C),A=k==null?void 0:k.avatarFallback;return q(`div`,{className:`univer-relative univer-mb-3 univer-pl-[30px]`,onMouseLeave:()=>O(!1),onMouseEnter:()=>O(!0),children:[K(`div`,{className:`univer-absolute univer-left-0 univer-top-0 univer-size-6 univer-rounded-full univer-bg-cover univer-bg-center univer-bg-no-repeat`,style:{backgroundImage:`url(${(y==null?void 0:y.avatar)||A})`}}),y?q(`div`,{className:`univer-mb-1 univer-flex univer-h-6 univer-items-center univer-justify-between`,children:[K(`div`,{className:`univer-text-sm univer-font-medium univer-leading-5`,children:(y==null?void 0:y.name)||` `}),q(`div`,{children:[S||c?null:D&&y?K(`div`,{className:`univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-sm univer-text-base hover:univer-bg-gray-50`,onClick:()=>o(y),children:K(V,{})}):null,x&&!S&&!c?K(I,{overlay:K(`div`,{className:`univer-rounded-lg`,children:q(`ul`,{className:`univer-m-0 univer-box-border univer-grid univer-list-none univer-p-1.5 univer-text-sm [&_a]:univer-block [&_a]:univer-cursor-pointer [&_a]:univer-rounded [&_a]:univer-px-2 [&_a]:univer-py-1.5 [&_a]:univer-transition-colors`,children:[K(`li`,{children:K(`a`,{className:`hover:univer-bg-gray-200`,onClick:()=>a==null?void 0:a(!0),children:_.t(`threadCommentUI.item.edit`)})}),K(`li`,{children:K(`a`,{className:`hover:univer-bg-gray-200`,onClick:()=>{(d==null?void 0:d(t))!==!1&&(h.executeCommand(l?ee.id:j.id,{unitId:n,subUnitId:r,commentId:t.id}),l&&(u==null||u()))},children:_.t(`threadCommentUI.item.delete`)})})]})}),children:K(`div`,{className:`univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-sm univer-text-base hover:univer-bg-gray-50`,children:K(oe,{})})}):null]})]}):null,K(`time`,{className:`univer-mb-1 univer-text-xs/normal univer-text-gray-600 dark:!univer-text-gray-200`,children:t.dT}),i?K(Se,{type:p,id:t.id,comment:t,onCancel:()=>a==null?void 0:a(!1),autoFocus:!0,unitId:n,subUnitId:r,editorId:m,onSave:({text:e,attachments:i})=>{a==null||a(!1),h.executeCommand(N.id,{unitId:n,subUnitId:r,payload:{commentId:t.id,text:e,attachments:i}})}}):K(`div`,{className:`univer-text-sm univer-text-gray-900 dark:!univer-text-white`,children:we(t.text).map((e,t)=>K(`div`,{className:`univer-break-words`,children:e.map((e,t)=>{switch(e.type){case`mention`:return q(`a`,{className:`univer-text-primary-600`,children:[e.content.label,` `]},t);default:return e.content}})},t))})]})},ke=e=>{var t,n,i;let{id:a,unitId:o,subUnitId:c,refStr:l,showEdit:u=!0,onClick:d,showHighlight:f,onClose:p,getSubUnitName:m,location:h,autoFocus:v,onMouseEnter:y,onMouseLeave:b,onAddComment:x,onDeleteComment:S,onResolve:C,type:w,style:D,full:k}=e,j=T(ne),[M,N]=W(!1),[F,I]=W(``);E(U(()=>j.commentUpdate$.pipe(O(16)),[j]));let L=a?j.getCommentWithChildren(o,c,a):null,B=T(s),oe=T(g),V=L==null?void 0:L.root.resolved,H=E(oe.currentUser$),ue=de(null),fe=[...L?[L.root]:[{id:De,text:{dataStream:`
4
- \r`},personId:(t=H==null?void 0:H.userID)==null?``:t,ref:l==null?``:l,dT:``,unitId:o,subUnitId:c,threadId:``}],...(n=L==null?void 0:L.children)==null?[]:n],G=de(null),pe=e=>{e.stopPropagation(),V?B.executeCommand(Q.id,{unitId:o,subUnitId:c,commentId:a}):B.executeCommand(Q.id),B.executeCommand(te.id,{unitId:o,subUnitId:c,commentId:a,resolved:!V}),C==null||C(!V)},J=e=>{e.stopPropagation(),B.executeCommand(Q.id),!(L!=null&&L.root&&(S==null?void 0:S(L.root))===!1)&&(B.executeCommand(ee.id,{unitId:o,subUnitId:c,commentId:a}),p==null||p())};le(()=>b==null?void 0:b(),[]);let me=m((i=L==null?void 0:L.root.subUnitId)==null?c:i),he=u&&!F&&!V,Y=`${l||(L==null?void 0:L.root.ref)||``}${me?` · `:``}${me}`,X=`${r}_${h}`;return q(`div`,{id:`${h}-${o}-${c}-${a}`,className:z(`univer-relative univer-box-border univer-rounded-md univer-bg-white univer-p-4 dark:!univer-bg-gray-900 dark:!univer-text-white`,re,{"univer-w-[278px]":!k,"univer-w-full":k,"univer-shadow":!V&&(f||M||h===Ee.CELL)}),style:D,onClick:d,onMouseEnter:()=>{y==null||y(),N(!0)},onMouseLeave:()=>{b==null||b(),N(!1)},children:[!V&&f&&K(`div`,{className:`univer-absolute univer-left-0 univer-right-0 univer-top-0 univer-h-1.5 univer-rounded-t-md univer-bg-yellow-400`}),q(`div`,{className:`univer-mb-4 univer-flex univer-flex-row univer-items-center univer-justify-between univer-text-sm univer-leading-5`,children:[q(`div`,{className:`univer-flex univer-flex-1 univer-flex-row univer-items-center univer-overflow-hidden`,children:[K(`div`,{className:`univer-mr-2 univer-h-3.5 univer-w-[3px] univer-flex-shrink-0 univer-flex-grow-0 univer-rounded-sm univer-bg-yellow-500`}),K(R,{showIfEllipsis:!0,title:Y,children:K(`span`,{className:`univer-flex-1 univer-truncate`,children:Y})})]}),!!L&&q(`div`,{className:`univer-flex univer-flex-shrink-0 univer-flex-grow-0 univer-flex-row`,children:[K(`div`,{className:z(`univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-[3px] univer-text-base hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-800`,{"univer-text-green-500":V}),onClick:pe,children:K(V?se:ce,{})}),(H==null?void 0:H.userID)===L.root.personId?K(`div`,{className:`univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-[3px] univer-text-base hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-800`,onClick:J,children:K(ae,{})}):null]})]}),K(`div`,{ref:G,className:z(`univer-max-h-80 univer-overflow-y-auto univer-overflow-x-hidden`,ie),children:fe.map(e=>K(Oe,{unitId:o,subUnitId:c,item:e,isRoot:e.id===(L==null?void 0:L.root.id),editing:F===e.id,resolved:L==null?void 0:L.root.resolved,type:w,threadCommentEditorId:X,onClose:p,onEditingChange:t=>{I(t?e.id:``)},onReply:e=>{e&&requestAnimationFrame(()=>{var t;(t=ue.current)==null||t.reply(Te([{type:`mention`,content:{id:e.userID,label:`@${e.name}`}},{type:`text`,content:` `}]))})},onAddComment:x,onDeleteComment:S},e.id))}),he&&K(`div`,{children:K(Se,{ref:ue,type:w,unitId:o,subUnitId:c,editorId:X,onSave:async({text:e,attachments:t})=>{var n,r;let i={text:e,attachments:t,dT:P(),id:_(),ref:l,personId:(n=H==null?void 0:H.userID)==null?``:n,parentId:L==null?void 0:L.root.id,unitId:o,subUnitId:c,threadId:(r=L==null?void 0:L.root.threadId)==null?``:r};(x==null?void 0:x(i))!==!1&&(await B.executeCommand(A.id,{unitId:o,subUnitId:c,comment:i}),G.current&&(G.current.scrollTop=G.current.scrollHeight))},autoFocus:v||!L,onCancel:()=>{L||p==null||p()}},`${v}`)})]})},Ae=e=>{let{unitId:t,subUnitId$:n,type:r,onAdd:i,getSubUnitName:a,onResolve:o,sortComments:c,onItemLeave:l,onItemEnter:u,disableAdd:d,tempComment:p,onAddComment:m,onDeleteComment:_,showComments:v}=e,[y,b]=W(`all`),[x,S]=W(`all`),C=T(f),w=T(g),D=T(ne),[O,k]=W(()=>D.getUnit(t)),A=E(T(Z).activeCommentId$),j=E(D.commentUpdate$),ee=T(s),te=E(n),M=de(!0),N=Ee.PANEL,P=E(w.currentUser$),I=U(()=>{var e;let t=y===`all`?O:(e=O.filter(e=>e.subUnitId===te))==null?[]:e,n=c==null?(e=>e):c,r=t.map(e=>{var t;return{...e.root,children:(t=e.children)==null?[]:t,users:e.relativeUsers}});if(v){let e=new Map;return r.forEach(t=>{e.set(t.id,t)}),[...v,``].map(t=>e.get(t)).filter(Boolean)}else return n(r)},[v,y,O,c,te]),R=U(()=>[...I.filter(e=>!e.resolved),...I.filter(e=>e.resolved)],[I]),re=U(()=>x===`resolved`?R.filter(e=>e.resolved):x===`unsolved`?R.filter(e=>!e.resolved):x===`concern_me`&&P!=null&&P.userID?R.filter(e=>e==null?void 0:e.users.has(P.userID)):R,[R,P==null?void 0:P.userID,x]),z=p?[p,...re]:re,ie=z.filter(e=>!e.resolved),ae=z.filter(e=>e.resolved),oe=x!==`all`||y!==`all`,V=()=>{S(`all`),b(`all`)};le(()=>{t&&k(D.getUnit(t))},[t,D,j]),le(()=>{var e;if(!A)return;if(!M.current){M.current=!0;return}let{unitId:t,subUnitId:n,commentId:r}=A,i=`${N}-${t}-${n}-${r}`;(e=document.getElementById(i))==null||e.scrollIntoView({block:`center`})},[A]);let se=e=>K(ke,{location:N,getSubUnitName:a,id:e.id,unitId:e.unitId,subUnitId:e.subUnitId,refStr:e.ref,type:r,showEdit:(A==null?void 0:A.commentId)===e.id,showHighlight:(A==null?void 0:A.commentId)===e.id,onClick:()=>{M.current=!1,e.resolved?ee.executeCommand(Q.id):ee.executeCommand(Q.id,{unitId:e.unitId,subUnitId:e.subUnitId,commentId:e.id,temp:!1})},onMouseEnter:()=>u==null?void 0:u(e),onMouseLeave:()=>l==null?void 0:l(e),onAddComment:m,onDeleteComment:_,onResolve:t=>o==null?void 0:o(e.id,t)},e.id);return q(`div`,{className:`univer-flex univer-min-h-full univer-flex-col univer-pb-3`,children:[q(`div`,{className:`univer-mt-3 univer-flex univer-flex-row univer-justify-between`,children:[r===h.UNIVER_SHEET?K(L,{borderless:!0,value:y,options:[{value:`current`,label:C.t(`threadCommentUI.filter.sheet.current`)},{value:`all`,label:C.t(`threadCommentUI.filter.sheet.all`)}],onChange:b}):null,K(L,{borderless:!0,value:x,options:[{value:`all`,label:C.t(`threadCommentUI.filter.status.all`)},{value:`resolved`,label:C.t(`threadCommentUI.filter.status.resolved`)},{value:`unsolved`,label:C.t(`threadCommentUI.filter.status.unsolved`)},{value:`concern_me`,label:C.t(`threadCommentUI.filter.status.concernMe`)}],onChange:S})]}),z.length===0?q(`div`,{className:`univer-flex univer-flex-1 univer-flex-col univer-items-center univer-justify-center univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200`,children:[C.t(`threadCommentUI.panel.empty`),oe?K(`div`,{className:`univer-mt-2 univer-flex univer-flex-row`,children:K(F,{onClick:V,children:C.t(`threadCommentUI.panel.reset`)})}):d?null:K(`div`,{className:`univer-mt-2 univer-flex univer-flex-row`,children:q(F,{onClick:i,children:[K(B,{className:`univer-mr-1.5`}),C.t(`threadCommentUI.panel.addComment`)]})})]}):q(`div`,{className:`univer-mt-3 univer-flex univer-flex-col univer-gap-3`,children:[ie.map(se),ae.length>0&&K(`div`,{className:`univer-text-xs`,children:C.t(`threadCommentUI.panel.solved`)}),ae.map(se)]})]})};export{Q as SetActiveCommentOperation,Ae as ThreadCommentPanel,Z as ThreadCommentPanelService,ke as ThreadCommentTree,Ee as ThreadCommentTreeLocation,$ as UniverThreadCommentUIPlugin};
1
+ import { BuildTextUtils, CommandType, CustomRangeType, DOCS_COMMENT_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Disposable, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, Tools, UniverInstanceType, UserManagerService, generateRandomId, getBodySlice, merge, mergeOverrideWithDependencies } from "@univerjs/core";
2
+ import { ISidebarService, KeyCode, UI_PLUGIN_CONFIG_KEY, useConfigValue, useDependency, useObservable } from "@univerjs/ui";
3
+ import { BehaviorSubject, debounceTime, filter } from "rxjs";
4
+ import { AddCommentCommand, DeleteCommentCommand, DeleteCommentTreeCommand, ResolveCommentCommand, ThreadCommentModel, UniverThreadCommentPlugin, UpdateCommentCommand, getDT } from "@univerjs/thread-comment";
5
+ import { Button, Dropdown, Select, Tooltip, borderClassName, clsx, scrollbarClassName } from "@univerjs/design";
6
+ import { DeleteIcon, IncreaseIcon, MoreHorizontalIcon, ReplyToCommentIcon, ResolvedIcon, SolveIcon } from "@univerjs/icons";
7
+ import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
8
+ import { BreakLineCommand, IEditorService, RichTextEditor } from "@univerjs/docs-ui";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+
11
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
12
+ function _typeof(o) {
13
+ "@babel/helpers - typeof";
14
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
15
+ return typeof o;
16
+ } : function(o) {
17
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
18
+ }, _typeof(o);
19
+ }
20
+
21
+ //#endregion
22
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
23
+ function toPrimitive(t, r) {
24
+ if ("object" != _typeof(t) || !t) return t;
25
+ var e = t[Symbol.toPrimitive];
26
+ if (void 0 !== e) {
27
+ var i = e.call(t, r || "default");
28
+ if ("object" != _typeof(i)) return i;
29
+ throw new TypeError("@@toPrimitive must return a primitive value.");
30
+ }
31
+ return ("string" === r ? String : Number)(t);
32
+ }
33
+
34
+ //#endregion
35
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
36
+ function toPropertyKey(t) {
37
+ var i = toPrimitive(t, "string");
38
+ return "symbol" == _typeof(i) ? i : i + "";
39
+ }
40
+
41
+ //#endregion
42
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
43
+ function _defineProperty(e, r, t) {
44
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
45
+ value: t,
46
+ enumerable: !0,
47
+ configurable: !0,
48
+ writable: !0
49
+ }) : e[r] = t, e;
50
+ }
51
+
52
+ //#endregion
53
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
54
+ function __decorateParam(paramIndex, decorator) {
55
+ return function(target, key) {
56
+ decorator(target, key, paramIndex);
57
+ };
58
+ }
59
+
60
+ //#endregion
61
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
62
+ function __decorate(decorators, target, key, desc) {
63
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
64
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
65
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
66
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
67
+ }
68
+
69
+ //#endregion
70
+ //#region src/services/thread-comment-panel.service.ts
71
+ let ThreadCommentPanelService = class ThreadCommentPanelService extends Disposable {
72
+ constructor(_sidebarService, _univerInstanceService) {
73
+ super();
74
+ this._sidebarService = _sidebarService;
75
+ this._univerInstanceService = _univerInstanceService;
76
+ _defineProperty(this, "_panelVisible", false);
77
+ _defineProperty(this, "_panelVisible$", new BehaviorSubject(false));
78
+ _defineProperty(this, "_activeCommentId", void 0);
79
+ _defineProperty(this, "_activeCommentId$", new BehaviorSubject(void 0));
80
+ _defineProperty(this, "panelVisible$", this._panelVisible$.asObservable());
81
+ _defineProperty(this, "activeCommentId$", this._activeCommentId$.asObservable());
82
+ this._init();
83
+ this.disposeWithMe(() => {
84
+ this._activeCommentId$.complete();
85
+ this._panelVisible$.complete();
86
+ });
87
+ }
88
+ _init() {
89
+ this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe((opt) => {
90
+ if (!opt.visible) this.setPanelVisible(false);
91
+ }));
92
+ this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(filter((sheet) => !sheet)).subscribe(() => {
93
+ this._sidebarService.close();
94
+ }));
95
+ }
96
+ get panelVisible() {
97
+ return this._panelVisible;
98
+ }
99
+ get activeCommentId() {
100
+ return this._activeCommentId;
101
+ }
102
+ setPanelVisible(visible) {
103
+ this._panelVisible = visible;
104
+ this._panelVisible$.next(visible);
105
+ }
106
+ setActiveComment(commentInfo) {
107
+ this._activeCommentId = commentInfo;
108
+ this._activeCommentId$.next(commentInfo);
109
+ }
110
+ };
111
+ ThreadCommentPanelService = __decorate([__decorateParam(0, Inject(ISidebarService)), __decorateParam(1, IUniverInstanceService)], ThreadCommentPanelService);
112
+
113
+ //#endregion
114
+ //#region src/commands/operations/comment.operations.ts
115
+ const SetActiveCommentOperation = {
116
+ id: "thread-comment-ui.operation.set-active-comment",
117
+ type: CommandType.OPERATION,
118
+ handler(accessor, params) {
119
+ accessor.get(ThreadCommentPanelService).setActiveComment(params);
120
+ return true;
121
+ }
122
+ };
123
+
124
+ //#endregion
125
+ //#region package.json
126
+ var name = "@univerjs/thread-comment-ui";
127
+ var version = "0.21.0";
128
+
129
+ //#endregion
130
+ //#region src/config/config.ts
131
+ const THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY = "thread-comment-ui.config";
132
+ const configSymbol = Symbol(THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY);
133
+ const defaultPluginConfig = {};
134
+
135
+ //#endregion
136
+ //#region src/types/const.ts
137
+ /**
138
+ * Copyright 2023-present DreamNum Co., Ltd.
139
+ *
140
+ * Licensed under the Apache License, Version 2.0 (the "License");
141
+ * you may not use this file except in compliance with the License.
142
+ * You may obtain a copy of the License at
143
+ *
144
+ * http://www.apache.org/licenses/LICENSE-2.0
145
+ *
146
+ * Unless required by applicable law or agreed to in writing, software
147
+ * distributed under the License is distributed on an "AS IS" BASIS,
148
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
149
+ * See the License for the specific language governing permissions and
150
+ * limitations under the License.
151
+ */
152
+ const PLUGIN_NAME = "UNIVER_THREAD_COMMENT_UI_PLUGIN";
153
+
154
+ //#endregion
155
+ //#region src/plugin.ts
156
+ let UniverThreadCommentUIPlugin = class UniverThreadCommentUIPlugin extends Plugin {
157
+ constructor(_config = defaultPluginConfig, _injector, _commandService, _configService) {
158
+ super();
159
+ this._config = _config;
160
+ this._injector = _injector;
161
+ this._commandService = _commandService;
162
+ this._configService = _configService;
163
+ const { menu, ...rest } = merge({}, defaultPluginConfig, this._config);
164
+ if (menu) this._configService.setConfig("menu", menu, { merge: true });
165
+ this._configService.setConfig(THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY, rest);
166
+ }
167
+ onStarting() {
168
+ var _this$_config;
169
+ mergeOverrideWithDependencies([[ThreadCommentPanelService]], (_this$_config = this._config) === null || _this$_config === void 0 ? void 0 : _this$_config.overrides).forEach((dep) => {
170
+ this._injector.add(dep);
171
+ });
172
+ [SetActiveCommentOperation].forEach((command) => {
173
+ this._commandService.registerCommand(command);
174
+ });
175
+ }
176
+ };
177
+ _defineProperty(UniverThreadCommentUIPlugin, "pluginName", PLUGIN_NAME);
178
+ _defineProperty(UniverThreadCommentUIPlugin, "packageName", name);
179
+ _defineProperty(UniverThreadCommentUIPlugin, "version", version);
180
+ _defineProperty(UniverThreadCommentUIPlugin, "type", UniverInstanceType.UNIVER_UNKNOWN);
181
+ UniverThreadCommentUIPlugin = __decorate([
182
+ DependentOn(UniverThreadCommentPlugin),
183
+ __decorateParam(1, Inject(Injector)),
184
+ __decorateParam(2, ICommandService),
185
+ __decorateParam(3, IConfigService)
186
+ ], UniverThreadCommentUIPlugin);
187
+
188
+ //#endregion
189
+ //#region src/views/thread-comment-editor/index.tsx
190
+ function getSnapshot(body) {
191
+ return {
192
+ id: "d",
193
+ body,
194
+ documentStyle: {}
195
+ };
196
+ }
197
+ const ThreadCommentEditor = forwardRef((props, ref) => {
198
+ var _editor$current5;
199
+ const { comment, onSave, id, onCancel, autoFocus, unitId, type, editorId } = props;
200
+ const commandService = useDependency(ICommandService);
201
+ const localeService = useDependency(LocaleService);
202
+ const [editing, setEditing] = useState(false);
203
+ const editorService = useDependency(IEditorService);
204
+ const editor = useRef(null);
205
+ const rootEditorId = type === UniverInstanceType.UNIVER_DOC ? DOCS_NORMAL_EDITOR_UNIT_ID_KEY : unitId;
206
+ const [canSubmit, setCanSubmit] = useState(() => {
207
+ var _editor$current$getDo, _editor$current;
208
+ return BuildTextUtils.transform.getPlainText((_editor$current$getDo = (_editor$current = editor.current) === null || _editor$current === void 0 || (_editor$current = _editor$current.getDocumentData().body) === null || _editor$current === void 0 ? void 0 : _editor$current.dataStream) !== null && _editor$current$getDo !== void 0 ? _editor$current$getDo : "");
209
+ });
210
+ useEffect(() => {
211
+ var _editor$current$getDo2, _editor$current2, _editor$current3;
212
+ setCanSubmit(BuildTextUtils.transform.getPlainText((_editor$current$getDo2 = (_editor$current2 = editor.current) === null || _editor$current2 === void 0 || (_editor$current2 = _editor$current2.getDocumentData().body) === null || _editor$current2 === void 0 ? void 0 : _editor$current2.dataStream) !== null && _editor$current$getDo2 !== void 0 ? _editor$current$getDo2 : ""));
213
+ const sub = (_editor$current3 = editor.current) === null || _editor$current3 === void 0 ? void 0 : _editor$current3.selectionChange$.subscribe(() => {
214
+ var _editor$current$getDo3, _editor$current4;
215
+ setCanSubmit(BuildTextUtils.transform.getPlainText((_editor$current$getDo3 = (_editor$current4 = editor.current) === null || _editor$current4 === void 0 || (_editor$current4 = _editor$current4.getDocumentData().body) === null || _editor$current4 === void 0 ? void 0 : _editor$current4.dataStream) !== null && _editor$current$getDo3 !== void 0 ? _editor$current$getDo3 : ""));
216
+ });
217
+ return () => sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
218
+ }, [(_editor$current5 = editor.current) === null || _editor$current5 === void 0 ? void 0 : _editor$current5.selectionChange$]);
219
+ const keyboardEventConfig = useMemo(() => ({
220
+ keyCodes: [{ keyCode: KeyCode.ENTER }],
221
+ handler: (keyCode) => {
222
+ if (keyCode === KeyCode.ENTER) commandService.executeCommand(BreakLineCommand.id);
223
+ }
224
+ }), [commandService]);
225
+ useImperativeHandle(ref, () => ({ reply(text) {
226
+ var _getEditorId, _editor$current6;
227
+ if (!editor.current) return;
228
+ editorService.focus((_getEditorId = editor.current.getEditorId()) !== null && _getEditorId !== void 0 ? _getEditorId : "");
229
+ const documentData = getSnapshot(text);
230
+ (_editor$current6 = editor.current) === null || _editor$current6 === void 0 || _editor$current6.setDocumentData(documentData, [{
231
+ startOffset: documentData.body.dataStream.length - 2,
232
+ endOffset: documentData.body.dataStream.length - 2,
233
+ collapsed: true
234
+ }]);
235
+ } }));
236
+ const handleSave = () => {
237
+ if (editor.current) {
238
+ const newText = Tools.deepClone(editor.current.getDocumentData().body);
239
+ setEditing(false);
240
+ onSave === null || onSave === void 0 || onSave({
241
+ ...comment,
242
+ text: newText
243
+ });
244
+ editor.current.replaceText("");
245
+ setTimeout(() => {
246
+ var _editor$current7, _editor$current8;
247
+ (_editor$current7 = editor.current) === null || _editor$current7 === void 0 || _editor$current7.setSelectionRanges([]);
248
+ (_editor$current8 = editor.current) === null || _editor$current8 === void 0 || _editor$current8.blur();
249
+ }, 10);
250
+ }
251
+ };
252
+ return /* @__PURE__ */ jsxs("div", {
253
+ onClick: (e) => e.preventDefault(),
254
+ children: [/* @__PURE__ */ jsx(RichTextEditor, {
255
+ className: "univer-w-full",
256
+ editorRef: editor,
257
+ editorId,
258
+ autoFocus,
259
+ keyboardEventConfig,
260
+ placeholder: localeService.t("threadCommentUI.editor.placeholder"),
261
+ initialValue: (comment === null || comment === void 0 ? void 0 : comment.text) && getSnapshot(comment.text),
262
+ onFocusChange: (isFocus) => isFocus && setEditing(isFocus),
263
+ isSingle: false,
264
+ maxHeight: 64,
265
+ onClickOutside: () => {
266
+ setTimeout(() => {
267
+ editorService.focus(rootEditorId);
268
+ }, 30);
269
+ }
270
+ }), editing ? /* @__PURE__ */ jsxs("div", {
271
+ className: "univer-mt-3 univer-flex univer-flex-row univer-justify-end univer-gap-2",
272
+ children: [/* @__PURE__ */ jsx(Button, {
273
+ onClick: () => {
274
+ var _editor$current9;
275
+ onCancel === null || onCancel === void 0 || onCancel();
276
+ setEditing(false);
277
+ (_editor$current9 = editor.current) === null || _editor$current9 === void 0 || _editor$current9.replaceText("", true);
278
+ commandService.executeCommand(SetActiveCommentOperation.id);
279
+ },
280
+ children: localeService.t("threadCommentUI.editor.cancel")
281
+ }), /* @__PURE__ */ jsx(Button, {
282
+ variant: "primary",
283
+ disabled: !canSubmit,
284
+ onClick: handleSave,
285
+ children: localeService.t(id ? "threadCommentUI.editor.save" : "threadCommentUI.editor.reply")
286
+ })]
287
+ }) : null]
288
+ });
289
+ });
290
+
291
+ //#endregion
292
+ //#region src/views/thread-comment-editor/util.ts
293
+ const transformDocument2TextNodesInParagraph = (doc) => {
294
+ const { dataStream, customRanges } = doc;
295
+ const end = dataStream.endsWith("\r\n") ? dataStream.length - 2 : dataStream.length;
296
+ const textNodes = [];
297
+ let lastIndex = 0;
298
+ customRanges === null || customRanges === void 0 || customRanges.forEach((range) => {
299
+ if (lastIndex < range.startIndex) textNodes.push({
300
+ type: "text",
301
+ content: dataStream.slice(lastIndex, range.startIndex)
302
+ });
303
+ textNodes.push({
304
+ type: "mention",
305
+ content: {
306
+ label: dataStream.slice(range.startIndex, range.endIndex + 1),
307
+ id: range.rangeId
308
+ }
309
+ });
310
+ lastIndex = range.endIndex + 1;
311
+ });
312
+ textNodes.push({
313
+ type: "text",
314
+ content: dataStream.slice(lastIndex, end)
315
+ });
316
+ return textNodes;
317
+ };
318
+ const transformDocument2TextNodes = (doc) => {
319
+ if (!doc) return [];
320
+ const { paragraphs = [] } = doc;
321
+ return paragraphs.map((paragraph, index) => {
322
+ return transformDocument2TextNodesInParagraph(getBodySlice(doc, index === 0 ? 0 : paragraphs[index - 1].startIndex + 1, paragraph.startIndex));
323
+ });
324
+ };
325
+ const transformTextNodes2Document = (nodes) => {
326
+ let str = "";
327
+ const customRanges = [];
328
+ nodes.forEach((node) => {
329
+ switch (node.type) {
330
+ case "text":
331
+ str += node.content;
332
+ break;
333
+ case "mention": {
334
+ const start = str.length;
335
+ str += node.content.label;
336
+ const end = str.length - 1;
337
+ customRanges.push({
338
+ rangeId: node.content.id,
339
+ rangeType: CustomRangeType.MENTION,
340
+ startIndex: start,
341
+ endIndex: end,
342
+ properties: {},
343
+ wholeEntity: true
344
+ });
345
+ break;
346
+ }
347
+ default: break;
348
+ }
349
+ });
350
+ str += "\r\n";
351
+ return {
352
+ textRuns: [],
353
+ paragraphs: [{
354
+ startIndex: str.length - 2,
355
+ paragraphStyle: {}
356
+ }],
357
+ sectionBreaks: [{ startIndex: str.length - 1 }],
358
+ dataStream: str,
359
+ customRanges
360
+ };
361
+ };
362
+
363
+ //#endregion
364
+ //#region src/views/thread-comment-tree/index.tsx
365
+ let ThreadCommentTreeLocation = /* @__PURE__ */ function(ThreadCommentTreeLocation) {
366
+ ThreadCommentTreeLocation["CELL"] = "CELL";
367
+ ThreadCommentTreeLocation["PANEL"] = "PANEL";
368
+ return ThreadCommentTreeLocation;
369
+ }({});
370
+ const MOCK_ID = "__mock__";
371
+ const ThreadCommentItem = (props) => {
372
+ const { item, unitId, subUnitId, editing, onEditingChange, onReply, resolved, isRoot, onClose, onDeleteComment, type, threadCommentEditorId } = props;
373
+ const commandService = useDependency(ICommandService);
374
+ const localeService = useDependency(LocaleService);
375
+ const userManagerService = useDependency(UserManagerService);
376
+ const user = userManagerService.getUser(item.personId);
377
+ const currentUser = useObservable(userManagerService.currentUser$);
378
+ const isCommentBySelf = (currentUser === null || currentUser === void 0 ? void 0 : currentUser.userID) === item.personId;
379
+ const isMock = item.id === MOCK_ID;
380
+ const [showReply, setShowReply] = useState(false);
381
+ const uiConfig = useConfigValue(UI_PLUGIN_CONFIG_KEY);
382
+ const avatarFallback = uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.avatarFallback;
383
+ const handleDeleteItem = () => {
384
+ if ((onDeleteComment === null || onDeleteComment === void 0 ? void 0 : onDeleteComment(item)) === false) return;
385
+ commandService.executeCommand(isRoot ? DeleteCommentTreeCommand.id : DeleteCommentCommand.id, {
386
+ unitId,
387
+ subUnitId,
388
+ commentId: item.id
389
+ });
390
+ if (isRoot) onClose === null || onClose === void 0 || onClose();
391
+ };
392
+ return /* @__PURE__ */ jsxs("div", {
393
+ className: "univer-relative univer-mb-3 univer-pl-[30px]",
394
+ onMouseLeave: () => setShowReply(false),
395
+ onMouseEnter: () => setShowReply(true),
396
+ children: [
397
+ /* @__PURE__ */ jsx("div", {
398
+ className: "univer-absolute univer-left-0 univer-top-0 univer-size-6 univer-rounded-full univer-bg-cover univer-bg-center univer-bg-no-repeat",
399
+ style: { backgroundImage: `url(${(user === null || user === void 0 ? void 0 : user.avatar) || avatarFallback})` }
400
+ }),
401
+ user ? /* @__PURE__ */ jsxs("div", {
402
+ className: "univer-mb-1 univer-flex univer-h-6 univer-items-center univer-justify-between",
403
+ children: [/* @__PURE__ */ jsx("div", {
404
+ className: "univer-text-sm univer-font-medium univer-leading-5",
405
+ children: (user === null || user === void 0 ? void 0 : user.name) || " "
406
+ }), /* @__PURE__ */ jsxs("div", { children: [isMock || resolved ? null : showReply && user ? /* @__PURE__ */ jsx("div", {
407
+ className: "univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-sm univer-text-base hover:univer-bg-gray-50",
408
+ onClick: () => onReply(user),
409
+ children: /* @__PURE__ */ jsx(ReplyToCommentIcon, {})
410
+ }) : null, isCommentBySelf && !isMock && !resolved ? /* @__PURE__ */ jsx(Dropdown, {
411
+ overlay: /* @__PURE__ */ jsx("div", {
412
+ className: "univer-rounded-lg",
413
+ children: /* @__PURE__ */ jsxs("ul", {
414
+ className: "univer-m-0 univer-box-border univer-grid univer-list-none univer-p-1.5 univer-text-sm [&_a]:univer-block [&_a]:univer-cursor-pointer [&_a]:univer-rounded [&_a]:univer-px-2 [&_a]:univer-py-1.5 [&_a]:univer-transition-colors",
415
+ children: [/* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("a", {
416
+ className: "hover:univer-bg-gray-200",
417
+ onClick: () => onEditingChange === null || onEditingChange === void 0 ? void 0 : onEditingChange(true),
418
+ children: localeService.t("threadCommentUI.item.edit")
419
+ }) }), /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("a", {
420
+ className: "hover:univer-bg-gray-200",
421
+ onClick: handleDeleteItem,
422
+ children: localeService.t("threadCommentUI.item.delete")
423
+ }) })]
424
+ })
425
+ }),
426
+ children: /* @__PURE__ */ jsx("div", {
427
+ className: "univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-sm univer-text-base hover:univer-bg-gray-50",
428
+ children: /* @__PURE__ */ jsx(MoreHorizontalIcon, {})
429
+ })
430
+ }) : null] })]
431
+ }) : null,
432
+ /* @__PURE__ */ jsx("time", {
433
+ className: "univer-mb-1 univer-text-xs/normal univer-text-gray-600 dark:!univer-text-gray-200",
434
+ children: item.dT
435
+ }),
436
+ editing ? /* @__PURE__ */ jsx(ThreadCommentEditor, {
437
+ type,
438
+ id: item.id,
439
+ comment: item,
440
+ onCancel: () => onEditingChange === null || onEditingChange === void 0 ? void 0 : onEditingChange(false),
441
+ autoFocus: true,
442
+ unitId,
443
+ subUnitId,
444
+ editorId: threadCommentEditorId,
445
+ onSave: ({ text, attachments }) => {
446
+ onEditingChange === null || onEditingChange === void 0 || onEditingChange(false);
447
+ commandService.executeCommand(UpdateCommentCommand.id, {
448
+ unitId,
449
+ subUnitId,
450
+ payload: {
451
+ commentId: item.id,
452
+ text,
453
+ attachments
454
+ }
455
+ });
456
+ }
457
+ }) : /* @__PURE__ */ jsx("div", {
458
+ className: "univer-text-sm univer-text-gray-900 dark:!univer-text-white",
459
+ children: transformDocument2TextNodes(item.text).map((paragraph, i) => /* @__PURE__ */ jsx("div", {
460
+ className: "univer-break-words",
461
+ children: paragraph.map((item, i) => {
462
+ switch (item.type) {
463
+ case "mention": return /* @__PURE__ */ jsxs("a", {
464
+ className: "univer-text-primary-600",
465
+ children: [item.content.label, " "]
466
+ }, i);
467
+ default: return item.content;
468
+ }
469
+ })
470
+ }, i))
471
+ })
472
+ ]
473
+ });
474
+ };
475
+ const ThreadCommentTree = (props) => {
476
+ var _currentUser$userID, _comments$children, _comments$root$subUni;
477
+ const { id, unitId, subUnitId, refStr, showEdit = true, onClick, showHighlight, onClose, getSubUnitName, location, autoFocus, onMouseEnter, onMouseLeave, onAddComment, onDeleteComment, onResolve, type, style, full } = props;
478
+ const threadCommentModel = useDependency(ThreadCommentModel);
479
+ const [isHover, setIsHover] = useState(false);
480
+ const [editingId, setEditingId] = useState("");
481
+ useObservable(useMemo(() => threadCommentModel.commentUpdate$.pipe(debounceTime(16)), [threadCommentModel]));
482
+ const comments = id ? threadCommentModel.getCommentWithChildren(unitId, subUnitId, id) : null;
483
+ const commandService = useDependency(ICommandService);
484
+ const userManagerService = useDependency(UserManagerService);
485
+ const resolved = comments === null || comments === void 0 ? void 0 : comments.root.resolved;
486
+ const currentUser = useObservable(userManagerService.currentUser$);
487
+ const editorRef = useRef(null);
488
+ const renderComments = [...comments ? [comments.root] : [{
489
+ id: MOCK_ID,
490
+ text: { dataStream: "\n\r" },
491
+ personId: (_currentUser$userID = currentUser === null || currentUser === void 0 ? void 0 : currentUser.userID) !== null && _currentUser$userID !== void 0 ? _currentUser$userID : "",
492
+ ref: refStr !== null && refStr !== void 0 ? refStr : "",
493
+ dT: "",
494
+ unitId,
495
+ subUnitId,
496
+ threadId: ""
497
+ }], ...(_comments$children = comments === null || comments === void 0 ? void 0 : comments.children) !== null && _comments$children !== void 0 ? _comments$children : []];
498
+ const scroller = useRef(null);
499
+ const handleResolve = (e) => {
500
+ e.stopPropagation();
501
+ if (!resolved) commandService.executeCommand(SetActiveCommentOperation.id);
502
+ else commandService.executeCommand(SetActiveCommentOperation.id, {
503
+ unitId,
504
+ subUnitId,
505
+ commentId: id
506
+ });
507
+ commandService.executeCommand(ResolveCommentCommand.id, {
508
+ unitId,
509
+ subUnitId,
510
+ commentId: id,
511
+ resolved: !resolved
512
+ });
513
+ onResolve === null || onResolve === void 0 || onResolve(!resolved);
514
+ };
515
+ const handleDeleteRoot = (e) => {
516
+ e.stopPropagation();
517
+ commandService.executeCommand(SetActiveCommentOperation.id);
518
+ if ((comments === null || comments === void 0 ? void 0 : comments.root) && (onDeleteComment === null || onDeleteComment === void 0 ? void 0 : onDeleteComment(comments.root)) === false) return;
519
+ commandService.executeCommand(DeleteCommentTreeCommand.id, {
520
+ unitId,
521
+ subUnitId,
522
+ commentId: id
523
+ });
524
+ onClose === null || onClose === void 0 || onClose();
525
+ };
526
+ useEffect(() => {
527
+ return onMouseLeave === null || onMouseLeave === void 0 ? void 0 : onMouseLeave();
528
+ }, []);
529
+ const subUnitName = getSubUnitName((_comments$root$subUni = comments === null || comments === void 0 ? void 0 : comments.root.subUnitId) !== null && _comments$root$subUni !== void 0 ? _comments$root$subUni : subUnitId);
530
+ const editorVisible = showEdit && !editingId && !resolved;
531
+ const title = `${refStr || (comments === null || comments === void 0 ? void 0 : comments.root.ref) || ""}${subUnitName ? " · " : ""}${subUnitName}`;
532
+ const threadCommentEditorId = `${DOCS_COMMENT_EDITOR_UNIT_ID_KEY}_${location}`;
533
+ return /* @__PURE__ */ jsxs("div", {
534
+ id: `${location}-${unitId}-${subUnitId}-${id}`,
535
+ className: clsx("univer-relative univer-box-border univer-rounded-md univer-bg-white univer-p-4 dark:!univer-bg-gray-900 dark:!univer-text-white", borderClassName, {
536
+ "univer-w-[278px]": !full,
537
+ "univer-w-full": full,
538
+ "univer-shadow": !resolved && (showHighlight || isHover || location === ThreadCommentTreeLocation.CELL)
539
+ }),
540
+ style,
541
+ onClick,
542
+ onMouseEnter: () => {
543
+ onMouseEnter === null || onMouseEnter === void 0 || onMouseEnter();
544
+ setIsHover(true);
545
+ },
546
+ onMouseLeave: () => {
547
+ onMouseLeave === null || onMouseLeave === void 0 || onMouseLeave();
548
+ setIsHover(false);
549
+ },
550
+ children: [
551
+ !resolved && showHighlight && /* @__PURE__ */ jsx("div", { className: "univer-absolute univer-left-0 univer-right-0 univer-top-0 univer-h-1.5 univer-rounded-t-md univer-bg-yellow-400" }),
552
+ /* @__PURE__ */ jsxs("div", {
553
+ className: "univer-mb-4 univer-flex univer-flex-row univer-items-center univer-justify-between univer-text-sm univer-leading-5",
554
+ children: [/* @__PURE__ */ jsxs("div", {
555
+ className: "univer-flex univer-flex-1 univer-flex-row univer-items-center univer-overflow-hidden",
556
+ children: [/* @__PURE__ */ jsx("div", { className: "univer-mr-2 univer-h-3.5 univer-w-[3px] univer-flex-shrink-0 univer-flex-grow-0 univer-rounded-sm univer-bg-yellow-500" }), /* @__PURE__ */ jsx(Tooltip, {
557
+ showIfEllipsis: true,
558
+ title,
559
+ children: /* @__PURE__ */ jsx("span", {
560
+ className: "univer-flex-1 univer-truncate",
561
+ children: title
562
+ })
563
+ })]
564
+ }), !!comments && /* @__PURE__ */ jsxs("div", {
565
+ className: "univer-flex univer-flex-shrink-0 univer-flex-grow-0 univer-flex-row",
566
+ children: [/* @__PURE__ */ jsx("div", {
567
+ className: clsx("univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-[3px] univer-text-base hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-800", { "univer-text-green-500": resolved }),
568
+ onClick: handleResolve,
569
+ children: resolved ? /* @__PURE__ */ jsx(ResolvedIcon, {}) : /* @__PURE__ */ jsx(SolveIcon, {})
570
+ }), (currentUser === null || currentUser === void 0 ? void 0 : currentUser.userID) === comments.root.personId ? /* @__PURE__ */ jsx("div", {
571
+ className: "univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-[3px] univer-text-base hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-800",
572
+ onClick: handleDeleteRoot,
573
+ children: /* @__PURE__ */ jsx(DeleteIcon, {})
574
+ }) : null]
575
+ })]
576
+ }),
577
+ /* @__PURE__ */ jsx("div", {
578
+ ref: scroller,
579
+ className: clsx("univer-max-h-80 univer-overflow-y-auto univer-overflow-x-hidden", scrollbarClassName),
580
+ children: renderComments.map((item) => /* @__PURE__ */ jsx(ThreadCommentItem, {
581
+ unitId,
582
+ subUnitId,
583
+ item,
584
+ isRoot: item.id === (comments === null || comments === void 0 ? void 0 : comments.root.id),
585
+ editing: editingId === item.id,
586
+ resolved: comments === null || comments === void 0 ? void 0 : comments.root.resolved,
587
+ type,
588
+ threadCommentEditorId,
589
+ onClose,
590
+ onEditingChange: (editing) => {
591
+ if (editing) setEditingId(item.id);
592
+ else setEditingId("");
593
+ },
594
+ onReply: (user) => {
595
+ if (!user) return;
596
+ requestAnimationFrame(() => {
597
+ var _editorRef$current;
598
+ (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 || _editorRef$current.reply(transformTextNodes2Document([{
599
+ type: "mention",
600
+ content: {
601
+ id: user.userID,
602
+ label: `@${user.name}`
603
+ }
604
+ }, {
605
+ type: "text",
606
+ content: " "
607
+ }]));
608
+ });
609
+ },
610
+ onAddComment,
611
+ onDeleteComment
612
+ }, item.id))
613
+ }),
614
+ editorVisible && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(ThreadCommentEditor, {
615
+ ref: editorRef,
616
+ type,
617
+ unitId,
618
+ subUnitId,
619
+ editorId: threadCommentEditorId,
620
+ onSave: async ({ text, attachments }) => {
621
+ var _currentUser$userID2, _comments$root$thread;
622
+ const comment = {
623
+ text,
624
+ attachments,
625
+ dT: getDT(),
626
+ id: generateRandomId(),
627
+ ref: refStr,
628
+ personId: (_currentUser$userID2 = currentUser === null || currentUser === void 0 ? void 0 : currentUser.userID) !== null && _currentUser$userID2 !== void 0 ? _currentUser$userID2 : "",
629
+ parentId: comments === null || comments === void 0 ? void 0 : comments.root.id,
630
+ unitId,
631
+ subUnitId,
632
+ threadId: (_comments$root$thread = comments === null || comments === void 0 ? void 0 : comments.root.threadId) !== null && _comments$root$thread !== void 0 ? _comments$root$thread : ""
633
+ };
634
+ if ((onAddComment === null || onAddComment === void 0 ? void 0 : onAddComment(comment)) === false) return;
635
+ await commandService.executeCommand(AddCommentCommand.id, {
636
+ unitId,
637
+ subUnitId,
638
+ comment
639
+ });
640
+ if (scroller.current) scroller.current.scrollTop = scroller.current.scrollHeight;
641
+ },
642
+ autoFocus: autoFocus || !comments,
643
+ onCancel: () => {
644
+ if (!comments) onClose === null || onClose === void 0 || onClose();
645
+ }
646
+ }, `${autoFocus}`) })
647
+ ]
648
+ });
649
+ };
650
+
651
+ //#endregion
652
+ //#region src/views/thread-comment-panel/index.tsx
653
+ const ThreadCommentPanel = (props) => {
654
+ const { unitId, subUnitId$, type, onAdd, getSubUnitName, onResolve, sortComments, onItemLeave, onItemEnter, disableAdd, tempComment, onAddComment, onDeleteComment, showComments } = props;
655
+ const [unit, setUnit] = useState("all");
656
+ const [status, setStatus] = useState("all");
657
+ const localeService = useDependency(LocaleService);
658
+ const userService = useDependency(UserManagerService);
659
+ const threadCommentModel = useDependency(ThreadCommentModel);
660
+ const [unitComments, setUnitComments] = useState(() => threadCommentModel.getUnit(unitId));
661
+ const activeCommentId = useObservable(useDependency(ThreadCommentPanelService).activeCommentId$);
662
+ const update = useObservable(threadCommentModel.commentUpdate$);
663
+ const commandService = useDependency(ICommandService);
664
+ const subUnitId = useObservable(subUnitId$);
665
+ const shouldScroll = useRef(true);
666
+ const location = ThreadCommentTreeLocation.PANEL;
667
+ const currentUser = useObservable(userService.currentUser$);
668
+ const comments = useMemo(() => {
669
+ var _unitComments$filter;
670
+ const allComments = unit === "all" ? unitComments : (_unitComments$filter = unitComments.filter((i) => i.subUnitId === subUnitId)) !== null && _unitComments$filter !== void 0 ? _unitComments$filter : [];
671
+ const sort = sortComments !== null && sortComments !== void 0 ? sortComments : ((a) => a);
672
+ const res = allComments.map((i) => {
673
+ var _i$children;
674
+ return {
675
+ ...i.root,
676
+ children: (_i$children = i.children) !== null && _i$children !== void 0 ? _i$children : [],
677
+ users: i.relativeUsers
678
+ };
679
+ });
680
+ if (showComments) {
681
+ const map = /* @__PURE__ */ new Map();
682
+ res.forEach((comment) => {
683
+ map.set(comment.id, comment);
684
+ });
685
+ return [...showComments, ""].map((id) => map.get(id)).filter(Boolean);
686
+ } else return sort(res);
687
+ }, [
688
+ showComments,
689
+ unit,
690
+ unitComments,
691
+ sortComments,
692
+ subUnitId
693
+ ]);
694
+ const commentsSorted = useMemo(() => [...comments.filter((comment) => !comment.resolved), ...comments.filter((comment) => comment.resolved)], [comments]);
695
+ const statuedComments = useMemo(() => {
696
+ if (status === "resolved") return commentsSorted.filter((comment) => comment.resolved);
697
+ if (status === "unsolved") return commentsSorted.filter((comment) => !comment.resolved);
698
+ if (status === "concern_me") {
699
+ if (!(currentUser === null || currentUser === void 0 ? void 0 : currentUser.userID)) return commentsSorted;
700
+ return commentsSorted.filter((comment) => comment === null || comment === void 0 ? void 0 : comment.users.has(currentUser.userID));
701
+ }
702
+ return commentsSorted;
703
+ }, [
704
+ commentsSorted,
705
+ currentUser === null || currentUser === void 0 ? void 0 : currentUser.userID,
706
+ status
707
+ ]);
708
+ const renderComments = tempComment ? [tempComment, ...statuedComments] : statuedComments;
709
+ const unSolvedComments = renderComments.filter((comment) => !comment.resolved);
710
+ const solvedComments = renderComments.filter((comment) => comment.resolved);
711
+ const isFiltering = status !== "all" || unit !== "all";
712
+ const onReset = () => {
713
+ setStatus("all");
714
+ setUnit("all");
715
+ };
716
+ useEffect(() => {
717
+ if (unitId) setUnitComments(threadCommentModel.getUnit(unitId));
718
+ }, [
719
+ unitId,
720
+ threadCommentModel,
721
+ update
722
+ ]);
723
+ useEffect(() => {
724
+ var _document$getElementB;
725
+ if (!activeCommentId) return;
726
+ if (!shouldScroll.current) {
727
+ shouldScroll.current = true;
728
+ return;
729
+ }
730
+ const { unitId, subUnitId, commentId } = activeCommentId;
731
+ const id = `${location}-${unitId}-${subUnitId}-${commentId}`;
732
+ (_document$getElementB = document.getElementById(id)) === null || _document$getElementB === void 0 || _document$getElementB.scrollIntoView({ block: "center" });
733
+ }, [activeCommentId]);
734
+ const renderComment = (comment) => /* @__PURE__ */ jsx(ThreadCommentTree, {
735
+ location,
736
+ getSubUnitName,
737
+ id: comment.id,
738
+ unitId: comment.unitId,
739
+ subUnitId: comment.subUnitId,
740
+ refStr: comment.ref,
741
+ type,
742
+ showEdit: (activeCommentId === null || activeCommentId === void 0 ? void 0 : activeCommentId.commentId) === comment.id,
743
+ showHighlight: (activeCommentId === null || activeCommentId === void 0 ? void 0 : activeCommentId.commentId) === comment.id,
744
+ onClick: () => {
745
+ shouldScroll.current = false;
746
+ if (!comment.resolved) commandService.executeCommand(SetActiveCommentOperation.id, {
747
+ unitId: comment.unitId,
748
+ subUnitId: comment.subUnitId,
749
+ commentId: comment.id,
750
+ temp: false
751
+ });
752
+ else commandService.executeCommand(SetActiveCommentOperation.id);
753
+ },
754
+ onMouseEnter: () => onItemEnter === null || onItemEnter === void 0 ? void 0 : onItemEnter(comment),
755
+ onMouseLeave: () => onItemLeave === null || onItemLeave === void 0 ? void 0 : onItemLeave(comment),
756
+ onAddComment,
757
+ onDeleteComment,
758
+ onResolve: (resolved) => onResolve === null || onResolve === void 0 ? void 0 : onResolve(comment.id, resolved)
759
+ }, comment.id);
760
+ return /* @__PURE__ */ jsxs("div", {
761
+ className: "univer-flex univer-min-h-full univer-flex-col univer-pb-3",
762
+ children: [/* @__PURE__ */ jsxs("div", {
763
+ className: "univer-mt-3 univer-flex univer-flex-row univer-justify-between",
764
+ children: [type === UniverInstanceType.UNIVER_SHEET ? /* @__PURE__ */ jsx(Select, {
765
+ borderless: true,
766
+ value: unit,
767
+ options: [{
768
+ value: "current",
769
+ label: localeService.t("threadCommentUI.filter.sheet.current")
770
+ }, {
771
+ value: "all",
772
+ label: localeService.t("threadCommentUI.filter.sheet.all")
773
+ }],
774
+ onChange: setUnit
775
+ }) : null, /* @__PURE__ */ jsx(Select, {
776
+ borderless: true,
777
+ value: status,
778
+ options: [
779
+ {
780
+ value: "all",
781
+ label: localeService.t("threadCommentUI.filter.status.all")
782
+ },
783
+ {
784
+ value: "resolved",
785
+ label: localeService.t("threadCommentUI.filter.status.resolved")
786
+ },
787
+ {
788
+ value: "unsolved",
789
+ label: localeService.t("threadCommentUI.filter.status.unsolved")
790
+ },
791
+ {
792
+ value: "concern_me",
793
+ label: localeService.t("threadCommentUI.filter.status.concernMe")
794
+ }
795
+ ],
796
+ onChange: setStatus
797
+ })]
798
+ }), renderComments.length === 0 ? /* @__PURE__ */ jsxs("div", {
799
+ className: "univer-flex univer-flex-1 univer-flex-col univer-items-center univer-justify-center univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",
800
+ children: [localeService.t("threadCommentUI.panel.empty"), isFiltering ? /* @__PURE__ */ jsx("div", {
801
+ className: "univer-mt-2 univer-flex univer-flex-row",
802
+ children: /* @__PURE__ */ jsx(Button, {
803
+ onClick: onReset,
804
+ children: localeService.t("threadCommentUI.panel.reset")
805
+ })
806
+ }) : !disableAdd ? /* @__PURE__ */ jsx("div", {
807
+ className: "univer-mt-2 univer-flex univer-flex-row",
808
+ children: /* @__PURE__ */ jsxs(Button, {
809
+ onClick: onAdd,
810
+ children: [/* @__PURE__ */ jsx(IncreaseIcon, { className: "univer-mr-1.5" }), localeService.t("threadCommentUI.panel.addComment")]
811
+ })
812
+ }) : null]
813
+ }) : /* @__PURE__ */ jsxs("div", {
814
+ className: "univer-mt-3 univer-flex univer-flex-col univer-gap-3",
815
+ children: [
816
+ unSolvedComments.map(renderComment),
817
+ solvedComments.length > 0 && /* @__PURE__ */ jsx("div", {
818
+ className: "univer-text-xs",
819
+ children: localeService.t("threadCommentUI.panel.solved")
820
+ }),
821
+ solvedComments.map(renderComment)
822
+ ]
823
+ })]
824
+ });
825
+ };
826
+
827
+ //#endregion
828
+ export { SetActiveCommentOperation, ThreadCommentPanel, ThreadCommentPanelService, ThreadCommentTree, ThreadCommentTreeLocation, UniverThreadCommentUIPlugin };