@univerjs/sheets-formula-ui 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +368 -367
- package/lib/types/facade/f-univer.d.ts +19 -10
- package/lib/types/services/range-selector.service.d.ts +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +13 -13
package/lib/cjs/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
${Se.formulaSearchFunctionItem}
|
|
9
9
|
${Se.formulaSearchFunctionItemActive}
|
|
10
10
|
`:Se.formulaSearchFunctionItem,onMouseEnter:()=>N(O),onMouseLeave:$,onMouseMove:P,onClick:()=>{x(y.name),s&&s.focus()},children:[v.jsxs("span",{className:Se.formulaSearchFunctionItemName,children:[v.jsx("span",{className:Se.formulaSearchFunctionItemNameLight,children:y.name.substring(0,p.length)}),v.jsx("span",{children:y.name.slice(p.length)})]}),v.jsx("span",{className:Se.formulaSearchFunctionItemDesc,children:y.desc})]},y.name))})})}const Mo=e=>e.startsWith(F.operatorToken.EQUALS)?e.slice(1):"",Tt=()=>{};function Yt(e){var vt,Ct;const{errorText:t,initValue:n,unitId:o,subUnitId:r,isFocus:s=!0,isSupportAcrossSheet:i=!1,onFocus:c=Tt,onBlur:d=Tt,onChange:h,onVerify:f,actions:p,className:u,editorId:g,moveCursor:m=!0,onFormulaSelectingChange:T,keyboradEventConfig:C,onMoveInEditor:R,resetSelectionOnBlur:I=!0,autoScrollbar:E=!0,isSingle:_=!0,disableSelectionOnClick:x=!1,disableContextMenu:N,style:$}=e,L=a.useDependency(z.IEditorService),P=S.useRef(null),y=a.useEvent(h);p&&(p.handleOutClick=(X,J)=>{P.current&&!P.current.contains(X.target)&&J()});const O=a.useEvent(T),D=S.useRef(null),M=S.useRef(void 0),b=M.current,[A,k]=S.useState(s),H=S.useRef(null),W=S.useMemo(()=>g!=null?g:l.createInternalEditorID(`${w.EMBEDDING_FORMULA_EDITOR}-${l.generateRandomId(4)}`),[]),ee=S.useMemo(()=>t!==void 0,[t]),oe=a.useDependency(l.IUniverInstanceService),q=oe.getUnit(W);a.useObservable(q==null?void 0:q.change$);const xe=Qn(),U=l.BuildTextUtils.transform.getPlainText((Ct=(vt=q==null?void 0:q.getBody())==null?void 0:vt.dataStream)!=null?Ct:""),Z=be(U),se=S.useMemo(()=>Mo(U),[U]),ie=S.useMemo(()=>xe(se),[se,xe]),{isSelecting:ne,isSelectingRef:ce}=Jn({unitId:o,subUnitId:r,editorId:W,isFocus:A,disableOnClick:x}),he=S.useRef(""),Ne=a.useDependency(V.IRenderManagerService).getRenderById(W),Y=Ne==null?void 0:Ne.with(z.DocSelectionRenderService),ae=Y==null?void 0:Y.isFocusing,Re=S.useMemo(()=>oe.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_DOC),[oe]),me=a.useObservable(Re),ge=(me==null?void 0:me.getUnitId())===W,le=S.useRef([]),Ue=ne;a.useUpdateEffect(()=>{y(U)},[U,y]);const nt=qt("="),pt=to(o,r),Fe=a.useEvent((X,J=!0,ue,de)=>{if(!M.current)return;he.current=X;const Ae=xe(X[0]==="="?X.slice(1):""),pe=nt(M.current,Ae,J,de);if(le.current=pe,ue){const We=de!=null?de:b==null?void 0:b.getSelectionRanges();if((We==null?void 0:We.length)!==1)return;const nn=We[0].startOffset-1,on=dt(Ae,nn,!1),It=kt(Ae,on);if(It>=0){const Rt=pe.splice(It,1)[0];Rt&&pe.push(Rt)}pt(A?pe:[],M.current)}});S.useEffect(()=>{A&&Fe(U,!1,!0)},[A]),S.useEffect(()=>{if(A){if(he.current===U)return;Fe(U,!1,!0)}},[U]),ho(A,f,U);const Me=Yn(b),St=io(A,o,r);S.useEffect(()=>{O(ne)},[O,ne]),z.useKeyboardEvent(A,C,b),S.useLayoutEffect(()=>{let X;if(H.current){X=L.register({autofocus:!0,editorUnitId:W,initialSnapshot:{id:W,body:{dataStream:`${n}\r
|
|
11
|
-
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},H.current);const J=L.getEditor(W);M.current=J,Fe(n,!1,!0)}return()=>{X==null||X.dispose()}},[]),S.useLayoutEffect(()=>{s?(k(s),Me()):(I&&(b==null||b.blur(),St()),k(s))},[s,b,Me,St,I]);const{checkScrollBar:Jt}=z.useResize(b,_,E);so(A,!!(ne&&ge),o,N),ro(A&&m,Ue,b,R);const Qt=a.useEvent((X,J,ue)=>{if(!ae)return;const de=J!==-1?[{startOffset:J+1,endOffset:J+1,collapsed:!0}]:void 0;Fe(`=${X}`,!0,ue,de),ue&&(Me(),J!==-1&&setTimeout(()=>{const Ae={startOffset:J+1,endOffset:J+1},pe=b==null?void 0:b.render.with(z.DocBackScrollRenderController);pe==null||pe.scrollToRange({...Ae,collapsed:!0})},50),Jt())});uo(A&&!!(ne&&ge),A,ce,o,r,le,i,!!Ue,b,Qt),fo(A&&!!(ne&&ge),o,i,k,d,()=>{Fe(Z.current,!1,!0)});const en=X=>{if(X){const J=b==null?void 0:b.getSelectionRanges();if(J&&J.length===1){const ue=J[0];if(ue.collapsed){const de=X.offset;setTimeout(()=>{b==null||b.setSelectionRanges([{startOffset:ue.startOffset-de,endOffset:ue.endOffset-de}])},30)}}Me(),Fe(`=${X.text}`)}},tn=()=>{k(!0),c(),Me()};return v.jsxs("div",{style:$,className:te.clsx(Oe.sheetEmbeddingFormulaEditor,u),children:[v.jsx("div",{className:te.clsx(Oe.sheetEmbeddingFormulaEditorWrap,{[Oe.sheetEmbeddingFormulaEditorActive]:A,[Oe.sheetEmbeddingFormulaEditorError]:ee}),ref:P,children:v.jsx("div",{className:Oe.sheetEmbeddingFormulaEditorText,ref:H,onMouseUp:tn})}),t!==void 0?v.jsx("div",{className:Oe.sheetEmbeddingFormulaEditorErrorWrap,children:t}):null,b?v.jsx(qn,{editor:b,isFocus:A,formulaText:U,onClose:()=>Me()}):null,b?v.jsx(No,{isFocus:A,sequenceNodes:ie,onSelect:en,ref:D,editor:b}):null]})}function Do(e,t,n,o){const r=a.useDependency(F.LexerTreeBuilder),s=qt(""),i=a.useObservable(e==null?void 0:e.getDocumentDataModel().change$),[c,d]=S.useState([]),h=a.useDependency(w.IMarkSelectionService),f=S.useRef(""),p=a.useDependency(l.IUniverInstanceService);return S.useEffect(()=>{if(!e)return;const u=e.getDocumentDataModel().getPlainText();if(f.current===u)return;f.current=u;const g=r.sequenceNodesBuilder(u);d(g!=null?g:[])},[i,e,r]),S.useEffect(()=>{var m,T;if(!e)return;if(!t){const C=e.getDocumentData();e.setDocumentData({...C,body:{...C.body,dataStream:(T=(m=C.body)==null?void 0:m.dataStream)!=null?T:"",textRuns:[]}});return}const u=s(e,c,!1),g=new l.DisposableCollection;return u.forEach(C=>{const R=F.deserializeRangeWithSheet(C.token),I=p.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),E=I==null?void 0:I.getActiveSheet();if(!R.sheetName&&o!==(E==null?void 0:E.getSheetId())||R.sheetName&&(E==null?void 0:E.getName())!==R.sheetName)return;const _=new l.ColorKit(C.themeColor).toRgb(),x=h.addShape({range:R.range,style:{stroke:C.themeColor,fill:`rgba(${_.r}, ${_.g}, ${_.b}, 0.1)`,strokeDash:12},primary:null});x&&g.add(()=>h.removeShape(x))}),()=>{g.dispose()}},[e,t,s,h,c]),{sequenceNodes:c}}function Oo(e){const t=a.useDependency(j.SheetsSelectionsService),{supportAcrossSheet:n=!1,unitId:o,subUnitId:r,onChange:s}=e,c=a.useDependency(l.IUniverInstanceService).getUnit(o,l.UniverInstanceType.UNIVER_SHEET),d=a.useEvent(s),h=a.useEvent((f,p)=>{const u=c==null?void 0:c.getActiveSheet();if(!u||!n&&u.getSheetId()!==r||!(f!=null&&f.length))return;const g=f.map(m=>({range:m.range,unitId:o,sheetName:u.getSheetId()===r?"":u.getName()}));d(g,p)});S.useEffect(()=>{const f=new l.DisposableCollection;return f.add(t.selectionMoveStart$.subscribe(p=>{h(p,!0)})),f.add(t.selectionMoving$.subscribe(p=>{h(p,!1)})),f.add(t.selectionMoveEnd$.subscribe(p=>{h(p,!1)})),()=>{f.dispose()}},[h,t.selectionMoveEnd$,t.selectionMoveStart$,t.selectionMoving$])}const Ao="univer-sheet-range-selector-icon",Po="univer-sheet-range-selector-dialog",Lo="univer-sheet-range-selector-dialog-item",wo="univer-sheet-range-selector-dialog-item-delete",Ke={sheetRangeSelectorIcon:Ao,sheetRangeSelectorDialog:Po,sheetRangeSelectorDialogItem:Lo,sheetRangeSelectorDialogItemDelete:wo},bt=e=>!e.some(n=>{if(typeof n=="string"){if(n!==F.matchToken.COMMA)return!0}else if(n.nodeType!==F.sequenceNodeType.REFERENCE)return!0;return!1}),ko=e=>{if(e.endColumn<e.startColumn){const t=e.endColumn;e.endColumn=e.startColumn,e.startColumn=t}if(e.endRow<e.startRow){const t=e.endRow;e.endRow=e.startRow,e.startRow=t}return e};function $o(e){const{visible:t,initialValue:n,unitId:o,subUnitId:r,maxRangeCount:s=1/0,supportAcrossSheet:i,onConfirm:c,onClose:d,onShowBySelection:h}=e,f=a.useDependency(l.LocaleService),p=a.useDependency(F.LexerTreeBuilder),[u,g]=S.useState([]),[m,T]=S.useState(0),C=S.useRef(null);S.useEffect(()=>{if(t&&n.length){const _=n.map(x=>x.sheetName?F.serializeRangeWithSheet(x.sheetName,x.range):F.serializeRange(x.range));g(_),T(_.length-1)}else g([""]),T(0)},[t]);const R=(_,x)=>{const N=[...u];N[_]=x,g(N)},I=()=>{g([...u,""]),T(u.length)},E=_=>{u.splice(_,1),g([...u])};return Oo({unitId:o,subUnitId:r,supportAcrossSheet:i,onChange:(_,x)=>{if(!t&&h!=null&&h(_))return;const N=new Set(u),$=_.map(y=>y.sheetName?F.serializeRangeWithSheet(y.sheetName,y.range):F.serializeRange(y.range)),L=$.filter(y=>!N.has(y));if(!L.length)return;const P=[...u];if($.length>1){x||P.splice(m,1),P.push(...L);const y=P.slice(0,s);g(y),T(y.length-1),requestAnimationFrame(()=>{var O;(O=C.current)==null||O.scrollTo({top:C.current.scrollHeight})})}else{P.splice(m,1,...L);const y=P.slice(0,s);g(y),T(m+L.length-1)}}}),v.jsx(te.Dialog,{width:"328px",visible:t,title:f.t("rangeSelector.title"),draggable:!0,closeIcon:v.jsx(et,{}),footer:v.jsxs("footer",{children:[v.jsx(te.Button,{onClick:d,children:f.t("rangeSelector.cancel")}),v.jsx(te.Button,{style:{marginLeft:10},onClick:()=>{c(u.filter(_=>{const x=p.sequenceNodesBuilder(_);return x&&x.length===1&&typeof x[0]!="string"&&x[0].nodeType===F.sequenceNodeType.REFERENCE}).map(_=>F.deserializeRangeWithSheet(_)).map(_=>({..._,range:ko(_.range)})))},type:"primary",children:f.t("rangeSelector.confirm")})]}),onClose:d,children:v.jsxs("div",{ref:C,className:Ke.sheetRangeSelectorDialog,children:[u.map((_,x)=>v.jsxs("div",{className:Ke.sheetRangeSelectorDialogItem,children:[v.jsx(te.Input,{affixWrapperStyle:{width:"100%"},placeholder:f.t("rangeSelector.placeHolder"),onFocus:()=>T(x),value:_,onChange:N=>R(x,N),style:{borderColor:m===x?"rgb(var(--primary-color))":void 0}}),u.length>1&&v.jsx(Ht,{className:Ke.sheetRangeSelectorDialogItemDelete,onClick:()=>E(x)})]},x)),u.length<s&&v.jsx("div",{children:v.jsxs(te.Button,{type:"link",size:"small",onClick:I,children:[v.jsx(Wt,{}),v.jsx("span",{children:f.t("rangeSelector.addAnotherRange")})]})})]})})}function jo(e){return e.split(F.matchToken.COMMA).filter(t=>!!t).map(t=>F.deserializeRangeWithSheet(t))}function Ho(e){return e.map(t=>t.sheetName?F.serializeRangeWithSheet(t.sheetName,t.range):F.serializeRange(t.range)).join(F.matchToken.COMMA)}function mt(e){const[t,n]=S.useState(null),{onVerify:o,selectorRef:r,unitId:s,subUnitId:i,maxRangeCount:c,supportAcrossSheet:d,autoFocus:h,onChange:f,onRangeSelectorDialogVisibleChange:p,onClickOutside:u,onFocusChange:g,forceShowDialogWhenSelectionChanged:m,hideEditor:T,resetRange:C}=e,[R,I]=S.useState(h!=null?h:!1),[E,_]=S.useState(!1),[x,N]=S.useState([]),$=a.useDependency(l.LocaleService),L=a.useDependency(z.IEditorService),{sequenceNodes:P}=Do(t,R,s,i),y=be(P),O=a.useDependency(l.ICommandService),D=a.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),L.blur()}),M=a.useEvent(()=>{var b;D(),N(jo((b=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?b:"")),_(!0)});return S.useEffect(()=>{r&&(r.current={get editor(){return t},focus(){L.focus(t.getEditorId())},blur:D,verify:()=>bt(y.current),showDialog:b=>{D(),N(b),_(!0)},hideDialog:()=>{N([]),_(!1)},getValue:()=>{var b;return(b=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?b:""}})},[D,t,L,r,y]),S.useEffect(()=>{var b;o==null||o(bt(P),(b=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?b:"")},[P]),S.useEffect(()=>{p==null||p(E)},[E]),S.useEffect(()=>{if(E&&C)return()=>{const b={unitId:s,subUnitId:i,selections:C};O.executeCommand(j.SetSelectionsOperation.id,b)}},[E]),v.jsxs(v.Fragment,{children:[T?null:v.jsx(z.RichTextEditor,{isSingle:!0,...e,onFocusChange:(b,A)=>{I(b),g==null||g(b,A)},editorRef:n,onClickOutside:()=>{I(!1),D(),u==null||u()},icon:v.jsx(te.Tooltip,{title:$.t("rangeSelector.buttonTooltip"),placement:"bottom",children:v.jsx(Vt,{className:Ke.sheetRangeSelectorIcon,onClick:M})})}),v.jsx($o,{initialValue:x,unitId:s,subUnitId:i,visible:E,maxRangeCount:c,onConfirm:b=>{const A=Ho(b),k=l.RichTextBuilder.newEmptyData();k.body.dataStream=A,t==null||t.replaceText(A,!1),f==null||f(k,A),_(!1),N([]),requestAnimationFrame(()=>{D()})},onClose:()=>{_(!1),N([])},supportAcrossSheet:d,onShowBySelection:b=>R||m?(N(b),_(!0),!1):!0})]})}class gt{constructor(){K(this,"_currentSelector$",new B.BehaviorSubject(null));K(this,"currentSelector$",this._currentSelector$.asObservable())}showRangeSelectorDialog(t){const n=t.callback,o=new Promise(r=>{t.callback=(s,i)=>{r(s),n(s,i)}});return this._currentSelector$.next(t),o}}const Uo="sheets-formula-ui.base.config",xt={};function Wo(e){return e.getContextValue(l.FOCUSING_DOC)&&e.getContextValue(l.FOCUSING_UNIVER_EDITOR)}function zt(e,t=!1){return!t&&!(l.isFormulaString(e==null?void 0:e.f)||l.isFormulaId(e==null?void 0:e.si))?null:typeof(e==null?void 0:e.v)=="string"&&F.ERROR_TYPE_SET.has(e.v)?e.v:null}var Vo=Object.getOwnPropertyDescriptor,Bo=(e,t,n,o)=>{for(var r=o>1?void 0:o?Vo(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Pe=(e,t)=>(n,o)=>t(n,o,e);const rt="SHEET_FORMULA_ALERT",Ko={[F.ErrorType.DIV_BY_ZERO]:"divByZero",[F.ErrorType.NAME]:"name",[F.ErrorType.VALUE]:"value",[F.ErrorType.NUM]:"num",[F.ErrorType.NA]:"na",[F.ErrorType.CYCLE]:"cycle",[F.ErrorType.REF]:"ref",[F.ErrorType.SPILL]:"spill",[F.ErrorType.CALC]:"calc",[F.ErrorType.ERROR]:"error",[F.ErrorType.CONNECT]:"connect",[F.ErrorType.NULL]:"null"};let lt=class extends l.Disposable{constructor(e,t,n,o,r,s){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=o,this._formulaDataModel=r,this._zenZoneService=s,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(B.debounceTime(100)).subscribe(e=>{var t,n,o,r,s;if(e){const c=this._context.unit.getActiveSheet();if(!c)return;const d=c.getCell(e.location.row,e.location.col),h=(r=(o=(n=(t=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:t[e.location.unitId])==null?void 0:n[e.location.subUnitId])==null?void 0:o[e.location.row])==null?void 0:r[e.location.col];if(l.isICellData(d)){const f=zt(d,!!h);if(!f){this._hideAlert();return}const p=this._cellAlertManagerService.currentAlert.get(rt),u=(s=p==null?void 0:p.alert)==null?void 0:s.location;if(u&&u.row===e.location.row&&u.col===e.location.col&&u.subUnitId===e.location.subUnitId&&u.unitId===e.location.unitId)return;this._cellAlertManagerService.showAlert({type:w.CellAlertType.ERROR,title:this._localeService.t("formula.error.title"),message:this._localeService.t(`formula.error.${Ko[f]}`),location:e.location,width:200,height:74,key:rt});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(rt)}};lt=Bo([Pe(1,l.Inject(w.HoverManagerService)),Pe(2,l.Inject(w.CellAlertManagerService)),Pe(3,l.Inject(l.LocaleService)),Pe(4,l.Inject(F.FormulaDataModel)),Pe(5,a.IZenZoneService)],lt);var qo=Object.getOwnPropertyDescriptor,Yo=(e,t,n,o)=>{for(var r=o>1?void 0:o?qo(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Nt=(e,t)=>(n,o)=>t(n,o,e);let qe=class extends l.Disposable{constructor(e,t){super(),this._autoFillService=e,this._lexerTreeBuilder=t,this._registerAutoFill()}_registerAutoFill(){const e={type:w.DATA_TYPE.FORMULA,priority:1001,match:t=>l.isFormulaString(t==null?void 0:t.f)||l.isFormulaId(t==null?void 0:t.si),isContinue:(t,n)=>t.type===w.DATA_TYPE.FORMULA,applyFunctions:{[w.APPLY_TYPE.COPY]:(t,n,o,r)=>{const{data:s,index:i}=t;return this._fillCopyFormula(s,n,o,i,r)}}};this._autoFillService.registerRule(e)}_fillCopyFormula(e,t,n,o,r){var d,h;const s=Go(r),i=[],c=new Map;for(let f=1;f<=t;f++){const p=(f-1)%e.length,u=l.Tools.deepClone(e[p]);if(u){const g=((d=e[p])==null?void 0:d.f)||"",m=((h=e[p])==null?void 0:h.si)||"",T=l.isFormulaString(g);if(l.isFormulaId(m))u.si=m,u.f=null,u.v=null,u.p=null,u.t=null,i.push(u);else if(T){let R=c.get(p);if(R)u.si=R,u.f=null,u.v=null,u.p=null,u.t=null;else{R=l.Tools.generateRandomId(6),c.set(p,R);const{offsetX:I,offsetY:E}=zo(s,t,n),_=this._lexerTreeBuilder.moveFormulaRefOffset(g,I,E);u.si=R,u.f=_,u.v=null,u.p=null,u.t=null}i.push(u)}}}return i}};qe=Yo([Nt(0,w.IAutoFillService),Nt(1,l.Inject(F.LexerTreeBuilder))],qe);function zo(e,t,n){let o=0,r=0;switch(n){case l.Direction.UP:r=-e*t;break;case l.Direction.RIGHT:o=e;break;case l.Direction.DOWN:r=e;break;case l.Direction.LEFT:o=-e*t;break}return{offsetX:o,offsetY:r}}function Go(e){let t=0;for(const n in e)e[n].forEach(o=>{t+=o.data.length});return t}var Zo=Object.getOwnPropertyDescriptor,Xo=(e,t,n,o)=>{for(var r=o>1?void 0:o?Zo(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Le=(e,t)=>(n,o)=>t(n,o,e);const Jo="default-paste-formula";let Ye=class extends l.Disposable{constructor(e,t,n,o,r){super(),this._currentUniverSheet=e,this._lexerTreeBuilder=t,this._sheetClipboardService=n,this._injector=o,this._formulaDataModel=r,this._initialize()}_initialize(){this._registerClipboardHook()}_registerClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteFormulaHook())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteWithFormulaHook()))}_pasteFormulaHook(){return{id:w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA,priority:10,specialPasteInfo:{label:"specialPaste.formula"},onPasteCells:(e,t,n,o)=>this._onPasteCells(e,t,n,o,!0)}}_pasteWithFormulaHook(){return{id:Jo,priority:10,onPasteCells:(e,t,n,o)=>this._onPasteCells(e,t,n,o,!1)}}_onPasteCells(e,t,n,o,r){var u;if([w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH].includes(o.pasteType))return{undos:[],redos:[]};const i=this._currentUniverSheet.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),c=t.unitId||i.getUnitId(),d=t.subUnitId||((u=i.getActiveSheet())==null?void 0:u.getSheetId());if(!c||!d)return{undos:[],redos:[]};const h=t.range,f=n,p={copyType:o.copyType||w.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:o.pasteType};return this._injector.invoke(g=>Qo(c,d,h,f,g,p,this._lexerTreeBuilder,this._formulaDataModel,r,e))}};Ye=Xo([Le(0,l.IUniverInstanceService),Le(1,l.Inject(F.LexerTreeBuilder)),Le(2,w.ISheetClipboardService),Le(3,l.Inject(l.Injector)),Le(4,l.Inject(F.FormulaDataModel))],Ye);function Qo(e,t,n,o,r,s,i,c,d=!1,h){const f=[],p=[],u=er(e,t,n,o,s,i,c,h);if(!u.hasValue())return{undos:[],redos:[]};const g={unitId:e,subUnitId:t,cellValue:u.getData()};f.push({id:j.SetRangeValuesMutation.id,params:g});const m=j.SetRangeValuesUndoMutationFactory(r,g);return p.push({id:j.SetRangeValuesMutation.id,params:m}),{undos:p,redos:f}}function er(e,t,n,o,r,s,i,c){return c?r.pasteType===w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE?nr(e,t,n,o,i,c):r.pasteType===w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA?or(e,t,n,o,s,i,c):rr(e,t,n,o,r.copyType,s,i,c):tr(e,t,n,o,i)}function tr(e,t,n,o,r){const s=new l.ObjectMatrix,i=r.getSheetFormulaData(e,t);return o.forValue((c,d,h)=>{var g;const f=n.rows[c],p=n.cols[d],u={};l.isFormulaString(h.v)?(u.v=null,u.f=`${h.v}`,u.si=null,u.p=null,s.setValue(f,p,u)):(g=i==null?void 0:i[f])!=null&&g[p]&&(u.v=h.v,u.f=null,u.si=null,u.p=null,s.setValue(f,p,u))}),s}function nr(e,t,n,o,r,s){var h,f;const i=new l.ObjectMatrix,c=(f=(h=r.getArrayFormulaCellData())==null?void 0:h[s.unitId])==null?void 0:f[s.subUnitId],d=r.getSheetFormulaData(e,t);return o.forValue((p,u,g)=>{var E,_;const m=s.range.rows[p%s.range.rows.length],T=s.range.cols[u%s.range.cols.length],C=n.rows[p],R=n.cols[u],I={};if(l.isFormulaString(g.f)||l.isFormulaId(g.si))I.v=g.v,I.f=null,I.si=null,I.p=null,i.setValue(C,R,I);else if((E=c==null?void 0:c[m])!=null&&E[T]){const x=c[m][T];I.v=x.v,I.f=null,I.si=null,I.p=null,i.setValue(C,R,I)}else if((_=d==null?void 0:d[C])!=null&&_[R]){if(I.v=g.v,I.f=null,I.si=null,I.p=null,g.p){const x=Gt(g);x&&(I.v=x)}i.setValue(C,R,I)}}),i}function or(e,t,n,o,r,s,i){const c=new l.ObjectMatrix,d=new Map;return o.forValue((h,f,p)=>{const u=n.rows[h],g=n.cols[f],m={};if(l.isFormulaId(p.si)){if(i.unitId!==e||i.subUnitId!==t){const T=s.getFormulaStringByCell(i.range.rows[h%i.range.rows.length],i.range.cols[f%i.range.cols.length],i.subUnitId,i.unitId),C=n.cols[f]-i.range.cols[f%i.range.cols.length],R=n.rows[h]-i.range.rows[h%i.range.rows.length],I=r.moveFormulaRefOffset(T||"",C,R);m.si=null,m.f=I}else m.si=p.si,m.f=null;m.v=null,m.p=null,c.setValue(u,g,m)}else if(l.isFormulaString(p.f)){const T=`${h%i.range.rows.length}_${f%i.range.cols.length}`;let C=d.get(T);if(C)m.si=C,m.f=null;else{C=l.Tools.generateRandomId(6),d.set(T,C);const R=n.cols[f]-i.range.cols[f%i.range.cols.length],I=n.rows[h]-i.range.rows[h%i.range.rows.length],E=r.moveFormulaRefOffset(p.f||"",R,I);m.si=C,m.f=E}m.v=null,m.p=null,c.setValue(u,g,m)}else{if(m.v=p.v,m.f=null,m.si=null,m.p=null,p.p){const T=Gt(p);T&&(m.v=T)}c.setValue(u,g,m)}}),c}function rr(e,t,n,o,r,s,i,c){const d=new l.ObjectMatrix,h=new Map,f=i.getSheetFormulaData(e,t),p=[];return r===w.COPY_TYPE.CUT?o.forValue((u,g,m)=>{const T=n.rows[u],C=n.cols[g],R={};if(l.isFormulaId(m.si)){if(l.isFormulaString(m.f))p.push(m.si),R.f=m.f,R.si=m.si;else if(p.includes(m.si))R.f=null,R.si=m.si;else{const I=i.getFormulaStringByCell(c.range.rows[u%c.range.rows.length],c.range.cols[g%c.range.cols.length],c.subUnitId,c.unitId);R.f=I,R.si=null}R.v=null,R.p=null,d.setValue(T,C,R)}else l.isFormulaString(m.f)&&(R.f=m.f,R.si=null,R.v=null,R.p=null,d.setValue(T,C,R))}):o.forValue((u,g,m)=>{var I;const T=n.rows[u],C=n.cols[g],R={};if(l.isFormulaId(m.si)){if(c.unitId!==e||c.subUnitId!==t){const E=i.getFormulaStringByCell(c.range.rows[u%c.range.rows.length],c.range.cols[g%c.range.cols.length],c.subUnitId,c.unitId),_=n.cols[g]-c.range.cols[g%c.range.cols.length],x=n.rows[u]-c.range.rows[u%c.range.rows.length],N=s.moveFormulaRefOffset(E||"",_,x);R.si=null,R.f=N}else R.si=m.si,R.f=null;R.v=null,R.p=null,d.setValue(T,C,R)}else if(l.isFormulaString(m.f)){const E=`${u%c.range.rows.length}_${g%c.range.cols.length}`;let _=h.get(E);if(_)R.si=_,R.f=null;else{_=l.Tools.generateRandomId(6),h.set(E,_);const x=n.cols[g]-c.range.cols[g%c.range.cols.length],N=n.rows[u]-c.range.rows[u%c.range.rows.length],$=s.moveFormulaRefOffset(m.f||"",x,N);R.si=_,R.f=$}R.v=null,R.p=null,d.setValue(T,C,R)}else(I=f==null?void 0:f[T])!=null&&I[C]&&(R.v=m.v,R.f=null,R.si=null,R.p=m.p,d.setValue(T,C,R))}),p.length>0&&new l.ObjectMatrix(f).forValue((u,g,m)=>{if(!(c.range.rows.includes(u)&&c.range.cols.includes(g))&&!(n.rows.includes(u)&&n.cols.includes(g))&&p.includes(m==null?void 0:m.si)){const T=i.getFormulaStringByCell(u,g,c.subUnitId,c.unitId);d.setValue(u,g,{f:T,si:null,v:null,p:null})}}),d}function Gt(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return;const n=t.dataStream;return n.substring(n.length-2,n.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n}}var sr=Object.getOwnPropertyDescriptor,ir=(e,t,n,o)=>{for(var r=o>1?void 0:o?sr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Ee=(e,t)=>(n,o)=>t(n,o,e);let ze=class extends l.Disposable{constructor(t,n,o,r,s,i,c,d){super();K(this,"_previousShape");K(this,"_skeleton");this._context=t,this._sheetInterceptorService=n,this._formulaDataModel=o,this._themeService=r,this._renderManagerService=s,this._sheetSkeletonManagerService=i,this._commandService=c,this._logService=d,this._initSkeletonChangeListener(),this._initInterceptorEditorStart(),this._commandExecutedListener()}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(t=>{var n,o;if(t==null)this._logService.debug("[FormulaEditorShowController]: should not receive currentSkeleton$ as null!");else{const{skeleton:r}=t,s=(o=(n=this._skeleton)==null?void 0:n.worksheet)==null?void 0:o.getSheetId();if(this._changeRuntime(r),s!==r.worksheet.getSheetId())this._removeArrayFormulaRangeShape();else{const{unitId:i,sheetId:c}=t;this._updateArrayFormulaRangeShape(i,c)}}}))}_changeRuntime(t){this._skeleton=t}_initInterceptorEditorStart(){this.disposeWithMe(l.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(j.BEFORE_CELL_EDIT,{handler:(t,n,o)=>{var m,T,C,R;const{row:r,col:s,unitId:i,subUnitId:c,worksheet:d}=n,h=this._formulaDataModel.getArrayFormulaRange(),f=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return o(t);let p=null;const u=this._formulaDataModel.getFormulaStringByCell(r,s,c,i);if(u!==null&&(p={f:u}),t.v!=null&&t.v!==""&&((C=(T=(m=f[i])==null?void 0:m[c])==null?void 0:T[r])==null?void 0:C[s])==null)return p?{...t,...p}:o(t);const g=(R=h==null?void 0:h[i])==null?void 0:R[c];return g!=null&&(p=this._displayArrayFormulaRangeShape(g,r,s,i,c,d,p)),p?{...t,...p}:o(t)}})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{(t.id===F.SetFormulaCalculationResultMutation.id||t.id===F.SetArrayFormulaDataMutation.id&&n&&n.remove)&&this._removeArrayFormulaRangeShape()})),this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{j.SetWorksheetRowAutoHeightMutation.id===t.id&&requestIdleCallback(()=>{const n=t.params,{unitId:o,subUnitId:r,rowsAutoHeightInfo:s}=n;this._refreshArrayFormulaRangeShapeByRow(o,r,s)})}))}_displayArrayFormulaRangeShape(t,n,o,r,s,i,c){const d=this._formulaDataModel.getSheetFormulaData(r,s);return new l.ObjectMatrix(t).forValue((h,f,p)=>{var C;if(p==null)return!0;const{startRow:u,startColumn:g,endRow:m,endColumn:T}=p;if(h===n&&f===o)return this._createArrayFormulaRangeShape(p,r),!1;if(n>=u&&n<=m&&o>=g&&o<=T){const R=i.getCell(u,g);if((R==null?void 0:R.v)===F.ErrorType.SPILL)return;const I=(C=d==null?void 0:d[h])==null?void 0:C[f];return I==null||I.f==null?!0:(c==null&&(c={f:I.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(p,r),!1)}}),c}_createArrayFormulaRangeShape(t,n){const o=this._renderManagerService.getRenderById(n),r=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!o||!r)return;const{scene:s}=o;if(!s)return;const i=this._themeService.getCurrentTheme(),c={range:t,primary:null,style:{strokeWidth:1,stroke:i.hyacinth700,fill:new l.ColorKit(i.colorWhite).setAlpha(0).toString(),widgets:{}}},d=w.attachSelectionWithCoord(c,r),{rowHeaderWidth:h,columnHeaderHeight:f}=r,p=new w.SelectionControl(s,w.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:h,columnHeaderHeight:f});p.updateRangeBySelectionWithCoord(d),p.setEvent(!1),this._previousShape=p}_removeArrayFormulaRangeShape(){this._previousShape!=null&&(this._previousShape.dispose(),this._previousShape=null)}_refreshArrayFormulaRangeShape(t,n){if(this._previousShape){const{startRow:o,endRow:r,startColumn:s,endColumn:i}=this._previousShape.getRange(),c={startRow:o,endRow:r,startColumn:s,endColumn:i};this._removeArrayFormulaRangeShape(),this._createArrayFormulaRangeShape(c,t)}}_checkCurrentSheet(t,n){const o=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!o)return!1;const r=o.worksheet;return r?r.unitId===t&&r.getSheetId()===n:!1}_updateArrayFormulaRangeShape(t,n){this._checkCurrentSheet(t,n)&&this._previousShape&&this._refreshArrayFormulaRangeShape(t)}_refreshArrayFormulaRangeShapeByRow(t,n,o){if(!this._checkCurrentSheet(t,n)||!this._previousShape)return;const{startRow:r,endRow:s,startColumn:i,endColumn:c}=this._previousShape.getRange();for(let d=0;d<o.length;d++){const{row:h}=o[d];if(r>=h){const f={startRow:r,endRow:s,startColumn:i,endColumn:c};this._refreshArrayFormulaRangeShape(t,f);break}}}};ze=ir([Ee(1,l.Inject(j.SheetInterceptorService)),Ee(2,l.Inject(F.FormulaDataModel)),Ee(3,l.Inject(l.ThemeService)),Ee(4,V.IRenderManagerService),Ee(5,l.Inject(w.SheetSkeletonManagerService)),Ee(6,l.ICommandService),Ee(7,l.ILogService)],ze);var cr=Object.getOwnPropertyDescriptor,ar=(e,t,n,o)=>{for(var r=o>1?void 0:o?cr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Ft=(e,t)=>(n,o)=>t(n,o,e);const lr={tl:{size:6,color:"#409f11"}};let Ge=class extends l.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(j.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,handler:(n,o,r)=>{var c,d,h,f;const s=(f=(h=(d=(c=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:c[o.unitId])==null?void 0:d[o.subUnitId])==null?void 0:h[o.row])==null?void 0:f[o.col];return zt(n,!!s)?r({...n,markers:{...n==null?void 0:n.markers,...lr}}):r(n)},priority:10}))}};Ge=ar([Ft(0,l.Inject(j.SheetInterceptorService)),Ft(1,l.Inject(F.FormulaDataModel))],Ge);function ur(){const e=a.useDependency(ye.TriggerCalculationController),t=a.useDependency(l.ICommandService),n=a.useObservable(e.progress$),o=S.useCallback(()=>{t.executeCommand(F.SetFormulaCalculationStopMutation.id)},[t]),r=S.useCallback(()=>{e.clearProgress()},[e]);return v.jsx(a.ProgressBar,{progress:n,onTerminate:o,onClearProgress:r})}const dr=(e,t=100)=>{S.useEffect(()=>{let n=null;const o=()=>{n===null&&(n=window.setTimeout(()=>{e(),n=null},t))};return window.addEventListener("scroll",o),window.addEventListener("resize",o),()=>{n!==null&&clearTimeout(n),window.removeEventListener("scroll",o),window.removeEventListener("resize",o)}},[e,t])},fr="univer-formula-help-function",hr="univer-formula-help-function-title",mr="univer-formula-help-function-title-icons",gr="univer-formula-help-function-title-icon",pr="univer-formula-help-function-content",Sr="univer-formula-help-function-content-inner",vr="univer-formula-help-function-content-params",Cr="univer-formula-help-function-content-params-title",Ir="univer-formula-help-function-content-params-detail",Rr="univer-formula-help-function-active",Er="univer-formula-help-decorator",_r="univer-formula-help-param",yr="univer-formula-help-param-prefix",Tr="univer-formula-help-param-item",br="univer-formula-help-param-active",G={formulaHelpFunction:fr,formulaHelpFunctionTitle:hr,formulaHelpFunctionTitleIcons:mr,formulaHelpFunctionTitleIcon:gr,formulaHelpFunctionContent:pr,formulaHelpFunctionContentInner:Sr,formulaHelpFunctionContentParams:vr,formulaHelpFunctionContentParamsTitle:Cr,formulaHelpFunctionContentParamsDetail:Ir,formulaHelpFunctionActive:Rr,formulaHelpDecorator:Er,formulaHelpParam:_r,formulaHelpParamPrefix:yr,formulaHelpParamItem:Tr,formulaHelpParamActive:br};function xr(){const[e,t]=S.useState(!1),[n,o]=S.useState(!0),[r,s]=S.useState(!0),[i,c]=S.useState(0),[d,h]=S.useState([0,0]),[f,p]=S.useState({left:0,top:0}),[u,g]=S.useState(null),m=a.useDependency(je),T=a.useDependency(l.LocaleService),C=T.t("formula.prompt.required"),R=T.t("formula.prompt.optional"),I=a.useDependency(l.IUniverInstanceService),E=a.useDependency(z.IEditorService),_=a.useDependency(a.ISidebarService),x=a.useInjector();dr(N),S.useEffect(()=>{const y=m.help$.subscribe(D=>{const{visible:M,paramIndex:b,functionInfo:A}=D;if(!M){t(M);return}const k=$();if(k==null)return;const{left:H,top:W,height:ee}=k;A.description===""&&A.functionParameter.length===0||(h([H,W+ee]),c(b),g(A),p({left:H,top:W}),t(M))}),O=_.scrollEvent$.pipe(B.throttleTime(100)).subscribe(N);return()=>{y==null||y.unsubscribe(),O.unsubscribe()}},[]);function N(){if(!r)return;const y=$();if(y==null)return;const{left:O,top:D,height:M}=y;h([O,D+M])}function $(){const y=I.getCurrentUniverDocInstance();if(!y)return;const O=y.getUnitId();if(!E.isEditor(O))return;const D=E.getEditor(O);return D==null?void 0:D.getBoundingClientRect()}function L(y){c(y)}function P(){s(!r),x.get(a.ILayoutService).focus()}return v.jsx(v.Fragment,{children:r?v.jsx(te.Popup,{visible:e,offset:d,children:u?v.jsxs("div",{className:G.formulaHelpFunction,children:[v.jsxs("div",{className:G.formulaHelpFunctionTitle,children:[v.jsx(Nr,{prefix:u.functionName,value:u.functionParameter,active:i,onClick:L}),v.jsxs("div",{className:G.formulaHelpFunctionTitleIcons,children:[v.jsx("div",{className:G.formulaHelpFunctionTitleIcon,style:{transform:n?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>o(!n),children:v.jsx(ft,{})}),v.jsx("div",{className:G.formulaHelpFunctionTitleIcon,onClick:P,children:v.jsx(et,{})})]})]}),v.jsx("div",{className:G.formulaHelpFunctionContent,style:{height:n?"unset":0,padding:n?"revert-layer":0},children:v.jsxs("div",{className:G.formulaHelpFunctionContentInner,children:[v.jsx(st,{title:T.t("formula.prompt.helpExample"),value:`${u.functionName}(${u.functionParameter.map(y=>y.example).join(",")})`}),v.jsx(st,{title:T.t("formula.prompt.helpAbstract"),value:u.description}),u&&u.functionParameter&&u.functionParameter.map((y,O)=>v.jsx(st,{className:i===O?G.formulaHelpFunctionActive:"",title:y.name,value:`${y.require?C:R} ${y.detail}`},O))]})})]}):v.jsx(v.Fragment,{})}):e?v.jsx("div",{className:G.formulaHelpDecorator,onClick:()=>s(!r),style:{left:f.left-24,top:f.top},children:v.jsx(Ut,{})}):v.jsx(v.Fragment,{})})}const st=e=>v.jsxs("div",{className:G.formulaHelpFunctionContentParams,children:[v.jsx("div",{className:`
|
|
11
|
+
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},H.current);const J=L.getEditor(W);M.current=J,Fe(n,!1,!0)}return()=>{X==null||X.dispose()}},[]),S.useLayoutEffect(()=>{s?(k(s),Me()):(I&&(b==null||b.blur(),St()),k(s))},[s,b,Me,St,I]);const{checkScrollBar:Jt}=z.useResize(b,_,E);so(A,!!(ne&&ge),o,N),ro(A&&m,Ue,b,R);const Qt=a.useEvent((X,J,ue)=>{if(!ae)return;const de=J!==-1?[{startOffset:J+1,endOffset:J+1,collapsed:!0}]:void 0;Fe(`=${X}`,!0,ue,de),ue&&(Me(),J!==-1&&setTimeout(()=>{const Ae={startOffset:J+1,endOffset:J+1},pe=b==null?void 0:b.render.with(z.DocBackScrollRenderController);pe==null||pe.scrollToRange({...Ae,collapsed:!0})},50),Jt())});uo(A&&!!(ne&&ge),A,ce,o,r,le,i,!!Ue,b,Qt),fo(A&&!!(ne&&ge),o,i,k,d,()=>{Fe(Z.current,!1,!0)});const en=X=>{if(X){const J=b==null?void 0:b.getSelectionRanges();if(J&&J.length===1){const ue=J[0];if(ue.collapsed){const de=X.offset;setTimeout(()=>{b==null||b.setSelectionRanges([{startOffset:ue.startOffset-de,endOffset:ue.endOffset-de}])},30)}}Me(),Fe(`=${X.text}`)}},tn=()=>{k(!0),c(),Me()};return v.jsxs("div",{style:$,className:te.clsx(Oe.sheetEmbeddingFormulaEditor,u),children:[v.jsx("div",{className:te.clsx(Oe.sheetEmbeddingFormulaEditorWrap,{[Oe.sheetEmbeddingFormulaEditorActive]:A,[Oe.sheetEmbeddingFormulaEditorError]:ee}),ref:P,children:v.jsx("div",{className:Oe.sheetEmbeddingFormulaEditorText,ref:H,onMouseUp:tn})}),t!==void 0?v.jsx("div",{className:Oe.sheetEmbeddingFormulaEditorErrorWrap,children:t}):null,b?v.jsx(qn,{editor:b,isFocus:A,formulaText:U,onClose:()=>Me()}):null,b?v.jsx(No,{isFocus:A,sequenceNodes:ie,onSelect:en,ref:D,editor:b}):null]})}function Do(e,t,n,o){const r=a.useDependency(F.LexerTreeBuilder),s=qt(""),i=a.useObservable(e==null?void 0:e.getDocumentDataModel().change$),[c,d]=S.useState([]),h=a.useDependency(w.IMarkSelectionService),f=S.useRef(""),p=a.useDependency(l.IUniverInstanceService);return S.useEffect(()=>{if(!e)return;const u=e.getDocumentDataModel().getPlainText();if(f.current===u)return;f.current=u;const g=r.sequenceNodesBuilder(u);d(g!=null?g:[])},[i,e,r]),S.useEffect(()=>{var m,T;if(!e)return;if(!t){const C=e.getDocumentData();e.setDocumentData({...C,body:{...C.body,dataStream:(T=(m=C.body)==null?void 0:m.dataStream)!=null?T:"",textRuns:[]}});return}const u=s(e,c,!1),g=new l.DisposableCollection;return u.forEach(C=>{const R=F.deserializeRangeWithSheet(C.token),I=p.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),E=I==null?void 0:I.getActiveSheet();if(!R.sheetName&&o!==(E==null?void 0:E.getSheetId())||R.sheetName&&(E==null?void 0:E.getName())!==R.sheetName)return;const _=new l.ColorKit(C.themeColor).toRgb(),x=h.addShape({range:R.range,style:{stroke:C.themeColor,fill:`rgba(${_.r}, ${_.g}, ${_.b}, 0.1)`,strokeDash:12},primary:null});x&&g.add(()=>h.removeShape(x))}),()=>{g.dispose()}},[e,t,s,h,c]),{sequenceNodes:c}}function Oo(e){const t=a.useDependency(j.SheetsSelectionsService),{supportAcrossSheet:n=!1,unitId:o,subUnitId:r,onChange:s}=e,c=a.useDependency(l.IUniverInstanceService).getUnit(o,l.UniverInstanceType.UNIVER_SHEET),d=a.useEvent(s),h=a.useEvent((f,p)=>{const u=c==null?void 0:c.getActiveSheet();if(!u||!n&&u.getSheetId()!==r||!(f!=null&&f.length))return;const g=f.map(m=>({range:m.range,unitId:o,sheetName:u.getSheetId()===r?"":u.getName()}));d(g,p)});S.useEffect(()=>{const f=new l.DisposableCollection;return f.add(t.selectionMoveStart$.subscribe(p=>{h(p,!0)})),f.add(t.selectionMoving$.subscribe(p=>{h(p,!1)})),f.add(t.selectionMoveEnd$.subscribe(p=>{h(p,!1)})),()=>{f.dispose()}},[h,t.selectionMoveEnd$,t.selectionMoveStart$,t.selectionMoving$])}const Ao="univer-sheet-range-selector-icon",Po="univer-sheet-range-selector-dialog",Lo="univer-sheet-range-selector-dialog-item",wo="univer-sheet-range-selector-dialog-item-delete",Ke={sheetRangeSelectorIcon:Ao,sheetRangeSelectorDialog:Po,sheetRangeSelectorDialogItem:Lo,sheetRangeSelectorDialogItemDelete:wo},bt=e=>!e.some(n=>{if(typeof n=="string"){if(n!==F.matchToken.COMMA)return!0}else if(n.nodeType!==F.sequenceNodeType.REFERENCE)return!0;return!1}),ko=e=>{if(e.endColumn<e.startColumn){const t=e.endColumn;e.endColumn=e.startColumn,e.startColumn=t}if(e.endRow<e.startRow){const t=e.endRow;e.endRow=e.startRow,e.startRow=t}return e};function $o(e){const{visible:t,initialValue:n,unitId:o,subUnitId:r,maxRangeCount:s=1/0,supportAcrossSheet:i,onConfirm:c,onClose:d,onShowBySelection:h}=e,f=a.useDependency(l.LocaleService),p=a.useDependency(F.LexerTreeBuilder),[u,g]=S.useState([]),[m,T]=S.useState(0),C=S.useRef(null);S.useEffect(()=>{if(t&&n.length){const _=n.map(x=>x.sheetName?F.serializeRangeWithSheet(x.sheetName,x.range):F.serializeRange(x.range));g(_),T(_.length-1)}else g([""]),T(0)},[t]);const R=(_,x)=>{const N=[...u];N[_]=x,g(N)},I=()=>{g([...u,""]),T(u.length)},E=_=>{u.splice(_,1),g([...u])};return Oo({unitId:o,subUnitId:r,supportAcrossSheet:i,onChange:(_,x)=>{if(!t&&h!=null&&h(_))return;const N=new Set(u),$=_.map(y=>y.sheetName?F.serializeRangeWithSheet(y.sheetName,y.range):F.serializeRange(y.range)),L=$.filter(y=>!N.has(y));if(!L.length)return;const P=[...u];if($.length>1){x||P.splice(m,1),P.push(...L);const y=P.slice(0,s);g(y),T(y.length-1),requestAnimationFrame(()=>{var O;(O=C.current)==null||O.scrollTo({top:C.current.scrollHeight})})}else{P.splice(m,1,...L);const y=P.slice(0,s);g(y),T(m+L.length-1)}}}),v.jsx(te.Dialog,{width:"328px",visible:t,title:f.t("rangeSelector.title"),draggable:!0,closeIcon:v.jsx(et,{}),footer:v.jsxs("footer",{children:[v.jsx(te.Button,{onClick:d,children:f.t("rangeSelector.cancel")}),v.jsx(te.Button,{style:{marginLeft:10},onClick:()=>{c(u.filter(_=>{const x=p.sequenceNodesBuilder(_);return x&&x.length===1&&typeof x[0]!="string"&&x[0].nodeType===F.sequenceNodeType.REFERENCE}).map(_=>F.deserializeRangeWithSheet(_)).map(_=>({..._,range:ko(_.range)})))},type:"primary",children:f.t("rangeSelector.confirm")})]}),onClose:d,children:v.jsxs("div",{ref:C,className:Ke.sheetRangeSelectorDialog,children:[u.map((_,x)=>v.jsxs("div",{className:Ke.sheetRangeSelectorDialogItem,children:[v.jsx(te.Input,{affixWrapperStyle:{width:"100%"},placeholder:f.t("rangeSelector.placeHolder"),onFocus:()=>T(x),value:_,onChange:N=>R(x,N),style:{borderColor:m===x?"rgb(var(--primary-color))":void 0}}),u.length>1&&v.jsx(Ht,{className:Ke.sheetRangeSelectorDialogItemDelete,onClick:()=>E(x)})]},x)),u.length<s&&v.jsx("div",{children:v.jsxs(te.Button,{type:"link",size:"small",onClick:I,children:[v.jsx(Wt,{}),v.jsx("span",{children:f.t("rangeSelector.addAnotherRange")})]})})]})})}function jo(e){return e.split(F.matchToken.COMMA).filter(t=>!!t).map(t=>F.deserializeRangeWithSheet(t))}function Ho(e){return e.map(t=>t.sheetName?F.serializeRangeWithSheet(t.sheetName,t.range):F.serializeRange(t.range)).join(F.matchToken.COMMA)}function mt(e){const[t,n]=S.useState(null),{onVerify:o,selectorRef:r,unitId:s,subUnitId:i,maxRangeCount:c,supportAcrossSheet:d,autoFocus:h,onChange:f,onRangeSelectorDialogVisibleChange:p,onClickOutside:u,onFocusChange:g,forceShowDialogWhenSelectionChanged:m,hideEditor:T,resetRange:C}=e,[R,I]=S.useState(h!=null?h:!1),[E,_]=S.useState(!1),[x,N]=S.useState([]),$=a.useDependency(l.LocaleService),L=a.useDependency(z.IEditorService),{sequenceNodes:P}=Do(t,R,s,i),y=be(P),O=a.useDependency(l.ICommandService),D=a.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),L.blur()}),M=a.useEvent(()=>{var b;D(),N(jo((b=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?b:"")),_(!0)});return S.useEffect(()=>{r&&(r.current={get editor(){return t},focus(){L.focus(t.getEditorId())},blur:D,verify:()=>bt(y.current),showDialog:b=>{D(),N(b),_(!0)},hideDialog:()=>{N([]),_(!1)},getValue:()=>{var b;return(b=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?b:""}})},[D,t,L,r,y]),S.useEffect(()=>{var b;o==null||o(bt(P),(b=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?b:"")},[P]),S.useEffect(()=>{p==null||p(E)},[E]),S.useEffect(()=>{if(E&&C)return()=>{const b={unitId:s,subUnitId:i,selections:C};O.executeCommand(j.SetSelectionsOperation.id,b)}},[E]),v.jsxs(v.Fragment,{children:[T?null:v.jsx(z.RichTextEditor,{isSingle:!0,...e,onFocusChange:(b,A)=>{I(b),g==null||g(b,A)},editorRef:n,onClickOutside:()=>{I(!1),D(),u==null||u()},icon:v.jsx(te.Tooltip,{title:$.t("rangeSelector.buttonTooltip"),placement:"bottom",children:v.jsx(Vt,{className:Ke.sheetRangeSelectorIcon,onClick:M})})}),v.jsx($o,{initialValue:x,unitId:s,subUnitId:i,visible:E,maxRangeCount:c,onConfirm:b=>{const A=Ho(b),k=l.RichTextBuilder.newEmptyData();k.body.dataStream=A,t==null||t.replaceText(A,!1),f==null||f(k,A),_(!1),N([]),requestAnimationFrame(()=>{D()})},onClose:()=>{_(!1),N([])},supportAcrossSheet:d,onShowBySelection:b=>R||m?(N(b),_(!0),!1):!0})]})}class gt{constructor(){K(this,"_currentSelector$",new B.BehaviorSubject(null));K(this,"currentSelector$",this._currentSelector$.asObservable())}showRangeSelectorDialog(t){const n=t.callback,o=new Promise(r=>{t.callback=s=>{r(s),n(s)}});return this._currentSelector$.next(t),o}}const Uo="sheets-formula-ui.base.config",xt={};function Wo(e){return e.getContextValue(l.FOCUSING_DOC)&&e.getContextValue(l.FOCUSING_UNIVER_EDITOR)}function zt(e,t=!1){return!t&&!(l.isFormulaString(e==null?void 0:e.f)||l.isFormulaId(e==null?void 0:e.si))?null:typeof(e==null?void 0:e.v)=="string"&&F.ERROR_TYPE_SET.has(e.v)?e.v:null}var Vo=Object.getOwnPropertyDescriptor,Bo=(e,t,n,o)=>{for(var r=o>1?void 0:o?Vo(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Pe=(e,t)=>(n,o)=>t(n,o,e);const rt="SHEET_FORMULA_ALERT",Ko={[F.ErrorType.DIV_BY_ZERO]:"divByZero",[F.ErrorType.NAME]:"name",[F.ErrorType.VALUE]:"value",[F.ErrorType.NUM]:"num",[F.ErrorType.NA]:"na",[F.ErrorType.CYCLE]:"cycle",[F.ErrorType.REF]:"ref",[F.ErrorType.SPILL]:"spill",[F.ErrorType.CALC]:"calc",[F.ErrorType.ERROR]:"error",[F.ErrorType.CONNECT]:"connect",[F.ErrorType.NULL]:"null"};let lt=class extends l.Disposable{constructor(e,t,n,o,r,s){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=o,this._formulaDataModel=r,this._zenZoneService=s,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(B.debounceTime(100)).subscribe(e=>{var t,n,o,r,s;if(e){const c=this._context.unit.getActiveSheet();if(!c)return;const d=c.getCell(e.location.row,e.location.col),h=(r=(o=(n=(t=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:t[e.location.unitId])==null?void 0:n[e.location.subUnitId])==null?void 0:o[e.location.row])==null?void 0:r[e.location.col];if(l.isICellData(d)){const f=zt(d,!!h);if(!f){this._hideAlert();return}const p=this._cellAlertManagerService.currentAlert.get(rt),u=(s=p==null?void 0:p.alert)==null?void 0:s.location;if(u&&u.row===e.location.row&&u.col===e.location.col&&u.subUnitId===e.location.subUnitId&&u.unitId===e.location.unitId)return;this._cellAlertManagerService.showAlert({type:w.CellAlertType.ERROR,title:this._localeService.t("formula.error.title"),message:this._localeService.t(`formula.error.${Ko[f]}`),location:e.location,width:200,height:74,key:rt});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(rt)}};lt=Bo([Pe(1,l.Inject(w.HoverManagerService)),Pe(2,l.Inject(w.CellAlertManagerService)),Pe(3,l.Inject(l.LocaleService)),Pe(4,l.Inject(F.FormulaDataModel)),Pe(5,a.IZenZoneService)],lt);var qo=Object.getOwnPropertyDescriptor,Yo=(e,t,n,o)=>{for(var r=o>1?void 0:o?qo(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Nt=(e,t)=>(n,o)=>t(n,o,e);let qe=class extends l.Disposable{constructor(e,t){super(),this._autoFillService=e,this._lexerTreeBuilder=t,this._registerAutoFill()}_registerAutoFill(){const e={type:w.DATA_TYPE.FORMULA,priority:1001,match:t=>l.isFormulaString(t==null?void 0:t.f)||l.isFormulaId(t==null?void 0:t.si),isContinue:(t,n)=>t.type===w.DATA_TYPE.FORMULA,applyFunctions:{[w.APPLY_TYPE.COPY]:(t,n,o,r)=>{const{data:s,index:i}=t;return this._fillCopyFormula(s,n,o,i,r)}}};this._autoFillService.registerRule(e)}_fillCopyFormula(e,t,n,o,r){var d,h;const s=Go(r),i=[],c=new Map;for(let f=1;f<=t;f++){const p=(f-1)%e.length,u=l.Tools.deepClone(e[p]);if(u){const g=((d=e[p])==null?void 0:d.f)||"",m=((h=e[p])==null?void 0:h.si)||"",T=l.isFormulaString(g);if(l.isFormulaId(m))u.si=m,u.f=null,u.v=null,u.p=null,u.t=null,i.push(u);else if(T){let R=c.get(p);if(R)u.si=R,u.f=null,u.v=null,u.p=null,u.t=null;else{R=l.Tools.generateRandomId(6),c.set(p,R);const{offsetX:I,offsetY:E}=zo(s,t,n),_=this._lexerTreeBuilder.moveFormulaRefOffset(g,I,E);u.si=R,u.f=_,u.v=null,u.p=null,u.t=null}i.push(u)}}}return i}};qe=Yo([Nt(0,w.IAutoFillService),Nt(1,l.Inject(F.LexerTreeBuilder))],qe);function zo(e,t,n){let o=0,r=0;switch(n){case l.Direction.UP:r=-e*t;break;case l.Direction.RIGHT:o=e;break;case l.Direction.DOWN:r=e;break;case l.Direction.LEFT:o=-e*t;break}return{offsetX:o,offsetY:r}}function Go(e){let t=0;for(const n in e)e[n].forEach(o=>{t+=o.data.length});return t}var Zo=Object.getOwnPropertyDescriptor,Xo=(e,t,n,o)=>{for(var r=o>1?void 0:o?Zo(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Le=(e,t)=>(n,o)=>t(n,o,e);const Jo="default-paste-formula";let Ye=class extends l.Disposable{constructor(e,t,n,o,r){super(),this._currentUniverSheet=e,this._lexerTreeBuilder=t,this._sheetClipboardService=n,this._injector=o,this._formulaDataModel=r,this._initialize()}_initialize(){this._registerClipboardHook()}_registerClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteFormulaHook())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteWithFormulaHook()))}_pasteFormulaHook(){return{id:w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA,priority:10,specialPasteInfo:{label:"specialPaste.formula"},onPasteCells:(e,t,n,o)=>this._onPasteCells(e,t,n,o,!0)}}_pasteWithFormulaHook(){return{id:Jo,priority:10,onPasteCells:(e,t,n,o)=>this._onPasteCells(e,t,n,o,!1)}}_onPasteCells(e,t,n,o,r){var u;if([w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH].includes(o.pasteType))return{undos:[],redos:[]};const i=this._currentUniverSheet.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),c=t.unitId||i.getUnitId(),d=t.subUnitId||((u=i.getActiveSheet())==null?void 0:u.getSheetId());if(!c||!d)return{undos:[],redos:[]};const h=t.range,f=n,p={copyType:o.copyType||w.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:o.pasteType};return this._injector.invoke(g=>Qo(c,d,h,f,g,p,this._lexerTreeBuilder,this._formulaDataModel,r,e))}};Ye=Xo([Le(0,l.IUniverInstanceService),Le(1,l.Inject(F.LexerTreeBuilder)),Le(2,w.ISheetClipboardService),Le(3,l.Inject(l.Injector)),Le(4,l.Inject(F.FormulaDataModel))],Ye);function Qo(e,t,n,o,r,s,i,c,d=!1,h){const f=[],p=[],u=er(e,t,n,o,s,i,c,h);if(!u.hasValue())return{undos:[],redos:[]};const g={unitId:e,subUnitId:t,cellValue:u.getData()};f.push({id:j.SetRangeValuesMutation.id,params:g});const m=j.SetRangeValuesUndoMutationFactory(r,g);return p.push({id:j.SetRangeValuesMutation.id,params:m}),{undos:p,redos:f}}function er(e,t,n,o,r,s,i,c){return c?r.pasteType===w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE?nr(e,t,n,o,i,c):r.pasteType===w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA?or(e,t,n,o,s,i,c):rr(e,t,n,o,r.copyType,s,i,c):tr(e,t,n,o,i)}function tr(e,t,n,o,r){const s=new l.ObjectMatrix,i=r.getSheetFormulaData(e,t);return o.forValue((c,d,h)=>{var g;const f=n.rows[c],p=n.cols[d],u={};l.isFormulaString(h.v)?(u.v=null,u.f=`${h.v}`,u.si=null,u.p=null,s.setValue(f,p,u)):(g=i==null?void 0:i[f])!=null&&g[p]&&(u.v=h.v,u.f=null,u.si=null,u.p=null,s.setValue(f,p,u))}),s}function nr(e,t,n,o,r,s){var h,f;const i=new l.ObjectMatrix,c=(f=(h=r.getArrayFormulaCellData())==null?void 0:h[s.unitId])==null?void 0:f[s.subUnitId],d=r.getSheetFormulaData(e,t);return o.forValue((p,u,g)=>{var E,_;const m=s.range.rows[p%s.range.rows.length],T=s.range.cols[u%s.range.cols.length],C=n.rows[p],R=n.cols[u],I={};if(l.isFormulaString(g.f)||l.isFormulaId(g.si))I.v=g.v,I.f=null,I.si=null,I.p=null,i.setValue(C,R,I);else if((E=c==null?void 0:c[m])!=null&&E[T]){const x=c[m][T];I.v=x.v,I.f=null,I.si=null,I.p=null,i.setValue(C,R,I)}else if((_=d==null?void 0:d[C])!=null&&_[R]){if(I.v=g.v,I.f=null,I.si=null,I.p=null,g.p){const x=Gt(g);x&&(I.v=x)}i.setValue(C,R,I)}}),i}function or(e,t,n,o,r,s,i){const c=new l.ObjectMatrix,d=new Map;return o.forValue((h,f,p)=>{const u=n.rows[h],g=n.cols[f],m={};if(l.isFormulaId(p.si)){if(i.unitId!==e||i.subUnitId!==t){const T=s.getFormulaStringByCell(i.range.rows[h%i.range.rows.length],i.range.cols[f%i.range.cols.length],i.subUnitId,i.unitId),C=n.cols[f]-i.range.cols[f%i.range.cols.length],R=n.rows[h]-i.range.rows[h%i.range.rows.length],I=r.moveFormulaRefOffset(T||"",C,R);m.si=null,m.f=I}else m.si=p.si,m.f=null;m.v=null,m.p=null,c.setValue(u,g,m)}else if(l.isFormulaString(p.f)){const T=`${h%i.range.rows.length}_${f%i.range.cols.length}`;let C=d.get(T);if(C)m.si=C,m.f=null;else{C=l.Tools.generateRandomId(6),d.set(T,C);const R=n.cols[f]-i.range.cols[f%i.range.cols.length],I=n.rows[h]-i.range.rows[h%i.range.rows.length],E=r.moveFormulaRefOffset(p.f||"",R,I);m.si=C,m.f=E}m.v=null,m.p=null,c.setValue(u,g,m)}else{if(m.v=p.v,m.f=null,m.si=null,m.p=null,p.p){const T=Gt(p);T&&(m.v=T)}c.setValue(u,g,m)}}),c}function rr(e,t,n,o,r,s,i,c){const d=new l.ObjectMatrix,h=new Map,f=i.getSheetFormulaData(e,t),p=[];return r===w.COPY_TYPE.CUT?o.forValue((u,g,m)=>{const T=n.rows[u],C=n.cols[g],R={};if(l.isFormulaId(m.si)){if(l.isFormulaString(m.f))p.push(m.si),R.f=m.f,R.si=m.si;else if(p.includes(m.si))R.f=null,R.si=m.si;else{const I=i.getFormulaStringByCell(c.range.rows[u%c.range.rows.length],c.range.cols[g%c.range.cols.length],c.subUnitId,c.unitId);R.f=I,R.si=null}R.v=null,R.p=null,d.setValue(T,C,R)}else l.isFormulaString(m.f)&&(R.f=m.f,R.si=null,R.v=null,R.p=null,d.setValue(T,C,R))}):o.forValue((u,g,m)=>{var I;const T=n.rows[u],C=n.cols[g],R={};if(l.isFormulaId(m.si)){if(c.unitId!==e||c.subUnitId!==t){const E=i.getFormulaStringByCell(c.range.rows[u%c.range.rows.length],c.range.cols[g%c.range.cols.length],c.subUnitId,c.unitId),_=n.cols[g]-c.range.cols[g%c.range.cols.length],x=n.rows[u]-c.range.rows[u%c.range.rows.length],N=s.moveFormulaRefOffset(E||"",_,x);R.si=null,R.f=N}else R.si=m.si,R.f=null;R.v=null,R.p=null,d.setValue(T,C,R)}else if(l.isFormulaString(m.f)){const E=`${u%c.range.rows.length}_${g%c.range.cols.length}`;let _=h.get(E);if(_)R.si=_,R.f=null;else{_=l.Tools.generateRandomId(6),h.set(E,_);const x=n.cols[g]-c.range.cols[g%c.range.cols.length],N=n.rows[u]-c.range.rows[u%c.range.rows.length],$=s.moveFormulaRefOffset(m.f||"",x,N);R.si=_,R.f=$}R.v=null,R.p=null,d.setValue(T,C,R)}else(I=f==null?void 0:f[T])!=null&&I[C]&&(R.v=m.v,R.f=null,R.si=null,R.p=m.p,d.setValue(T,C,R))}),p.length>0&&new l.ObjectMatrix(f).forValue((u,g,m)=>{if(!(c.range.rows.includes(u)&&c.range.cols.includes(g))&&!(n.rows.includes(u)&&n.cols.includes(g))&&p.includes(m==null?void 0:m.si)){const T=i.getFormulaStringByCell(u,g,c.subUnitId,c.unitId);d.setValue(u,g,{f:T,si:null,v:null,p:null})}}),d}function Gt(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return;const n=t.dataStream;return n.substring(n.length-2,n.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n}}var sr=Object.getOwnPropertyDescriptor,ir=(e,t,n,o)=>{for(var r=o>1?void 0:o?sr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Ee=(e,t)=>(n,o)=>t(n,o,e);let ze=class extends l.Disposable{constructor(t,n,o,r,s,i,c,d){super();K(this,"_previousShape");K(this,"_skeleton");this._context=t,this._sheetInterceptorService=n,this._formulaDataModel=o,this._themeService=r,this._renderManagerService=s,this._sheetSkeletonManagerService=i,this._commandService=c,this._logService=d,this._initSkeletonChangeListener(),this._initInterceptorEditorStart(),this._commandExecutedListener()}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(t=>{var n,o;if(t==null)this._logService.debug("[FormulaEditorShowController]: should not receive currentSkeleton$ as null!");else{const{skeleton:r}=t,s=(o=(n=this._skeleton)==null?void 0:n.worksheet)==null?void 0:o.getSheetId();if(this._changeRuntime(r),s!==r.worksheet.getSheetId())this._removeArrayFormulaRangeShape();else{const{unitId:i,sheetId:c}=t;this._updateArrayFormulaRangeShape(i,c)}}}))}_changeRuntime(t){this._skeleton=t}_initInterceptorEditorStart(){this.disposeWithMe(l.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(j.BEFORE_CELL_EDIT,{handler:(t,n,o)=>{var m,T,C,R;const{row:r,col:s,unitId:i,subUnitId:c,worksheet:d}=n,h=this._formulaDataModel.getArrayFormulaRange(),f=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return o(t);let p=null;const u=this._formulaDataModel.getFormulaStringByCell(r,s,c,i);if(u!==null&&(p={f:u}),t.v!=null&&t.v!==""&&((C=(T=(m=f[i])==null?void 0:m[c])==null?void 0:T[r])==null?void 0:C[s])==null)return p?{...t,...p}:o(t);const g=(R=h==null?void 0:h[i])==null?void 0:R[c];return g!=null&&(p=this._displayArrayFormulaRangeShape(g,r,s,i,c,d,p)),p?{...t,...p}:o(t)}})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{(t.id===F.SetFormulaCalculationResultMutation.id||t.id===F.SetArrayFormulaDataMutation.id&&n&&n.remove)&&this._removeArrayFormulaRangeShape()})),this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{j.SetWorksheetRowAutoHeightMutation.id===t.id&&requestIdleCallback(()=>{const n=t.params,{unitId:o,subUnitId:r,rowsAutoHeightInfo:s}=n;this._refreshArrayFormulaRangeShapeByRow(o,r,s)})}))}_displayArrayFormulaRangeShape(t,n,o,r,s,i,c){const d=this._formulaDataModel.getSheetFormulaData(r,s);return new l.ObjectMatrix(t).forValue((h,f,p)=>{var C;if(p==null)return!0;const{startRow:u,startColumn:g,endRow:m,endColumn:T}=p;if(h===n&&f===o)return this._createArrayFormulaRangeShape(p,r),!1;if(n>=u&&n<=m&&o>=g&&o<=T){const R=i.getCell(u,g);if((R==null?void 0:R.v)===F.ErrorType.SPILL)return;const I=(C=d==null?void 0:d[h])==null?void 0:C[f];return I==null||I.f==null?!0:(c==null&&(c={f:I.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(p,r),!1)}}),c}_createArrayFormulaRangeShape(t,n){const o=this._renderManagerService.getRenderById(n),r=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!o||!r)return;const{scene:s}=o;if(!s)return;const i=this._themeService.getCurrentTheme(),c={range:t,primary:null,style:{strokeWidth:1,stroke:i.hyacinth700,fill:new l.ColorKit(i.colorWhite).setAlpha(0).toString(),widgets:{}}},d=w.attachSelectionWithCoord(c,r),{rowHeaderWidth:h,columnHeaderHeight:f}=r,p=new w.SelectionControl(s,w.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:h,columnHeaderHeight:f});p.updateRangeBySelectionWithCoord(d),p.setEvent(!1),this._previousShape=p}_removeArrayFormulaRangeShape(){this._previousShape!=null&&(this._previousShape.dispose(),this._previousShape=null)}_refreshArrayFormulaRangeShape(t,n){if(this._previousShape){const{startRow:o,endRow:r,startColumn:s,endColumn:i}=this._previousShape.getRange(),c={startRow:o,endRow:r,startColumn:s,endColumn:i};this._removeArrayFormulaRangeShape(),this._createArrayFormulaRangeShape(c,t)}}_checkCurrentSheet(t,n){const o=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!o)return!1;const r=o.worksheet;return r?r.unitId===t&&r.getSheetId()===n:!1}_updateArrayFormulaRangeShape(t,n){this._checkCurrentSheet(t,n)&&this._previousShape&&this._refreshArrayFormulaRangeShape(t)}_refreshArrayFormulaRangeShapeByRow(t,n,o){if(!this._checkCurrentSheet(t,n)||!this._previousShape)return;const{startRow:r,endRow:s,startColumn:i,endColumn:c}=this._previousShape.getRange();for(let d=0;d<o.length;d++){const{row:h}=o[d];if(r>=h){const f={startRow:r,endRow:s,startColumn:i,endColumn:c};this._refreshArrayFormulaRangeShape(t,f);break}}}};ze=ir([Ee(1,l.Inject(j.SheetInterceptorService)),Ee(2,l.Inject(F.FormulaDataModel)),Ee(3,l.Inject(l.ThemeService)),Ee(4,V.IRenderManagerService),Ee(5,l.Inject(w.SheetSkeletonManagerService)),Ee(6,l.ICommandService),Ee(7,l.ILogService)],ze);var cr=Object.getOwnPropertyDescriptor,ar=(e,t,n,o)=>{for(var r=o>1?void 0:o?cr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Ft=(e,t)=>(n,o)=>t(n,o,e);const lr={tl:{size:6,color:"#409f11"}};let Ge=class extends l.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(j.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,handler:(n,o,r)=>{var c,d,h,f;const s=(f=(h=(d=(c=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:c[o.unitId])==null?void 0:d[o.subUnitId])==null?void 0:h[o.row])==null?void 0:f[o.col];return zt(n,!!s)?r({...n,markers:{...n==null?void 0:n.markers,...lr}}):r(n)},priority:10}))}};Ge=ar([Ft(0,l.Inject(j.SheetInterceptorService)),Ft(1,l.Inject(F.FormulaDataModel))],Ge);function ur(){const e=a.useDependency(ye.TriggerCalculationController),t=a.useDependency(l.ICommandService),n=a.useObservable(e.progress$),o=S.useCallback(()=>{t.executeCommand(F.SetFormulaCalculationStopMutation.id)},[t]),r=S.useCallback(()=>{e.clearProgress()},[e]);return v.jsx(a.ProgressBar,{progress:n,onTerminate:o,onClearProgress:r})}const dr=(e,t=100)=>{S.useEffect(()=>{let n=null;const o=()=>{n===null&&(n=window.setTimeout(()=>{e(),n=null},t))};return window.addEventListener("scroll",o),window.addEventListener("resize",o),()=>{n!==null&&clearTimeout(n),window.removeEventListener("scroll",o),window.removeEventListener("resize",o)}},[e,t])},fr="univer-formula-help-function",hr="univer-formula-help-function-title",mr="univer-formula-help-function-title-icons",gr="univer-formula-help-function-title-icon",pr="univer-formula-help-function-content",Sr="univer-formula-help-function-content-inner",vr="univer-formula-help-function-content-params",Cr="univer-formula-help-function-content-params-title",Ir="univer-formula-help-function-content-params-detail",Rr="univer-formula-help-function-active",Er="univer-formula-help-decorator",_r="univer-formula-help-param",yr="univer-formula-help-param-prefix",Tr="univer-formula-help-param-item",br="univer-formula-help-param-active",G={formulaHelpFunction:fr,formulaHelpFunctionTitle:hr,formulaHelpFunctionTitleIcons:mr,formulaHelpFunctionTitleIcon:gr,formulaHelpFunctionContent:pr,formulaHelpFunctionContentInner:Sr,formulaHelpFunctionContentParams:vr,formulaHelpFunctionContentParamsTitle:Cr,formulaHelpFunctionContentParamsDetail:Ir,formulaHelpFunctionActive:Rr,formulaHelpDecorator:Er,formulaHelpParam:_r,formulaHelpParamPrefix:yr,formulaHelpParamItem:Tr,formulaHelpParamActive:br};function xr(){const[e,t]=S.useState(!1),[n,o]=S.useState(!0),[r,s]=S.useState(!0),[i,c]=S.useState(0),[d,h]=S.useState([0,0]),[f,p]=S.useState({left:0,top:0}),[u,g]=S.useState(null),m=a.useDependency(je),T=a.useDependency(l.LocaleService),C=T.t("formula.prompt.required"),R=T.t("formula.prompt.optional"),I=a.useDependency(l.IUniverInstanceService),E=a.useDependency(z.IEditorService),_=a.useDependency(a.ISidebarService),x=a.useInjector();dr(N),S.useEffect(()=>{const y=m.help$.subscribe(D=>{const{visible:M,paramIndex:b,functionInfo:A}=D;if(!M){t(M);return}const k=$();if(k==null)return;const{left:H,top:W,height:ee}=k;A.description===""&&A.functionParameter.length===0||(h([H,W+ee]),c(b),g(A),p({left:H,top:W}),t(M))}),O=_.scrollEvent$.pipe(B.throttleTime(100)).subscribe(N);return()=>{y==null||y.unsubscribe(),O.unsubscribe()}},[]);function N(){if(!r)return;const y=$();if(y==null)return;const{left:O,top:D,height:M}=y;h([O,D+M])}function $(){const y=I.getCurrentUniverDocInstance();if(!y)return;const O=y.getUnitId();if(!E.isEditor(O))return;const D=E.getEditor(O);return D==null?void 0:D.getBoundingClientRect()}function L(y){c(y)}function P(){s(!r),x.get(a.ILayoutService).focus()}return v.jsx(v.Fragment,{children:r?v.jsx(te.Popup,{visible:e,offset:d,children:u?v.jsxs("div",{className:G.formulaHelpFunction,children:[v.jsxs("div",{className:G.formulaHelpFunctionTitle,children:[v.jsx(Nr,{prefix:u.functionName,value:u.functionParameter,active:i,onClick:L}),v.jsxs("div",{className:G.formulaHelpFunctionTitleIcons,children:[v.jsx("div",{className:G.formulaHelpFunctionTitleIcon,style:{transform:n?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>o(!n),children:v.jsx(ft,{})}),v.jsx("div",{className:G.formulaHelpFunctionTitleIcon,onClick:P,children:v.jsx(et,{})})]})]}),v.jsx("div",{className:G.formulaHelpFunctionContent,style:{height:n?"unset":0,padding:n?"revert-layer":0},children:v.jsxs("div",{className:G.formulaHelpFunctionContentInner,children:[v.jsx(st,{title:T.t("formula.prompt.helpExample"),value:`${u.functionName}(${u.functionParameter.map(y=>y.example).join(",")})`}),v.jsx(st,{title:T.t("formula.prompt.helpAbstract"),value:u.description}),u&&u.functionParameter&&u.functionParameter.map((y,O)=>v.jsx(st,{className:i===O?G.formulaHelpFunctionActive:"",title:y.name,value:`${y.require?C:R} ${y.detail}`},O))]})})]}):v.jsx(v.Fragment,{})}):e?v.jsx("div",{className:G.formulaHelpDecorator,onClick:()=>s(!r),style:{left:f.left-24,top:f.top},children:v.jsx(Ut,{})}):v.jsx(v.Fragment,{})})}const st=e=>v.jsxs("div",{className:G.formulaHelpFunctionContentParams,children:[v.jsx("div",{className:`
|
|
12
12
|
${G.formulaHelpFunctionContentParamsTitle}
|
|
13
13
|
${e.className}
|
|
14
14
|
`,children:e.title}),v.jsx("div",{className:G.formulaHelpFunctionContentParamsDetail,children:e.value})]}),Nr=e=>{const{prefix:t,value:n,active:o,onClick:r}=e;return v.jsxs("div",{className:G.formulaHelpParam,children:[v.jsxs("span",{className:G.formulaHelpParamPrefix,children:[t,"("]}),n&&n.map((s,i)=>v.jsxs("span",{className:G.formulaHelpParamItem,children:[v.jsx("span",{className:o===i?G.formulaHelpFunctionActive:G.formulaHelpParamActive,onClick:()=>r(i),children:ht(s)}),i===n.length-1?"":","]},i)),")"]})},Fr="univer-formula-search-function",Mr="univer-formula-search-function-item",Dr="univer-formula-search-function-item-name",Or="univer-formula-search-function-item-name-light",Ar="univer-formula-search-function-item-desc",Pr="univer-formula-search-function-item-active",ve={formulaSearchFunction:Fr,formulaSearchFunctionItem:Mr,formulaSearchFunctionItemName:Dr,formulaSearchFunctionItemNameLight:Or,formulaSearchFunctionItemDesc:Ar,formulaSearchFunctionItemActive:Pr};function Lr(){const[e,t]=S.useState(!1),[n,o]=S.useState(0),[r,s]=S.useState([0,0]),[i,c]=S.useState([]),[d,h]=S.useState(""),f=S.useRef(null),p=a.useDependency(je),u=a.useDependency(l.IUniverInstanceService),g=a.useDependency(z.IEditorService);S.useEffect(()=>{let I=[],E=0;const _=p.search$.subscribe($=>{const{visible:L,searchText:P,searchList:y}=$;if(!L){t(L);return}const O=m();if(O==null)return;const{left:D,top:M,height:b}=O;h(P),c(y),I=y,s([D,M+b]),t(L),o(0),E=0}),x=p.navigate$.subscribe($=>{const{direction:L}=$;if(L===l.Direction.UP){let P=E-1;P=P<0?I.length-1:P,o(P),E=P}else if(L===l.Direction.DOWN){let P=E+1;P=P>=I.length?0:P,o(P),E=P}R(E)}),N=p.accept$.subscribe($=>{const L=I[E].name;p.acceptFormulaName(L)});return()=>{_==null||_.unsubscribe(),x==null||x.unsubscribe(),N==null||N.unsubscribe()}},[]);function m(){const E=u.getCurrentUniverDocInstance().getUnitId();if(!g.isEditor(E))return;const _=g.getEditor(E);return _==null?void 0:_.getBoundingClientRect()}function T(I){o(I)}function C(){o(-1)}function R(I){var D;const E=(D=f.current)==null?void 0:D.querySelectorAll(`.${ve.formulaSearchFunctionItem}`)[I];if(!E)return;const _=E.parentNode;if(!_)return;const N=_.getBoundingClientRect().top,$=_.offsetHeight,L=E.getBoundingClientRect(),P=L.top,y=L.height;if(P>=0&&P>N&&P-N+y<=$)return;const O=E.offsetTop-($-y)/2;_.scrollTo({top:O,behavior:"smooth"})}return i.length>0&&v.jsx(te.Popup,{visible:e,offset:r,children:v.jsx("ul",{className:ve.formulaSearchFunction,ref:f,children:i.map((I,E)=>v.jsxs("li",{className:n===E?`
|
|
@@ -20,4 +20,4 @@
|
|
|
20
20
|
`,children:o}),v.jsx("div",{className:it.formulaFunctionParamsDetail,children:n})]})}const Wr="univer-formula-input-params-list",Vr="univer-formula-input-params-list-item-name",Br="univer-formula-input-params-list-item-selector",we={formulaInputParamsList:Wr,formulaInputParamsListItemName:Vr,formulaInputParamsListItemSelector:Br};function Kr(e){const{functionInfo:t,onChange:n}=e;if(!t)return null;const[o,r]=S.useState([]),[s,i]=S.useState(t.functionParameter),[c,d]=S.useState(-1);return v.jsxs("div",{className:we.formulaInputParams,children:[v.jsx("div",{className:we.formulaInputParamsList,children:s.map((h,f)=>v.jsxs("div",{children:[v.jsx("div",{className:we.formulaInputParamsListItemName,children:h.name}),v.jsx("div",{className:we.formulaInputParamsListItemSelector})]},f))}),v.jsx("div",{className:we.formulaInputParamsInfo,children:v.jsx(ke,{title:c===-1?v.jsx(Zt,{prefix:t.functionName,value:s}):s[c].name,value:c===-1?t.description:s[c].detail})})]})}const qr="univer-formula-select-function-select",Yr="univer-formula-select-function-result",zr="univer-formula-select-function-result-item",Gr="univer-formula-select-function-result-item-name-light",Zr="univer-formula-select-function-result-item-selected",Xr="univer-formula-select-function-result-item-active",Jr="univer-formula-select-function-content",fe={formulaSelectFunctionSelect:qr,formulaSelectFunctionResult:Yr,formulaSelectFunctionResultItem:zr,formulaSelectFunctionResultItemNameLight:Gr,formulaSelectFunctionResultItemSelected:Zr,formulaSelectFunctionResultItemActive:Xr,formulaSelectFunctionContent:Jr};function Qr(e){const{onChange:t}=e,n="-1",[o,r]=S.useState(""),[s,i]=S.useState([]),[c,d]=S.useState(0),[h,f]=S.useState(n),[p,u]=S.useState(0),[g,m]=S.useState(null),T=a.useDependency(ye.IDescriptionService),C=a.useDependency(l.LocaleService),R=a.useDependency(a.ISidebarService),I=a.useObservable(R.sidebarOptions$),E=Nn(F.FunctionType,C);E.unshift({label:C.t("formula.moreFunctions.allFunctions"),value:n});const _=C.t("formula.prompt.required"),x=C.t("formula.prompt.optional");S.useEffect(()=>{L(n)},[]),S.useEffect(()=>{$(0)},[s]),S.useEffect(()=>{I!=null&&I.visible&&(r(""),i([]),d(0),f(n),u(0),m(null),L(n))},[I]);const N=M=>{if(o.trim()==="")return M;const b=new RegExp(`(${o.toLocaleUpperCase()})`);return M.split(b).filter(Boolean).map((k,H)=>k.match(b)?v.jsx("span",{className:fe.formulaSelectFunctionResultItemNameLight,children:k},H):k)},$=M=>{if(s.length===0){m(null);return}u(M);const b=T.getFunctionInfo(s[M].name);if(!b){m(null);return}m(b),t(b)};function L(M){f(M);const b=T.getSearchListByType(+M);i(b)}function P(M){r(M);const b=T.getSearchListByName(M);i(b)}function y(M){if(M.stopPropagation(),M.key==="ArrowDown"){const b=c+1;d(b===s.length?0:b)}else if(M.key==="ArrowUp"){const b=c-1;d(b===-1?s.length-1:b)}else M.key==="Enter"&&$(c)}const O=M=>{d(M)},D=()=>{d(-1)};return v.jsxs("div",{children:[v.jsxs("div",{className:fe.formulaSelectFunctionSelect,children:[v.jsx(te.Select,{value:h,options:E,onChange:L}),v.jsx(te.Input,{placeholder:C.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:y,value:o,onChange:P,size:"small",allowClear:!0})]}),v.jsx("ul",{className:fe.formulaSelectFunctionResult,onKeyDown:y,tabIndex:-1,children:s.map(({name:M},b)=>v.jsxs("li",{className:c===b?`
|
|
21
21
|
${fe.formulaSelectFunctionResultItem}
|
|
22
22
|
${fe.formulaSelectFunctionResultItemActive}
|
|
23
|
-
`:fe.formulaSelectFunctionResultItem,onMouseEnter:()=>O(b),onMouseLeave:D,onClick:()=>$(b),children:[p===b&&v.jsx(jt,{className:fe.formulaSelectFunctionResultItemSelected}),v.jsx("span",{className:fe.formulaSelectFunctionResultItemName,children:N(M)})]},b))}),g&&v.jsxs("div",{className:fe.formulaSelectFunctionContent,children:[v.jsx(ke,{title:g.functionName,value:g.description}),v.jsx(ke,{title:C.t("formula.moreFunctions.syntax"),value:v.jsx(Zt,{prefix:g.functionName,value:g.functionParameter})}),v.jsx(ke,{title:C.t("formula.prompt.helpExample"),value:`${g.functionName}(${g.functionParameter.map(M=>M.example).join(",")})`}),g.functionParameter&&g.functionParameter.map(M=>v.jsx(ke,{title:M.name,value:`${M.require?_:x} ${M.detail}`},M.name))]})]})}function es(){const e=w.useActiveWorkbook(),[t,n]=S.useState(!0),[o,r]=S.useState(!1),[s,i]=S.useState(null);a.useDependency(w.IEditorBridgeService);const c=a.useDependency(l.LocaleService),d=a.useDependency(z.IEditorService),h=a.useDependency(l.IUniverInstanceService),f=a.useDependency(l.ICommandService);function p(){n(!t),r(!o)}function u(){const g=j.getSheetCommandTarget(h);if(!g)return;f.executeCommand(w.SetCellEditVisibleOperation.id,{visible:!0,unitId:g.unitId,eventType:V.DeviceInputEventType.Dblclick});const m=d.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),T=d.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),C=`=${s==null?void 0:s.functionName}(`;m==null||m.replaceText(C),T==null||T.replaceText(C,!1)}return v.jsxs("div",{className:Mt.formulaMoreFunctions,children:[t&&v.jsx(Qr,{onChange:i}),o&&v.jsx(Kr,{functionInfo:s,onChange:()=>{}}),v.jsxs("div",{className:Mt.formulaMoreFunctionsOperation,children:[o&&v.jsx(te.Button,{type:"primary",size:"small",onClick:p,children:c.t("formula.moreFunctions.next")}),o&&v.jsx(te.Button,{size:"small",onClick:p,children:c.t("formula.moreFunctions.prev")}),t&&!!e&&v.jsx(te.Button,{type:"primary",size:"small",onClick:u,children:c.t("formula.moreFunctions.confirm")})]})]})}function ts(e){return{id:Je.id,icon:"FunctionSingle",tooltip:"formula.insert.tooltip",type:a.MenuItemType.SELECTOR,selections:[{label:{name:"SUM",selectable:!1},value:"SUM",icon:"SumSingle"},{label:{name:"AVERAGE",selectable:!1},value:"AVERAGE",icon:"AvgSingle"},{label:{name:"COUNT",selectable:!1},value:"COUNT",icon:"CntSingle"},{label:{name:"MAX",selectable:!1},value:"MAX",icon:"MaxSingle"},{label:{name:"MIN",selectable:!1},value:"MIN",icon:"MinSingle"}],hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:w.getCurrentRangeDisable$(e,{workbookTypes:[j.WorkbookEditablePermission],worksheetTypes:[j.WorksheetEditPermission,j.WorksheetSetCellValuePermission],rangeTypes:[j.RangeProtectionPermissionEditPoint]})}}function ns(e){return{id:Qe.id,title:"formula.insert.more",type:a.MenuItemType.BUTTON}}function os(e){return e.get(l.IUniverInstanceService).getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(B.switchMap(o=>o&&e.get(a.IClipboardInterfaceService)?new B.Observable(s=>s.next(!e.get(a.IClipboardInterfaceService).supportClipboard)):B.of(!0)))}function rs(e){return{id:Xe.id,type:a.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:os(e).pipe(B.combineLatestWith(w.getCurrentRangeDisable$(e,{workbookTypes:[j.WorkbookEditablePermission],rangeTypes:[j.RangeProtectionPermissionEditPoint],worksheetTypes:[j.WorksheetSetCellValuePermission,j.WorksheetEditPermission]})),B.map(([t,n])=>t||n))}}const ss={[a.RibbonStartGroup.FORMULAS_INSERT]:{[Je.id]:{order:1,menuItemFactory:ts,[Qe.id]:{order:1,menuItemFactory:ns}}},[w.PASTE_SPECIAL_MENU_ID]:{[Xe.id]:{order:4,menuItemFactory:rs}}},is="meta_key_ctrl_And_Shift",tt=[a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP,a.KeyCode.ARROW_LEFT,a.KeyCode.ARROW_RIGHT],cs=[...tt,a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ESC];function as(){const e=[];for(const t of cs)e.push({id:Te.id,binding:t,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:V.DeviceInputEventType.Keyboard,keycode:t}});return e}function ls(){const e=[];for(const t of tt)e.push({id:Te.id,binding:t|a.MetaKeys.SHIFT,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:V.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.SHIFT}});return e}function us(){const e=[];for(const t of tt)e.push({id:Te.id,binding:t|a.MetaKeys.CTRL_COMMAND,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:V.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.CTRL_COMMAND}});return e}function ds(){const e=[];for(const t of tt)e.push({id:Te.id,binding:t|a.MetaKeys.SHIFT|a.MetaKeys.CTRL_COMMAND,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:V.DeviceInputEventType.Keyboard,keycode:t,metaKey:is}});return e}const fs={id:ut.id,binding:a.KeyCode.F4,preconditions:e=>w.whenFormulaEditorActivated(e)};function hs(){const e=[];for(const t of[a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP])e.push({id:Te.id,binding:t,preconditions:n=>Wo(n),staticParameters:{eventType:V.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}var ms=Object.getOwnPropertyDescriptor,gs=(e,t,n,o)=>{for(var r=o>1?void 0:o?ms(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},_e=(e,t)=>(n,o)=>t(n,o,e);let Ze=class extends l.Disposable{constructor(e,t,n,o,r,s,i){super(),this._injector=e,this._menuManagerService=t,this._commandService=n,this._shortcutService=o,this._uiPartsService=r,this._renderManagerService=s,this._componentManager=i,this._initialize()}_initialize(){this._registerCommands(),this._registerMenus(),this._registerShortcuts(),this._registerComponents(),this._registerRenderModules()}_registerMenus(){this._menuManagerService.mergeMenu(ss)}_registerCommands(){[Xe,Je,Qe,wt,At,Te,ut].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...as(),...ls(),...us(),...ds(),...hs(),fs].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(a.BuiltInUIPart.CONTENT,()=>a.connectInjector(wr,this._injector))),this.disposeWithMe(this._uiPartsService.registerComponent(w.SheetsUIPart.FORMULA_AUX,()=>a.connectInjector(ur,this._injector))),this._componentManager.register(Lt,es)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,[ze]))}};Ze=gs([_e(0,l.Inject(l.Injector)),_e(1,a.IMenuManagerService),_e(2,l.ICommandService),_e(3,a.IShortcutService),_e(4,a.IUIPartsService),_e(5,V.IRenderManagerService),_e(6,l.Inject(a.ComponentManager))],Ze);const ps=()=>{var o,r;const e=a.useDependency(gt),t=a.useObservable(e.currentSelector$),n=S.useRef(null);return S.useEffect(()=>{var s,i;if(t)return(i=n.current)==null||i.showDialog((s=t.initialValue)!=null?s:[]),()=>{var c;(c=n.current)==null||c.hideDialog()}},[t]),v.jsx(mt,{unitId:(o=t==null?void 0:t.unitId)!=null?o:"",subUnitId:(r=t==null?void 0:t.subUnitId)!=null?r:"",hideEditor:!0,selectorRef:n})};var Ss=Object.defineProperty,vs=Object.getOwnPropertyDescriptor,Cs=(e,t,n)=>t in e?Ss(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Is=(e,t,n,o)=>{for(var r=o>1?void 0:o?vs(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Be=(e,t)=>(n,o)=>t(n,o,e),Xt=(e,t,n)=>Cs(e,typeof t!="symbol"?t+"":t,n);exports.UniverSheetsFormulaUIPlugin=class extends l.Plugin{constructor(t=xt,n,o,r,s){super(),this._config=t,this._injector=n,this._renderManagerService=o,this._configService=r,this._uiPartsService=s;const{menu:i,...c}=l.merge(xt,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Uo,c,{merge:!0})}onStarting(){const t=this._injector;[[je,{useClass:ct}],[gt],[Ze],[qe],[Ye],[ze],[Ge]].forEach(r=>t.add(r));const o=this._injector.get(a.ComponentManager);o.register(w.RANGE_SELECTOR_COMPONENT_KEY,mt),o.register(w.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,Yt),this._initUIPart()}onRendered(){[[exports.RefSelectionsRenderService],[lt]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))}),l.touchDependencies(this._injector,[[Ze],[Ye],[Ge]])}onSteady(){this._injector.get(qe)}_initUIPart(){this.disposeWithMe(this._uiPartsService.registerComponent(a.BuiltInUIPart.GLOBAL,()=>a.connectInjector(ps,this._injector)))}};Xt(exports.UniverSheetsFormulaUIPlugin,"pluginName",Pt);Xt(exports.UniverSheetsFormulaUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFormulaUIPlugin=Is([l.DependentOn(F.UniverFormulaEnginePlugin,ye.UniverSheetsFormulaPlugin),Be(1,l.Inject(l.Injector)),Be(2,V.IRenderManagerService),Be(3,l.IConfigService),Be(4,a.IUIPartsService)],exports.UniverSheetsFormulaUIPlugin);exports.FORMULA_PROMPT_ACTIVATED=Ot;exports.FormulaEditor=Yt;exports.GlobalRangeSelectorService=gt;exports.HelpFunctionOperation=At;exports.InsertFunctionOperation=Je;exports.MoreFunctionsOperation=Qe;exports.RangeSelector=mt;exports.ReferenceAbsoluteOperation=ut;exports.SearchFunctionOperation=wt;exports.SelectEditorFormulaOperation=Te;exports.SheetOnlyPasteFormulaCommand=Xe;
|
|
23
|
+
`:fe.formulaSelectFunctionResultItem,onMouseEnter:()=>O(b),onMouseLeave:D,onClick:()=>$(b),children:[p===b&&v.jsx(jt,{className:fe.formulaSelectFunctionResultItemSelected}),v.jsx("span",{className:fe.formulaSelectFunctionResultItemName,children:N(M)})]},b))}),g&&v.jsxs("div",{className:fe.formulaSelectFunctionContent,children:[v.jsx(ke,{title:g.functionName,value:g.description}),v.jsx(ke,{title:C.t("formula.moreFunctions.syntax"),value:v.jsx(Zt,{prefix:g.functionName,value:g.functionParameter})}),v.jsx(ke,{title:C.t("formula.prompt.helpExample"),value:`${g.functionName}(${g.functionParameter.map(M=>M.example).join(",")})`}),g.functionParameter&&g.functionParameter.map(M=>v.jsx(ke,{title:M.name,value:`${M.require?_:x} ${M.detail}`},M.name))]})]})}function es(){const e=w.useActiveWorkbook(),[t,n]=S.useState(!0),[o,r]=S.useState(!1),[s,i]=S.useState(null);a.useDependency(w.IEditorBridgeService);const c=a.useDependency(l.LocaleService),d=a.useDependency(z.IEditorService),h=a.useDependency(l.IUniverInstanceService),f=a.useDependency(l.ICommandService);function p(){n(!t),r(!o)}function u(){const g=j.getSheetCommandTarget(h);if(!g)return;f.executeCommand(w.SetCellEditVisibleOperation.id,{visible:!0,unitId:g.unitId,eventType:V.DeviceInputEventType.Dblclick});const m=d.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),T=d.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),C=`=${s==null?void 0:s.functionName}(`;m==null||m.replaceText(C),T==null||T.replaceText(C,!1)}return v.jsxs("div",{className:Mt.formulaMoreFunctions,children:[t&&v.jsx(Qr,{onChange:i}),o&&v.jsx(Kr,{functionInfo:s,onChange:()=>{}}),v.jsxs("div",{className:Mt.formulaMoreFunctionsOperation,children:[o&&v.jsx(te.Button,{type:"primary",size:"small",onClick:p,children:c.t("formula.moreFunctions.next")}),o&&v.jsx(te.Button,{size:"small",onClick:p,children:c.t("formula.moreFunctions.prev")}),t&&!!e&&v.jsx(te.Button,{type:"primary",size:"small",onClick:u,children:c.t("formula.moreFunctions.confirm")})]})]})}function ts(e){return{id:Je.id,icon:"FunctionSingle",tooltip:"formula.insert.tooltip",type:a.MenuItemType.SELECTOR,selections:[{label:{name:"SUM",selectable:!1},value:"SUM",icon:"SumSingle"},{label:{name:"AVERAGE",selectable:!1},value:"AVERAGE",icon:"AvgSingle"},{label:{name:"COUNT",selectable:!1},value:"COUNT",icon:"CntSingle"},{label:{name:"MAX",selectable:!1},value:"MAX",icon:"MaxSingle"},{label:{name:"MIN",selectable:!1},value:"MIN",icon:"MinSingle"}],hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:w.getCurrentRangeDisable$(e,{workbookTypes:[j.WorkbookEditablePermission],worksheetTypes:[j.WorksheetEditPermission,j.WorksheetSetCellValuePermission],rangeTypes:[j.RangeProtectionPermissionEditPoint]})}}function ns(e){return{id:Qe.id,title:"formula.insert.more",type:a.MenuItemType.BUTTON}}function os(e){return e.get(l.IUniverInstanceService).getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(B.switchMap(o=>o&&e.get(a.IClipboardInterfaceService)?new B.Observable(s=>s.next(!e.get(a.IClipboardInterfaceService).supportClipboard)):B.of(!0)))}function rs(e){return{id:Xe.id,type:a.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:os(e).pipe(B.combineLatestWith(w.getCurrentRangeDisable$(e,{workbookTypes:[j.WorkbookEditablePermission],rangeTypes:[j.RangeProtectionPermissionEditPoint],worksheetTypes:[j.WorksheetSetCellValuePermission,j.WorksheetEditPermission]})),B.map(([t,n])=>t||n))}}const ss={[a.RibbonStartGroup.FORMULAS_INSERT]:{[Je.id]:{order:1,menuItemFactory:ts,[Qe.id]:{order:1,menuItemFactory:ns}}},[w.PASTE_SPECIAL_MENU_ID]:{[Xe.id]:{order:4,menuItemFactory:rs}}},is="meta_key_ctrl_And_Shift",tt=[a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP,a.KeyCode.ARROW_LEFT,a.KeyCode.ARROW_RIGHT],cs=[...tt,a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ESC];function as(){const e=[];for(const t of cs)e.push({id:Te.id,binding:t,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:V.DeviceInputEventType.Keyboard,keycode:t}});return e}function ls(){const e=[];for(const t of tt)e.push({id:Te.id,binding:t|a.MetaKeys.SHIFT,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:V.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.SHIFT}});return e}function us(){const e=[];for(const t of tt)e.push({id:Te.id,binding:t|a.MetaKeys.CTRL_COMMAND,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:V.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.CTRL_COMMAND}});return e}function ds(){const e=[];for(const t of tt)e.push({id:Te.id,binding:t|a.MetaKeys.SHIFT|a.MetaKeys.CTRL_COMMAND,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:V.DeviceInputEventType.Keyboard,keycode:t,metaKey:is}});return e}const fs={id:ut.id,binding:a.KeyCode.F4,preconditions:e=>w.whenFormulaEditorActivated(e)};function hs(){const e=[];for(const t of[a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP])e.push({id:Te.id,binding:t,preconditions:n=>Wo(n),staticParameters:{eventType:V.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}var ms=Object.getOwnPropertyDescriptor,gs=(e,t,n,o)=>{for(var r=o>1?void 0:o?ms(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},_e=(e,t)=>(n,o)=>t(n,o,e);let Ze=class extends l.Disposable{constructor(e,t,n,o,r,s,i){super(),this._injector=e,this._menuManagerService=t,this._commandService=n,this._shortcutService=o,this._uiPartsService=r,this._renderManagerService=s,this._componentManager=i,this._initialize()}_initialize(){this._registerCommands(),this._registerMenus(),this._registerShortcuts(),this._registerComponents(),this._registerRenderModules()}_registerMenus(){this._menuManagerService.mergeMenu(ss)}_registerCommands(){[Xe,Je,Qe,wt,At,Te,ut].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...as(),...ls(),...us(),...ds(),...hs(),fs].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(a.BuiltInUIPart.CONTENT,()=>a.connectInjector(wr,this._injector))),this.disposeWithMe(this._uiPartsService.registerComponent(w.SheetsUIPart.FORMULA_AUX,()=>a.connectInjector(ur,this._injector))),this._componentManager.register(Lt,es)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,[ze]))}};Ze=gs([_e(0,l.Inject(l.Injector)),_e(1,a.IMenuManagerService),_e(2,l.ICommandService),_e(3,a.IShortcutService),_e(4,a.IUIPartsService),_e(5,V.IRenderManagerService),_e(6,l.Inject(a.ComponentManager))],Ze);const ps=()=>{var o,r;const e=a.useDependency(gt),t=a.useObservable(e.currentSelector$),n=S.useRef(null);return S.useEffect(()=>{var s,i;if(t)return(i=n.current)==null||i.showDialog((s=t.initialValue)!=null?s:[]),()=>{var c;(c=n.current)==null||c.hideDialog()}},[t]),v.jsx(mt,{unitId:(o=t==null?void 0:t.unitId)!=null?o:"",subUnitId:(r=t==null?void 0:t.subUnitId)!=null?r:"",hideEditor:!0,selectorRef:n,onChange:(s,i)=>{var c;t==null||t.callback((c=i==null?void 0:i.split(",").map(d=>F.deserializeRangeWithSheet(d)))!=null?c:[])}})};var Ss=Object.defineProperty,vs=Object.getOwnPropertyDescriptor,Cs=(e,t,n)=>t in e?Ss(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Is=(e,t,n,o)=>{for(var r=o>1?void 0:o?vs(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Be=(e,t)=>(n,o)=>t(n,o,e),Xt=(e,t,n)=>Cs(e,typeof t!="symbol"?t+"":t,n);exports.UniverSheetsFormulaUIPlugin=class extends l.Plugin{constructor(t=xt,n,o,r,s){super(),this._config=t,this._injector=n,this._renderManagerService=o,this._configService=r,this._uiPartsService=s;const{menu:i,...c}=l.merge(xt,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Uo,c,{merge:!0})}onStarting(){const t=this._injector;[[je,{useClass:ct}],[gt],[Ze],[qe],[Ye],[ze],[Ge]].forEach(r=>t.add(r));const o=this._injector.get(a.ComponentManager);o.register(w.RANGE_SELECTOR_COMPONENT_KEY,mt),o.register(w.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,Yt),this._initUIPart()}onRendered(){[[exports.RefSelectionsRenderService],[lt]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))}),l.touchDependencies(this._injector,[[Ze],[Ye],[Ge]])}onSteady(){this._injector.get(qe)}_initUIPart(){this.disposeWithMe(this._uiPartsService.registerComponent(a.BuiltInUIPart.GLOBAL,()=>a.connectInjector(ps,this._injector)))}};Xt(exports.UniverSheetsFormulaUIPlugin,"pluginName",Pt);Xt(exports.UniverSheetsFormulaUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFormulaUIPlugin=Is([l.DependentOn(F.UniverFormulaEnginePlugin,ye.UniverSheetsFormulaPlugin),Be(1,l.Inject(l.Injector)),Be(2,V.IRenderManagerService),Be(3,l.IConfigService),Be(4,a.IUIPartsService)],exports.UniverSheetsFormulaUIPlugin);exports.FORMULA_PROMPT_ACTIVATED=Ot;exports.FormulaEditor=Yt;exports.GlobalRangeSelectorService=gt;exports.HelpFunctionOperation=At;exports.InsertFunctionOperation=Je;exports.MoreFunctionsOperation=Qe;exports.RangeSelector=mt;exports.ReferenceAbsoluteOperation=ut;exports.SearchFunctionOperation=wt;exports.SelectEditorFormulaOperation=Te;exports.SheetOnlyPasteFormulaCommand=Xe;
|