@univerjs/thread-comment-ui 0.10.11 → 0.10.12-nightly.202510251119

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 CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var ye=Object.defineProperty;var Se=(n,e,t)=>e in n?ye(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var K=(n,e,t)=>Se(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),f=require("@univerjs/ui"),re=require("rxjs"),B=require("@univerjs/thread-comment"),s=require("react/jsx-runtime"),U=require("@univerjs/design"),l=require("react"),ie=require("@univerjs/docs-ui");var we=Object.getOwnPropertyDescriptor,_e=(n,e,t,r)=>{for(var i=r>1?void 0:r?we(e,t):e,a=n.length-1,u;a>=0;a--)(u=n[a])&&(i=u(i)||i);return i},ae=(n,e)=>(t,r)=>e(t,r,n);exports.ThreadCommentPanelService=class extends d.Disposable{constructor(t,r){super();K(this,"_panelVisible",!1);K(this,"_panelVisible$",new re.BehaviorSubject(!1));K(this,"_activeCommentId");K(this,"_activeCommentId$",new re.BehaviorSubject(void 0));K(this,"panelVisible$",this._panelVisible$.asObservable());K(this,"activeCommentId$",this._activeCommentId$.asObservable());this._sidebarService=t,this._univerInstanceService=r,this._init(),this.disposeWithMe(()=>{this._activeCommentId$.complete(),this._panelVisible$.complete()})}_init(){this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(t=>{t.visible||this.setPanelVisible(!1)})),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(re.filter(t=>!t)).subscribe(()=>{this._sidebarService.close()}))}get panelVisible(){return this._panelVisible}get activeCommentId(){return this._activeCommentId}setPanelVisible(t){this._panelVisible=t,this._panelVisible$.next(t)}setActiveComment(t){this._activeCommentId=t,this._activeCommentId$.next(t)}};exports.ThreadCommentPanelService=_e([ae(0,d.Inject(f.ISidebarService)),ae(1,d.IUniverInstanceService)],exports.ThreadCommentPanelService);const ce="thread-comment-panel",je="UNIVER_THREAD_COMMENT_UI_PLUGIN",de={id:"thread-comment-ui.operation.toggle-panel",type:d.CommandType.OPERATION,handler(n){const e=n.get(f.ISidebarService),t=n.get(exports.ThreadCommentPanelService);return t.panelVisible?(e.close(),t.setPanelVisible(!1)):(e.open({header:{title:"threadCommentUI.panel.title"},children:{label:ce},width:330}),t.setPanelVisible(!0)),!0}},Z={id:"thread-comment-ui.operation.set-active-comment",type:d.CommandType.OPERATION,handler(n,e){return n.get(exports.ThreadCommentPanelService).setActiveComment(e),!0}},Ne="thread-comment-ui.config",oe={};var Te=Object.defineProperty,Ue=Object.getOwnPropertyDescriptor,Oe=(n,e,t)=>e in n?Te(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Ee=(n,e,t,r)=>{for(var i=r>1?void 0:r?Ue(e,t):e,a=n.length-1,u;a>=0;a--)(u=n[a])&&(i=u(i)||i);return i},se=(n,e)=>(t,r)=>e(t,r,n),ue=(n,e,t)=>Oe(n,typeof e!="symbol"?e+"":e,t);exports.UniverThreadCommentUIPlugin=class extends d.Plugin{constructor(e=oe,t,r,i){super(),this._config=e,this._injector=t,this._commandService=r,this._configService=i;const{menu:a,...u}=d.merge({},oe,this._config);a&&this._configService.setConfig("menu",a,{merge:!0}),this._configService.setConfig(Ne,u)}onStarting(){var e;d.mergeOverrideWithDependencies([[exports.ThreadCommentPanelService]],(e=this._config)==null?void 0:e.overrides).forEach(t=>{this._injector.add(t)}),[de,Z].forEach(t=>{this._commandService.registerCommand(t)})}};ue(exports.UniverThreadCommentUIPlugin,"pluginName",je);ue(exports.UniverThreadCommentUIPlugin,"type",d.UniverInstanceType.UNIVER_UNKNOWN);exports.UniverThreadCommentUIPlugin=Ee([d.DependentOn(B.UniverThreadCommentPlugin),se(1,d.Inject(d.Injector)),se(2,d.ICommandService),se(3,d.IConfigService)],exports.UniverThreadCommentUIPlugin);var P=function(){return P=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i])}return n},P.apply(this,arguments)},ke=function(n,e){var t={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(n);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(n,r[i])&&(t[r[i]]=n[r[i]]);return t},G=l.forwardRef(function(n,e){var t=n.icon,r=n.id,i=n.className,a=n.extend,u=ke(n,["icon","id","className","extend"]),C="univerjs-icon univerjs-icon-".concat(r," ").concat(i||"").trim(),g=l.useRef("_".concat(Re()));return ve(t,"".concat(r),{defIds:t.defIds,idSuffix:g.current},P({ref:e,className:C},u),a)});function ve(n,e,t,r,i){return l.createElement(n.tag,P(P({key:e},De(n,t,i)),r),(Me(n,t).children||[]).map(function(a,u){return ve(a,"".concat(e,"-").concat(n.tag,"-").concat(u),t,void 0,i)}))}function De(n,e,t){var r=P({},n.attrs);t!=null&&t.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=t.colorChannel1),n.tag==="mask"&&r.id&&(r.id=r.id+e.idSuffix),Object.entries(r).forEach(function(a){var u=a[0],C=a[1];u==="mask"&&typeof C=="string"&&(r[u]=C.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))});var i=e.defIds;return!i||i.length===0||(n.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+e.idSuffix),Object.entries(r).forEach(function(a){var u=a[0],C=a[1];typeof C=="string"&&(r[u]=C.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),r}function Me(n,e){var t,r=e.defIds;return!r||r.length===0?n:n.tag==="defs"&&(!((t=n.children)===null||t===void 0)&&t.length)?P(P({},n),{children:n.children.map(function(i){return typeof i.attrs.id=="string"&&r&&r.includes(i.attrs.id)?P(P({},i),{attrs:P(P({},i.attrs),{id:i.attrs.id+e.idSuffix})}):i})}):n}function Re(){return Math.random().toString(36).substring(2,8)}G.displayName="UniverIcon";var Pe={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},me=l.forwardRef(function(n,e){return l.createElement(G,Object.assign({},n,{id:"delete-icon",ref:e,icon:Pe}))});me.displayName="DeleteIcon";var $e={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},fe=l.forwardRef(function(n,e){return l.createElement(G,Object.assign({},n,{id:"increase-icon",ref:e,icon:$e}))});fe.displayName="IncreaseIcon";var Le={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3 9C3.55228 9 4 8.55228 4 8C4 7.44772 3.55228 7 3 7C2.44772 7 2 7.44772 2 8C2 8.55228 2.44772 9 3 9Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M8 9C8.55228 9 9 8.55228 9 8C9 7.44772 8.55228 7 8 7C7.44772 7 7 7.44772 7 8C7 8.55228 7.44772 9 8 9Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M13 9C13.5523 9 14 8.55228 14 8C14 7.44772 13.5523 7 13 7C12.4477 7 12 7.44772 12 8C12 8.55228 12.4477 9 13 9Z"}}]},he=l.forwardRef(function(n,e){return l.createElement(G,Object.assign({},n,{id:"more-horizontal-icon",ref:e,icon:Le}))});he.displayName="MoreHorizontalIcon";var He={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{stroke:"currentColor",d:"M7.48389 10.3267V12.1905C7.48389 12.7428 7.9316 13.1905 8.48389 13.1905H11.2216L12.2955 14.2644L13.3695 13.1905H14.1593C14.7116 13.1905 15.1593 12.7428 15.1593 12.1905V8.46289C15.1593 7.91061 14.7116 7.46289 14.1593 7.46289H12.2955",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M0.840332 3.73535C0.840332 2.63078 1.73576 1.73535 2.84033 1.73535H10.2955C11.4001 1.73535 12.2955 2.63078 12.2955 3.73535V8.32676C12.2955 9.43132 11.4001 10.3268 10.2955 10.3268H5.6014L4.1695 11.7587L3.05978 10.3268H2.84033C1.73576 10.3268 0.840332 9.43133 0.840332 8.32676V3.73535Z",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M6.41016 6.1311H6.76813",strokeLinecap:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M8.91626 6.1311H9.27424",strokeLinecap:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M3.90454 6.1311H4.26252",strokeLinecap:"round",strokeWidth:1.2}}]},pe=l.forwardRef(function(n,e){return l.createElement(G,Object.assign({},n,{id:"reply-to-comment-icon",ref:e,icon:He}))});pe.displayName="ReplyToCommentIcon";var Ve={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6106 15.4036C12.4766 15.4036 15.6106 12.2696 15.6106 8.40356C15.6106 4.53757 12.4766 1.40356 8.6106 1.40356C4.7446 1.40356 1.6106 4.53757 1.6106 8.40356C1.6106 12.2696 4.7446 15.4036 8.6106 15.4036ZM12.3351 6.82773C12.5694 6.59342 12.5694 6.21352 12.3351 5.9792C12.1007 5.74489 11.7208 5.74489 11.4865 5.9792L7.91079 9.55494L6.33506 7.9792C6.10074 7.74489 5.72084 7.74489 5.48653 7.9792C5.25221 8.21352 5.25221 8.59342 5.48653 8.82773L7.48653 10.8277C7.72084 11.062 8.10074 11.062 8.33506 10.8277L12.3351 6.82773Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ce=l.forwardRef(function(n,e){return l.createElement(G,Object.assign({},n,{id:"resolved-icon",ref:e,icon:Ve}))});Ce.displayName="ResolvedIcon";var Be={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"circle",attrs:{cx:8.73,cy:8.4,r:6.4,stroke:"currentColor",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M6.02637 8.40356L8.02637 10.4036L12.0264 6.40356",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.2}}]},ge=l.forwardRef(function(n,e){return l.createElement(G,Object.assign({},n,{id:"solve-icon",ref:e,icon:Be}))});ge.displayName="SolveIcon";function le(n){return{id:"d",body:n,documentStyle:{}}}const xe=l.forwardRef((n,e)=>{var $;const{comment:t,onSave:r,id:i,onCancel:a,autoFocus:u,unitId:C,type:g}=n,N=f.useDependency(d.ICommandService),O=f.useDependency(d.LocaleService),[A,E]=l.useState(!1),S=f.useDependency(ie.IEditorService),m=l.useRef(null),h=g===d.UniverInstanceType.UNIVER_SHEET?d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:C,[k,w]=l.useState(()=>{var v,p,x;return d.BuildTextUtils.transform.getPlainText((x=(p=(v=m.current)==null?void 0:v.getDocumentData().body)==null?void 0:p.dataStream)!=null?x:"")});l.useEffect(()=>{var p,x,_,I;w(d.BuildTextUtils.transform.getPlainText((_=(x=(p=m.current)==null?void 0:p.getDocumentData().body)==null?void 0:x.dataStream)!=null?_:""));const v=(I=m.current)==null?void 0:I.selectionChange$.subscribe(()=>{var o,j,F;w(d.BuildTextUtils.transform.getPlainText((F=(j=(o=m.current)==null?void 0:o.getDocumentData().body)==null?void 0:j.dataStream)!=null?F:""))});return()=>v==null?void 0:v.unsubscribe()},[($=m.current)==null?void 0:$.selectionChange$]);const W=l.useMemo(()=>({keyCodes:[{keyCode:f.KeyCode.ENTER}],handler:v=>{v===f.KeyCode.ENTER&&N.executeCommand(ie.BreakLineCommand.id)}}),[N]);l.useImperativeHandle(e,()=>({reply(v){var x,_;if(!m.current)return;S.focus((x=m.current.getEditorId())!=null?x:"");const p=le(v);(_=m.current)==null||_.setDocumentData(p,[{startOffset:p.body.dataStream.length-2,endOffset:p.body.dataStream.length-2,collapsed:!0}])}}));const b=()=>{if(m.current){const v=d.Tools.deepClone(m.current.getDocumentData().body);E(!1),r==null||r({...t,text:v}),m.current.replaceText(""),setTimeout(()=>{var p,x;(p=m.current)==null||p.setSelectionRanges([]),(x=m.current)==null||x.blur()},10)}};return s.jsxs("div",{onClick:v=>v.preventDefault(),children:[s.jsx(ie.RichTextEditor,{className:"univer-w-full",editorRef:m,autoFocus:u,keyboardEventConfig:W,placeholder:O.t("threadCommentUI.editor.placeholder"),initialValue:(t==null?void 0:t.text)&&le(t.text),onFocusChange:v=>v&&E(v),isSingle:!1,maxHeight:64,onClickOutside:()=>{setTimeout(()=>{S.focus(h)},30)}}),A?s.jsxs("div",{className:"univer-mt-3 univer-flex univer-flex-row univer-justify-end univer-gap-2",children:[s.jsx(U.Button,{onClick:()=>{var v;a==null||a(),E(!1),(v=m.current)==null||v.replaceText("",!0),N.executeCommand(Z.id)},children:O.t("threadCommentUI.editor.cancel")}),s.jsx(U.Button,{variant:"primary",disabled:!k,onClick:b,children:O.t(i?"threadCommentUI.editor.save":"threadCommentUI.editor.reply")})]}):null]})}),Ae=n=>{const{dataStream:e,customRanges:t}=n,r=e.endsWith(`\r
2
- `)?e.length-2:e.length,i=[];let a=0;return t==null||t.forEach(u=>{a<u.startIndex&&i.push({type:"text",content:e.slice(a,u.startIndex)}),i.push({type:"mention",content:{label:e.slice(u.startIndex,u.endIndex+1),id:u.rangeId}}),a=u.endIndex+1}),i.push({type:"text",content:e.slice(a,r)}),i},We=n=>{const{paragraphs:e=[]}=n;let t=0;return e.map(r=>{const i=d.getBodySlice(n,t,r.startIndex);return t=r.startIndex+1,Ae(i)})},Ze=n=>{let e="";const t=[];return n.forEach(r=>{switch(r.type){case"text":e+=r.content;break;case"mention":{const i=e.length;e+=r.content.label;const a=e.length-1;t.push({rangeId:r.content.id,rangeType:d.CustomRangeType.MENTION,startIndex:i,endIndex:a,properties:{},wholeEntity:!0});break}}}),e+=`\r
3
- `,{textRuns:[],paragraphs:[{startIndex:e.length-2,paragraphStyle:{}}],sectionBreaks:[{startIndex:e.length-1}],dataStream:e,customRanges:t}},Ie="__mock__",Fe=n=>{const{item:e,unitId:t,subUnitId:r,editing:i,onEditingChange:a,onReply:u,resolved:C,isRoot:g,onClose:N,onDeleteComment:O,type:A}=n,E=f.useDependency(d.ICommandService),S=f.useDependency(d.LocaleService),m=f.useDependency(d.UserManagerService),h=m.getUser(e.personId),k=f.useObservable(m.currentUser$),w=(k==null?void 0:k.userID)===e.personId,W=e.id===Ie,[b,$]=l.useState(!1),v=f.useConfigValue(f.UI_PLUGIN_CONFIG_KEY),p=v==null?void 0:v.avatarFallback,x=()=>{(O==null?void 0:O(e))!==!1&&(E.executeCommand(g?B.DeleteCommentTreeCommand.id:B.DeleteCommentCommand.id,{unitId:t,subUnitId:r,commentId:e.id}),g&&(N==null||N()))};return s.jsxs("div",{className:"univer-relative univer-mb-3 univer-pl-[30px]",onMouseLeave:()=>$(!1),onMouseEnter:()=>$(!0),children:[s.jsx("div",{className:"univer-absolute univer-left-0 univer-top-0 univer-h-6 univer-w-6 univer-rounded-full univer-bg-cover univer-bg-center univer-bg-no-repeat",style:{backgroundImage:`url(${(h==null?void 0:h.avatar)||p})`}}),h?s.jsxs("div",{className:"univer-mb-1 univer-flex univer-h-6 univer-items-center univer-justify-between",children:[s.jsx("div",{className:"univer-text-sm univer-font-medium univer-leading-5",children:(h==null?void 0:h.name)||" "}),s.jsxs("div",{children:[W||C?null:b&&h?s.jsx("div",{className:"univer-ml-1 univer-inline-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-sm univer-text-base hover:univer-bg-gray-50",onClick:()=>u(h),children:s.jsx(pe,{})}):null,w&&!W&&!C?s.jsx(U.Dropdown,{overlay:s.jsx("div",{className:"univer-rounded-lg",children:s.jsxs("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:[s.jsx("li",{children:s.jsx("a",{className:"hover:univer-bg-gray-200",onClick:()=>a==null?void 0:a(!0),children:S.t("threadCommentUI.item.edit")})}),s.jsx("li",{children:s.jsx("a",{className:"hover:univer-bg-gray-200",onClick:x,children:S.t("threadCommentUI.item.delete")})})]})}),children:s.jsx("div",{className:"univer-ml-1 univer-inline-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-sm univer-text-base hover:univer-bg-gray-50",children:s.jsx(he,{})})}):null]})]}):null,s.jsx("time",{className:"univer-mb-1 univer-text-xs/normal univer-text-gray-600 dark:!univer-text-gray-200",children:e.dT}),i?s.jsx(xe,{type:A,id:e.id,comment:e,onCancel:()=>a==null?void 0:a(!1),autoFocus:!0,unitId:t,subUnitId:r,onSave:({text:_,attachments:I})=>{a==null||a(!1),E.executeCommand(B.UpdateCommentCommand.id,{unitId:t,subUnitId:r,payload:{commentId:e.id,text:_,attachments:I}})}}):s.jsx("div",{className:"univer-text-sm univer-text-gray-900 dark:!univer-text-white",children:We(e.text).map((_,I)=>s.jsx("div",{className:"univer-break-words",children:_.map((o,j)=>{switch(o.type){case"mention":return s.jsxs("a",{className:"univer-text-primary-600",children:[o.content.label," "]},j);default:return o.content}})},I))})]})},be=n=>{var ne,J,c;const{id:e,unitId:t,subUnitId:r,refStr:i,showEdit:a=!0,onClick:u,showHighlight:C,onClose:g,getSubUnitName:N,prefix:O,autoFocus:A,onMouseEnter:E,onMouseLeave:S,onAddComment:m,onDeleteComment:h,onResolve:k,type:w,style:W,full:b}=n,$=f.useDependency(B.ThreadCommentModel),[v,p]=l.useState(!1),[x,_]=l.useState(""),I=l.useMemo(()=>$.commentUpdate$.pipe(re.debounceTime(16)),[$]);f.useObservable(I);const o=e?$.getCommentWithChildren(t,r,e):null,j=f.useDependency(d.ICommandService),F=f.useDependency(d.UserManagerService),D=o==null?void 0:o.root.resolved,M=f.useObservable(F.currentUser$),H=l.useRef(null),z=[...o?[o.root]:[{id:Ie,text:{dataStream:`
4
- \r`},personId:(ne=M==null?void 0:M.userID)!=null?ne:"",ref:i!=null?i:"",dT:"",unitId:t,subUnitId:r,threadId:""}],...(J=o==null?void 0:o.children)!=null?J:[]],L=l.useRef(null),Q=y=>{y.stopPropagation(),D?j.executeCommand(Z.id,{unitId:t,subUnitId:r,commentId:e}):j.executeCommand(Z.id),j.executeCommand(B.ResolveCommentCommand.id,{unitId:t,subUnitId:r,commentId:e,resolved:!D}),k==null||k(!D)},Y=y=>{y.stopPropagation(),j.executeCommand(Z.id),!(o!=null&&o.root&&(h==null?void 0:h(o.root))===!1)&&(j.executeCommand(B.DeleteCommentTreeCommand.id,{unitId:t,subUnitId:r,commentId:e}),g==null||g())};l.useEffect(()=>S==null?void 0:S(),[]);const X=N((c=o==null?void 0:o.root.subUnitId)!=null?c:r),ee=a&&!x&&!D,te=`${i||(o==null?void 0:o.root.ref)||""}${X?" · ":""}${X}`;return s.jsxs("div",{id:`${O}-${t}-${r}-${e}`,className:U.clsx("univer-relative univer-box-border univer-rounded-md univer-bg-white univer-p-4 dark:!univer-bg-gray-900 dark:!univer-text-white",U.borderClassName,{"univer-w-[278px]":!b,"univer-w-full":b,"univer-shadow":!D&&(C||v||O==="cell")}),style:W,onClick:u,onMouseEnter:()=>{E==null||E(),p(!0)},onMouseLeave:()=>{S==null||S(),p(!1)},children:[!D&&C&&s.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"}),s.jsxs("div",{className:"univer-mb-4 univer-flex univer-flex-row univer-items-center univer-justify-between univer-text-sm univer-leading-5",children:[s.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-row univer-items-center univer-overflow-hidden",children:[s.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"}),s.jsx(U.Tooltip,{showIfEllipsis:!0,title:te,children:s.jsx("div",{className:"univer-flex-1 univer-truncate",children:te})})]}),!!o&&s.jsxs("div",{className:"univer-flex univer-flex-shrink-0 univer-flex-grow-0 univer-flex-row",children:[s.jsx("div",{className:U.clsx("univer-ml-1 univer-inline-flex univer-h-6 univer-w-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":D}),onClick:Q,children:D?s.jsx(Ce,{}):s.jsx(ge,{})}),(M==null?void 0:M.userID)===o.root.personId?s.jsx("div",{className:"univer-ml-1 univer-inline-flex univer-h-6 univer-w-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:Y,children:s.jsx(me,{})}):null]})]}),s.jsx("div",{ref:L,className:U.clsx("univer-max-h-80 univer-overflow-y-auto univer-overflow-x-hidden",U.scrollbarClassName),children:z.map(y=>s.jsx(Fe,{unitId:t,subUnitId:r,item:y,isRoot:y.id===(o==null?void 0:o.root.id),editing:x===y.id,resolved:o==null?void 0:o.root.resolved,type:w,onClose:g,onEditingChange:R=>{_(R?y.id:"")},onReply:R=>{R&&requestAnimationFrame(()=>{var V;(V=H.current)==null||V.reply(Ze([{type:"mention",content:{id:R.userID,label:`@${R.name}`}},{type:"text",content:" "}]))})},onAddComment:m,onDeleteComment:h},y.id))}),ee&&s.jsx("div",{children:s.jsx(xe,{ref:H,type:w,unitId:t,subUnitId:r,onSave:async({text:y,attachments:R})=>{const V={text:y,attachments:R,dT:B.getDT(),id:d.generateRandomId(),ref:i,personId:M==null?void 0:M.userID,parentId:o==null?void 0:o.root.id,unitId:t,subUnitId:r,threadId:o==null?void 0:o.root.threadId};(m==null?void 0:m(V))!==!1&&(await j.executeCommand(B.AddCommentCommand.id,{unitId:t,subUnitId:r,comment:V}),L.current&&(L.current.scrollTop=L.current.scrollHeight))},autoFocus:A||!o,onCancel:()=>{o||g==null||g()}},`${A}`)})]})},qe=n=>{const{unitId:e,subUnitId$:t,type:r,onAdd:i,getSubUnitName:a,onResolve:u,sortComments:C,onItemLeave:g,onItemEnter:N,disableAdd:O,tempComment:A,onAddComment:E,onDeleteComment:S,showComments:m}=n,[h,k]=l.useState("all"),[w,W]=l.useState("all"),b=f.useDependency(d.LocaleService),$=f.useDependency(d.UserManagerService),v=f.useDependency(B.ThreadCommentModel),[p,x]=l.useState(()=>v.getUnit(e)),_=f.useDependency(exports.ThreadCommentPanelService),I=f.useObservable(_.activeCommentId$),o=f.useObservable(v.commentUpdate$),j=f.useDependency(d.ICommandService),F=f.useObservable(t),D=l.useRef(!0),M="panel",H=f.useObservable($.currentUser$),z=l.useMemo(()=>{var V;const c=h==="all"?p:(V=p.filter(T=>T.subUnitId===F))!=null?V:[],y=C!=null?C:(T=>T),R=c.map(T=>{var q;return{...T.root,children:(q=T.children)!=null?q:[],users:T.relativeUsers}});if(m){const T=new Map;return R.forEach(q=>{T.set(q.id,q)}),[...m,""].map(q=>T.get(q)).filter(Boolean)}else return y(R)},[m,h,p,C,F]),L=l.useMemo(()=>[...z.filter(c=>!c.resolved),...z.filter(c=>c.resolved)],[z]),Q=l.useMemo(()=>w==="resolved"?L.filter(c=>c.resolved):w==="unsolved"?L.filter(c=>!c.resolved):w==="concern_me"&&H!=null&&H.userID?L.filter(c=>c==null?void 0:c.users.has(H.userID)):L,[L,H==null?void 0:H.userID,w]),Y=A?[A,...Q]:Q,X=Y.filter(c=>!c.resolved),ee=Y.filter(c=>c.resolved),te=w!=="all"||h!=="all",ne=()=>{W("all"),k("all")};l.useEffect(()=>{e&&x(v.getUnit(e))},[e,v,o]),l.useEffect(()=>{var T;if(!I)return;if(!D.current){D.current=!0;return}const{unitId:c,subUnitId:y,commentId:R}=I,V=`${M}-${c}-${y}-${R}`;(T=document.getElementById(V))==null||T.scrollIntoView({block:"center"})},[I]);const J=c=>s.jsx(be,{full:!0,prefix:M,getSubUnitName:a,id:c.id,unitId:c.unitId,subUnitId:c.subUnitId,refStr:c.ref,type:r,showEdit:(I==null?void 0:I.commentId)===c.id,showHighlight:(I==null?void 0:I.commentId)===c.id,onClick:()=>{D.current=!1,c.resolved?j.executeCommand(Z.id):j.executeCommand(Z.id,{unitId:c.unitId,subUnitId:c.subUnitId,commentId:c.id,temp:!1})},onMouseEnter:()=>N==null?void 0:N(c),onMouseLeave:()=>g==null?void 0:g(c),onAddComment:E,onDeleteComment:S,onResolve:y=>u==null?void 0:u(c.id,y)},c.id);return s.jsxs("div",{className:"univer-flex univer-min-h-full univer-flex-col univer-pb-3",children:[s.jsxs("div",{className:"univer-mt-3 univer-flex univer-flex-row univer-justify-between",children:[r===d.UniverInstanceType.UNIVER_SHEET?s.jsx(U.Select,{borderless:!0,value:h,options:[{value:"current",label:b.t("threadCommentUI.filter.sheet.current")},{value:"all",label:b.t("threadCommentUI.filter.sheet.all")}],onChange:k}):null,s.jsx(U.Select,{borderless:!0,value:w,options:[{value:"all",label:b.t("threadCommentUI.filter.status.all")},{value:"resolved",label:b.t("threadCommentUI.filter.status.resolved")},{value:"unsolved",label:b.t("threadCommentUI.filter.status.unsolved")},{value:"concern_me",label:b.t("threadCommentUI.filter.status.concernMe")}],onChange:W})]}),Y.length===0?s.jsxs("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:[b.t("threadCommentUI.panel.empty"),te?s.jsx("div",{className:"univer-mt-2 univer-flex univer-flex-row",children:s.jsx(U.Button,{onClick:ne,children:b.t("threadCommentUI.panel.reset")})}):O?null:s.jsx("div",{className:"univer-mt-2 univer-flex univer-flex-row",children:s.jsxs(U.Button,{onClick:i,children:[s.jsx(fe,{className:"univer-mr-1.5"}),b.t("threadCommentUI.panel.addComment")]})})]}):s.jsxs("div",{className:"univer-mt-3 univer-flex univer-flex-col univer-gap-3",children:[X.map(J),ee.length>0&&s.jsx("div",{className:"univer-text-xs",children:b.t("threadCommentUI.panel.solved")}),ee.map(J)]})]})};exports.SetActiveCommentOperation=Z;exports.THREAD_COMMENT_PANEL=ce;exports.ThreadCommentPanel=qe;exports.ThreadCommentTree=be;exports.ToggleSheetCommentPanelOperation=de;
1
+ "use strict";var be=Object.defineProperty;var ye=(n,e,t)=>e in n?be(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var q=(n,e,t)=>ye(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),h=require("@univerjs/ui"),ne=require("rxjs"),V=require("@univerjs/thread-comment"),i=require("react/jsx-runtime"),U=require("@univerjs/design"),c=require("react"),re=require("@univerjs/docs-ui");var Se=Object.getOwnPropertyDescriptor,we=(n,e,t,r)=>{for(var s=r>1?void 0:r?Se(e,t):e,o=n.length-1,u;o>=0;o--)(u=n[o])&&(s=u(s)||s);return s},se=(n,e)=>(t,r)=>e(t,r,n);exports.ThreadCommentPanelService=class extends d.Disposable{constructor(t,r){super();q(this,"_panelVisible",!1);q(this,"_panelVisible$",new ne.BehaviorSubject(!1));q(this,"_activeCommentId");q(this,"_activeCommentId$",new ne.BehaviorSubject(void 0));q(this,"panelVisible$",this._panelVisible$.asObservable());q(this,"activeCommentId$",this._activeCommentId$.asObservable());this._sidebarService=t,this._univerInstanceService=r,this._init(),this.disposeWithMe(()=>{this._activeCommentId$.complete(),this._panelVisible$.complete()})}_init(){this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(t=>{t.visible||this.setPanelVisible(!1)})),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(ne.filter(t=>!t)).subscribe(()=>{this._sidebarService.close()}))}get panelVisible(){return this._panelVisible}get activeCommentId(){return this._activeCommentId}setPanelVisible(t){this._panelVisible=t,this._panelVisible$.next(t)}setActiveComment(t){this._activeCommentId=t,this._activeCommentId$.next(t)}};exports.ThreadCommentPanelService=we([se(0,d.Inject(h.ISidebarService)),se(1,d.IUniverInstanceService)],exports.ThreadCommentPanelService);const le="thread-comment-panel",je="UNIVER_THREAD_COMMENT_UI_PLUGIN",ce={id:"thread-comment-ui.operation.toggle-panel",type:d.CommandType.OPERATION,handler(n){const e=n.get(h.ISidebarService),t=n.get(exports.ThreadCommentPanelService);return t.panelVisible?(e.close(),t.setPanelVisible(!1)):(e.open({header:{title:"threadCommentUI.panel.title"},children:{label:le},width:330}),t.setPanelVisible(!0)),!0}},W={id:"thread-comment-ui.operation.set-active-comment",type:d.CommandType.OPERATION,handler(n,e){return n.get(exports.ThreadCommentPanelService).setActiveComment(e),!0}},_e="thread-comment-ui.config",oe={};var Ne=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,Ue=(n,e,t)=>e in n?Ne(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,De=(n,e,t,r)=>{for(var s=r>1?void 0:r?Te(e,t):e,o=n.length-1,u;o>=0;o--)(u=n[o])&&(s=u(s)||s);return s},ie=(n,e)=>(t,r)=>e(t,r,n),de=(n,e,t)=>Ue(n,typeof e!="symbol"?e+"":e,t);exports.UniverThreadCommentUIPlugin=class extends d.Plugin{constructor(e=oe,t,r,s){super(),this._config=e,this._injector=t,this._commandService=r,this._configService=s;const{menu:o,...u}=d.merge({},oe,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(_e,u)}onStarting(){var e;d.mergeOverrideWithDependencies([[exports.ThreadCommentPanelService]],(e=this._config)==null?void 0:e.overrides).forEach(t=>{this._injector.add(t)}),[ce,W].forEach(t=>{this._commandService.registerCommand(t)})}};de(exports.UniverThreadCommentUIPlugin,"pluginName",je);de(exports.UniverThreadCommentUIPlugin,"type",d.UniverInstanceType.UNIVER_UNKNOWN);exports.UniverThreadCommentUIPlugin=De([d.DependentOn(V.UniverThreadCommentPlugin),ie(1,d.Inject(d.Injector)),ie(2,d.ICommandService),ie(3,d.IConfigService)],exports.UniverThreadCommentUIPlugin);function K({ref:n,...e}){const{icon:t,id:r,className:s,extend:o,...u}=e,y=`univerjs-icon univerjs-icon-${r} ${s||""}`.trim(),C=c.useRef(`_${ke()}`);return ue(t,`${r}`,{defIds:t.defIds,idSuffix:C.current},{ref:n,className:y,...u},o)}function ue(n,e,t,r,s){return c.createElement(n.tag,{key:e,...$e(n,t,s),...r},(Ee(n,t).children||[]).map((o,u)=>ue(o,`${e}-${n.tag}-${u}`,t,void 0,s)))}function $e(n,e,t){const r={...n.attrs};t!=null&&t.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=t.colorChannel1),n.tag==="mask"&&r.id&&(r.id=r.id+e.idSuffix),Object.entries(r).forEach(([o,u])=>{o==="mask"&&typeof u=="string"&&(r[o]=u.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))});const{defIds:s}=e;return!s||s.length===0||(n.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+e.idSuffix),Object.entries(r).forEach(([o,u])=>{typeof u=="string"&&(r[o]=u.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))})),r}function Ee(n,e){var r;const{defIds:t}=e;return!t||t.length===0?n:n.tag==="defs"&&((r=n.children)!=null&&r.length)?{...n,children:n.children.map(s=>typeof s.attrs.id=="string"&&t&&t.includes(s.attrs.id)?{...s,attrs:{...s.attrs,id:s.attrs.id+e.idSuffix}}:s)}:n}function ke(){return Math.random().toString(36).substring(2,8)}K.displayName="UniverIcon";const Me={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ve=c.forwardRef(function(e,t){return c.createElement(K,Object.assign({},e,{id:"delete-icon",ref:t,icon:Me}))});ve.displayName="DeleteIcon";const Re={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},me=c.forwardRef(function(e,t){return c.createElement(K,Object.assign({},e,{id:"increase-icon",ref:t,icon:Re}))});me.displayName="IncreaseIcon";const Oe={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3 9C3.55228 9 4 8.55228 4 8C4 7.44772 3.55228 7 3 7C2.44772 7 2 7.44772 2 8C2 8.55228 2.44772 9 3 9Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M8 9C8.55228 9 9 8.55228 9 8C9 7.44772 8.55228 7 8 7C7.44772 7 7 7.44772 7 8C7 8.55228 7.44772 9 8 9Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M13 9C13.5523 9 14 8.55228 14 8C14 7.44772 13.5523 7 13 7C12.4477 7 12 7.44772 12 8C12 8.55228 12.4477 9 13 9Z"}}]},he=c.forwardRef(function(e,t){return c.createElement(K,Object.assign({},e,{id:"more-horizontal-icon",ref:t,icon:Oe}))});he.displayName="MoreHorizontalIcon";const Pe={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{stroke:"currentColor",d:"M7.48389 10.3267V12.1905C7.48389 12.7428 7.9316 13.1905 8.48389 13.1905H11.2216L12.2955 14.2644L13.3695 13.1905H14.1593C14.7116 13.1905 15.1593 12.7428 15.1593 12.1905V8.46289C15.1593 7.91061 14.7116 7.46289 14.1593 7.46289H12.2955",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M0.840332 3.73535C0.840332 2.63078 1.73576 1.73535 2.84033 1.73535H10.2955C11.4001 1.73535 12.2955 2.63078 12.2955 3.73535V8.32676C12.2955 9.43132 11.4001 10.3268 10.2955 10.3268H5.6014L4.1695 11.7587L3.05978 10.3268H2.84033C1.73576 10.3268 0.840332 9.43133 0.840332 8.32676V3.73535Z",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M6.41016 6.1311H6.76813",strokeLinecap:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M8.91626 6.1311H9.27424",strokeLinecap:"round",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M3.90454 6.1311H4.26252",strokeLinecap:"round",strokeWidth:1.2}}]},fe=c.forwardRef(function(e,t){return c.createElement(K,Object.assign({},e,{id:"reply-to-comment-icon",ref:t,icon:Pe}))});fe.displayName="ReplyToCommentIcon";const Le={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:"M8.6106 15.4036C12.4766 15.4036 15.6106 12.2696 15.6106 8.40356C15.6106 4.53757 12.4766 1.40356 8.6106 1.40356C4.7446 1.40356 1.6106 4.53757 1.6106 8.40356C1.6106 12.2696 4.7446 15.4036 8.6106 15.4036ZM12.3351 6.82773C12.5694 6.59342 12.5694 6.21352 12.3351 5.9792C12.1007 5.74489 11.7208 5.74489 11.4865 5.9792L7.91079 9.55494L6.33506 7.9792C6.10074 7.74489 5.72084 7.74489 5.48653 7.9792C5.25221 8.21352 5.25221 8.59342 5.48653 8.82773L7.48653 10.8277C7.72084 11.062 8.10074 11.062 8.33506 10.8277L12.3351 6.82773Z",fillRule:"evenodd",clipRule:"evenodd"}}]},pe=c.forwardRef(function(e,t){return c.createElement(K,Object.assign({},e,{id:"resolved-icon",ref:t,icon:Le}))});pe.displayName="ResolvedIcon";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:"circle",attrs:{cx:8.73,cy:8.4,r:6.4,stroke:"currentColor",strokeWidth:1.2}},{tag:"path",attrs:{stroke:"currentColor",d:"M6.02637 8.40356L8.02637 10.4036L12.0264 6.40356",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.2}}]},Ce=c.forwardRef(function(e,t){return c.createElement(K,Object.assign({},e,{id:"solve-icon",ref:t,icon:He}))});Ce.displayName="SolveIcon";function ae(n){return{id:"d",body:n,documentStyle:{}}}const ge=c.forwardRef((n,e)=>{var O;const{comment:t,onSave:r,id:s,onCancel:o,autoFocus:u,unitId:y,type:C}=n,N=h.useDependency(d.ICommandService),D=h.useDependency(d.LocaleService),[B,$]=c.useState(!1),S=h.useDependency(re.IEditorService),m=c.useRef(null),f=C===d.UniverInstanceType.UNIVER_DOC?d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:y,[E,w]=c.useState(()=>{var v,p,g;return d.BuildTextUtils.transform.getPlainText((g=(p=(v=m.current)==null?void 0:v.getDocumentData().body)==null?void 0:p.dataStream)!=null?g:"")});c.useEffect(()=>{var p,g,j,x;w(d.BuildTextUtils.transform.getPlainText((j=(g=(p=m.current)==null?void 0:p.getDocumentData().body)==null?void 0:g.dataStream)!=null?j:""));const v=(x=m.current)==null?void 0:x.selectionChange$.subscribe(()=>{var a,_,Z;w(d.BuildTextUtils.transform.getPlainText((Z=(_=(a=m.current)==null?void 0:a.getDocumentData().body)==null?void 0:_.dataStream)!=null?Z:""))});return()=>v==null?void 0:v.unsubscribe()},[(O=m.current)==null?void 0:O.selectionChange$]);const A=c.useMemo(()=>({keyCodes:[{keyCode:h.KeyCode.ENTER}],handler:v=>{v===h.KeyCode.ENTER&&N.executeCommand(re.BreakLineCommand.id)}}),[N]);c.useImperativeHandle(e,()=>({reply(v){var g,j;if(!m.current)return;S.focus((g=m.current.getEditorId())!=null?g:"");const p=ae(v);(j=m.current)==null||j.setDocumentData(p,[{startOffset:p.body.dataStream.length-2,endOffset:p.body.dataStream.length-2,collapsed:!0}])}}));const I=()=>{if(m.current){const v=d.Tools.deepClone(m.current.getDocumentData().body);$(!1),r==null||r({...t,text:v}),m.current.replaceText(""),setTimeout(()=>{var p,g;(p=m.current)==null||p.setSelectionRanges([]),(g=m.current)==null||g.blur()},10)}};return i.jsxs("div",{onClick:v=>v.preventDefault(),children:[i.jsx(re.RichTextEditor,{className:"univer-w-full",editorRef:m,autoFocus:u,keyboardEventConfig:A,placeholder:D.t("threadCommentUI.editor.placeholder"),initialValue:(t==null?void 0:t.text)&&ae(t.text),onFocusChange:v=>v&&$(v),isSingle:!1,maxHeight:64,onClickOutside:()=>{setTimeout(()=>{S.focus(f)},30)}}),B?i.jsxs("div",{className:"univer-mt-3 univer-flex univer-flex-row univer-justify-end univer-gap-2",children:[i.jsx(U.Button,{onClick:()=>{var v;o==null||o(),$(!1),(v=m.current)==null||v.replaceText("",!0),N.executeCommand(W.id)},children:D.t("threadCommentUI.editor.cancel")}),i.jsx(U.Button,{variant:"primary",disabled:!E,onClick:I,children:D.t(s?"threadCommentUI.editor.save":"threadCommentUI.editor.reply")})]}):null]})}),Ve=n=>{const{dataStream:e,customRanges:t}=n,r=e.endsWith(`\r
2
+ `)?e.length-2:e.length,s=[];let o=0;return t==null||t.forEach(u=>{o<u.startIndex&&s.push({type:"text",content:e.slice(o,u.startIndex)}),s.push({type:"mention",content:{label:e.slice(u.startIndex,u.endIndex+1),id:u.rangeId}}),o=u.endIndex+1}),s.push({type:"text",content:e.slice(o,r)}),s},Be=n=>{const{paragraphs:e=[]}=n;let t=0;return e.map(r=>{const s=d.getBodySlice(n,t,r.startIndex);return t=r.startIndex+1,Ve(s)})},Ae=n=>{let e="";const t=[];return n.forEach(r=>{switch(r.type){case"text":e+=r.content;break;case"mention":{const s=e.length;e+=r.content.label;const o=e.length-1;t.push({rangeId:r.content.id,rangeType:d.CustomRangeType.MENTION,startIndex:s,endIndex:o,properties:{},wholeEntity:!0});break}}}),e+=`\r
3
+ `,{textRuns:[],paragraphs:[{startIndex:e.length-2,paragraphStyle:{}}],sectionBreaks:[{startIndex:e.length-1}],dataStream:e,customRanges:t}},xe="__mock__",We=n=>{const{item:e,unitId:t,subUnitId:r,editing:s,onEditingChange:o,onReply:u,resolved:y,isRoot:C,onClose:N,onDeleteComment:D,type:B}=n,$=h.useDependency(d.ICommandService),S=h.useDependency(d.LocaleService),m=h.useDependency(d.UserManagerService),f=m.getUser(e.personId),E=h.useObservable(m.currentUser$),w=(E==null?void 0:E.userID)===e.personId,A=e.id===xe,[I,O]=c.useState(!1),v=h.useConfigValue(h.UI_PLUGIN_CONFIG_KEY),p=v==null?void 0:v.avatarFallback,g=()=>{(D==null?void 0:D(e))!==!1&&($.executeCommand(C?V.DeleteCommentTreeCommand.id:V.DeleteCommentCommand.id,{unitId:t,subUnitId:r,commentId:e.id}),C&&(N==null||N()))};return i.jsxs("div",{className:"univer-relative univer-mb-3 univer-pl-[30px]",onMouseLeave:()=>O(!1),onMouseEnter:()=>O(!0),children:[i.jsx("div",{className:"univer-absolute univer-left-0 univer-top-0 univer-h-6 univer-w-6 univer-rounded-full univer-bg-cover univer-bg-center univer-bg-no-repeat",style:{backgroundImage:`url(${(f==null?void 0:f.avatar)||p})`}}),f?i.jsxs("div",{className:"univer-mb-1 univer-flex univer-h-6 univer-items-center univer-justify-between",children:[i.jsx("div",{className:"univer-text-sm univer-font-medium univer-leading-5",children:(f==null?void 0:f.name)||" "}),i.jsxs("div",{children:[A||y?null:I&&f?i.jsx("div",{className:"univer-ml-1 univer-inline-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-sm univer-text-base hover:univer-bg-gray-50",onClick:()=>u(f),children:i.jsx(fe,{})}):null,w&&!A&&!y?i.jsx(U.Dropdown,{overlay:i.jsx("div",{className:"univer-rounded-lg",children:i.jsxs("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:[i.jsx("li",{children:i.jsx("a",{className:"hover:univer-bg-gray-200",onClick:()=>o==null?void 0:o(!0),children:S.t("threadCommentUI.item.edit")})}),i.jsx("li",{children:i.jsx("a",{className:"hover:univer-bg-gray-200",onClick:g,children:S.t("threadCommentUI.item.delete")})})]})}),children:i.jsx("div",{className:"univer-ml-1 univer-inline-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-sm univer-text-base hover:univer-bg-gray-50",children:i.jsx(he,{})})}):null]})]}):null,i.jsx("time",{className:"univer-mb-1 univer-text-xs/normal univer-text-gray-600 dark:!univer-text-gray-200",children:e.dT}),s?i.jsx(ge,{type:B,id:e.id,comment:e,onCancel:()=>o==null?void 0:o(!1),autoFocus:!0,unitId:t,subUnitId:r,onSave:({text:j,attachments:x})=>{o==null||o(!1),$.executeCommand(V.UpdateCommentCommand.id,{unitId:t,subUnitId:r,payload:{commentId:e.id,text:j,attachments:x}})}}):i.jsx("div",{className:"univer-text-sm univer-text-gray-900 dark:!univer-text-white",children:Be(e.text).map((j,x)=>i.jsx("div",{className:"univer-break-words",children:j.map((a,_)=>{switch(a.type){case"mention":return i.jsxs("a",{className:"univer-text-primary-600",children:[a.content.label," "]},_);default:return a.content}})},x))})]})},Ie=n=>{var te,Y,l;const{id:e,unitId:t,subUnitId:r,refStr:s,showEdit:o=!0,onClick:u,showHighlight:y,onClose:C,getSubUnitName:N,prefix:D,autoFocus:B,onMouseEnter:$,onMouseLeave:S,onAddComment:m,onDeleteComment:f,onResolve:E,type:w,style:A,full:I}=n,O=h.useDependency(V.ThreadCommentModel),[v,p]=c.useState(!1),[g,j]=c.useState(""),x=c.useMemo(()=>O.commentUpdate$.pipe(ne.debounceTime(16)),[O]);h.useObservable(x);const a=e?O.getCommentWithChildren(t,r,e):null,_=h.useDependency(d.ICommandService),Z=h.useDependency(d.UserManagerService),k=a==null?void 0:a.root.resolved,M=h.useObservable(Z.currentUser$),L=c.useRef(null),G=[...a?[a.root]:[{id:xe,text:{dataStream:`
4
+ \r`},personId:(te=M==null?void 0:M.userID)!=null?te:"",ref:s!=null?s:"",dT:"",unitId:t,subUnitId:r,threadId:""}],...(Y=a==null?void 0:a.children)!=null?Y:[]],P=c.useRef(null),J=b=>{b.stopPropagation(),k?_.executeCommand(W.id,{unitId:t,subUnitId:r,commentId:e}):_.executeCommand(W.id),_.executeCommand(V.ResolveCommentCommand.id,{unitId:t,subUnitId:r,commentId:e,resolved:!k}),E==null||E(!k)},z=b=>{b.stopPropagation(),_.executeCommand(W.id),!(a!=null&&a.root&&(f==null?void 0:f(a.root))===!1)&&(_.executeCommand(V.DeleteCommentTreeCommand.id,{unitId:t,subUnitId:r,commentId:e}),C==null||C())};c.useEffect(()=>S==null?void 0:S(),[]);const Q=N((l=a==null?void 0:a.root.subUnitId)!=null?l:r),X=o&&!g&&!k,ee=`${s||(a==null?void 0:a.root.ref)||""}${Q?" · ":""}${Q}`;return i.jsxs("div",{id:`${D}-${t}-${r}-${e}`,className:U.clsx("univer-relative univer-box-border univer-rounded-md univer-bg-white univer-p-4 dark:!univer-bg-gray-900 dark:!univer-text-white",U.borderClassName,{"univer-w-[278px]":!I,"univer-w-full":I,"univer-shadow":!k&&(y||v||D==="cell")}),style:A,onClick:u,onMouseEnter:()=>{$==null||$(),p(!0)},onMouseLeave:()=>{S==null||S(),p(!1)},children:[!k&&y&&i.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"}),i.jsxs("div",{className:"univer-mb-4 univer-flex univer-flex-row univer-items-center univer-justify-between univer-text-sm univer-leading-5",children:[i.jsxs("div",{className:"univer-flex univer-flex-1 univer-flex-row univer-items-center univer-overflow-hidden",children:[i.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"}),i.jsx(U.Tooltip,{showIfEllipsis:!0,title:ee,children:i.jsx("div",{className:"univer-flex-1 univer-truncate",children:ee})})]}),!!a&&i.jsxs("div",{className:"univer-flex univer-flex-shrink-0 univer-flex-grow-0 univer-flex-row",children:[i.jsx("div",{className:U.clsx("univer-ml-1 univer-inline-flex univer-h-6 univer-w-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":k}),onClick:J,children:k?i.jsx(pe,{}):i.jsx(Ce,{})}),(M==null?void 0:M.userID)===a.root.personId?i.jsx("div",{className:"univer-ml-1 univer-inline-flex univer-h-6 univer-w-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:z,children:i.jsx(ve,{})}):null]})]}),i.jsx("div",{ref:P,className:U.clsx("univer-max-h-80 univer-overflow-y-auto univer-overflow-x-hidden",U.scrollbarClassName),children:G.map(b=>i.jsx(We,{unitId:t,subUnitId:r,item:b,isRoot:b.id===(a==null?void 0:a.root.id),editing:g===b.id,resolved:a==null?void 0:a.root.resolved,type:w,onClose:C,onEditingChange:R=>{j(R?b.id:"")},onReply:R=>{R&&requestAnimationFrame(()=>{var H;(H=L.current)==null||H.reply(Ae([{type:"mention",content:{id:R.userID,label:`@${R.name}`}},{type:"text",content:" "}]))})},onAddComment:m,onDeleteComment:f},b.id))}),X&&i.jsx("div",{children:i.jsx(ge,{ref:L,type:w,unitId:t,subUnitId:r,onSave:async({text:b,attachments:R})=>{const H={text:b,attachments:R,dT:V.getDT(),id:d.generateRandomId(),ref:s,personId:M==null?void 0:M.userID,parentId:a==null?void 0:a.root.id,unitId:t,subUnitId:r,threadId:a==null?void 0:a.root.threadId};(m==null?void 0:m(H))!==!1&&(await _.executeCommand(V.AddCommentCommand.id,{unitId:t,subUnitId:r,comment:H}),P.current&&(P.current.scrollTop=P.current.scrollHeight))},autoFocus:B||!a,onCancel:()=>{a||C==null||C()}},`${B}`)})]})},Ze=n=>{const{unitId:e,subUnitId$:t,type:r,onAdd:s,getSubUnitName:o,onResolve:u,sortComments:y,onItemLeave:C,onItemEnter:N,disableAdd:D,tempComment:B,onAddComment:$,onDeleteComment:S,showComments:m}=n,[f,E]=c.useState("all"),[w,A]=c.useState("all"),I=h.useDependency(d.LocaleService),O=h.useDependency(d.UserManagerService),v=h.useDependency(V.ThreadCommentModel),[p,g]=c.useState(()=>v.getUnit(e)),j=h.useDependency(exports.ThreadCommentPanelService),x=h.useObservable(j.activeCommentId$),a=h.useObservable(v.commentUpdate$),_=h.useDependency(d.ICommandService),Z=h.useObservable(t),k=c.useRef(!0),M="panel",L=h.useObservable(O.currentUser$),G=c.useMemo(()=>{var H;const l=f==="all"?p:(H=p.filter(T=>T.subUnitId===Z))!=null?H:[],b=y!=null?y:(T=>T),R=l.map(T=>{var F;return{...T.root,children:(F=T.children)!=null?F:[],users:T.relativeUsers}});if(m){const T=new Map;return R.forEach(F=>{T.set(F.id,F)}),[...m,""].map(F=>T.get(F)).filter(Boolean)}else return b(R)},[m,f,p,y,Z]),P=c.useMemo(()=>[...G.filter(l=>!l.resolved),...G.filter(l=>l.resolved)],[G]),J=c.useMemo(()=>w==="resolved"?P.filter(l=>l.resolved):w==="unsolved"?P.filter(l=>!l.resolved):w==="concern_me"&&L!=null&&L.userID?P.filter(l=>l==null?void 0:l.users.has(L.userID)):P,[P,L==null?void 0:L.userID,w]),z=B?[B,...J]:J,Q=z.filter(l=>!l.resolved),X=z.filter(l=>l.resolved),ee=w!=="all"||f!=="all",te=()=>{A("all"),E("all")};c.useEffect(()=>{e&&g(v.getUnit(e))},[e,v,a]),c.useEffect(()=>{var T;if(!x)return;if(!k.current){k.current=!0;return}const{unitId:l,subUnitId:b,commentId:R}=x,H=`${M}-${l}-${b}-${R}`;(T=document.getElementById(H))==null||T.scrollIntoView({block:"center"})},[x]);const Y=l=>i.jsx(Ie,{full:!0,prefix:M,getSubUnitName:o,id:l.id,unitId:l.unitId,subUnitId:l.subUnitId,refStr:l.ref,type:r,showEdit:(x==null?void 0:x.commentId)===l.id,showHighlight:(x==null?void 0:x.commentId)===l.id,onClick:()=>{k.current=!1,l.resolved?_.executeCommand(W.id):_.executeCommand(W.id,{unitId:l.unitId,subUnitId:l.subUnitId,commentId:l.id,temp:!1})},onMouseEnter:()=>N==null?void 0:N(l),onMouseLeave:()=>C==null?void 0:C(l),onAddComment:$,onDeleteComment:S,onResolve:b=>u==null?void 0:u(l.id,b)},l.id);return i.jsxs("div",{className:"univer-flex univer-min-h-full univer-flex-col univer-pb-3",children:[i.jsxs("div",{className:"univer-mt-3 univer-flex univer-flex-row univer-justify-between",children:[r===d.UniverInstanceType.UNIVER_SHEET?i.jsx(U.Select,{borderless:!0,value:f,options:[{value:"current",label:I.t("threadCommentUI.filter.sheet.current")},{value:"all",label:I.t("threadCommentUI.filter.sheet.all")}],onChange:E}):null,i.jsx(U.Select,{borderless:!0,value:w,options:[{value:"all",label:I.t("threadCommentUI.filter.status.all")},{value:"resolved",label:I.t("threadCommentUI.filter.status.resolved")},{value:"unsolved",label:I.t("threadCommentUI.filter.status.unsolved")},{value:"concern_me",label:I.t("threadCommentUI.filter.status.concernMe")}],onChange:A})]}),z.length===0?i.jsxs("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:[I.t("threadCommentUI.panel.empty"),ee?i.jsx("div",{className:"univer-mt-2 univer-flex univer-flex-row",children:i.jsx(U.Button,{onClick:te,children:I.t("threadCommentUI.panel.reset")})}):D?null:i.jsx("div",{className:"univer-mt-2 univer-flex univer-flex-row",children:i.jsxs(U.Button,{onClick:s,children:[i.jsx(me,{className:"univer-mr-1.5"}),I.t("threadCommentUI.panel.addComment")]})})]}):i.jsxs("div",{className:"univer-mt-3 univer-flex univer-flex-col univer-gap-3",children:[Q.map(Y),X.length>0&&i.jsx("div",{className:"univer-text-xs",children:I.t("threadCommentUI.panel.solved")}),X.map(Y)]})]})};exports.SetActiveCommentOperation=W;exports.THREAD_COMMENT_PANEL=le;exports.ThreadCommentPanel=Ze;exports.ThreadCommentTree=Ie;exports.ToggleSheetCommentPanelOperation=ce;