@univerjs/thread-comment-ui 0.6.1 → 0.6.2
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 +8 -4
- package/lib/es/index.js +301 -290
- package/lib/index.css +1 -1
- package/lib/umd/index.js +8 -4
- package/package.json +9 -10
package/lib/cjs/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
"use strict";var je=Object.defineProperty;var Ue=(n,e,t)=>e in n?je(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var F=(n,e,t)=>Ue(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),L=require("@univerjs/thread-comment"),C=require("@univerjs/ui"),ie=require("rxjs"),i=require("react/jsx-runtime"),H=require("@univerjs/design"),l=require("react"),ae=require("@univerjs/docs-ui");var Ne=Object.getOwnPropertyDescriptor,Ee=(n,e,t,r)=>{for(var o=r>1?void 0:r?Ne(e,t):e,s=n.length-1,m;s>=0;s--)(m=n[s])&&(o=m(o)||o);return o},de=(n,e)=>(t,r)=>e(t,r,n);exports.ThreadCommentPanelService=class extends c.Disposable{constructor(t,r){super();F(this,"_panelVisible",!1);F(this,"_panelVisible$",new ie.BehaviorSubject(!1));F(this,"_activeCommentId");F(this,"_activeCommentId$",new ie.BehaviorSubject(void 0));F(this,"panelVisible$",this._panelVisible$.asObservable());F(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$(c.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=Ee([de(0,c.Inject(C.ISidebarService)),de(1,c.IUniverInstanceService)],exports.ThreadCommentPanelService);const ue="thread-comment-panel",Pe="UNIVER_THREAD_COMMENT_UI_PLUGIN",he={id:"thread-comment-ui.operation.toggle-panel",type:c.CommandType.OPERATION,handler(n){const e=n.get(C.ISidebarService),t=n.get(exports.ThreadCommentPanelService);return t.panelVisible?(e.close(),t.setPanelVisible(!1)):(e.open({header:{title:"threadCommentUI.panel.title"},children:{label:ue},width:330}),t.setPanelVisible(!0)),!0}},B={id:"thread-comment-ui.operation.set-active-comment",type:c.CommandType.OPERATION,handler(n,e){return n.get(exports.ThreadCommentPanelService).setActiveComment(e),!0}},Oe="thread-comment-ui.config",le={};var De=Object.defineProperty,Me=Object.getOwnPropertyDescriptor,Re=(n,e,t)=>e in n?De(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,we=(n,e,t,r)=>{for(var o=r>1?void 0:r?Me(e,t):e,s=n.length-1,m;s>=0;s--)(m=n[s])&&(o=m(o)||o);return o},se=(n,e)=>(t,r)=>e(t,r,n),Ce=(n,e,t)=>Re(n,typeof e!="symbol"?e+"":e,t);exports.UniverThreadCommentUIPlugin=class extends c.Plugin{constructor(e=le,t,r,o){super(),this._config=e,this._injector=t,this._commandService=r,this._configService=o;const{menu:s,...m}=c.merge({},le,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(Oe,m)}onStarting(){var e;c.mergeOverrideWithDependencies([[exports.ThreadCommentPanelService]],(e=this._config)==null?void 0:e.overrides).forEach(t=>{this._injector.add(t)}),[he,B].forEach(t=>{this._commandService.registerCommand(t)})}};Ce(exports.UniverThreadCommentUIPlugin,"pluginName",Pe);Ce(exports.UniverThreadCommentUIPlugin,"type",c.UniverInstanceType.UNIVER_UNKNOWN);exports.UniverThreadCommentUIPlugin=we([c.DependentOn(L.UniverThreadCommentPlugin),se(1,c.Inject(c.Injector)),se(2,c.ICommandService),se(3,c.IConfigService)],exports.UniverThreadCommentUIPlugin);var R=function(){return R=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},R.apply(this,arguments)},$e=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},q=l.forwardRef(function(n,e){var t=n.icon,r=n.id,o=n.className,s=n.extend,m=$e(n,["icon","id","className","extend"]),p="univerjs-icon univerjs-icon-".concat(r," ").concat(o||"").trim(),S=l.useRef("_".concat(Le()));return ve(t,"".concat(r),{defIds:t.defIds,idSuffix:S.current},R({ref:e,className:p},m),s)});function ve(n,e,t,r,o){return l.createElement(n.tag,R(R({key:e},He(n,t,o)),r),(ke(n,t).children||[]).map(function(s,m){return ve(s,"".concat(e,"-").concat(n.tag,"-").concat(m),t,void 0,o)}))}function He(n,e,t){var r=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(function(s){var m=s[0],p=s[1];m==="mask"&&typeof p=="string"&&(r[m]=p.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))});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],p=s[1];typeof p=="string"&&(r[m]=p.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),r}function ke(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)?R(R({},n),{children:n.children.map(function(o){return typeof o.attrs.id=="string"&&r&&r.indexOf(o.attrs.id)>-1?R(R({},o),{attrs:R(R({},o.attrs),{id:o.attrs.id+e.idSuffix})}):o})}):n}function Le(){return Math.random().toString(36).substring(2,8)}q.displayName="UniverIcon";var Ae={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=l.forwardRef(function(n,e){return l.createElement(q,Object.assign({},n,{id:"delete-single",ref:e,icon:Ae}))});fe.displayName="DeleteSingle";var Ve={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"}}]},pe=l.forwardRef(function(n,e){return l.createElement(q,Object.assign({},n,{id:"increase-single",ref:e,icon:Ve}))});pe.displayName="IncreaseSingle";var Be={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"}}]},ge=l.forwardRef(function(n,e){return l.createElement(q,Object.assign({},n,{id:"more-horizontal-single",ref:e,icon:Be}))});ge.displayName="MoreHorizontalSingle";var We={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=l.forwardRef(function(n,e){return l.createElement(q,Object.assign({},n,{id:"reply-to-comment-single",ref:e,icon:We}))});Ie.displayName="ReplyToCommentSingle";var Fe={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"}}]},xe=l.forwardRef(function(n,e){return l.createElement(q,Object.assign({},n,{id:"resolved-single",ref:e,icon:Fe}))});xe.displayName="ResolvedSingle";var qe={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}}]},Se=l.forwardRef(function(n,e){return l.createElement(q,Object.assign({},n,{id:"solve-single",ref:e,icon:qe}))});Se.displayName="SolveSingle";function be(n){var e,t,r="";if(typeof n=="string"||typeof n=="number")r+=n;else if(typeof n=="object")if(Array.isArray(n)){var o=n.length;for(e=0;e<o;e++)n[e]&&(t=be(n[e]))&&(r&&(r+=" "),r+=t)}else for(t in n)n[t]&&(r&&(r+=" "),r+=t);return r}function ze(){for(var n,e,t=0,r="",o=arguments.length;t<o;t++)(n=arguments[t])&&(e=be(n))&&(r&&(r+=" "),r+=e);return r}const Ke="univer-thread-comment-editor-buttons",ce={threadCommentEditorButtons:Ke};function me(n){return{id:"d",body:n,documentStyle:{}}}const ye=l.forwardRef((n,e)=>{var k;const{comment:t,onSave:r,id:o,onCancel:s,autoFocus:m,unitId:p,type:S}=n,U=C.useDependency(c.ICommandService),P=C.useDependency(c.LocaleService),[A,O]=l.useState(!1),N=C.useDependency(ae.IEditorService),h=l.useRef(null),I=S===c.UniverInstanceType.UNIVER_SHEET?c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:p,[D,T]=l.useState(()=>{var u,v,x;return c.BuildTextUtils.transform.getPlainText((x=(v=(u=h.current)==null?void 0:u.getDocumentData().body)==null?void 0:v.dataStream)!=null?x:"")});l.useEffect(()=>{var v,x,d,f;T(c.BuildTextUtils.transform.getPlainText((d=(x=(v=h.current)==null?void 0:v.getDocumentData().body)==null?void 0:x.dataStream)!=null?d:""));const u=(f=h.current)==null?void 0:f.selectionChange$.subscribe(()=>{var z,_,y;T(c.BuildTextUtils.transform.getPlainText((y=(_=(z=h.current)==null?void 0:z.getDocumentData().body)==null?void 0:_.dataStream)!=null?y:""))});return()=>u==null?void 0:u.unsubscribe()},[(k=h.current)==null?void 0:k.selectionChange$]);const w=l.useMemo(()=>({keyCodes:[{keyCode:C.KeyCode.ENTER}],handler:u=>{u===C.KeyCode.ENTER&&U.executeCommand(ae.BreakLineCommand.id)}}),[U]);l.useImperativeHandle(e,()=>({reply(u){var v,x;(v=h.current)==null||v.focus(),(x=h.current)==null||x.setDocumentData(me(u))}}));const b=()=>{if(h.current){const u=c.Tools.deepClone(h.current.getDocumentData().body);O(!1),r==null||r({...t,text:u}),h.current.replaceText(""),setTimeout(()=>{var v,x;(v=h.current)==null||v.setSelectionRanges([]),(x=h.current)==null||x.blur()},10)}};return i.jsxs("div",{className:ce.threadCommentEditor,onClick:u=>u.preventDefault(),children:[i.jsx(ae.RichTextEditor,{ref:h,autoFocus:m,style:{width:"100%"},keyboardEventConfig:w,placeholder:P.t("threadCommentUI.editor.placeholder"),initialValue:(t==null?void 0:t.text)&&me(t.text),onFocusChange:u=>u&&O(u),isSingle:!1,maxHeight:64,onClickOutside:()=>{setTimeout(()=>{N.focus(I)},30)}}),A?i.jsxs("div",{className:ce.threadCommentEditorButtons,children:[i.jsx(H.Button,{style:{marginRight:12},onClick:()=>{var u;s==null||s(),O(!1),(u=h.current)==null||u.replaceText("",!0),U.executeCommand(B.id)},children:P.t("threadCommentUI.editor.cancel")}),i.jsx(H.Button,{type:"primary",disabled:!D,onClick:b,children:P.t(o?"threadCommentUI.editor.save":"threadCommentUI.editor.reply")})]}):null]})}),Ze=n=>{const{dataStream:e,customRanges:t}=n,r=e.endsWith(`\r
|
|
2
|
-
`)?e.length-2:e.length,
|
|
3
|
-
\r`,{textRuns:[],paragraphs:[{startIndex:e.length-2,paragraphStyle:{}}],sectionBreaks:[{startIndex:e.length-1}],dataStream:e,customRanges:t}},
|
|
4
|
-
|
|
1
|
+
"use strict";var _e=Object.defineProperty;var je=(n,e,t)=>e in n?_e(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var F=(n,e,t)=>je(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),k=require("@univerjs/thread-comment"),v=require("@univerjs/ui"),oe=require("rxjs"),o=require("react/jsx-runtime"),V=require("@univerjs/design"),l=require("react"),ae=require("@univerjs/docs-ui");var Ue=Object.getOwnPropertyDescriptor,Ne=(n,e,t,r)=>{for(var i=r>1?void 0:r?Ue(e,t):e,s=n.length-1,m;s>=0;s--)(m=n[s])&&(i=m(i)||i);return i},de=(n,e)=>(t,r)=>e(t,r,n);exports.ThreadCommentPanelService=class extends c.Disposable{constructor(t,r){super();F(this,"_panelVisible",!1);F(this,"_panelVisible$",new oe.BehaviorSubject(!1));F(this,"_activeCommentId");F(this,"_activeCommentId$",new oe.BehaviorSubject(void 0));F(this,"panelVisible$",this._panelVisible$.asObservable());F(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$(c.UniverInstanceType.UNIVER_SHEET).pipe(oe.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=Ne([de(0,c.Inject(v.ISidebarService)),de(1,c.IUniverInstanceService)],exports.ThreadCommentPanelService);const ue="thread-comment-panel",Ee="UNIVER_THREAD_COMMENT_UI_PLUGIN",he={id:"thread-comment-ui.operation.toggle-panel",type:c.CommandType.OPERATION,handler(n){const e=n.get(v.ISidebarService),t=n.get(exports.ThreadCommentPanelService);return t.panelVisible?(e.close(),t.setPanelVisible(!1)):(e.open({header:{title:"threadCommentUI.panel.title"},children:{label:ue},width:330}),t.setPanelVisible(!0)),!0}},B={id:"thread-comment-ui.operation.set-active-comment",type:c.CommandType.OPERATION,handler(n,e){return n.get(exports.ThreadCommentPanelService).setActiveComment(e),!0}},Pe="thread-comment-ui.config",le={};var Oe=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Re=(n,e,t)=>e in n?Oe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Me=(n,e,t,r)=>{for(var i=r>1?void 0:r?De(e,t):e,s=n.length-1,m;s>=0;s--)(m=n[s])&&(i=m(i)||i);return i},se=(n,e)=>(t,r)=>e(t,r,n),ve=(n,e,t)=>Re(n,typeof e!="symbol"?e+"":e,t);exports.UniverThreadCommentUIPlugin=class extends c.Plugin{constructor(e=le,t,r,i){super(),this._config=e,this._injector=t,this._commandService=r,this._configService=i;const{menu:s,...m}=c.merge({},le,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(Pe,m)}onStarting(){var e;c.mergeOverrideWithDependencies([[exports.ThreadCommentPanelService]],(e=this._config)==null?void 0:e.overrides).forEach(t=>{this._injector.add(t)}),[he,B].forEach(t=>{this._commandService.registerCommand(t)})}};ve(exports.UniverThreadCommentUIPlugin,"pluginName",Ee);ve(exports.UniverThreadCommentUIPlugin,"type",c.UniverInstanceType.UNIVER_UNKNOWN);exports.UniverThreadCommentUIPlugin=Me([c.DependentOn(k.UniverThreadCommentPlugin),se(1,c.Inject(c.Injector)),se(2,c.ICommandService),se(3,c.IConfigService)],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 i in e)Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i])}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 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},q=l.forwardRef(function(n,e){var t=n.icon,r=n.id,i=n.className,s=n.extend,m=we(n,["icon","id","className","extend"]),p="univerjs-icon univerjs-icon-".concat(r," ").concat(i||"").trim(),S=l.useRef("_".concat(ke()));return Ce(t,"".concat(r),{defIds:t.defIds,idSuffix:S.current},M({ref:e,className:p},m),s)});function Ce(n,e,t,r,i){return l.createElement(n.tag,M(M({key:e},$e(n,t,i)),r),(He(n,t).children||[]).map(function(s,m){return Ce(s,"".concat(e,"-").concat(n.tag,"-").concat(m),t,void 0,i)}))}function $e(n,e,t){var r=M({},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(s){var m=s[0],p=s[1];m==="mask"&&typeof p=="string"&&(r[m]=p.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(s){var m=s[0],p=s[1];typeof p=="string"&&(r[m]=p.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),r}function He(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(i){return typeof i.attrs.id=="string"&&r&&r.indexOf(i.attrs.id)>-1?M(M({},i),{attrs:M(M({},i.attrs),{id:i.attrs.id+e.idSuffix})}):i})}):n}function ke(){return Math.random().toString(36).substring(2,8)}q.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"}}]},fe=l.forwardRef(function(n,e){return l.createElement(q,Object.assign({},n,{id:"delete-single",ref:e,icon:Le}))});fe.displayName="DeleteSingle";var Ve={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"}}]},pe=l.forwardRef(function(n,e){return l.createElement(q,Object.assign({},n,{id:"increase-single",ref:e,icon:Ve}))});pe.displayName="IncreaseSingle";var Ae={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"}}]},ge=l.forwardRef(function(n,e){return l.createElement(q,Object.assign({},n,{id:"more-horizontal-single",ref:e,icon:Ae}))});ge.displayName="MoreHorizontalSingle";var Be={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=l.forwardRef(function(n,e){return l.createElement(q,Object.assign({},n,{id:"reply-to-comment-single",ref:e,icon:Be}))});Ie.displayName="ReplyToCommentSingle";var We={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"}}]},xe=l.forwardRef(function(n,e){return l.createElement(q,Object.assign({},n,{id:"resolved-single",ref:e,icon:We}))});xe.displayName="ResolvedSingle";var Fe={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}}]},Se=l.forwardRef(function(n,e){return l.createElement(q,Object.assign({},n,{id:"solve-single",ref:e,icon:Fe}))});Se.displayName="SolveSingle";const qe="univer-thread-comment-editor-buttons",ce={threadCommentEditorButtons:qe};function me(n){return{id:"d",body:n,documentStyle:{}}}const be=l.forwardRef((n,e)=>{var H;const{comment:t,onSave:r,id:i,onCancel:s,autoFocus:m,unitId:p,type:S}=n,U=v.useDependency(c.ICommandService),P=v.useDependency(c.LocaleService),[L,O]=l.useState(!1),N=v.useDependency(ae.IEditorService),h=l.useRef(null),I=S===c.UniverInstanceType.UNIVER_SHEET?c.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:p,[D,T]=l.useState(()=>{var u,C,x;return c.BuildTextUtils.transform.getPlainText((x=(C=(u=h.current)==null?void 0:u.getDocumentData().body)==null?void 0:C.dataStream)!=null?x:"")});l.useEffect(()=>{var C,x,d,f;T(c.BuildTextUtils.transform.getPlainText((d=(x=(C=h.current)==null?void 0:C.getDocumentData().body)==null?void 0:x.dataStream)!=null?d:""));const u=(f=h.current)==null?void 0:f.selectionChange$.subscribe(()=>{var z,_,y;T(c.BuildTextUtils.transform.getPlainText((y=(_=(z=h.current)==null?void 0:z.getDocumentData().body)==null?void 0:_.dataStream)!=null?y:""))});return()=>u==null?void 0:u.unsubscribe()},[(H=h.current)==null?void 0:H.selectionChange$]);const w=l.useMemo(()=>({keyCodes:[{keyCode:v.KeyCode.ENTER}],handler:u=>{u===v.KeyCode.ENTER&&U.executeCommand(ae.BreakLineCommand.id)}}),[U]);l.useImperativeHandle(e,()=>({reply(u){var C,x;(C=h.current)==null||C.focus(),(x=h.current)==null||x.setDocumentData(me(u))}}));const b=()=>{if(h.current){const u=c.Tools.deepClone(h.current.getDocumentData().body);O(!1),r==null||r({...t,text:u}),h.current.replaceText(""),setTimeout(()=>{var C,x;(C=h.current)==null||C.setSelectionRanges([]),(x=h.current)==null||x.blur()},10)}};return o.jsxs("div",{className:ce.threadCommentEditor,onClick:u=>u.preventDefault(),children:[o.jsx(ae.RichTextEditor,{editorRef:h,autoFocus:m,style:{width:"100%"},keyboardEventConfig:w,placeholder:P.t("threadCommentUI.editor.placeholder"),initialValue:(t==null?void 0:t.text)&&me(t.text),onFocusChange:u=>u&&O(u),isSingle:!1,maxHeight:64,onClickOutside:()=>{setTimeout(()=>{N.focus(I)},30)}}),L?o.jsxs("div",{className:ce.threadCommentEditorButtons,children:[o.jsx(V.Button,{style:{marginRight:12},onClick:()=>{var u;s==null||s(),O(!1),(u=h.current)==null||u.replaceText("",!0),U.executeCommand(B.id)},children:P.t("threadCommentUI.editor.cancel")}),o.jsx(V.Button,{type:"primary",disabled:!D,onClick:b,children:P.t(i?"threadCommentUI.editor.save":"threadCommentUI.editor.reply")})]}):null]})}),ze=n=>{const{dataStream:e,customRanges:t}=n,r=e.endsWith(`\r
|
|
2
|
+
`)?e.length-2:e.length,i=[];let s=0;return t==null||t.forEach(m=>{s<m.startIndex&&i.push({type:"text",content:e.slice(s,m.startIndex)}),i.push({type:"mention",content:{label:e.slice(m.startIndex,m.endIndex+1),id:m.rangeId}}),s=m.endIndex+1}),i.push({type:"text",content:e.slice(s,r)}),i},Ke=n=>{const{paragraphs:e=[]}=n;let t=0;return e.map(r=>{const i=c.getBodySlice(n,t,r.startIndex);return t=r.startIndex+1,ze(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 s=e.length-1;t.push({rangeId:r.content.id,rangeType:c.CustomRangeType.MENTION,startIndex:i,endIndex:s,properties:{}});break}}}),e+=`
|
|
3
|
+
\r`,{textRuns:[],paragraphs:[{startIndex:e.length-2,paragraphStyle:{}}],sectionBreaks:[{startIndex:e.length-1}],dataStream:e,customRanges:t}},Ge="univer-thread-comment",Ye="univer-thread-comment-active",Je="univer-thread-comment-content",Qe="univer-thread-comment-highlight",Xe="univer-thread-comment-icon-container",et="univer-thread-comment-icon",tt="univer-thread-comment-title",nt="univer-thread-comment-title-position",rt="univer-thread-comment-title-highlight",it="univer-thread-comment-title-position-text",ot="univer-thread-comment-username",at="univer-thread-comment-item",st="univer-thread-comment-item-head",dt="univer-thread-comment-item-title",lt="univer-thread-comment-item-time",ct="univer-thread-comment-item-content",mt="univer-thread-comment-item-at",g={threadComment:Ge,threadCommentActive:Ye,threadCommentContent:Je,threadCommentHighlight:Qe,threadCommentIconContainer:Xe,threadCommentIcon:et,threadCommentTitle:tt,threadCommentTitlePosition:nt,threadCommentTitleHighlight:rt,threadCommentTitlePositionText:it,threadCommentUsername:ot,threadCommentItem:at,threadCommentItemHead:st,threadCommentItemTitle:dt,threadCommentItemTime:lt,threadCommentItemContent:ct,threadCommentItemAt:mt},ye="__mock__",ut=n=>{const{item:e,unitId:t,subUnitId:r,editing:i,onEditingChange:s,onReply:m,resolved:p,isRoot:S,onClose:U,onDeleteComment:P,type:L}=n,O=v.useDependency(c.ICommandService),N=v.useDependency(c.LocaleService),h=v.useDependency(c.UserManagerService),I=h.getUser(e.personId),D=v.useObservable(h.currentUser$),T=(D==null?void 0:D.userID)===e.personId,w=e.id===ye,[b,H]=l.useState(!1),u=()=>{(P==null?void 0:P(e))!==!1&&(O.executeCommand(S?k.DeleteCommentTreeCommand.id:k.DeleteCommentCommand.id,{unitId:t,subUnitId:r,commentId:e.id}),S&&(U==null||U()))};return o.jsxs("div",{className:g.threadCommentItem,onMouseLeave:()=>H(!1),onMouseEnter:()=>H(!0),children:[o.jsx("img",{className:g.threadCommentItemHead,src:I==null?void 0:I.avatar}),o.jsxs("div",{className:g.threadCommentItemTitle,children:[o.jsx("div",{className:g.threadCommentUsername,children:(I==null?void 0:I.name)||" "}),o.jsxs("div",{children:[w||p?null:b?o.jsx("div",{className:g.threadCommentIcon,onClick:()=>m(I),children:o.jsx(Ie,{})}):null,T&&!w&&!p?o.jsx(V.Dropdown,{overlay:o.jsx("div",{className:"univer-rounded-lg univer-p-4 univer-theme",children:o.jsxs("ul",{className:`
|
|
4
|
+
univer-m-0 univer-grid univer-list-none univer-gap-2 univer-p-0
|
|
5
|
+
univer-text-sm
|
|
6
|
+
[&_a]:univer-cursor-pointer [&_a]:univer-rounded [&_a]:univer-p-1
|
|
7
|
+
`,children:[o.jsx("li",{children:o.jsx("a",{className:"hover:univer-bg-gray-200",onClick:()=>s==null?void 0:s(!0),children:N.t("threadCommentUI.item.edit")})}),o.jsx("li",{children:o.jsx("a",{className:"hover:univer-bg-gray-200",onClick:u,children:N.t("threadCommentUI.item.delete")})})]})}),children:o.jsx("div",{className:g.threadCommentIcon,children:o.jsx(ge,{})})}):null]})]}),o.jsx("div",{className:g.threadCommentItemTime,children:e.dT}),i?o.jsx(be,{type:L,id:e.id,comment:e,onCancel:()=>s==null?void 0:s(!1),autoFocus:!0,unitId:t,subUnitId:r,onSave:({text:C,attachments:x})=>{s==null||s(!1),O.executeCommand(k.UpdateCommentCommand.id,{unitId:t,subUnitId:r,payload:{commentId:e.id,text:C,attachments:x}})}}):o.jsx("div",{className:g.threadCommentItemContent,children:Ke(e.text).map((C,x)=>o.jsx("div",{children:C.map((d,f)=>{switch(d.type){case"mention":return o.jsxs("a",{className:g.threadCommentItemAt,children:[d.content.label," "]},f);default:return d.content}})},x))})]})},Te=n=>{var J,Q,ne;const{id:e,unitId:t,subUnitId:r,refStr:i,showEdit:s=!0,onClick:m,showHighlight:p,onClose:S,getSubUnitName:U,prefix:P,autoFocus:L,onMouseEnter:O,onMouseLeave:N,onAddComment:h,onDeleteComment:I,onResolve:D,type:T}=n,w=v.useDependency(k.ThreadCommentModel),[b,H]=l.useState(!1),[u,C]=l.useState(""),x=l.useMemo(()=>w.commentUpdate$.pipe(oe.debounceTime(16)),[w]);v.useObservable(x);const d=e?w.getCommentWithChildren(t,r,e):null,f=v.useDependency(c.ICommandService),z=v.useDependency(c.UserManagerService),_=d==null?void 0:d.root.resolved,y=v.useObservable(z.currentUser$),K=l.useRef(null),ee=[...d?[d.root]:[{id:ye,text:{dataStream:`
|
|
8
|
+
\r`},personId:(J=y==null?void 0:y.userID)!=null?J:"",ref:i!=null?i:"",dT:"",unitId:t,subUnitId:r,threadId:""}],...(Q=d==null?void 0:d.children)!=null?Q:[]],R=l.useRef(null),Z=j=>{j.stopPropagation(),_?f.executeCommand(B.id,{unitId:t,subUnitId:r,commentId:e}):f.executeCommand(B.id),f.executeCommand(k.ResolveCommentCommand.id,{unitId:t,subUnitId:r,commentId:e,resolved:!_}),D==null||D(!_)},A=j=>{j.stopPropagation(),f.executeCommand(B.id),!(d!=null&&d.root&&(I==null?void 0:I(d.root))===!1)&&(f.executeCommand(k.DeleteCommentTreeCommand.id,{unitId:t,subUnitId:r,commentId:e}),S==null||S())};l.useEffect(()=>N==null?void 0:N(),[]);const G=U((ne=d==null?void 0:d.root.subUnitId)!=null?ne:r),Y=s&&!u&&!_,te=`${i||(d==null?void 0:d.root.ref)||""}${G?" · ":""}${G}`;return o.jsxs("div",{className:V.clsx(g.threadComment,{[g.threadCommentActive]:!_&&(p||b||P==="cell")}),onClick:m,id:`${P}-${t}-${r}-${e}`,onMouseEnter:()=>{O==null||O(),H(!0)},onMouseLeave:()=>{N==null||N(),H(!1)},children:[!_&&p?o.jsx("div",{className:g.threadCommentHighlight}):null,o.jsxs("div",{className:g.threadCommentTitle,children:[o.jsxs("div",{className:g.threadCommentTitlePosition,children:[o.jsx("div",{className:g.threadCommentTitleHighlight}),o.jsx(V.Tooltip,{showIfEllipsis:!0,title:te,children:o.jsx("div",{className:g.threadCommentTitlePositionText,children:te})})]}),d?o.jsxs("div",{className:g.threadCommentIconContainer,children:[o.jsx("div",{onClick:Z,className:g.threadCommentIcon,style:{color:_?"rgb(var(--green-500))":""},children:_?o.jsx(xe,{}):o.jsx(Se,{})}),(y==null?void 0:y.userID)===d.root.personId?o.jsx("div",{className:g.threadCommentIcon,onClick:A,children:o.jsx(fe,{})}):null]}):null]}),o.jsx("div",{className:g.threadCommentContent,ref:R,children:ee.map(j=>o.jsx(ut,{onClose:S,unitId:t,subUnitId:r,item:j,isRoot:j.id===(d==null?void 0:d.root.id),editing:u===j.id,resolved:d==null?void 0:d.root.resolved,type:T,onEditingChange:a=>{C(a?j.id:"")},onReply:a=>{a&&requestAnimationFrame(()=>{var $;($=K.current)==null||$.reply(Ze([{type:"mention",content:{id:a.userID,label:a.name}}]))})},onAddComment:h,onDeleteComment:I},j.id))}),Y?o.jsx("div",{children:o.jsx(be,{ref:K,type:T,unitId:t,subUnitId:r,onSave:async({text:j,attachments:a})=>{const $={text:j,attachments:a,dT:k.getDT(),id:c.generateRandomId(),ref:i,personId:y==null?void 0:y.userID,parentId:d==null?void 0:d.root.id,unitId:t,subUnitId:r,threadId:d==null?void 0:d.root.threadId};(h==null?void 0:h($))!==!1&&(await f.executeCommand(k.AddCommentCommand.id,{unitId:t,subUnitId:r,comment:$}),R.current&&(R.current.scrollTop=R.current.scrollHeight))},autoFocus:L||!d,onCancel:()=>{d||S==null||S()}},`${L}`)}):null]})},ht="univer-thread-comment-panel",vt="univer-thread-comment-panel-forms",Ct="univer-thread-comment-panel-empty",ft="univer-thread-comment-panel-add",pt="univer-thread-comment-panel-solved",X={threadCommentPanel:ht,threadCommentPanelForms:vt,threadCommentPanelEmpty:Ct,threadCommentPanelAdd:ft,threadCommentPanelSolved:pt},gt=n=>{const{unitId:e,subUnitId$:t,type:r,onAdd:i,getSubUnitName:s,onResolve:m,sortComments:p,onItemLeave:S,onItemEnter:U,disableAdd:P,tempComment:L,onAddComment:O,onDeleteComment:N,showComments:h}=n,[I,D]=l.useState("all"),[T,w]=l.useState("all"),b=v.useDependency(c.LocaleService),H=v.useDependency(c.UserManagerService),u=v.useDependency(k.ThreadCommentModel),[C,x]=l.useState(()=>u.getUnit(e)),d=v.useDependency(exports.ThreadCommentPanelService),f=v.useObservable(d.activeCommentId$),z=v.useObservable(u.commentUpdate$),_=v.useDependency(c.ICommandService),y=v.useObservable(t),K=l.useRef(!0),ee="panel",R=v.useObservable(H.currentUser$),Z=l.useMemo(()=>{var ie;const a=I==="all"?C:(ie=C.filter(E=>E.subUnitId===y))!=null?ie:[],$=p!=null?p:E=>E,re=a.map(E=>{var W;return{...E.root,children:(W=E.children)!=null?W:[],users:E.relativeUsers}});if(h){const E=new Map;return re.forEach(W=>{E.set(W.id,W)}),[...h,""].map(W=>E.get(W)).filter(Boolean)}else return $(re)},[h,I,C,p,y]),A=l.useMemo(()=>[...Z.filter(a=>!a.resolved),...Z.filter(a=>a.resolved)],[Z]),G=l.useMemo(()=>T==="resolved"?A.filter(a=>a.resolved):T==="unsolved"?A.filter(a=>!a.resolved):T==="concern_me"&&R!=null&&R.userID?A.filter(a=>a==null?void 0:a.users.has(R.userID)):A,[A,R==null?void 0:R.userID,T]),Y=L?[L,...G]:G,te=Y.filter(a=>!a.resolved),J=Y.filter(a=>a.resolved),Q=T!=="all"||I!=="all",ne=()=>{w("all"),D("all")};l.useEffect(()=>{e&&x(u.getUnit(e))},[e,u,z]),l.useEffect(()=>{var E;if(!f)return;if(!K.current){K.current=!0;return}const{unitId:a,subUnitId:$,commentId:re}=f,ie=`${ee}-${a}-${$}-${re}`;(E=document.getElementById(ie))==null||E.scrollIntoView({block:"center"})},[f]);const j=a=>o.jsx(Te,{prefix:ee,getSubUnitName:s,id:a.id,unitId:a.unitId,subUnitId:a.subUnitId,refStr:a.ref,type:r,showEdit:(f==null?void 0:f.commentId)===a.id,showHighlight:(f==null?void 0:f.commentId)===a.id,onClick:()=>{K.current=!1,a.resolved?_.executeCommand(B.id):_.executeCommand(B.id,{unitId:a.unitId,subUnitId:a.subUnitId,commentId:a.id,temp:!1})},onMouseEnter:()=>U==null?void 0:U(a),onMouseLeave:()=>S==null?void 0:S(a),onAddComment:O,onDeleteComment:N,onResolve:$=>m==null?void 0:m(a.id,$)},a.id);return o.jsxs("div",{className:X.threadCommentPanel,children:[o.jsxs("div",{className:X.threadCommentPanelForms,children:[r===c.UniverInstanceType.UNIVER_SHEET?o.jsx(V.Select,{borderless:!0,value:I,onChange:a=>D(a),options:[{value:"current",label:b.t("threadCommentUI.filter.sheet.current")},{value:"all",label:b.t("threadCommentUI.filter.sheet.all")}]}):null,o.jsx(V.Select,{borderless:!0,value:T,onChange:a=>w(a),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")}]})]}),te.map(j),J.length?o.jsx("div",{className:X.threadCommentPanelSolved,children:"已解决"}):null,J.map(j),Y.length?null:o.jsxs("div",{className:X.threadCommentPanelEmpty,children:[Q?b.t("threadCommentUI.panel.filterEmpty"):b.t("threadCommentUI.panel.empty"),Q?o.jsx(V.Button,{onClick:ne,type:"link",children:b.t("threadCommentUI.panel.reset")}):o.jsxs(V.Button,{id:"thread-comment-add",className:X.threadCommentPanelAdd,type:"primary",onClick:i,disabled:P,children:[o.jsx(pe,{}),b.t("threadCommentUI.panel.addComment")]})]})]})};exports.SetActiveCommentOperation=B;exports.THREAD_COMMENT_PANEL=ue;exports.ThreadCommentPanel=gt;exports.ThreadCommentTree=Te;exports.ToggleSheetCommentPanelOperation=he;
|