@univerjs/thread-comment-ui 0.1.17 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var ge=Object.defineProperty;var pe=(n,e,t)=>e in n?ge(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var $=(n,e,t)=>pe(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("@univerjs/thread-comment"),d=require("@univerjs/core"),W=require("@wendellhu/redi"),R=require("@univerjs/ui"),G=require("rxjs"),a=require("react"),y=require("@wendellhu/redi/react-bindings"),x=require("@univerjs/design"),Ie=require("dayjs"),Se=require("clsx"),te="thread-comment-panel",be="THREAD_COMMENT_UI_PLUGIN";var ye=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,Te=(n,e,t,r)=>{for(var o=r>1?void 0:r?Ee(e,t):e,i=n.length-1,s;i>=0;i--)(s=n[i])&&(o=(r?s(e,t,o):s(o))||o);return r&&o&&ye(e,t,o),o},X=(n,e)=>(t,r)=>e(t,r,n);exports.ThreadCommentPanelService=class extends d.Disposable{constructor(t,r){super();$(this,"_panelVisible",!1);$(this,"_panelVisible$",new G.BehaviorSubject(!1));$(this,"_activeCommentId");$(this,"_activeCommentId$",new G.BehaviorSubject(void 0));$(this,"panelVisible$",this._panelVisible$.asObservable());$(this,"activeCommentId$",this._activeCommentId$.asObservable());this._sidebarService=t,this._univerInstanceService=r,this._init()}_init(){this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(t=>{t.visible||this.setPanelVisible(!1)})),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(G.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=Te([X(0,W.Inject(R.ISidebarService)),X(1,d.IUniverInstanceService)],exports.ThreadCommentPanelService);const ne={id:"thread-comment-ui.operation.toggle-panel",type:d.CommandType.OPERATION,handler(n){const e=n.get(R.ISidebarService),t=n.get(exports.ThreadCommentPanelService);return t.panelVisible?(e.close(),t.setPanelVisible(!1)):(e.open({header:{title:"threadCommentUI.panel.title"},children:{label:te},width:320}),t.setPanelVisible(!0)),!0}},K={id:"thread-comment-ui.operation.set-active-comment",type:d.CommandType.OPERATION,handler(n,e){return n.get(exports.ThreadCommentPanelService).setActiveComment(e),!0}};var _e=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,Ue=(n,e,t,r)=>{for(var o=r>1?void 0:r?xe(e,t):e,i=n.length-1,s;i>=0;i--)(s=n[i])&&(o=(r?s(e,t,o):s(o))||o);return r&&o&&_e(e,t,o),o},Me=(n,e)=>(t,r)=>e(t,r,n);let Z=class extends d.Disposable{constructor(n){super(),this._localeService=n}};Z=Ue([d.OnLifecycle(d.LifecycleStages.Starting,Z),Me(0,W.Inject(d.LocaleService))],Z);class Pe{constructor(){$(this,"trigger","@")}async getMentions(e){return[]}}const J=W.createIdentifier("thread-comment.mention-data.service");var re=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,Oe=(n,e,t)=>e in n?re(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,De=(n,e,t,r)=>{for(var o=r>1?void 0:r?Ne(e,t):e,i=n.length-1,s;i>=0;i--)(s=n[i])&&(o=(r?s(e,t,o):s(o))||o);return r&&o&&re(e,t,o),o},ee=(n,e)=>(t,r)=>e(t,r,n),ae=(n,e,t)=>Oe(n,typeof e!="symbol"?e+"":e,t);exports.UniverThreadCommentUIPlugin=class extends d.Plugin{constructor(e,t,r){super(),this._config=e,this._injector=t,this._commandService=r}onStarting(e){var t;d.mergeOverrideWithDependencies([[Z],[exports.ThreadCommentPanelService],[J,{useClass:Pe}]],(t=this._config)==null?void 0:t.overrides).forEach(r=>{e.add(r)}),[ne,K].forEach(r=>{this._commandService.registerCommand(r)})}};ae(exports.UniverThreadCommentUIPlugin,"pluginName",be);ae(exports.UniverThreadCommentUIPlugin,"type",d.UniverInstanceType.UNIVER_UNKNOWN);exports.UniverThreadCommentUIPlugin=De([d.DependentOn(O.UniverThreadCommentPlugin),ee(1,W.Inject(W.Injector)),ee(2,d.ICommandService)],exports.UniverThreadCommentUIPlugin);var _=function(){return _=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o])}return n},_.apply(this,arguments)},we=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 o=0,r=Object.getOwnPropertySymbols(n);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(n,r[o])&&(t[r[o]]=n[r[o]]);return t},k=a.forwardRef(function(n,e){var t=n.icon,r=n.id,o=n.className,i=n.extend,s=we(n,["icon","id","className","extend"]),u="univerjs-icon univerjs-icon-".concat(r," ").concat(o||"").trim(),c=a.useRef("_".concat(He()));return oe(t,"".concat(r),{defIds:t.defIds,idSuffix:c.current},_({ref:e,className:u},s),i)});function oe(n,e,t,r,o){return a.createElement(n.tag,_(_({key:e},$e(n,t,o)),r),(Re(n,t).children||[]).map(function(i,s){return oe(i,"".concat(e,"-").concat(n.tag,"-").concat(s),t,void 0,o)}))}function $e(n,e,t){var r=_({},n.attrs);t!=null&&t.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=t.colorChannel1);var o=e.defIds;return!o||o.length===0||(n.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+e.idSuffix),Object.entries(r).forEach(function(i){var s=i[0],u=i[1];typeof u=="string"&&(r[s]=u.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),r}function Re(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)?_(_({},n),{children:n.children.map(function(o){return typeof o.attrs.id=="string"&&r&&r.indexOf(o.attrs.id)>-1?_(_({},o),{attrs:_(_({},o.attrs),{id:o.attrs.id+e.idSuffix})}):o})}):n}function He(){return Math.random().toString(36).substring(2,8)}k.displayName="UniverIcon";var Le={tag:"svg",attrs:{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.866699 5.9313.866699H10.069C10.4004.866699 10.669 1.13533 10.669 1.4667 10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667zM1.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.64443 14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443zM6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928 9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171 10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778 9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539 9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263 6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539 5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778 6.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"}}]},ie=a.forwardRef(function(n,e){return a.createElement(k,Object.assign({},n,{id:"delete-single",ref:e,icon:Le}))});ie.displayName="DeleteSingle";var je={tag:"svg",attrs:{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"}}]},le=a.forwardRef(function(n,e){return a.createElement(k,Object.assign({},n,{id:"increase-single",ref:e,icon:je}))});le.displayName="IncreaseSingle";var ke={tag:"svg",attrs:{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 8 4 7.44772 3.55228 7 3 7 2.44772 7 2 7.44772 2 8 2 8.55228 2.44772 9 3 9zM8 9C8.55228 9 9 8.55228 9 8 9 7.44772 8.55228 7 8 7 7.44772 7 7 7.44772 7 8 7 8.55228 7.44772 9 8 9zM13 9C13.5523 9 14 8.55228 14 8 14 7.44772 13.5523 7 13 7 12.4477 7 12 7.44772 12 8 12 8.55228 12.4477 9 13 9z"}}]},se=a.forwardRef(function(n,e){return a.createElement(k,Object.assign({},n,{id:"more-horizontal-single",ref:e,icon:ke}))});se.displayName="MoreHorizontalSingle";var Ae={tag:"svg",attrs:{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.76813M8.91626 6.1311H9.27424M3.90454 6.1311H4.26252",strokeLinecap:"round",strokeWidth:1.2}}]},me=a.forwardRef(function(n,e){return a.createElement(k,Object.assign({},n,{id:"reply-to-comment-single",ref:e,icon:Ae}))});me.displayName="ReplyToCommentSingle";var Ve={tag:"svg",attrs:{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"}}]},de=a.forwardRef(function(n,e){return a.createElement(k,Object.assign({},n,{id:"resolved-single",ref:e,icon:Ve}))});de.displayName="ResolvedSingle";var Be={tag:"svg",attrs:{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=a.forwardRef(function(n,e){return a.createElement(k,Object.assign({},n,{id:"solve-single",ref:e,icon:Be}))});ce.displayName="SolveSingle";const We="univer-thread-comment-editor-buttons",qe="univer-thread-comment-editor-suggestion",Fe="univer-thread-comment-editor-suggestionActive",ze="univer-thread-comment-editor-suggestion-icon",Y={threadCommentEditorButtons:We,threadCommentEditorSuggestion:qe,threadCommentEditorSuggestionActive:Fe,threadCommentEditorSuggestionIcon:ze},Ze=n=>{const e=/@\[(.*?)\]\((.*?)\)|(\w+)/g;let t,r=0;const o=[];for(;(t=e.exec(n))!==null;)t.index>r&&o.push({type:"text",content:n.substring(r,t.index)}),t[1]&&t[2]?o.push({type:"mention",content:{label:t[1],id:t[2]}}):t[3]&&o.push({type:"text",content:t[3]}),r=e.lastIndex;return r<n.length&&o.push({type:"text",content:n.substring(r)}),o},Ye=n=>n.map(e=>{switch(e.type){case"mention":return`@[${e.content.label}](${e.content.id})`;default:return e.content}}).join(""),ue=n=>{const{dataStream:e,customRanges:t}=n,r=e.length-2,o=[];let i=0;return t==null||t.forEach(s=>{i<s.startIndex&&o.push({type:"text",content:e.slice(i,s.startIndex)}),o.push({type:"mention",content:{label:e.slice(s.startIndex,s.endIndex).slice(1,-1),id:s.rangeId}}),i=s.endIndex}),o.push({type:"text",content:e.slice(i,r)}),o},he=n=>{let e="";const t=[];return n.forEach(r=>{switch(r.type){case"text":e+=r.content;break;case"mention":{const o=e.length;e+=`${r.content.label}`;const i=e.length;t.push({rangeId:r.content.id,rangeType:d.CustomRangeType.MENTION,startIndex:o,endIndex:i});break}}}),e+=`
2
- \r`,{textRuns:[],paragraphs:[{startIndex:e.length-2,paragraphStyle:{}}],sectionBreaks:[{startIndex:e.length-1}],dataStream:e,customRanges:t}},Ge=n=>({display:n.label,id:`${n.id}`,raw:n}),Ke=(n,e,t,r,o)=>{var s,u;const i=(s=n.raw)==null?void 0:s.icon;return a.createElement("div",{className:Y.threadCommentEditorSuggestion},i?a.createElement("img",{className:Y.threadCommentEditorSuggestionIcon,src:i}):null,a.createElement("div",null,(u=n.display)!=null?u:n.id))},ve=a.forwardRef((n,e)=>{var h;const{comment:t,onSave:r,id:o,onCancel:i,autoFocus:s}=n,u=y.useDependency(J),c=y.useDependency(d.LocaleService),[g,p]=a.useState({...t}),[U,I]=a.useState(!1),S=a.useRef(null);return a.useImperativeHandle(e,()=>({reply(b){var v;p({...t,text:b,attachments:[]}),(v=S.current)==null||v.inputElement.focus()}})),a.createElement("div",{className:Y.threadCommentEditor,onClick:b=>b.preventDefault()},a.createElement(x.Mentions,{ref:S,autoFocus:s,style:{width:"100%"},placeholder:c.t("threadCommentUI.editor.placeholder"),value:g!=null&&g.text?Ye(ue(g.text)):"",onChange:b=>{b.target.value||p({...t,text:void 0}),p==null||p({...t,text:he(Ze(b.target.value))})},onFocus:()=>{I(!0)}},a.createElement(x.Mention,{key:u.trigger,trigger:u.trigger,data:(b,v)=>u.getMentions(b).then(M=>M.map(Ge)).then(v),displayTransform:(b,v)=>`@${v} `,renderSuggestion:(h=u.renderSuggestion)!=null?h:Ke})),U?a.createElement("div",{className:Y.threadCommentEditorButtons},a.createElement(x.Button,{style:{marginRight:12},onClick:()=>{i==null||i(),I(!1),p({text:void 0})}},c.t("threadCommentUI.editor.cancel")),a.createElement(x.Button,{type:"primary",disabled:!g.text,onClick:()=>{g.text&&(r==null||r({...g,text:g.text}),I(!1),p({text:void 0}))}},c.t(o?"threadCommentUI.editor.save":"threadCommentUI.editor.reply"))):null)}),Je="univer-thread-comment",Qe="univer-thread-comment-active",Xe="univer-thread-comment-content",et="univer-thread-comment-highlight",tt="univer-thread-comment-icon-container",nt="univer-thread-comment-icon",rt="univer-thread-comment-title",at="univer-thread-comment-title-position",ot="univer-thread-comment-title-highlight",it="univer-thread-comment-username",lt="univer-thread-comment-item",st="univer-thread-comment-item-head",mt="univer-thread-comment-item-title",dt="univer-thread-comment-item-title-position",ct="univer-thread-comment-item-title-highlight",ut="univer-thread-comment-item-time",ht="univer-thread-comment-item-content",vt="univer-thread-comment-item-at",f={threadComment:Je,threadCommentActive:Qe,threadCommentContent:Xe,threadCommentHighlight:et,threadCommentIconContainer:tt,threadCommentIcon:nt,threadCommentTitle:rt,threadCommentTitlePosition:at,threadCommentTitleHighlight:ot,threadCommentUsername:it,threadCommentItem:lt,threadCommentItemHead:st,threadCommentItemTitle:mt,threadCommentItemTitlePosition:dt,threadCommentItemTitleHighlight:ct,threadCommentItemTime:ut,threadCommentItemContent:ht,threadCommentItemAt:vt},Ce="__mock__",Ct=n=>{const{item:e,unitId:t,subUnitId:r,editing:o,onEditingChange:i,onReply:s,resolved:u,isRoot:c,onClose:g}=n,p=y.useDependency(d.ICommandService),U=y.useDependency(d.LocaleService),I=y.useDependency(d.UserManagerService),S=I.getUser(e.personId),h=R.useObservable(I.currentUser$),b=(h==null?void 0:h.userID)===e.personId,v=e.id===Ce,[M,H]=a.useState(!1),m=()=>{p.executeCommand(c?O.DeleteCommentTreeCommand.id:O.DeleteCommentCommand.id,{unitId:t,subUnitId:r,commentId:e.id}),c&&(g==null||g())};return a.createElement("div",{className:f.threadCommentItem,onMouseLeave:()=>H(!1),onMouseEnter:()=>H(!0)},a.createElement("img",{className:f.threadCommentItemHead,src:S==null?void 0:S.avatar}),a.createElement("div",{className:f.threadCommentItemTitle},a.createElement("div",{className:f.threadCommentUsername},(S==null?void 0:S.name)||" "),a.createElement("div",null,v||u?null:M?a.createElement("div",{className:f.threadCommentIcon,onClick:()=>s(S)},a.createElement(me,null)):null,b&&!v&&!u?a.createElement(x.Dropdown,{overlay:a.createElement(x.Menu,null,a.createElement(x.MenuItem,{key:"edit",onClick:()=>i==null?void 0:i(!0)},U.t("threadCommentUI.item.edit")),a.createElement(x.MenuItem,{key:"delete",onClick:m},U.t("threadCommentUI.item.delete")))},a.createElement("div",{className:f.threadCommentIcon},a.createElement(se,null))):null)),a.createElement("div",{className:f.threadCommentItemTime},e.dT),o?a.createElement(ve,{id:e.id,comment:e,onCancel:()=>i==null?void 0:i(!1),autoFocus:!0,onSave:({text:C,attachments:L})=>{i==null||i(!1),p.executeCommand(O.UpdateCommentCommand.id,{unitId:t,subUnitId:r,payload:{commentId:e.id,text:C,attachments:L}})}}):a.createElement("div",{className:f.threadCommentItemContent},ue(e.text).map((C,L)=>{switch(C.type){case"mention":return a.createElement("a",{className:f.threadCommentItemAt,key:L},"@",C.content.label," ");default:return C.content}})))},fe=n=>{var j,V,F;const{id:e,unitId:t,subUnitId:r,refStr:o,showEdit:i=!0,onClick:s,showHighlight:u,onClose:c,getSubUnitName:g,prefix:p,autoFocus:U,onMouseEnter:I,onMouseLeave:S}=n,h=y.useDependency(O.ThreadCommentModel),[b,v]=a.useState(!1),[M,H]=a.useState("");R.useObservable(h.commentMap$);const m=e?h.getCommentWithChildren(t,r,e):null,C=y.useDependency(d.ICommandService),L=y.useDependency(d.UserManagerService),D=m==null?void 0:m.root.resolved,E=R.useObservable(L.currentUser$),P=a.useRef(null),A=[...m?[m.root]:[{id:Ce,text:{dataStream:`
3
- \r`},personId:(j=E==null?void 0:E.userID)!=null?j:"",ref:o!=null?o:"",dT:"",unitId:t,subUnitId:r}],...(V=m==null?void 0:m.children)!=null?V:[]],q=()=>{C.executeCommand(O.ResolveCommentCommand.id,{unitId:t,subUnitId:r,commentId:e,resolved:!D}),c==null||c()},w=()=>{C.executeCommand(O.DeleteCommentTreeCommand.id,{unitId:t,subUnitId:r,commentId:e}),c==null||c()};return a.createElement("div",{className:Se(f.threadComment,{[f.threadCommentActive]:!D&&(u||b||p==="cell")}),onClick:s,id:`${p}-${t}-${r}-${e}`,onMouseEnter:()=>{I==null||I(),v(!0)},onMouseLeave:()=>{S==null||S(),v(!1)}},!D&&u?a.createElement("div",{className:f.threadCommentHighlight}):null,a.createElement("div",{className:f.threadCommentTitle},a.createElement("div",{className:f.threadCommentTitlePosition},a.createElement("div",{className:f.threadCommentTitleHighlight}),o||(m==null?void 0:m.root.ref)," · ",g((F=m==null?void 0:m.root.subUnitId)!=null?F:r)),m?a.createElement("div",{className:f.threadCommentIconContainer},a.createElement("div",{onClick:q,className:f.threadCommentIcon,style:{color:D?"rgb(var(--green-500))":""}},D?a.createElement(de,null):a.createElement(ce,null)),(E==null?void 0:E.userID)===m.root.personId?a.createElement("div",{className:f.threadCommentIcon,onClick:w},a.createElement(ie,null)):null):null),a.createElement("div",{className:f.threadCommentContent},A.map(l=>a.createElement(Ct,{onClose:c,unitId:t,subUnitId:r,item:l,key:l.id,isRoot:l.id===(m==null?void 0:m.root.id),editing:M===l.id,resolved:m==null?void 0:m.root.resolved,onEditingChange:T=>{H(T?l.id:"")},onReply:T=>{var N;T&&((N=P.current)==null||N.reply(he([{type:"mention",content:{id:T.userID,label:T.name}}])))}}))),i&&!M&&!D?a.createElement("div",null,a.createElement(ve,{key:`${U}`,ref:P,onSave:({text:l,attachments:T})=>{C.executeCommand(O.AddCommentCommand.id,{unitId:t,subUnitId:r,comment:{text:l,attachments:T,dT:Ie().format("YYYY/MM/DD HH:mm"),id:d.Tools.generateRandomId(),ref:o,personId:E==null?void 0:E.userID,parentId:m==null?void 0:m.root.id,unitId:t,subUnitId:r}})},autoFocus:U||!m,onCancel:()=>{m||c==null||c()}})):null)},ft="univer-thread-comment-panel",gt="univer-thread-comment",pt="univer-thread-comment-panel-forms",It="univer-select",St="univer-thread-comment-panel-empty",bt="univer-thread-comment-panel-add",z={threadCommentPanel:ft,threadComment:gt,threadCommentPanelForms:pt,select:It,threadCommentPanelEmpty:St,threadCommentPanelAdd:bt},yt=n=>{const{unitId:e,subUnitId$:t,type:r,onAdd:o,getSubUnitName:i,onResolve:s,sortComments:u,onItemLeave:c,onItemEnter:g}=n,[p,U]=a.useState("all"),[I,S]=a.useState("all"),h=y.useDependency(d.LocaleService),b=y.useDependency(d.UserManagerService),v=y.useDependency(O.ThreadCommentModel),[M,H]=a.useState(()=>v.getUnit(e)),m=y.useDependency(exports.ThreadCommentPanelService),C=R.useObservable(m.activeCommentId$),L=R.useObservable(v.commentUpdate$),D=y.useDependency(d.ICommandService),E=R.useObservable(t),P=b.getCurrentUser(),A=a.useRef(!0),q="panel",w=a.useMemo(()=>{var l,T;if(p==="all"){const N=M.map(B=>B[1]).flat().filter(B=>!B.parentId);return u?u(N):N}else return(T=(l=M.find(N=>N[0]===E))==null?void 0:l[1])!=null?T:[]},[p,M,E,u]),j=a.useMemo(()=>I==="resolved"?w.filter(l=>l.resolved):I==="unsolved"?w.filter(l=>!l.resolved):I==="concern_me"&&P!=null&&P.userID?w.map(l=>v.getCommentWithChildren(l.unitId,l.subUnitId,l.id)).map(l=>l!=null&&l.relativeUsers.has(P.userID)?l.root:null).filter(Boolean):w,[w,P==null?void 0:P.userID,I,v]),V=I!=="all"||p!=="all",F=()=>{S("all"),U("all")};return a.useEffect(()=>{e&&H(v.getUnit(e))},[e,v,L]),a.useEffect(()=>{var Q;if(!C)return;if(!A.current){A.current=!0;return}const{unitId:l,subUnitId:T,commentId:N}=C,B=`${q}-${l}-${T}-${N}`;(Q=document.getElementById(B))==null||Q.scrollIntoView({block:"center"})},[C]),a.createElement("div",{className:z.threadCommentPanel},a.createElement("div",{className:z.threadCommentPanelForms},a.createElement(x.Select,{borderless:!0,value:p,onChange:l=>U(l),options:[{value:"current",label:h.t("threadCommentUI.filter.sheet.current")},{value:"all",label:h.t("threadCommentUI.filter.sheet.all")}]}),a.createElement(x.Select,{borderless:!0,value:I,onChange:l=>S(l),options:[{value:"all",label:h.t("threadCommentUI.filter.status.all")},{value:"resolved",label:h.t("threadCommentUI.filter.status.resolved")},{value:"unsolved",label:h.t("threadCommentUI.filter.status.unsolved")},{value:"concern_me",label:h.t("threadCommentUI.filter.status.concernMe")}]})),j==null?void 0:j.map(l=>a.createElement(fe,{prefix:q,getSubUnitName:i,key:l.id,id:l.id,unitId:l.unitId,subUnitId:l.subUnitId,type:r,showEdit:(C==null?void 0:C.commentId)===l.id,showHighlight:(C==null?void 0:C.commentId)===l.id,onClick:()=>{A.current=!1,D.executeCommand(K.id,{unitId:l.unitId,subUnitId:l.subUnitId,commentId:l.id,temp:!0})},onClose:()=>s==null?void 0:s(l.id),onMouseEnter:()=>g==null?void 0:g(l),onMouseLeave:()=>c==null?void 0:c(l)})),j.length?null:a.createElement("div",{className:z.threadCommentPanelEmpty},V?h.t("threadCommentUI.panel.filterEmpty"):h.t("threadCommentUI.panel.empty"),V?a.createElement(x.Button,{onClick:F,type:"link"},h.t("threadCommentUI.panel.reset")):a.createElement(x.Button,{id:"thread-comment-add",className:z.threadCommentPanelAdd,type:"primary",onClick:o},a.createElement(le,null),h.t("threadCommentUI.panel.addComment"))))};exports.IThreadCommentMentionDataService=J;exports.SetActiveCommentOperation=K;exports.THREAD_COMMENT_PANEL=te;exports.ThreadCommentPanel=yt;exports.ThreadCommentTree=fe;exports.ToggleSheetCommentPanelOperation=ne;
1
+ "use strict";var Me=Object.defineProperty;var Pe=(n,e,t)=>e in n?Me(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var $=(n,e,t)=>Pe(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ue=require("dayjs"),H=require("@univerjs/thread-comment"),d=require("@univerjs/core"),K=require("@wendellhu/redi"),j=require("@univerjs/ui"),ie=require("rxjs"),a=require("react"),y=require("@wendellhu/redi/react-bindings"),P=require("@univerjs/design"),Ne=require("clsx"),Oe=require("@univerjs/engine-render"),De=require("@univerjs/docs");function de(){return Ue().format("YYYY/MM/DD HH:mm")}const ce="thread-comment-panel",Re="THREAD_COMMENT_UI_PLUGIN";var we=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,He=(n,e,t,r)=>{for(var o=r>1?void 0:r?$e(e,t):e,s=n.length-1,m;s>=0;s--)(m=n[s])&&(o=(r?m(e,t,o):m(o))||o);return r&&o&&we(e,t,o),o},le=(n,e)=>(t,r)=>e(t,r,n);exports.ThreadCommentPanelService=class extends d.Disposable{constructor(t,r){super();$(this,"_panelVisible",!1);$(this,"_panelVisible$",new ie.BehaviorSubject(!1));$(this,"_activeCommentId");$(this,"_activeCommentId$",new ie.BehaviorSubject(void 0));$(this,"panelVisible$",this._panelVisible$.asObservable());$(this,"activeCommentId$",this._activeCommentId$.asObservable());this._sidebarService=t,this._univerInstanceService=r,this._init()}_init(){this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(t=>{t.visible||this.setPanelVisible(!1)})),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(ie.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=He([le(0,K.Inject(j.ISidebarService)),le(1,d.IUniverInstanceService)],exports.ThreadCommentPanelService);const ue={id:"thread-comment-ui.operation.toggle-panel",type:d.CommandType.OPERATION,handler(n){const e=n.get(j.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:320}),t.setPanelVisible(!0)),!0}},V={id:"thread-comment-ui.operation.set-active-comment",type:d.CommandType.OPERATION,handler(n,e){return n.get(exports.ThreadCommentPanelService).setActiveComment(e),!0}};var je=Object.defineProperty,Le=Object.getOwnPropertyDescriptor,Ae=(n,e,t,r)=>{for(var o=r>1?void 0:r?Le(e,t):e,s=n.length-1,m;s>=0;s--)(m=n[s])&&(o=(r?m(e,t,o):m(o))||o);return r&&o&&je(e,t,o),o},ke=(n,e)=>(t,r)=>e(t,r,n);let re=class extends d.Disposable{constructor(n){super(),this._localeService=n}};re=Ae([d.OnLifecycle(d.LifecycleStages.Starting,re),ke(0,K.Inject(d.LocaleService))],re);class Ve{constructor(){$(this,"dataSource");$(this,"renderSuggestion");$(this,"trigger","@")}async getMentions(e,t,r){return this.dataSource?this.dataSource.getMentions(e,t,r):[]}}const se=K.createIdentifier("thread-comment.mention-data.service");var he=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,qe=(n,e,t)=>e in n?he(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Fe=(n,e,t,r)=>{for(var o=r>1?void 0:r?Be(e,t):e,s=n.length-1,m;s>=0;s--)(m=n[s])&&(o=(r?m(e,t,o):m(o))||o);return r&&o&&he(e,t,o),o},me=(n,e)=>(t,r)=>e(t,r,n),ve=(n,e,t)=>qe(n,typeof e!="symbol"?e+"":e,t);exports.UniverThreadCommentUIPlugin=class extends d.Plugin{constructor(e,t,r){super(),this._config=e,this._injector=t,this._commandService=r}onStarting(e){var t;d.mergeOverrideWithDependencies([[re],[exports.ThreadCommentPanelService],[se,{useClass:Ve}]],(t=this._config)==null?void 0:t.overrides).forEach(r=>{e.add(r)}),[ue,V].forEach(r=>{this._commandService.registerCommand(r)})}};ve(exports.UniverThreadCommentUIPlugin,"pluginName",Re);ve(exports.UniverThreadCommentUIPlugin,"type",d.UniverInstanceType.UNIVER_UNKNOWN);exports.UniverThreadCommentUIPlugin=Fe([d.DependentOn(H.UniverThreadCommentPlugin),me(1,K.Inject(K.Injector)),me(2,d.ICommandService)],exports.UniverThreadCommentUIPlugin);var M=function(){return M=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o])}return n},M.apply(this,arguments)},We=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 o=0,r=Object.getOwnPropertySymbols(n);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(n,r[o])&&(t[r[o]]=n[r[o]]);return t},B=a.forwardRef(function(n,e){var t=n.icon,r=n.id,o=n.className,s=n.extend,m=We(n,["icon","id","className","extend"]),u="univerjs-icon univerjs-icon-".concat(r," ").concat(o||"").trim(),g=a.useRef("_".concat(Ye()));return Ce(t,"".concat(r),{defIds:t.defIds,idSuffix:g.current},M({ref:e,className:u},m),s)});function Ce(n,e,t,r,o){return a.createElement(n.tag,M(M({key:e},ze(n,t,o)),r),(Ze(n,t).children||[]).map(function(s,m){return Ce(s,"".concat(e,"-").concat(n.tag,"-").concat(m),t,void 0,o)}))}function ze(n,e,t){var r=M({},n.attrs);t!=null&&t.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=t.colorChannel1);var o=e.defIds;return!o||o.length===0||(n.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+e.idSuffix),Object.entries(r).forEach(function(s){var m=s[0],u=s[1];typeof u=="string"&&(r[m]=u.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),r}function Ze(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)?M(M({},n),{children:n.children.map(function(o){return typeof o.attrs.id=="string"&&r&&r.indexOf(o.attrs.id)>-1?M(M({},o),{attrs:M(M({},o.attrs),{id:o.attrs.id+e.idSuffix})}):o})}):n}function Ye(){return Math.random().toString(36).substring(2,8)}B.displayName="UniverIcon";var Ge={tag:"svg",attrs:{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.866699 5.9313.866699H10.069C10.4004.866699 10.669 1.13533 10.669 1.4667 10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667zM1.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.64443 14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443zM6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928 9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171 10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778 9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539 9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263 6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539 5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778 6.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"}}]},fe=a.forwardRef(function(n,e){return a.createElement(B,Object.assign({},n,{id:"delete-single",ref:e,icon:Ge}))});fe.displayName="DeleteSingle";var Ke={tag:"svg",attrs:{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"}}]},ge=a.forwardRef(function(n,e){return a.createElement(B,Object.assign({},n,{id:"increase-single",ref:e,icon:Ke}))});ge.displayName="IncreaseSingle";var Je={tag:"svg",attrs:{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 8 4 7.44772 3.55228 7 3 7 2.44772 7 2 7.44772 2 8 2 8.55228 2.44772 9 3 9zM8 9C8.55228 9 9 8.55228 9 8 9 7.44772 8.55228 7 8 7 7.44772 7 7 7.44772 7 8 7 8.55228 7.44772 9 8 9zM13 9C13.5523 9 14 8.55228 14 8 14 7.44772 13.5523 7 13 7 12.4477 7 12 7.44772 12 8 12 8.55228 12.4477 9 13 9z"}}]},pe=a.forwardRef(function(n,e){return a.createElement(B,Object.assign({},n,{id:"more-horizontal-single",ref:e,icon:Je}))});pe.displayName="MoreHorizontalSingle";var Qe={tag:"svg",attrs:{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.76813M8.91626 6.1311H9.27424M3.90454 6.1311H4.26252",strokeLinecap:"round",strokeWidth:1.2}}]},Ie=a.forwardRef(function(n,e){return a.createElement(B,Object.assign({},n,{id:"reply-to-comment-single",ref:e,icon:Qe}))});Ie.displayName="ReplyToCommentSingle";var Xe={tag:"svg",attrs:{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"}}]},Se=a.forwardRef(function(n,e){return a.createElement(B,Object.assign({},n,{id:"resolved-single",ref:e,icon:Xe}))});Se.displayName="ResolvedSingle";var et={tag:"svg",attrs:{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}}]},be=a.forwardRef(function(n,e){return a.createElement(B,Object.assign({},n,{id:"solve-single",ref:e,icon:et}))});be.displayName="SolveSingle";const tt="univer-thread-comment-editor-buttons",nt="univer-thread-comment-editor-suggestion",rt="univer-thread-comment-editor-suggestionActive",at="univer-thread-comment-editor-suggestion-icon",ae={threadCommentEditorButtons:tt,threadCommentEditorSuggestion:nt,threadCommentEditorSuggestionActive:rt,threadCommentEditorSuggestionIcon:at},ot=n=>{const e=/@\[(.*?)\]\((.*?)\)|(\w+)/g;let t,r=0;const o=[];for(;(t=e.exec(n))!==null;)t.index>r&&o.push({type:"text",content:n.substring(r,t.index)}),t[1]&&t[2]?o.push({type:"mention",content:{label:t[1],id:t[2]}}):t[3]&&o.push({type:"text",content:t[3]}),r=e.lastIndex;return r<n.length&&o.push({type:"text",content:n.substring(r)}),o},it=n=>n.map(e=>{switch(e.type){case"mention":return`@[${e.content.label}](${e.content.id})`;default:return e.content}}).join(""),ye=n=>{const{dataStream:e,customRanges:t}=n,r=e.length-2,o=[];let s=0;return t==null||t.forEach(m=>{s<m.startIndex&&o.push({type:"text",content:e.slice(s,m.startIndex)}),o.push({type:"mention",content:{label:e.slice(m.startIndex,m.endIndex).slice(1,-1),id:m.rangeId}}),s=m.endIndex}),o.push({type:"text",content:e.slice(s,r)}),o},Ee=n=>{let e="";const t=[];return n.forEach(r=>{switch(r.type){case"text":e+=r.content;break;case"mention":{const o=e.length;e+=`${r.content.label}`;const s=e.length;t.push({rangeId:r.content.id,rangeType:d.CustomRangeType.MENTION,startIndex:o,endIndex:s});break}}}),e+=`
2
+ \r`,{textRuns:[],paragraphs:[{startIndex:e.length-2,paragraphStyle:{}}],sectionBreaks:[{startIndex:e.length-1}],dataStream:e,customRanges:t}},st=n=>({display:n.label,id:`${n.id}`,raw:n}),lt=(n,e,t,r,o)=>{var m,u;const s=(m=n.raw)==null?void 0:m.icon;return a.createElement("div",{className:ae.threadCommentEditorSuggestion},s?a.createElement("img",{className:ae.threadCommentEditorSuggestionIcon,src:s}):null,a.createElement("div",null,(u=n.display)!=null?u:n.id))},Te=a.forwardRef((n,e)=>{var C;const{comment:t,onSave:r,id:o,onCancel:s,autoFocus:m,unitId:u,subUnitId:g}=n,T=y.useDependency(se),D=y.useDependency(d.ICommandService),_=y.useDependency(d.LocaleService),[S,v]=a.useState({...t}),[p,b]=a.useState(!1),U=a.useRef(null),E=y.useDependency(Oe.ITextSelectionRenderManager),L=y.useDependency(De.TextSelectionManagerService);return a.useImperativeHandle(e,()=>({reply(f){var c;v({...t,text:f,attachments:[]}),(c=U.current)==null||c.inputElement.focus()}})),a.createElement("div",{className:ae.threadCommentEditor,onClick:f=>f.preventDefault()},a.createElement(P.Mentions,{ref:U,autoFocus:m,style:{width:"100%"},placeholder:_.t("threadCommentUI.editor.placeholder"),value:S!=null&&S.text?it(ye(S.text)):"",onChange:f=>{f.target.value||v({...t,text:void 0}),v==null||v({...t,text:Ee(ot(f.target.value))})},onFocus:()=>{const f=L.getActiveRange();f&&f.collapsed&&E.removeAllTextRanges(),E.blur(),b(!0)}},a.createElement(P.Mention,{key:T.trigger,trigger:T.trigger,data:(f,c)=>T.getMentions(f,u,g).then(l=>l.map(st)).then(c),displayTransform:(f,c)=>`@${c} `,renderSuggestion:(C=T.renderSuggestion)!=null?C:lt})),p?a.createElement("div",{className:ae.threadCommentEditorButtons},a.createElement(P.Button,{style:{marginRight:12},onClick:()=>{s==null||s(),b(!1),v({text:void 0}),D.executeCommand(V.id)}},_.t("threadCommentUI.editor.cancel")),a.createElement(P.Button,{type:"primary",disabled:!S.text,onClick:()=>{S.text&&(r==null||r({...S,text:S.text}),b(!1),v({text:void 0}))}},_.t(o?"threadCommentUI.editor.save":"threadCommentUI.editor.reply"))):null)}),mt="univer-thread-comment",dt="univer-thread-comment-active",ct="univer-thread-comment-content",ut="univer-thread-comment-highlight",ht="univer-thread-comment-icon-container",vt="univer-thread-comment-icon",Ct="univer-thread-comment-title",ft="univer-thread-comment-title-position",gt="univer-thread-comment-title-highlight",pt="univer-thread-comment-title-position-text",It="univer-thread-comment-username",St="univer-thread-comment-item",bt="univer-thread-comment-item-head",yt="univer-thread-comment-item-title",Et="univer-thread-comment-item-title-position",Tt="univer-thread-comment-item-title-highlight",xt="univer-thread-comment-item-time",_t="univer-thread-comment-item-content",Mt="univer-thread-comment-item-at",h={threadComment:mt,threadCommentActive:dt,threadCommentContent:ct,threadCommentHighlight:ut,threadCommentIconContainer:ht,threadCommentIcon:vt,threadCommentTitle:Ct,threadCommentTitlePosition:ft,threadCommentTitleHighlight:gt,threadCommentTitlePositionText:pt,threadCommentUsername:It,threadCommentItem:St,threadCommentItemHead:bt,threadCommentItemTitle:yt,threadCommentItemTitlePosition:Et,threadCommentItemTitleHighlight:Tt,threadCommentItemTime:xt,threadCommentItemContent:_t,threadCommentItemAt:Mt},xe="__mock__",Pt=n=>{const{item:e,unitId:t,subUnitId:r,editing:o,onEditingChange:s,onReply:m,resolved:u,isRoot:g,onClose:T,onDeleteComment:D}=n,_=y.useDependency(d.ICommandService),S=y.useDependency(d.LocaleService),v=y.useDependency(d.UserManagerService),p=v.getUser(e.personId),b=j.useObservable(v.currentUser$),U=(b==null?void 0:b.userID)===e.personId,E=e.id===xe,[L,C]=a.useState(!1),f=()=>{(D==null?void 0:D(e))!==!1&&(_.executeCommand(g?H.DeleteCommentTreeCommand.id:H.DeleteCommentCommand.id,{unitId:t,subUnitId:r,commentId:e.id}),g&&(T==null||T()))};return a.createElement("div",{className:h.threadCommentItem,onMouseLeave:()=>C(!1),onMouseEnter:()=>C(!0)},a.createElement("img",{className:h.threadCommentItemHead,src:p==null?void 0:p.avatar}),a.createElement("div",{className:h.threadCommentItemTitle},a.createElement("div",{className:h.threadCommentUsername},(p==null?void 0:p.name)||" "),a.createElement("div",null,E||u?null:L?a.createElement("div",{className:h.threadCommentIcon,onClick:()=>m(p)},a.createElement(Ie,null)):null,U&&!E&&!u?a.createElement(P.Dropdown,{overlay:a.createElement(P.Menu,null,a.createElement(P.MenuItem,{key:"edit",onClick:()=>s==null?void 0:s(!0)},S.t("threadCommentUI.item.edit")),a.createElement(P.MenuItem,{key:"delete",onClick:f},S.t("threadCommentUI.item.delete")))},a.createElement("div",{className:h.threadCommentIcon},a.createElement(pe,null))):null)),a.createElement("div",{className:h.threadCommentItemTime},e.dT),o?a.createElement(Te,{id:e.id,comment:e,onCancel:()=>s==null?void 0:s(!1),autoFocus:!0,unitId:t,subUnitId:r,onSave:({text:c,attachments:l})=>{s==null||s(!1),_.executeCommand(H.UpdateCommentCommand.id,{unitId:t,subUnitId:r,payload:{commentId:e.id,text:c,attachments:l}})}}):a.createElement("div",{className:h.threadCommentItemContent},ye(e.text).map((c,l)=>{switch(c.type){case"mention":return a.createElement("a",{className:h.threadCommentItemAt,key:l},"@",c.content.label," ");default:return c.content}})))},_e=n=>{var z,Z,Y;const{id:e,unitId:t,subUnitId:r,refStr:o,showEdit:s=!0,onClick:m,showHighlight:u,onClose:g,getSubUnitName:T,prefix:D,autoFocus:_,onMouseEnter:S,onMouseLeave:v,onAddComment:p,onDeleteComment:b,onResolve:U}=n,E=y.useDependency(H.ThreadCommentModel),[L,C]=a.useState(!1),[f,c]=a.useState("");j.useObservable(E.commentMap$);const l=e?E.getCommentWithChildren(t,r,e):null,A=y.useDependency(d.ICommandService),oe=y.useDependency(d.UserManagerService),I=l==null?void 0:l.root.resolved,N=j.useObservable(oe.currentUser$),q=a.useRef(null),J=[...l?[l.root]:[{id:xe,text:{dataStream:`
3
+ \r`},personId:(z=N==null?void 0:N.userID)!=null?z:"",ref:o!=null?o:"",dT:"",unitId:t,subUnitId:r,threadId:""}],...(Z=l==null?void 0:l.children)!=null?Z:[]],F=x=>{x.stopPropagation(),I?A.executeCommand(V.id,{unitId:t,subUnitId:r,commentId:e}):A.executeCommand(V.id),A.executeCommand(H.ResolveCommentCommand.id,{unitId:t,subUnitId:r,commentId:e,resolved:!I}),U==null||U(!I)},Q=x=>{x.stopPropagation(),A.executeCommand(V.id),!(l!=null&&l.root&&(b==null?void 0:b(l.root))===!1)&&(A.executeCommand(H.DeleteCommentTreeCommand.id,{unitId:t,subUnitId:r,commentId:e}),g==null||g())};a.useEffect(()=>v==null?void 0:v(),[]);const R=T((Y=l==null?void 0:l.root.subUnitId)!=null?Y:r),W=s&&!f&&!I,k=`${o||(l==null?void 0:l.root.ref)}${R?" · ":""}${R}`;return a.createElement("div",{className:Ne(h.threadComment,{[h.threadCommentActive]:!I&&(u||L||D==="cell")}),onClick:m,id:`${D}-${t}-${r}-${e}`,onMouseEnter:()=>{S==null||S(),C(!0)},onMouseLeave:()=>{v==null||v(),C(!1)}},!I&&u?a.createElement("div",{className:h.threadCommentHighlight}):null,a.createElement("div",{className:h.threadCommentTitle},a.createElement("div",{className:h.threadCommentTitlePosition},a.createElement("div",{className:h.threadCommentTitleHighlight}),a.createElement("div",{className:h.threadCommentTitlePositionText},k)),l?a.createElement("div",{className:h.threadCommentIconContainer},a.createElement("div",{onClick:F,className:h.threadCommentIcon,style:{color:I?"rgb(var(--green-500))":""}},I?a.createElement(Se,null):a.createElement(be,null)),(N==null?void 0:N.userID)===l.root.personId?a.createElement("div",{className:h.threadCommentIcon,onClick:Q},a.createElement(fe,null)):null):null),a.createElement("div",{className:h.threadCommentContent},J.map(x=>a.createElement(Pt,{onClose:g,unitId:t,subUnitId:r,item:x,key:x.id,isRoot:x.id===(l==null?void 0:l.root.id),editing:f===x.id,resolved:l==null?void 0:l.root.resolved,onEditingChange:i=>{c(i?x.id:"")},onReply:i=>{i&&requestAnimationFrame(()=>{var O;(O=q.current)==null||O.reply(Ee([{type:"mention",content:{id:i.userID,label:i.name}}]))})},onAddComment:p,onDeleteComment:b}))),W?a.createElement("div",null,a.createElement(Te,{key:`${_}`,ref:q,unitId:t,subUnitId:r,onSave:({text:x,attachments:i})=>{const O={text:x,attachments:i,dT:de(),id:d.Tools.generateRandomId(),ref:o,personId:N==null?void 0:N.userID,parentId:l==null?void 0:l.root.id,unitId:t,subUnitId:r,threadId:l==null?void 0:l.root.threadId};(p==null?void 0:p(O))!==!1&&A.executeCommand(H.AddCommentCommand.id,{unitId:t,subUnitId:r,comment:O})},autoFocus:_||!l,onCancel:()=>{l||g==null||g()}})):null)},Ut="univer-thread-comment-panel",Nt="univer-thread-comment",Ot="univer-thread-comment-panel-forms",Dt="univer-select",Rt="univer-thread-comment-panel-empty",wt="univer-thread-comment-panel-add",ne={threadCommentPanel:Ut,threadComment:Nt,threadCommentPanelForms:Ot,select:Dt,threadCommentPanelEmpty:Rt,threadCommentPanelAdd:wt},$t=n=>{const{unitId:e,subUnitId$:t,type:r,onAdd:o,getSubUnitName:s,onResolve:m,sortComments:u,onItemLeave:g,onItemEnter:T,disableAdd:D,tempComment:_,onAddComment:S,onDeleteComment:v,showComments:p}=n,[b,U]=a.useState("all"),[E,L]=a.useState("all"),C=y.useDependency(d.LocaleService),f=y.useDependency(d.UserManagerService),c=y.useDependency(H.ThreadCommentModel),[l,A]=a.useState(()=>c.getUnit(e)),oe=y.useDependency(exports.ThreadCommentPanelService),I=j.useObservable(oe.activeCommentId$),N=j.useObservable(c.commentUpdate$),q=y.useDependency(d.ICommandService),J=j.useObservable(t),F=a.useRef(!0),Q="panel",R=j.useObservable(f.currentUser$),W=a.useMemo(()=>{var ee,G;const i=(b==="all"?l.map(w=>w[1]).flat():(G=(ee=l.find(w=>w[0]===J))==null?void 0:ee[1])!=null?G:[]).filter(w=>!w.parentId),O=u!=null?u:w=>w,X=i;if(p){const w=new Map;return X.forEach(te=>{w.set(te.id,te)}),[...p,""].map(te=>w.get(te)).filter(Boolean)}else return O(X)},[p,b,l,u,J]),k=a.useMemo(()=>[...W.filter(i=>!i.resolved),...W.filter(i=>i.resolved)],[W]),z=a.useMemo(()=>E==="resolved"?k.filter(i=>i.resolved):E==="unsolved"?k.filter(i=>!i.resolved):E==="concern_me"&&R!=null&&R.userID?k.map(i=>c.getCommentWithChildren(i.unitId,i.subUnitId,i.id)).map(i=>i!=null&&i.relativeUsers.has(R.userID)?i.root:null).filter(Boolean):k,[k,R==null?void 0:R.userID,E,c]),Z=_?[_,...z]:z,Y=E!=="all"||b!=="all",x=()=>{L("all"),U("all")};return a.useEffect(()=>{e&&A(c.getUnit(e))},[e,c,N]),a.useEffect(()=>{var G;if(!I)return;if(!F.current){F.current=!0;return}const{unitId:i,subUnitId:O,commentId:X}=I,ee=`${Q}-${i}-${O}-${X}`;(G=document.getElementById(ee))==null||G.scrollIntoView({block:"center"})},[I]),a.createElement("div",{className:ne.threadCommentPanel},a.createElement("div",{className:ne.threadCommentPanelForms},r===d.UniverInstanceType.UNIVER_SHEET?a.createElement(P.Select,{borderless:!0,value:b,onChange:i=>U(i),options:[{value:"current",label:C.t("threadCommentUI.filter.sheet.current")},{value:"all",label:C.t("threadCommentUI.filter.sheet.all")}]}):null,a.createElement(P.Select,{borderless:!0,value:E,onChange:i=>L(i),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")}]})),Z.map(i=>a.createElement(_e,{prefix:Q,getSubUnitName:s,key:i.id,id:i.id,unitId:i.unitId,subUnitId:i.subUnitId,refStr:i.ref,type:r,showEdit:(I==null?void 0:I.commentId)===i.id,showHighlight:(I==null?void 0:I.commentId)===i.id,onClick:()=>{F.current=!1,i.resolved?q.executeCommand(V.id):q.executeCommand(V.id,{unitId:i.unitId,subUnitId:i.subUnitId,commentId:i.id,temp:!1})},onMouseEnter:()=>T==null?void 0:T(i),onMouseLeave:()=>g==null?void 0:g(i),onAddComment:S,onDeleteComment:v,onResolve:O=>m==null?void 0:m(i.id,O)})),Z.length?null:a.createElement("div",{className:ne.threadCommentPanelEmpty},Y?C.t("threadCommentUI.panel.filterEmpty"):C.t("threadCommentUI.panel.empty"),Y?a.createElement(P.Button,{onClick:x,type:"link"},C.t("threadCommentUI.panel.reset")):a.createElement(P.Button,{id:"thread-comment-add",className:ne.threadCommentPanelAdd,type:"primary",onClick:o,disabled:D},a.createElement(ge,null),C.t("threadCommentUI.panel.addComment"))))};exports.IThreadCommentMentionDataService=se;exports.SetActiveCommentOperation=V;exports.THREAD_COMMENT_PANEL=ce;exports.ThreadCommentPanel=$t;exports.ThreadCommentTree=_e;exports.ToggleSheetCommentPanelOperation=ue;exports.getDT=de;