@univerjs/preset-sheets-thread-comment 0.5.5 → 0.6.0-alpha.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/umd/index.js +5 -21
- package/package.json +7 -7
package/lib/umd/index.js
CHANGED
|
@@ -11,30 +11,14 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
// @univerjs/thread-comment-ui/index
|
|
14
|
-
(function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/thread-comment"),require("@univerjs/ui"),require("rxjs"),require("react"),require("@univerjs/design"),require("@univerjs/docs-ui")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/thread-comment","@univerjs/ui","rxjs","react","@univerjs/design","@univerjs/docs-ui"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.UniverThreadCommentUi={},c.UniverCore,c.UniverThreadComment,c.UniverUi,c.rxjs,c.React,c.UniverDesign,c.UniverDocsUi))})(this,function(c,o,U,A,ne,l,L,de){"use strict";var it=Object.defineProperty;var ot=(c,o,U)=>o in c?it(c,o,{enumerable:!0,configurable:!0,writable:!0,value:U}):c[o]=U;var Z=(c,o,U)=>ot(c,typeof o!="symbol"?o+"":o,U);var Oe=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Me=(n,e,t,r)=>{for(var i=r>1?void 0:r?De(e,t):e,d=n.length-1,u;d>=0;d--)(u=n[d])&&(i=(r?u(e,t,i):u(i))||i);return r&&i&&Oe(e,t,i),i},ce=(n,e)=>(t,r)=>e(t,r,n);c.ThreadCommentPanelService=class extends o.Disposable{constructor(t,r){super();Z(this,"_panelVisible",!1);Z(this,"_panelVisible$",new ne.BehaviorSubject(!1));Z(this,"_activeCommentId");Z(this,"_activeCommentId$",new ne.BehaviorSubject(void 0));Z(this,"panelVisible$",this._panelVisible$.asObservable());Z(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$(o.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)}},c.ThreadCommentPanelService=Me([ce(0,o.Inject(A.ISidebarService)),ce(1,o.IUniverInstanceService)],c.ThreadCommentPanelService);const ue="thread-comment-panel",we="UNIVER_THREAD_COMMENT_UI_PLUGIN",he={id:"thread-comment-ui.operation.toggle-panel",type:o.CommandType.OPERATION,handler(n){const e=n.get(A.ISidebarService),t=n.get(c.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}},F={id:"thread-comment-ui.operation.set-active-comment",type:o.CommandType.OPERATION,handler(n,e){return n.get(c.ThreadCommentPanelService).setActiveComment(e),!0}},He="thread-comment-ui.config",Ce={};var ve=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,Le=(n,e,t)=>e in n?ve(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,ke=(n,e,t,r)=>{for(var i=r>1?void 0:r?Ae(e,t):e,d=n.length-1,u;d>=0;d--)(u=n[d])&&(i=(r?u(e,t,i):u(i))||i);return r&&i&&ve(e,t,i),i},me=(n,e)=>(t,r)=>e(t,r,n),fe=(n,e,t)=>Le(n,typeof e!="symbol"?e+"":e,t);c.UniverThreadCommentUIPlugin=class extends o.Plugin{constructor(e=Ce,t,r,i){super(),this._config=e,this._injector=t,this._commandService=r,this._configService=i;const{menu:d,...u}=o.merge({},Ce,this._config);d&&this._configService.setConfig("menu",d,{merge:!0}),this._configService.setConfig(He,u)}onStarting(){var e;o.mergeOverrideWithDependencies([[c.ThreadCommentPanelService]],(e=this._config)==null?void 0:e.overrides).forEach(t=>{this._injector.add(t)}),[he,F].forEach(t=>{this._commandService.registerCommand(t)})}},fe(c.UniverThreadCommentUIPlugin,"pluginName",we),fe(c.UniverThreadCommentUIPlugin,"type",o.UniverInstanceType.UNIVER_UNKNOWN),c.UniverThreadCommentUIPlugin=ke([o.DependentOn(U.UniverThreadCommentPlugin),me(1,o.Inject(o.Injector)),me(2,o.ICommandService),me(3,o.IConfigService)],c.UniverThreadCommentUIPlugin);var le={exports:{}},Y={};/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
19
|
-
*
|
|
20
|
-
* This source code is licensed under the MIT license found in the
|
|
21
|
-
* LICENSE file in the root directory of this source tree.
|
|
22
|
-
*/var pe;function Ve(){if(pe)return Y;pe=1;var n=l,e=Symbol.for("react.element"),t=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,i=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,d={key:!0,ref:!0,__self:!0,__source:!0};function u(f,C,T){var p,P={},b=null,_=null;T!==void 0&&(b=""+T),C.key!==void 0&&(b=""+C.key),C.ref!==void 0&&(_=C.ref);for(p in C)r.call(C,p)&&!d.hasOwnProperty(p)&&(P[p]=C[p]);if(f&&f.defaultProps)for(p in C=f.defaultProps,C)P[p]===void 0&&(P[p]=C[p]);return{$$typeof:e,type:f,key:b,ref:_,props:P,_owner:i.current}}return Y.Fragment=t,Y.jsx=u,Y.jsxs=u,Y}var ge;function Be(){return ge||(ge=1,le.exports=Ve()),le.exports}var a=Be(),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)},Fe=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},z=l.forwardRef(function(n,e){var t=n.icon,r=n.id,i=n.className,d=n.extend,u=Fe(n,["icon","id","className","extend"]),f="univerjs-icon univerjs-icon-".concat(r," ").concat(i||"").trim(),C=l.useRef("_".concat(Ke()));return Ie(t,"".concat(r),{defIds:t.defIds,idSuffix:C.current},M({ref:e,className:f},u),d)});function Ie(n,e,t,r,i){return l.createElement(n.tag,M(M({key:e},We(n,t,i)),r),(ze(n,t).children||[]).map(function(d,u){return Ie(d,"".concat(e,"-").concat(n.tag,"-").concat(u),t,void 0,i)}))}function We(n,e,t){var r=M({},n.attrs);t!=null&&t.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=t.colorChannel1);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(d){var u=d[0],f=d[1];typeof f=="string"&&(r[u]=f.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(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)}z.displayName="UniverIcon";var Ze={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"}}]},Se=l.forwardRef(function(n,e){return l.createElement(z,Object.assign({},n,{id:"delete-single",ref:e,icon:Ze}))});Se.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"}}]},xe=l.forwardRef(function(n,e){return l.createElement(z,Object.assign({},n,{id:"increase-single",ref:e,icon:Je}))});xe.displayName="IncreaseSingle";var Ge={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"}}]},ye=l.forwardRef(function(n,e){return l.createElement(z,Object.assign({},n,{id:"more-horizontal-single",ref:e,icon:Ge}))});ye.displayName="MoreHorizontalSingle";var Ye={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}}]},Te=l.forwardRef(function(n,e){return l.createElement(z,Object.assign({},n,{id:"reply-to-comment-single",ref:e,icon:Ye}))});Te.displayName="ReplyToCommentSingle";var Qe={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"}}]},be=l.forwardRef(function(n,e){return l.createElement(z,Object.assign({},n,{id:"resolved-single",ref:e,icon:Qe}))});be.displayName="ResolvedSingle";var Xe={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}}]},_e=l.forwardRef(function(n,e){return l.createElement(z,Object.assign({},n,{id:"solve-single",ref:e,icon:Xe}))});_e.displayName="SolveSingle";function je(n){var e,t,r="";if(typeof n=="string"||typeof n=="number")r+=n;else if(typeof n=="object")if(Array.isArray(n)){var i=n.length;for(e=0;e<i;e++)n[e]&&(t=je(n[e]))&&(r&&(r+=" "),r+=t)}else for(t in n)n[t]&&(r&&(r+=" "),r+=t);return r}function qe(){for(var n,e,t=0,r="",i=arguments.length;t<i;t++)(n=arguments[t])&&(e=je(n))&&(r&&(r+=" "),r+=e);return r}const Ue={threadCommentEditorButtons:"univer-thread-comment-editor-buttons",threadCommentEditorSuggestion:"univer-thread-comment-editor-suggestion",threadCommentEditorSuggestionActive:"univer-thread-comment-editor-suggestionActive",threadCommentEditorSuggestionIcon:"univer-thread-comment-editor-suggestion-icon"};function Ee(n){return{id:"d",body:n,documentStyle:{}}}const Pe=l.forwardRef((n,e)=>{var B;const{comment:t,onSave:r,id:i,onCancel:d,autoFocus:u,unitId:f,type:C}=n,T=o.useDependency(o.ICommandService),p=o.useDependency(o.LocaleService),[P,b]=l.useState(!1),_=o.useDependency(de.IEditorService),v=l.useRef(null),x=C===o.UniverInstanceType.UNIVER_SHEET?o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:f,[w,N]=l.useState(()=>{var h,g,y;return o.BuildTextUtils.transform.getPlainText((y=(g=(h=v.current)==null?void 0:h.getDocumentData().body)==null?void 0:g.dataStream)!=null?y:"")});l.useEffect(()=>{var g,y,m,I;N(o.BuildTextUtils.transform.getPlainText((m=(y=(g=v.current)==null?void 0:g.getDocumentData().body)==null?void 0:y.dataStream)!=null?m:""));const h=(I=v.current)==null?void 0:I.selectionChange$.subscribe(()=>{var J,R,E;N(o.BuildTextUtils.transform.getPlainText((E=(R=(J=v.current)==null?void 0:J.getDocumentData().body)==null?void 0:R.dataStream)!=null?E:""))});return()=>h==null?void 0:h.unsubscribe()},[(B=v.current)==null?void 0:B.selectionChange$]);const k=l.useMemo(()=>({keyCodes:[{keyCode:A.KeyCode.ENTER}],handler:h=>{h===A.KeyCode.ENTER&&T.executeCommand(de.BreakLineCommand.id)}}),[T]);l.useImperativeHandle(e,()=>({reply(h){var g,y;(g=v.current)==null||g.focus(),(y=v.current)==null||y.setDocumentData(Ee(h))}}));const j=()=>{if(v.current){const h=o.Tools.deepClone(v.current.getDocumentData().body);b(!1),r==null||r({...t,text:h}),v.current.replaceText(""),setTimeout(()=>{var g,y;(g=v.current)==null||g.setSelectionRanges([]),(y=v.current)==null||y.blur()},10)}};return a.jsxs("div",{className:Ue.threadCommentEditor,onClick:h=>h.preventDefault(),children:[a.jsx(de.RichTextEditor,{ref:v,autoFocus:u,style:{width:"100%"},keyboardEventConfig:k,placeholder:p.t("threadCommentUI.editor.placeholder"),initialValue:(t==null?void 0:t.text)&&Ee(t.text),onFocusChange:h=>h&&b(h),isSingle:!1,maxHeight:64,onClickOutside:()=>{setTimeout(()=>{_.focus(x)},30)}}),P?a.jsxs("div",{className:Ue.threadCommentEditorButtons,children:[a.jsx(L.Button,{style:{marginRight:12},onClick:()=>{var h;d==null||d(),b(!1),(h=v.current)==null||h.replaceText("",!0),T.executeCommand(F.id)},children:p.t("threadCommentUI.editor.cancel")}),a.jsx(L.Button,{type:"primary",disabled:!w,onClick:j,children:p.t(i?"threadCommentUI.editor.save":"threadCommentUI.editor.reply")})]}):null]})}),$e=n=>{const{dataStream:e,customRanges:t}=n,r=e.endsWith(`\r
|
|
23
|
-
`)?e.length-2:e.length,i=[];let d=0;return t==null||t.forEach(u=>{d<u.startIndex&&i.push({type:"text",content:e.slice(d,u.startIndex)}),i.push({type:"mention",content:{label:e.slice(u.startIndex,u.endIndex+1),id:u.rangeId}}),d=u.endIndex+1}),i.push({type:"text",content:e.slice(d,r)}),i},et=n=>{const{paragraphs:e=[]}=n;let t=0;return e.map(r=>{const i=o.getBodySlice(n,t,r.startIndex);return t=r.startIndex+1,$e(i)})},tt=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 d=e.length-1;t.push({rangeId:r.content.id,rangeType:o.CustomRangeType.MENTION,startIndex:i,endIndex:d,properties:{}});break}}}),e+=`
|
|
24
|
-
\r`,{textRuns:[],paragraphs:[{startIndex:e.length-2,paragraphStyle:{}}],sectionBreaks:[{startIndex:e.length-1}],dataStream:e,customRanges:t}},S={threadComment:"univer-thread-comment",threadCommentActive:"univer-thread-comment-active",threadCommentContent:"univer-thread-comment-content",threadCommentHighlight:"univer-thread-comment-highlight",threadCommentIconContainer:"univer-thread-comment-icon-container",threadCommentIcon:"univer-thread-comment-icon",threadCommentTitle:"univer-thread-comment-title",threadCommentTitlePosition:"univer-thread-comment-title-position",threadCommentTitleHighlight:"univer-thread-comment-title-highlight",threadCommentTitlePositionText:"univer-thread-comment-title-position-text",threadCommentUsername:"univer-thread-comment-username",threadCommentItem:"univer-thread-comment-item",threadCommentItemHead:"univer-thread-comment-item-head",threadCommentItemTitle:"univer-thread-comment-item-title",threadCommentItemTitlePosition:"univer-thread-comment-item-title-position",threadCommentItemTitleHighlight:"univer-thread-comment-item-title-highlight",threadCommentItemTime:"univer-thread-comment-item-time",threadCommentItemContent:"univer-thread-comment-item-content",threadCommentItemAt:"univer-thread-comment-item-at"},Ne="__mock__",nt=n=>{const{item:e,unitId:t,subUnitId:r,editing:i,onEditingChange:d,onReply:u,resolved:f,isRoot:C,onClose:T,onDeleteComment:p,type:P}=n,b=o.useDependency(o.ICommandService),_=o.useDependency(o.LocaleService),v=o.useDependency(o.UserManagerService),x=v.getUser(e.personId),w=A.useObservable(v.currentUser$),N=(w==null?void 0:w.userID)===e.personId,k=e.id===Ne,[j,B]=l.useState(!1),h=()=>{(p==null?void 0:p(e))!==!1&&(b.executeCommand(C?U.DeleteCommentTreeCommand.id:U.DeleteCommentCommand.id,{unitId:t,subUnitId:r,commentId:e.id}),C&&(T==null||T()))};return a.jsxs("div",{className:S.threadCommentItem,onMouseLeave:()=>B(!1),onMouseEnter:()=>B(!0),children:[a.jsx("img",{className:S.threadCommentItemHead,src:x==null?void 0:x.avatar}),a.jsxs("div",{className:S.threadCommentItemTitle,children:[a.jsx("div",{className:S.threadCommentUsername,children:(x==null?void 0:x.name)||" "}),a.jsxs("div",{children:[k||f?null:j?a.jsx("div",{className:S.threadCommentIcon,onClick:()=>u(x),children:a.jsx(Te,{})}):null,N&&!k&&!f?a.jsx(L.DropdownLegacy,{overlay:a.jsxs(L.Menu,{children:[a.jsx(L.MenuItem,{onClick:()=>d==null?void 0:d(!0),children:_.t("threadCommentUI.item.edit")},"edit"),a.jsx(L.MenuItem,{onClick:h,children:_.t("threadCommentUI.item.delete")},"delete")]}),children:a.jsx("div",{className:S.threadCommentIcon,children:a.jsx(ye,{})})}):null]})]}),a.jsx("div",{className:S.threadCommentItemTime,children:e.dT}),i?a.jsx(Pe,{type:P,id:e.id,comment:e,onCancel:()=>d==null?void 0:d(!1),autoFocus:!0,unitId:t,subUnitId:r,onSave:({text:g,attachments:y})=>{d==null||d(!1),b.executeCommand(U.UpdateCommentCommand.id,{unitId:t,subUnitId:r,payload:{commentId:e.id,text:g,attachments:y}})}}):a.jsx("div",{className:S.threadCommentItemContent,children:et(e.text).map((g,y)=>a.jsx("div",{children:g.map((m,I)=>{switch(m.type){case"mention":return a.jsxs("a",{className:S.threadCommentItemAt,children:[m.content.label," "]},I);default:return m.content}})},y))})]})},Re=n=>{var ee,te,oe;const{id:e,unitId:t,subUnitId:r,refStr:i,showEdit:d=!0,onClick:u,showHighlight:f,onClose:C,getSubUnitName:T,prefix:p,autoFocus:P,onMouseEnter:b,onMouseLeave:_,onAddComment:v,onDeleteComment:x,onResolve:w,type:N}=n,k=o.useDependency(U.ThreadCommentModel),[j,B]=l.useState(!1),[h,g]=l.useState(""),y=l.useMemo(()=>k.commentUpdate$.pipe(ne.debounceTime(16)),[k]);A.useObservable(y);const m=e?k.getCommentWithChildren(t,r,e):null,I=o.useDependency(o.ICommandService),J=o.useDependency(o.UserManagerService),R=m==null?void 0:m.root.resolved,E=A.useObservable(J.currentUser$),G=l.useRef(null),re=[...m?[m.root]:[{id:Ne,text:{dataStream:`
|
|
25
|
-
\r`},personId:(ee=E==null?void 0:E.userID)!=null?ee:"",ref:i!=null?i:"",dT:"",unitId:t,subUnitId:r,threadId:""}],...(te=m==null?void 0:m.children)!=null?te:[]],H=l.useRef(null),X=O=>{O.stopPropagation(),R?I.executeCommand(F.id,{unitId:t,subUnitId:r,commentId:e}):I.executeCommand(F.id),I.executeCommand(U.ResolveCommentCommand.id,{unitId:t,subUnitId:r,commentId:e,resolved:!R}),w==null||w(!R)},W=O=>{O.stopPropagation(),I.executeCommand(F.id),!(m!=null&&m.root&&(x==null?void 0:x(m.root))===!1)&&(I.executeCommand(U.DeleteCommentTreeCommand.id,{unitId:t,subUnitId:r,commentId:e}),C==null||C())};l.useEffect(()=>_==null?void 0:_(),[]);const q=T((oe=m==null?void 0:m.root.subUnitId)!=null?oe:r),$=d&&!h&&!R,ie=`${i||(m==null?void 0:m.root.ref)||""}${q?" · ":""}${q}`;return a.jsxs("div",{className:qe(S.threadComment,{[S.threadCommentActive]:!R&&(f||j||p==="cell")}),onClick:u,id:`${p}-${t}-${r}-${e}`,onMouseEnter:()=>{b==null||b(),B(!0)},onMouseLeave:()=>{_==null||_(),B(!1)},children:[!R&&f?a.jsx("div",{className:S.threadCommentHighlight}):null,a.jsxs("div",{className:S.threadCommentTitle,children:[a.jsxs("div",{className:S.threadCommentTitlePosition,children:[a.jsx("div",{className:S.threadCommentTitleHighlight}),a.jsx(L.Tooltip,{showIfEllipsis:!0,title:ie,children:a.jsx("div",{className:S.threadCommentTitlePositionText,children:ie})})]}),m?a.jsxs("div",{className:S.threadCommentIconContainer,children:[a.jsx("div",{onClick:X,className:S.threadCommentIcon,style:{color:R?"rgb(var(--green-500))":""},children:R?a.jsx(be,{}):a.jsx(_e,{})}),(E==null?void 0:E.userID)===m.root.personId?a.jsx("div",{className:S.threadCommentIcon,onClick:W,children:a.jsx(Se,{})}):null]}):null]}),a.jsx("div",{className:S.threadCommentContent,ref:H,children:re.map(O=>a.jsx(nt,{onClose:C,unitId:t,subUnitId:r,item:O,isRoot:O.id===(m==null?void 0:m.root.id),editing:h===O.id,resolved:m==null?void 0:m.root.resolved,type:N,onEditingChange:s=>{g(s?O.id:"")},onReply:s=>{s&&requestAnimationFrame(()=>{var V;(V=G.current)==null||V.reply(tt([{type:"mention",content:{id:s.userID,label:s.name}}]))})},onAddComment:v,onDeleteComment:x},O.id))}),$?a.jsx("div",{children:a.jsx(Pe,{ref:G,type:N,unitId:t,subUnitId:r,onSave:async({text:O,attachments:s})=>{const V={text:O,attachments:s,dT:U.getDT(),id:o.generateRandomId(),ref:i,personId:E==null?void 0:E.userID,parentId:m==null?void 0:m.root.id,unitId:t,subUnitId:r,threadId:m==null?void 0:m.root.threadId};(v==null?void 0:v(V))!==!1&&(await I.executeCommand(U.AddCommentCommand.id,{unitId:t,subUnitId:r,comment:V}),H.current&&(H.current.scrollTop=H.current.scrollHeight))},autoFocus:P||!m,onCancel:()=>{m||C==null||C()}},`${P}`)}):null]})},Q={threadCommentPanel:"univer-thread-comment-panel",threadComment:"univer-thread-comment",threadCommentPanelForms:"univer-thread-comment-panel-forms",select:"univer-select",threadCommentPanelEmpty:"univer-thread-comment-panel-empty",threadCommentPanelAdd:"univer-thread-comment-panel-add",threadCommentPanelSolved:"univer-thread-comment-panel-solved"},rt=n=>{const{unitId:e,subUnitId$:t,type:r,onAdd:i,getSubUnitName:d,onResolve:u,sortComments:f,onItemLeave:C,onItemEnter:T,disableAdd:p,tempComment:P,onAddComment:b,onDeleteComment:_,showComments:v}=n,[x,w]=l.useState("all"),[N,k]=l.useState("all"),j=o.useDependency(o.LocaleService),B=o.useDependency(o.UserManagerService),h=o.useDependency(U.ThreadCommentModel),[g,y]=l.useState(()=>h.getUnit(e)),m=o.useDependency(c.ThreadCommentPanelService),I=A.useObservable(m.activeCommentId$),J=A.useObservable(h.commentUpdate$),R=o.useDependency(o.ICommandService),E=A.useObservable(t),G=l.useRef(!0),re="panel",H=A.useObservable(B.currentUser$),X=l.useMemo(()=>{var se;const s=x==="all"?g:(se=g.filter(D=>D.subUnitId===E))!=null?se:[],V=f!=null?f:D=>D,ae=s.map(D=>{var K;return{...D.root,children:(K=D.children)!=null?K:[],users:D.relativeUsers}});if(v){const D=new Map;return ae.forEach(K=>{D.set(K.id,K)}),[...v,""].map(K=>D.get(K)).filter(Boolean)}else return V(ae)},[v,x,g,f,E]),W=l.useMemo(()=>[...X.filter(s=>!s.resolved),...X.filter(s=>s.resolved)],[X]),q=l.useMemo(()=>N==="resolved"?W.filter(s=>s.resolved):N==="unsolved"?W.filter(s=>!s.resolved):N==="concern_me"&&H!=null&&H.userID?W.filter(s=>s==null?void 0:s.users.has(H.userID)):W,[W,H==null?void 0:H.userID,N]),$=P?[P,...q]:q,ie=$.filter(s=>!s.resolved),ee=$.filter(s=>s.resolved),te=N!=="all"||x!=="all",oe=()=>{k("all"),w("all")};l.useEffect(()=>{e&&y(h.getUnit(e))},[e,h,J]),l.useEffect(()=>{var D;if(!I)return;if(!G.current){G.current=!0;return}const{unitId:s,subUnitId:V,commentId:ae}=I,se=`${re}-${s}-${V}-${ae}`;(D=document.getElementById(se))==null||D.scrollIntoView({block:"center"})},[I]);const O=s=>a.jsx(Re,{prefix:re,getSubUnitName:d,id:s.id,unitId:s.unitId,subUnitId:s.subUnitId,refStr:s.ref,type:r,showEdit:(I==null?void 0:I.commentId)===s.id,showHighlight:(I==null?void 0:I.commentId)===s.id,onClick:()=>{G.current=!1,s.resolved?R.executeCommand(F.id):R.executeCommand(F.id,{unitId:s.unitId,subUnitId:s.subUnitId,commentId:s.id,temp:!1})},onMouseEnter:()=>T==null?void 0:T(s),onMouseLeave:()=>C==null?void 0:C(s),onAddComment:b,onDeleteComment:_,onResolve:V=>u==null?void 0:u(s.id,V)},s.id);return a.jsxs("div",{className:Q.threadCommentPanel,children:[a.jsxs("div",{className:Q.threadCommentPanelForms,children:[r===o.UniverInstanceType.UNIVER_SHEET?a.jsx(L.Select,{borderless:!0,value:x,onChange:s=>w(s),options:[{value:"current",label:j.t("threadCommentUI.filter.sheet.current")},{value:"all",label:j.t("threadCommentUI.filter.sheet.all")}]}):null,a.jsx(L.Select,{borderless:!0,value:N,onChange:s=>k(s),options:[{value:"all",label:j.t("threadCommentUI.filter.status.all")},{value:"resolved",label:j.t("threadCommentUI.filter.status.resolved")},{value:"unsolved",label:j.t("threadCommentUI.filter.status.unsolved")},{value:"concern_me",label:j.t("threadCommentUI.filter.status.concernMe")}]})]}),ie.map(O),ee.length?a.jsx("div",{className:Q.threadCommentPanelSolved,children:"已解决"}):null,ee.map(O),$.length?null:a.jsxs("div",{className:Q.threadCommentPanelEmpty,children:[te?j.t("threadCommentUI.panel.filterEmpty"):j.t("threadCommentUI.panel.empty"),te?a.jsx(L.Button,{onClick:oe,type:"link",children:j.t("threadCommentUI.panel.reset")}):a.jsxs(L.Button,{id:"thread-comment-add",className:Q.threadCommentPanelAdd,type:"primary",onClick:i,disabled:p,children:[a.jsx(xe,{}),j.t("threadCommentUI.panel.addComment")]})]})]})};c.SetActiveCommentOperation=F,c.THREAD_COMMENT_PANEL=ue,c.ThreadCommentPanel=rt,c.ThreadCommentTree=Re,c.ToggleSheetCommentPanelOperation=he,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
14
|
+
(function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/thread-comment"),require("@univerjs/ui"),require("rxjs"),require("react/jsx-runtime"),require("@univerjs/design"),require("react"),require("@univerjs/docs-ui")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/thread-comment","@univerjs/ui","rxjs","react/jsx-runtime","@univerjs/design","react","@univerjs/docs-ui"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.UniverThreadCommentUi={},c.UniverCore,c.UniverThreadComment,c.UniverUi,c.rxjs,c.React,c.UniverDesign,c.React,c.UniverDocsUi))})(this,function(c,o,y,$,te,a,A,m,se){"use strict";var Qe=Object.defineProperty;var Xe=(c,o,y)=>o in c?Qe(c,o,{enumerable:!0,configurable:!0,writable:!0,value:y}):c[o]=y;var R=(c,o,y)=>Xe(c,typeof o!="symbol"?o+"":o,y);var Ne=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,De=(n,e,t,r)=>{for(var i=r>1?void 0:r?xe(e,t):e,l=n.length-1,h;l>=0;l--)(h=n[l])&&(i=(r?h(e,t,i):h(i))||i);return r&&i&&Ne(e,t,i),i},le=(n,e)=>(t,r)=>e(t,r,n);c.ThreadCommentPanelService=class extends o.Disposable{constructor(t,r){super();R(this,"_panelVisible",!1);R(this,"_panelVisible$",new te.BehaviorSubject(!1));R(this,"_activeCommentId");R(this,"_activeCommentId$",new te.BehaviorSubject(void 0));R(this,"panelVisible$",this._panelVisible$.asObservable());R(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$(o.UniverInstanceType.UNIVER_SHEET).pipe(te.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)}},c.ThreadCommentPanelService=De([le(0,o.Inject($.ISidebarService)),le(1,o.IUniverInstanceService)],c.ThreadCommentPanelService);const me="thread-comment-panel",Oe="UNIVER_THREAD_COMMENT_UI_PLUGIN",ce={id:"thread-comment-ui.operation.toggle-panel",type:o.CommandType.OPERATION,handler(n){const e=n.get($.ISidebarService),t=n.get(c.ThreadCommentPanelService);return t.panelVisible?(e.close(),t.setPanelVisible(!1)):(e.open({header:{title:"threadCommentUI.panel.title"},children:{label:me},width:330}),t.setPanelVisible(!0)),!0}},F={id:"thread-comment-ui.operation.set-active-comment",type:o.CommandType.OPERATION,handler(n,e){return n.get(c.ThreadCommentPanelService).setActiveComment(e),!0}},Me="thread-comment-ui.config",he={};var ue=Object.defineProperty,He=Object.getOwnPropertyDescriptor,we=(n,e,t)=>e in n?ue(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,je=(n,e,t,r)=>{for(var i=r>1?void 0:r?He(e,t):e,l=n.length-1,h;l>=0;l--)(h=n[l])&&(i=(r?h(e,t,i):h(i))||i);return r&&i&&ue(e,t,i),i},de=(n,e)=>(t,r)=>e(t,r,n),Ce=(n,e,t)=>we(n,typeof e!="symbol"?e+"":e,t);c.UniverThreadCommentUIPlugin=class extends o.Plugin{constructor(e=he,t,r,i){super(),this._config=e,this._injector=t,this._commandService=r,this._configService=i;const{menu:l,...h}=o.merge({},he,this._config);l&&this._configService.setConfig("menu",l,{merge:!0}),this._configService.setConfig(Me,h)}onStarting(){var e;o.mergeOverrideWithDependencies([[c.ThreadCommentPanelService]],(e=this._config)==null?void 0:e.overrides).forEach(t=>{this._injector.add(t)}),[ce,F].forEach(t=>{this._commandService.registerCommand(t)})}},Ce(c.UniverThreadCommentUIPlugin,"pluginName",Oe),Ce(c.UniverThreadCommentUIPlugin,"type",o.UniverInstanceType.UNIVER_UNKNOWN),c.UniverThreadCommentUIPlugin=je([o.DependentOn(y.UniverThreadCommentPlugin),de(1,o.Inject(o.Injector)),de(2,o.ICommandService),de(3,o.IConfigService)],c.UniverThreadCommentUIPlugin);var O=function(){return O=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},O.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 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=m.forwardRef(function(n,e){var t=n.icon,r=n.id,i=n.className,l=n.extend,h=$e(n,["icon","id","className","extend"]),T="univerjs-icon univerjs-icon-".concat(r," ").concat(i||"").trim(),S=m.useRef("_".concat(ke()));return ve(t,"".concat(r),{defIds:t.defIds,idSuffix:S.current},O({ref:e,className:T},h),l)});function ve(n,e,t,r,i){return m.createElement(n.tag,O(O({key:e},Ae(n,t,i)),r),(Le(n,t).children||[]).map(function(l,h){return ve(l,"".concat(e,"-").concat(n.tag,"-").concat(h),t,void 0,i)}))}function Ae(n,e,t){var r=O({},n.attrs);t!=null&&t.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=t.colorChannel1);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(l){var h=l[0],T=l[1];typeof T=="string"&&(r[h]=T.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),r}function Le(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)?O(O({},n),{children:n.children.map(function(i){return typeof i.attrs.id=="string"&&r&&r.indexOf(i.attrs.id)>-1?O(O({},i),{attrs:O(O({},i.attrs),{id:i.attrs.id+e.idSuffix})}):i})}):n}function ke(){return Math.random().toString(36).substring(2,8)}q.displayName="UniverIcon";var Ve={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=m.forwardRef(function(n,e){return m.createElement(q,Object.assign({},n,{id:"delete-single",ref:e,icon:Ve}))});fe.displayName="DeleteSingle";var Be={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=m.forwardRef(function(n,e){return m.createElement(q,Object.assign({},n,{id:"increase-single",ref:e,icon:Be}))});ge.displayName="IncreaseSingle";var Fe={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=m.forwardRef(function(n,e){return m.createElement(q,Object.assign({},n,{id:"more-horizontal-single",ref:e,icon:Fe}))});pe.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=m.forwardRef(function(n,e){return m.createElement(q,Object.assign({},n,{id:"reply-to-comment-single",ref:e,icon:We}))});Ie.displayName="ReplyToCommentSingle";var qe={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=m.forwardRef(function(n,e){return m.createElement(q,Object.assign({},n,{id:"resolved-single",ref:e,icon:qe}))});Se.displayName="ResolvedSingle";var ze={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}}]},Te=m.forwardRef(function(n,e){return m.createElement(q,Object.assign({},n,{id:"solve-single",ref:e,icon:ze}))});Te.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 i=n.length;for(e=0;e<i;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 Re(){for(var n,e,t=0,r="",i=arguments.length;t<i;t++)(n=arguments[t])&&(e=be(n))&&(r&&(r+=" "),r+=e);return r}const ye={threadCommentEditorButtons:"univer-thread-comment-editor-buttons",threadCommentEditorSuggestion:"univer-thread-comment-editor-suggestion",threadCommentEditorSuggestionActive:"univer-thread-comment-editor-suggestionActive",threadCommentEditorSuggestionIcon:"univer-thread-comment-editor-suggestion-icon"};function _e(n){return{id:"d",body:n,documentStyle:{}}}const Ue=m.forwardRef((n,e)=>{var V;const{comment:t,onSave:r,id:i,onCancel:l,autoFocus:h,unitId:T,type:S}=n,N=o.useDependency(o.ICommandService),M=o.useDependency(o.LocaleService),[B,H]=m.useState(!1),x=o.useDependency(se.IEditorService),C=m.useRef(null),p=S===o.UniverInstanceType.UNIVER_SHEET?o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:T,[w,U]=m.useState(()=>{var u,v,I;return o.BuildTextUtils.transform.getPlainText((I=(v=(u=C.current)==null?void 0:u.getDocumentData().body)==null?void 0:v.dataStream)!=null?I:"")});m.useEffect(()=>{var v,I,d,f;U(o.BuildTextUtils.transform.getPlainText((d=(I=(v=C.current)==null?void 0:v.getDocumentData().body)==null?void 0:I.dataStream)!=null?d:""));const u=(f=C.current)==null?void 0:f.selectionChange$.subscribe(()=>{var K,P,_;U(o.BuildTextUtils.transform.getPlainText((_=(P=(K=C.current)==null?void 0:K.getDocumentData().body)==null?void 0:P.dataStream)!=null?_:""))});return()=>u==null?void 0:u.unsubscribe()},[(V=C.current)==null?void 0:V.selectionChange$]);const L=m.useMemo(()=>({keyCodes:[{keyCode:$.KeyCode.ENTER}],handler:u=>{u===$.KeyCode.ENTER&&N.executeCommand(se.BreakLineCommand.id)}}),[N]);m.useImperativeHandle(e,()=>({reply(u){var v,I;(v=C.current)==null||v.focus(),(I=C.current)==null||I.setDocumentData(_e(u))}}));const b=()=>{if(C.current){const u=o.Tools.deepClone(C.current.getDocumentData().body);H(!1),r==null||r({...t,text:u}),C.current.replaceText(""),setTimeout(()=>{var v,I;(v=C.current)==null||v.setSelectionRanges([]),(I=C.current)==null||I.blur()},10)}};return a.jsxs("div",{className:ye.threadCommentEditor,onClick:u=>u.preventDefault(),children:[a.jsx(se.RichTextEditor,{ref:C,autoFocus:h,style:{width:"100%"},keyboardEventConfig:L,placeholder:M.t("threadCommentUI.editor.placeholder"),initialValue:(t==null?void 0:t.text)&&_e(t.text),onFocusChange:u=>u&&H(u),isSingle:!1,maxHeight:64,onClickOutside:()=>{setTimeout(()=>{x.focus(p)},30)}}),B?a.jsxs("div",{className:ye.threadCommentEditorButtons,children:[a.jsx(A.Button,{style:{marginRight:12},onClick:()=>{var u;l==null||l(),H(!1),(u=C.current)==null||u.replaceText("",!0),N.executeCommand(F.id)},children:M.t("threadCommentUI.editor.cancel")}),a.jsx(A.Button,{type:"primary",disabled:!w,onClick:b,children:M.t(i?"threadCommentUI.editor.save":"threadCommentUI.editor.reply")})]}):null]})}),Ke=n=>{const{dataStream:e,customRanges:t}=n,r=e.endsWith(`\r
|
|
15
|
+
`)?e.length-2:e.length,i=[];let l=0;return t==null||t.forEach(h=>{l<h.startIndex&&i.push({type:"text",content:e.slice(l,h.startIndex)}),i.push({type:"mention",content:{label:e.slice(h.startIndex,h.endIndex+1),id:h.rangeId}}),l=h.endIndex+1}),i.push({type:"text",content:e.slice(l,r)}),i},Ze=n=>{const{paragraphs:e=[]}=n;let t=0;return e.map(r=>{const i=o.getBodySlice(n,t,r.startIndex);return t=r.startIndex+1,Ke(i)})},Ge=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 l=e.length-1;t.push({rangeId:r.content.id,rangeType:o.CustomRangeType.MENTION,startIndex:i,endIndex:l,properties:{}});break}}}),e+=`
|
|
16
|
+
\r`,{textRuns:[],paragraphs:[{startIndex:e.length-2,paragraphStyle:{}}],sectionBreaks:[{startIndex:e.length-1}],dataStream:e,customRanges:t}},g={threadComment:"univer-thread-comment",threadCommentActive:"univer-thread-comment-active",threadCommentContent:"univer-thread-comment-content",threadCommentHighlight:"univer-thread-comment-highlight",threadCommentIconContainer:"univer-thread-comment-icon-container",threadCommentIcon:"univer-thread-comment-icon",threadCommentTitle:"univer-thread-comment-title",threadCommentTitlePosition:"univer-thread-comment-title-position",threadCommentTitleHighlight:"univer-thread-comment-title-highlight",threadCommentTitlePositionText:"univer-thread-comment-title-position-text",threadCommentUsername:"univer-thread-comment-username",threadCommentItem:"univer-thread-comment-item",threadCommentItemHead:"univer-thread-comment-item-head",threadCommentItemTitle:"univer-thread-comment-item-title",threadCommentItemTitlePosition:"univer-thread-comment-item-title-position",threadCommentItemTitleHighlight:"univer-thread-comment-item-title-highlight",threadCommentItemTime:"univer-thread-comment-item-time",threadCommentItemContent:"univer-thread-comment-item-content",threadCommentItemAt:"univer-thread-comment-item-at"},Pe="__mock__",Ye=n=>{const{item:e,unitId:t,subUnitId:r,editing:i,onEditingChange:l,onReply:h,resolved:T,isRoot:S,onClose:N,onDeleteComment:M,type:B}=n,H=o.useDependency(o.ICommandService),x=o.useDependency(o.LocaleService),C=o.useDependency(o.UserManagerService),p=C.getUser(e.personId),w=$.useObservable(C.currentUser$),U=(w==null?void 0:w.userID)===e.personId,L=e.id===Pe,[b,V]=m.useState(!1),u=()=>{(M==null?void 0:M(e))!==!1&&(H.executeCommand(S?y.DeleteCommentTreeCommand.id:y.DeleteCommentCommand.id,{unitId:t,subUnitId:r,commentId:e.id}),S&&(N==null||N()))};return a.jsxs("div",{className:g.threadCommentItem,onMouseLeave:()=>V(!1),onMouseEnter:()=>V(!0),children:[a.jsx("img",{className:g.threadCommentItemHead,src:p==null?void 0:p.avatar}),a.jsxs("div",{className:g.threadCommentItemTitle,children:[a.jsx("div",{className:g.threadCommentUsername,children:(p==null?void 0:p.name)||" "}),a.jsxs("div",{children:[L||T?null:b?a.jsx("div",{className:g.threadCommentIcon,onClick:()=>h(p),children:a.jsx(Ie,{})}):null,U&&!L&&!T?a.jsx(A.DropdownLegacy,{overlay:a.jsxs(A.Menu,{children:[a.jsx(A.MenuItem,{onClick:()=>l==null?void 0:l(!0),children:x.t("threadCommentUI.item.edit")},"edit"),a.jsx(A.MenuItem,{onClick:u,children:x.t("threadCommentUI.item.delete")},"delete")]}),children:a.jsx("div",{className:g.threadCommentIcon,children:a.jsx(pe,{})})}):null]})]}),a.jsx("div",{className:g.threadCommentItemTime,children:e.dT}),i?a.jsx(Ue,{type:B,id:e.id,comment:e,onCancel:()=>l==null?void 0:l(!1),autoFocus:!0,unitId:t,subUnitId:r,onSave:({text:v,attachments:I})=>{l==null||l(!1),H.executeCommand(y.UpdateCommentCommand.id,{unitId:t,subUnitId:r,payload:{commentId:e.id,text:v,attachments:I}})}}):a.jsx("div",{className:g.threadCommentItemContent,children:Ze(e.text).map((v,I)=>a.jsx("div",{children:v.map((d,f)=>{switch(d.type){case"mention":return a.jsxs("a",{className:g.threadCommentItemAt,children:[d.content.label," "]},f);default:return d.content}})},I))})]})},Ee=n=>{var X,ee,ie;const{id:e,unitId:t,subUnitId:r,refStr:i,showEdit:l=!0,onClick:h,showHighlight:T,onClose:S,getSubUnitName:N,prefix:M,autoFocus:B,onMouseEnter:H,onMouseLeave:x,onAddComment:C,onDeleteComment:p,onResolve:w,type:U}=n,L=o.useDependency(y.ThreadCommentModel),[b,V]=m.useState(!1),[u,v]=m.useState(""),I=m.useMemo(()=>L.commentUpdate$.pipe(te.debounceTime(16)),[L]);$.useObservable(I);const d=e?L.getCommentWithChildren(t,r,e):null,f=o.useDependency(o.ICommandService),K=o.useDependency(o.UserManagerService),P=d==null?void 0:d.root.resolved,_=$.useObservable(K.currentUser$),Z=m.useRef(null),ne=[...d?[d.root]:[{id:Pe,text:{dataStream:`
|
|
17
|
+
\r`},personId:(X=_==null?void 0:_.userID)!=null?X:"",ref:i!=null?i:"",dT:"",unitId:t,subUnitId:r,threadId:""}],...(ee=d==null?void 0:d.children)!=null?ee:[]],j=m.useRef(null),Y=E=>{E.stopPropagation(),P?f.executeCommand(F.id,{unitId:t,subUnitId:r,commentId:e}):f.executeCommand(F.id),f.executeCommand(y.ResolveCommentCommand.id,{unitId:t,subUnitId:r,commentId:e,resolved:!P}),w==null||w(!P)},W=E=>{E.stopPropagation(),f.executeCommand(F.id),!(d!=null&&d.root&&(p==null?void 0:p(d.root))===!1)&&(f.executeCommand(y.DeleteCommentTreeCommand.id,{unitId:t,subUnitId:r,commentId:e}),S==null||S())};m.useEffect(()=>x==null?void 0:x(),[]);const J=N((ie=d==null?void 0:d.root.subUnitId)!=null?ie:r),Q=l&&!u&&!P,re=`${i||(d==null?void 0:d.root.ref)||""}${J?" · ":""}${J}`;return a.jsxs("div",{className:Re(g.threadComment,{[g.threadCommentActive]:!P&&(T||b||M==="cell")}),onClick:h,id:`${M}-${t}-${r}-${e}`,onMouseEnter:()=>{H==null||H(),V(!0)},onMouseLeave:()=>{x==null||x(),V(!1)},children:[!P&&T?a.jsx("div",{className:g.threadCommentHighlight}):null,a.jsxs("div",{className:g.threadCommentTitle,children:[a.jsxs("div",{className:g.threadCommentTitlePosition,children:[a.jsx("div",{className:g.threadCommentTitleHighlight}),a.jsx(A.Tooltip,{showIfEllipsis:!0,title:re,children:a.jsx("div",{className:g.threadCommentTitlePositionText,children:re})})]}),d?a.jsxs("div",{className:g.threadCommentIconContainer,children:[a.jsx("div",{onClick:Y,className:g.threadCommentIcon,style:{color:P?"rgb(var(--green-500))":""},children:P?a.jsx(Se,{}):a.jsx(Te,{})}),(_==null?void 0:_.userID)===d.root.personId?a.jsx("div",{className:g.threadCommentIcon,onClick:W,children:a.jsx(fe,{})}):null]}):null]}),a.jsx("div",{className:g.threadCommentContent,ref:j,children:ne.map(E=>a.jsx(Ye,{onClose:S,unitId:t,subUnitId:r,item:E,isRoot:E.id===(d==null?void 0:d.root.id),editing:u===E.id,resolved:d==null?void 0:d.root.resolved,type:U,onEditingChange:s=>{v(s?E.id:"")},onReply:s=>{s&&requestAnimationFrame(()=>{var k;(k=Z.current)==null||k.reply(Ge([{type:"mention",content:{id:s.userID,label:s.name}}]))})},onAddComment:C,onDeleteComment:p},E.id))}),Q?a.jsx("div",{children:a.jsx(Ue,{ref:Z,type:U,unitId:t,subUnitId:r,onSave:async({text:E,attachments:s})=>{const k={text:E,attachments:s,dT:y.getDT(),id:o.generateRandomId(),ref:i,personId:_==null?void 0:_.userID,parentId:d==null?void 0:d.root.id,unitId:t,subUnitId:r,threadId:d==null?void 0:d.root.threadId};(C==null?void 0:C(k))!==!1&&(await f.executeCommand(y.AddCommentCommand.id,{unitId:t,subUnitId:r,comment:k}),j.current&&(j.current.scrollTop=j.current.scrollHeight))},autoFocus:B||!d,onCancel:()=>{d||S==null||S()}},`${B}`)}):null]})},G={threadCommentPanel:"univer-thread-comment-panel",threadComment:"univer-thread-comment",threadCommentPanelForms:"univer-thread-comment-panel-forms",select:"univer-select",threadCommentPanelEmpty:"univer-thread-comment-panel-empty",threadCommentPanelAdd:"univer-thread-comment-panel-add",threadCommentPanelSolved:"univer-thread-comment-panel-solved"},Je=n=>{const{unitId:e,subUnitId$:t,type:r,onAdd:i,getSubUnitName:l,onResolve:h,sortComments:T,onItemLeave:S,onItemEnter:N,disableAdd:M,tempComment:B,onAddComment:H,onDeleteComment:x,showComments:C}=n,[p,w]=m.useState("all"),[U,L]=m.useState("all"),b=o.useDependency(o.LocaleService),V=o.useDependency(o.UserManagerService),u=o.useDependency(y.ThreadCommentModel),[v,I]=m.useState(()=>u.getUnit(e)),d=o.useDependency(c.ThreadCommentPanelService),f=$.useObservable(d.activeCommentId$),K=$.useObservable(u.commentUpdate$),P=o.useDependency(o.ICommandService),_=$.useObservable(t),Z=m.useRef(!0),ne="panel",j=$.useObservable(V.currentUser$),Y=m.useMemo(()=>{var ae;const s=p==="all"?v:(ae=v.filter(D=>D.subUnitId===_))!=null?ae:[],k=T!=null?T:D=>D,oe=s.map(D=>{var z;return{...D.root,children:(z=D.children)!=null?z:[],users:D.relativeUsers}});if(C){const D=new Map;return oe.forEach(z=>{D.set(z.id,z)}),[...C,""].map(z=>D.get(z)).filter(Boolean)}else return k(oe)},[C,p,v,T,_]),W=m.useMemo(()=>[...Y.filter(s=>!s.resolved),...Y.filter(s=>s.resolved)],[Y]),J=m.useMemo(()=>U==="resolved"?W.filter(s=>s.resolved):U==="unsolved"?W.filter(s=>!s.resolved):U==="concern_me"&&j!=null&&j.userID?W.filter(s=>s==null?void 0:s.users.has(j.userID)):W,[W,j==null?void 0:j.userID,U]),Q=B?[B,...J]:J,re=Q.filter(s=>!s.resolved),X=Q.filter(s=>s.resolved),ee=U!=="all"||p!=="all",ie=()=>{L("all"),w("all")};m.useEffect(()=>{e&&I(u.getUnit(e))},[e,u,K]),m.useEffect(()=>{var D;if(!f)return;if(!Z.current){Z.current=!0;return}const{unitId:s,subUnitId:k,commentId:oe}=f,ae=`${ne}-${s}-${k}-${oe}`;(D=document.getElementById(ae))==null||D.scrollIntoView({block:"center"})},[f]);const E=s=>a.jsx(Ee,{prefix:ne,getSubUnitName:l,id:s.id,unitId:s.unitId,subUnitId:s.subUnitId,refStr:s.ref,type:r,showEdit:(f==null?void 0:f.commentId)===s.id,showHighlight:(f==null?void 0:f.commentId)===s.id,onClick:()=>{Z.current=!1,s.resolved?P.executeCommand(F.id):P.executeCommand(F.id,{unitId:s.unitId,subUnitId:s.subUnitId,commentId:s.id,temp:!1})},onMouseEnter:()=>N==null?void 0:N(s),onMouseLeave:()=>S==null?void 0:S(s),onAddComment:H,onDeleteComment:x,onResolve:k=>h==null?void 0:h(s.id,k)},s.id);return a.jsxs("div",{className:G.threadCommentPanel,children:[a.jsxs("div",{className:G.threadCommentPanelForms,children:[r===o.UniverInstanceType.UNIVER_SHEET?a.jsx(A.Select,{borderless:!0,value:p,onChange:s=>w(s),options:[{value:"current",label:b.t("threadCommentUI.filter.sheet.current")},{value:"all",label:b.t("threadCommentUI.filter.sheet.all")}]}):null,a.jsx(A.Select,{borderless:!0,value:U,onChange:s=>L(s),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")}]})]}),re.map(E),X.length?a.jsx("div",{className:G.threadCommentPanelSolved,children:"已解决"}):null,X.map(E),Q.length?null:a.jsxs("div",{className:G.threadCommentPanelEmpty,children:[ee?b.t("threadCommentUI.panel.filterEmpty"):b.t("threadCommentUI.panel.empty"),ee?a.jsx(A.Button,{onClick:ie,type:"link",children:b.t("threadCommentUI.panel.reset")}):a.jsxs(A.Button,{id:"thread-comment-add",className:G.threadCommentPanelAdd,type:"primary",onClick:i,disabled:M,children:[a.jsx(ge,{}),b.t("threadCommentUI.panel.addComment")]})]})]})};c.SetActiveCommentOperation=F,c.THREAD_COMMENT_PANEL=me,c.ThreadCommentPanel=Je,c.ThreadCommentTree=Ee,c.ToggleSheetCommentPanelOperation=ce,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
26
18
|
|
|
27
19
|
|
|
28
20
|
// @univerjs/sheets-thread-comment-ui/index
|
|
29
|
-
(function(d,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/sheets-thread-comment"),require("@univerjs/thread-comment-ui"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/engine-render"),require("@univerjs/engine-formula"),require("@univerjs/thread-comment"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/sheets-thread-comment","@univerjs/thread-comment-ui","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/engine-render","@univerjs/engine-formula","@univerjs/thread-comment","react"],s):(d=typeof globalThis<"u"?globalThis:d||self,s(d.UniverSheetsThreadCommentUi={},d.UniverCore,d.UniverSheets,d.UniverSheetsThreadComment,d.UniverThreadCommentUi,d.UniverSheetsUi,d.UniverUi,d.rxjs,d.UniverEngineRender,d.UniverEngineFormula,d.UniverThreadComment,d.React))})(this,function(d,s,v,A,g,b,f,x,ie,k,C,E){"use strict";var rt=Object.defineProperty;var it=(d,s,v)=>s in d?rt(d,s,{enumerable:!0,configurable:!0,writable:!0,value:v}):d[s]=v;var N=(d,s,v)=>it(d,typeof s!="symbol"?s+"":s,v);const oe="univer.sheet.thread-comment-modal",K="comment-single",Q="SHEET_THREAD_COMMENT";var _e=Object.defineProperty,fe=Object.getOwnPropertyDescriptor,Ce=(i,t,n,e)=>{for(var r=e>1?void 0:e?fe(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&_e(t,n,r),r},se=(i,t)=>(n,e)=>t(n,e,i);d.SheetsThreadCommentPopupService=class extends s.Disposable{constructor(n,e){super();N(this,"_lastPopup",null);N(this,"_activePopup");N(this,"_activePopup$",new x.BehaviorSubject(null));N(this,"activePopup$",this._activePopup$.asObservable());this._canvasPopupManagerService=n,this._zenZoneService=e,this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}get activePopup(){return this._activePopup}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(n=>{n&&this.hidePopup()}))}showPopup(n,e){var m;const{row:r,col:o,unitId:a,subUnitId:c}=n;if(this._activePopup&&r===this._activePopup.row&&o===this._activePopup.col&&a===this._activePopup.unitId&&c===((m=this.activePopup)==null?void 0:m.subUnitId)){this._activePopup=n,this._activePopup$.next(n);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=n,this._activePopup$.next(n);const u=this._canvasPopupManagerService.attachPopupToCell(r,o,{componentKey:oe,onClickOutside:()=>{this.hidePopup()},direction:"horizontal",excludeOutside:[...Array.from(document.querySelectorAll(".univer-thread-comment")),document.getElementById("thread-comment-add")].filter(Boolean)});if(!u)throw new Error("[SheetsThreadCommentPopupService]: cannot show popup!");const h=new s.DisposableCollection;h.add(u),h.add({dispose:()=>{e==null||e()}}),this._lastPopup=h}hidePopup(){this._activePopup&&(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}},d.SheetsThreadCommentPopupService=Ce([se(0,s.Inject(b.SheetCanvasPopManagerService)),se(1,f.IZenZoneService)],d.SheetsThreadCommentPopupService);const $={type:s.CommandType.OPERATION,id:"sheets.operation.show-comment-modal",handler(i){var I;const t=i.get(v.SheetsSelectionsService),n=i.get(s.IUniverInstanceService),e=i.get(d.SheetsThreadCommentPopupService),r=i.get(g.ThreadCommentPanelService),o=(I=t.getCurrentLastSelection())==null?void 0:I.primary,a=i.get(A.SheetsThreadCommentModel);if(!o)return!1;const c=v.getSheetCommandTarget(n);if(!c)return!1;const{workbook:u,worksheet:h,unitId:m,subUnitId:l}=c,p={workbook:u,worksheet:h,unitId:m,subUnitId:l,row:o.startRow,col:o.startColumn};e.showPopup(p);const S=a.getByLocation(m,l,o.startRow,o.startColumn);return S&&r.setActiveComment({unitId:m,subUnitId:l,commentId:S,trigger:"context-menu"}),!0}},Ie="sheets-thread-comment.config",ae={};var ge=Object.defineProperty,Pe=Object.getOwnPropertyDescriptor,Te=(i,t,n,e)=>{for(var r=e>1?void 0:e?Pe(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&ge(t,n,r),r},B=(i,t)=>(n,e)=>t(n,e,i);let W=class extends s.Disposable{constructor(i,t,n,e){super(),this._sheetInterceptorService=i,this._sheetsThreadCommentModel=t,this._univerInstanceService=n,this._renderManagerService=e,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(v.INTERCEPTOR_POINT.CELL_CONTENT,{effect:s.InterceptorEffectEnum.Style,handler:(i,t,n)=>{const{row:e,col:r,unitId:o,subUnitId:a}=t;return this._sheetsThreadCommentModel.showCommentMarker(o,a,e,r)?n({...i,markers:{...i==null?void 0:i.markers,tr:{color:"#FFBD37",size:6}}}):n(i)},priority:100}))}_initSkeletonChange(){const i=()=>{var r;const t=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!t)return;const n=t.getUnitId(),e=this._renderManagerService.getRenderById(n);(r=e==null?void 0:e.mainComponent)==null||r.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe(x.debounceTime(16)).subscribe(()=>{i()}))}};W=Te([B(0,s.Inject(v.SheetInterceptorService)),B(1,s.Inject(A.SheetsThreadCommentModel)),B(2,s.IUniverInstanceService),B(3,ie.IRenderManagerService)],W);var be=Object.defineProperty,ye=Object.getOwnPropertyDescriptor,Me=(i,t,n,e)=>{for(var r=e>1?void 0:e?ye(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&be(t,n,r),r},X=(i,t)=>(n,e)=>t(n,e,i);const we=(i,t,n)=>{const e=k.singleReferenceToGrid(i),r=n.row-t.row,o=n.column-t.column,a={startColumn:e.column+o,startRow:e.row+r,endColumn:e.column+o,endRow:e.row+r};return k.serializeRange(a)};let F=class extends s.Disposable{constructor(t,n,e){super();N(this,"_copyInfo");this._sheetClipboardService=t,this._sheetsThreadCommentModel=n,this._threadCommentDataSourceService=e,this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:Q,onBeforeCopy:(t,n,e)=>{this._copyInfo={unitId:t,subUnitId:n,range:e}},onPasteCells:(t,n,e,r)=>{const{unitId:o,subUnitId:a,range:c}=n,u={row:c.rows[0],column:c.cols[0]};if(r.copyType===b.COPY_TYPE.CUT&&this._copyInfo){const{range:h,unitId:m,subUnitId:l}=this._copyInfo,p={row:h.startRow,column:h.startColumn};if(!(o===m&&a===l)){const S=[];s.Range.foreach(h,(w,_)=>{const R=this._sheetsThreadCommentModel.getAllByLocation(m,l,w,_);this._threadCommentDataSourceService.syncUpdateMutationToColla?R.forEach(P=>{S.push(P)}):R.forEach(({children:P,...j})=>{j.parentId||S.push(j)})});const I=[],M=[],V=[],L=[],re=w=>{I.unshift({id:C.DeleteCommentMutation.id,params:{unitId:m,subUnitId:l,commentId:w.id}}),V.push({id:C.AddCommentMutation.id,params:{unitId:o,subUnitId:a,comment:{...w,ref:we(w.ref,p,u),unitId:o,subUnitId:a},sync:!0}}),M.push({id:C.AddCommentMutation.id,params:{unitId:m,subUnitId:l,comment:w,sync:!0}}),L.unshift({id:C.DeleteCommentMutation.id,params:{unitId:o,subUnitId:a,commentId:w.id}})};return S.forEach(w=>{re(w)}),{redos:[...I,...V],undos:[...L,...M]}}}return{redos:[],undos:[]}}}))}};F=Me([X(0,s.Inject(b.ISheetClipboardService)),X(1,s.Inject(A.SheetsThreadCommentModel)),X(2,C.IThreadCommentDataSourceService)],F);var Re=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,Oe=(i,t,n,e)=>{for(var r=e>1?void 0:e?Ee(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&Re(t,n,r),r},G=(i,t)=>(n,e)=>t(n,e,i);let Z=class extends s.Disposable{constructor(i,t,n,e){super(),this._hoverManagerService=i,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=n,this._sheetPermissionCheckController=e,this._initHoverEvent()}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(x.debounceTime(100)).subscribe(i=>{const t=this._sheetsThreadCommentPopupService.activePopup;if(i&&(t&&t.temp||!t)){const{location:n}=i,{unitId:e,subUnitId:r,row:o,col:a}=n,c=this._sheetsThreadCommentModel.getByLocation(e,r,o,a);if(c){if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[v.WorkbookCommentPermission],worksheetTypes:[v.WorksheetViewPermission],rangeTypes:[v.RangeProtectionPermissionViewPoint]},[{startRow:o,startColumn:a,endRow:o,endColumn:a}]))return;const h=this._sheetsThreadCommentModel.getComment(e,r,c);h&&!h.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:e,subUnitId:r,row:o,col:a,commentId:c,temp:!0})}else t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};Z=Oe([G(0,s.Inject(b.HoverManagerService)),G(1,s.Inject(d.SheetsThreadCommentPopupService)),G(2,s.Inject(A.SheetsThreadCommentModel)),G(3,s.Inject(v.SheetPermissionCheckController))],Z);var Ue=Object.defineProperty,je=Object.getOwnPropertyDescriptor,De=(i,t,n,e)=>{for(var r=e>1?void 0:e?je(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&Ue(t,n,r),r},U=(i,t)=>(n,e)=>t(n,e,i);let z=class extends s.Disposable{constructor(t,n,e,r,o,a,c,u,h,m){super();N(this,"_isSwitchToCommenting",!1);N(this,"_selectionShapeInfo",null);this._commandService=t,this._sheetsThreadCommentPopupService=n,this._sheetsThreadCommentModel=e,this._threadCommentPanelService=r,this._univerInstanceService=o,this._sheetPermissionCheckController=a,this._markSelectionService=c,this._sheetSelectionService=u,this._editorBridgeService=h,this._renderManagerService=m,this._initCommandListener(),this._initPanelListener(),this._initMarkSelection(),this._initSelectionUpdateListener(),this._initEditorBridge()}_handleSelectionChange(t,n,e){var p,S,I;const r=(p=t[0])==null?void 0:p.range,o=this._renderManagerService.getRenderById(n),a=(S=o==null?void 0:o.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(e))==null?void 0:S.skeleton;if(!a||!r)return;const c=a.getCellWithCoordByIndex(r.startRow,r.startColumn);if((((I=r.rangeType)!=null?I:s.RANGE_TYPE.NORMAL)!==s.RANGE_TYPE.NORMAL||r.endColumn-r.startColumn>0||r.endRow-r.startRow>0)&&!((c.isMerged||c.isMergedMainCell)&&s.Rectangle.equals(c.mergeInfo,r))){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(g.SetActiveCommentOperation.id);return}const h=c.actualRow,m=c.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(n,e,h,m)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(g.SetActiveCommentOperation.id);return}const l=this._sheetsThreadCommentModel.getByLocation(n,e,h,m);l&&this._commandService.executeCommand(g.SetActiveCommentOperation.id,{unitId:n,subUnitId:e,commentId:l})}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(t=>{if(this._isSwitchToCommenting)return;const n=this._sheetSelectionService.currentSelectionParam;n&&this._handleSelectionChange(t,n.unitId,n.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(t=>{t.visible&&this._sheetsThreadCommentPopupService.hidePopup()}))}_initCommandListener(){this._commandService.onCommandExecuted(t=>{if(t.id===C.DeleteCommentMutation.id){const n=t.params,e=this._sheetsThreadCommentPopupService.activePopup;if(!e)return;const{unitId:r,subUnitId:o,commentId:a}=e;n.unitId===r&&n.subUnitId===o&&n.commentId===a&&this._sheetsThreadCommentPopupService.hidePopup()}})}_initPanelListener(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async t=>{var n;if(t){const{unitId:e,subUnitId:r,commentId:o,trigger:a}=t,c=this._sheetsThreadCommentModel.getComment(e,r,o);if(!c||c.resolved)return;const u=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!u||u.getUnitId()!==e)return;this._isSwitchToCommenting=!0,((n=u.getActiveSheet())==null?void 0:n.getSheetId())!==r&&await this._commandService.executeCommand(v.SetWorksheetActiveOperation.id,{unitId:e,subUnitId:r}),this._isSwitchToCommenting=!1;const l=k.singleReferenceToGrid(c.ref),{row:p,column:S}=l;if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[v.WorkbookCommentPermission],worksheetTypes:[v.WorksheetViewPermission],rangeTypes:[v.RangeProtectionPermissionViewPoint]},[{startRow:p,startColumn:S,endRow:p,endColumn:S}]))return;const M=1;if(await this._commandService.executeCommand(b.ScrollToRangeOperation.id,{range:{startRow:Math.max(l.row-M,0),endRow:l.row+M,startColumn:Math.max(l.column-M,0),endColumn:l.column+M}}),this._editorBridgeService.isVisible().visible)return;this._sheetsThreadCommentPopupService.showPopup({unitId:e,subUnitId:r,row:l.row,col:l.column,commentId:c.id,trigger:a})}else this._sheetsThreadCommentPopupService.hidePopup()}))}_initMarkSelection(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe(x.debounceTime(100)).subscribe(t=>{var p,S;if(!t){this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);return}const{unitId:n,subUnitId:e,commentId:r}=t;this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);const o=this._sheetsThreadCommentModel.getComment(n,e,r);if(!o)return;const a=k.singleReferenceToGrid(o.ref),{row:c,column:u}=a;if(Number.isNaN(c)||Number.isNaN(u))return null;const h=(p=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET))==null?void 0:p.getSheetBySheetId(e),m=(S=h==null?void 0:h.getMergedCell(c,u))!=null?S:{startColumn:u,endColumn:u,startRow:c,endRow:c},l=this._markSelectionService.addShape({range:m,style:{fill:"rgb(255, 189, 55, 0.35)",strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null},[],-1);l&&(this._selectionShapeInfo={...t,shapeId:l})}))}};z=De([U(0,s.ICommandService),U(1,s.Inject(d.SheetsThreadCommentPopupService)),U(2,s.Inject(A.SheetsThreadCommentModel)),U(3,s.Inject(g.ThreadCommentPanelService)),U(4,s.IUniverInstanceService),U(5,s.Inject(v.SheetPermissionCheckController)),U(6,b.IMarkSelectionService),U(7,s.Inject(v.SheetsSelectionsService)),U(8,b.IEditorBridgeService),U(9,ie.IRenderManagerService)],z);var Ne=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,Ve=(i,t,n,e)=>{for(var r=e>1?void 0:e?Ae(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&Ne(t,n,r),r},q=(i,t)=>(n,e)=>t(n,e,i);let Y=class extends s.Disposable{constructor(i,t,n,e){super(),this._sheetInterceptorService=i,this._univerInstanceService=t,this._threadCommentModel=n,this._threadCommentDataSourceService=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===v.RemoveSheetCommand.id){const n=i.params,e=n.unitId?this._univerInstanceService.getUnit(n.unitId):this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!e)return{redos:[],undos:[]};const r=e.getUnitId(),o=n.subUnitId||((t=e.getActiveSheet())==null?void 0:t.getSheetId());if(!o)return{redos:[],undos:[]};const a=this._threadCommentModel.ensureMap(r,o),c=Array.from(a.values()).filter(p=>!p.parentId),u=c.map(p=>p.id),h=this._threadCommentDataSourceService.syncUpdateMutationToColla,m=u.map(p=>({id:C.DeleteCommentMutation.id,params:{unitId:r,subUnitId:o,commentId:p}})),l=c.map(({children:p,...S})=>({id:C.AddCommentMutation.id,params:{unitId:r,subUnitId:o,comment:{...S,children:h?p:void 0},sync:!h}}));return{redos:m,undos:l}}return{redos:[],undos:[]}}}))}};Y=Ve([q(0,s.Inject(v.SheetInterceptorService)),q(1,s.IUniverInstanceService),q(2,s.Inject(C.ThreadCommentModel)),q(3,C.IThreadCommentDataSourceService)],Y);var y=function(){return y=Object.assign||function(i){for(var t,n=1,e=arguments.length;n<e;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(i[r]=t[r])}return i},y.apply(this,arguments)},ke=function(i,t){var n={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&t.indexOf(e)<0&&(n[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,e=Object.getOwnPropertySymbols(i);r<e.length;r++)t.indexOf(e[r])<0&&Object.prototype.propertyIsEnumerable.call(i,e[r])&&(n[e[r]]=i[e[r]]);return n},ce=E.forwardRef(function(i,t){var n=i.icon,e=i.id,r=i.className,o=i.extend,a=ke(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(r||"").trim(),u=E.useRef("_".concat(He()));return ue(n,"".concat(e),{defIds:n.defIds,idSuffix:u.current},y({ref:t,className:c},a),o)});function ue(i,t,n,e,r){return E.createElement(i.tag,y(y({key:t},$e(i,n,r)),e),(xe(i,n).children||[]).map(function(o,a){return ue(o,"".concat(t,"-").concat(i.tag,"-").concat(a),n,void 0,r)}))}function $e(i,t,n){var e=y({},i.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var r=t.defIds;return!r||r.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+t.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],c=o[1];typeof c=="string"&&(e[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),e}function xe(i,t){var n,e=t.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?y(y({},i),{children:i.children.map(function(r){return typeof r.attrs.id=="string"&&e&&e.indexOf(r.attrs.id)>-1?y(y({},r),{attrs:y(y({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):i}function He(){return Math.random().toString(36).substring(2,8)}ce.displayName="UniverIcon";var Le={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345ZM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345ZM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521 5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345zM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521 8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345zM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521 11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.84351 3.41861C1.84351 3.01861 2.15531 2.69434 2.53993 2.69434H14.9381C15.3228 2.69434 15.6346 3.01861 15.6346 3.41861V12.4611C15.6346 12.8612 15.3228 13.1854 14.9381 13.1854H8.82117L6.06643 14.6179C5.85054 14.7301 5.59416 14.7181 5.38884 14.5862C5.18352 14.4542 5.05855 14.2211 5.05855 13.9701V13.1854H2.53993C2.15531 13.1854 1.84351 12.8612 1.84351 12.4611L1.84351 3.41861ZM6.45141 12.7982L8.34531 12.0135C8.44201 11.9632 8.54864 11.9371 8.65676 11.9371H14.2417C14.3522 11.9371 14.4417 11.8475 14.4417 11.7371V4.14271C14.4417 4.03225 14.3522 3.94271 14.2417 3.94271H3.23636C3.12591 3.94271 3.03636 4.03225 3.03636 4.14271L3.03636 11.7371C3.03636 11.8475 3.12591 11.9371 3.23636 11.9371L5.75498 11.9371C6.1396 11.9371 6.45141 12.0611 6.45141 12.4611V12.7982Z",fillRule:"evenodd",clipRule:"evenodd"}}]},de=E.forwardRef(function(i,t){return E.createElement(ce,Object.assign({},i,{id:"comment-single",ref:t,icon:Le}))});de.displayName="CommentSingle";var ee={exports:{}},H={};/**
|
|
30
|
-
* @license React
|
|
31
|
-
* react-jsx-runtime.production.min.js
|
|
32
|
-
*
|
|
33
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
34
|
-
*
|
|
35
|
-
* This source code is licensed under the MIT license found in the
|
|
36
|
-
* LICENSE file in the root directory of this source tree.
|
|
37
|
-
*/var me;function Be(){if(me)return H;me=1;var i=E,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,r=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function a(c,u,h){var m,l={},p=null,S=null;h!==void 0&&(p=""+h),u.key!==void 0&&(p=""+u.key),u.ref!==void 0&&(S=u.ref);for(m in u)e.call(u,m)&&!o.hasOwnProperty(m)&&(l[m]=u[m]);if(c&&c.defaultProps)for(m in u=c.defaultProps,u)l[m]===void 0&&(l[m]=u[m]);return{$$typeof:t,type:c,key:p,ref:S,props:l,_owner:r.current}}return H.Fragment=n,H.jsx=a,H.jsxs=a,H}var he;function We(){return he||(he=1,ee.exports=Be()),ee.exports}var le=We();const Fe=()=>{const i=s.useDependency(s.IUniverInstanceService),t=s.useDependency(d.SheetsThreadCommentPopupService),n=f.useObservable(t.activePopup$),e=s.useDependency(A.SheetsThreadCommentModel);if(f.useObservable(e.commentUpdate$),!n)return null;const{row:r,col:o,unitId:a,subUnitId:c,trigger:u}=n,h=e.getByLocation(a,c,r,o),m=`${s.Tools.chatAtABC(o)}${r+1}`,l=()=>{t.hidePopup()},p=S=>{var I,M,V;return(V=(M=(I=i.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET))==null?void 0:I.getSheetBySheetId(S))==null?void 0:M.getName())!=null?V:""};return le.jsx(g.ThreadCommentTree,{onClick:()=>{t.persistPopup()},prefix:"cell",id:h,unitId:a,subUnitId:c,type:s.UniverInstanceType.UNIVER_SHEET,refStr:m,onClose:l,getSubUnitName:p,autoFocus:u==="context-menu"})},Ge=()=>{var w;const i=s.useDependency(b.IMarkSelectionService),t=s.useDependency(s.IUniverInstanceService),n=s.useDependency(d.SheetsThreadCommentPopupService),e=t.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),r=e.getUnitId(),o=s.useDependency(s.ICommandService),a=E.useMemo(()=>e.activeSheet$.pipe(x.map(_=>_==null?void 0:_.getSheetId())),[e.activeSheet$]),c=f.useObservable(a,(w=e.getActiveSheet())==null?void 0:w.getSheetId()),u=E.useRef(),h=s.useDependency(g.ThreadCommentPanelService),m=f.useObservable(h.activeCommentId$),l=f.useObservable(h.panelVisible$,h.panelVisible),p=E.useCallback(_=>{const R=e.getSheets(),P={};R.forEach((O,T)=>{P[O.getSheetId()]=T});const j=O=>O.map(T=>{var Se;const D=k.singleReferenceToGrid(T.ref),nt=[(Se=P[T.subUnitId])!=null?Se:0,D.row,D.column];return{...T,p:nt}}).sort((T,D)=>T.p[0]===D.p[0]?T.p[1]===D.p[1]?T.p[2]-D.p[2]:T.p[1]-D.p[1]:T.p[0]-D.p[0]);return[...j(_.filter(O=>!O.resolved)),...j(_.filter(O=>O.resolved))]},[e]),S=E.useCallback(_=>{var R;if(_.unitId===r&&_.subUnitId===c&&!_.resolved){const{row:P,column:j}=k.singleReferenceToGrid(_.ref),O=e.getSheetBySheetId(_.subUnitId),T=(R=O==null?void 0:O.getMergedCell(P,j))!=null?R:{startColumn:j,endColumn:j,startRow:P,endRow:P};if(!Number.isNaN(P)&&!Number.isNaN(j))return i.addShape({range:T,style:{fill:"rgb(255, 189, 55, 0.35)",strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null})}},[i,c,r]),I=_=>{var R,P;return(P=(R=e.getSheetBySheetId(_))==null?void 0:R.getName())!=null?P:""},M=()=>{o.executeCommand($.id)},V=_=>{m&&m.unitId===_.unitId&&m.subUnitId===_.subUnitId&&m.commentId===_.id||(u.current&&(i.removeShape(u.current),u.current=null),u.current=S(_))},L=()=>{u.current&&(i.removeShape(u.current),u.current=null)},re=(_,R)=>{R&&n.hidePopup()};return E.useEffect(()=>{!l&&u.current&&i.removeShape(u.current)},[i,l]),le.jsx(g.ThreadCommentPanel,{unitId:r,subUnitId$:a,type:s.UniverInstanceType.UNIVER_SHEET,onAdd:M,getSubUnitName:I,onResolve:re,sortComments:p,onItemEnter:V,onItemLeave:L,onDeleteComment:()=>(L(),!0)})},Ze=i=>({id:$.id,type:f.MenuItemType.BUTTON,icon:K,title:"sheetThreadComment.menu.addComment",hidden$:f.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_SHEET),disabled$:b.getCurrentRangeDisable$(i,{workbookTypes:[v.WorkbookCommentPermission],worksheetTypes:[v.WorksheetViewPermission],rangeTypes:[v.RangeProtectionPermissionViewPoint]})}),ze=i=>({id:g.ToggleSheetCommentPanelOperation.id,type:f.MenuItemType.BUTTON,icon:K,tooltip:"sheetThreadComment.menu.commentManagement",disabled$:b.getCurrentRangeDisable$(i,{workbookTypes:[v.WorkbookCommentPermission],worksheetTypes:[v.WorksheetViewPermission],rangeTypes:[v.RangeProtectionPermissionViewPoint]}),hidden$:f.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_SHEET)}),qe={id:$.id,binding:f.KeyCode.M|f.MetaKeys.CTRL_COMMAND|f.MetaKeys.ALT,preconditions:b.whenSheetEditorFocused},Ye={[f.RibbonStartGroup.OTHERS]:{[g.ToggleSheetCommentPanelOperation.id]:{order:1,menuItemFactory:ze}},[f.ContextMenuPosition.MAIN_AREA]:{[f.ContextMenuGroup.OTHERS]:{[$.id]:{order:0,menuItemFactory:Ze}}}};var Je=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,Qe=(i,t,n,e)=>{for(var r=e>1?void 0:e?Ke(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&Je(t,n,r),r},te=(i,t)=>(n,e)=>t(n,e,i);let J=class extends s.Disposable{constructor(i,t,n){super(),this._menuManagerService=i,this._componentManager=t,this._shortcutService=n,this._initMenu(),this._initShortcut(),this._initComponent()}_initShortcut(){this._shortcutService.registerShortcut(qe)}_initMenu(){this._menuManagerService.mergeMenu(Ye)}_initComponent(){[[oe,Fe],[g.THREAD_COMMENT_PANEL,Ge],[K,de]].forEach(([i,t])=>{this._componentManager.register(i,t)})}};J=Qe([te(0,f.IMenuManagerService),te(1,s.Inject(f.ComponentManager)),te(2,f.IShortcutService)],J);var pe=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,et=(i,t,n)=>t in i?pe(i,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[t]=n,tt=(i,t,n,e)=>{for(var r=e>1?void 0:e?Xe(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&pe(t,n,r),r},ne=(i,t)=>(n,e)=>t(n,e,i),ve=(i,t,n)=>et(i,typeof t!="symbol"?t+"":t,n);d.UniverSheetsThreadCommentUIPlugin=class extends s.Plugin{constructor(t=ae,n,e,r){super(),this._config=t,this._injector=n,this._commandService=e,this._configService=r;const{menu:o,...a}=s.merge({},ae,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Ie,a)}onStarting(){[[J],[W],[F],[Z],[Y],[z],[d.SheetsThreadCommentPopupService]].forEach(t=>{this._injector.add(t)}),[$].forEach(t=>{this._commandService.registerCommand(t)}),this._injector.get(J)}onReady(){this._injector.get(W),this._injector.get(Y)}onRendered(){this._injector.get(F),this._injector.get(Z),this._injector.get(z)}},ve(d.UniverSheetsThreadCommentUIPlugin,"pluginName",Q),ve(d.UniverSheetsThreadCommentUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),d.UniverSheetsThreadCommentUIPlugin=tt([s.DependentOn(g.UniverThreadCommentUIPlugin,A.UniverSheetsThreadCommentPlugin),ne(1,s.Inject(s.Injector)),ne(2,s.Inject(s.ICommandService)),ne(3,s.IConfigService)],d.UniverSheetsThreadCommentUIPlugin),Object.defineProperty(d,"UniverThreadCommentUIPlugin",{enumerable:!0,get:()=>g.UniverThreadCommentUIPlugin}),Object.defineProperty(d,"AddCommentCommand",{enumerable:!0,get:()=>C.AddCommentCommand}),Object.defineProperty(d,"DeleteCommentCommand",{enumerable:!0,get:()=>C.DeleteCommentCommand}),Object.defineProperty(d,"DeleteCommentTreeCommand",{enumerable:!0,get:()=>C.DeleteCommentTreeCommand}),Object.defineProperty(d,"IThreadCommentDataSourceService",{enumerable:!0,get:()=>C.IThreadCommentDataSourceService}),Object.defineProperty(d,"ResolveCommentCommand",{enumerable:!0,get:()=>C.ResolveCommentCommand}),Object.defineProperty(d,"UpdateCommentCommand",{enumerable:!0,get:()=>C.UpdateCommentCommand}),d.SHEETS_THREAD_COMMENT=Q,d.ShowAddSheetCommentModalOperation=$,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
21
|
+
(function(c,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/sheets-thread-comment"),require("@univerjs/thread-comment-ui"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/engine-render"),require("@univerjs/engine-formula"),require("@univerjs/thread-comment"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/sheets-thread-comment","@univerjs/thread-comment-ui","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/engine-render","@univerjs/engine-formula","@univerjs/thread-comment","react/jsx-runtime","react"],s):(c=typeof globalThis<"u"?globalThis:c||self,s(c.UniverSheetsThreadCommentUi={},c.UniverCore,c.UniverSheets,c.UniverSheetsThreadComment,c.UniverThreadCommentUi,c.UniverSheetsUi,c.UniverUi,c.rxjs,c.UniverEngineRender,c.UniverEngineFormula,c.UniverThreadComment,c.React,c.React))})(this,function(c,s,p,$,g,b,_,H,ne,V,f,re,U){"use strict";var Je=Object.defineProperty;var Qe=(c,s,p)=>s in c?Je(c,s,{enumerable:!0,configurable:!0,writable:!0,value:p}):c[s]=p;var N=(c,s,p)=>Qe(c,typeof s!="symbol"?s+"":s,p);const ie="univer.sheet.thread-comment-modal",Y="comment-single",J="SHEET_THREAD_COMMENT";var le=Object.defineProperty,pe=Object.getOwnPropertyDescriptor,ve=(i,t,n,e)=>{for(var r=e>1?void 0:e?pe(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&le(t,n,r),r},oe=(i,t)=>(n,e)=>t(n,e,i);c.SheetsThreadCommentPopupService=class extends s.Disposable{constructor(n,e){super();N(this,"_lastPopup",null);N(this,"_activePopup");N(this,"_activePopup$",new H.BehaviorSubject(null));N(this,"activePopup$",this._activePopup$.asObservable());this._canvasPopupManagerService=n,this._zenZoneService=e,this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}get activePopup(){return this._activePopup}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(n=>{n&&this.hidePopup()}))}showPopup(n,e){var l;const{row:r,col:o,unitId:a,subUnitId:u}=n;if(this._activePopup&&r===this._activePopup.row&&o===this._activePopup.col&&a===this._activePopup.unitId&&u===((l=this.activePopup)==null?void 0:l.subUnitId)){this._activePopup=n,this._activePopup$.next(n);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=n,this._activePopup$.next(n);const d=this._canvasPopupManagerService.attachPopupToCell(r,o,{componentKey:ie,onClickOutside:()=>{this.hidePopup()},direction:"horizontal",excludeOutside:[...Array.from(document.querySelectorAll(".univer-thread-comment")),document.getElementById("thread-comment-add")].filter(Boolean)});if(!d)throw new Error("[SheetsThreadCommentPopupService]: cannot show popup!");const m=new s.DisposableCollection;m.add(d),m.add({dispose:()=>{e==null||e()}}),this._lastPopup=m}hidePopup(){this._activePopup&&(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}},c.SheetsThreadCommentPopupService=ve([oe(0,s.Inject(b.SheetCanvasPopManagerService)),oe(1,_.IZenZoneService)],c.SheetsThreadCommentPopupService);const k={type:s.CommandType.OPERATION,id:"sheets.operation.show-comment-modal",handler(i){var I;const t=i.get(p.SheetsSelectionsService),n=i.get(s.IUniverInstanceService),e=i.get(c.SheetsThreadCommentPopupService),r=i.get(g.ThreadCommentPanelService),o=(I=t.getCurrentLastSelection())==null?void 0:I.primary,a=i.get($.SheetsThreadCommentModel);if(!o)return!1;const u=p.getSheetCommandTarget(n);if(!u)return!1;const{workbook:d,worksheet:m,unitId:l,subUnitId:h}=u,v={workbook:d,worksheet:m,unitId:l,subUnitId:h,row:o.startRow,col:o.startColumn};e.showPopup(v);const C=a.getByLocation(l,h,o.startRow,o.startColumn);return C&&r.setActiveComment({unitId:l,subUnitId:h,commentId:C,trigger:"context-menu"}),!0}},Se="sheets-thread-comment.config",se={};var Ce=Object.defineProperty,_e=Object.getOwnPropertyDescriptor,fe=(i,t,n,e)=>{for(var r=e>1?void 0:e?_e(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&Ce(t,n,r),r},L=(i,t)=>(n,e)=>t(n,e,i);let W=class extends s.Disposable{constructor(i,t,n,e){super(),this._sheetInterceptorService=i,this._sheetsThreadCommentModel=t,this._univerInstanceService=n,this._renderManagerService=e,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(p.INTERCEPTOR_POINT.CELL_CONTENT,{effect:s.InterceptorEffectEnum.Style,handler:(i,t,n)=>{const{row:e,col:r,unitId:o,subUnitId:a}=t;return this._sheetsThreadCommentModel.showCommentMarker(o,a,e,r)?n({...i,markers:{...i==null?void 0:i.markers,tr:{color:"#FFBD37",size:6}}}):n(i)},priority:100}))}_initSkeletonChange(){const i=()=>{var r;const t=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!t)return;const n=t.getUnitId(),e=this._renderManagerService.getRenderById(n);(r=e==null?void 0:e.mainComponent)==null||r.makeForceDirty()};this.disposeWithMe(this._sheetsThreadCommentModel.commentUpdate$.pipe(H.debounceTime(16)).subscribe(()=>{i()}))}};W=fe([L(0,s.Inject(p.SheetInterceptorService)),L(1,s.Inject($.SheetsThreadCommentModel)),L(2,s.IUniverInstanceService),L(3,ne.IRenderManagerService)],W);var Ie=Object.defineProperty,ge=Object.getOwnPropertyDescriptor,Pe=(i,t,n,e)=>{for(var r=e>1?void 0:e?ge(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&Ie(t,n,r),r},Q=(i,t)=>(n,e)=>t(n,e,i);const Te=(i,t,n)=>{const e=V.singleReferenceToGrid(i),r=n.row-t.row,o=n.column-t.column,a={startColumn:e.column+o,startRow:e.row+r,endColumn:e.column+o,endRow:e.row+r};return V.serializeRange(a)};let x=class extends s.Disposable{constructor(t,n,e){super();N(this,"_copyInfo");this._sheetClipboardService=t,this._sheetsThreadCommentModel=n,this._threadCommentDataSourceService=e,this._initClipboardHook()}_initClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:J,onBeforeCopy:(t,n,e)=>{this._copyInfo={unitId:t,subUnitId:n,range:e}},onPasteCells:(t,n,e,r)=>{const{unitId:o,subUnitId:a,range:u}=n,d={row:u.rows[0],column:u.cols[0]};if(r.copyType===b.COPY_TYPE.CUT&&this._copyInfo){const{range:m,unitId:l,subUnitId:h}=this._copyInfo,v={row:m.startRow,column:m.startColumn};if(!(o===l&&a===h)){const C=[];s.Range.foreach(m,(w,S)=>{const E=this._sheetsThreadCommentModel.getAllByLocation(l,h,w,S);this._threadCommentDataSourceService.syncUpdateMutationToColla?E.forEach(P=>{C.push(P)}):E.forEach(({children:P,...j})=>{j.parentId||C.push(j)})});const I=[],y=[],A=[],B=[],te=w=>{I.unshift({id:f.DeleteCommentMutation.id,params:{unitId:l,subUnitId:h,commentId:w.id}}),A.push({id:f.AddCommentMutation.id,params:{unitId:o,subUnitId:a,comment:{...w,ref:Te(w.ref,v,d),unitId:o,subUnitId:a},sync:!0}}),y.push({id:f.AddCommentMutation.id,params:{unitId:l,subUnitId:h,comment:w,sync:!0}}),B.unshift({id:f.DeleteCommentMutation.id,params:{unitId:o,subUnitId:a,commentId:w.id}})};return C.forEach(w=>{te(w)}),{redos:[...I,...A],undos:[...B,...y]}}}return{redos:[],undos:[]}}}))}};x=Pe([Q(0,s.Inject(b.ISheetClipboardService)),Q(1,s.Inject($.SheetsThreadCommentModel)),Q(2,f.IThreadCommentDataSourceService)],x);var be=Object.defineProperty,Me=Object.getOwnPropertyDescriptor,ye=(i,t,n,e)=>{for(var r=e>1?void 0:e?Me(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&be(t,n,r),r},F=(i,t)=>(n,e)=>t(n,e,i);let q=class extends s.Disposable{constructor(i,t,n,e){super(),this._hoverManagerService=i,this._sheetsThreadCommentPopupService=t,this._sheetsThreadCommentModel=n,this._sheetPermissionCheckController=e,this._initHoverEvent()}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(H.debounceTime(100)).subscribe(i=>{const t=this._sheetsThreadCommentPopupService.activePopup;if(i&&(t&&t.temp||!t)){const{location:n}=i,{unitId:e,subUnitId:r,row:o,col:a}=n,u=this._sheetsThreadCommentModel.getByLocation(e,r,o,a);if(u){if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[p.WorkbookCommentPermission],worksheetTypes:[p.WorksheetViewPermission],rangeTypes:[p.RangeProtectionPermissionViewPoint]},[{startRow:o,startColumn:a,endRow:o,endColumn:a}]))return;const m=this._sheetsThreadCommentModel.getComment(e,r,u);m&&!m.resolved&&this._sheetsThreadCommentPopupService.showPopup({unitId:e,subUnitId:r,row:o,col:a,commentId:u,temp:!0})}else t&&this._sheetsThreadCommentPopupService.hidePopup()}}))}};q=ye([F(0,s.Inject(b.HoverManagerService)),F(1,s.Inject(c.SheetsThreadCommentPopupService)),F(2,s.Inject($.SheetsThreadCommentModel)),F(3,s.Inject(p.SheetPermissionCheckController))],q);var we=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,Oe=(i,t,n,e)=>{for(var r=e>1?void 0:e?Ee(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&we(t,n,r),r},R=(i,t)=>(n,e)=>t(n,e,i);let G=class extends s.Disposable{constructor(t,n,e,r,o,a,u,d,m,l){super();N(this,"_isSwitchToCommenting",!1);N(this,"_selectionShapeInfo",null);this._commandService=t,this._sheetsThreadCommentPopupService=n,this._sheetsThreadCommentModel=e,this._threadCommentPanelService=r,this._univerInstanceService=o,this._sheetPermissionCheckController=a,this._markSelectionService=u,this._sheetSelectionService=d,this._editorBridgeService=m,this._renderManagerService=l,this._initCommandListener(),this._initPanelListener(),this._initMarkSelection(),this._initSelectionUpdateListener(),this._initEditorBridge()}_handleSelectionChange(t,n,e){var v,C,I;const r=(v=t[0])==null?void 0:v.range,o=this._renderManagerService.getRenderById(n),a=(C=o==null?void 0:o.with(b.SheetSkeletonManagerService).getWorksheetSkeleton(e))==null?void 0:C.skeleton;if(!a||!r)return;const u=a.getCellWithCoordByIndex(r.startRow,r.startColumn);if((((I=r.rangeType)!=null?I:s.RANGE_TYPE.NORMAL)!==s.RANGE_TYPE.NORMAL||r.endColumn-r.startColumn>0||r.endRow-r.startRow>0)&&!((u.isMerged||u.isMergedMainCell)&&s.Rectangle.equals(u.mergeInfo,r))){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(g.SetActiveCommentOperation.id);return}const m=u.actualRow,l=u.actualColumn;if(!this._sheetsThreadCommentModel.showCommentMarker(n,e,m,l)){this._threadCommentPanelService.activeCommentId&&this._commandService.executeCommand(g.SetActiveCommentOperation.id);return}const h=this._sheetsThreadCommentModel.getByLocation(n,e,m,l);h&&this._commandService.executeCommand(g.SetActiveCommentOperation.id,{unitId:n,subUnitId:e,commentId:h})}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(t=>{if(this._isSwitchToCommenting)return;const n=this._sheetSelectionService.currentSelectionParam;n&&this._handleSelectionChange(t,n.unitId,n.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(t=>{t.visible&&this._sheetsThreadCommentPopupService.hidePopup()}))}_initCommandListener(){this._commandService.onCommandExecuted(t=>{if(t.id===f.DeleteCommentMutation.id){const n=t.params,e=this._sheetsThreadCommentPopupService.activePopup;if(!e)return;const{unitId:r,subUnitId:o,commentId:a}=e;n.unitId===r&&n.subUnitId===o&&n.commentId===a&&this._sheetsThreadCommentPopupService.hidePopup()}})}_initPanelListener(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.subscribe(async t=>{var n;if(t){const{unitId:e,subUnitId:r,commentId:o,trigger:a}=t,u=this._sheetsThreadCommentModel.getComment(e,r,o);if(!u||u.resolved)return;const d=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!d||d.getUnitId()!==e)return;this._isSwitchToCommenting=!0,((n=d.getActiveSheet())==null?void 0:n.getSheetId())!==r&&await this._commandService.executeCommand(p.SetWorksheetActiveOperation.id,{unitId:e,subUnitId:r}),this._isSwitchToCommenting=!1;const h=V.singleReferenceToGrid(u.ref),{row:v,column:C}=h;if(!this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[p.WorkbookCommentPermission],worksheetTypes:[p.WorksheetViewPermission],rangeTypes:[p.RangeProtectionPermissionViewPoint]},[{startRow:v,startColumn:C,endRow:v,endColumn:C}]))return;const y=1;if(await this._commandService.executeCommand(b.ScrollToRangeOperation.id,{range:{startRow:Math.max(h.row-y,0),endRow:h.row+y,startColumn:Math.max(h.column-y,0),endColumn:h.column+y}}),this._editorBridgeService.isVisible().visible)return;this._sheetsThreadCommentPopupService.showPopup({unitId:e,subUnitId:r,row:h.row,col:h.column,commentId:u.id,trigger:a})}else this._sheetsThreadCommentPopupService.hidePopup()}))}_initMarkSelection(){this.disposeWithMe(this._threadCommentPanelService.activeCommentId$.pipe(H.debounceTime(100)).subscribe(t=>{var v,C;if(!t){this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);return}const{unitId:n,subUnitId:e,commentId:r}=t;this._selectionShapeInfo&&(this._markSelectionService.removeShape(this._selectionShapeInfo.shapeId),this._selectionShapeInfo=null);const o=this._sheetsThreadCommentModel.getComment(n,e,r);if(!o)return;const a=V.singleReferenceToGrid(o.ref),{row:u,column:d}=a;if(Number.isNaN(u)||Number.isNaN(d))return null;const m=(v=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET))==null?void 0:v.getSheetBySheetId(e),l=(C=m==null?void 0:m.getMergedCell(u,d))!=null?C:{startColumn:d,endColumn:d,startRow:u,endRow:u},h=this._markSelectionService.addShape({range:l,style:{fill:"rgb(255, 189, 55, 0.35)",strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null},[],-1);h&&(this._selectionShapeInfo={...t,shapeId:h})}))}};G=Oe([R(0,s.ICommandService),R(1,s.Inject(c.SheetsThreadCommentPopupService)),R(2,s.Inject($.SheetsThreadCommentModel)),R(3,s.Inject(g.ThreadCommentPanelService)),R(4,s.IUniverInstanceService),R(5,s.Inject(p.SheetPermissionCheckController)),R(6,b.IMarkSelectionService),R(7,s.Inject(p.SheetsSelectionsService)),R(8,b.IEditorBridgeService),R(9,ne.IRenderManagerService)],G);var Ue=Object.defineProperty,Re=Object.getOwnPropertyDescriptor,je=(i,t,n,e)=>{for(var r=e>1?void 0:e?Re(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&Ue(t,n,r),r},Z=(i,t)=>(n,e)=>t(n,e,i);let z=class extends s.Disposable{constructor(i,t,n,e){super(),this._sheetInterceptorService=i,this._univerInstanceService=t,this._threadCommentModel=n,this._threadCommentDataSourceService=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===p.RemoveSheetCommand.id){const n=i.params,e=n.unitId?this._univerInstanceService.getUnit(n.unitId):this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!e)return{redos:[],undos:[]};const r=e.getUnitId(),o=n.subUnitId||((t=e.getActiveSheet())==null?void 0:t.getSheetId());if(!o)return{redos:[],undos:[]};const a=this._threadCommentModel.ensureMap(r,o),u=Array.from(a.values()).filter(v=>!v.parentId),d=u.map(v=>v.id),m=this._threadCommentDataSourceService.syncUpdateMutationToColla,l=d.map(v=>({id:f.DeleteCommentMutation.id,params:{unitId:r,subUnitId:o,commentId:v}})),h=u.map(({children:v,...C})=>({id:f.AddCommentMutation.id,params:{unitId:r,subUnitId:o,comment:{...C,children:m?v:void 0},sync:!m}}));return{redos:l,undos:h}}return{redos:[],undos:[]}}}))}};z=je([Z(0,s.Inject(p.SheetInterceptorService)),Z(1,s.IUniverInstanceService),Z(2,s.Inject(f.ThreadCommentModel)),Z(3,f.IThreadCommentDataSourceService)],z);var M=function(){return M=Object.assign||function(i){for(var t,n=1,e=arguments.length;n<e;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(i[r]=t[r])}return i},M.apply(this,arguments)},De=function(i,t){var n={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&t.indexOf(e)<0&&(n[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,e=Object.getOwnPropertySymbols(i);r<e.length;r++)t.indexOf(e[r])<0&&Object.prototype.propertyIsEnumerable.call(i,e[r])&&(n[e[r]]=i[e[r]]);return n},ae=U.forwardRef(function(i,t){var n=i.icon,e=i.id,r=i.className,o=i.extend,a=De(i,["icon","id","className","extend"]),u="univerjs-icon univerjs-icon-".concat(e," ").concat(r||"").trim(),d=U.useRef("_".concat(Ae()));return ce(n,"".concat(e),{defIds:n.defIds,idSuffix:d.current},M({ref:t,className:u},a),o)});function ce(i,t,n,e,r){return U.createElement(i.tag,M(M({key:t},Ne(i,n,r)),e),($e(i,n).children||[]).map(function(o,a){return ce(o,"".concat(t,"-").concat(i.tag,"-").concat(a),n,void 0,r)}))}function Ne(i,t,n){var e=M({},i.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var r=t.defIds;return!r||r.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+t.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],u=o[1];typeof u=="string"&&(e[a]=u.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),e}function $e(i,t){var n,e=t.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?M(M({},i),{children:i.children.map(function(r){return typeof r.attrs.id=="string"&&e&&e.indexOf(r.attrs.id)>-1?M(M({},r),{attrs:M(M({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):i}function Ae(){return Math.random().toString(36).substring(2,8)}ae.displayName="UniverIcon";var Ve={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521C5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345ZM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521C8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345ZM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521C11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.83725 6.78345C6.22188 6.78345 6.53368 7.10742 6.53368 7.50706V8.41159C6.53368 8.81123 6.22188 9.13521 5.83725 9.13521 5.45263 9.13521 5.14082 8.81123 5.14082 8.41159V7.50706C5.14082 7.10742 5.45263 6.78345 5.83725 6.78345zM8.73904 6.78345C9.12366 6.78345 9.43546 7.10742 9.43546 7.50706V8.41159C9.43546 8.81123 9.12366 9.13521 8.73904 9.13521 8.35441 9.13521 8.04261 8.81123 8.04261 8.41159V7.50706C8.04261 7.10742 8.35441 6.78345 8.73904 6.78345zM11.6408 6.78345C12.0254 6.78345 12.3372 7.10742 12.3372 7.50706V8.41159C12.3372 8.81123 12.0254 9.13521 11.6408 9.13521 11.2562 9.13521 10.9444 8.81123 10.9444 8.41159V7.50706C10.9444 7.10742 11.2562 6.78345 11.6408 6.78345z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.84351 3.41861C1.84351 3.01861 2.15531 2.69434 2.53993 2.69434H14.9381C15.3228 2.69434 15.6346 3.01861 15.6346 3.41861V12.4611C15.6346 12.8612 15.3228 13.1854 14.9381 13.1854H8.82117L6.06643 14.6179C5.85054 14.7301 5.59416 14.7181 5.38884 14.5862C5.18352 14.4542 5.05855 14.2211 5.05855 13.9701V13.1854H2.53993C2.15531 13.1854 1.84351 12.8612 1.84351 12.4611L1.84351 3.41861ZM6.45141 12.7982L8.34531 12.0135C8.44201 11.9632 8.54864 11.9371 8.65676 11.9371H14.2417C14.3522 11.9371 14.4417 11.8475 14.4417 11.7371V4.14271C14.4417 4.03225 14.3522 3.94271 14.2417 3.94271H3.23636C3.12591 3.94271 3.03636 4.03225 3.03636 4.14271L3.03636 11.7371C3.03636 11.8475 3.12591 11.9371 3.23636 11.9371L5.75498 11.9371C6.1396 11.9371 6.45141 12.0611 6.45141 12.4611V12.7982Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ue=U.forwardRef(function(i,t){return U.createElement(ae,Object.assign({},i,{id:"comment-single",ref:t,icon:Ve}))});ue.displayName="CommentSingle";const ke=()=>{const i=s.useDependency(s.IUniverInstanceService),t=s.useDependency(c.SheetsThreadCommentPopupService),n=_.useObservable(t.activePopup$),e=s.useDependency($.SheetsThreadCommentModel);if(_.useObservable(e.commentUpdate$),!n)return null;const{row:r,col:o,unitId:a,subUnitId:u,trigger:d}=n,m=e.getByLocation(a,u,r,o),l=`${s.Tools.chatAtABC(o)}${r+1}`,h=()=>{t.hidePopup()},v=C=>{var I,y,A;return(A=(y=(I=i.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET))==null?void 0:I.getSheetBySheetId(C))==null?void 0:y.getName())!=null?A:""};return re.jsx(g.ThreadCommentTree,{onClick:()=>{t.persistPopup()},prefix:"cell",id:m,unitId:a,subUnitId:u,type:s.UniverInstanceType.UNIVER_SHEET,refStr:l,onClose:h,getSubUnitName:v,autoFocus:d==="context-menu"})},He=()=>{var w;const i=s.useDependency(b.IMarkSelectionService),t=s.useDependency(s.IUniverInstanceService),n=s.useDependency(c.SheetsThreadCommentPopupService),e=t.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),r=e.getUnitId(),o=s.useDependency(s.ICommandService),a=U.useMemo(()=>e.activeSheet$.pipe(H.map(S=>S==null?void 0:S.getSheetId())),[e.activeSheet$]),u=_.useObservable(a,(w=e.getActiveSheet())==null?void 0:w.getSheetId()),d=U.useRef(null),m=s.useDependency(g.ThreadCommentPanelService),l=_.useObservable(m.activeCommentId$),h=_.useObservable(m.panelVisible$,m.panelVisible),v=U.useCallback(S=>{const E=e.getSheets(),P={};E.forEach((O,T)=>{P[O.getSheetId()]=T});const j=O=>O.map(T=>{var he;const D=V.singleReferenceToGrid(T.ref),Ye=[(he=P[T.subUnitId])!=null?he:0,D.row,D.column];return{...T,p:Ye}}).sort((T,D)=>T.p[0]===D.p[0]?T.p[1]===D.p[1]?T.p[2]-D.p[2]:T.p[1]-D.p[1]:T.p[0]-D.p[0]);return[...j(S.filter(O=>!O.resolved)),...j(S.filter(O=>O.resolved))]},[e]),C=U.useCallback(S=>{var E;if(S.unitId===r&&S.subUnitId===u&&!S.resolved){const{row:P,column:j}=V.singleReferenceToGrid(S.ref),O=e.getSheetBySheetId(S.subUnitId),T=(E=O==null?void 0:O.getMergedCell(P,j))!=null?E:{startColumn:j,endColumn:j,startRow:P,endRow:P};if(!Number.isNaN(P)&&!Number.isNaN(j))return i.addShape({range:T,style:{fill:"rgb(255, 189, 55, 0.35)",strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null})}return null},[i,u,r]),I=S=>{var E,P;return(P=(E=e.getSheetBySheetId(S))==null?void 0:E.getName())!=null?P:""},y=()=>{o.executeCommand(k.id)},A=S=>{l&&l.unitId===S.unitId&&l.subUnitId===S.subUnitId&&l.commentId===S.id||(d.current&&(i.removeShape(d.current),d.current=null),d.current=C(S))},B=()=>{d.current&&(i.removeShape(d.current),d.current=null)},te=(S,E)=>{E&&n.hidePopup()};return U.useEffect(()=>{!h&&d.current&&i.removeShape(d.current)},[i,h]),re.jsx(g.ThreadCommentPanel,{unitId:r,subUnitId$:a,type:s.UniverInstanceType.UNIVER_SHEET,onAdd:y,getSubUnitName:I,onResolve:te,sortComments:v,onItemEnter:A,onItemLeave:B,onDeleteComment:()=>(B(),!0)})},Be=i=>({id:k.id,type:_.MenuItemType.BUTTON,icon:Y,title:"sheetThreadComment.menu.addComment",hidden$:_.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_SHEET),disabled$:b.getCurrentRangeDisable$(i,{workbookTypes:[p.WorkbookCommentPermission],worksheetTypes:[p.WorksheetViewPermission],rangeTypes:[p.RangeProtectionPermissionViewPoint]})}),Le=i=>({id:g.ToggleSheetCommentPanelOperation.id,type:_.MenuItemType.BUTTON,icon:Y,tooltip:"sheetThreadComment.menu.commentManagement",disabled$:b.getCurrentRangeDisable$(i,{workbookTypes:[p.WorkbookCommentPermission],worksheetTypes:[p.WorksheetViewPermission],rangeTypes:[p.RangeProtectionPermissionViewPoint]}),hidden$:_.getMenuHiddenObservable(i,s.UniverInstanceType.UNIVER_SHEET)}),We={id:k.id,binding:_.KeyCode.M|_.MetaKeys.CTRL_COMMAND|_.MetaKeys.ALT,preconditions:b.whenSheetEditorFocused},xe={[_.RibbonStartGroup.OTHERS]:{[g.ToggleSheetCommentPanelOperation.id]:{order:1,menuItemFactory:Le}},[_.ContextMenuPosition.MAIN_AREA]:{[_.ContextMenuGroup.OTHERS]:{[k.id]:{order:0,menuItemFactory:Be}}}};var Fe=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Ge=(i,t,n,e)=>{for(var r=e>1?void 0:e?qe(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&Fe(t,n,r),r},X=(i,t)=>(n,e)=>t(n,e,i);let K=class extends s.Disposable{constructor(i,t,n){super(),this._menuManagerService=i,this._componentManager=t,this._shortcutService=n,this._initMenu(),this._initShortcut(),this._initComponent()}_initShortcut(){this._shortcutService.registerShortcut(We)}_initMenu(){this._menuManagerService.mergeMenu(xe)}_initComponent(){[[ie,ke],[g.THREAD_COMMENT_PANEL,He],[Y,ue]].forEach(([i,t])=>{this._componentManager.register(i,t)})}};K=Ge([X(0,_.IMenuManagerService),X(1,s.Inject(_.ComponentManager)),X(2,_.IShortcutService)],K);var de=Object.defineProperty,Ze=Object.getOwnPropertyDescriptor,ze=(i,t,n)=>t in i?de(i,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[t]=n,Ke=(i,t,n,e)=>{for(var r=e>1?void 0:e?Ze(t,n):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(e?a(t,n,r):a(r))||r);return e&&r&&de(t,n,r),r},ee=(i,t)=>(n,e)=>t(n,e,i),me=(i,t,n)=>ze(i,typeof t!="symbol"?t+"":t,n);c.UniverSheetsThreadCommentUIPlugin=class extends s.Plugin{constructor(t=se,n,e,r){super(),this._config=t,this._injector=n,this._commandService=e,this._configService=r;const{menu:o,...a}=s.merge({},se,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Se,a)}onStarting(){[[K],[W],[x],[q],[z],[G],[c.SheetsThreadCommentPopupService]].forEach(t=>{this._injector.add(t)}),[k].forEach(t=>{this._commandService.registerCommand(t)}),this._injector.get(K)}onReady(){this._injector.get(W),this._injector.get(z)}onRendered(){this._injector.get(x),this._injector.get(q),this._injector.get(G)}},me(c.UniverSheetsThreadCommentUIPlugin,"pluginName",J),me(c.UniverSheetsThreadCommentUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),c.UniverSheetsThreadCommentUIPlugin=Ke([s.DependentOn(g.UniverThreadCommentUIPlugin,$.UniverSheetsThreadCommentPlugin),ee(1,s.Inject(s.Injector)),ee(2,s.Inject(s.ICommandService)),ee(3,s.IConfigService)],c.UniverSheetsThreadCommentUIPlugin),Object.defineProperty(c,"UniverThreadCommentUIPlugin",{enumerable:!0,get:()=>g.UniverThreadCommentUIPlugin}),Object.defineProperty(c,"AddCommentCommand",{enumerable:!0,get:()=>f.AddCommentCommand}),Object.defineProperty(c,"DeleteCommentCommand",{enumerable:!0,get:()=>f.DeleteCommentCommand}),Object.defineProperty(c,"DeleteCommentTreeCommand",{enumerable:!0,get:()=>f.DeleteCommentTreeCommand}),Object.defineProperty(c,"IThreadCommentDataSourceService",{enumerable:!0,get:()=>f.IThreadCommentDataSourceService}),Object.defineProperty(c,"ResolveCommentCommand",{enumerable:!0,get:()=>f.ResolveCommentCommand}),Object.defineProperty(c,"UpdateCommentCommand",{enumerable:!0,get:()=>f.UpdateCommentCommand}),c.SHEETS_THREAD_COMMENT=J,c.ShowAddSheetCommentModalOperation=k,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
38
22
|
|
|
39
23
|
|
|
40
24
|
// index
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/preset-sheets-thread-comment",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-alpha.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -57,15 +57,15 @@
|
|
|
57
57
|
"rxjs": ">=7.0.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@univerjs/sheets-thread-comment": "0.
|
|
61
|
-
"@univerjs/sheets-thread-comment-ui": "0.
|
|
62
|
-
"@univerjs/thread-comment": "0.
|
|
63
|
-
"@univerjs/thread-comment-ui": "0.
|
|
60
|
+
"@univerjs/sheets-thread-comment": "0.6.0-alpha.0",
|
|
61
|
+
"@univerjs/sheets-thread-comment-ui": "0.6.0-alpha.0",
|
|
62
|
+
"@univerjs/thread-comment": "0.6.0-alpha.0",
|
|
63
|
+
"@univerjs/thread-comment-ui": "0.6.0-alpha.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@univerjs/core": "0.
|
|
66
|
+
"@univerjs/core": "0.6.0-alpha.0",
|
|
67
67
|
"typescript": "^5.7.2",
|
|
68
|
-
"@univerjs-infra/shared": "0.
|
|
68
|
+
"@univerjs-infra/shared": "0.6.0-alpha.0"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"prebuild:preset": "tsx prepare.ts",
|