@univerjs/sheets-formula-ui 0.10.14 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +5 -3
- package/lib/index.css +1 -1
- package/lib/index.js +5 -3
- package/lib/umd/index.js +2 -2
- package/package.json +12 -12
package/lib/cjs/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var en=Object.defineProperty;var tn=(e,t,n)=>t in e?en(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var K=(e,t,n)=>tn(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),k=require("@univerjs/sheets-ui"),y=require("@univerjs/engine-formula"),q=require("rxjs"),ee=require("@univerjs/docs-ui"),H=require("@univerjs/engine-render"),P=require("@univerjs/sheets"),Ce=require("@univerjs/sheets-formula"),a=require("@univerjs/ui"),E=require("react/jsx-runtime"),_=require("react"),W=require("@univerjs/design"),xt=require("@univerjs/docs"),nn=require("rxjs/operators"),Qe={id:"sheet.command.paste-formula",type:l.CommandType.COMMAND,handler:async e=>e.get(l.ICommandService).executeCommand(k.SheetPasteCommand.id,{value:k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA})},xe={id:"formula-ui.operation.select-editor-formula",type:l.CommandType.OPERATION,handler:(e,t)=>!0};var rn=Object.getOwnPropertyDescriptor,sn=(e,t,n,s)=>{for(var r=s>1?void 0:s?rn(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},on=(e,t)=>(n,s)=>t(n,s,e);const Mt="FORMULA_PROMPT_ACTIVATED",Je=l.createIdentifier("formula-ui.prompt-service");let st=class{constructor(e){K(this,"_search$",new q.Subject);K(this,"_help$",new q.Subject);K(this,"_navigate$",new q.Subject);K(this,"_accept$",new q.Subject);K(this,"_acceptFormulaName$",new q.Subject);K(this,"search$",this._search$.asObservable());K(this,"help$",this._help$.asObservable());K(this,"navigate$",this._navigate$.asObservable());K(this,"accept$",this._accept$.asObservable());K(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());K(this,"_searching",!1);K(this,"_helping",!1);K(this,"_sequenceNodes",[]);K(this,"_isLockedOnSelectionChangeRefString",!1);K(this,"_isLockedOnSelectionInsertRefString",!1);this._contextService=e}dispose(){this._search$.complete(),this._help$.complete(),this._navigate$.complete(),this._accept$.complete(),this._acceptFormulaName$.complete(),this._sequenceNodes=[]}search(e){this._contextService.setContextValue(Mt,e.visible),this._searching=e.visible,this._search$.next(e)}isSearching(){return this._searching}help(e){this._helping=e.visible,this._help$.next(e)}isHelping(){return this._helping}navigate(e){this._navigate$.next(e)}accept(e){this._accept$.next(e)}acceptFormulaName(e){this._acceptFormulaName$.next(e)}getSequenceNodes(){return[...this._sequenceNodes]}setSequenceNodes(e){this._sequenceNodes=e}clearSequenceNodes(){this._sequenceNodes=[]}getCurrentSequenceNode(e){return this._sequenceNodes[this.getCurrentSequenceNodeIndex(e)]}getCurrentSequenceNodeByIndex(e){return this._sequenceNodes[e]}getCurrentSequenceNodeIndex(e){let t=0;const n=this._sequenceNodes[0];for(let s=0,r=this._sequenceNodes.length;s<r;s++){const o=this._sequenceNodes[s];if(typeof o=="string")t++;else{const{endIndex:i}=o;t=i}if(e<=t)return typeof n=="string"&&e!==0?s+1:s}return this._sequenceNodes.length}updateSequenceRef(e,t){const n=this._sequenceNodes[e];if(typeof n=="string"||n.nodeType!==y.sequenceNodeType.REFERENCE)return;const s=t.length-n.token.length,r={...n};r.token=t,r.endIndex+=s,this._sequenceNodes[e]=r;for(let o=e+1,i=this._sequenceNodes.length;o<i;o++){const c=this._sequenceNodes[o];if(typeof c=="string")continue;const d={...c};d.startIndex+=s,d.endIndex+=s,this._sequenceNodes[o]=d}}insertSequenceRef(e,t){const n=t.length,s=this.getCurrentSequenceNodeIndex(e);this._sequenceNodes.splice(s,0,{token:t,startIndex:e,endIndex:e+n-1,nodeType:y.sequenceNodeType.REFERENCE});for(let r=s+1,o=this._sequenceNodes.length;r<o;r++){const i=this._sequenceNodes[r];if(typeof i=="string")continue;const c={...i};c.startIndex+=n,c.endIndex+=n,this._sequenceNodes[r]=c}}insertSequenceString(e,t){const n=this.getCurrentSequenceNodeIndex(e),s=t.split("");this._sequenceNodes.splice(n,0,...s);const r=s.length;for(let o=n+r,i=this._sequenceNodes.length;o<i;o++){const c=this._sequenceNodes[o];if(typeof c=="string")continue;const d={...c};d.startIndex+=r,d.endIndex+=r,this._sequenceNodes[o]=d}}enableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!0}disableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!1}isLockedSelectionChange(){return this._isLockedOnSelectionChangeRefString}enableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!0}disableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!1}isLockedSelectionInsert(){return this._isLockedOnSelectionInsertRefString}};st=sn([on(0,l.IContextService)],st);const Ot={id:"formula-ui.operation.help-function",type:l.CommandType.OPERATION,handler:async(e,t)=>(e.get(Je).help(t),!0)},le={id:"formula-ui.operation.insert-function",type:l.CommandType.OPERATION,handler:async(e,t)=>{var I,b;const n=e.get(P.SheetsSelectionsService),s=e.get(ee.IEditorService),r=n.getCurrentSelections();if(!r||!r.length)return!1;const o=P.getSheetCommandTarget(e.get(l.IUniverInstanceService));if(!o)return!1;const{worksheet:i,unitId:c,subUnitId:d}=o,g=i.getCellMatrix(),{value:p}=t,m=e.get(l.ICommandService);e.get(k.IEditorBridgeService);const f=[],h=[];let u=null,R=0,v=0,C="";if(r.length===1&&(ln(r[0].range)||un(r[0].range)&&Rt(g,r[0].range))){const{range:O,primary:S}=r[0],x=(I=S==null?void 0:S.actualRow)!=null?I:O.startRow,N=(b=S==null?void 0:S.actualColumn)!=null?b:O.startColumn;u=O,R=x,v=N;const U=Ct(g,x,N);U&&(C=y.serializeRange(U))}else r.some(O=>{var N,U;const{range:S,primary:x}=O;if(Rt(g,S)){const $=(N=x==null?void 0:x.actualRow)!=null?N:S.startRow,w=(U=x==null?void 0:x.actualColumn)!=null?U:S.startColumn,L=Ct(g,$,w);if(!L)return u=S,R=$,v=w,!0;const D=y.serializeRange(L),M=`=${p}(${D})`;f.push({range:S,primary:{row:$,column:w},formula:M})}else{const{startRow:$,startColumn:w,endRow:L,endColumn:D}=S;if($===L){const M=dn(g,$,D,i.getColumnCount()-1),A=M===D?D-1:D,T=y.serializeRange({startRow:$,endRow:L,startColumn:w,endColumn:A}),F=`=${p}(${T})`;h.push({range:S,primary:{row:$,column:M},formula:F})}else{let M=-1;for(let T=w;T<=D;T++){const F=hn(g,T,L,i.getRowCount()-1);M=Math.max(M,F)}const A=M===L?L-1:L;for(let T=w;T<=D;T++){const F=y.serializeRange({startRow:$,endRow:A,startColumn:T,endColumn:T}),j=`=${p}(${F})`;h.push({range:S,primary:{row:M,column:T},formula:j})}}}return!1});if(u){const O=P.getCellAtRowCol(R,v,i),S={range:l.Rectangle.clone(u),primary:{startRow:O.startRow,startColumn:O.startColumn,endRow:O.endRow,endColumn:O.endColumn,actualRow:R,actualColumn:v,isMerged:O.isMerged,isMergedMainCell:O.startRow===R&&O.startColumn===v}},x={unitId:c,subUnitId:d,selections:[S]};await m.executeCommand(P.SetSelectionsOperation.id,x);const N=s.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),U=s.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);m.syncExecuteCommand(k.SetCellEditVisibleOperation.id,{visible:!0,unitId:c,eventType:H.DeviceInputEventType.Dblclick});const $=`=${p}(${C}`;N==null||N.replaceText($),U==null||U.replaceText($,!1)}return f.length===0&&h.length===0?!1:m.executeCommand(Ce.InsertFunctionCommand.id,{list:f,listOfRangeHasNumber:h})}};function Ct(e,t,n){const s=cn(e,t,n);if(s!==t)return{startRow:s,endRow:t-1,startColumn:n,endColumn:n};const r=an(e,t,n);return r!==n?{startRow:t,endRow:t,startColumn:r,endColumn:n-1}:null}function cn(e,t,n){let s=!1;if(t===0)return t;for(let r=t-1;r>=0;r--){const o=e.getValue(r,n);if(Le(o)&&!s){if(r===0)return 0;s=!0}else{if(s&&!Le(o))return r+1;if(s&&r===0)return 0}}return t}function an(e,t,n){let s=!1;if(n===0)return n;for(let r=n-1;r>=0;r--){const o=e.getValue(t,r);if(Le(o)&&!s){if(r===0)return 0;s=!0}else{if(s&&!Le(o))return r+1;if(s&&r===0)return 0}}return n}function Le(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return!1;const n=t.dataStream,r=n.substring(n.length-2,n.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n;return l.isRealNum(r)}return e&&(e.t===l.CellValueType.NUMBER||l.getCellValueType(e)===l.CellValueType.NUMBER)}function ln(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}function un(e){return e.startRow!==e.endRow&&e.startColumn!==e.endColumn}function Rt(e,t){for(let n=t.startRow;n<=t.endRow;n++)for(let s=t.startColumn;s<=t.endColumn;s++)if(Le(e.getValue(n,s)))return!1;return!0}function dn(e,t,n,s){for(let r=n;r<=s;r++)if(!e.getValue(t,r))return r;return s}function hn(e,t,n,s){for(let r=n;r<=s;r++)if(!e.getValue(r,t))return r;return s}const Nt="SHEET_FORMULA_UI_PLUGIN",Dt=`${Nt}_MORE_FUNCTIONS_COMPONENT`,et={id:"formula-ui.operation.more-functions",type:l.CommandType.OPERATION,handler:async e=>(e.get(a.ISidebarService).open({header:{title:"formula.insert.tooltip"},children:{label:Dt}}),!0)},ct={id:"formula-ui.operation.change-ref-to-absolute",type:l.CommandType.OPERATION,handler:async e=>!0},kt={id:"formula-ui.operation.search-function",type:l.CommandType.OPERATION,handler:async(e,t)=>(e.get(Je).search(t),!0)};var fn=Object.getOwnPropertyDescriptor,gn=(e,t,n,s)=>{for(var r=s>1?void 0:s?fn(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},He=(e,t)=>(n,s)=>t(n,s,e);exports.FormulaReorderController=class extends l.Disposable{constructor(t,n,s,r){super(),this._sheetInterceptorService=t,this._univerInstanceService=n,this._formulaDataModel=s,this._lexerTreeBuilder=r,this._initialize()}_initialize(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>t.id===P.ReorderRangeCommand.id?this._reorderFormula(t.params):{redos:[],undos:[]}}))}_reorderFormula(t){const n=[],s=[],{unitId:r,subUnitId:o,range:i,order:c}=t,d=this._univerInstanceService.getUniverSheetInstance(r),g=d==null?void 0:d.getSheetBySheetId(o);if(!g)return{redos:n,undos:s};const p=g.getCellMatrix(),m=new l.ObjectMatrix,f=new l.ObjectMatrix;let h=!1;return l.Range.foreach(i,(u,R)=>{let v=u;c.hasOwnProperty(u)&&(v=c[u]);const C=p.getValue(v,R);if(C!=null&&C.f||C!=null&&C.si){h=!0;const I=this._formulaDataModel.getFormulaStringByCell(v,R,o,r),b=this._lexerTreeBuilder.moveFormulaRefOffset(I,0,u-v),O=l.Tools.deepClone(C);O.f=b,O.si=null,m.setValue(u,R,O)}else m.setValue(u,R,C);f.setValue(u,R,p.getValue(u,R))}),h?(n.push({id:P.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:o,cellValue:m.getMatrix()}}),s.push({id:P.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:o,cellValue:f.getMatrix()}}),{redos:n,undos:s}):{redos:n,undos:s}}};exports.FormulaReorderController=gn([He(0,l.Inject(P.SheetInterceptorService)),He(1,l.Inject(l.IUniverInstanceService)),He(2,l.Inject(y.FormulaDataModel)),He(3,l.Inject(y.LexerTreeBuilder))],exports.FormulaReorderController);const wt="sheets-formula-ui.base.config",_t={};var mn=Object.getOwnPropertyDescriptor,pn=(e,t,n,s)=>{for(var r=s>1?void 0:s?mn(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Ae=(e,t)=>(n,s)=>t(n,s,e);const nt="SHEET_FORMULA_ALERT",Sn={[y.ErrorType.DIV_BY_ZERO]:"divByZero",[y.ErrorType.NAME]:"name",[y.ErrorType.VALUE]:"value",[y.ErrorType.NUM]:"num",[y.ErrorType.NA]:"na",[y.ErrorType.CYCLE]:"cycle",[y.ErrorType.REF]:"ref",[y.ErrorType.SPILL]:"spill",[y.ErrorType.CALC]:"calc",[y.ErrorType.ERROR]:"error",[y.ErrorType.CONNECT]:"connect",[y.ErrorType.NULL]:"null"};let ot=class extends l.Disposable{constructor(e,t,n,s,r,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=s,this._formulaDataModel=r,this._zenZoneService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(q.debounceTime(100)).subscribe(e=>{var t,n,s,r,o;if(e){const c=this._context.unit.getActiveSheet();if(!c)return;const d=c.getCell(e.location.row,e.location.col),g=(r=(s=(n=(t=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:t[e.location.unitId])==null?void 0:n[e.location.subUnitId])==null?void 0:s[e.location.row])==null?void 0:r[e.location.col];if(l.isICellData(d)){const p=y.extractFormulaError(d,!!g);if(!p){this._hideAlert();return}const m=this._cellAlertManagerService.currentAlert.get(nt),f=(o=m==null?void 0:m.alert)==null?void 0:o.location;if(f&&f.row===e.location.row&&f.col===e.location.col&&f.subUnitId===e.location.subUnitId&&f.unitId===e.location.unitId)return;this._cellAlertManagerService.showAlert({type:k.CellAlertType.ERROR,title:this._localeService.t("formula.error.title"),message:this._localeService.t(`formula.error.${Sn[p]}`),location:e.location,width:200,height:74,key:nt});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(nt)}};ot=pn([Ae(1,l.Inject(k.HoverManagerService)),Ae(2,l.Inject(k.CellAlertManagerService)),Ae(3,l.Inject(l.LocaleService)),Ae(4,l.Inject(y.FormulaDataModel)),Ae(5,a.IZenZoneService)],ot);var vn=Object.getOwnPropertyDescriptor,Cn=(e,t,n,s)=>{for(var r=s>1?void 0:s?vn(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},It=(e,t)=>(n,s)=>t(n,s,e);let Ye=class extends l.Disposable{constructor(e,t){super(),this._autoFillService=e,this._lexerTreeBuilder=t,this._registerAutoFill()}_registerAutoFill(){const e={type:k.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===k.DATA_TYPE.FORMULA,applyFunctions:{[k.APPLY_TYPE.COPY]:(t,n,s,r,o)=>{const{data:i,index:c}=t;return this._fillCopyFormula(i,n,s,c,r,o)}}};this._autoFillService.registerRule(e)}_fillCopyFormula(e,t,n,s,r,o){var g,p;const i=_n(r),c=[],d=new Map;for(let m=1;m<=t;m++){const f=(m-1)%e.length,h=s[f],u=l.Tools.deepClone(e[f]);if(u){const R=((g=e[f])==null?void 0:g.f)||"",v=((p=e[f])==null?void 0:p.si)||"",C=l.isFormulaString(R);if(l.isFormulaId(v))u.si=v,u.f=null,u.v=null,u.p=null,u.t=null,c.push(u);else if(C){let b=d.get(f);if(b)u.si=b,u.f=null,u.v=null,u.p=null,u.t=null;else{b=l.generateRandomId(6),d.set(f,b);const{offsetX:O,offsetY:S}=Rn(i,t,n,o,h),x=this._lexerTreeBuilder.moveFormulaRefOffset(R,O,S);u.si=b,u.f=x,u.v=null,u.p=null,u.t=null}c.push(u)}}}return c}};Ye=Cn([It(0,k.IAutoFillService),It(1,l.Inject(y.LexerTreeBuilder))],Ye);function Rn(e,t,n,s,r){const{source:o,target:i}=s,{rows:c}=i,{rows:d}=o;let g=0,p=0;switch(n){case l.Direction.UP:p=c[r]-d[r];break;case l.Direction.RIGHT:g=e;break;case l.Direction.DOWN:p=c[r]-d[r];break;case l.Direction.LEFT:g=-e*t;break}return{offsetX:g,offsetY:p}}function _n(e){let t=0;for(const n in e)e[n].forEach(s=>{t+=s.data.length});return t}var In=Object.getOwnPropertyDescriptor,En=(e,t,n,s)=>{for(var r=s>1?void 0:s?In(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Fe=(e,t)=>(n,s)=>t(n,s,e);const yn="default-paste-formula";let ze=class extends l.Disposable{constructor(e,t,n,s,r){super(),this._currentUniverSheet=e,this._lexerTreeBuilder=t,this._sheetClipboardService=n,this._injector=s,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:k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA,priority:10,specialPasteInfo:{label:"specialPaste.formula"},onPasteCells:(e,t,n,s)=>this._onPasteCells(e,t,n,s,!0)}}_pasteWithFormulaHook(){return{id:yn,priority:10,onPasteCells:(e,t,n,s)=>this._onPasteCells(e,t,n,s,!1)}}_onPasteCells(e,t,n,s,r){var f;if([k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH].includes(s.pasteType))return{undos:[],redos:[]};const i=this._currentUniverSheet.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),c=t.unitId||i.getUnitId(),d=t.subUnitId||((f=i.getActiveSheet())==null?void 0:f.getSheetId());if(!c||!d)return{undos:[],redos:[]};const g=t.range,p=n,m={copyType:s.copyType||k.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:s.pasteType};return this._injector.invoke(h=>bn(c,d,g,p,h,m,this._lexerTreeBuilder,this._formulaDataModel,r,e))}};ze=En([Fe(0,l.IUniverInstanceService),Fe(1,l.Inject(y.LexerTreeBuilder)),Fe(2,k.ISheetClipboardService),Fe(3,l.Inject(l.Injector)),Fe(4,l.Inject(y.FormulaDataModel))],ze);function bn(e,t,n,s,r,o,i,c,d=!1,g){const p=[],m=[],f=Tn(e,t,n,s,o,i,c,g);if(!f.hasValue())return{undos:[],redos:[]};const h={unitId:e,subUnitId:t,cellValue:f.getData()};p.push({id:P.SetRangeValuesMutation.id,params:h});const u=P.SetRangeValuesUndoMutationFactory(r,h);return m.push({id:P.SetRangeValuesMutation.id,params:u}),{undos:m,redos:p}}function Tn(e,t,n,s,r,o,i,c){return c?r.pasteType===k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE?Mn(e,t,n,s,i,c):r.pasteType===k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA?On(e,t,n,s,o,i,c):Nn(e,t,n,s,r.copyType,o,i,c):xn(e,t,n,s,i)}function xn(e,t,n,s,r){const o=new l.ObjectMatrix,i=r.getSheetFormulaData(e,t);return s.forValue((c,d,g)=>{var h;const p=n.rows[c],m=n.cols[d],f={};l.isFormulaString(g.v)?(f.v=null,f.f=`${g.v}`,f.si=null,f.p=null,o.setValue(p,m,f)):(h=i==null?void 0:i[p])!=null&&h[m]&&(f.v=g.v,f.f=null,f.si=null,f.p=null,o.setValue(p,m,f))}),o}function Mn(e,t,n,s,r,o){var g,p;const i=new l.ObjectMatrix,c=(p=(g=r.getArrayFormulaCellData())==null?void 0:g[o.unitId])==null?void 0:p[o.subUnitId],d=r.getSheetFormulaData(e,t);return s.forValue((m,f,h)=>{var b,O;const u=o.range.rows[m%o.range.rows.length],R=o.range.cols[f%o.range.cols.length],v=n.rows[m],C=n.cols[f],I={};if(l.isFormulaString(h.f)||l.isFormulaId(h.si))I.v=h.v,I.f=null,I.si=null,I.p=null,i.setValue(v,C,I);else if((b=c==null?void 0:c[u])!=null&&b[R]){const S=c[u][R];I.v=S.v,I.f=null,I.si=null,I.p=null,i.setValue(v,C,I)}else if((O=d==null?void 0:d[v])!=null&&O[C]){if(I.v=h.v,I.f=null,I.si=null,I.p=null,h.p){const S=At(h);S&&(I.v=S)}i.setValue(v,C,I)}}),i}function On(e,t,n,s,r,o,i){const c=new l.ObjectMatrix,d=new Map;return s.forValue((g,p,m)=>{const f=n.rows[g],h=n.cols[p],u={};if(l.isFormulaId(m.si)){if(i.unitId!==e||i.subUnitId!==t){const R=o.getFormulaStringByCell(i.range.rows[g%i.range.rows.length],i.range.cols[p%i.range.cols.length],i.subUnitId,i.unitId),v=n.cols[p]-i.range.cols[p%i.range.cols.length],C=n.rows[g]-i.range.rows[g%i.range.rows.length],I=r.moveFormulaRefOffset(R||"",v,C);u.si=null,u.f=I}else u.si=m.si,u.f=null;u.v=null,u.p=null,c.setValue(f,h,u)}else if(l.isFormulaString(m.f)){const R=`${g%i.range.rows.length}_${p%i.range.cols.length}`;let v=d.get(R);if(v)u.si=v,u.f=null;else{v=l.generateRandomId(6),d.set(R,v);const C=n.cols[p]-i.range.cols[p%i.range.cols.length],I=n.rows[g]-i.range.rows[g%i.range.rows.length],b=r.moveFormulaRefOffset(m.f||"",C,I);u.si=v,u.f=b}u.v=null,u.p=null,c.setValue(f,h,u)}else{if(u.v=m.v,u.f=null,u.si=null,u.p=null,m.p){const R=At(m);R&&(u.v=R)}c.setValue(f,h,u)}}),c}function Nn(e,t,n,s,r,o,i,c){const d=new l.ObjectMatrix,g=new Map,p=i.getSheetFormulaData(e,t),m=[];return r===k.COPY_TYPE.CUT?s.forValue((f,h,u)=>{const R=n.rows[f],v=n.cols[h],C={};if(l.isFormulaId(u.si)){if(l.isFormulaString(u.f))m.push(u.si),C.f=u.f,C.si=u.si;else if(m.includes(u.si))C.f=null,C.si=u.si;else{const I=i.getFormulaStringByCell(c.range.rows[f%c.range.rows.length],c.range.cols[h%c.range.cols.length],c.subUnitId,c.unitId);C.f=I,C.si=null}C.v=null,C.p=null,d.setValue(R,v,C)}else l.isFormulaString(u.f)&&(C.f=u.f,C.si=null,C.v=null,C.p=null,d.setValue(R,v,C))}):s.forValue((f,h,u)=>{var I;const R=n.rows[f],v=n.cols[h],C={};if(l.isFormulaId(u.si)){if(c.unitId!==e||c.subUnitId!==t){const b=i.getFormulaStringByCell(c.range.rows[f%c.range.rows.length],c.range.cols[h%c.range.cols.length],c.subUnitId,c.unitId),O=n.cols[h]-c.range.cols[h%c.range.cols.length],S=n.rows[f]-c.range.rows[f%c.range.rows.length],x=o.moveFormulaRefOffset(b||"",O,S);C.si=null,C.f=x}else C.si=u.si,C.f=null;C.v=null,C.p=null,d.setValue(R,v,C)}else if(l.isFormulaString(u.f)){const b=`${f%c.range.rows.length}_${h%c.range.cols.length}`;let O=g.get(b);if(O)C.si=O,C.f=null;else{O=l.generateRandomId(6),g.set(b,O);const S=n.cols[h]-c.range.cols[h%c.range.cols.length],x=n.rows[f]-c.range.rows[f%c.range.rows.length],N=o.moveFormulaRefOffset(u.f||"",S,x);C.si=O,C.f=N}C.v=null,C.p=null,d.setValue(R,v,C)}else(I=p==null?void 0:p[R])!=null&&I[v]&&(C.v=u.v,C.f=null,C.si=null,C.p=u.p,d.setValue(R,v,C))}),m.length>0&&new l.ObjectMatrix(p).forValue((f,h,u)=>{if(!(c.range.rows.includes(f)&&c.range.cols.includes(h))&&!(n.rows.includes(f)&&n.cols.includes(h))&&m.includes(u==null?void 0:u.si)){const R=i.getFormulaStringByCell(f,h,c.subUnitId,c.unitId);d.setValue(f,h,{f:R,si:null,v:null,p:null})}}),d}function At(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 Dn=Object.getOwnPropertyDescriptor,kn=(e,t,n,s)=>{for(var r=s>1?void 0:s?Dn(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},be=(e,t)=>(n,s)=>t(n,s,e);let Ge=class extends l.Disposable{constructor(t,n,s,r,o,i,c,d){super();K(this,"_previousShape");K(this,"_skeleton");this._context=t,this._sheetInterceptorService=n,this._formulaDataModel=s,this._themeService=r,this._renderManagerService=o,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,s;if(t==null)this._logService.debug("[FormulaEditorShowController]: should not receive currentSkeleton$ as null!");else{const{skeleton:r}=t,o=(s=(n=this._skeleton)==null?void 0:n.worksheet)==null?void 0:s.getSheetId();if(this._changeRuntime(r),o!==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(P.BEFORE_CELL_EDIT,{handler:(t,n,s)=>{var u,R,v,C;const{row:r,col:o,unitId:i,subUnitId:c,worksheet:d}=n,g=this._formulaDataModel.getArrayFormulaRange(),p=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return s(t);let m=null;const f=this._formulaDataModel.getFormulaStringByCell(r,o,c,i);if(f!==null&&(m={f}),t.v!=null&&t.v!==""&&((v=(R=(u=p[i])==null?void 0:u[c])==null?void 0:R[r])==null?void 0:v[o])==null)return m?{...t,...m}:s(t);const h=(C=g==null?void 0:g[i])==null?void 0:C[c];return h!=null&&(m=this._displayArrayFormulaRangeShape(h,r,o,i,c,d,m)),m?{...t,...m}:s(t)}})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{(t.id===y.SetFormulaCalculationResultMutation.id||t.id===y.SetArrayFormulaDataMutation.id&&n&&n.remove)&&this._removeArrayFormulaRangeShape()})),this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{P.SetWorksheetRowAutoHeightMutation.id===t.id&&requestIdleCallback(()=>{const n=t.params,{unitId:s,subUnitId:r,rowsAutoHeightInfo:o}=n;this._refreshArrayFormulaRangeShapeByRow(s,r,o)})}))}_displayArrayFormulaRangeShape(t,n,s,r,o,i,c){const d=this._formulaDataModel.getSheetFormulaData(r,o);return new l.ObjectMatrix(t).forValue((g,p,m)=>{var v;if(m==null)return!0;const{startRow:f,startColumn:h,endRow:u,endColumn:R}=m;if(g===n&&p===s)return this._createArrayFormulaRangeShape(m,r),!1;if(n>=f&&n<=u&&s>=h&&s<=R){const C=i.getCell(f,h);if((C==null?void 0:C.v)===y.ErrorType.SPILL)return;const I=(v=d==null?void 0:d[g])==null?void 0:v[p];return I==null||I.f==null?!0:(c==null&&(c={f:I.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(m,r),!1)}}),c}_createArrayFormulaRangeShape(t,n){const s=this._renderManagerService.getRenderById(n),r=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!s||!r)return;const{scene:o}=s;if(!o)return;const i={range:t,primary:null,style:{strokeWidth:1,stroke:this._themeService.getColorFromTheme("primary.600"),fill:new l.ColorKit(this._themeService.getColorFromTheme("white")).setAlpha(0).toString(),widgets:{}}},c=k.attachSelectionWithCoord(i,r),{rowHeaderWidth:d,columnHeaderHeight:g}=r,p=new k.SelectionControl(o,k.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:d,columnHeaderHeight:g});p.updateRangeBySelectionWithCoord(c),p.setEvent(!1),this._previousShape=p}_removeArrayFormulaRangeShape(){this._previousShape!=null&&(this._previousShape.dispose(),this._previousShape=null)}_refreshArrayFormulaRangeShape(t,n){if(this._previousShape){const{startRow:s,endRow:r,startColumn:o,endColumn:i}=this._previousShape.getRange(),c={startRow:s,endRow:r,startColumn:o,endColumn:i};this._removeArrayFormulaRangeShape(),this._createArrayFormulaRangeShape(c,t)}}_checkCurrentSheet(t,n){const s=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!s)return!1;const r=s.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,s){if(!this._checkCurrentSheet(t,n)||!this._previousShape)return;const{startRow:r,endRow:o,startColumn:i,endColumn:c}=this._previousShape.getRange();for(let d=0;d<s.length;d++){const{row:g}=s[d];if(r>=g){const p={startRow:r,endRow:o,startColumn:i,endColumn:c};this._refreshArrayFormulaRangeShape(t,p);break}}}};Ge=kn([be(1,l.Inject(P.SheetInterceptorService)),be(2,l.Inject(y.FormulaDataModel)),be(3,l.Inject(l.ThemeService)),be(4,H.IRenderManagerService),be(5,l.Inject(k.SheetSkeletonManagerService)),be(6,l.ICommandService),be(7,l.ILogService)],Ge);var wn=Object.getOwnPropertyDescriptor,An=(e,t,n,s)=>{for(var r=s>1?void 0:s?wn(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Et=(e,t)=>(n,s)=>t(n,s,e);const Fn={tl:{size:6,color:"#409f11"}};let Ze=class extends l.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(P.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,handler:(n,s,r)=>{var c,d,g,p;const o=(p=(g=(d=(c=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:c[s.unitId])==null?void 0:d[s.subUnitId])==null?void 0:g[s.row])==null?void 0:p[s.col];return!y.extractFormulaError(n,!!o)||!n||(n===s.rawData&&(n={...s.rawData}),n.markers={...n==null?void 0:n.markers,...Fn}),r(n)},priority:10}))}};Ze=An([Et(0,l.Inject(P.SheetInterceptorService)),Et(1,l.Inject(y.FormulaDataModel))],Ze);function Pn(){const e=a.useDependency(Ce.TriggerCalculationController),t=a.useDependency(l.ICommandService),n=a.useObservable(e.progress$),s=_.useCallback(()=>{t.executeCommand(y.SetFormulaCalculationStopMutation.id)},[t]),r=_.useCallback(()=>{e.clearProgress()},[e]);return E.jsx(a.ProgressBar,{progress:n,onTerminate:s,onClearProgress:r})}function Ln(e,t){return Object.keys(e).filter(n=>isNaN(Number(n))&&n!=="DefinedName").map(n=>({label:t.t(`formula.functionType.${n.toLocaleLowerCase()}`),value:`${e[n]}`}))}function Ft(e){if(!e.require&&!e.repeat)return`[${e.name}]`;if(e.require&&!e.repeat)return e.name;if(!e.require&&e.repeat)return`[${e.name},...]`;if(e.require&&e.repeat)return`${e.name},...`}function Pt(e){const{prefix:t,value:n}=e;return E.jsxs("div",{children:[E.jsxs("span",{children:[t,"("]}),n&&n.map((s,r)=>E.jsxs("span",{children:[E.jsx("span",{children:Ft(s)}),r===n.length-1?"":","]},r)),")"]})}function Pe(e){const{className:t,value:n,title:s}=e;return E.jsxs("div",{className:"univer-mb-2 univer-text-xs",children:[E.jsx("div",{className:W.clsx("univer-mb-2 univer-font-medium univer-text-gray-500 dark:!univer-text-gray-300",t),children:s}),E.jsx("div",{className:"univer-break-all univer-text-gray-900 dark:!univer-text-white",children:n})]})}function Un(e){const{functionInfo:t,onChange:n}=e;if(!t)return null;const[s,r]=_.useState([]),[o,i]=_.useState(t.functionParameter),[c,d]=_.useState(-1);return E.jsxs("div",{children:[E.jsx("div",{className:W.clsx("univer-h-[364px] univer-overflow-y-auto",W.scrollbarClassName),children:o.map((g,p)=>E.jsxs("div",{children:[E.jsx("div",{className:"univer-text-sm",children:g.name}),E.jsx("div",{className:"univer-mb-2 univer-mt-1"})]},p))}),E.jsx("div",{className:W.clsx("univer-flex-1 univer-p-3",W.borderLeftClassName),children:E.jsx(Pe,{title:c===-1?E.jsx(Pt,{prefix:t.functionName,value:o}):o[c].name,value:c===-1?t.description:o[c].detail})})]})}function Me({ref:e,...t}){const{icon:n,id:s,className:r,extend:o,...i}=t,c=`univerjs-icon univerjs-icon-${s} ${r||""}`.trim(),d=_.useRef(`_${Wn()}`);return Lt(n,`${s}`,{defIds:n.defIds,idSuffix:d.current},{ref:e,className:c,...i},o)}function Lt(e,t,n,s,r){return _.createElement(e.tag,{key:t,...$n(e,n,r),...s},(jn(e,n).children||[]).map((o,i)=>Lt(o,`${t}-${e.tag}-${i}`,n,void 0,r)))}function $n(e,t,n){const s={...e.attrs};n!=null&&n.colorChannel1&&s.fill==="colorChannel1"&&(s.fill=n.colorChannel1),e.tag==="mask"&&s.id&&(s.id=s.id+t.idSuffix),Object.entries(s).forEach(([o,i])=>{o==="mask"&&typeof i=="string"&&(s[o]=i.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:r}=t;return!r||r.length===0||(e.tag==="use"&&s["xlink:href"]&&(s["xlink:href"]=s["xlink:href"]+t.idSuffix),Object.entries(s).forEach(([o,i])=>{typeof i=="string"&&(s[o]=i.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),s}function jn(e,t){var s;const{defIds:n}=t;return!n||n.length===0?e:e.tag==="defs"&&((s=e.children)!=null&&s.length)?{...e,children:e.children.map(r=>typeof r.attrs.id=="string"&&n&&n.includes(r.attrs.id)?{...r,attrs:{...r.attrs,id:r.attrs.id+t.idSuffix}}:r)}:e}function Wn(){return Math.random().toString(36).substring(2,8)}Me.displayName="UniverIcon";const Vn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ut=_.forwardRef(function(t,n){return _.createElement(Me,Object.assign({},t,{id:"check-mark-icon",ref:n,icon:Vn}))});Ut.displayName="CheckMarkIcon";const Bn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},$t=_.forwardRef(function(t,n){return _.createElement(Me,Object.assign({},t,{id:"close-icon",ref:n,icon:Bn}))});$t.displayName="CloseIcon";const Hn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},jt=_.forwardRef(function(t,n){return _.createElement(Me,Object.assign({},t,{id:"delete-icon",ref:n,icon:Hn}))});jt.displayName="DeleteIcon";const Kn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},Wt=_.forwardRef(function(t,n){return _.createElement(Me,Object.assign({},t,{id:"increase-icon",ref:n,icon:Kn}))});Wt.displayName="IncreaseIcon";const qn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.90913 3.57564C6.14345 3.34132 6.52335 3.34132 6.75766 3.57564L10.7577 7.57564C10.992 7.80995 10.992 8.18985 10.7577 8.42417L6.75766 12.4242C6.52335 12.6585 6.14345 12.6585 5.90913 12.4242C5.67482 12.1899 5.67482 11.81 5.90913 11.5756L9.48487 7.9999L5.90913 4.42417C5.67482 4.18985 5.67482 3.80995 5.90913 3.57564Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Vt=_.forwardRef(function(t,n){return _.createElement(Me,Object.assign({},t,{id:"more-icon",ref:n,icon:qn}))});Vt.displayName="MoreIcon";const Yn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6185 12.4423C12.5907 12.2749 12.7773 12.15 12.9343 12.2308L15.4242 13.5126C15.6102 13.6084 15.5544 13.8745 15.3439 13.8955L14.2456 14.184L13.4521 15.1286C13.3495 15.2939 13.085 15.2463 13.0534 15.0568L12.6185 12.4423Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1 3.6C1 2.16406 2.16406 1 3.6 1H12.3C13.7359 1 14.9 2.16406 14.9 3.6V5.81156C14.9003 5.81881 14.9004 5.82609 14.9004 5.8334C14.9004 5.84071 14.9003 5.84799 14.9 5.85524V10.045C14.9003 10.0522 14.9004 10.0595 14.9004 10.0668C14.9004 10.3982 14.6318 10.6668 14.3004 10.6668H11.1668C10.8907 10.6668 10.6668 10.8907 10.6668 11.1668V14.3C10.6668 14.6314 10.3982 14.9 10.0668 14.9L10.05 14.8998L3.6 14.9C2.16406 14.9 1 13.7359 1 12.3V3.6ZM13.2 5.2334C13.4761 5.2334 13.7 5.00954 13.7 4.7334V3.6C13.7 2.8268 13.0732 2.2 12.3 2.2H11.1668C10.8907 2.2 10.6668 2.42386 10.6668 2.7V4.7334C10.6668 5.00954 10.8907 5.2334 11.1668 5.2334H13.2ZM10.6668 6.9334C10.6668 6.65726 10.8907 6.4334 11.1668 6.4334H13.2C13.4761 6.4334 13.7 6.65726 13.7 6.9334V8.9668C13.7 9.24294 13.4761 9.4668 13.2 9.4668H11.1668C10.8907 9.4668 10.6668 9.24294 10.6668 8.9668V6.9334ZM8.9668 5.2334C9.24294 5.2334 9.4668 5.00954 9.4668 4.7334V2.7C9.4668 2.42386 9.24294 2.2 8.9668 2.2H6.9334C6.65726 2.2 6.4334 2.42386 6.4334 2.7V4.7334C6.4334 5.00954 6.65726 5.2334 6.9334 5.2334L8.9668 5.2334ZM6.4334 6.9334C6.4334 6.65726 6.65726 6.4334 6.9334 6.4334L8.9668 6.4334C9.24294 6.4334 9.4668 6.65726 9.4668 6.9334V8.9668C9.4668 9.24294 9.24294 9.4668 8.9668 9.4668L6.9334 9.4668C6.65726 9.4668 6.4334 9.24294 6.4334 8.9668V6.9334ZM4.7334 5.2334C5.00954 5.2334 5.2334 5.00954 5.2334 4.7334V2.7C5.2334 2.42386 5.00954 2.2 4.7334 2.2H3.6C2.8268 2.2 2.2 2.8268 2.2 3.6V4.7334C2.2 5.00954 2.42386 5.2334 2.7 5.2334H4.7334ZM2.2 6.9334C2.2 6.65726 2.42386 6.4334 2.7 6.4334H4.7334C5.00954 6.4334 5.2334 6.65725 5.2334 6.9334V8.9668C5.2334 9.24294 5.00954 9.4668 4.7334 9.4668H2.7C2.42386 9.4668 2.2 9.24294 2.2 8.9668V6.9334ZM5.2334 11.1668C5.2334 10.8907 5.00954 10.6668 4.7334 10.6668H2.7C2.42386 10.6668 2.2 10.8907 2.2 11.1668V12.3C2.2 13.0732 2.8268 13.7 3.6 13.7H4.7334C5.00954 13.7 5.2334 13.4761 5.2334 13.2V11.1668ZM9.4668 11.1668C9.4668 10.8907 9.24294 10.6668 8.9668 10.6668H6.9334C6.65726 10.6668 6.4334 10.8907 6.4334 11.1668V13.2C6.4334 13.4761 6.65726 13.7 6.9334 13.7H8.9668C9.24294 13.7 9.4668 13.4761 9.4668 13.2V11.1668Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Bt=_.forwardRef(function(t,n){return _.createElement(Me,Object.assign({},t,{id:"select-range-icon",ref:n,icon:Yn}))});Bt.displayName="SelectRangeIcon";function zn(e){const{onChange:t}=e,n="-1",[s,r]=_.useState(""),[o,i]=_.useState([]),[c,d]=_.useState(0),[g,p]=_.useState(n),[m,f]=_.useState(0),[h,u]=_.useState(null),R=a.useDependency(Ce.IDescriptionService),v=a.useDependency(l.LocaleService),C=a.useDependency(a.ISidebarService),I=a.useObservable(C.sidebarOptions$),b=Ln(y.FunctionType,v);b.unshift({label:v.t("formula.moreFunctions.allFunctions"),value:n});const O=v.t("formula.prompt.required"),S=v.t("formula.prompt.optional");_.useEffect(()=>{U(n)},[]),_.useEffect(()=>{N(0)},[o]),_.useEffect(()=>{I!=null&&I.visible&&(r(""),i([]),d(0),p(n),f(0),u(null),U(n))},[I]);const x=M=>{if(s.trim()==="")return M;const A=new RegExp(`(${s.toLocaleUpperCase()})`);return M.split(A).filter(Boolean).map((F,j)=>F.match(A)?E.jsx("span",{className:"univer-text-red-500",children:F},j):F)},N=M=>{if(o.length===0){u(null);return}f(M);const A=R.getFunctionInfo(o[M].name);if(!A){u(null);return}u(A),t(A)};function U(M){p(M);const A=R.getSearchListByType(+M);i(A)}function $(M){r(M);const A=R.getSearchListByName(M);i(A)}function w(M){if(M.stopPropagation(),M.key==="ArrowDown"){const A=c+1;d(A===o.length?0:A)}else if(M.key==="ArrowUp"){const A=c-1;d(A===-1?o.length-1:A)}else M.key==="Enter"&&N(c)}const L=M=>{d(M)},D=()=>{d(-1)};return E.jsxs("div",{children:[E.jsxs("div",{className:"univer-flex univer-items-center univer-justify-between univer-gap-2",children:[E.jsx(W.Select,{value:g,options:b,onChange:U}),E.jsx(W.Input,{placeholder:v.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:w,value:s,onChange:$,size:"small",allowClear:!0})]}),o.length>0&&E.jsx("ul",{className:W.clsx("univer-mb-0 univer-mt-2 univer-box-border univer-max-h-72 univer-w-full univer-select-none univer-list-none univer-overflow-y-auto univer-rounded univer-p-3 univer-outline-none",W.borderClassName,W.scrollbarClassName),onKeyDown:w,tabIndex:-1,children:o.map(({name:M},A)=>E.jsxs("li",{className:W.clsx("univer-relative univer-box-border univer-cursor-pointer univer-rounded univer-px-7 univer-py-1 univer-text-sm univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200 dark:!univer-bg-gray-600":c===A}),onMouseEnter:()=>L(A),onMouseLeave:D,onClick:()=>N(A),children:[m===A&&E.jsx(Ut,{className:"univer-absolute univer-left-1.5 univer-top-1/2 univer-inline-flex -univer-translate-y-1/2 univer-text-base univer-text-primary-600"}),E.jsx("span",{className:"univer-block",children:x(M)})]},A))}),h&&E.jsxs("div",{className:W.clsx("univer-mx-0 univer-my-2 univer-overflow-y-auto",W.scrollbarClassName),children:[E.jsx(Pe,{title:h.functionName,value:h.description}),E.jsx(Pe,{title:v.t("formula.moreFunctions.syntax"),value:E.jsx(Pt,{prefix:h.functionName,value:h.functionParameter})}),E.jsx(Pe,{title:v.t("formula.prompt.helpExample"),value:`${h.functionName}(${h.functionParameter.map(M=>M.example).join(",")})`}),h.functionParameter&&h.functionParameter.map(M=>E.jsx(Pe,{title:M.name,value:`${M.require?O:S} ${M.detail}`},M.name))]})]})}function Gn(){const e=k.useActiveWorkbook(),[t,n]=_.useState(!0),[s,r]=_.useState(!1),[o,i]=_.useState(null);a.useDependency(k.IEditorBridgeService);const c=a.useDependency(l.LocaleService),d=a.useDependency(ee.IEditorService),g=a.useDependency(l.IUniverInstanceService),p=a.useDependency(l.ICommandService);function m(){n(!t),r(!s)}function f(){const h=P.getSheetCommandTarget(g);if(!h)return;p.executeCommand(k.SetCellEditVisibleOperation.id,{visible:!0,unitId:h.unitId,eventType:H.DeviceInputEventType.Dblclick});const u=d.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),R=d.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),v=`=${o==null?void 0:o.functionName}(`;u==null||u.replaceText(v),R==null||R.replaceText(v,!1)}return E.jsxs("div",{"data-u-comp":"sheets-formula-functions-panel",className:"univer-box-border univer-flex univer-h-full univer-flex-col univer-justify-between univer-py-2",children:[t&&E.jsx(zn,{onChange:i}),s&&E.jsx(Un,{functionInfo:o,onChange:()=>{}}),E.jsxs("div",{className:"univer-flex univer-justify-end",children:[s&&E.jsx(W.Button,{variant:"primary",onClick:m,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.next")}),s&&E.jsx(W.Button,{onClick:m,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.prev")}),t&&!!e&&E.jsx(W.Button,{variant:"primary",onClick:f,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.confirm")})]})]})}function Zn(e){return{id:le.id,title:"SUM",icon:"SumIcon",type:a.MenuItemType.BUTTON,params:{value:"SUM"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[P.WorkbookEditablePermission],worksheetTypes:[P.WorksheetEditPermission,P.WorksheetSetCellValuePermission],rangeTypes:[P.RangeProtectionPermissionEditPoint]})}}function Xn(e){return{id:le.id,title:"COUNT",icon:"CntIcon",type:a.MenuItemType.BUTTON,params:{value:"COUNT"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[P.WorkbookEditablePermission],worksheetTypes:[P.WorksheetEditPermission,P.WorksheetSetCellValuePermission],rangeTypes:[P.RangeProtectionPermissionEditPoint]})}}function Qn(e){return{id:le.id,title:"AVERAGE",icon:"AvgIcon",type:a.MenuItemType.BUTTON,params:{value:"AVERAGE"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[P.WorkbookEditablePermission],worksheetTypes:[P.WorksheetEditPermission,P.WorksheetSetCellValuePermission],rangeTypes:[P.RangeProtectionPermissionEditPoint]})}}function Jn(e){return{id:le.id,title:"MAX",icon:"MaxIcon",type:a.MenuItemType.BUTTON,params:{value:"MAX"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[P.WorkbookEditablePermission],worksheetTypes:[P.WorksheetEditPermission,P.WorksheetSetCellValuePermission],rangeTypes:[P.RangeProtectionPermissionEditPoint]})}}function er(e){return{id:le.id,title:"MIN",icon:"MinIcon",type:a.MenuItemType.BUTTON,params:{value:"MIN"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[P.WorkbookEditablePermission],worksheetTypes:[P.WorksheetEditPermission,P.WorksheetSetCellValuePermission],rangeTypes:[P.RangeProtectionPermissionEditPoint]})}}function tr(e){return{id:et.id,title:"formula.insert.more",tooltip:"formula.insert.tooltip",type:a.MenuItemType.BUTTON,hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[P.WorkbookEditablePermission],worksheetTypes:[P.WorksheetEditPermission,P.WorksheetSetCellValuePermission],rangeTypes:[P.RangeProtectionPermissionEditPoint]})}}function nr(e){return e.get(l.IUniverInstanceService).getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(q.switchMap(s=>s&&e.get(a.IClipboardInterfaceService)?new q.Observable(o=>o.next(!e.get(a.IClipboardInterfaceService).supportClipboard)):q.of(!0)))}function rr(e){return{id:Qe.id,type:a.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:nr(e).pipe(q.combineLatestWith(k.getCurrentRangeDisable$(e,{workbookTypes:[P.WorkbookEditablePermission],rangeTypes:[P.RangeProtectionPermissionEditPoint],worksheetTypes:[P.WorksheetSetCellValuePermission,P.WorksheetEditPermission]})),q.map(([t,n])=>t||n))}}const sr={[a.RibbonFormulasGroup.BASIC]:{[`${le.id}.sum`]:{order:0,menuItemFactory:Zn},[`${le.id}.count`]:{order:1,menuItemFactory:Xn},[`${le.id}.average`]:{order:2,menuItemFactory:Qn},[`${le.id}.max`]:{order:3,menuItemFactory:Jn},[`${le.id}.min`]:{order:4,menuItemFactory:er}},[a.RibbonFormulasGroup.OTHERS]:{[et.id]:{order:0,menuItemFactory:tr}},[k.PASTE_SPECIAL_MENU_ID]:{[Qe.id]:{order:4,menuItemFactory:rr}}},or="meta_key_ctrl_And_Shift";function ir(e){return e.getContextValue(l.FOCUSING_DOC)&&e.getContextValue(l.FOCUSING_UNIVER_EDITOR)}const tt=[a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP,a.KeyCode.ARROW_LEFT,a.KeyCode.ARROW_RIGHT],cr=[...tt,a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ESC];function ar(){const e=[];for(const t of cr)e.push({id:xe.id,binding:t,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t}});return e}function lr(){const e=[];for(const t of tt)e.push({id:xe.id,binding:t|a.MetaKeys.SHIFT,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.SHIFT}});return e}function ur(){const e=[];for(const t of tt)e.push({id:xe.id,binding:t|a.MetaKeys.CTRL_COMMAND,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.CTRL_COMMAND}});return e}function dr(){const e=[];for(const t of tt)e.push({id:xe.id,binding:t|a.MetaKeys.SHIFT|a.MetaKeys.CTRL_COMMAND,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,metaKey:or}});return e}const hr={id:ct.id,binding:a.KeyCode.F4,preconditions:e=>k.whenFormulaEditorActivated(e)};function fr(){const e=[];for(const t of[a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP])e.push({id:xe.id,binding:t,preconditions:n=>ir(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}const gr={id:Ce.QuickSumCommand.id,binding:a.MetaKeys.ALT|a.KeyCode.EQUAL,preconditions:k.whenSheetEditorFocused,mac:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.ALT|a.KeyCode.EQUAL,description:"shortcut.sheets-formula-ui.quick-sum",group:"4_sheet-edit"};var mr=Object.getOwnPropertyDescriptor,pr=(e,t,n,s)=>{for(var r=s>1?void 0:s?mr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Te=(e,t)=>(n,s)=>t(n,s,e);let Xe=class extends l.Disposable{constructor(e,t,n,s,r,o,i){super(),this._injector=e,this._menuManagerService=t,this._commandService=n,this._shortcutService=s,this._uiPartsService=r,this._renderManagerService=o,this._componentManager=i,this._initialize()}_initialize(){this._registerCommands(),this._registerMenus(),this._registerShortcuts(),this._registerComponents(),this._registerRenderModules()}_registerMenus(){this._menuManagerService.mergeMenu(sr)}_registerCommands(){[Qe,le,et,kt,Ot,xe,ct].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...ar(),...lr(),...ur(),...dr(),...fr(),gr,hr].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(k.SheetsUIPart.FORMULA_AUX,()=>a.connectInjector(Pn,this._injector))),this._componentManager.register(Dt,Gn)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,[Ge]))}};Xe=pr([Te(0,l.Inject(l.Injector)),Te(1,a.IMenuManagerService),Te(2,l.ICommandService),Te(3,a.IShortcutService),Te(4,a.IUIPartsService),Te(5,H.IRenderManagerService),Te(6,l.Inject(a.ComponentManager))],Xe);class at{constructor(){K(this,"_currentSelector$",new q.BehaviorSubject(null));K(this,"currentSelector$",this._currentSelector$.asObservable())}showRangeSelectorDialog(t){const n=t.callback,s=new Promise(r=>{t.callback=o=>{r(o),n(o)}});return this._currentSelector$.next(t),s}}var Sr=Object.getOwnPropertyDescriptor,vr=(e,t,n,s)=>{for(var r=s>1?void 0:s?Sr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},we=(e,t)=>(n,s)=>t(n,s,e);exports.RefSelectionsRenderService=class extends k.BaseSelectionRenderService{constructor(n,s,r,o,i,c,d){super(s,r,o,i,c);K(this,"_workbookSelections");K(this,"_eventDisposables");this._context=n,this._contextService=c,this._refSelectionsService=d,this._workbookSelections=this._refSelectionsService.getWorkbookSelections(this._context.unitId),this._initSelectionChangeListener(),this._initSkeletonChangeListener(),this._initUserActionSyncListener(),this._setSelectionStyle(Cr(this._themeService)),this._remainLastEnabled=!0,this._highlightHeader=!1}getLocation(){return this._skeleton.getLocation()}setRemainLastEnabled(n){this._remainLastEnabled=n}setSkipLastEnabled(n){this._skipLastEnabled=n}clearLastSelection(){const n=this._selectionControls[this._selectionControls.length-1];n&&(n.dispose(),this._selectionControls.pop())}enableSelectionChanging(){return this._disableSelectionChanging(),this._eventDisposables=this._initCanvasEventListeners(),l.toDisposable(()=>this._disableSelectionChanging())}_disableSelectionChanging(){var n;(n=this._eventDisposables)==null||n.dispose(),this._eventDisposables=null}disableSelectionChanging(){this._disableSelectionChanging()}_initCanvasEventListeners(){const n=this._getSheetObject(),{spreadsheetRowHeader:s,spreadsheetColumnHeader:r,spreadsheet:o,spreadsheetLeftTopPlaceholder:i}=n,{scene:c}=this._context,d=new l.DisposableCollection;return d.add(o==null?void 0:o.onPointerDown$.subscribeEvent((g,p)=>{this.inRefSelectionMode()&&(this._onPointerDown(g,o.zIndex+1,l.RANGE_TYPE.NORMAL,this._getActiveViewport(g)),g.button!==2&&p.stopPropagation())})),d.add(s==null?void 0:s.onPointerDown$.subscribeEvent((g,p)=>{if(!this.inRefSelectionMode())return;const m=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:f}=k.getCoordByOffset(g.offsetX,g.offsetY,c,m);k.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),f,l.RANGE_TYPE.ROW)||(this._onPointerDown(g,(o.zIndex||1)+1,l.RANGE_TYPE.ROW,this._getActiveViewport(g),H.ScrollTimerType.Y),g.button!==2&&p.stopPropagation())})),d.add(r==null?void 0:r.onPointerDown$.subscribeEvent((g,p)=>{if(!this.inRefSelectionMode())return;const m=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:f}=k.getCoordByOffset(g.offsetX,g.offsetY,c,m);k.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),f,l.RANGE_TYPE.COLUMN)||(this._onPointerDown(g,(o.zIndex||1)+1,l.RANGE_TYPE.COLUMN,this._getActiveViewport(g),H.ScrollTimerType.X),g.button!==2&&p.stopPropagation())})),d.add(i==null?void 0:i.onPointerDown$.subscribeEvent((g,p)=>{if(this._reset(),!this.inRefSelectionMode())return;const m=this._sheetSkeletonManagerService.getCurrent().skeleton,f=k.getAllSelection(m);this._addSelectionControlByModelData(f),this._selectionMoveStart$.next(this.getSelectionDataWithStyle());const h=c.onPointerUp$.subscribeEvent(()=>{h.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});g.button!==2&&p.stopPropagation()})),d}_addSelectionControlByModelData(n){var c;const s=this._skeleton,r=(c=n.style)!=null?c:k.genNormalSelectionStyle(this._themeService),o=this._scene;return n.style=r,this.newSelectionControl(o,s,n)}_initSelectionChangeListener(){this.disposeWithMe(this._refSelectionsService.selectionSet$.subscribe(n=>{this._reset(),this._skeleton&&this.resetSelectionsByModelData(n||[])}))}_initUserActionSyncListener(){this.disposeWithMe(this.selectionMoveStart$.subscribe(n=>{this._updateSelections(n,P.SelectionMoveType.MOVE_START)})),this.disposeWithMe(this.selectionMoving$.subscribe(n=>{this._updateSelections(n,P.SelectionMoveType.MOVING)})),this.disposeWithMe(this.selectionMoveEnd$.subscribe(n=>{this._updateSelections(n,P.SelectionMoveType.MOVE_END)}))}_updateSelections(n,s){const o=this._context.unit.getActiveSheet().getSheetId();n.length!==0&&this._workbookSelections.setSelections(o,n.map(i=>P.convertSelectionDataToRange(i)),s)}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(n=>{var c;if(!n)return;const{skeleton:s}=n,{scene:r}=this._context,o=r.getViewport(H.SHEET_VIEWPORT_KEY.VIEW_MAIN);this._skeleton&&((c=this._skeleton.worksheet)==null?void 0:c.getSheetId())!==s.worksheet.getSheetId()&&this._reset(),this._changeRuntime(s,r,o);const i=this._workbookSelections.getCurrentSelections();this.resetSelectionsByModelData(i)}))}_getActiveViewport(n){const s=this._getSheetObject();return s==null?void 0:s.scene.getActiveViewportByCoord(H.Vector2.FromArray([n.offsetX,n.offsetY]))}_getSheetObject(){return k.getSheetObject(this._context.unit,this._context)}_onPointerDown(n,s=0,r=l.RANGE_TYPE.NORMAL,o,i=H.ScrollTimerType.ALL){var L;this._rangeType=r;const c=this._skeleton,d=this._scene;if(!d||!c)return;o&&(this._activeViewport=o);const{offsetX:g,offsetY:p}=n,m=d.getViewport(H.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!m)return;const f=d.getCoordRelativeToViewport(H.Vector2.FromArray([g,p])),{x:h,y:u}=f;this._startViewportPosX=h,this._startViewportPosY=u;const R=d.getScrollXYInfoByViewport(f),{scaleX:v,scaleY:C}=d.getAncestorScale(),I=this._skeleton.getCellByOffset(h,u,v,C,R);if(!I)return;switch(r){case l.RANGE_TYPE.NORMAL:break;case l.RANGE_TYPE.ROW:I.startColumn=0,I.endColumn=this._skeleton.getColumnCount()-1;break;case l.RANGE_TYPE.COLUMN:I.startRow=0,I.endRow=this._skeleton.getRowCount()-1;break;case l.RANGE_TYPE.ALL:I.startRow=0,I.startColumn=0,I.endRow=this._skeleton.getRowCount()-1,I.endColumn=this._skeleton.getColumnCount()-1}const b={range:I,primary:I,style:null};b.range.rangeType=r;const O=k.attachSelectionWithCoord(b,this._skeleton);this._startRangeWhenPointerDown={...O.rangeWithCoord};const S={...O.rangeWithCoord,rangeType:r};let x=this.getActiveSelectionControl();const N=this.getSelectionControls();for(const D of N){if(n.button===2&&l.Rectangle.contains(D.model,S)){x=D;return}if(D.model.isEqual(S)){x=D;break}}this._checkClearPreviousControls(n);const U=x==null?void 0:x.model.currentCell,$=n.shiftKey&&U,w=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;$&&U?this._makeSelectionByTwoCells(U,S,c,r,x):w&&x?x.updateRangeBySelectionWithCoord(O):x=this.newSelectionControl(d,c,b);for(let D=0;D<this.getSelectionControls().length-1;D++)this.getSelectionControls()[D].clearHighlight();this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),d.disableObjectsEvent(),this._clearUpdatingListeners(),this._addEndingListeners(),(L=d.getTransformer())==null||L.clearSelectedObjects(),this._setupPointerMoveListener(m,x,r,i,h,u),this._escapeShortcutDisposable=this._shortcutService.forceEscape(),this._scenePointerUpSub=d.onPointerUp$.subscribeEvent(()=>{var D;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(D=this._escapeShortcutDisposable)==null||D.dispose(),this._escapeShortcutDisposable=null})}newSelectionControl(n,s,r){const o=this.getSelectionControls().length,{rowHeaderWidth:i,columnHeaderHeight:c}=s,d=new k.SelectionControl(n,o,this._themeService,{highlightHeader:this._highlightHeader,enableAutoFill:!1,rowHeaderWidth:i,columnHeaderHeight:c}),g=k.attachSelectionWithCoord(r,s);return d.updateRangeBySelectionWithCoord(g),this._selectionControls.push(d),d.setControlExtension({skeleton:s,scene:n,themeService:this._themeService,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),d}};exports.RefSelectionsRenderService=vr([we(1,l.Inject(l.Injector)),we(2,l.Inject(l.ThemeService)),we(3,a.IShortcutService),we(4,l.Inject(k.SheetSkeletonManagerService)),we(5,l.IContextService),we(6,P.IRefSelectionsService)],exports.RefSelectionsRenderService);function Cr(e){const t=k.genNormalSelectionStyle(e);return t.widgets={tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},t}const lt=(e,t,n=!0)=>{let s=-1;return e.reduce((r,o,i)=>{if(r.isFinish)return r;const c=r.currentIndex;if(typeof o!="string")r.currentIndex+=o.token.length;else{const d=o.length;r.currentIndex+=d}return(n?r.currentIndex===t:t>c&&t<=r.currentIndex)&&(s=i,r.isFinish=!0),r},{currentIndex:0,isFinish:!1}),s},Ht=(e,t)=>{const n=e[t];let s=-1;if(!n||typeof n=="string"||n.nodeType!==y.sequenceNodeType.REFERENCE)return-1;for(let r=0;r<=t;r++){const o=e[r];typeof o!="string"&&o.nodeType===y.sequenceNodeType.REFERENCE&&s++}return s},Rr=(e,t=100)=>{_.useEffect(()=>{let n=null;const s=()=>{n===null&&(n=window.setTimeout(()=>{e(),n=null},t))};return window.addEventListener("scroll",s),window.addEventListener("resize",s),()=>{n!==null&&clearTimeout(n),window.removeEventListener("scroll",s),window.removeEventListener("resize",s)}},[e,t])};function Kt(e,t,n){const s=a.useDependency(ee.IEditorService),r=_.useMemo(()=>new q.BehaviorSubject({left:-999,top:-999,right:-999,bottom:-999}),[]),o=a.useDependency(a.ISidebarService),i=a.useDependency(l.IUniverInstanceService),c=a.useEvent(()=>{var b;const d=s.getEditor(e);if(!d)return;const g=d.getBoundingClientRect(),{marginTop:p=0,marginBottom:m=0}=d.getDocumentData().documentStyle,f=d.getSkeleton();if(!f)return;const h=(b=f.getSkeletonData())==null?void 0:b.pages[0].height;let{left:u,top:R,right:v,bottom:C}=g;R=R+p,C=h?R+h:C-m;const I=r.getValue();if(!(I.left===u&&I.top===R&&I.right===v&&I.bottom===C))return r.next({left:u-1,right:v+1,top:R-1,bottom:C+1}),g});return _.useEffect(()=>{t&&c()},[e,s,i.unitAdded$,c,t,...n!=null?n:[]]),Rr(c),_.useEffect(()=>{const d=o.scrollEvent$.pipe(q.throttleTime(100)).subscribe(c);return()=>{d.unsubscribe()}},[]),[r,c]}const Oe=e=>{const t=_.useRef(e);return t.current=e,t},_r=(e,t,n)=>{const s=a.useDependency(Je),r=a.useDependency(Ce.IDescriptionService),o=a.useDependency(y.LexerTreeBuilder),[i,c]=_.useState(),[d,g]=_.useState(-1),[p,m]=_.useState(!0),f=Oe(p),h=_.useRef(t);h.current=t;const u=()=>{c(void 0),g(-1),m(!1)};return _.useEffect(()=>{const R=o.sequenceNodesBuilder(t.slice(1));s.setSequenceNodes(R!=null?R:[])},[t]),_.useEffect(()=>{if(n&&e){const R=n.selectionChange$.pipe(q.debounceTime(50)).subscribe(C=>{if(C.textRanges.length===1){const[I]=C.textRanges;if(I.collapsed&&f.current){const{startOffset:b}=I,O=s.getCurrentSequenceNodeIndex(b-2),S=s.getCurrentSequenceNodeByIndex(O),x=s.getCurrentSequenceNodeByIndex(O+1);if(S)if(typeof S!="string"&&S.nodeType===3&&!r.hasDefinedNameDescription(S.token.trim())&&x===y.matchToken.OPEN_BRACKET){const N=r.getFunctionInfo(S.token);c(N),g(-1);return}else{const N=o.getFunctionAndParameter(`${h.current}A`,b-1);if(N){const{functionName:U,paramIndex:$}=N,w=r.getFunctionInfo(U);c(w),g($);return}}}}c(void 0),g(-1)}),v=n.selectionChange$.pipe(q.filter(C=>C.textRanges.length===1),q.map(C=>C.textRanges[0].startOffset),q.distinctUntilChanged()).subscribe(()=>{m(!0)});return()=>{R.unsubscribe(),v.unsubscribe()}}},[n,e]),_.useEffect(()=>{e||u()},[e]),{functionInfo:i,paramIndex:d,reset:u}},Ir=({onClick:e})=>E.jsx("div",{className:"univer-z-[15] univer-box-border univer-h-[18px] univer-cursor-pointer univer-overflow-visible univer-whitespace-nowrap univer-rounded-l univer-border univer-border-r-0 univer-border-gray-600 univer-bg-primary-600 univer-p-0.5 univer-text-xs univer-font-bold univer-leading-[13px] univer-text-white",onClick:e,children:"?"}),rt=({className:e,title:t,value:n})=>E.jsxs("div",{className:"univer-my-2",children:[E.jsx("div",{className:W.clsx("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",e),children:t}),E.jsx("div",{className:"univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",children:n})]}),Er=e=>{const{prefix:t,value:n,active:s,onClick:r}=e;return E.jsxs("div",{children:[E.jsxs("span",{children:[t,"("]}),n&&n.map((o,i)=>E.jsxs("span",{children:[E.jsx("span",{className:s===i?"univer-text-primary-500":"",onClick:()=>r(i),children:Ft(o)}),i===n.length-1?"":","]},o.name)),")"]})},yt=()=>{};function yr(e){const{onParamsSwitch:t=yt,onClose:n=yt,isFocus:s,editor:r,formulaText:o}=e,{functionInfo:i,paramIndex:c,reset:d}=_r(s,o,r),g=a.useDependency(k.IEditorBridgeService),p=!a.useObservable(g.helpFunctionVisible$),[m,f]=_.useState(!0),h=a.useDependency(l.LocaleService),u=h.t("formula.prompt.required"),R=h.t("formula.prompt.optional"),v=r.getEditorId(),[C]=Kt(v,!!i,[i,c]);function I(S){t&&t(S)}const b=a.useEvent(S=>{g.helpFunctionVisible$.next(!S)}),O=()=>{b(!0),n()};return i?p?E.jsx(a.RectPopup,{portal:!0,anchorRect$:C,direction:"left-center",children:E.jsx(Ir,{onClick:()=>b(!1)})},"hidden"):E.jsx(a.RectPopup,{portal:!0,onClickOutside:()=>d(),anchorRect$:C,direction:"vertical",children:E.jsxs("div",{className:W.clsx("univer-m-0 univer-box-border univer-w-[250px] univer-select-none univer-list-none univer-rounded-lg univer-bg-white univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",W.borderClassName),children:[E.jsxs("div",{className:W.clsx("univer-wrap-anywhere univer-box-border univer-flex univer-items-center univer-justify-between univer-px-4 univer-py-3 univer-text-xs univer-font-medium univer-text-gray-900 dark:!univer-text-white",W.borderTopClassName),children:[E.jsx(Er,{prefix:i.functionName,value:i.functionParameter,active:c,onClick:I}),E.jsxs("div",{className:"univer-flex",children:[E.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-500 univer-outline-none univer-transition-colors hover:univer-bg-gray-200 dark:hover:!univer-bg-gray-600",style:{transform:m?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>f(!m),children:E.jsx(Vt,{})}),E.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-600 univer-outline-none univer-transition-colors hover:univer-bg-gray-300 dark:!univer-text-gray-200 dark:hover:!univer-bg-gray-600",onClick:O,children:E.jsx($t,{})})]})]}),E.jsx("div",{className:W.clsx("univer-box-border univer-max-h-[350px] univer-overflow-y-auto univer-px-4 univer-pb-3 univer-pt-0",W.scrollbarClassName),style:{height:m?"unset":0,padding:m?"revert-layer":0},children:E.jsxs("div",{className:"univer-mt-3",children:[E.jsx(rt,{title:h.t("formula.prompt.helpExample"),value:`${i.functionName}(${i.functionParameter.map(S=>S.example).join(",")})`}),E.jsx(rt,{title:h.t("formula.prompt.helpAbstract"),value:i.description}),i&&i.functionParameter&&i.functionParameter.map((S,x)=>E.jsx(rt,{className:c===x?"univer-text-primary-500":"",title:S.name,value:`${S.require?u:R} ${S.detail}`},x))]})})]})},"show"):null}const br=e=>{const t=a.useDependency(ee.IEditorService);return a.useEvent(s=>{var r,o;if(e){t.focus(e.getEditorId());const i=[...e.getSelectionRanges()];if(l.Tools.isDefine(s))e.setSelectionRanges([{startOffset:s,endOffset:s}]);else if(!i.length&&!e.docSelectionRenderService.isOnPointerEvent){const c=(o=(r=e.getDocumentData().body)==null?void 0:r.dataStream)!=null?o:`\r
|
|
1
|
+
"use strict";var en=Object.defineProperty;var tn=(e,t,n)=>t in e?en(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var K=(e,t,n)=>tn(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),k=require("@univerjs/sheets-ui"),y=require("@univerjs/engine-formula"),q=require("rxjs"),ee=require("@univerjs/docs-ui"),H=require("@univerjs/engine-render"),P=require("@univerjs/sheets"),Ce=require("@univerjs/sheets-formula"),a=require("@univerjs/ui"),E=require("react/jsx-runtime"),_=require("react"),W=require("@univerjs/design"),xt=require("@univerjs/docs"),nn=require("rxjs/operators"),Qe={id:"sheet.command.paste-formula",type:l.CommandType.COMMAND,handler:async e=>e.get(l.ICommandService).executeCommand(k.SheetPasteCommand.id,{value:k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA})},xe={id:"formula-ui.operation.select-editor-formula",type:l.CommandType.OPERATION,handler:(e,t)=>!0};var rn=Object.getOwnPropertyDescriptor,sn=(e,t,n,s)=>{for(var r=s>1?void 0:s?rn(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},on=(e,t)=>(n,s)=>t(n,s,e);const Mt="FORMULA_PROMPT_ACTIVATED",Je=l.createIdentifier("formula-ui.prompt-service");let st=class{constructor(e){K(this,"_search$",new q.Subject);K(this,"_help$",new q.Subject);K(this,"_navigate$",new q.Subject);K(this,"_accept$",new q.Subject);K(this,"_acceptFormulaName$",new q.Subject);K(this,"search$",this._search$.asObservable());K(this,"help$",this._help$.asObservable());K(this,"navigate$",this._navigate$.asObservable());K(this,"accept$",this._accept$.asObservable());K(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());K(this,"_searching",!1);K(this,"_helping",!1);K(this,"_sequenceNodes",[]);K(this,"_isLockedOnSelectionChangeRefString",!1);K(this,"_isLockedOnSelectionInsertRefString",!1);this._contextService=e}dispose(){this._search$.complete(),this._help$.complete(),this._navigate$.complete(),this._accept$.complete(),this._acceptFormulaName$.complete(),this._sequenceNodes=[]}search(e){this._contextService.setContextValue(Mt,e.visible),this._searching=e.visible,this._search$.next(e)}isSearching(){return this._searching}help(e){this._helping=e.visible,this._help$.next(e)}isHelping(){return this._helping}navigate(e){this._navigate$.next(e)}accept(e){this._accept$.next(e)}acceptFormulaName(e){this._acceptFormulaName$.next(e)}getSequenceNodes(){return[...this._sequenceNodes]}setSequenceNodes(e){this._sequenceNodes=e}clearSequenceNodes(){this._sequenceNodes=[]}getCurrentSequenceNode(e){return this._sequenceNodes[this.getCurrentSequenceNodeIndex(e)]}getCurrentSequenceNodeByIndex(e){return this._sequenceNodes[e]}getCurrentSequenceNodeIndex(e){let t=0;const n=this._sequenceNodes[0];for(let s=0,r=this._sequenceNodes.length;s<r;s++){const o=this._sequenceNodes[s];if(typeof o=="string")t++;else{const{endIndex:i}=o;t=i}if(e<=t)return typeof n=="string"&&e!==0?s+1:s}return this._sequenceNodes.length}updateSequenceRef(e,t){const n=this._sequenceNodes[e];if(typeof n=="string"||n.nodeType!==y.sequenceNodeType.REFERENCE)return;const s=t.length-n.token.length,r={...n};r.token=t,r.endIndex+=s,this._sequenceNodes[e]=r;for(let o=e+1,i=this._sequenceNodes.length;o<i;o++){const c=this._sequenceNodes[o];if(typeof c=="string")continue;const d={...c};d.startIndex+=s,d.endIndex+=s,this._sequenceNodes[o]=d}}insertSequenceRef(e,t){const n=t.length,s=this.getCurrentSequenceNodeIndex(e);this._sequenceNodes.splice(s,0,{token:t,startIndex:e,endIndex:e+n-1,nodeType:y.sequenceNodeType.REFERENCE});for(let r=s+1,o=this._sequenceNodes.length;r<o;r++){const i=this._sequenceNodes[r];if(typeof i=="string")continue;const c={...i};c.startIndex+=n,c.endIndex+=n,this._sequenceNodes[r]=c}}insertSequenceString(e,t){const n=this.getCurrentSequenceNodeIndex(e),s=t.split("");this._sequenceNodes.splice(n,0,...s);const r=s.length;for(let o=n+r,i=this._sequenceNodes.length;o<i;o++){const c=this._sequenceNodes[o];if(typeof c=="string")continue;const d={...c};d.startIndex+=r,d.endIndex+=r,this._sequenceNodes[o]=d}}enableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!0}disableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!1}isLockedSelectionChange(){return this._isLockedOnSelectionChangeRefString}enableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!0}disableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!1}isLockedSelectionInsert(){return this._isLockedOnSelectionInsertRefString}};st=sn([on(0,l.IContextService)],st);const Ot={id:"formula-ui.operation.help-function",type:l.CommandType.OPERATION,handler:async(e,t)=>(e.get(Je).help(t),!0)},le={id:"formula-ui.operation.insert-function",type:l.CommandType.OPERATION,handler:async(e,t)=>{var I,b;const n=e.get(P.SheetsSelectionsService),s=e.get(ee.IEditorService),r=n.getCurrentSelections();if(!r||!r.length)return!1;const o=P.getSheetCommandTarget(e.get(l.IUniverInstanceService));if(!o)return!1;const{worksheet:i,unitId:c,subUnitId:d}=o,g=i.getCellMatrix(),{value:p}=t,m=e.get(l.ICommandService);e.get(k.IEditorBridgeService);const f=[],h=[];let u=null,R=0,v=0,C="";if(r.length===1&&(ln(r[0].range)||un(r[0].range)&&Rt(g,r[0].range))){const{range:O,primary:S}=r[0],x=(I=S==null?void 0:S.actualRow)!=null?I:O.startRow,N=(b=S==null?void 0:S.actualColumn)!=null?b:O.startColumn;u=O,R=x,v=N;const U=Ct(g,x,N);U&&(C=y.serializeRange(U))}else r.some(O=>{var N,U;const{range:S,primary:x}=O;if(Rt(g,S)){const $=(N=x==null?void 0:x.actualRow)!=null?N:S.startRow,w=(U=x==null?void 0:x.actualColumn)!=null?U:S.startColumn,L=Ct(g,$,w);if(!L)return u=S,R=$,v=w,!0;const D=y.serializeRange(L),M=`=${p}(${D})`;f.push({range:S,primary:{row:$,column:w},formula:M})}else{const{startRow:$,startColumn:w,endRow:L,endColumn:D}=S;if($===L){const M=dn(g,$,D,i.getColumnCount()-1),A=M===D?D-1:D,T=y.serializeRange({startRow:$,endRow:L,startColumn:w,endColumn:A}),F=`=${p}(${T})`;h.push({range:S,primary:{row:$,column:M},formula:F})}else{let M=-1;for(let T=w;T<=D;T++){const F=hn(g,T,L,i.getRowCount()-1);M=Math.max(M,F)}const A=M===L?L-1:L;for(let T=w;T<=D;T++){const F=y.serializeRange({startRow:$,endRow:A,startColumn:T,endColumn:T}),j=`=${p}(${F})`;h.push({range:S,primary:{row:M,column:T},formula:j})}}}return!1});if(u){const O=P.getCellAtRowCol(R,v,i),S={range:l.Rectangle.clone(u),primary:{startRow:O.startRow,startColumn:O.startColumn,endRow:O.endRow,endColumn:O.endColumn,actualRow:R,actualColumn:v,isMerged:O.isMerged,isMergedMainCell:O.startRow===R&&O.startColumn===v}},x={unitId:c,subUnitId:d,selections:[S]};await m.executeCommand(P.SetSelectionsOperation.id,x);const N=s.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),U=s.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);m.syncExecuteCommand(k.SetCellEditVisibleOperation.id,{visible:!0,unitId:c,eventType:H.DeviceInputEventType.Dblclick});const $=`=${p}(${C}`;N==null||N.replaceText($),U==null||U.replaceText($,!1)}return f.length===0&&h.length===0?!1:m.executeCommand(Ce.InsertFunctionCommand.id,{list:f,listOfRangeHasNumber:h})}};function Ct(e,t,n){const s=cn(e,t,n);if(s!==t)return{startRow:s,endRow:t-1,startColumn:n,endColumn:n};const r=an(e,t,n);return r!==n?{startRow:t,endRow:t,startColumn:r,endColumn:n-1}:null}function cn(e,t,n){let s=!1;if(t===0)return t;for(let r=t-1;r>=0;r--){const o=e.getValue(r,n);if(Le(o)&&!s){if(r===0)return 0;s=!0}else{if(s&&!Le(o))return r+1;if(s&&r===0)return 0}}return t}function an(e,t,n){let s=!1;if(n===0)return n;for(let r=n-1;r>=0;r--){const o=e.getValue(t,r);if(Le(o)&&!s){if(r===0)return 0;s=!0}else{if(s&&!Le(o))return r+1;if(s&&r===0)return 0}}return n}function Le(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return!1;const n=t.dataStream,r=n.substring(n.length-2,n.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n;return l.isRealNum(r)}return e&&(e.t===l.CellValueType.NUMBER||l.getCellValueType(e)===l.CellValueType.NUMBER)}function ln(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}function un(e){return e.startRow!==e.endRow&&e.startColumn!==e.endColumn}function Rt(e,t){for(let n=t.startRow;n<=t.endRow;n++)for(let s=t.startColumn;s<=t.endColumn;s++)if(Le(e.getValue(n,s)))return!1;return!0}function dn(e,t,n,s){for(let r=n;r<=s;r++)if(!e.getValue(t,r))return r;return s}function hn(e,t,n,s){for(let r=n;r<=s;r++)if(!e.getValue(r,t))return r;return s}const Nt="SHEET_FORMULA_UI_PLUGIN",Dt=`${Nt}_MORE_FUNCTIONS_COMPONENT`,et={id:"formula-ui.operation.more-functions",type:l.CommandType.OPERATION,handler:async e=>(e.get(a.ISidebarService).open({header:{title:"formula.insert.tooltip"},children:{label:Dt}}),!0)},ct={id:"formula-ui.operation.change-ref-to-absolute",type:l.CommandType.OPERATION,handler:async e=>!0},kt={id:"formula-ui.operation.search-function",type:l.CommandType.OPERATION,handler:async(e,t)=>(e.get(Je).search(t),!0)};var fn=Object.getOwnPropertyDescriptor,gn=(e,t,n,s)=>{for(var r=s>1?void 0:s?fn(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},He=(e,t)=>(n,s)=>t(n,s,e);exports.FormulaReorderController=class extends l.Disposable{constructor(t,n,s,r){super(),this._sheetInterceptorService=t,this._univerInstanceService=n,this._formulaDataModel=s,this._lexerTreeBuilder=r,this._initialize()}_initialize(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>t.id===P.ReorderRangeCommand.id?this._reorderFormula(t.params):{redos:[],undos:[]}}))}_reorderFormula(t){const n=[],s=[],{unitId:r,subUnitId:o,range:i,order:c}=t,d=this._univerInstanceService.getUniverSheetInstance(r),g=d==null?void 0:d.getSheetBySheetId(o);if(!g)return{redos:n,undos:s};const p=g.getCellMatrix(),m=new l.ObjectMatrix,f=new l.ObjectMatrix;let h=!1;return l.Range.foreach(i,(u,R)=>{let v=u;c.hasOwnProperty(u)&&(v=c[u]);const C=p.getValue(v,R);if(C!=null&&C.f||C!=null&&C.si){h=!0;const I=this._formulaDataModel.getFormulaStringByCell(v,R,o,r),b=this._lexerTreeBuilder.moveFormulaRefOffset(I,0,u-v),O=l.Tools.deepClone(C);O.f=b,O.si=null,m.setValue(u,R,O)}else m.setValue(u,R,C);f.setValue(u,R,p.getValue(u,R))}),h?(n.push({id:P.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:o,cellValue:m.getMatrix()}}),s.push({id:P.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:o,cellValue:f.getMatrix()}}),{redos:n,undos:s}):{redos:n,undos:s}}};exports.FormulaReorderController=gn([He(0,l.Inject(P.SheetInterceptorService)),He(1,l.Inject(l.IUniverInstanceService)),He(2,l.Inject(y.FormulaDataModel)),He(3,l.Inject(y.LexerTreeBuilder))],exports.FormulaReorderController);const wt="sheets-formula-ui.base.config",_t={};var mn=Object.getOwnPropertyDescriptor,pn=(e,t,n,s)=>{for(var r=s>1?void 0:s?mn(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Ae=(e,t)=>(n,s)=>t(n,s,e);const nt="SHEET_FORMULA_ALERT",Sn={[y.ErrorType.DIV_BY_ZERO]:"divByZero",[y.ErrorType.NAME]:"name",[y.ErrorType.VALUE]:"value",[y.ErrorType.NUM]:"num",[y.ErrorType.NA]:"na",[y.ErrorType.CYCLE]:"cycle",[y.ErrorType.REF]:"ref",[y.ErrorType.SPILL]:"spill",[y.ErrorType.CALC]:"calc",[y.ErrorType.ERROR]:"error",[y.ErrorType.CONNECT]:"connect",[y.ErrorType.NULL]:"null"};let ot=class extends l.Disposable{constructor(e,t,n,s,r,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=s,this._formulaDataModel=r,this._zenZoneService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(q.debounceTime(100)).subscribe(e=>{var t,n,s,r,o;if(e){const c=this._context.unit.getActiveSheet();if(!c)return this._hideAlert();const d=c.getCell(e.location.row,e.location.col),g=(r=(s=(n=(t=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:t[e.location.unitId])==null?void 0:n[e.location.subUnitId])==null?void 0:s[e.location.row])==null?void 0:r[e.location.col];if(l.isICellData(d)){const p=y.extractFormulaError(d,!!g);if(!p){this._hideAlert();return}const m=this._cellAlertManagerService.currentAlert.get(nt),f=(o=m==null?void 0:m.alert)==null?void 0:o.location;if(f&&f.row===e.location.row&&f.col===e.location.col&&f.subUnitId===e.location.subUnitId&&f.unitId===e.location.unitId){this._hideAlert();return}this._cellAlertManagerService.showAlert({type:k.CellAlertType.ERROR,title:this._localeService.t("formula.error.title"),message:this._localeService.t(`formula.error.${Sn[p]}`),location:e.location,width:200,height:74,key:nt});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(nt)}};ot=pn([Ae(1,l.Inject(k.HoverManagerService)),Ae(2,l.Inject(k.CellAlertManagerService)),Ae(3,l.Inject(l.LocaleService)),Ae(4,l.Inject(y.FormulaDataModel)),Ae(5,a.IZenZoneService)],ot);var vn=Object.getOwnPropertyDescriptor,Cn=(e,t,n,s)=>{for(var r=s>1?void 0:s?vn(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},It=(e,t)=>(n,s)=>t(n,s,e);let Ye=class extends l.Disposable{constructor(e,t){super(),this._autoFillService=e,this._lexerTreeBuilder=t,this._registerAutoFill()}_registerAutoFill(){const e={type:k.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===k.DATA_TYPE.FORMULA,applyFunctions:{[k.APPLY_TYPE.COPY]:(t,n,s,r,o)=>{const{data:i,index:c}=t;return this._fillCopyFormula(i,n,s,c,r,o)}}};this._autoFillService.registerRule(e)}_fillCopyFormula(e,t,n,s,r,o){var g,p;const i=_n(r),c=[],d=new Map;for(let m=1;m<=t;m++){const f=(m-1)%e.length,h=s[f],u=l.Tools.deepClone(e[f]);if(u){const R=((g=e[f])==null?void 0:g.f)||"",v=((p=e[f])==null?void 0:p.si)||"",C=l.isFormulaString(R);if(l.isFormulaId(v))u.si=v,u.f=null,u.v=null,u.p=null,u.t=null,c.push(u);else if(C){let b=d.get(f);if(b)u.si=b,u.f=null,u.v=null,u.p=null,u.t=null;else{b=l.generateRandomId(6),d.set(f,b);const{offsetX:O,offsetY:S}=Rn(i,t,n,o,h),x=this._lexerTreeBuilder.moveFormulaRefOffset(R,O,S);u.si=b,u.f=x,u.v=null,u.p=null,u.t=null}c.push(u)}}}return c}};Ye=Cn([It(0,k.IAutoFillService),It(1,l.Inject(y.LexerTreeBuilder))],Ye);function Rn(e,t,n,s,r){const{source:o,target:i}=s,{rows:c}=i,{rows:d}=o;let g=0,p=0;switch(n){case l.Direction.UP:p=c[r]-d[r];break;case l.Direction.RIGHT:g=e;break;case l.Direction.DOWN:p=c[r]-d[r];break;case l.Direction.LEFT:g=-e*t;break}return{offsetX:g,offsetY:p}}function _n(e){let t=0;for(const n in e)e[n].forEach(s=>{t+=s.data.length});return t}var In=Object.getOwnPropertyDescriptor,En=(e,t,n,s)=>{for(var r=s>1?void 0:s?In(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Fe=(e,t)=>(n,s)=>t(n,s,e);const yn="default-paste-formula";let ze=class extends l.Disposable{constructor(e,t,n,s,r){super(),this._currentUniverSheet=e,this._lexerTreeBuilder=t,this._sheetClipboardService=n,this._injector=s,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:k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA,priority:10,specialPasteInfo:{label:"specialPaste.formula"},onPasteCells:(e,t,n,s)=>this._onPasteCells(e,t,n,s,!0)}}_pasteWithFormulaHook(){return{id:yn,priority:10,onPasteCells:(e,t,n,s)=>this._onPasteCells(e,t,n,s,!1)}}_onPasteCells(e,t,n,s,r){var f;if([k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH].includes(s.pasteType))return{undos:[],redos:[]};const i=this._currentUniverSheet.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),c=t.unitId||i.getUnitId(),d=t.subUnitId||((f=i.getActiveSheet())==null?void 0:f.getSheetId());if(!c||!d)return{undos:[],redos:[]};const g=t.range,p=n,m={copyType:s.copyType||k.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:s.pasteType};return this._injector.invoke(h=>bn(c,d,g,p,h,m,this._lexerTreeBuilder,this._formulaDataModel,r,e))}};ze=En([Fe(0,l.IUniverInstanceService),Fe(1,l.Inject(y.LexerTreeBuilder)),Fe(2,k.ISheetClipboardService),Fe(3,l.Inject(l.Injector)),Fe(4,l.Inject(y.FormulaDataModel))],ze);function bn(e,t,n,s,r,o,i,c,d=!1,g){const p=[],m=[],f=Tn(e,t,n,s,o,i,c,g);if(!f.hasValue())return{undos:[],redos:[]};const h={unitId:e,subUnitId:t,cellValue:f.getData()};p.push({id:P.SetRangeValuesMutation.id,params:h});const u=P.SetRangeValuesUndoMutationFactory(r,h);return m.push({id:P.SetRangeValuesMutation.id,params:u}),{undos:m,redos:p}}function Tn(e,t,n,s,r,o,i,c){return c?r.pasteType===k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE?Mn(e,t,n,s,i,c):r.pasteType===k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA?On(e,t,n,s,o,i,c):Nn(e,t,n,s,r.copyType,o,i,c):xn(e,t,n,s,i)}function xn(e,t,n,s,r){const o=new l.ObjectMatrix,i=r.getSheetFormulaData(e,t);return s.forValue((c,d,g)=>{var h;const p=n.rows[c],m=n.cols[d],f={};l.isFormulaString(g.v)?(f.v=null,f.f=`${g.v}`,f.si=null,f.p=null,o.setValue(p,m,f)):(h=i==null?void 0:i[p])!=null&&h[m]&&(f.v=g.v,f.f=null,f.si=null,f.p=null,o.setValue(p,m,f))}),o}function Mn(e,t,n,s,r,o){var g,p;const i=new l.ObjectMatrix,c=(p=(g=r.getArrayFormulaCellData())==null?void 0:g[o.unitId])==null?void 0:p[o.subUnitId],d=r.getSheetFormulaData(e,t);return s.forValue((m,f,h)=>{var b,O;const u=o.range.rows[m%o.range.rows.length],R=o.range.cols[f%o.range.cols.length],v=n.rows[m],C=n.cols[f],I={};if(l.isFormulaString(h.f)||l.isFormulaId(h.si))I.v=h.v,I.f=null,I.si=null,I.p=null,i.setValue(v,C,I);else if((b=c==null?void 0:c[u])!=null&&b[R]){const S=c[u][R];I.v=S.v,I.f=null,I.si=null,I.p=null,i.setValue(v,C,I)}else if((O=d==null?void 0:d[v])!=null&&O[C]){if(I.v=h.v,I.f=null,I.si=null,I.p=null,h.p){const S=At(h);S&&(I.v=S)}i.setValue(v,C,I)}}),i}function On(e,t,n,s,r,o,i){const c=new l.ObjectMatrix,d=new Map;return s.forValue((g,p,m)=>{const f=n.rows[g],h=n.cols[p],u={};if(l.isFormulaId(m.si)){if(i.unitId!==e||i.subUnitId!==t){const R=o.getFormulaStringByCell(i.range.rows[g%i.range.rows.length],i.range.cols[p%i.range.cols.length],i.subUnitId,i.unitId),v=n.cols[p]-i.range.cols[p%i.range.cols.length],C=n.rows[g]-i.range.rows[g%i.range.rows.length],I=r.moveFormulaRefOffset(R||"",v,C);u.si=null,u.f=I}else u.si=m.si,u.f=null;u.v=null,u.p=null,c.setValue(f,h,u)}else if(l.isFormulaString(m.f)){const R=`${g%i.range.rows.length}_${p%i.range.cols.length}`;let v=d.get(R);if(v)u.si=v,u.f=null;else{v=l.generateRandomId(6),d.set(R,v);const C=n.cols[p]-i.range.cols[p%i.range.cols.length],I=n.rows[g]-i.range.rows[g%i.range.rows.length],b=r.moveFormulaRefOffset(m.f||"",C,I);u.si=v,u.f=b}u.v=null,u.p=null,c.setValue(f,h,u)}else{if(u.v=m.v,u.f=null,u.si=null,u.p=null,m.p){const R=At(m);R&&(u.v=R)}c.setValue(f,h,u)}}),c}function Nn(e,t,n,s,r,o,i,c){const d=new l.ObjectMatrix,g=new Map,p=i.getSheetFormulaData(e,t),m=[];return r===k.COPY_TYPE.CUT?s.forValue((f,h,u)=>{const R=n.rows[f],v=n.cols[h],C={};if(l.isFormulaId(u.si)){if(l.isFormulaString(u.f))m.push(u.si),C.f=u.f,C.si=u.si;else if(m.includes(u.si))C.f=null,C.si=u.si;else{const I=i.getFormulaStringByCell(c.range.rows[f%c.range.rows.length],c.range.cols[h%c.range.cols.length],c.subUnitId,c.unitId);C.f=I,C.si=null}C.v=null,C.p=null,d.setValue(R,v,C)}else l.isFormulaString(u.f)&&(C.f=u.f,C.si=null,C.v=null,C.p=null,d.setValue(R,v,C))}):s.forValue((f,h,u)=>{var I;const R=n.rows[f],v=n.cols[h],C={};if(l.isFormulaId(u.si)){if(c.unitId!==e||c.subUnitId!==t){const b=i.getFormulaStringByCell(c.range.rows[f%c.range.rows.length],c.range.cols[h%c.range.cols.length],c.subUnitId,c.unitId),O=n.cols[h]-c.range.cols[h%c.range.cols.length],S=n.rows[f]-c.range.rows[f%c.range.rows.length],x=o.moveFormulaRefOffset(b||"",O,S);C.si=null,C.f=x}else C.si=u.si,C.f=null;C.v=null,C.p=null,d.setValue(R,v,C)}else if(l.isFormulaString(u.f)){const b=`${f%c.range.rows.length}_${h%c.range.cols.length}`;let O=g.get(b);if(O)C.si=O,C.f=null;else{O=l.generateRandomId(6),g.set(b,O);const S=n.cols[h]-c.range.cols[h%c.range.cols.length],x=n.rows[f]-c.range.rows[f%c.range.rows.length],N=o.moveFormulaRefOffset(u.f||"",S,x);C.si=O,C.f=N}C.v=null,C.p=null,d.setValue(R,v,C)}else(I=p==null?void 0:p[R])!=null&&I[v]&&(C.v=u.v,C.f=null,C.si=null,C.p=u.p,d.setValue(R,v,C))}),m.length>0&&new l.ObjectMatrix(p).forValue((f,h,u)=>{if(!(c.range.rows.includes(f)&&c.range.cols.includes(h))&&!(n.rows.includes(f)&&n.cols.includes(h))&&m.includes(u==null?void 0:u.si)){const R=i.getFormulaStringByCell(f,h,c.subUnitId,c.unitId);d.setValue(f,h,{f:R,si:null,v:null,p:null})}}),d}function At(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 Dn=Object.getOwnPropertyDescriptor,kn=(e,t,n,s)=>{for(var r=s>1?void 0:s?Dn(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},be=(e,t)=>(n,s)=>t(n,s,e);let Ge=class extends l.Disposable{constructor(t,n,s,r,o,i,c,d){super();K(this,"_previousShape");K(this,"_skeleton");this._context=t,this._sheetInterceptorService=n,this._formulaDataModel=s,this._themeService=r,this._renderManagerService=o,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,s;if(t==null)this._logService.debug("[FormulaEditorShowController]: should not receive currentSkeleton$ as null!");else{const{skeleton:r}=t,o=(s=(n=this._skeleton)==null?void 0:n.worksheet)==null?void 0:s.getSheetId();if(this._changeRuntime(r),o!==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(P.BEFORE_CELL_EDIT,{handler:(t,n,s)=>{var u,R,v,C;const{row:r,col:o,unitId:i,subUnitId:c,worksheet:d}=n,g=this._formulaDataModel.getArrayFormulaRange(),p=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return s(t);let m=null;const f=this._formulaDataModel.getFormulaStringByCell(r,o,c,i);if(f!==null&&(m={f}),t.v!=null&&t.v!==""&&((v=(R=(u=p[i])==null?void 0:u[c])==null?void 0:R[r])==null?void 0:v[o])==null)return m?{...t,...m}:s(t);const h=(C=g==null?void 0:g[i])==null?void 0:C[c];return h!=null&&(m=this._displayArrayFormulaRangeShape(h,r,o,i,c,d,m)),m?{...t,...m}:s(t)}})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{(t.id===y.SetFormulaCalculationResultMutation.id||t.id===y.SetArrayFormulaDataMutation.id&&n&&n.remove)&&this._removeArrayFormulaRangeShape()})),this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{P.SetWorksheetRowAutoHeightMutation.id===t.id&&requestIdleCallback(()=>{const n=t.params,{unitId:s,subUnitId:r,rowsAutoHeightInfo:o}=n;this._refreshArrayFormulaRangeShapeByRow(s,r,o)})}))}_displayArrayFormulaRangeShape(t,n,s,r,o,i,c){const d=this._formulaDataModel.getSheetFormulaData(r,o);return new l.ObjectMatrix(t).forValue((g,p,m)=>{var v;if(m==null)return!0;const{startRow:f,startColumn:h,endRow:u,endColumn:R}=m;if(g===n&&p===s)return this._createArrayFormulaRangeShape(m,r),!1;if(n>=f&&n<=u&&s>=h&&s<=R){const C=i.getCell(f,h);if((C==null?void 0:C.v)===y.ErrorType.SPILL)return;const I=(v=d==null?void 0:d[g])==null?void 0:v[p];return I==null||I.f==null?!0:(c==null&&(c={f:I.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(m,r),!1)}}),c}_createArrayFormulaRangeShape(t,n){const s=this._renderManagerService.getRenderById(n),r=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!s||!r)return;const{scene:o}=s;if(!o)return;const i={range:t,primary:null,style:{strokeWidth:1,stroke:this._themeService.getColorFromTheme("primary.600"),fill:new l.ColorKit(this._themeService.getColorFromTheme("white")).setAlpha(0).toString(),widgets:{}}},c=k.attachSelectionWithCoord(i,r),{rowHeaderWidth:d,columnHeaderHeight:g}=r,p=new k.SelectionControl(o,k.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:d,columnHeaderHeight:g});p.updateRangeBySelectionWithCoord(c),p.setEvent(!1),this._previousShape=p}_removeArrayFormulaRangeShape(){this._previousShape!=null&&(this._previousShape.dispose(),this._previousShape=null)}_refreshArrayFormulaRangeShape(t,n){if(this._previousShape){const{startRow:s,endRow:r,startColumn:o,endColumn:i}=this._previousShape.getRange(),c={startRow:s,endRow:r,startColumn:o,endColumn:i};this._removeArrayFormulaRangeShape(),this._createArrayFormulaRangeShape(c,t)}}_checkCurrentSheet(t,n){const s=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!s)return!1;const r=s.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,s){if(!this._checkCurrentSheet(t,n)||!this._previousShape)return;const{startRow:r,endRow:o,startColumn:i,endColumn:c}=this._previousShape.getRange();for(let d=0;d<s.length;d++){const{row:g}=s[d];if(r>=g){const p={startRow:r,endRow:o,startColumn:i,endColumn:c};this._refreshArrayFormulaRangeShape(t,p);break}}}};Ge=kn([be(1,l.Inject(P.SheetInterceptorService)),be(2,l.Inject(y.FormulaDataModel)),be(3,l.Inject(l.ThemeService)),be(4,H.IRenderManagerService),be(5,l.Inject(k.SheetSkeletonManagerService)),be(6,l.ICommandService),be(7,l.ILogService)],Ge);var wn=Object.getOwnPropertyDescriptor,An=(e,t,n,s)=>{for(var r=s>1?void 0:s?wn(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Et=(e,t)=>(n,s)=>t(n,s,e);const Fn={tl:{size:6,color:"#409f11"}};let Ze=class extends l.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(P.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,handler:(n,s,r)=>{var c,d,g,p;const o=(p=(g=(d=(c=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:c[s.unitId])==null?void 0:d[s.subUnitId])==null?void 0:g[s.row])==null?void 0:p[s.col];return!y.extractFormulaError(n,!!o)||!n||(n===s.rawData&&(n={...s.rawData}),n.markers={...n==null?void 0:n.markers,...Fn}),r(n)},priority:10}))}};Ze=An([Et(0,l.Inject(P.SheetInterceptorService)),Et(1,l.Inject(y.FormulaDataModel))],Ze);function Pn(){const e=a.useDependency(Ce.TriggerCalculationController),t=a.useDependency(l.ICommandService),n=a.useObservable(e.progress$),s=_.useCallback(()=>{t.executeCommand(y.SetFormulaCalculationStopMutation.id)},[t]),r=_.useCallback(()=>{e.clearProgress()},[e]);return E.jsx(a.ProgressBar,{progress:n,onTerminate:s,onClearProgress:r})}function Ln(e,t){return Object.keys(e).filter(n=>isNaN(Number(n))&&n!=="DefinedName").map(n=>({label:t.t(`formula.functionType.${n.toLocaleLowerCase()}`),value:`${e[n]}`}))}function Ft(e){if(!e.require&&!e.repeat)return`[${e.name}]`;if(e.require&&!e.repeat)return e.name;if(!e.require&&e.repeat)return`[${e.name},...]`;if(e.require&&e.repeat)return`${e.name},...`}function Pt(e){const{prefix:t,value:n}=e;return E.jsxs("div",{children:[E.jsxs("span",{children:[t,"("]}),n&&n.map((s,r)=>E.jsxs("span",{children:[E.jsx("span",{children:Ft(s)}),r===n.length-1?"":","]},r)),")"]})}function Pe(e){const{className:t,value:n,title:s}=e;return E.jsxs("div",{className:"univer-mb-2 univer-text-xs",children:[E.jsx("div",{className:W.clsx("univer-mb-2 univer-font-medium univer-text-gray-500 dark:!univer-text-gray-300",t),children:s}),E.jsx("div",{className:"univer-break-all univer-text-gray-900 dark:!univer-text-white",children:n})]})}function Un(e){const{functionInfo:t,onChange:n}=e;if(!t)return null;const[s,r]=_.useState([]),[o,i]=_.useState(t.functionParameter),[c,d]=_.useState(-1);return E.jsxs("div",{children:[E.jsx("div",{className:W.clsx("univer-h-[364px] univer-overflow-y-auto",W.scrollbarClassName),children:o.map((g,p)=>E.jsxs("div",{children:[E.jsx("div",{className:"univer-text-sm",children:g.name}),E.jsx("div",{className:"univer-mb-2 univer-mt-1"})]},p))}),E.jsx("div",{className:W.clsx("univer-flex-1 univer-p-3",W.borderLeftClassName),children:E.jsx(Pe,{title:c===-1?E.jsx(Pt,{prefix:t.functionName,value:o}):o[c].name,value:c===-1?t.description:o[c].detail})})]})}function Me({ref:e,...t}){const{icon:n,id:s,className:r,extend:o,...i}=t,c=`univerjs-icon univerjs-icon-${s} ${r||""}`.trim(),d=_.useRef(`_${Wn()}`);return Lt(n,`${s}`,{defIds:n.defIds,idSuffix:d.current},{ref:e,className:c,...i},o)}function Lt(e,t,n,s,r){return _.createElement(e.tag,{key:t,...$n(e,n,r),...s},(jn(e,n).children||[]).map((o,i)=>Lt(o,`${t}-${e.tag}-${i}`,n,void 0,r)))}function $n(e,t,n){const s={...e.attrs};n!=null&&n.colorChannel1&&s.fill==="colorChannel1"&&(s.fill=n.colorChannel1),e.tag==="mask"&&s.id&&(s.id=s.id+t.idSuffix),Object.entries(s).forEach(([o,i])=>{o==="mask"&&typeof i=="string"&&(s[o]=i.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:r}=t;return!r||r.length===0||(e.tag==="use"&&s["xlink:href"]&&(s["xlink:href"]=s["xlink:href"]+t.idSuffix),Object.entries(s).forEach(([o,i])=>{typeof i=="string"&&(s[o]=i.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),s}function jn(e,t){var s;const{defIds:n}=t;return!n||n.length===0?e:e.tag==="defs"&&((s=e.children)!=null&&s.length)?{...e,children:e.children.map(r=>typeof r.attrs.id=="string"&&n&&n.includes(r.attrs.id)?{...r,attrs:{...r.attrs,id:r.attrs.id+t.idSuffix}}:r)}:e}function Wn(){return Math.random().toString(36).substring(2,8)}Me.displayName="UniverIcon";const Vn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ut=_.forwardRef(function(t,n){return _.createElement(Me,Object.assign({},t,{id:"check-mark-icon",ref:n,icon:Vn}))});Ut.displayName="CheckMarkIcon";const Bn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},$t=_.forwardRef(function(t,n){return _.createElement(Me,Object.assign({},t,{id:"close-icon",ref:n,icon:Bn}))});$t.displayName="CloseIcon";const Hn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},jt=_.forwardRef(function(t,n){return _.createElement(Me,Object.assign({},t,{id:"delete-icon",ref:n,icon:Hn}))});jt.displayName="DeleteIcon";const Kn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},Wt=_.forwardRef(function(t,n){return _.createElement(Me,Object.assign({},t,{id:"increase-icon",ref:n,icon:Kn}))});Wt.displayName="IncreaseIcon";const qn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.90913 3.57564C6.14345 3.34132 6.52335 3.34132 6.75766 3.57564L10.7577 7.57564C10.992 7.80995 10.992 8.18985 10.7577 8.42417L6.75766 12.4242C6.52335 12.6585 6.14345 12.6585 5.90913 12.4242C5.67482 12.1899 5.67482 11.81 5.90913 11.5756L9.48487 7.9999L5.90913 4.42417C5.67482 4.18985 5.67482 3.80995 5.90913 3.57564Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Vt=_.forwardRef(function(t,n){return _.createElement(Me,Object.assign({},t,{id:"more-icon",ref:n,icon:qn}))});Vt.displayName="MoreIcon";const Yn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6185 12.4423C12.5907 12.2749 12.7773 12.15 12.9343 12.2308L15.4242 13.5126C15.6102 13.6084 15.5544 13.8745 15.3439 13.8955L14.2456 14.184L13.4521 15.1286C13.3495 15.2939 13.085 15.2463 13.0534 15.0568L12.6185 12.4423Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1 3.6C1 2.16406 2.16406 1 3.6 1H12.3C13.7359 1 14.9 2.16406 14.9 3.6V5.81156C14.9003 5.81881 14.9004 5.82609 14.9004 5.8334C14.9004 5.84071 14.9003 5.84799 14.9 5.85524V10.045C14.9003 10.0522 14.9004 10.0595 14.9004 10.0668C14.9004 10.3982 14.6318 10.6668 14.3004 10.6668H11.1668C10.8907 10.6668 10.6668 10.8907 10.6668 11.1668V14.3C10.6668 14.6314 10.3982 14.9 10.0668 14.9L10.05 14.8998L3.6 14.9C2.16406 14.9 1 13.7359 1 12.3V3.6ZM13.2 5.2334C13.4761 5.2334 13.7 5.00954 13.7 4.7334V3.6C13.7 2.8268 13.0732 2.2 12.3 2.2H11.1668C10.8907 2.2 10.6668 2.42386 10.6668 2.7V4.7334C10.6668 5.00954 10.8907 5.2334 11.1668 5.2334H13.2ZM10.6668 6.9334C10.6668 6.65726 10.8907 6.4334 11.1668 6.4334H13.2C13.4761 6.4334 13.7 6.65726 13.7 6.9334V8.9668C13.7 9.24294 13.4761 9.4668 13.2 9.4668H11.1668C10.8907 9.4668 10.6668 9.24294 10.6668 8.9668V6.9334ZM8.9668 5.2334C9.24294 5.2334 9.4668 5.00954 9.4668 4.7334V2.7C9.4668 2.42386 9.24294 2.2 8.9668 2.2H6.9334C6.65726 2.2 6.4334 2.42386 6.4334 2.7V4.7334C6.4334 5.00954 6.65726 5.2334 6.9334 5.2334L8.9668 5.2334ZM6.4334 6.9334C6.4334 6.65726 6.65726 6.4334 6.9334 6.4334L8.9668 6.4334C9.24294 6.4334 9.4668 6.65726 9.4668 6.9334V8.9668C9.4668 9.24294 9.24294 9.4668 8.9668 9.4668L6.9334 9.4668C6.65726 9.4668 6.4334 9.24294 6.4334 8.9668V6.9334ZM4.7334 5.2334C5.00954 5.2334 5.2334 5.00954 5.2334 4.7334V2.7C5.2334 2.42386 5.00954 2.2 4.7334 2.2H3.6C2.8268 2.2 2.2 2.8268 2.2 3.6V4.7334C2.2 5.00954 2.42386 5.2334 2.7 5.2334H4.7334ZM2.2 6.9334C2.2 6.65726 2.42386 6.4334 2.7 6.4334H4.7334C5.00954 6.4334 5.2334 6.65725 5.2334 6.9334V8.9668C5.2334 9.24294 5.00954 9.4668 4.7334 9.4668H2.7C2.42386 9.4668 2.2 9.24294 2.2 8.9668V6.9334ZM5.2334 11.1668C5.2334 10.8907 5.00954 10.6668 4.7334 10.6668H2.7C2.42386 10.6668 2.2 10.8907 2.2 11.1668V12.3C2.2 13.0732 2.8268 13.7 3.6 13.7H4.7334C5.00954 13.7 5.2334 13.4761 5.2334 13.2V11.1668ZM9.4668 11.1668C9.4668 10.8907 9.24294 10.6668 8.9668 10.6668H6.9334C6.65726 10.6668 6.4334 10.8907 6.4334 11.1668V13.2C6.4334 13.4761 6.65726 13.7 6.9334 13.7H8.9668C9.24294 13.7 9.4668 13.4761 9.4668 13.2V11.1668Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Bt=_.forwardRef(function(t,n){return _.createElement(Me,Object.assign({},t,{id:"select-range-icon",ref:n,icon:Yn}))});Bt.displayName="SelectRangeIcon";function zn(e){const{onChange:t}=e,n="-1",[s,r]=_.useState(""),[o,i]=_.useState([]),[c,d]=_.useState(0),[g,p]=_.useState(n),[m,f]=_.useState(0),[h,u]=_.useState(null),R=a.useDependency(Ce.IDescriptionService),v=a.useDependency(l.LocaleService),C=a.useDependency(a.ISidebarService),I=a.useObservable(C.sidebarOptions$),b=Ln(y.FunctionType,v);b.unshift({label:v.t("formula.moreFunctions.allFunctions"),value:n});const O=v.t("formula.prompt.required"),S=v.t("formula.prompt.optional");_.useEffect(()=>{U(n)},[]),_.useEffect(()=>{N(0)},[o]),_.useEffect(()=>{I!=null&&I.visible&&(r(""),i([]),d(0),p(n),f(0),u(null),U(n))},[I]);const x=M=>{if(s.trim()==="")return M;const A=new RegExp(`(${s.toLocaleUpperCase()})`);return M.split(A).filter(Boolean).map((F,j)=>F.match(A)?E.jsx("span",{className:"univer-text-red-500",children:F},j):F)},N=M=>{if(o.length===0){u(null);return}f(M);const A=R.getFunctionInfo(o[M].name);if(!A){u(null);return}u(A),t(A)};function U(M){p(M);const A=R.getSearchListByType(+M);i(A)}function $(M){r(M);const A=R.getSearchListByName(M);i(A)}function w(M){if(M.stopPropagation(),M.key==="ArrowDown"){const A=c+1;d(A===o.length?0:A)}else if(M.key==="ArrowUp"){const A=c-1;d(A===-1?o.length-1:A)}else M.key==="Enter"&&N(c)}const L=M=>{d(M)},D=()=>{d(-1)};return E.jsxs("div",{children:[E.jsxs("div",{className:"univer-flex univer-items-center univer-justify-between univer-gap-2",children:[E.jsx(W.Select,{value:g,options:b,onChange:U}),E.jsx(W.Input,{placeholder:v.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:w,value:s,onChange:$,size:"small",allowClear:!0})]}),o.length>0&&E.jsx("ul",{className:W.clsx("univer-mb-0 univer-mt-2 univer-box-border univer-max-h-72 univer-w-full univer-select-none univer-list-none univer-overflow-y-auto univer-rounded univer-p-3 univer-outline-none",W.borderClassName,W.scrollbarClassName),onKeyDown:w,tabIndex:-1,children:o.map(({name:M},A)=>E.jsxs("li",{className:W.clsx("univer-relative univer-box-border univer-cursor-pointer univer-rounded univer-px-7 univer-py-1 univer-text-sm univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200 dark:!univer-bg-gray-600":c===A}),onMouseEnter:()=>L(A),onMouseLeave:D,onClick:()=>N(A),children:[m===A&&E.jsx(Ut,{className:"univer-absolute univer-left-1.5 univer-top-1/2 univer-inline-flex -univer-translate-y-1/2 univer-text-base univer-text-primary-600"}),E.jsx("span",{className:"univer-block",children:x(M)})]},A))}),h&&E.jsxs("div",{className:W.clsx("univer-mx-0 univer-my-2 univer-overflow-y-auto",W.scrollbarClassName),children:[E.jsx(Pe,{title:h.functionName,value:h.description}),E.jsx(Pe,{title:v.t("formula.moreFunctions.syntax"),value:E.jsx(Pt,{prefix:h.functionName,value:h.functionParameter})}),E.jsx(Pe,{title:v.t("formula.prompt.helpExample"),value:`${h.functionName}(${h.functionParameter.map(M=>M.example).join(",")})`}),h.functionParameter&&h.functionParameter.map(M=>E.jsx(Pe,{title:M.name,value:`${M.require?O:S} ${M.detail}`},M.name))]})]})}function Gn(){const e=k.useActiveWorkbook(),[t,n]=_.useState(!0),[s,r]=_.useState(!1),[o,i]=_.useState(null);a.useDependency(k.IEditorBridgeService);const c=a.useDependency(l.LocaleService),d=a.useDependency(ee.IEditorService),g=a.useDependency(l.IUniverInstanceService),p=a.useDependency(l.ICommandService);function m(){n(!t),r(!s)}function f(){const h=P.getSheetCommandTarget(g);if(!h)return;p.executeCommand(k.SetCellEditVisibleOperation.id,{visible:!0,unitId:h.unitId,eventType:H.DeviceInputEventType.Dblclick});const u=d.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),R=d.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),v=`=${o==null?void 0:o.functionName}(`;u==null||u.replaceText(v),R==null||R.replaceText(v,!1)}return E.jsxs("div",{"data-u-comp":"sheets-formula-functions-panel",className:"univer-box-border univer-flex univer-h-full univer-flex-col univer-justify-between univer-py-2",children:[t&&E.jsx(zn,{onChange:i}),s&&E.jsx(Un,{functionInfo:o,onChange:()=>{}}),E.jsxs("div",{className:"univer-flex univer-justify-end",children:[s&&E.jsx(W.Button,{variant:"primary",onClick:m,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.next")}),s&&E.jsx(W.Button,{onClick:m,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.prev")}),t&&!!e&&E.jsx(W.Button,{variant:"primary",onClick:f,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.confirm")})]})]})}function Zn(e){return{id:le.id,title:"SUM",icon:"SumIcon",type:a.MenuItemType.BUTTON,params:{value:"SUM"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[P.WorkbookEditablePermission],worksheetTypes:[P.WorksheetEditPermission,P.WorksheetSetCellValuePermission],rangeTypes:[P.RangeProtectionPermissionEditPoint]})}}function Xn(e){return{id:le.id,title:"COUNT",icon:"CntIcon",type:a.MenuItemType.BUTTON,params:{value:"COUNT"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[P.WorkbookEditablePermission],worksheetTypes:[P.WorksheetEditPermission,P.WorksheetSetCellValuePermission],rangeTypes:[P.RangeProtectionPermissionEditPoint]})}}function Qn(e){return{id:le.id,title:"AVERAGE",icon:"AvgIcon",type:a.MenuItemType.BUTTON,params:{value:"AVERAGE"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[P.WorkbookEditablePermission],worksheetTypes:[P.WorksheetEditPermission,P.WorksheetSetCellValuePermission],rangeTypes:[P.RangeProtectionPermissionEditPoint]})}}function Jn(e){return{id:le.id,title:"MAX",icon:"MaxIcon",type:a.MenuItemType.BUTTON,params:{value:"MAX"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[P.WorkbookEditablePermission],worksheetTypes:[P.WorksheetEditPermission,P.WorksheetSetCellValuePermission],rangeTypes:[P.RangeProtectionPermissionEditPoint]})}}function er(e){return{id:le.id,title:"MIN",icon:"MinIcon",type:a.MenuItemType.BUTTON,params:{value:"MIN"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[P.WorkbookEditablePermission],worksheetTypes:[P.WorksheetEditPermission,P.WorksheetSetCellValuePermission],rangeTypes:[P.RangeProtectionPermissionEditPoint]})}}function tr(e){return{id:et.id,title:"formula.insert.more",tooltip:"formula.insert.tooltip",type:a.MenuItemType.BUTTON,hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[P.WorkbookEditablePermission],worksheetTypes:[P.WorksheetEditPermission,P.WorksheetSetCellValuePermission],rangeTypes:[P.RangeProtectionPermissionEditPoint]})}}function nr(e){return e.get(l.IUniverInstanceService).getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(q.switchMap(s=>s&&e.get(a.IClipboardInterfaceService)?new q.Observable(o=>o.next(!e.get(a.IClipboardInterfaceService).supportClipboard)):q.of(!0)))}function rr(e){return{id:Qe.id,type:a.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:nr(e).pipe(q.combineLatestWith(k.getCurrentRangeDisable$(e,{workbookTypes:[P.WorkbookEditablePermission],rangeTypes:[P.RangeProtectionPermissionEditPoint],worksheetTypes:[P.WorksheetSetCellValuePermission,P.WorksheetEditPermission]})),q.map(([t,n])=>t||n))}}const sr={[a.RibbonFormulasGroup.BASIC]:{[`${le.id}.sum`]:{order:0,menuItemFactory:Zn},[`${le.id}.count`]:{order:1,menuItemFactory:Xn},[`${le.id}.average`]:{order:2,menuItemFactory:Qn},[`${le.id}.max`]:{order:3,menuItemFactory:Jn},[`${le.id}.min`]:{order:4,menuItemFactory:er}},[a.RibbonFormulasGroup.OTHERS]:{[et.id]:{order:0,menuItemFactory:tr}},[k.PASTE_SPECIAL_MENU_ID]:{[Qe.id]:{order:4,menuItemFactory:rr}}},or="meta_key_ctrl_And_Shift";function ir(e){return e.getContextValue(l.FOCUSING_DOC)&&e.getContextValue(l.FOCUSING_UNIVER_EDITOR)}const tt=[a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP,a.KeyCode.ARROW_LEFT,a.KeyCode.ARROW_RIGHT],cr=[...tt,a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ESC];function ar(){const e=[];for(const t of cr)e.push({id:xe.id,binding:t,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t}});return e}function lr(){const e=[];for(const t of tt)e.push({id:xe.id,binding:t|a.MetaKeys.SHIFT,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.SHIFT}});return e}function ur(){const e=[];for(const t of tt)e.push({id:xe.id,binding:t|a.MetaKeys.CTRL_COMMAND,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.CTRL_COMMAND}});return e}function dr(){const e=[];for(const t of tt)e.push({id:xe.id,binding:t|a.MetaKeys.SHIFT|a.MetaKeys.CTRL_COMMAND,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,metaKey:or}});return e}const hr={id:ct.id,binding:a.KeyCode.F4,preconditions:e=>k.whenFormulaEditorActivated(e)};function fr(){const e=[];for(const t of[a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP])e.push({id:xe.id,binding:t,preconditions:n=>ir(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}const gr={id:Ce.QuickSumCommand.id,binding:a.MetaKeys.ALT|a.KeyCode.EQUAL,preconditions:k.whenSheetEditorFocused,mac:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.ALT|a.KeyCode.EQUAL,description:"shortcut.sheets-formula-ui.quick-sum",group:"4_sheet-edit"};var mr=Object.getOwnPropertyDescriptor,pr=(e,t,n,s)=>{for(var r=s>1?void 0:s?mr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Te=(e,t)=>(n,s)=>t(n,s,e);let Xe=class extends l.Disposable{constructor(e,t,n,s,r,o,i){super(),this._injector=e,this._menuManagerService=t,this._commandService=n,this._shortcutService=s,this._uiPartsService=r,this._renderManagerService=o,this._componentManager=i,this._initialize()}_initialize(){this._registerCommands(),this._registerMenus(),this._registerShortcuts(),this._registerComponents(),this._registerRenderModules()}_registerMenus(){this._menuManagerService.mergeMenu(sr)}_registerCommands(){[Qe,le,et,kt,Ot,xe,ct].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...ar(),...lr(),...ur(),...dr(),...fr(),gr,hr].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(k.SheetsUIPart.FORMULA_AUX,()=>a.connectInjector(Pn,this._injector))),this._componentManager.register(Dt,Gn)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,[Ge]))}};Xe=pr([Te(0,l.Inject(l.Injector)),Te(1,a.IMenuManagerService),Te(2,l.ICommandService),Te(3,a.IShortcutService),Te(4,a.IUIPartsService),Te(5,H.IRenderManagerService),Te(6,l.Inject(a.ComponentManager))],Xe);class at{constructor(){K(this,"_currentSelector$",new q.BehaviorSubject(null));K(this,"currentSelector$",this._currentSelector$.asObservable())}showRangeSelectorDialog(t){const n=t.callback,s=new Promise(r=>{t.callback=o=>{r(o),n(o)}});return this._currentSelector$.next(t),s}}var Sr=Object.getOwnPropertyDescriptor,vr=(e,t,n,s)=>{for(var r=s>1?void 0:s?Sr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},we=(e,t)=>(n,s)=>t(n,s,e);exports.RefSelectionsRenderService=class extends k.BaseSelectionRenderService{constructor(n,s,r,o,i,c,d){super(s,r,o,i,c);K(this,"_workbookSelections");K(this,"_eventDisposables");this._context=n,this._contextService=c,this._refSelectionsService=d,this._workbookSelections=this._refSelectionsService.getWorkbookSelections(this._context.unitId),this._initSelectionChangeListener(),this._initSkeletonChangeListener(),this._initUserActionSyncListener(),this._setSelectionStyle(Cr(this._themeService)),this._remainLastEnabled=!0,this._highlightHeader=!1}getLocation(){return this._skeleton.getLocation()}setRemainLastEnabled(n){this._remainLastEnabled=n}setSkipLastEnabled(n){this._skipLastEnabled=n}clearLastSelection(){const n=this._selectionControls[this._selectionControls.length-1];n&&(n.dispose(),this._selectionControls.pop())}enableSelectionChanging(){return this._disableSelectionChanging(),this._eventDisposables=this._initCanvasEventListeners(),l.toDisposable(()=>this._disableSelectionChanging())}_disableSelectionChanging(){var n;(n=this._eventDisposables)==null||n.dispose(),this._eventDisposables=null}disableSelectionChanging(){this._disableSelectionChanging()}_initCanvasEventListeners(){const n=this._getSheetObject(),{spreadsheetRowHeader:s,spreadsheetColumnHeader:r,spreadsheet:o,spreadsheetLeftTopPlaceholder:i}=n,{scene:c}=this._context,d=new l.DisposableCollection;return d.add(o==null?void 0:o.onPointerDown$.subscribeEvent((g,p)=>{this.inRefSelectionMode()&&(this._onPointerDown(g,o.zIndex+1,l.RANGE_TYPE.NORMAL,this._getActiveViewport(g)),g.button!==2&&p.stopPropagation())})),d.add(s==null?void 0:s.onPointerDown$.subscribeEvent((g,p)=>{if(!this.inRefSelectionMode())return;const m=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:f}=k.getCoordByOffset(g.offsetX,g.offsetY,c,m);k.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),f,l.RANGE_TYPE.ROW)||(this._onPointerDown(g,(o.zIndex||1)+1,l.RANGE_TYPE.ROW,this._getActiveViewport(g),H.ScrollTimerType.Y),g.button!==2&&p.stopPropagation())})),d.add(r==null?void 0:r.onPointerDown$.subscribeEvent((g,p)=>{if(!this.inRefSelectionMode())return;const m=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:f}=k.getCoordByOffset(g.offsetX,g.offsetY,c,m);k.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),f,l.RANGE_TYPE.COLUMN)||(this._onPointerDown(g,(o.zIndex||1)+1,l.RANGE_TYPE.COLUMN,this._getActiveViewport(g),H.ScrollTimerType.X),g.button!==2&&p.stopPropagation())})),d.add(i==null?void 0:i.onPointerDown$.subscribeEvent((g,p)=>{if(this._reset(),!this.inRefSelectionMode())return;const m=this._sheetSkeletonManagerService.getCurrent().skeleton,f=k.getAllSelection(m);this._addSelectionControlByModelData(f),this._selectionMoveStart$.next(this.getSelectionDataWithStyle());const h=c.onPointerUp$.subscribeEvent(()=>{h.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});g.button!==2&&p.stopPropagation()})),d}_addSelectionControlByModelData(n){var c;const s=this._skeleton,r=(c=n.style)!=null?c:k.genNormalSelectionStyle(this._themeService),o=this._scene;return n.style=r,this.newSelectionControl(o,s,n)}_initSelectionChangeListener(){this.disposeWithMe(this._refSelectionsService.selectionSet$.subscribe(n=>{this._reset(),this._skeleton&&this.resetSelectionsByModelData(n||[])}))}_initUserActionSyncListener(){this.disposeWithMe(this.selectionMoveStart$.subscribe(n=>{this._updateSelections(n,P.SelectionMoveType.MOVE_START)})),this.disposeWithMe(this.selectionMoving$.subscribe(n=>{this._updateSelections(n,P.SelectionMoveType.MOVING)})),this.disposeWithMe(this.selectionMoveEnd$.subscribe(n=>{this._updateSelections(n,P.SelectionMoveType.MOVE_END)}))}_updateSelections(n,s){const o=this._context.unit.getActiveSheet().getSheetId();n.length!==0&&this._workbookSelections.setSelections(o,n.map(i=>P.convertSelectionDataToRange(i)),s)}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(n=>{var c;if(!n)return;const{skeleton:s}=n,{scene:r}=this._context,o=r.getViewport(H.SHEET_VIEWPORT_KEY.VIEW_MAIN);this._skeleton&&((c=this._skeleton.worksheet)==null?void 0:c.getSheetId())!==s.worksheet.getSheetId()&&this._reset(),this._changeRuntime(s,r,o);const i=this._workbookSelections.getCurrentSelections();this.resetSelectionsByModelData(i)}))}_getActiveViewport(n){const s=this._getSheetObject();return s==null?void 0:s.scene.getActiveViewportByCoord(H.Vector2.FromArray([n.offsetX,n.offsetY]))}_getSheetObject(){return k.getSheetObject(this._context.unit,this._context)}_onPointerDown(n,s=0,r=l.RANGE_TYPE.NORMAL,o,i=H.ScrollTimerType.ALL){var L;this._rangeType=r;const c=this._skeleton,d=this._scene;if(!d||!c)return;o&&(this._activeViewport=o);const{offsetX:g,offsetY:p}=n,m=d.getViewport(H.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!m)return;const f=d.getCoordRelativeToViewport(H.Vector2.FromArray([g,p])),{x:h,y:u}=f;this._startViewportPosX=h,this._startViewportPosY=u;const R=d.getScrollXYInfoByViewport(f),{scaleX:v,scaleY:C}=d.getAncestorScale(),I=this._skeleton.getCellByOffset(h,u,v,C,R);if(!I)return;switch(r){case l.RANGE_TYPE.NORMAL:break;case l.RANGE_TYPE.ROW:I.startColumn=0,I.endColumn=this._skeleton.getColumnCount()-1;break;case l.RANGE_TYPE.COLUMN:I.startRow=0,I.endRow=this._skeleton.getRowCount()-1;break;case l.RANGE_TYPE.ALL:I.startRow=0,I.startColumn=0,I.endRow=this._skeleton.getRowCount()-1,I.endColumn=this._skeleton.getColumnCount()-1}const b={range:I,primary:I,style:null};b.range.rangeType=r;const O=k.attachSelectionWithCoord(b,this._skeleton);this._startRangeWhenPointerDown={...O.rangeWithCoord};const S={...O.rangeWithCoord,rangeType:r};let x=this.getActiveSelectionControl();const N=this.getSelectionControls();for(const D of N){if(n.button===2&&l.Rectangle.contains(D.model,S)){x=D;return}if(D.model.isEqual(S)){x=D;break}}this._checkClearPreviousControls(n);const U=x==null?void 0:x.model.currentCell,$=n.shiftKey&&U,w=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;$&&U?this._makeSelectionByTwoCells(U,S,c,r,x):w&&x?x.updateRangeBySelectionWithCoord(O):x=this.newSelectionControl(d,c,b);for(let D=0;D<this.getSelectionControls().length-1;D++)this.getSelectionControls()[D].clearHighlight();this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),d.disableObjectsEvent(),this._clearUpdatingListeners(),this._addEndingListeners(),(L=d.getTransformer())==null||L.clearSelectedObjects(),this._setupPointerMoveListener(m,x,r,i,h,u),this._escapeShortcutDisposable=this._shortcutService.forceEscape(),this._scenePointerUpSub=d.onPointerUp$.subscribeEvent(()=>{var D;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(D=this._escapeShortcutDisposable)==null||D.dispose(),this._escapeShortcutDisposable=null})}newSelectionControl(n,s,r){const o=this.getSelectionControls().length,{rowHeaderWidth:i,columnHeaderHeight:c}=s,d=new k.SelectionControl(n,o,this._themeService,{highlightHeader:this._highlightHeader,enableAutoFill:!1,rowHeaderWidth:i,columnHeaderHeight:c}),g=k.attachSelectionWithCoord(r,s);return d.updateRangeBySelectionWithCoord(g),this._selectionControls.push(d),d.setControlExtension({skeleton:s,scene:n,themeService:this._themeService,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),d}};exports.RefSelectionsRenderService=vr([we(1,l.Inject(l.Injector)),we(2,l.Inject(l.ThemeService)),we(3,a.IShortcutService),we(4,l.Inject(k.SheetSkeletonManagerService)),we(5,l.IContextService),we(6,P.IRefSelectionsService)],exports.RefSelectionsRenderService);function Cr(e){const t=k.genNormalSelectionStyle(e);return t.widgets={tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},t}const lt=(e,t,n=!0)=>{let s=-1;return e.reduce((r,o,i)=>{if(r.isFinish)return r;const c=r.currentIndex;if(typeof o!="string")r.currentIndex+=o.token.length;else{const d=o.length;r.currentIndex+=d}return(n?r.currentIndex===t:t>c&&t<=r.currentIndex)&&(s=i,r.isFinish=!0),r},{currentIndex:0,isFinish:!1}),s},Ht=(e,t)=>{const n=e[t];let s=-1;if(!n||typeof n=="string"||n.nodeType!==y.sequenceNodeType.REFERENCE)return-1;for(let r=0;r<=t;r++){const o=e[r];typeof o!="string"&&o.nodeType===y.sequenceNodeType.REFERENCE&&s++}return s},Rr=(e,t=100)=>{_.useEffect(()=>{let n=null;const s=()=>{n===null&&(n=window.setTimeout(()=>{e(),n=null},t))};return window.addEventListener("scroll",s),window.addEventListener("resize",s),()=>{n!==null&&clearTimeout(n),window.removeEventListener("scroll",s),window.removeEventListener("resize",s)}},[e,t])};function Kt(e,t,n){const s=a.useDependency(ee.IEditorService),r=_.useMemo(()=>new q.BehaviorSubject({left:-999,top:-999,right:-999,bottom:-999}),[]),o=a.useDependency(a.ISidebarService),i=a.useDependency(l.IUniverInstanceService),c=a.useEvent(()=>{var b;const d=s.getEditor(e);if(!d)return;const g=d.getBoundingClientRect(),{marginTop:p=0,marginBottom:m=0}=d.getDocumentData().documentStyle,f=d.getSkeleton();if(!f)return;const h=(b=f.getSkeletonData())==null?void 0:b.pages[0].height;let{left:u,top:R,right:v,bottom:C}=g;R=R+p,C=h?R+h:C-m;const I=r.getValue();if(!(I.left===u&&I.top===R&&I.right===v&&I.bottom===C))return r.next({left:u-1,right:v+1,top:R-1,bottom:C+1}),g});return _.useEffect(()=>{t&&c()},[e,s,i.unitAdded$,c,t,...n!=null?n:[]]),Rr(c),_.useEffect(()=>{const d=o.scrollEvent$.pipe(q.throttleTime(100)).subscribe(c);return()=>{d.unsubscribe()}},[]),[r,c]}const Oe=e=>{const t=_.useRef(e);return t.current=e,t},_r=(e,t,n)=>{const s=a.useDependency(Je),r=a.useDependency(Ce.IDescriptionService),o=a.useDependency(y.LexerTreeBuilder),[i,c]=_.useState(),[d,g]=_.useState(-1),[p,m]=_.useState(!0),f=Oe(p),h=_.useRef(t);h.current=t;const u=()=>{c(void 0),g(-1),m(!1)};return _.useEffect(()=>{const R=o.sequenceNodesBuilder(t.slice(1));s.setSequenceNodes(R!=null?R:[])},[t]),_.useEffect(()=>{if(n&&e){const R=n.selectionChange$.pipe(q.debounceTime(50)).subscribe(C=>{if(C.textRanges.length===1){const[I]=C.textRanges;if(I.collapsed&&f.current){const{startOffset:b}=I,O=s.getCurrentSequenceNodeIndex(b-2),S=s.getCurrentSequenceNodeByIndex(O),x=s.getCurrentSequenceNodeByIndex(O+1);if(S)if(typeof S!="string"&&S.nodeType===3&&!r.hasDefinedNameDescription(S.token.trim())&&x===y.matchToken.OPEN_BRACKET){const N=r.getFunctionInfo(S.token);c(N),g(-1);return}else{const N=o.getFunctionAndParameter(`${h.current}A`,b-1);if(N){const{functionName:U,paramIndex:$}=N,w=r.getFunctionInfo(U);c(w),g($);return}}}}c(void 0),g(-1)}),v=n.selectionChange$.pipe(q.filter(C=>C.textRanges.length===1),q.map(C=>C.textRanges[0].startOffset),q.distinctUntilChanged()).subscribe(()=>{m(!0)});return()=>{R.unsubscribe(),v.unsubscribe()}}},[n,e]),_.useEffect(()=>{e||u()},[e]),{functionInfo:i,paramIndex:d,reset:u}},Ir=({onClick:e})=>E.jsx("div",{className:"univer-z-[15] univer-box-border univer-h-[18px] univer-cursor-pointer univer-overflow-visible univer-whitespace-nowrap univer-rounded-l univer-border univer-border-r-0 univer-border-gray-600 univer-bg-primary-600 univer-p-0.5 univer-text-xs univer-font-bold univer-leading-[13px] univer-text-white",onClick:e,children:"?"}),rt=({className:e,title:t,value:n})=>E.jsxs("div",{className:"univer-my-2",children:[E.jsx("div",{className:W.clsx("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",e),children:t}),E.jsx("div",{className:"univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",children:n})]}),Er=e=>{const{prefix:t,value:n,active:s,onClick:r}=e;return E.jsxs("div",{children:[E.jsxs("span",{children:[t,"("]}),n&&n.map((o,i)=>E.jsxs("span",{children:[E.jsx("span",{className:s===i?"univer-text-primary-500":"",onClick:()=>r(i),children:Ft(o)}),i===n.length-1?"":","]},o.name)),")"]})},yt=()=>{};function yr(e){const{onParamsSwitch:t=yt,onClose:n=yt,isFocus:s,editor:r,formulaText:o}=e,{functionInfo:i,paramIndex:c,reset:d}=_r(s,o,r),g=a.useDependency(k.IEditorBridgeService),p=!a.useObservable(g.helpFunctionVisible$),[m,f]=_.useState(!0),h=a.useDependency(l.LocaleService),u=h.t("formula.prompt.required"),R=h.t("formula.prompt.optional"),v=r.getEditorId(),[C]=Kt(v,!!i,[i,c]);function I(S){t&&t(S)}const b=a.useEvent(S=>{g.helpFunctionVisible$.next(!S)}),O=()=>{b(!0),n()};return i?p?E.jsx(a.RectPopup,{portal:!0,anchorRect$:C,direction:"left-center",children:E.jsx(Ir,{onClick:()=>b(!1)})},"hidden"):E.jsx(a.RectPopup,{portal:!0,onClickOutside:()=>d(),anchorRect$:C,direction:"vertical",children:E.jsxs("div",{className:W.clsx("univer-m-0 univer-box-border univer-w-[250px] univer-select-none univer-list-none univer-rounded-lg univer-bg-white univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",W.borderClassName),children:[E.jsxs("div",{className:W.clsx("univer-wrap-anywhere univer-box-border univer-flex univer-items-center univer-justify-between univer-px-4 univer-py-3 univer-text-xs univer-font-medium univer-text-gray-900 dark:!univer-text-white",W.borderTopClassName),children:[E.jsx(Er,{prefix:i.functionName,value:i.functionParameter,active:c,onClick:I}),E.jsxs("div",{className:"univer-flex",children:[E.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-500 univer-outline-none univer-transition-colors hover:univer-bg-gray-200 dark:hover:!univer-bg-gray-600",style:{transform:m?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>f(!m),children:E.jsx(Vt,{})}),E.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-600 univer-outline-none univer-transition-colors hover:univer-bg-gray-300 dark:!univer-text-gray-200 dark:hover:!univer-bg-gray-600",onClick:O,children:E.jsx($t,{})})]})]}),E.jsx("div",{className:W.clsx("univer-box-border univer-max-h-[350px] univer-overflow-y-auto univer-px-4 univer-pb-3 univer-pt-0",W.scrollbarClassName),style:{height:m?"unset":0,padding:m?"revert-layer":0},children:E.jsxs("div",{className:"univer-mt-3",children:[E.jsx(rt,{title:h.t("formula.prompt.helpExample"),value:`${i.functionName}(${i.functionParameter.map(S=>S.example).join(",")})`}),E.jsx(rt,{title:h.t("formula.prompt.helpAbstract"),value:i.description}),i&&i.functionParameter&&i.functionParameter.map((S,x)=>E.jsx(rt,{className:c===x?"univer-text-primary-500":"",title:S.name,value:`${S.require?u:R} ${S.detail}`},x))]})})]})},"show"):null}const br=e=>{const t=a.useDependency(ee.IEditorService);return a.useEvent(s=>{var r,o;if(e){t.focus(e.getEditorId());const i=[...e.getSelectionRanges()];if(l.Tools.isDefine(s))e.setSelectionRanges([{startOffset:s,endOffset:s}]);else if(!i.length&&!e.docSelectionRenderService.isOnPointerEvent){const c=(o=(r=e.getDocumentData().body)==null?void 0:r.dataStream)!=null?o:`\r
|
|
2
2
|
`,d=Math.max(c.length-2,0);e.setSelectionRanges([{startOffset:d,endOffset:d}])}else e.setSelectionRanges(i)}})};function Tr(e){var r,o;const n=e.get(l.IUniverInstanceService).getCurrentUniverDocInstance();return n!=null&&n.getBody()?{dataStream:(o=(r=n.getBody())==null?void 0:r.dataStream)!=null?o:"",offset:0}:void 0}var me=(e=>(e[e.NOT_SELECT=0]="NOT_SELECT",e[e.NEED_ADD=1]="NEED_ADD",e[e.CAN_EDIT=2]="CAN_EDIT",e[e.EDIT_OTHER_SHEET_REFERENCE=3]="EDIT_OTHER_SHEET_REFERENCE",e[e.EDIT_OTHER_WORKBOOK_REFERENCE=4]="EDIT_OTHER_WORKBOOK_REFERENCE",e))(me||{});function xr(e){var N;const{editorId:t,isFocus:n,disableOnClick:s,unitId:r,subUnitId:o}=e,i=a.useDependency(H.IRenderManagerService),c=a.useDependency(l.IUniverInstanceService),d=i.getRenderById(r),g=i.getRenderById(t),p=g==null?void 0:g.with(ee.DocSelectionRenderService),m=a.useDependency(xt.DocSelectionManagerService),f=a.useDependency(l.Injector),[h,u]=_.useState(0),R=a.useDependency(y.LexerTreeBuilder),v=_.useRef(!0),C=d==null?void 0:d.with(exports.RefSelectionsRenderService),I=Oe(h),b=c.getUnit(r,l.UniverInstanceType.UNIVER_SHEET),O=b==null?void 0:b.getSheetBySheetId(o),S=a.useEvent(U=>{C&&C.setSkipLastEnabled(U===1||U===3||U===4),I.current=U,u(U)}),x=a.useEvent(()=>{var re,se,ie;const U=c.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_SHEET);if(!U)return;const $=U.getActiveSheet(),w=p==null?void 0:p.getActiveTextRange(),L=w!=null&&w.collapsed?w.startOffset:-1,D=Tr(f);if(!D)return;const M=(re=D==null?void 0:D.dataStream)==null?void 0:re.slice(0,-2),A=((se=R.sequenceNodesBuilder(M))!=null?se:[]).map(Y=>typeof Y=="object"?Y.nodeType===y.sequenceNodeType.REFERENCE?{...Y,range:y.deserializeRangeWithSheetWithCache(Y.token)}:{...Y,range:void 0}:Y),T=M[L-1],F=M[L],j=A.find(Y=>typeof Y=="object"&&Y.nodeType===y.sequenceNodeType.REFERENCE&&L===Y.endIndex+2),V=T&&y.matchRefDrawToken(T)&&(!F||y.isFormulaLexerToken(F)&&F!==y.matchToken.OPEN_BRACKET),B=!!j;if((M==null?void 0:M.substring(0,1))==="="&&(V||B))if(B){if(v.current)return;const{sheetName:Y,unitId:Q}=j.range,Ne=(ie=c.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:ie.getUnitId();Q&&Q!==Ne?S(4):!Y&&$.getSheetId()===(O==null?void 0:O.getSheetId())||Y===$.getName()?S(2):S(3)}else v.current=!1,S(1);else S(0)});return _.useEffect(()=>{const U=m.textSelection$.pipe(q.filter($=>$.unitId===t)).subscribe(()=>{x()});return()=>U.unsubscribe()},[x,m.textSelection$,t]),_.useEffect(()=>{n||(S(0),v.current=!0)},[n,S]),_.useEffect(()=>{var $;if(!s)return;const U=($=g==null?void 0:g.mainComponent)==null?void 0:$.onPointerDown$.subscribeEvent(()=>{S(0),v.current=!0});return()=>U==null?void 0:U.unsubscribe()},[s,(N=g==null?void 0:g.mainComponent)==null?void 0:N.onPointerDown$,S]),_.useEffect(()=>{if(!n)return;const U=b==null?void 0:b.activeSheet$.subscribe(()=>{x()}),$=c.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).subscribe(()=>{x()});return()=>{U==null||U.unsubscribe(),$==null||$.unsubscribe()}},[x,n,b==null?void 0:b.activeSheet$,c.getCurrentTypeOfUnit$]),{isSelecting:h,isSelectingRef:I}}const Mr=()=>{const e=a.useDependency(y.LexerTreeBuilder);return _.useCallback(n=>e.sequenceNodesBuilder(n)||[],[e])};function Or(e,t,n){const s=new l.ColorKit(t).setAlpha(.05).toRgbString();return{id:n,strokeWidth:1,stroke:t,fill:s,widgets:{tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},widgetSize:6,widgetStrokeWidth:1,widgetStroke:e.getColorFromTheme("white")}}function qt(e){var b,O,S;const{unitId:t,subUnitId:n,currentWorkbook:s,refSelections:r,editor:o,refSelectionsService:i,refSelectionsRenderService:c,sheetSkeletonManagerService:d,themeService:g,univerInstanceService:p}=e,m=s.getUnitId(),f=p.getUnit(t,l.UniverInstanceType.UNIVER_SHEET),h=f==null?void 0:f.getActiveSheet(),u=[];if(!f||!h){i.setSelections(u);return}const R=h.getSheetId(),v=x=>{var N;return(N=f==null?void 0:f.getSheetBySheetName(x))==null?void 0:N.getSheetId()};if(!((b=d==null?void 0:d.getWorksheetSkeleton(R))==null?void 0:b.skeleton))return;const I=[];for(let x=0,N=r.length;x<N;x++){const U=r[x],{themeColor:$,token:w,refIndex:L,endIndex:D}=U,M=y.deserializeRangeWithSheet(w),{unitId:A,sheetName:T,range:F}=M,j=v(T);if(!j&&T||m!==t&&A!==m||A&&A!==m||j&&j!==R||!j&&R!==n)continue;const V=P.setEndForRange(F,h.getRowCount(),h.getColumnCount());V.unitId=t,V.sheetId=R,u.push({range:V,primary:null,style:Or(g,$,L.toString())}),I.push(D)}if(o){const x=(S=(O=o.getSelectionRanges())==null?void 0:O[0])==null?void 0:S.startOffset,N=I.findIndex(U=>U+2===x);N!==-1?c==null||c.setActiveSelectionIndex(N):c==null||c.resetActiveSelectionIndex()}return u}function Nr(e,t){const n=a.useDependency(l.IUniverInstanceService),s=a.useDependency(l.ThemeService),r=a.useDependency(P.IRefSelectionsService),o=a.useDependency(H.IRenderManagerService),i=a.useObservable(_.useMemo(()=>n.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),[n])),c=i?o.getRenderById(i.getUnitId()):null,d=c==null?void 0:c.with(exports.RefSelectionsRenderService),g=c==null?void 0:c.with(k.SheetSkeletonManagerService),p=a.useEvent((m,f)=>{const h=n.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_SHEET);if(!h||d!=null&&d.selectionMoving)return;const u=qt({unitId:e,subUnitId:t,currentWorkbook:h,refSelections:m,editor:f,refSelectionsService:r,refSelectionsRenderService:d,sheetSkeletonManagerService:g,themeService:s,univerInstanceService:n});if(!u)return;((d==null?void 0:d.getSelectionControls())||[]).length===u.length?d==null||d.resetSelectionsByModelData(u):r.setSelections(u)});return _.useEffect(()=>()=>{d==null||d.resetActiveSelectionIndex()},[d]),p}function Yt(e=""){const t=a.useDependency(Ce.IDescriptionService),n=Dr(),s=a.useDependency(l.ICommandService),r=_.useMemo(()=>e.length,[e]);return a.useEvent((i,c,d=!0,g)=>{const p=i.getDocumentData(),m=i.getEditorId();if(!p)return[];const f=p.body;if(!f)return[];const h=f.dataStream.slice(0,f.dataStream.length-2),u={dataStream:"",...p.body};if(!h.startsWith(e))return[];if(c==null||c.length===0)return u.textRuns=[],s.syncExecuteCommand(ee.ReplaceTextRunsCommand.id,{unitId:m,body:l.getBodySlice(u,0,u.dataStream.length-2)}),[];{const{textRuns:R,refSelections:v}=kr(t,n,c);r&&R.forEach(b=>{b.ed=b.ed+r,b.st=b.st+r}),u.textRuns=[{st:0,ed:1,ts:{fs:11}},...R];const C=c.reduce((b,O)=>typeof O=="string"?`${b}${O}`:`${b}${O.token}`,"");u.dataStream=`${e}${C}\r
|
|
3
3
|
`;let I;if(d){I=i.getSelectionRanges();const b=u.dataStream.length-2+r;I.forEach(O=>{O.startOffset=Math.max(0,Math.min(O.startOffset,b)),O.endOffset=Math.max(0,Math.min(O.endOffset,b))})}return s.syncExecuteCommand(ee.ReplaceTextRunsCommand.id,{unitId:m,body:l.getBodySlice(u,0,u.dataStream.length-2),textRanges:g!=null?g:I}),v}})}function Dr(){const e=a.useDependency(l.ThemeService),t=e.getCurrentTheme();return _.useMemo(()=>{const s=[e.getColorFromTheme("loop-color.1"),e.getColorFromTheme("loop-color.2"),e.getColorFromTheme("loop-color.3"),e.getColorFromTheme("loop-color.4"),e.getColorFromTheme("loop-color.5"),e.getColorFromTheme("loop-color.6"),e.getColorFromTheme("loop-color.7"),e.getColorFromTheme("loop-color.8"),e.getColorFromTheme("loop-color.9"),e.getColorFromTheme("loop-color.10"),e.getColorFromTheme("loop-color.11"),e.getColorFromTheme("loop-color.12")].map(c=>e.isValidThemeColor(c)?e.getColorFromTheme(c):c),r=e.getColorFromTheme("blue.700"),o=e.getColorFromTheme("jiqing.800"),i=e.getColorFromTheme("black");return{formulaRefColors:s,numberColor:r,stringColor:o,plainTextColor:i}},[t])}function kr(e,t,n){const{formulaRefColors:s,numberColor:r,stringColor:o,plainTextColor:i}=t,c=[],d=[],g=new Map;let p=0;for(let m=0,f=n.length;m<f;m++){const h=n[m];if(typeof h=="string"){const b=c[c.length-1],O=b?b.ed:0,S=O+h.length;c.push({st:O,ed:S,ts:{cl:{rgb:i},fs:11}});continue}if(e.hasDefinedNameDescription(h.token.trim())){c.push({st:h.startIndex,ed:h.endIndex+1,ts:{cl:{rgb:i},fs:11}});continue}const{startIndex:u,endIndex:R,nodeType:v,token:C}=h;let I="";if(v===y.sequenceNodeType.REFERENCE){if(g.has(C))I=g.get(C);else{const b=p%s.length;I=s[b],g.set(C,I),p++}d.push({refIndex:m,themeColor:I,token:C,startIndex:h.startIndex,endIndex:h.endIndex,index:d.length})}else v===y.sequenceNodeType.NUMBER?I=r:(v===y.sequenceNodeType.STRING||v===y.sequenceNodeType.ARRAY)&&(I=o);I&&I.length>0?c.push({st:u,ed:R+1,ts:{cl:{rgb:I},fs:11}}):c.push({st:u,ed:R+1,ts:{cl:{rgb:i},fs:11}})}return{textRuns:c,refSelections:d}}const wr=(e,t,n,s)=>{const r=a.useDependency(l.ICommandService),o=a.useDependency(a.IShortcutService),i=_.useRef(t);i.current=t;const c=_.useRef(s);c.current=s,_.useEffect(()=>{if(!n||!e)return;const g=`sheet.formula-embedding-editor.${n.getEditorId()}`,p=new l.DisposableCollection,m=(u,R)=>{if(c.current){c.current(u,R);return}let v=l.Direction.LEFT;u===a.KeyCode.ARROW_DOWN?v=l.Direction.DOWN:u===a.KeyCode.ARROW_UP?v=l.Direction.UP:u===a.KeyCode.ARROW_RIGHT&&(v=l.Direction.RIGHT),R===a.MetaKeys.SHIFT?r.executeCommand(ee.MoveSelectionOperation.id,{direction:v}):r.executeCommand(ee.MoveCursorOperation.id,{direction:v})},f=(u,R)=>{let v=l.Direction.DOWN;u===a.KeyCode.ARROW_DOWN?v=l.Direction.DOWN:u===a.KeyCode.ARROW_UP?v=l.Direction.UP:u===a.KeyCode.ARROW_LEFT?v=l.Direction.LEFT:u===a.KeyCode.ARROW_RIGHT&&(v=l.Direction.RIGHT),i.current?R===a.MetaKeys.CTRL_COMMAND?r.executeCommand(k.MoveSelectionCommand.id,{direction:v,jumpOver:k.JumpOver.moveGap,extra:"formula-editor",fromCurrentSelection:i.current===me.NEED_ADD||i.current===me.EDIT_OTHER_SHEET_REFERENCE}):R===a.MetaKeys.SHIFT?r.executeCommand(k.ExpandSelectionCommand.id,{direction:v,extra:"formula-editor"}):R===(a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT)?r.executeCommand(k.ExpandSelectionCommand.id,{direction:v,jumpOver:k.JumpOver.moveGap,extra:"formula-editor"}):r.executeCommand(k.MoveSelectionCommand.id,{direction:v,extra:"formula-editor",fromCurrentSelection:i.current===me.NEED_ADD||i.current===me.EDIT_OTHER_SHEET_REFERENCE}):m(u,R)};return p.add(r.registerCommand({id:g,type:l.CommandType.OPERATION,handler(u,R){const{keyCode:v,metaKey:C}=R;f(v,C)}})),[{keyCode:a.KeyCode.ARROW_DOWN},{keyCode:a.KeyCode.ARROW_LEFT},{keyCode:a.KeyCode.ARROW_RIGHT},{keyCode:a.KeyCode.ARROW_UP},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT}].map(({keyCode:u,metaKey:R})=>({id:g,binding:R?u|R:u,preconditions:()=>!0,priority:900,staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keyCode:u,metaKey:R}})).forEach(u=>{p.add(o.registerShortcut(u))}),()=>{p.dispose()}},[r,n,e,o])},Ar=(e,t,n,s,r=!0)=>{var h;const o=a.useDependency(H.IRenderManagerService),i=a.useDependency(l.IContextService),c=a.useDependency(a.IContextMenuService),d=a.useDependency(P.IRefSelectionsService),g=a.useDependency(l.IUniverInstanceService),p=a.useObservable(_.useMemo(()=>g.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),[g])),m=o.getRenderById((h=p==null?void 0:p.getUnitId())!=null?h:""),f=m==null?void 0:m.with(exports.RefSelectionsRenderService);_.useLayoutEffect(()=>{if(e)return i.setContextValue(l.EDITOR_ACTIVATED,!0),r&&c.disable(),()=>{const u=g.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_DOC);(u==null?void 0:u.getUnitId())===s&&i.setContextValue(l.EDITOR_ACTIVATED,!1),r&&c.enable(),d.clear()}},[i,e,d,r,s]),_.useLayoutEffect(()=>{if(e&&t){const u=f==null?void 0:f.enableSelectionChanging();return i.setContextValue(P.REF_SELECTIONS_ENABLED,!0),()=>{i.setContextValue(P.REF_SELECTIONS_ENABLED,!1),u==null||u.dispose()}}},[i,e,f,t]),_.useEffect(()=>{e&&(f==null||f.setSkipLastEnabled(!1))},[e,f])},Fr=(e,t,n)=>{const s=a.useDependency(l.IUniverInstanceService),r=a.useDependency(P.SheetsSelectionsService);return _.useCallback(()=>{if(e){const i=[...r.getWorkbookSelections(t).getSelectionsOfWorksheet(n)],c=s.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),d=c==null?void 0:c.getActiveSheet();(c==null?void 0:c.getUnitId())!==t&&s.setCurrentUnitForType(t),d&&d.getSheetId()===n&&r.setSelections(i)}},[e,r,n,t,s])},Pr=e=>e.reduce((t,n)=>typeof n=="string"?t+n.length:t+n.token.length,0),it=e=>e.map(t=>typeof t=="string"?t:t.token).join(""),Ke=(e,t=!1,n="",s=!1)=>!t&&!s?e.map(r=>y.serializeRange(r.range)):e.map(r=>s?y.serializeRangeToRefString(r):r.sheetName!==""&&r.sheetName!==n?y.serializeRangeWithSheet(r.sheetName,r.range):y.serializeRange(r.range)),Lr=e=>{var p,m,f;const{editor:t,lexerTreeBuilder:n}=e,s=t==null?void 0:t.getSelectionRanges();if((s==null?void 0:s.length)!==1)return;const o=s[0].startOffset-1,i=((m=(p=t==null?void 0:t.getDocumentData().body)==null?void 0:p.dataStream)!=null?m:`\r
|
|
4
|
-
`).slice(0,-2),c=(f=n.sequenceNodesBuilder(i.slice(1)))!=null?f:[],d=lt(c,o,!1),g=Ht(c,d);return{nodeIndex:d,updatingRefIndex:g,sequenceNodes:c,offset:o}},Ur=(()=>{}),$r=(e,t,n,s,r,o,i,c,d,g=Ur)=>{var L;const p=a.useDependency(H.IRenderManagerService),m=a.useDependency(l.IUniverInstanceService),f=a.useDependency(l.ICommandService),h=a.useDependency(xt.DocSelectionManagerService),u=a.useDependency(l.ThemeService),R=a.useDependency(y.LexerTreeBuilder),v=m.getUnit(s),C=a.useEvent((D,M)=>{var A,T,F;return(F=(T=(A=m.getUnit(D))==null?void 0:A.getSheetBySheetId(M))==null?void 0:T.getName())!=null?F:""}),I=_.useMemo(()=>C(s,r),[C,r,s]),b=a.useObservable(v==null?void 0:v.activeSheet$),O=Oe({activeSheet:b,sheetName:I}),S=a.useObservable(_.useMemo(()=>m.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),[m])),x=p.getRenderById((L=S==null?void 0:S.getUnitId())!=null?L:""),N=x==null?void 0:x.with(exports.RefSelectionsRenderService),U=x==null?void 0:x.with(k.SheetSkeletonManagerService),$=a.useDependency(P.IRefSelectionsService),w=a.useEvent((D,M)=>{var B,re,se,ie,Y,Q,Ne,De,Ue,ue;const A=Lr({editor:d,lexerTreeBuilder:R});if(!A)return;const{nodeIndex:T,updatingRefIndex:F,sequenceNodes:j,offset:V}=A;if(n.current===me.NEED_ADD)if(V!==0){if(T===-1&&j.length)return;const z=D[D.length-1],X=j.splice(T+1),de=(B=z.sheetId)!=null?B:r,ce={range:z,unitId:(re=z.unitId)!=null?re:S.getUnitId(),sheetName:C((se=z.unitId)!=null?se:S.getUnitId(),de)},J=de!==r,oe=(S==null?void 0:S.getUnitId())!==s,he=Ke([ce],i&&(J||oe),I,oe);j.push({token:he[0],nodeType:y.sequenceNodeType.REFERENCE});const Re=[...j,...X],pe=it(Re);g(pe,Pr(j),M)}else{const z=D[D.length-1],X=(ie=z.sheetId)!=null?ie:r,de={range:z,unitId:(Y=z.unitId)!=null?Y:S.getUnitId(),sheetName:C((Q=z.unitId)!=null?Q:S.getUnitId(),X)},ce=X!==r,J=(S==null?void 0:S.getUnitId())!==s,oe=Ke([de],i&&(ce||J),I,J);j.unshift({token:oe[0],nodeType:y.sequenceNodeType.REFERENCE});const he=it(j);g(he,oe[0].length,M)}else if(n.current===me.EDIT_OTHER_SHEET_REFERENCE||n.current===me.EDIT_OTHER_WORKBOOK_REFERENCE){const z=D.pop();if(!z)return;const X=j[T];if(typeof X=="object"&&X.nodeType===y.sequenceNodeType.REFERENCE){const de=X.token;(S==null?void 0:S.getUnitId())!==s?X.token=y.serializeRangeWithSpreadsheet((Ne=S==null?void 0:S.getUnitId())!=null?Ne:"",I,z):X.token=I===(b==null?void 0:b.getName())?y.serializeRange(z):y.serializeRangeWithSheet(b.getName(),z);const J=V+(X.token.length-de.length);g(y.generateStringWithSequence(j),J,M)}}else{const z=[...D];if(F!==-1){const G=z.pop();G&&z.splice(F,0,G)}let X=0;const de=j.map(G=>{var ae,ke,_e,Ie;if(typeof G=="string")return G;if(G.nodeType===y.sequenceNodeType.REFERENCE){const Ee=y.deserializeRangeWithSheet(G.token);if(Ee.sheetName||(Ee.sheetName=I),(Ee.unitId||s)!==(S==null?void 0:S.getUnitId())||i&&((ae=O.current.activeSheet)==null?void 0:ae.getName())!==Ee.sheetName)return G.token;const te=z[X];if(X++,!te)return"";const fe=(ke=te.sheetId)!=null?ke:r,$e={range:te,unitId:(_e=te.unitId)!=null?_e:S.getUnitId(),sheetName:C((Ie=te.unitId)!=null?Ie:S.getUnitId(),fe)},je=(S==null?void 0:S.getUnitId())!==s;return Ke([$e],i&&(fe!==r||je),I,je)[0]}return G.token});let ce="",J;de.forEach((G,ae)=>{ce+=G,ae===T&&(J=ce.length)});const oe=[];for(let G=X;G<=D.length-1;G++){const ae=D[G],ke=(De=ae.sheetId)!=null?De:r,_e={range:ae,unitId:(Ue=ae.unitId)!=null?Ue:S.getUnitId(),sheetName:C((ue=ae.unitId)!=null?ue:S.getUnitId(),ke)},Ie=(S==null?void 0:S.getUnitId())!==s,te=Ke([_e],i&&(ke!==r||Ie),I,Ie);oe.push(te[0])}const he=j[j.length-1],Re=he&&(typeof he=="string"?!1:he.nodeType===y.sequenceNodeType.REFERENCE),pe=`${ce}${oe.length&&Re?",":""}${oe.join(",")}`;g(pe,!oe.length&&J?J:pe.length,M)}});_.useEffect(()=>{if(N&&e){let D=!0;const M=(T,F)=>{if(D){D=!1;return}w(T.map(j=>j.rangeWithCoord),F)},A=new l.DisposableCollection;return A.add(N.selectionMoving$.subscribe(T=>{M(T,!1)})),A.add(N.selectionMoveEnd$.subscribe(T=>{M(T,!0)})),()=>{A.dispose()}}},[e,w,N]),_.useEffect(()=>{if(t&&N&&d){const D=new l.DisposableCollection,M=()=>{D.dispose(),N.getSelectionControls().forEach((F,j)=>{D.add(F.selectionScaling$.subscribe(V=>{const B=N.getSelectionDataWithStyle().map(se=>se.rangeWithCoord),re=B[j];V.sheetId=re.sheetId,V.unitId=re.unitId,B[j]=V,w(B,!1)})),D.add(F.selectionMoving$.subscribe(V=>{const B=N.getSelectionDataWithStyle().map(se=>se.rangeWithCoord),re=B[j];V.sheetId=re.sheetId,V.unitId=re.unitId,B[j]=V,w(B,!0)}))})},A=q.merge(d.input$,$.selectionSet$,N.selectionMoveEnd$).pipe(nn.debounceTime(50)).subscribe(()=>{M()});return()=>{A.unsubscribe(),D.dispose()}}},[d,t,w,N,$.selectionSet$]),N==null||N.getSelectionDataWithStyle(),_.useEffect(()=>{if(c){const D=f.onCommandExecuted(M=>{var T;if(M.id!==P.SetSelectionsOperation.id)return;const A=M.params;if(A.extra==="formula-editor"&&A.selections.length){const F=A.selections[A.selections.length-1];if(F){const j=n.current===me.NEED_ADD,V=((T=N==null?void 0:N.getSelectionDataWithStyle())!=null?T:[]).map(B=>B.rangeWithCoord);j?V.push(F.range):V[V.length-1]=F.range,w(V,!0)}}});return()=>{D.dispose()}}},[f,d,n,R,c,w,N]),_.useEffect(()=>{if(!d)return;const D=h.textSelection$.subscribe(M=>{M.unitId===d.getEditorId()&&qt({unitId:s,subUnitId:r,refSelections:o.current,editor:d,refSelectionsService:$,refSelectionsRenderService:N,sheetSkeletonManagerService:U,themeService:u,univerInstanceService:m,currentWorkbook:S})});return()=>D.unsubscribe()},[h.textSelection$,d,o,N,$,U,r,u,s,m])},jr=(e,t,n,s,r,o)=>{const i=a.useDependency(l.ICommandService),c=a.useDependency(ee.IEditorService),g=a.useDependency(H.IRenderManagerService).getRenderById(t),p=a.useDependency(l.IUniverInstanceService),m=g==null?void 0:g.with(exports.RefSelectionsRenderService);_.useEffect(()=>{if(e&&m)if(n){const f=()=>{const R=m.getSelectionControls().length;for(let v=1;v<=R;v++)m.clearLastSelection();return setTimeout(()=>{o()},30)},h=i.onCommandExecuted(R=>{R.id===P.SetWorksheetActiveOperation.id&&f()}),u=p.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).subscribe(R=>{f()});return()=>{h.dispose(),u.unsubscribe()}}else{const f=i.beforeCommandExecuted(h=>{if(h.id===P.SetWorksheetActiveOperation.id){s(!1),r(),o();const u=c.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);u==null||u.focus()}});return()=>{f.dispose()}}},[e,m])},Wr=(e,t,n)=>{const s=a.useDependency(y.LexerTreeBuilder),r=_.useRef(!0);_.useEffect(()=>{if(e){const o=setTimeout(()=>{r.current=!1},500);return()=>{clearTimeout(o)}}},[e]),_.useEffect(()=>{if(!r.current&&t){const o=s.checkIfAddBracket(n);t(o===0&&n.startsWith(y.operatorToken.EQUALS),`${n}`)}},[n,t])},Vr=(e,t=[],n)=>{const s=a.useDependency(Ce.IDescriptionService),[r,o]=_.useState([]),[i,c]=_.useState(""),d=_.useRef(-1),g=Oe({nodes:t}),p=()=>{o([]),c(""),d.current=-1};return _.useEffect(()=>{if(n&&e){const f=n.input$.pipe(q.debounceTime(300)).subscribe(()=>{const h=n.getSelectionRanges();if(h.length===1){const u=g.current.nodes,R=h[0];if(R.collapsed){const v=lt(u,R.startOffset-1,!1);d.current=v;const C=u[v];if(C&&typeof C!="string"&&C.nodeType===y.sequenceNodeType.FUNCTION){d.current=v;const I=C.token,b=s.getSearchListByNameFirstLetter(I);o(b),c(I);return}}}d.current=-1,c(""),o(u=>u!=null&&u.length?[]:u)});return()=>{f.unsubscribe()}}},[n,e]),_.useEffect(()=>{e||p()},[e]),{searchList:r,searchText:i,handlerFormulaReplace:(f,h)=>{const u=[...g.current.nodes];if(d.current!==-1){const R=u.splice(d.current+1),v=u.pop()||"";let C=(typeof v=="string"?v.length:v.token.length)-f.length;return u.push(f),R[0]!==y.matchToken.OPEN_BRACKET&&h!==y.FunctionType.DefinedName&&(u.push(y.matchToken.OPEN_BRACKET),C--),{text:it([...u,...R]),offset:C}}},reset:p}},Br=()=>{},Hr=_.forwardRef(Kr);function Kr(e,t){const{isFocus:n,sequenceNodes:s,onSelect:r,editor:o,onClose:i=Br}=e,c=o.getEditorId(),d=a.useDependency(a.IShortcutService),g=a.useDependency(l.ICommandService),{searchList:p,searchText:m,handlerFormulaReplace:f,reset:h}=Vr(n,s,o),u=_.useMemo(()=>!!p.length,[p]),R=_.useRef(void 0),[v,C]=_.useState(0),I=_.useRef(!1),[b]=Kt(c,u,[m,p]),O=Oe({searchList:p,active:v}),S=(w,L)=>{const D=f(w,L);D&&(h(),r(D))};function x(w){I.current&&C(w)}function N(){I.current&&C(-1)}_.useEffect(()=>{if(!p.length)return;const w=`sheet.formula-embedding-editor.search_function.${c}`,L=new l.DisposableCollection,D=M=>{const{searchList:A,active:T}=O.current;switch(M){case a.KeyCode.ARROW_UP:{C(F=>{const j=Math.max(0,F-1);return U(j),j});break}case a.KeyCode.ARROW_DOWN:{C(F=>{const j=Math.min(A.length-1,F+1);return U(j),j});break}case a.KeyCode.TAB:case a.KeyCode.ENTER:{const F=A[T];S(F.name,F.functionType);break}case a.KeyCode.ESC:{h(),i();break}}};return L.add(g.registerCommand({id:w,type:l.CommandType.OPERATION,handler(M,A){const{keyCode:T}=A;D(T)}})),[a.KeyCode.ARROW_UP,a.KeyCode.ARROW_DOWN,a.KeyCode.ENTER,a.KeyCode.ESC,a.KeyCode.TAB].map(M=>({id:w,binding:M,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keyCode:M}})).forEach(M=>{L.add(d.registerShortcut(M))}),()=>{L.dispose()}},[p]);function U(w){const L=R.current;if(!L)return;const D=L.children[w];if(!D)return;const A=L.getBoundingClientRect().top,T=L.offsetHeight,F=D.getBoundingClientRect(),j=F.top,V=F.height;if(j>=0&&j>A&&j-A+V<=T)return;const B=D.offsetTop-(T-V)/2;L.scrollTo({top:B,behavior:"smooth"})}const $=_.useMemo(()=>{let w="";return()=>{clearTimeout(w),I.current=!0,w=setTimeout(()=>{I.current=!1},300)}},[]);return p.length>0&&u&&E.jsx(a.RectPopup,{portal:!0,anchorRect$:b,direction:"vertical",children:E.jsx("ul",{ref:w=>{R.current=w,t&&(t.current=w)},"data-u-comp":"sheets-formula-editor",className:W.clsx("univer-m-0 univer-box-border univer-max-h-[400px] univer-w-[250px] univer-list-none univer-overflow-y-auto univer-rounded-lg univer-bg-white univer-p-2 univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",W.borderClassName,W.scrollbarClassName),children:p.map((w,L)=>E.jsxs("li",{className:W.clsx("univer-box-border univer-cursor-pointer univer-rounded univer-px-2 univer-py-1 univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200 dark:!univer-bg-gray-600":v===L}),onMouseEnter:()=>x(L),onMouseLeave:N,onMouseMove:$,onClick:()=>{S(w.name,w.functionType),o&&o.focus()},children:[E.jsxs("span",{className:"univer-block univer-overflow-x-hidden univer-text-ellipsis univer-text-xs",children:[E.jsx("span",{className:"univer-text-red-500",children:w.name.substring(0,m.length)}),E.jsx("span",{children:w.name.slice(m.length)})]}),E.jsx("span",{className:"univer-block univer-text-xs univer-text-gray-400",children:w.desc})]},w.name))})})}const qr=e=>e.startsWith(y.operatorToken.EQUALS)?e.slice(1):"",bt=()=>{},zt=_.forwardRef((e,t)=>{var ft,gt,mt,pt;const{errorText:n,initValue:s,unitId:r,subUnitId:o,isFocus:i=!0,isSupportAcrossSheet:c=!1,onFocus:d=bt,onBlur:g=bt,onChange:p,onVerify:m,className:f,editorId:h,moveCursor:u=!0,onFormulaSelectingChange:R,keyboardEventConfig:v,onMoveInEditor:C,resetSelectionOnBlur:I=!0,autoScrollbar:b=!0,isSingle:O=!0,disableSelectionOnClick:S=!1,autofocus:x=!0,disableContextMenu:N,style:U}=e,$=a.useDependency(ee.IEditorService),w=_.useRef(null),L=a.useEvent(p);_.useImperativeHandle(t,()=>({isClickOutSide:Z=>w.current?!w.current.contains(Z.target):!1}));const D=a.useEvent(R),M=_.useRef(null),A=_.useRef(void 0),T=A.current,[F,j]=_.useState(i),V=_.useRef(null),B=_.useMemo(()=>h!=null?h:l.createInternalEditorID(`${k.EMBEDDING_FORMULA_EDITOR}-${l.generateRandomId(4)}`),[]),re=_.useMemo(()=>n!==void 0,[n]),se=a.useDependency(l.IUniverInstanceService),ie=se.getUnit(B);a.useObservable(ie==null?void 0:ie.change$);const Y=Mr(),Q=l.BuildTextUtils.transform.getPlainText((gt=(ft=ie==null?void 0:ie.getBody())==null?void 0:ft.dataStream)!=null?gt:""),Ne=Oe(Q),De=_.useMemo(()=>qr(Q),[Q]),Ue=_.useMemo(()=>Y(De),[De,Y]),{isSelecting:ue,isSelectingRef:z}=xr({unitId:r,subUnitId:o,editorId:B,isFocus:F,disableOnClick:S}),X=_.useRef(""),ce=a.useDependency(H.IRenderManagerService).getRenderById(B),J=ce==null?void 0:ce.with(ee.DocSelectionRenderService),oe=J==null?void 0:J.isFocusing,he=_.useMemo(()=>se.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_DOC),[se]),Re=a.useObservable(he),pe=(Re==null?void 0:Re.getUnitId())===B,G=_.useRef([]),ae=ue,_e=(pt=(mt=a.useDependency(l.IConfigService).getConfig(wt))==null?void 0:mt.functionScreenTips)!=null?pt:!0;a.useUpdateEffect(()=>{L(Q)},[Q,L]);const Ie=Yt("="),Ee=Nr(r,o),te=a.useEvent((Z,ne=!0,Se,ge)=>{if(!A.current)return;X.current=Z;const We=Z[0]==="="?Z.slice(1):"",ve=Y(We),Xt=ve.reduce((ye,Be)=>typeof Be=="object"?`${ye}${Be.token}`:`${ye}${Be}`,""),Ve=Ie(A.current,Xt===We?ve:[],ne,ge);if(G.current=Ve,Se){const ye=ge!=null?ge:T==null?void 0:T.getSelectionRanges();if((ye==null?void 0:ye.length)!==1)return;const Qt=ye[0].startOffset-1,Jt=lt(ve,Qt,!1),St=Ht(ve,Jt);if(St>=0){const vt=Ve.splice(St,1)[0];vt&&Ve.push(vt)}Ee(F?Ve:[],A.current)}});_.useEffect(()=>{F&&te(Q,!1,!0)},[F]),_.useEffect(()=>{if(F){if(X.current===Q)return;te(Q,!1,!0)}},[Q]),Wr(F,m,Q);const fe=br(T),$e=Fr(F,r,o);_.useEffect(()=>{var Z;D(ue,(Z=J==null?void 0:J.isFocusing)!=null?Z:!0)},[D,ue]),ee.useKeyboardEvent(F,v,T),_.useLayoutEffect(()=>{let Z;if(V.current){Z=$.register({autofocus:x,editorUnitId:B,initialSnapshot:{id:B,body:{dataStream:`${s}\r
|
|
4
|
+
`).slice(0,-2),c=(f=n.sequenceNodesBuilder(i.slice(1)))!=null?f:[],d=lt(c,o,!1),g=Ht(c,d);return{nodeIndex:d,updatingRefIndex:g,sequenceNodes:c,offset:o}},Ur=(()=>{}),$r=(e,t,n,s,r,o,i,c,d,g=Ur)=>{var L;const p=a.useDependency(H.IRenderManagerService),m=a.useDependency(l.IUniverInstanceService),f=a.useDependency(l.ICommandService),h=a.useDependency(xt.DocSelectionManagerService),u=a.useDependency(l.ThemeService),R=a.useDependency(y.LexerTreeBuilder),v=m.getUnit(s),C=a.useEvent((D,M)=>{var A,T,F;return(F=(T=(A=m.getUnit(D))==null?void 0:A.getSheetBySheetId(M))==null?void 0:T.getName())!=null?F:""}),I=_.useMemo(()=>C(s,r),[C,r,s]),b=a.useObservable(v==null?void 0:v.activeSheet$),O=Oe({activeSheet:b,sheetName:I}),S=a.useObservable(_.useMemo(()=>m.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),[m])),x=p.getRenderById((L=S==null?void 0:S.getUnitId())!=null?L:""),N=x==null?void 0:x.with(exports.RefSelectionsRenderService),U=x==null?void 0:x.with(k.SheetSkeletonManagerService),$=a.useDependency(P.IRefSelectionsService),w=a.useEvent((D,M)=>{var B,re,se,ie,Y,Q,Ne,De,Ue,ue;const A=Lr({editor:d,lexerTreeBuilder:R});if(!A)return;const{nodeIndex:T,updatingRefIndex:F,sequenceNodes:j,offset:V}=A;if(n.current===me.NEED_ADD)if(V!==0){if(T===-1&&j.length)return;const z=D[D.length-1],X=j.splice(T+1),de=(B=z.sheetId)!=null?B:r,ce={range:z,unitId:(re=z.unitId)!=null?re:S.getUnitId(),sheetName:C((se=z.unitId)!=null?se:S.getUnitId(),de)},J=de!==r,oe=(S==null?void 0:S.getUnitId())!==s,he=Ke([ce],i&&(J||oe),I,oe);j.push({token:he[0],nodeType:y.sequenceNodeType.REFERENCE});const Re=[...j,...X],pe=it(Re);g(pe,Pr(j),M)}else{const z=D[D.length-1],X=(ie=z.sheetId)!=null?ie:r,de={range:z,unitId:(Y=z.unitId)!=null?Y:S.getUnitId(),sheetName:C((Q=z.unitId)!=null?Q:S.getUnitId(),X)},ce=X!==r,J=(S==null?void 0:S.getUnitId())!==s,oe=Ke([de],i&&(ce||J),I,J);j.unshift({token:oe[0],nodeType:y.sequenceNodeType.REFERENCE});const he=it(j);g(he,oe[0].length,M)}else if(n.current===me.EDIT_OTHER_SHEET_REFERENCE||n.current===me.EDIT_OTHER_WORKBOOK_REFERENCE){const z=D.pop();if(!z)return;const X=j[T];if(typeof X=="object"&&X.nodeType===y.sequenceNodeType.REFERENCE){const de=X.token;(S==null?void 0:S.getUnitId())!==s?X.token=y.serializeRangeWithSpreadsheet((Ne=S==null?void 0:S.getUnitId())!=null?Ne:"",I,z):X.token=I===(b==null?void 0:b.getName())?y.serializeRange(z):y.serializeRangeWithSheet(b.getName(),z);const J=V+(X.token.length-de.length);g(y.generateStringWithSequence(j),J,M)}}else{const z=[...D];if(F!==-1){const G=z.pop();G&&z.splice(F,0,G)}let X=0;const de=j.map(G=>{var ae,ke,_e,Ie;if(typeof G=="string")return G;if(G.nodeType===y.sequenceNodeType.REFERENCE){const Ee=y.deserializeRangeWithSheet(G.token);if(Ee.sheetName||(Ee.sheetName=I),(Ee.unitId||s)!==(S==null?void 0:S.getUnitId())||i&&((ae=O.current.activeSheet)==null?void 0:ae.getName())!==Ee.sheetName)return G.token;const te=z[X];if(X++,!te)return"";const fe=(ke=te.sheetId)!=null?ke:r,$e={range:te,unitId:(_e=te.unitId)!=null?_e:S.getUnitId(),sheetName:C((Ie=te.unitId)!=null?Ie:S.getUnitId(),fe)},je=(S==null?void 0:S.getUnitId())!==s;return Ke([$e],i&&(fe!==r||je),I,je)[0]}return G.token});let ce="",J;de.forEach((G,ae)=>{ce+=G,ae===T&&(J=ce.length)});const oe=[];for(let G=X;G<=D.length-1;G++){const ae=D[G],ke=(De=ae.sheetId)!=null?De:r,_e={range:ae,unitId:(Ue=ae.unitId)!=null?Ue:S.getUnitId(),sheetName:C((ue=ae.unitId)!=null?ue:S.getUnitId(),ke)},Ie=(S==null?void 0:S.getUnitId())!==s,te=Ke([_e],i&&(ke!==r||Ie),I,Ie);oe.push(te[0])}const he=j[j.length-1],Re=he&&(typeof he=="string"?!1:he.nodeType===y.sequenceNodeType.REFERENCE),pe=`${ce}${oe.length&&Re?",":""}${oe.join(",")}`;g(pe,!oe.length&&J?J:pe.length,M)}});_.useEffect(()=>{if(N&&e){let D=!0;const M=(T,F)=>{if(D){D=!1;return}w(T.map(j=>j.rangeWithCoord),F)},A=new l.DisposableCollection;return A.add(N.selectionMoving$.subscribe(T=>{M(T,!1)})),A.add(N.selectionMoveEnd$.subscribe(T=>{M(T,!0)})),()=>{A.dispose()}}},[e,w,N]),_.useEffect(()=>{if(t&&N&&d){const D=new l.DisposableCollection,M=()=>{D.dispose(),N.getSelectionControls().forEach((F,j)=>{D.add(F.selectionScaling$.subscribe(V=>{const B=N.getSelectionDataWithStyle().map(se=>se.rangeWithCoord),re=B[j];V.sheetId=re.sheetId,V.unitId=re.unitId,B[j]=V,w(B,!1)})),D.add(F.selectionMoving$.subscribe(V=>{const B=N.getSelectionDataWithStyle().map(se=>se.rangeWithCoord),re=B[j];V.sheetId=re.sheetId,V.unitId=re.unitId,B[j]=V,w(B,!0)}))})},A=q.merge(d.input$,$.selectionSet$,N.selectionMoveEnd$).pipe(nn.debounceTime(50)).subscribe(()=>{M()});return()=>{A.unsubscribe(),D.dispose()}}},[d,t,w,N,$.selectionSet$]),N==null||N.getSelectionDataWithStyle(),_.useEffect(()=>{if(c){const D=f.onCommandExecuted(M=>{var T;if(M.id!==P.SetSelectionsOperation.id)return;const A=M.params;if(A.extra==="formula-editor"&&A.selections.length){const F=A.selections[A.selections.length-1];if(F){const j=n.current===me.NEED_ADD,V=((T=N==null?void 0:N.getSelectionDataWithStyle())!=null?T:[]).map(B=>B.rangeWithCoord);j?V.push(F.range):V[V.length-1]=F.range,w(V,!0)}}});return()=>{D.dispose()}}},[f,d,n,R,c,w,N]),_.useEffect(()=>{if(!d)return;const D=h.textSelection$.subscribe(M=>{M.unitId===d.getEditorId()&&qt({unitId:s,subUnitId:r,refSelections:o.current,editor:d,refSelectionsService:$,refSelectionsRenderService:N,sheetSkeletonManagerService:U,themeService:u,univerInstanceService:m,currentWorkbook:S})});return()=>D.unsubscribe()},[h.textSelection$,d,o,N,$,U,r,u,s,m])},jr=(e,t,n,s,r,o)=>{const i=a.useDependency(l.ICommandService),c=a.useDependency(ee.IEditorService),g=a.useDependency(H.IRenderManagerService).getRenderById(t),p=a.useDependency(l.IUniverInstanceService),m=g==null?void 0:g.with(exports.RefSelectionsRenderService);_.useEffect(()=>{if(e&&m)if(n){const f=()=>{const R=m.getSelectionControls().length;for(let v=1;v<=R;v++)m.clearLastSelection();return setTimeout(()=>{o()},30)},h=i.onCommandExecuted(R=>{R.id===P.SetWorksheetActiveOperation.id&&f()}),u=p.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).subscribe(R=>{f()});return()=>{h.dispose(),u.unsubscribe()}}else{const f=i.beforeCommandExecuted(h=>{if(h.id===P.SetWorksheetActiveOperation.id){s(!1),r(),o();const u=c.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);u==null||u.focus()}});return()=>{f.dispose()}}},[e,m])},Wr=(e,t,n)=>{const s=a.useDependency(y.LexerTreeBuilder),r=_.useRef(!0);_.useEffect(()=>{if(e){const o=setTimeout(()=>{r.current=!1},500);return()=>{clearTimeout(o)}}},[e]),_.useEffect(()=>{if(!r.current&&t){const o=s.checkIfAddBracket(n);t(o===0&&n.startsWith(y.operatorToken.EQUALS),`${n}`)}},[n,t])},Vr=(e,t=[],n)=>{const s=a.useDependency(Ce.IDescriptionService),[r,o]=_.useState([]),[i,c]=_.useState(""),d=_.useRef(-1),g=Oe({nodes:t}),p=()=>{o([]),c(""),d.current=-1};return _.useEffect(()=>{if(n&&e){const f=n.input$.pipe(q.debounceTime(300)).subscribe(()=>{const h=n.getSelectionRanges();if(h.length===1){const u=g.current.nodes,R=h[0];if(R.collapsed){const v=lt(u,R.startOffset-1,!1);d.current=v;const C=u[v];if(C&&typeof C!="string"&&C.nodeType===y.sequenceNodeType.FUNCTION){d.current=v;const I=C.token,b=s.getSearchListByNameFirstLetter(I);o(b),c(I);return}}}d.current=-1,c(""),o(u=>u!=null&&u.length?[]:u)});return()=>{f.unsubscribe()}}},[n,e]),_.useEffect(()=>{e||p()},[e]),{searchList:r,searchText:i,handlerFormulaReplace:(f,h)=>{const u=[...g.current.nodes];if(d.current!==-1){const R=u.splice(d.current+1),v=u.pop()||"";let C=(typeof v=="string"?v.length:v.token.length)-f.length;return u.push(f),R[0]!==y.matchToken.OPEN_BRACKET&&h!==y.FunctionType.DefinedName&&(u.push(y.matchToken.OPEN_BRACKET),C--),{text:it([...u,...R]),offset:C}}},reset:p}},Br=()=>{},Hr=_.forwardRef(Kr);function Kr(e,t){const{isFocus:n,sequenceNodes:s,onSelect:r,editor:o,onClose:i=Br}=e,c=o.getEditorId(),d=a.useDependency(a.IShortcutService),g=a.useDependency(l.ICommandService),{searchList:p,searchText:m,handlerFormulaReplace:f,reset:h}=Vr(n,s,o),u=_.useMemo(()=>!!p.length,[p]),R=_.useRef(void 0),[v,C]=_.useState(0),I=_.useRef(!1),[b]=Kt(c,u,[m,p]),O=Oe({searchList:p,active:v}),S=(w,L)=>{const D=f(w,L);D&&(h(),r(D))};function x(w){I.current&&C(w)}function N(){I.current&&C(-1)}_.useEffect(()=>{if(!p.length)return;const w=`sheet.formula-embedding-editor.search_function.${c}`,L=new l.DisposableCollection,D=M=>{const{searchList:A,active:T}=O.current;switch(M){case a.KeyCode.ARROW_UP:{C(F=>{const j=Math.max(0,F-1);return U(j),j});break}case a.KeyCode.ARROW_DOWN:{C(F=>{const j=Math.min(A.length-1,F+1);return U(j),j});break}case a.KeyCode.TAB:case a.KeyCode.ENTER:{const F=A[T];S(F.name,F.functionType);break}case a.KeyCode.ESC:{h(),i();break}}};return L.add(g.registerCommand({id:w,type:l.CommandType.OPERATION,handler(M,A){const{keyCode:T}=A;D(T)}})),[a.KeyCode.ARROW_UP,a.KeyCode.ARROW_DOWN,a.KeyCode.ENTER,a.KeyCode.ESC,a.KeyCode.TAB].map(M=>({id:w,binding:M,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keyCode:M}})).forEach(M=>{L.add(d.registerShortcut(M))}),()=>{L.dispose()}},[p]);function U(w){const L=R.current;if(!L)return;const D=L.children[w];if(!D)return;const A=L.getBoundingClientRect().top,T=L.offsetHeight,F=D.getBoundingClientRect(),j=F.top,V=F.height;if(j>=0&&j>A&&j-A+V<=T)return;const B=D.offsetTop-(T-V)/2;L.scrollTo({top:B,behavior:"smooth"})}const $=_.useMemo(()=>{let w="";return()=>{clearTimeout(w),I.current=!0,w=setTimeout(()=>{I.current=!1},300)}},[]);return p.length>0&&u&&E.jsx(a.RectPopup,{portal:!0,anchorRect$:b,direction:"vertical",children:E.jsx("ul",{ref:w=>{R.current=w,t&&(t.current=w)},"data-u-comp":"sheets-formula-editor",className:W.clsx("univer-m-0 univer-box-border univer-max-h-[400px] univer-w-[250px] univer-list-none univer-overflow-y-auto univer-rounded-lg univer-bg-white univer-p-2 univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",W.borderClassName,W.scrollbarClassName),children:p.map((w,L)=>E.jsxs("li",{className:W.clsx("univer-box-border univer-cursor-pointer univer-rounded univer-px-2 univer-py-1 univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200 dark:!univer-bg-gray-600":v===L}),onMouseEnter:()=>x(L),onMouseLeave:N,onMouseMove:$,onClick:()=>{S(w.name,w.functionType),o&&o.focus()},children:[E.jsxs("span",{className:"univer-block univer-truncate univer-text-xs",children:[E.jsx("span",{className:"univer-text-red-500",children:w.name.substring(0,m.length)}),E.jsx("span",{children:w.name.slice(m.length)})]}),E.jsx("span",{className:"univer-block univer-text-xs univer-text-gray-400",children:w.desc})]},w.name))})})}const qr=e=>e.startsWith(y.operatorToken.EQUALS)?e.slice(1):"",bt=()=>{},zt=_.forwardRef((e,t)=>{var ft,gt,mt,pt;const{errorText:n,initValue:s,unitId:r,subUnitId:o,isFocus:i=!0,isSupportAcrossSheet:c=!1,onFocus:d=bt,onBlur:g=bt,onChange:p,onVerify:m,className:f,editorId:h,moveCursor:u=!0,onFormulaSelectingChange:R,keyboardEventConfig:v,onMoveInEditor:C,resetSelectionOnBlur:I=!0,autoScrollbar:b=!0,isSingle:O=!0,disableSelectionOnClick:S=!1,autofocus:x=!0,disableContextMenu:N,style:U}=e,$=a.useDependency(ee.IEditorService),w=_.useRef(null),L=a.useEvent(p);_.useImperativeHandle(t,()=>({isClickOutSide:Z=>w.current?!w.current.contains(Z.target):!1}));const D=a.useEvent(R),M=_.useRef(null),A=_.useRef(void 0),T=A.current,[F,j]=_.useState(i),V=_.useRef(null),B=_.useMemo(()=>h!=null?h:l.createInternalEditorID(`${k.EMBEDDING_FORMULA_EDITOR}-${l.generateRandomId(4)}`),[]),re=_.useMemo(()=>n!==void 0,[n]),se=a.useDependency(l.IUniverInstanceService),ie=se.getUnit(B);a.useObservable(ie==null?void 0:ie.change$);const Y=Mr(),Q=l.BuildTextUtils.transform.getPlainText((gt=(ft=ie==null?void 0:ie.getBody())==null?void 0:ft.dataStream)!=null?gt:""),Ne=Oe(Q),De=_.useMemo(()=>qr(Q),[Q]),Ue=_.useMemo(()=>Y(De),[De,Y]),{isSelecting:ue,isSelectingRef:z}=xr({unitId:r,subUnitId:o,editorId:B,isFocus:F,disableOnClick:S}),X=_.useRef(""),ce=a.useDependency(H.IRenderManagerService).getRenderById(B),J=ce==null?void 0:ce.with(ee.DocSelectionRenderService),oe=J==null?void 0:J.isFocusing,he=_.useMemo(()=>se.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_DOC),[se]),Re=a.useObservable(he),pe=(Re==null?void 0:Re.getUnitId())===B,G=_.useRef([]),ae=ue,_e=(pt=(mt=a.useDependency(l.IConfigService).getConfig(wt))==null?void 0:mt.functionScreenTips)!=null?pt:!0;a.useUpdateEffect(()=>{L(Q)},[Q,L]);const Ie=Yt("="),Ee=Nr(r,o),te=a.useEvent((Z,ne=!0,Se,ge)=>{if(!A.current)return;X.current=Z;const We=Z[0]==="="?Z.slice(1):"",ve=Y(We),Xt=ve.reduce((ye,Be)=>typeof Be=="object"?`${ye}${Be.token}`:`${ye}${Be}`,""),Ve=Ie(A.current,Xt===We?ve:[],ne,ge);if(G.current=Ve,Se){const ye=ge!=null?ge:T==null?void 0:T.getSelectionRanges();if((ye==null?void 0:ye.length)!==1)return;const Qt=ye[0].startOffset-1,Jt=lt(ve,Qt,!1),St=Ht(ve,Jt);if(St>=0){const vt=Ve.splice(St,1)[0];vt&&Ve.push(vt)}Ee(F?Ve:[],A.current)}});_.useEffect(()=>{F&&te(Q,!1,!0)},[F]),_.useEffect(()=>{if(F){if(X.current===Q)return;te(Q,!1,!0)}},[Q]),Wr(F,m,Q);const fe=br(T),$e=Fr(F,r,o);_.useEffect(()=>{var Z;D(ue,(Z=J==null?void 0:J.isFocusing)!=null?Z:!0)},[D,ue]),ee.useKeyboardEvent(F,v,T),_.useLayoutEffect(()=>{let Z;if(V.current){Z=$.register({autofocus:x,editorUnitId:B,initialSnapshot:{id:B,body:{dataStream:`${s}\r
|
|
5
5
|
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},V.current);const ne=$.getEditor(B);A.current=ne,te(s,!1,!0)}return()=>{Z==null||Z.dispose()}},[]),_.useLayoutEffect(()=>{i?(j(i),fe()):(I&&(T==null||T.blur(),$e()),j(i))},[i,T,fe,$e,I]);const{checkScrollBar:je}=ee.useResize(T,O,b);Ar(F,!!(ue&&pe),r,B,N),wr(!!(F&&oe&&u),ae,T,C);const dt=a.useEvent((Z,ne,Se)=>{if(!oe)return;const ge=ne!==-1?[{startOffset:ne+1,endOffset:ne+1,collapsed:!0}]:void 0;te(`=${Z}`,!0,Se,ge),Se&&(fe(),ne!==-1&&setTimeout(()=>{const We={startOffset:ne+1,endOffset:ne+1},ve=T==null?void 0:T.render.with(ee.DocBackScrollRenderController);ve==null||ve.scrollToRange({...We,collapsed:!0})},50),je())});$r(F&&!!(ue&&pe),F,z,r,o,G,c,!!ae,T,dt),jr(F&&!!(ue&&pe),r,c,j,g,()=>{te(Ne.current,!1,!0)});const ht=Z=>{if(Z){const ne=T==null?void 0:T.getSelectionRanges();if(ne&&ne.length===1){const Se=ne[0];if(Se.collapsed){const ge=Z.offset;setTimeout(()=>{T==null||T.setSelectionRanges([{startOffset:Se.startOffset-ge,endOffset:Se.endOffset-ge}])},30)}}fe(),te(`=${Z.text}`)}},Zt=()=>{j(!0),d(),fe()};return E.jsxs("div",{className:f,children:[E.jsx("div",{ref:w,className:W.clsx("univer-relative univer-box-border univer-flex univer-h-full univer-w-full univer-items-center univer-justify-around univer-gap-2 univer-rounded-none univer-p-0 univer-ring-1",{"univer-ring-primary-500":F,"univer-ring-red-500":re}),children:E.jsx("div",{ref:V,className:"univer-relative univer-h-full univer-w-full",onMouseUp:Zt})}),n!==void 0&&E.jsx("div",{className:"univer-my-1 univer-text-xs univer-text-red-500",children:n}),_e&&T&&De!==""&&E.jsx(yr,{editor:T,isFocus:F,formulaText:Q,onClose:()=>fe()}),_e&&!!T&&E.jsx(Hr,{isFocus:F,sequenceNodes:Ue,onSelect:ht,ref:M,editor:T})]})});function Yr(e,t,n,s){const r=a.useDependency(y.LexerTreeBuilder),o=Yt(""),i=a.useObservable(e==null?void 0:e.getDocumentDataModel().change$),[c,d]=_.useState([]),g=a.useDependency(k.IMarkSelectionService),p=_.useRef(""),m=a.useDependency(l.IUniverInstanceService);return _.useEffect(()=>{if(!e)return;const f=e.getDocumentDataModel().getPlainText();if(p.current===f)return;p.current=f;const h=r.sequenceNodesBuilder(f);d(h!=null?h:[])},[i,e,r]),_.useEffect(()=>{var u,R;if(!e)return;if(!t){const v=e.getDocumentData();e.setDocumentData({...v,body:{...v.body,dataStream:(R=(u=v.body)==null?void 0:u.dataStream)!=null?R:"",textRuns:[]}});return}const f=o(e,c,!1),h=new l.DisposableCollection;return f.forEach(v=>{const C=y.deserializeRangeWithSheet(v.token),I=m.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),b=I==null?void 0:I.getActiveSheet();if(!C.sheetName&&s!==(b==null?void 0:b.getSheetId())||C.sheetName&&(b==null?void 0:b.getName())!==C.sheetName)return;const O=new l.ColorKit(v.themeColor).toRgb(),S=g.addShape({range:C.range,style:{stroke:v.themeColor,fill:`rgba(${O.r}, ${O.g}, ${O.b}, 0.1)`,strokeDash:12},primary:null});S&&h.add(()=>g.removeShape(S))}),()=>{h.dispose()}},[e,t,o,g,c]),{sequenceNodes:c}}function zr(e){const t=a.useDependency(P.SheetsSelectionsService),{supportAcrossSheet:n=!1,keepSheetReference:s=!1,unitId:r,subUnitId:o,onChange:i}=e,d=a.useDependency(l.IUniverInstanceService).getUnit(r,l.UniverInstanceType.UNIVER_SHEET),g=a.useEvent(i),p=a.useEvent((m,f)=>{const h=d==null?void 0:d.getActiveSheet();if(!h||!n&&h.getSheetId()!==o||!(m!=null&&m.length))return;const u=s?h.getName():h.getSheetId()===o?"":h.getName(),R=m.map(v=>({range:v.range,unitId:r,sheetName:u}));g(R,f)});_.useEffect(()=>{const m=new l.DisposableCollection;return m.add(t.selectionMoveStart$.subscribe(f=>{p(f,!0)})),m.add(t.selectionMoving$.subscribe(f=>{p(f,!1)})),m.add(t.selectionMoveEnd$.subscribe(f=>{p(f,!1)})),()=>{m.dispose()}},[p,t.selectionMoveEnd$,t.selectionMoveStart$,t.selectionMoving$])}const Tt=e=>!e.some(n=>{if(typeof n=="string"){if(n!==y.matchToken.COMMA)return!0}else if(n.nodeType!==y.sequenceNodeType.REFERENCE)return!0;return!1}),Gr=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 Zr(e){const{visible:t,initialValue:n,unitId:s,subUnitId:r,maxRangeCount:o=1/0,supportAcrossSheet:i,keepSheetReference:c,onConfirm:d,onClose:g,onShowBySelection:p}=e,m=a.useDependency(l.LocaleService),f=a.useDependency(y.LexerTreeBuilder),[h,u]=_.useState([]),[R,v]=_.useState(0),C=_.useRef(null);_.useEffect(()=>{if(t&&n.length){const S=n.map(x=>x.sheetName?y.serializeRangeWithSheet(x.sheetName,x.range):y.serializeRange(x.range));u(S),v(S.length-1)}else u([""]),v(0)},[t]);const I=(S,x)=>{const N=[...h];N[S]=x,u(N)},b=()=>{u([...h,""]),v(h.length)},O=S=>{h.splice(S,1),u([...h])};return zr({unitId:s,subUnitId:r,supportAcrossSheet:i,keepSheetReference:c,onChange:(S,x)=>{if(!t&&p!=null&&p(S))return;const N=new Set(h),U=S.map(L=>L.sheetName?y.serializeRangeWithSheet(L.sheetName,L.range):y.serializeRange(L.range)),$=U.filter(L=>!N.has(L));if(!$.length)return;const w=[...h];if(U.length>1){x||w.splice(R,1),w.push(...$);const L=w.slice(0,o);u(L),v(L.length-1),requestAnimationFrame(()=>{var D;(D=C.current)==null||D.scrollTo({top:C.current.scrollHeight})})}else{w.splice(R,1,...$);const L=w.slice(0,o);u(L),v(R+$.length-1)}}}),E.jsx(W.Dialog,{width:"328px",open:t,title:m.t("rangeSelector.title"),draggable:!0,mask:!1,maskClosable:!1,footer:E.jsxs("footer",{className:"univer-flex univer-gap-2",children:[E.jsx(W.Button,{onClick:g,children:m.t("rangeSelector.cancel")}),E.jsx(W.Button,{variant:"primary",onClick:()=>{d(h.filter(S=>{const x=f.sequenceNodesBuilder(S);return x&&x.length===1&&typeof x[0]!="string"&&x[0].nodeType===y.sequenceNodeType.REFERENCE}).map(S=>y.deserializeRangeWithSheet(S)).map(S=>({...S,range:Gr(S.range)})))},children:m.t("rangeSelector.confirm")})]}),onClose:g,children:E.jsxs("div",{ref:C,className:W.clsx("-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6",W.scrollbarClassName),children:[h.map((S,x)=>E.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-gap-4",children:[E.jsx(W.Input,{className:W.clsx("univer-w-full",{"univer-border-primary-600":R===x}),placeholder:m.t("rangeSelector.placeHolder"),onFocus:()=>v(x),value:S,onChange:N=>I(x,N)}),h.length>1&&E.jsx(jt,{className:"univer-cursor-pointer",onClick:()=>O(x)})]},x)),h.length<o&&E.jsx("div",{children:E.jsxs(W.Button,{variant:"link",onClick:b,children:[E.jsx(Wt,{}),E.jsx("span",{children:m.t("rangeSelector.addAnotherRange")})]})})]})})}function Xr(e){return e.split(y.matchToken.COMMA).filter(t=>!!t).map(t=>y.deserializeRangeWithSheet(t))}function Qr(e){return e.map(t=>t.sheetName?y.serializeRangeWithSheet(t.sheetName,t.range):y.serializeRange(t.range)).join(y.matchToken.COMMA)}function ut(e){const[t,n]=_.useState(null),{onVerify:s,selectorRef:r,unitId:o,subUnitId:i,maxRangeCount:c,supportAcrossSheet:d,keepSheetReference:g,autoFocus:p,onChange:m,onRangeSelectorDialogVisibleChange:f,onClickOutside:h,onFocusChange:u,forceShowDialogWhenSelectionChanged:R,hideEditor:v,resetRange:C}=e,[I,b]=_.useState(p!=null?p:!1),[O,S]=_.useState(!1),[x,N]=_.useState([]),U=a.useDependency(l.LocaleService),$=a.useDependency(ee.IEditorService),{sequenceNodes:w}=Yr(t,I,o,i),L=Oe(w),D=a.useDependency(l.ICommandService),M=a.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),$.blur()}),A=a.useEvent(()=>{var T;M(),N(Xr((T=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?T:"")),S(!0)});return _.useEffect(()=>{r&&(r.current={get editor(){return t},focus(){$.focus(t.getEditorId())},blur:M,verify:()=>Tt(L.current),showDialog:T=>{M(),N(T),S(!0)},hideDialog:()=>{N([]),S(!1)},getValue:()=>{var T;return(T=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?T:""}})},[M,t,$,r,L]),_.useEffect(()=>{var T;s==null||s(Tt(w),(T=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?T:"")},[w]),_.useEffect(()=>{f==null||f(O)},[O]),_.useEffect(()=>{if(O&&C)return()=>{const T={unitId:o,subUnitId:i,selections:C};D.executeCommand(P.SetSelectionsOperation.id,T)}},[O]),E.jsxs(E.Fragment,{children:[v?null:E.jsx(ee.RichTextEditor,{isSingle:!0,...e,onFocusChange:(T,F)=>{b(T),u==null||u(T,F)},editorRef:n,onClickOutside:()=>{b(!1),M(),h==null||h()},icon:E.jsx(W.Tooltip,{title:U.t("rangeSelector.buttonTooltip"),placement:"bottom",children:E.jsx(Bt,{className:"univer-cursor-pointer dark:!univer-text-gray-300",onClick:A})})}),E.jsx(Zr,{initialValue:x,unitId:o,subUnitId:i,visible:O,maxRangeCount:c,onConfirm:T=>{const F=Qr(T),j=l.RichTextBuilder.newEmptyData();j.body.dataStream=F,t==null||t.replaceText(F,!1),m==null||m(j,F),S(!1),N([]),requestAnimationFrame(()=>{M()})},onClose:()=>{S(!1),N([])},supportAcrossSheet:d,keepSheetReference:g,onShowBySelection:T=>I||R?(N(T),S(!0),!1):!0})]})}const Jr=()=>{var s,r;const e=a.useDependency(at),t=a.useObservable(e.currentSelector$),n=_.useRef(null);return _.useEffect(()=>{var o,i;if(t)return(i=n.current)==null||i.showDialog((o=t.initialValue)!=null?o:[]),()=>{var c;(c=n.current)==null||c.hideDialog()}},[t]),E.jsx(ut,{unitId:(s=t==null?void 0:t.unitId)!=null?s:"",subUnitId:(r=t==null?void 0:t.subUnitId)!=null?r:"",hideEditor:!0,selectorRef:n,onChange:(o,i)=>{var c;t==null||t.callback((c=i==null?void 0:i.split(",").map(d=>y.deserializeRangeWithSheet(d)))!=null?c:[])}})};var es=Object.defineProperty,ts=Object.getOwnPropertyDescriptor,ns=(e,t,n)=>t in e?es(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,rs=(e,t,n,s)=>{for(var r=s>1?void 0:s?ts(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},qe=(e,t)=>(n,s)=>t(n,s,e),Gt=(e,t,n)=>ns(e,typeof t!="symbol"?t+"":t,n);exports.UniverSheetsFormulaUIPlugin=class extends l.Plugin{constructor(t=_t,n,s,r,o){super(),this._config=t,this._injector=n,this._renderManagerService=s,this._configService=r,this._uiPartsService=o;const{menu:i,...c}=l.merge(_t,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(wt,c,{merge:!0})}onStarting(){l.registerDependencies(this._injector,[[Je,{useClass:st}],[at],[Xe],[Ye],[ze],[Ge],[Ze],[exports.FormulaReorderController]]),this._initUIPart()}onReady(){[[exports.RefSelectionsRenderService]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))})}onRendered(){[[ot]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))}),l.touchDependencies(this._injector,[[Xe],[ze],[Ze]])}onSteady(){this._injector.get(Ye),this._injector.get(exports.FormulaReorderController)}_initUIPart(){const t=this._injector.get(a.ComponentManager);this.disposeWithMe(t.register(k.RANGE_SELECTOR_COMPONENT_KEY,ut)),this.disposeWithMe(t.register(k.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,zt)),this.disposeWithMe(this._uiPartsService.registerComponent(a.BuiltInUIPart.GLOBAL,()=>a.connectInjector(Jr,this._injector)))}};Gt(exports.UniverSheetsFormulaUIPlugin,"pluginName",Nt);Gt(exports.UniverSheetsFormulaUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFormulaUIPlugin=rs([l.DependentOn(y.UniverFormulaEnginePlugin,Ce.UniverSheetsFormulaPlugin),qe(1,l.Inject(l.Injector)),qe(2,H.IRenderManagerService),qe(3,l.IConfigService),qe(4,a.IUIPartsService)],exports.UniverSheetsFormulaUIPlugin);exports.FORMULA_PROMPT_ACTIVATED=Mt;exports.FormulaEditor=zt;exports.GlobalRangeSelectorService=at;exports.HelpFunctionOperation=Ot;exports.InsertFunctionOperation=le;exports.MoreFunctionsOperation=et;exports.RangeSelector=ut;exports.ReferenceAbsoluteOperation=ct;exports.SearchFunctionOperation=kt;exports.SelectEditorFormulaOperation=xe;exports.SheetOnlyPasteFormulaCommand=Qe;
|
package/lib/es/index.js
CHANGED
|
@@ -513,7 +513,7 @@ let on = class extends ut {
|
|
|
513
513
|
var t, n, o, r, s;
|
|
514
514
|
if (e) {
|
|
515
515
|
const c = this._context.unit.getActiveSheet();
|
|
516
|
-
if (!c) return;
|
|
516
|
+
if (!c) return this._hideAlert();
|
|
517
517
|
const l = c.getCell(e.location.row, e.location.col), g = (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];
|
|
518
518
|
if (Jr(l)) {
|
|
519
519
|
const m = lr(l, !!g);
|
|
@@ -522,8 +522,10 @@ let on = class extends ut {
|
|
|
522
522
|
return;
|
|
523
523
|
}
|
|
524
524
|
const h = this._cellAlertManagerService.currentAlert.get(Jt), d = (s = h == null ? void 0 : h.alert) == null ? void 0 : s.location;
|
|
525
|
-
if (d && d.row === e.location.row && d.col === e.location.col && d.subUnitId === e.location.subUnitId && d.unitId === e.location.unitId)
|
|
525
|
+
if (d && d.row === e.location.row && d.col === e.location.col && d.subUnitId === e.location.subUnitId && d.unitId === e.location.unitId) {
|
|
526
|
+
this._hideAlert();
|
|
526
527
|
return;
|
|
528
|
+
}
|
|
527
529
|
this._cellAlertManagerService.showAlert({
|
|
528
530
|
type: So.ERROR,
|
|
529
531
|
title: this._localeService.t("formula.error.title"),
|
|
@@ -3159,7 +3161,7 @@ function Sc(e, t) {
|
|
|
3159
3161
|
f(N.name, N.functionType), s && s.focus();
|
|
3160
3162
|
},
|
|
3161
3163
|
children: [
|
|
3162
|
-
/* @__PURE__ */ W("span", { className: "univer-block univer-
|
|
3164
|
+
/* @__PURE__ */ W("span", { className: "univer-block univer-truncate univer-text-xs", children: [
|
|
3163
3165
|
/* @__PURE__ */ M("span", { className: "univer-text-red-500", children: N.name.substring(0, h.length) }),
|
|
3164
3166
|
/* @__PURE__ */ M("span", { children: N.name.slice(h.length) })
|
|
3165
3167
|
] }),
|
package/lib/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.univer-absolute{position:absolute}.univer-relative{position:relative}.univer-left-1\.5{left:.375rem}.univer-top-1\/2{top:50%}.univer-z-\[15\]{z-index:15}.univer-m-0{margin:0}.-univer-mx-6{margin-left:-1.5rem;margin-right:-1.5rem}.univer-mx-0{margin-left:0;margin-right:0}.univer-my-1{margin-top:.25rem;margin-bottom:.25rem}.univer-my-2{margin-top:.5rem;margin-bottom:.5rem}.univer-mb-0{margin-bottom:0}.univer-mb-2{margin-bottom:.5rem}.univer-mb-5{margin-bottom:1.25rem}.univer-ml-2{margin-left:.5rem}.univer-ml-4{margin-left:1rem}.univer-mr-0{margin-right:0}.univer-mt-0{margin-top:0}.univer-mt-1{margin-top:.25rem}.univer-mt-2{margin-top:.5rem}.univer-mt-3{margin-top:.75rem}.univer-box-border{box-sizing:border-box}.univer-block{display:block}.univer-flex{display:flex}.univer-inline-flex{display:inline-flex}.univer-h-6{height:1.5rem}.univer-h-\[18px\]{height:18px}.univer-h-\[364px\]{height:364px}.univer-h-full{height:100%}.univer-max-h-60{max-height:15rem}.univer-max-h-72{max-height:18rem}.univer-max-h-\[350px\]{max-height:350px}.univer-max-h-\[400px\]{max-height:400px}.univer-w-6{width:1.5rem}.univer-w-\[250px\]{width:250px}.univer-w-full{width:100%}.univer-flex-1{flex:1 1 0%}.-univer-translate-y-1\/2{--univer-tw-translate-y: -50%;transform:translate(var(--univer-tw-translate-x),-50%) rotate(var(--univer-tw-rotate)) skew(var(--univer-tw-skew-x)) skewY(var(--univer-tw-skew-y)) scaleX(var(--univer-tw-scale-x)) scaleY(var(--univer-tw-scale-y));transform:translate(var(--univer-tw-translate-x),var(--univer-tw-translate-y)) rotate(var(--univer-tw-rotate)) skew(var(--univer-tw-skew-x)) skewY(var(--univer-tw-skew-y)) scaleX(var(--univer-tw-scale-x)) scaleY(var(--univer-tw-scale-y))}.univer-cursor-pointer{cursor:pointer}.univer-select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.univer-list-none{list-style-type:none}.univer-flex-col{flex-direction:column}.univer-items-center{align-items:center}.univer-justify-end{justify-content:flex-end}.univer-justify-center{justify-content:center}.univer-justify-between{justify-content:space-between}.univer-justify-around{justify-content:space-around}.univer-gap-2{gap:.5rem}.univer-gap-4{gap:1rem}.univer-overflow-visible{overflow:visible}.univer-overflow-y-auto{overflow-y:auto}.univer-
|
|
1
|
+
.univer-absolute{position:absolute}.univer-relative{position:relative}.univer-left-1\.5{left:.375rem}.univer-top-1\/2{top:50%}.univer-z-\[15\]{z-index:15}.univer-m-0{margin:0}.-univer-mx-6{margin-left:-1.5rem;margin-right:-1.5rem}.univer-mx-0{margin-left:0;margin-right:0}.univer-my-1{margin-top:.25rem;margin-bottom:.25rem}.univer-my-2{margin-top:.5rem;margin-bottom:.5rem}.univer-mb-0{margin-bottom:0}.univer-mb-2{margin-bottom:.5rem}.univer-mb-5{margin-bottom:1.25rem}.univer-ml-2{margin-left:.5rem}.univer-ml-4{margin-left:1rem}.univer-mr-0{margin-right:0}.univer-mt-0{margin-top:0}.univer-mt-1{margin-top:.25rem}.univer-mt-2{margin-top:.5rem}.univer-mt-3{margin-top:.75rem}.univer-box-border{box-sizing:border-box}.univer-block{display:block}.univer-flex{display:flex}.univer-inline-flex{display:inline-flex}.univer-h-6{height:1.5rem}.univer-h-\[18px\]{height:18px}.univer-h-\[364px\]{height:364px}.univer-h-full{height:100%}.univer-max-h-60{max-height:15rem}.univer-max-h-72{max-height:18rem}.univer-max-h-\[350px\]{max-height:350px}.univer-max-h-\[400px\]{max-height:400px}.univer-w-6{width:1.5rem}.univer-w-\[250px\]{width:250px}.univer-w-full{width:100%}.univer-flex-1{flex:1 1 0%}.-univer-translate-y-1\/2{--univer-tw-translate-y: -50%;transform:translate(var(--univer-tw-translate-x),-50%) rotate(var(--univer-tw-rotate)) skew(var(--univer-tw-skew-x)) skewY(var(--univer-tw-skew-y)) scaleX(var(--univer-tw-scale-x)) scaleY(var(--univer-tw-scale-y));transform:translate(var(--univer-tw-translate-x),var(--univer-tw-translate-y)) rotate(var(--univer-tw-rotate)) skew(var(--univer-tw-skew-x)) skewY(var(--univer-tw-skew-y)) scaleX(var(--univer-tw-scale-x)) scaleY(var(--univer-tw-scale-y))}.univer-cursor-pointer{cursor:pointer}.univer-select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.univer-list-none{list-style-type:none}.univer-flex-col{flex-direction:column}.univer-items-center{align-items:center}.univer-justify-end{justify-content:flex-end}.univer-justify-center{justify-content:center}.univer-justify-between{justify-content:space-between}.univer-justify-around{justify-content:space-around}.univer-gap-2{gap:.5rem}.univer-gap-4{gap:1rem}.univer-overflow-visible{overflow:visible}.univer-overflow-y-auto{overflow-y:auto}.univer-truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.univer-whitespace-nowrap{white-space:nowrap}.univer-whitespace-pre-wrap{white-space:pre-wrap}.univer-break-words{word-wrap:break-word}.univer-break-all{word-break:break-all}.univer-rounded{border-radius:.25rem}.univer-rounded-lg{border-radius:.5rem}.univer-rounded-none{border-radius:0}.univer-rounded-l{border-top-left-radius:.25rem;border-bottom-left-radius:.25rem}.univer-border{border-width:1px}.univer-border-r-0{border-right-width:0px}.univer-border-gray-600{border-color:var(--univer-gray-600)}.univer-border-primary-600{border-color:var(--univer-primary-600)}.\!univer-bg-gray-600{background-color:var(--univer-gray-600)!important}.univer-bg-gray-200{background-color:var(--univer-gray-200)}.univer-bg-primary-600{background-color:var(--univer-primary-600)}.univer-bg-transparent{background-color:transparent}.univer-bg-white{background-color:var(--univer-white)}.univer-p-0{padding:0}.univer-p-0\.5{padding:.125rem}.univer-p-2{padding:.5rem}.univer-p-3{padding:.75rem}.univer-px-2{padding-left:.5rem;padding-right:.5rem}.univer-px-4{padding-left:1rem;padding-right:1rem}.univer-px-6{padding-left:1.5rem;padding-right:1.5rem}.univer-px-7{padding-left:1.75rem;padding-right:1.75rem}.univer-py-1{padding-top:.25rem;padding-bottom:.25rem}.univer-py-2{padding-top:.5rem;padding-bottom:.5rem}.univer-py-3{padding-top:.75rem;padding-bottom:.75rem}.univer-pb-3{padding-bottom:.75rem}.univer-pt-0{padding-top:0}.univer-text-base{font-size:1rem;line-height:1.5rem}.univer-text-sm{font-size:.875rem;line-height:1.25rem}.univer-text-xs{font-size:.75rem;line-height:1rem}.univer-font-bold{font-weight:700}.univer-font-medium{font-weight:500}.univer-leading-5{line-height:1.25rem}.univer-leading-\[13px\]{line-height:13px}.univer-text-gray-400{color:var(--univer-gray-400)}.univer-text-gray-500{color:var(--univer-gray-500)}.univer-text-gray-600{color:var(--univer-gray-600)}.univer-text-gray-900{color:var(--univer-gray-900)}.univer-text-primary-500{color:var(--univer-primary-500)}.univer-text-primary-600{color:var(--univer-primary-600)}.univer-text-red-500{color:var(--univer-red-500)}.univer-text-white{color:var(--univer-white)}.univer-shadow-md{--univer-tw-shadow: 0px 1px 6px -2px rgba(30, 40, 77, .08), 0px 2px 6px -1px rgba(30, 40, 77, .1);--univer-tw-shadow-colored: 0px 1px 6px -2px var(--univer-tw-shadow-color), 0px 2px 6px -1px var(--univer-tw-shadow-color);box-shadow:0 0 #0000,0 0 #0000,0 1px 6px -2px #1e284d14,0 2px 6px -1px #1e284d1a;box-shadow:var(--univer-tw-ring-offset-shadow, 0 0 rgba(0,0,0,0)),var(--univer-tw-ring-shadow, 0 0 rgba(0,0,0,0)),var(--univer-tw-shadow)}.univer-outline-none{outline:2px solid transparent;outline-offset:2px}.univer-ring-1{--univer-tw-ring-offset-shadow: var(--univer-tw-ring-inset) 0 0 0 var(--univer-tw-ring-offset-width) var(--univer-tw-ring-offset-color);--univer-tw-ring-shadow: var(--univer-tw-ring-inset) 0 0 0 calc(1px + var(--univer-tw-ring-offset-width)) var(--univer-tw-ring-color);box-shadow:var(--univer-tw-ring-offset-shadow),var(--univer-tw-ring-shadow),0 0 #0000;box-shadow:var(--univer-tw-ring-offset-shadow),var(--univer-tw-ring-shadow),var(--univer-tw-shadow, 0 0 rgba(0,0,0,0))}.univer-ring-primary-500{--univer-tw-ring-color: var(--univer-primary-500) }.univer-ring-red-500{--univer-tw-ring-color: var(--univer-red-500) }.univer-transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.hover\:univer-bg-gray-200:hover{background-color:var(--univer-gray-200)}.hover\:univer-bg-gray-300:hover{background-color:var(--univer-gray-300)}.dark\:\!univer-bg-gray-600:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-600)!important}.dark\:\!univer-bg-gray-900:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-900)!important}.dark\:\!univer-text-gray-200:where(.univer-dark,.univer-dark *){color:var(--univer-gray-200)!important}.dark\:\!univer-text-gray-300:where(.univer-dark,.univer-dark *){color:var(--univer-gray-300)!important}.dark\:\!univer-text-white:where(.univer-dark,.univer-dark *){color:var(--univer-white)!important}.dark\:hover\:\!univer-bg-gray-600:hover:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-600)!important}
|
package/lib/index.js
CHANGED
|
@@ -513,7 +513,7 @@ let on = class extends ut {
|
|
|
513
513
|
var t, n, o, r, s;
|
|
514
514
|
if (e) {
|
|
515
515
|
const c = this._context.unit.getActiveSheet();
|
|
516
|
-
if (!c) return;
|
|
516
|
+
if (!c) return this._hideAlert();
|
|
517
517
|
const l = c.getCell(e.location.row, e.location.col), g = (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];
|
|
518
518
|
if (Jr(l)) {
|
|
519
519
|
const m = lr(l, !!g);
|
|
@@ -522,8 +522,10 @@ let on = class extends ut {
|
|
|
522
522
|
return;
|
|
523
523
|
}
|
|
524
524
|
const h = this._cellAlertManagerService.currentAlert.get(Jt), d = (s = h == null ? void 0 : h.alert) == null ? void 0 : s.location;
|
|
525
|
-
if (d && d.row === e.location.row && d.col === e.location.col && d.subUnitId === e.location.subUnitId && d.unitId === e.location.unitId)
|
|
525
|
+
if (d && d.row === e.location.row && d.col === e.location.col && d.subUnitId === e.location.subUnitId && d.unitId === e.location.unitId) {
|
|
526
|
+
this._hideAlert();
|
|
526
527
|
return;
|
|
528
|
+
}
|
|
527
529
|
this._cellAlertManagerService.showAlert({
|
|
528
530
|
type: So.ERROR,
|
|
529
531
|
title: this._localeService.t("formula.error.title"),
|
|
@@ -3159,7 +3161,7 @@ function Sc(e, t) {
|
|
|
3159
3161
|
f(N.name, N.functionType), s && s.focus();
|
|
3160
3162
|
},
|
|
3161
3163
|
children: [
|
|
3162
|
-
/* @__PURE__ */ W("span", { className: "univer-block univer-
|
|
3164
|
+
/* @__PURE__ */ W("span", { className: "univer-block univer-truncate univer-text-xs", children: [
|
|
3163
3165
|
/* @__PURE__ */ M("span", { className: "univer-text-red-500", children: N.name.substring(0, h.length) }),
|
|
3164
3166
|
/* @__PURE__ */ M("span", { children: N.name.slice(h.length) })
|
|
3165
3167
|
] }),
|
package/lib/umd/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
(function(F,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets-ui"),require("@univerjs/engine-formula"),require("rxjs"),require("@univerjs/docs-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-formula"),require("@univerjs/ui"),require("react/jsx-runtime"),require("react"),require("@univerjs/design"),require("@univerjs/docs"),require("rxjs/operators")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-ui","@univerjs/engine-formula","rxjs","@univerjs/docs-ui","@univerjs/engine-render","@univerjs/sheets","@univerjs/sheets-formula","@univerjs/ui","react/jsx-runtime","react","@univerjs/design","@univerjs/docs","rxjs/operators"],a):(F=typeof globalThis<"u"?globalThis:F||self,a(F.UniverSheetsFormulaUi={},F.UniverCore,F.UniverSheetsUi,F.UniverEngineFormula,F.rxjs,F.UniverDocsUi,F.UniverEngineRender,F.UniverSheets,F.UniverSheetsFormula,F.UniverUi,F.React,F.React,F.UniverDesign,F.UniverDocs,F.rxjs.operators))})(this,(function(F,a,D,R,q,J,j,L,ve,l,y,I,B,ft,Xt){"use strict";var ro=Object.defineProperty;var oo=(F,a,D)=>a in F?ro(F,a,{enumerable:!0,configurable:!0,writable:!0,value:D}):F[a]=D;var Y=(F,a,D)=>oo(F,typeof a!="symbol"?a+"":a,D);const We={id:"sheet.command.paste-formula",type:a.CommandType.COMMAND,handler:async e=>e.get(a.ICommandService).executeCommand(D.SheetPasteCommand.id,{value:D.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA})},Ie={id:"formula-ui.operation.select-editor-formula",type:a.CommandType.OPERATION,handler:(e,t)=>!0};var Qt=Object.getOwnPropertyDescriptor,Jt=(e,t,n,o)=>{for(var r=o>1?void 0:o?Qt(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},en=(e,t)=>(n,o)=>t(n,o,e);const ht="FORMULA_PROMPT_ACTIVATED",Ue=a.createIdentifier("formula-ui.prompt-service");let rt=class{constructor(e){Y(this,"_search$",new q.Subject);Y(this,"_help$",new q.Subject);Y(this,"_navigate$",new q.Subject);Y(this,"_accept$",new q.Subject);Y(this,"_acceptFormulaName$",new q.Subject);Y(this,"search$",this._search$.asObservable());Y(this,"help$",this._help$.asObservable());Y(this,"navigate$",this._navigate$.asObservable());Y(this,"accept$",this._accept$.asObservable());Y(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());Y(this,"_searching",!1);Y(this,"_helping",!1);Y(this,"_sequenceNodes",[]);Y(this,"_isLockedOnSelectionChangeRefString",!1);Y(this,"_isLockedOnSelectionInsertRefString",!1);this._contextService=e}dispose(){this._search$.complete(),this._help$.complete(),this._navigate$.complete(),this._accept$.complete(),this._acceptFormulaName$.complete(),this._sequenceNodes=[]}search(e){this._contextService.setContextValue(ht,e.visible),this._searching=e.visible,this._search$.next(e)}isSearching(){return this._searching}help(e){this._helping=e.visible,this._help$.next(e)}isHelping(){return this._helping}navigate(e){this._navigate$.next(e)}accept(e){this._accept$.next(e)}acceptFormulaName(e){this._acceptFormulaName$.next(e)}getSequenceNodes(){return[...this._sequenceNodes]}setSequenceNodes(e){this._sequenceNodes=e}clearSequenceNodes(){this._sequenceNodes=[]}getCurrentSequenceNode(e){return this._sequenceNodes[this.getCurrentSequenceNodeIndex(e)]}getCurrentSequenceNodeByIndex(e){return this._sequenceNodes[e]}getCurrentSequenceNodeIndex(e){let t=0;const n=this._sequenceNodes[0];for(let o=0,r=this._sequenceNodes.length;o<r;o++){const s=this._sequenceNodes[o];if(typeof s=="string")t++;else{const{endIndex:i}=s;t=i}if(e<=t)return typeof n=="string"&&e!==0?o+1:o}return this._sequenceNodes.length}updateSequenceRef(e,t){const n=this._sequenceNodes[e];if(typeof n=="string"||n.nodeType!==R.sequenceNodeType.REFERENCE)return;const o=t.length-n.token.length,r={...n};r.token=t,r.endIndex+=o,this._sequenceNodes[e]=r;for(let s=e+1,i=this._sequenceNodes.length;s<i;s++){const c=this._sequenceNodes[s];if(typeof c=="string")continue;const d={...c};d.startIndex+=o,d.endIndex+=o,this._sequenceNodes[s]=d}}insertSequenceRef(e,t){const n=t.length,o=this.getCurrentSequenceNodeIndex(e);this._sequenceNodes.splice(o,0,{token:t,startIndex:e,endIndex:e+n-1,nodeType:R.sequenceNodeType.REFERENCE});for(let r=o+1,s=this._sequenceNodes.length;r<s;r++){const i=this._sequenceNodes[r];if(typeof i=="string")continue;const c={...i};c.startIndex+=n,c.endIndex+=n,this._sequenceNodes[r]=c}}insertSequenceString(e,t){const n=this.getCurrentSequenceNodeIndex(e),o=t.split("");this._sequenceNodes.splice(n,0,...o);const r=o.length;for(let s=n+r,i=this._sequenceNodes.length;s<i;s++){const c=this._sequenceNodes[s];if(typeof c=="string")continue;const d={...c};d.startIndex+=r,d.endIndex+=r,this._sequenceNodes[s]=d}}enableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!0}disableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!1}isLockedSelectionChange(){return this._isLockedOnSelectionChangeRefString}enableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!0}disableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!1}isLockedSelectionInsert(){return this._isLockedOnSelectionInsertRefString}};rt=Jt([en(0,a.IContextService)],rt);const gt={id:"formula-ui.operation.help-function",type:a.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ue).help(t),!0)},ce={id:"formula-ui.operation.insert-function",type:a.CommandType.OPERATION,handler:async(e,t)=>{var E,T;const n=e.get(L.SheetsSelectionsService),o=e.get(J.IEditorService),r=n.getCurrentSelections();if(!r||!r.length)return!1;const s=L.getSheetCommandTarget(e.get(a.IUniverInstanceService));if(!s)return!1;const{worksheet:i,unitId:c,subUnitId:d}=s,g=i.getCellMatrix(),{value:p}=t,S=e.get(a.ICommandService);e.get(D.IEditorBridgeService);const h=[],f=[];let u=null,_=0,m=0,C="";if(r.length===1&&(rn(r[0].range)||on(r[0].range)&&pt(g,r[0].range))){const{range:N,primary:v}=r[0],M=(E=v==null?void 0:v.actualRow)!=null?E:N.startRow,x=(T=v==null?void 0:v.actualColumn)!=null?T:N.startColumn;u=N,_=M,m=x;const W=St(g,M,x);W&&(C=R.serializeRange(W))}else r.some(N=>{var x,W;const{range:v,primary:M}=N;if(pt(g,v)){const U=(x=M==null?void 0:M.actualRow)!=null?x:v.startRow,w=(W=M==null?void 0:M.actualColumn)!=null?W:v.startColumn,$=St(g,U,w);if(!$)return u=v,_=U,m=w,!0;const k=R.serializeRange($),O=`=${p}(${k})`;h.push({range:v,primary:{row:U,column:w},formula:O})}else{const{startRow:U,startColumn:w,endRow:$,endColumn:k}=v;if(U===$){const O=sn(g,U,k,i.getColumnCount()-1),A=O===k?k-1:k,b=R.serializeRange({startRow:U,endRow:$,startColumn:w,endColumn:A}),P=`=${p}(${b})`;f.push({range:v,primary:{row:U,column:O},formula:P})}else{let O=-1;for(let b=w;b<=k;b++){const P=cn(g,b,$,i.getRowCount()-1);O=Math.max(O,P)}const A=O===$?$-1:$;for(let b=w;b<=k;b++){const P=R.serializeRange({startRow:U,endRow:A,startColumn:b,endColumn:b}),V=`=${p}(${P})`;f.push({range:v,primary:{row:O,column:b},formula:V})}}}return!1});if(u){const N=L.getCellAtRowCol(_,m,i),v={range:a.Rectangle.clone(u),primary:{startRow:N.startRow,startColumn:N.startColumn,endRow:N.endRow,endColumn:N.endColumn,actualRow:_,actualColumn:m,isMerged:N.isMerged,isMergedMainCell:N.startRow===_&&N.startColumn===m}},M={unitId:c,subUnitId:d,selections:[v]};await S.executeCommand(L.SetSelectionsOperation.id,M);const x=o.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),W=o.getEditor(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);S.syncExecuteCommand(D.SetCellEditVisibleOperation.id,{visible:!0,unitId:c,eventType:j.DeviceInputEventType.Dblclick});const U=`=${p}(${C}`;x==null||x.replaceText(U),W==null||W.replaceText(U,!1)}return h.length===0&&f.length===0?!1:S.executeCommand(ve.InsertFunctionCommand.id,{list:h,listOfRangeHasNumber:f})}};function St(e,t,n){const o=tn(e,t,n);if(o!==t)return{startRow:o,endRow:t-1,startColumn:n,endColumn:n};const r=nn(e,t,n);return r!==n?{startRow:t,endRow:t,startColumn:r,endColumn:n-1}:null}function tn(e,t,n){let o=!1;if(t===0)return t;for(let r=t-1;r>=0;r--){const s=e.getValue(r,n);if(Pe(s)&&!o){if(r===0)return 0;o=!0}else{if(o&&!Pe(s))return r+1;if(o&&r===0)return 0}}return t}function nn(e,t,n){let o=!1;if(n===0)return n;for(let r=n-1;r>=0;r--){const s=e.getValue(t,r);if(Pe(s)&&!o){if(r===0)return 0;o=!0}else{if(o&&!Pe(s))return r+1;if(o&&r===0)return 0}}return n}function Pe(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return!1;const n=t.dataStream,r=n.substring(n.length-2,n.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n;return a.isRealNum(r)}return e&&(e.t===a.CellValueType.NUMBER||a.getCellValueType(e)===a.CellValueType.NUMBER)}function rn(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}function on(e){return e.startRow!==e.endRow&&e.startColumn!==e.endColumn}function pt(e,t){for(let n=t.startRow;n<=t.endRow;n++)for(let o=t.startColumn;o<=t.endColumn;o++)if(Pe(e.getValue(n,o)))return!1;return!0}function sn(e,t,n,o){for(let r=n;r<=o;r++)if(!e.getValue(t,r))return r;return o}function cn(e,t,n,o){for(let r=n;r<=o;r++)if(!e.getValue(r,t))return r;return o}const vt="SHEET_FORMULA_UI_PLUGIN",mt=`${vt}_MORE_FUNCTIONS_COMPONENT`,Ve={id:"formula-ui.operation.more-functions",type:a.CommandType.OPERATION,handler:async e=>(e.get(l.ISidebarService).open({header:{title:"formula.insert.tooltip"},children:{label:mt}}),!0)},ot={id:"formula-ui.operation.change-ref-to-absolute",type:a.CommandType.OPERATION,handler:async e=>!0},Ct={id:"formula-ui.operation.search-function",type:a.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ue).search(t),!0)};var an=Object.getOwnPropertyDescriptor,ln=(e,t,n,o)=>{for(var r=o>1?void 0:o?an(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);F.FormulaReorderController=class extends a.Disposable{constructor(t,n,o,r){super(),this._sheetInterceptorService=t,this._univerInstanceService=n,this._formulaDataModel=o,this._lexerTreeBuilder=r,this._initialize()}_initialize(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>t.id===L.ReorderRangeCommand.id?this._reorderFormula(t.params):{redos:[],undos:[]}}))}_reorderFormula(t){const n=[],o=[],{unitId:r,subUnitId:s,range:i,order:c}=t,d=this._univerInstanceService.getUniverSheetInstance(r),g=d==null?void 0:d.getSheetBySheetId(s);if(!g)return{redos:n,undos:o};const p=g.getCellMatrix(),S=new a.ObjectMatrix,h=new a.ObjectMatrix;let f=!1;return a.Range.foreach(i,(u,_)=>{let m=u;c.hasOwnProperty(u)&&(m=c[u]);const C=p.getValue(m,_);if(C!=null&&C.f||C!=null&&C.si){f=!0;const E=this._formulaDataModel.getFormulaStringByCell(m,_,s,r),T=this._lexerTreeBuilder.moveFormulaRefOffset(E,0,u-m),N=a.Tools.deepClone(C);N.f=T,N.si=null,S.setValue(u,_,N)}else S.setValue(u,_,C);h.setValue(u,_,p.getValue(u,_))}),f?(n.push({id:L.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:s,cellValue:S.getMatrix()}}),o.push({id:L.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:s,cellValue:h.getMatrix()}}),{redos:n,undos:o}):{redos:n,undos:o}}},F.FormulaReorderController=ln([Be(0,a.Inject(L.SheetInterceptorService)),Be(1,a.Inject(a.IUniverInstanceService)),Be(2,a.Inject(R.FormulaDataModel)),Be(3,a.Inject(R.LexerTreeBuilder))],F.FormulaReorderController);const _t="sheets-formula-ui.base.config",It={};var un=Object.getOwnPropertyDescriptor,dn=(e,t,n,o)=>{for(var r=o>1?void 0:o?un(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 st="SHEET_FORMULA_ALERT",fn={[R.ErrorType.DIV_BY_ZERO]:"divByZero",[R.ErrorType.NAME]:"name",[R.ErrorType.VALUE]:"value",[R.ErrorType.NUM]:"num",[R.ErrorType.NA]:"na",[R.ErrorType.CYCLE]:"cycle",[R.ErrorType.REF]:"ref",[R.ErrorType.SPILL]:"spill",[R.ErrorType.CALC]:"calc",[R.ErrorType.ERROR]:"error",[R.ErrorType.CONNECT]:"connect",[R.ErrorType.NULL]:"null"};let it=class extends a.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(q.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),g=(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(a.isICellData(d)){const p=R.extractFormulaError(d,!!g);if(!p){this._hideAlert();return}const S=this._cellAlertManagerService.currentAlert.get(st),h=(s=S==null?void 0:S.alert)==null?void 0:s.location;if(h&&h.row===e.location.row&&h.col===e.location.col&&h.subUnitId===e.location.subUnitId&&h.unitId===e.location.unitId)return;this._cellAlertManagerService.showAlert({type:D.CellAlertType.ERROR,title:this._localeService.t("formula.error.title"),message:this._localeService.t(`formula.error.${fn[p]}`),location:e.location,width:200,height:74,key:st});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(st)}};it=dn([Le(1,a.Inject(D.HoverManagerService)),Le(2,a.Inject(D.CellAlertManagerService)),Le(3,a.Inject(a.LocaleService)),Le(4,a.Inject(R.FormulaDataModel)),Le(5,l.IZenZoneService)],it);var hn=Object.getOwnPropertyDescriptor,gn=(e,t,n,o)=>{for(var r=o>1?void 0:o?hn(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Et=(e,t)=>(n,o)=>t(n,o,e);let He=class extends a.Disposable{constructor(e,t){super(),this._autoFillService=e,this._lexerTreeBuilder=t,this._registerAutoFill()}_registerAutoFill(){const e={type:D.DATA_TYPE.FORMULA,priority:1001,match:t=>a.isFormulaString(t==null?void 0:t.f)||a.isFormulaId(t==null?void 0:t.si),isContinue:(t,n)=>t.type===D.DATA_TYPE.FORMULA,applyFunctions:{[D.APPLY_TYPE.COPY]:(t,n,o,r,s)=>{const{data:i,index:c}=t;return this._fillCopyFormula(i,n,o,c,r,s)}}};this._autoFillService.registerRule(e)}_fillCopyFormula(e,t,n,o,r,s){var g,p;const i=pn(r),c=[],d=new Map;for(let S=1;S<=t;S++){const h=(S-1)%e.length,f=o[h],u=a.Tools.deepClone(e[h]);if(u){const _=((g=e[h])==null?void 0:g.f)||"",m=((p=e[h])==null?void 0:p.si)||"",C=a.isFormulaString(_);if(a.isFormulaId(m))u.si=m,u.f=null,u.v=null,u.p=null,u.t=null,c.push(u);else if(C){let T=d.get(h);if(T)u.si=T,u.f=null,u.v=null,u.p=null,u.t=null;else{T=a.generateRandomId(6),d.set(h,T);const{offsetX:N,offsetY:v}=Sn(i,t,n,s,f),M=this._lexerTreeBuilder.moveFormulaRefOffset(_,N,v);u.si=T,u.f=M,u.v=null,u.p=null,u.t=null}c.push(u)}}}return c}};He=gn([Et(0,D.IAutoFillService),Et(1,a.Inject(R.LexerTreeBuilder))],He);function Sn(e,t,n,o,r){const{source:s,target:i}=o,{rows:c}=i,{rows:d}=s;let g=0,p=0;switch(n){case a.Direction.UP:p=c[r]-d[r];break;case a.Direction.RIGHT:g=e;break;case a.Direction.DOWN:p=c[r]-d[r];break;case a.Direction.LEFT:g=-e*t;break}return{offsetX:g,offsetY:p}}function pn(e){let t=0;for(const n in e)e[n].forEach(o=>{t+=o.data.length});return t}var vn=Object.getOwnPropertyDescriptor,mn=(e,t,n,o)=>{for(var r=o>1?void 0:o?vn(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);const Cn="default-paste-formula";let Ke=class extends a.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:D.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:Cn,priority:10,onPasteCells:(e,t,n,o)=>this._onPasteCells(e,t,n,o,!1)}}_onPasteCells(e,t,n,o,r){var h;if([D.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,D.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH].includes(o.pasteType))return{undos:[],redos:[]};const i=this._currentUniverSheet.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),c=t.unitId||i.getUnitId(),d=t.subUnitId||((h=i.getActiveSheet())==null?void 0:h.getSheetId());if(!c||!d)return{undos:[],redos:[]};const g=t.range,p=n,S={copyType:o.copyType||D.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:o.pasteType};return this._injector.invoke(f=>_n(c,d,g,p,f,S,this._lexerTreeBuilder,this._formulaDataModel,r,e))}};Ke=mn([$e(0,a.IUniverInstanceService),$e(1,a.Inject(R.LexerTreeBuilder)),$e(2,D.ISheetClipboardService),$e(3,a.Inject(a.Injector)),$e(4,a.Inject(R.FormulaDataModel))],Ke);function _n(e,t,n,o,r,s,i,c,d=!1,g){const p=[],S=[],h=In(e,t,n,o,s,i,c,g);if(!h.hasValue())return{undos:[],redos:[]};const f={unitId:e,subUnitId:t,cellValue:h.getData()};p.push({id:L.SetRangeValuesMutation.id,params:f});const u=L.SetRangeValuesUndoMutationFactory(r,f);return S.push({id:L.SetRangeValuesMutation.id,params:u}),{undos:S,redos:p}}function In(e,t,n,o,r,s,i,c){return c?r.pasteType===D.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE?yn(e,t,n,o,i,c):r.pasteType===D.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA?Rn(e,t,n,o,s,i,c):Tn(e,t,n,o,r.copyType,s,i,c):En(e,t,n,o,i)}function En(e,t,n,o,r){const s=new a.ObjectMatrix,i=r.getSheetFormulaData(e,t);return o.forValue((c,d,g)=>{var f;const p=n.rows[c],S=n.cols[d],h={};a.isFormulaString(g.v)?(h.v=null,h.f=`${g.v}`,h.si=null,h.p=null,s.setValue(p,S,h)):(f=i==null?void 0:i[p])!=null&&f[S]&&(h.v=g.v,h.f=null,h.si=null,h.p=null,s.setValue(p,S,h))}),s}function yn(e,t,n,o,r,s){var g,p;const i=new a.ObjectMatrix,c=(p=(g=r.getArrayFormulaCellData())==null?void 0:g[s.unitId])==null?void 0:p[s.subUnitId],d=r.getSheetFormulaData(e,t);return o.forValue((S,h,f)=>{var T,N;const u=s.range.rows[S%s.range.rows.length],_=s.range.cols[h%s.range.cols.length],m=n.rows[S],C=n.cols[h],E={};if(a.isFormulaString(f.f)||a.isFormulaId(f.si))E.v=f.v,E.f=null,E.si=null,E.p=null,i.setValue(m,C,E);else if((T=c==null?void 0:c[u])!=null&&T[_]){const v=c[u][_];E.v=v.v,E.f=null,E.si=null,E.p=null,i.setValue(m,C,E)}else if((N=d==null?void 0:d[m])!=null&&N[C]){if(E.v=f.v,E.f=null,E.si=null,E.p=null,f.p){const v=yt(f);v&&(E.v=v)}i.setValue(m,C,E)}}),i}function Rn(e,t,n,o,r,s,i){const c=new a.ObjectMatrix,d=new Map;return o.forValue((g,p,S)=>{const h=n.rows[g],f=n.cols[p],u={};if(a.isFormulaId(S.si)){if(i.unitId!==e||i.subUnitId!==t){const _=s.getFormulaStringByCell(i.range.rows[g%i.range.rows.length],i.range.cols[p%i.range.cols.length],i.subUnitId,i.unitId),m=n.cols[p]-i.range.cols[p%i.range.cols.length],C=n.rows[g]-i.range.rows[g%i.range.rows.length],E=r.moveFormulaRefOffset(_||"",m,C);u.si=null,u.f=E}else u.si=S.si,u.f=null;u.v=null,u.p=null,c.setValue(h,f,u)}else if(a.isFormulaString(S.f)){const _=`${g%i.range.rows.length}_${p%i.range.cols.length}`;let m=d.get(_);if(m)u.si=m,u.f=null;else{m=a.generateRandomId(6),d.set(_,m);const C=n.cols[p]-i.range.cols[p%i.range.cols.length],E=n.rows[g]-i.range.rows[g%i.range.rows.length],T=r.moveFormulaRefOffset(S.f||"",C,E);u.si=m,u.f=T}u.v=null,u.p=null,c.setValue(h,f,u)}else{if(u.v=S.v,u.f=null,u.si=null,u.p=null,S.p){const _=yt(S);_&&(u.v=_)}c.setValue(h,f,u)}}),c}function Tn(e,t,n,o,r,s,i,c){const d=new a.ObjectMatrix,g=new Map,p=i.getSheetFormulaData(e,t),S=[];return r===D.COPY_TYPE.CUT?o.forValue((h,f,u)=>{const _=n.rows[h],m=n.cols[f],C={};if(a.isFormulaId(u.si)){if(a.isFormulaString(u.f))S.push(u.si),C.f=u.f,C.si=u.si;else if(S.includes(u.si))C.f=null,C.si=u.si;else{const E=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[f%c.range.cols.length],c.subUnitId,c.unitId);C.f=E,C.si=null}C.v=null,C.p=null,d.setValue(_,m,C)}else a.isFormulaString(u.f)&&(C.f=u.f,C.si=null,C.v=null,C.p=null,d.setValue(_,m,C))}):o.forValue((h,f,u)=>{var E;const _=n.rows[h],m=n.cols[f],C={};if(a.isFormulaId(u.si)){if(c.unitId!==e||c.subUnitId!==t){const T=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[f%c.range.cols.length],c.subUnitId,c.unitId),N=n.cols[f]-c.range.cols[f%c.range.cols.length],v=n.rows[h]-c.range.rows[h%c.range.rows.length],M=s.moveFormulaRefOffset(T||"",N,v);C.si=null,C.f=M}else C.si=u.si,C.f=null;C.v=null,C.p=null,d.setValue(_,m,C)}else if(a.isFormulaString(u.f)){const T=`${h%c.range.rows.length}_${f%c.range.cols.length}`;let N=g.get(T);if(N)C.si=N,C.f=null;else{N=a.generateRandomId(6),g.set(T,N);const v=n.cols[f]-c.range.cols[f%c.range.cols.length],M=n.rows[h]-c.range.rows[h%c.range.rows.length],x=s.moveFormulaRefOffset(u.f||"",v,M);C.si=N,C.f=x}C.v=null,C.p=null,d.setValue(_,m,C)}else(E=p==null?void 0:p[_])!=null&&E[m]&&(C.v=u.v,C.f=null,C.si=null,C.p=u.p,d.setValue(_,m,C))}),S.length>0&&new a.ObjectMatrix(p).forValue((h,f,u)=>{if(!(c.range.rows.includes(h)&&c.range.cols.includes(f))&&!(n.rows.includes(h)&&n.cols.includes(f))&&S.includes(u==null?void 0:u.si)){const _=i.getFormulaStringByCell(h,f,c.subUnitId,c.unitId);d.setValue(h,f,{f:_,si:null,v:null,p:null})}}),d}function yt(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)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n}}var bn=Object.getOwnPropertyDescriptor,Mn=(e,t,n,o)=>{for(var r=o>1?void 0:o?bn(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 je=class extends a.Disposable{constructor(t,n,o,r,s,i,c,d){super();Y(this,"_previousShape");Y(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(a.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(L.BEFORE_CELL_EDIT,{handler:(t,n,o)=>{var u,_,m,C;const{row:r,col:s,unitId:i,subUnitId:c,worksheet:d}=n,g=this._formulaDataModel.getArrayFormulaRange(),p=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return o(t);let S=null;const h=this._formulaDataModel.getFormulaStringByCell(r,s,c,i);if(h!==null&&(S={f:h}),t.v!=null&&t.v!==""&&((m=(_=(u=p[i])==null?void 0:u[c])==null?void 0:_[r])==null?void 0:m[s])==null)return S?{...t,...S}:o(t);const f=(C=g==null?void 0:g[i])==null?void 0:C[c];return f!=null&&(S=this._displayArrayFormulaRangeShape(f,r,s,i,c,d,S)),S?{...t,...S}:o(t)}})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{(t.id===R.SetFormulaCalculationResultMutation.id||t.id===R.SetArrayFormulaDataMutation.id&&n&&n.remove)&&this._removeArrayFormulaRangeShape()})),this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{L.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 a.ObjectMatrix(t).forValue((g,p,S)=>{var m;if(S==null)return!0;const{startRow:h,startColumn:f,endRow:u,endColumn:_}=S;if(g===n&&p===o)return this._createArrayFormulaRangeShape(S,r),!1;if(n>=h&&n<=u&&o>=f&&o<=_){const C=i.getCell(h,f);if((C==null?void 0:C.v)===R.ErrorType.SPILL)return;const E=(m=d==null?void 0:d[g])==null?void 0:m[p];return E==null||E.f==null?!0:(c==null&&(c={f:E.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(S,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={range:t,primary:null,style:{strokeWidth:1,stroke:this._themeService.getColorFromTheme("primary.600"),fill:new a.ColorKit(this._themeService.getColorFromTheme("white")).setAlpha(0).toString(),widgets:{}}},c=D.attachSelectionWithCoord(i,r),{rowHeaderWidth:d,columnHeaderHeight:g}=r,p=new D.SelectionControl(s,D.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:d,columnHeaderHeight:g});p.updateRangeBySelectionWithCoord(c),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:g}=o[d];if(r>=g){const p={startRow:r,endRow:s,startColumn:i,endColumn:c};this._refreshArrayFormulaRangeShape(t,p);break}}}};je=Mn([Ee(1,a.Inject(L.SheetInterceptorService)),Ee(2,a.Inject(R.FormulaDataModel)),Ee(3,a.Inject(a.ThemeService)),Ee(4,j.IRenderManagerService),Ee(5,a.Inject(D.SheetSkeletonManagerService)),Ee(6,a.ICommandService),Ee(7,a.ILogService)],je);var On=Object.getOwnPropertyDescriptor,Nn=(e,t,n,o)=>{for(var r=o>1?void 0:o?On(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Rt=(e,t)=>(n,o)=>t(n,o,e);const Dn={tl:{size:6,color:"#409f11"}};let qe=class extends a.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(L.INTERCEPTOR_POINT.CELL_CONTENT,{effect:a.InterceptorEffectEnum.Style,handler:(n,o,r)=>{var c,d,g,p;const s=(p=(g=(d=(c=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:c[o.unitId])==null?void 0:d[o.subUnitId])==null?void 0:g[o.row])==null?void 0:p[o.col];return!R.extractFormulaError(n,!!s)||!n||(n===o.rawData&&(n={...o.rawData}),n.markers={...n==null?void 0:n.markers,...Dn}),r(n)},priority:10}))}};qe=Nn([Rt(0,a.Inject(L.SheetInterceptorService)),Rt(1,a.Inject(R.FormulaDataModel))],qe);function xn(){const e=l.useDependency(ve.TriggerCalculationController),t=l.useDependency(a.ICommandService),n=l.useObservable(e.progress$),o=I.useCallback(()=>{t.executeCommand(R.SetFormulaCalculationStopMutation.id)},[t]),r=I.useCallback(()=>{e.clearProgress()},[e]);return y.jsx(l.ProgressBar,{progress:n,onTerminate:o,onClearProgress:r})}function kn(e,t){return Object.keys(e).filter(n=>isNaN(Number(n))&&n!=="DefinedName").map(n=>({label:t.t(`formula.functionType.${n.toLocaleLowerCase()}`),value:`${e[n]}`}))}function Tt(e){if(!e.require&&!e.repeat)return`[${e.name}]`;if(e.require&&!e.repeat)return e.name;if(!e.require&&e.repeat)return`[${e.name},...]`;if(e.require&&e.repeat)return`${e.name},...`}function bt(e){const{prefix:t,value:n}=e;return y.jsxs("div",{children:[y.jsxs("span",{children:[t,"("]}),n&&n.map((o,r)=>y.jsxs("span",{children:[y.jsx("span",{children:Tt(o)}),r===n.length-1?"":","]},r)),")"]})}function Fe(e){const{className:t,value:n,title:o}=e;return y.jsxs("div",{className:"univer-mb-2 univer-text-xs",children:[y.jsx("div",{className:B.clsx("univer-mb-2 univer-font-medium univer-text-gray-500 dark:!univer-text-gray-300",t),children:o}),y.jsx("div",{className:"univer-break-all univer-text-gray-900 dark:!univer-text-white",children:n})]})}function wn(e){const{functionInfo:t,onChange:n}=e;if(!t)return null;const[o,r]=I.useState([]),[s,i]=I.useState(t.functionParameter),[c,d]=I.useState(-1);return y.jsxs("div",{children:[y.jsx("div",{className:B.clsx("univer-h-[364px] univer-overflow-y-auto",B.scrollbarClassName),children:s.map((g,p)=>y.jsxs("div",{children:[y.jsx("div",{className:"univer-text-sm",children:g.name}),y.jsx("div",{className:"univer-mb-2 univer-mt-1"})]},p))}),y.jsx("div",{className:B.clsx("univer-flex-1 univer-p-3",B.borderLeftClassName),children:y.jsx(Fe,{title:c===-1?y.jsx(bt,{prefix:t.functionName,value:s}):s[c].name,value:c===-1?t.description:s[c].detail})})]})}function ye({ref:e,...t}){const{icon:n,id:o,className:r,extend:s,...i}=t,c=`univerjs-icon univerjs-icon-${o} ${r||""}`.trim(),d=I.useRef(`_${Ln()}`);return Mt(n,`${o}`,{defIds:n.defIds,idSuffix:d.current},{ref:e,className:c,...i},s)}function Mt(e,t,n,o,r){return I.createElement(e.tag,{key:t,...An(e,n,r),...o},(Pn(e,n).children||[]).map((s,i)=>Mt(s,`${t}-${e.tag}-${i}`,n,void 0,r)))}function An(e,t,n){const o={...e.attrs};n!=null&&n.colorChannel1&&o.fill==="colorChannel1"&&(o.fill=n.colorChannel1),e.tag==="mask"&&o.id&&(o.id=o.id+t.idSuffix),Object.entries(o).forEach(([s,i])=>{s==="mask"&&typeof i=="string"&&(o[s]=i.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:r}=t;return!r||r.length===0||(e.tag==="use"&&o["xlink:href"]&&(o["xlink:href"]=o["xlink:href"]+t.idSuffix),Object.entries(o).forEach(([s,i])=>{typeof i=="string"&&(o[s]=i.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),o}function Pn(e,t){var o;const{defIds:n}=t;return!n||n.length===0?e:e.tag==="defs"&&((o=e.children)!=null&&o.length)?{...e,children:e.children.map(r=>typeof r.attrs.id=="string"&&n&&n.includes(r.attrs.id)?{...r,attrs:{...r.attrs,id:r.attrs.id+t.idSuffix}}:r)}:e}function Ln(){return Math.random().toString(36).substring(2,8)}ye.displayName="UniverIcon";const $n={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ot=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"check-mark-icon",ref:n,icon:$n}))});Ot.displayName="CheckMarkIcon";const Fn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},Nt=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"close-icon",ref:n,icon:Fn}))});Nt.displayName="CloseIcon";const Wn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Dt=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"delete-icon",ref:n,icon:Wn}))});Dt.displayName="DeleteIcon";const Un={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},xt=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"increase-icon",ref:n,icon:Un}))});xt.displayName="IncreaseIcon";const Vn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.90913 3.57564C6.14345 3.34132 6.52335 3.34132 6.75766 3.57564L10.7577 7.57564C10.992 7.80995 10.992 8.18985 10.7577 8.42417L6.75766 12.4242C6.52335 12.6585 6.14345 12.6585 5.90913 12.4242C5.67482 12.1899 5.67482 11.81 5.90913 11.5756L9.48487 7.9999L5.90913 4.42417C5.67482 4.18985 5.67482 3.80995 5.90913 3.57564Z",fillRule:"evenodd",clipRule:"evenodd"}}]},kt=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"more-icon",ref:n,icon:Vn}))});kt.displayName="MoreIcon";const Bn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6185 12.4423C12.5907 12.2749 12.7773 12.15 12.9343 12.2308L15.4242 13.5126C15.6102 13.6084 15.5544 13.8745 15.3439 13.8955L14.2456 14.184L13.4521 15.1286C13.3495 15.2939 13.085 15.2463 13.0534 15.0568L12.6185 12.4423Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1 3.6C1 2.16406 2.16406 1 3.6 1H12.3C13.7359 1 14.9 2.16406 14.9 3.6V5.81156C14.9003 5.81881 14.9004 5.82609 14.9004 5.8334C14.9004 5.84071 14.9003 5.84799 14.9 5.85524V10.045C14.9003 10.0522 14.9004 10.0595 14.9004 10.0668C14.9004 10.3982 14.6318 10.6668 14.3004 10.6668H11.1668C10.8907 10.6668 10.6668 10.8907 10.6668 11.1668V14.3C10.6668 14.6314 10.3982 14.9 10.0668 14.9L10.05 14.8998L3.6 14.9C2.16406 14.9 1 13.7359 1 12.3V3.6ZM13.2 5.2334C13.4761 5.2334 13.7 5.00954 13.7 4.7334V3.6C13.7 2.8268 13.0732 2.2 12.3 2.2H11.1668C10.8907 2.2 10.6668 2.42386 10.6668 2.7V4.7334C10.6668 5.00954 10.8907 5.2334 11.1668 5.2334H13.2ZM10.6668 6.9334C10.6668 6.65726 10.8907 6.4334 11.1668 6.4334H13.2C13.4761 6.4334 13.7 6.65726 13.7 6.9334V8.9668C13.7 9.24294 13.4761 9.4668 13.2 9.4668H11.1668C10.8907 9.4668 10.6668 9.24294 10.6668 8.9668V6.9334ZM8.9668 5.2334C9.24294 5.2334 9.4668 5.00954 9.4668 4.7334V2.7C9.4668 2.42386 9.24294 2.2 8.9668 2.2H6.9334C6.65726 2.2 6.4334 2.42386 6.4334 2.7V4.7334C6.4334 5.00954 6.65726 5.2334 6.9334 5.2334L8.9668 5.2334ZM6.4334 6.9334C6.4334 6.65726 6.65726 6.4334 6.9334 6.4334L8.9668 6.4334C9.24294 6.4334 9.4668 6.65726 9.4668 6.9334V8.9668C9.4668 9.24294 9.24294 9.4668 8.9668 9.4668L6.9334 9.4668C6.65726 9.4668 6.4334 9.24294 6.4334 8.9668V6.9334ZM4.7334 5.2334C5.00954 5.2334 5.2334 5.00954 5.2334 4.7334V2.7C5.2334 2.42386 5.00954 2.2 4.7334 2.2H3.6C2.8268 2.2 2.2 2.8268 2.2 3.6V4.7334C2.2 5.00954 2.42386 5.2334 2.7 5.2334H4.7334ZM2.2 6.9334C2.2 6.65726 2.42386 6.4334 2.7 6.4334H4.7334C5.00954 6.4334 5.2334 6.65725 5.2334 6.9334V8.9668C5.2334 9.24294 5.00954 9.4668 4.7334 9.4668H2.7C2.42386 9.4668 2.2 9.24294 2.2 8.9668V6.9334ZM5.2334 11.1668C5.2334 10.8907 5.00954 10.6668 4.7334 10.6668H2.7C2.42386 10.6668 2.2 10.8907 2.2 11.1668V12.3C2.2 13.0732 2.8268 13.7 3.6 13.7H4.7334C5.00954 13.7 5.2334 13.4761 5.2334 13.2V11.1668ZM9.4668 11.1668C9.4668 10.8907 9.24294 10.6668 8.9668 10.6668H6.9334C6.65726 10.6668 6.4334 10.8907 6.4334 11.1668V13.2C6.4334 13.4761 6.65726 13.7 6.9334 13.7H8.9668C9.24294 13.7 9.4668 13.4761 9.4668 13.2V11.1668Z",fillRule:"evenodd",clipRule:"evenodd"}}]},wt=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"select-range-icon",ref:n,icon:Bn}))});wt.displayName="SelectRangeIcon";function Hn(e){const{onChange:t}=e,n="-1",[o,r]=I.useState(""),[s,i]=I.useState([]),[c,d]=I.useState(0),[g,p]=I.useState(n),[S,h]=I.useState(0),[f,u]=I.useState(null),_=l.useDependency(ve.IDescriptionService),m=l.useDependency(a.LocaleService),C=l.useDependency(l.ISidebarService),E=l.useObservable(C.sidebarOptions$),T=kn(R.FunctionType,m);T.unshift({label:m.t("formula.moreFunctions.allFunctions"),value:n});const N=m.t("formula.prompt.required"),v=m.t("formula.prompt.optional");I.useEffect(()=>{W(n)},[]),I.useEffect(()=>{x(0)},[s]),I.useEffect(()=>{E!=null&&E.visible&&(r(""),i([]),d(0),p(n),h(0),u(null),W(n))},[E]);const M=O=>{if(o.trim()==="")return O;const A=new RegExp(`(${o.toLocaleUpperCase()})`);return O.split(A).filter(Boolean).map((P,V)=>P.match(A)?y.jsx("span",{className:"univer-text-red-500",children:P},V):P)},x=O=>{if(s.length===0){u(null);return}h(O);const A=_.getFunctionInfo(s[O].name);if(!A){u(null);return}u(A),t(A)};function W(O){p(O);const A=_.getSearchListByType(+O);i(A)}function U(O){r(O);const A=_.getSearchListByName(O);i(A)}function w(O){if(O.stopPropagation(),O.key==="ArrowDown"){const A=c+1;d(A===s.length?0:A)}else if(O.key==="ArrowUp"){const A=c-1;d(A===-1?s.length-1:A)}else O.key==="Enter"&&x(c)}const $=O=>{d(O)},k=()=>{d(-1)};return y.jsxs("div",{children:[y.jsxs("div",{className:"univer-flex univer-items-center univer-justify-between univer-gap-2",children:[y.jsx(B.Select,{value:g,options:T,onChange:W}),y.jsx(B.Input,{placeholder:m.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:w,value:o,onChange:U,size:"small",allowClear:!0})]}),s.length>0&&y.jsx("ul",{className:B.clsx("univer-mb-0 univer-mt-2 univer-box-border univer-max-h-72 univer-w-full univer-select-none univer-list-none univer-overflow-y-auto univer-rounded univer-p-3 univer-outline-none",B.borderClassName,B.scrollbarClassName),onKeyDown:w,tabIndex:-1,children:s.map(({name:O},A)=>y.jsxs("li",{className:B.clsx("univer-relative univer-box-border univer-cursor-pointer univer-rounded univer-px-7 univer-py-1 univer-text-sm univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200 dark:!univer-bg-gray-600":c===A}),onMouseEnter:()=>$(A),onMouseLeave:k,onClick:()=>x(A),children:[S===A&&y.jsx(Ot,{className:"univer-absolute univer-left-1.5 univer-top-1/2 univer-inline-flex -univer-translate-y-1/2 univer-text-base univer-text-primary-600"}),y.jsx("span",{className:"univer-block",children:M(O)})]},A))}),f&&y.jsxs("div",{className:B.clsx("univer-mx-0 univer-my-2 univer-overflow-y-auto",B.scrollbarClassName),children:[y.jsx(Fe,{title:f.functionName,value:f.description}),y.jsx(Fe,{title:m.t("formula.moreFunctions.syntax"),value:y.jsx(bt,{prefix:f.functionName,value:f.functionParameter})}),y.jsx(Fe,{title:m.t("formula.prompt.helpExample"),value:`${f.functionName}(${f.functionParameter.map(O=>O.example).join(",")})`}),f.functionParameter&&f.functionParameter.map(O=>y.jsx(Fe,{title:O.name,value:`${O.require?N:v} ${O.detail}`},O.name))]})]})}function Kn(){const e=D.useActiveWorkbook(),[t,n]=I.useState(!0),[o,r]=I.useState(!1),[s,i]=I.useState(null);l.useDependency(D.IEditorBridgeService);const c=l.useDependency(a.LocaleService),d=l.useDependency(J.IEditorService),g=l.useDependency(a.IUniverInstanceService),p=l.useDependency(a.ICommandService);function S(){n(!t),r(!o)}function h(){const f=L.getSheetCommandTarget(g);if(!f)return;p.executeCommand(D.SetCellEditVisibleOperation.id,{visible:!0,unitId:f.unitId,eventType:j.DeviceInputEventType.Dblclick});const u=d.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),_=d.getEditor(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),m=`=${s==null?void 0:s.functionName}(`;u==null||u.replaceText(m),_==null||_.replaceText(m,!1)}return y.jsxs("div",{"data-u-comp":"sheets-formula-functions-panel",className:"univer-box-border univer-flex univer-h-full univer-flex-col univer-justify-between univer-py-2",children:[t&&y.jsx(Hn,{onChange:i}),o&&y.jsx(wn,{functionInfo:s,onChange:()=>{}}),y.jsxs("div",{className:"univer-flex univer-justify-end",children:[o&&y.jsx(B.Button,{variant:"primary",onClick:S,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.next")}),o&&y.jsx(B.Button,{onClick:S,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.prev")}),t&&!!e&&y.jsx(B.Button,{variant:"primary",onClick:h,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.confirm")})]})]})}function jn(e){return{id:ce.id,title:"SUM",icon:"SumIcon",type:l.MenuItemType.BUTTON,params:{value:"SUM"},hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]})}}function qn(e){return{id:ce.id,title:"COUNT",icon:"CntIcon",type:l.MenuItemType.BUTTON,params:{value:"COUNT"},hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]})}}function Yn(e){return{id:ce.id,title:"AVERAGE",icon:"AvgIcon",type:l.MenuItemType.BUTTON,params:{value:"AVERAGE"},hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]})}}function zn(e){return{id:ce.id,title:"MAX",icon:"MaxIcon",type:l.MenuItemType.BUTTON,params:{value:"MAX"},hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]})}}function Gn(e){return{id:ce.id,title:"MIN",icon:"MinIcon",type:l.MenuItemType.BUTTON,params:{value:"MIN"},hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]})}}function Zn(e){return{id:Ve.id,title:"formula.insert.more",tooltip:"formula.insert.tooltip",type:l.MenuItemType.BUTTON,hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]})}}function Xn(e){return e.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(q.switchMap(o=>o&&e.get(l.IClipboardInterfaceService)?new q.Observable(s=>s.next(!e.get(l.IClipboardInterfaceService).supportClipboard)):q.of(!0)))}function Qn(e){return{id:We.id,type:l.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:Xn(e).pipe(q.combineLatestWith(D.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint],worksheetTypes:[L.WorksheetSetCellValuePermission,L.WorksheetEditPermission]})),q.map(([t,n])=>t||n))}}const Jn={[l.RibbonFormulasGroup.BASIC]:{[`${ce.id}.sum`]:{order:0,menuItemFactory:jn},[`${ce.id}.count`]:{order:1,menuItemFactory:qn},[`${ce.id}.average`]:{order:2,menuItemFactory:Yn},[`${ce.id}.max`]:{order:3,menuItemFactory:zn},[`${ce.id}.min`]:{order:4,menuItemFactory:Gn}},[l.RibbonFormulasGroup.OTHERS]:{[Ve.id]:{order:0,menuItemFactory:Zn}},[D.PASTE_SPECIAL_MENU_ID]:{[We.id]:{order:4,menuItemFactory:Qn}}},er="meta_key_ctrl_And_Shift";function tr(e){return e.getContextValue(a.FOCUSING_DOC)&&e.getContextValue(a.FOCUSING_UNIVER_EDITOR)}const Ye=[l.KeyCode.ARROW_DOWN,l.KeyCode.ARROW_UP,l.KeyCode.ARROW_LEFT,l.KeyCode.ARROW_RIGHT],nr=[...Ye,l.KeyCode.ENTER,l.KeyCode.TAB,l.KeyCode.ESC];function rr(){const e=[];for(const t of nr)e.push({id:Ie.id,binding:t,preconditions:n=>D.whenFormulaEditorActivated(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t}});return e}function or(){const e=[];for(const t of Ye)e.push({id:Ie.id,binding:t|l.MetaKeys.SHIFT,preconditions:n=>D.whenFormulaEditorActivated(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t,metaKey:l.MetaKeys.SHIFT}});return e}function sr(){const e=[];for(const t of Ye)e.push({id:Ie.id,binding:t|l.MetaKeys.CTRL_COMMAND,preconditions:n=>D.whenFormulaEditorActivated(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t,metaKey:l.MetaKeys.CTRL_COMMAND}});return e}function ir(){const e=[];for(const t of Ye)e.push({id:Ie.id,binding:t|l.MetaKeys.SHIFT|l.MetaKeys.CTRL_COMMAND,preconditions:n=>D.whenFormulaEditorActivated(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t,metaKey:er}});return e}const cr={id:ot.id,binding:l.KeyCode.F4,preconditions:e=>D.whenFormulaEditorActivated(e)};function ar(){const e=[];for(const t of[l.KeyCode.ENTER,l.KeyCode.TAB,l.KeyCode.ARROW_DOWN,l.KeyCode.ARROW_UP])e.push({id:Ie.id,binding:t,preconditions:n=>tr(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}const lr={id:ve.QuickSumCommand.id,binding:l.MetaKeys.ALT|l.KeyCode.EQUAL,preconditions:D.whenSheetEditorFocused,mac:l.MetaKeys.CTRL_COMMAND|l.MetaKeys.ALT|l.KeyCode.EQUAL,description:"shortcut.sheets-formula-ui.quick-sum",group:"4_sheet-edit"};var ur=Object.getOwnPropertyDescriptor,dr=(e,t,n,o)=>{for(var r=o>1?void 0:o?ur(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Re=(e,t)=>(n,o)=>t(n,o,e);let ze=class extends a.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(Jn)}_registerCommands(){[We,ce,Ve,Ct,gt,Ie,ot].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...rr(),...or(),...sr(),...ir(),...ar(),lr,cr].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(D.SheetsUIPart.FORMULA_AUX,()=>l.connectInjector(xn,this._injector))),this._componentManager.register(mt,Kn)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[je]))}};ze=dr([Re(0,a.Inject(a.Injector)),Re(1,l.IMenuManagerService),Re(2,a.ICommandService),Re(3,l.IShortcutService),Re(4,l.IUIPartsService),Re(5,j.IRenderManagerService),Re(6,a.Inject(l.ComponentManager))],ze);class ct{constructor(){Y(this,"_currentSelector$",new q.BehaviorSubject(null));Y(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}}var fr=Object.getOwnPropertyDescriptor,hr=(e,t,n,o)=>{for(var r=o>1?void 0:o?fr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},xe=(e,t)=>(n,o)=>t(n,o,e);F.RefSelectionsRenderService=class extends D.BaseSelectionRenderService{constructor(n,o,r,s,i,c,d){super(o,r,s,i,c);Y(this,"_workbookSelections");Y(this,"_eventDisposables");this._context=n,this._contextService=c,this._refSelectionsService=d,this._workbookSelections=this._refSelectionsService.getWorkbookSelections(this._context.unitId),this._initSelectionChangeListener(),this._initSkeletonChangeListener(),this._initUserActionSyncListener(),this._setSelectionStyle(gr(this._themeService)),this._remainLastEnabled=!0,this._highlightHeader=!1}getLocation(){return this._skeleton.getLocation()}setRemainLastEnabled(n){this._remainLastEnabled=n}setSkipLastEnabled(n){this._skipLastEnabled=n}clearLastSelection(){const n=this._selectionControls[this._selectionControls.length-1];n&&(n.dispose(),this._selectionControls.pop())}enableSelectionChanging(){return this._disableSelectionChanging(),this._eventDisposables=this._initCanvasEventListeners(),a.toDisposable(()=>this._disableSelectionChanging())}_disableSelectionChanging(){var n;(n=this._eventDisposables)==null||n.dispose(),this._eventDisposables=null}disableSelectionChanging(){this._disableSelectionChanging()}_initCanvasEventListeners(){const n=this._getSheetObject(),{spreadsheetRowHeader:o,spreadsheetColumnHeader:r,spreadsheet:s,spreadsheetLeftTopPlaceholder:i}=n,{scene:c}=this._context,d=new a.DisposableCollection;return d.add(s==null?void 0:s.onPointerDown$.subscribeEvent((g,p)=>{this.inRefSelectionMode()&&(this._onPointerDown(g,s.zIndex+1,a.RANGE_TYPE.NORMAL,this._getActiveViewport(g)),g.button!==2&&p.stopPropagation())})),d.add(o==null?void 0:o.onPointerDown$.subscribeEvent((g,p)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:h}=D.getCoordByOffset(g.offsetX,g.offsetY,c,S);D.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,a.RANGE_TYPE.ROW)||(this._onPointerDown(g,(s.zIndex||1)+1,a.RANGE_TYPE.ROW,this._getActiveViewport(g),j.ScrollTimerType.Y),g.button!==2&&p.stopPropagation())})),d.add(r==null?void 0:r.onPointerDown$.subscribeEvent((g,p)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:h}=D.getCoordByOffset(g.offsetX,g.offsetY,c,S);D.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,a.RANGE_TYPE.COLUMN)||(this._onPointerDown(g,(s.zIndex||1)+1,a.RANGE_TYPE.COLUMN,this._getActiveViewport(g),j.ScrollTimerType.X),g.button!==2&&p.stopPropagation())})),d.add(i==null?void 0:i.onPointerDown$.subscribeEvent((g,p)=>{if(this._reset(),!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,h=D.getAllSelection(S);this._addSelectionControlByModelData(h),this._selectionMoveStart$.next(this.getSelectionDataWithStyle());const f=c.onPointerUp$.subscribeEvent(()=>{f.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});g.button!==2&&p.stopPropagation()})),d}_addSelectionControlByModelData(n){var c;const o=this._skeleton,r=(c=n.style)!=null?c:D.genNormalSelectionStyle(this._themeService),s=this._scene;return n.style=r,this.newSelectionControl(s,o,n)}_initSelectionChangeListener(){this.disposeWithMe(this._refSelectionsService.selectionSet$.subscribe(n=>{this._reset(),this._skeleton&&this.resetSelectionsByModelData(n||[])}))}_initUserActionSyncListener(){this.disposeWithMe(this.selectionMoveStart$.subscribe(n=>{this._updateSelections(n,L.SelectionMoveType.MOVE_START)})),this.disposeWithMe(this.selectionMoving$.subscribe(n=>{this._updateSelections(n,L.SelectionMoveType.MOVING)})),this.disposeWithMe(this.selectionMoveEnd$.subscribe(n=>{this._updateSelections(n,L.SelectionMoveType.MOVE_END)}))}_updateSelections(n,o){const s=this._context.unit.getActiveSheet().getSheetId();n.length!==0&&this._workbookSelections.setSelections(s,n.map(i=>L.convertSelectionDataToRange(i)),o)}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(n=>{var c;if(!n)return;const{skeleton:o}=n,{scene:r}=this._context,s=r.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN);this._skeleton&&((c=this._skeleton.worksheet)==null?void 0:c.getSheetId())!==o.worksheet.getSheetId()&&this._reset(),this._changeRuntime(o,r,s);const i=this._workbookSelections.getCurrentSelections();this.resetSelectionsByModelData(i)}))}_getActiveViewport(n){const o=this._getSheetObject();return o==null?void 0:o.scene.getActiveViewportByCoord(j.Vector2.FromArray([n.offsetX,n.offsetY]))}_getSheetObject(){return D.getSheetObject(this._context.unit,this._context)}_onPointerDown(n,o=0,r=a.RANGE_TYPE.NORMAL,s,i=j.ScrollTimerType.ALL){var $;this._rangeType=r;const c=this._skeleton,d=this._scene;if(!d||!c)return;s&&(this._activeViewport=s);const{offsetX:g,offsetY:p}=n,S=d.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!S)return;const h=d.getCoordRelativeToViewport(j.Vector2.FromArray([g,p])),{x:f,y:u}=h;this._startViewportPosX=f,this._startViewportPosY=u;const _=d.getScrollXYInfoByViewport(h),{scaleX:m,scaleY:C}=d.getAncestorScale(),E=this._skeleton.getCellByOffset(f,u,m,C,_);if(!E)return;switch(r){case a.RANGE_TYPE.NORMAL:break;case a.RANGE_TYPE.ROW:E.startColumn=0,E.endColumn=this._skeleton.getColumnCount()-1;break;case a.RANGE_TYPE.COLUMN:E.startRow=0,E.endRow=this._skeleton.getRowCount()-1;break;case a.RANGE_TYPE.ALL:E.startRow=0,E.startColumn=0,E.endRow=this._skeleton.getRowCount()-1,E.endColumn=this._skeleton.getColumnCount()-1}const T={range:E,primary:E,style:null};T.range.rangeType=r;const N=D.attachSelectionWithCoord(T,this._skeleton);this._startRangeWhenPointerDown={...N.rangeWithCoord};const v={...N.rangeWithCoord,rangeType:r};let M=this.getActiveSelectionControl();const x=this.getSelectionControls();for(const k of x){if(n.button===2&&a.Rectangle.contains(k.model,v)){M=k;return}if(k.model.isEqual(v)){M=k;break}}this._checkClearPreviousControls(n);const W=M==null?void 0:M.model.currentCell,U=n.shiftKey&&W,w=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;U&&W?this._makeSelectionByTwoCells(W,v,c,r,M):w&&M?M.updateRangeBySelectionWithCoord(N):M=this.newSelectionControl(d,c,T);for(let k=0;k<this.getSelectionControls().length-1;k++)this.getSelectionControls()[k].clearHighlight();this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),d.disableObjectsEvent(),this._clearUpdatingListeners(),this._addEndingListeners(),($=d.getTransformer())==null||$.clearSelectedObjects(),this._setupPointerMoveListener(S,M,r,i,f,u),this._escapeShortcutDisposable=this._shortcutService.forceEscape(),this._scenePointerUpSub=d.onPointerUp$.subscribeEvent(()=>{var k;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(k=this._escapeShortcutDisposable)==null||k.dispose(),this._escapeShortcutDisposable=null})}newSelectionControl(n,o,r){const s=this.getSelectionControls().length,{rowHeaderWidth:i,columnHeaderHeight:c}=o,d=new D.SelectionControl(n,s,this._themeService,{highlightHeader:this._highlightHeader,enableAutoFill:!1,rowHeaderWidth:i,columnHeaderHeight:c}),g=D.attachSelectionWithCoord(r,o);return d.updateRangeBySelectionWithCoord(g),this._selectionControls.push(d),d.setControlExtension({skeleton:o,scene:n,themeService:this._themeService,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),d}},F.RefSelectionsRenderService=hr([xe(1,a.Inject(a.Injector)),xe(2,a.Inject(a.ThemeService)),xe(3,l.IShortcutService),xe(4,a.Inject(D.SheetSkeletonManagerService)),xe(5,a.IContextService),xe(6,L.IRefSelectionsService)],F.RefSelectionsRenderService);function gr(e){const t=D.genNormalSelectionStyle(e);return t.widgets={tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},t}const at=(e,t,n=!0)=>{let o=-1;return e.reduce((r,s,i)=>{if(r.isFinish)return r;const c=r.currentIndex;if(typeof s!="string")r.currentIndex+=s.token.length;else{const d=s.length;r.currentIndex+=d}return(n?r.currentIndex===t:t>c&&t<=r.currentIndex)&&(o=i,r.isFinish=!0),r},{currentIndex:0,isFinish:!1}),o},At=(e,t)=>{const n=e[t];let o=-1;if(!n||typeof n=="string"||n.nodeType!==R.sequenceNodeType.REFERENCE)return-1;for(let r=0;r<=t;r++){const s=e[r];typeof s!="string"&&s.nodeType===R.sequenceNodeType.REFERENCE&&o++}return o},Sr=(e,t=100)=>{I.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])};function Pt(e,t,n){const o=l.useDependency(J.IEditorService),r=I.useMemo(()=>new q.BehaviorSubject({left:-999,top:-999,right:-999,bottom:-999}),[]),s=l.useDependency(l.ISidebarService),i=l.useDependency(a.IUniverInstanceService),c=l.useEvent(()=>{var T;const d=o.getEditor(e);if(!d)return;const g=d.getBoundingClientRect(),{marginTop:p=0,marginBottom:S=0}=d.getDocumentData().documentStyle,h=d.getSkeleton();if(!h)return;const f=(T=h.getSkeletonData())==null?void 0:T.pages[0].height;let{left:u,top:_,right:m,bottom:C}=g;_=_+p,C=f?_+f:C-S;const E=r.getValue();if(!(E.left===u&&E.top===_&&E.right===m&&E.bottom===C))return r.next({left:u-1,right:m+1,top:_-1,bottom:C+1}),g});return I.useEffect(()=>{t&&c()},[e,o,i.unitAdded$,c,t,...n!=null?n:[]]),Sr(c),I.useEffect(()=>{const d=s.scrollEvent$.pipe(q.throttleTime(100)).subscribe(c);return()=>{d.unsubscribe()}},[]),[r,c]}const Te=e=>{const t=I.useRef(e);return t.current=e,t},pr=(e,t,n)=>{const o=l.useDependency(Ue),r=l.useDependency(ve.IDescriptionService),s=l.useDependency(R.LexerTreeBuilder),[i,c]=I.useState(),[d,g]=I.useState(-1),[p,S]=I.useState(!0),h=Te(p),f=I.useRef(t);f.current=t;const u=()=>{c(void 0),g(-1),S(!1)};return I.useEffect(()=>{const _=s.sequenceNodesBuilder(t.slice(1));o.setSequenceNodes(_!=null?_:[])},[t]),I.useEffect(()=>{if(n&&e){const _=n.selectionChange$.pipe(q.debounceTime(50)).subscribe(C=>{if(C.textRanges.length===1){const[E]=C.textRanges;if(E.collapsed&&h.current){const{startOffset:T}=E,N=o.getCurrentSequenceNodeIndex(T-2),v=o.getCurrentSequenceNodeByIndex(N),M=o.getCurrentSequenceNodeByIndex(N+1);if(v)if(typeof v!="string"&&v.nodeType===3&&!r.hasDefinedNameDescription(v.token.trim())&&M===R.matchToken.OPEN_BRACKET){const x=r.getFunctionInfo(v.token);c(x),g(-1);return}else{const x=s.getFunctionAndParameter(`${f.current}A`,T-1);if(x){const{functionName:W,paramIndex:U}=x,w=r.getFunctionInfo(W);c(w),g(U);return}}}}c(void 0),g(-1)}),m=n.selectionChange$.pipe(q.filter(C=>C.textRanges.length===1),q.map(C=>C.textRanges[0].startOffset),q.distinctUntilChanged()).subscribe(()=>{S(!0)});return()=>{_.unsubscribe(),m.unsubscribe()}}},[n,e]),I.useEffect(()=>{e||u()},[e]),{functionInfo:i,paramIndex:d,reset:u}},vr=({onClick:e})=>y.jsx("div",{className:"univer-z-[15] univer-box-border univer-h-[18px] univer-cursor-pointer univer-overflow-visible univer-whitespace-nowrap univer-rounded-l univer-border univer-border-r-0 univer-border-gray-600 univer-bg-primary-600 univer-p-0.5 univer-text-xs univer-font-bold univer-leading-[13px] univer-text-white",onClick:e,children:"?"}),lt=({className:e,title:t,value:n})=>y.jsxs("div",{className:"univer-my-2",children:[y.jsx("div",{className:B.clsx("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",e),children:t}),y.jsx("div",{className:"univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",children:n})]}),mr=e=>{const{prefix:t,value:n,active:o,onClick:r}=e;return y.jsxs("div",{children:[y.jsxs("span",{children:[t,"("]}),n&&n.map((s,i)=>y.jsxs("span",{children:[y.jsx("span",{className:o===i?"univer-text-primary-500":"",onClick:()=>r(i),children:Tt(s)}),i===n.length-1?"":","]},s.name)),")"]})},Lt=()=>{};function Cr(e){const{onParamsSwitch:t=Lt,onClose:n=Lt,isFocus:o,editor:r,formulaText:s}=e,{functionInfo:i,paramIndex:c,reset:d}=pr(o,s,r),g=l.useDependency(D.IEditorBridgeService),p=!l.useObservable(g.helpFunctionVisible$),[S,h]=I.useState(!0),f=l.useDependency(a.LocaleService),u=f.t("formula.prompt.required"),_=f.t("formula.prompt.optional"),m=r.getEditorId(),[C]=Pt(m,!!i,[i,c]);function E(v){t&&t(v)}const T=l.useEvent(v=>{g.helpFunctionVisible$.next(!v)}),N=()=>{T(!0),n()};return i?p?y.jsx(l.RectPopup,{portal:!0,anchorRect$:C,direction:"left-center",children:y.jsx(vr,{onClick:()=>T(!1)})},"hidden"):y.jsx(l.RectPopup,{portal:!0,onClickOutside:()=>d(),anchorRect$:C,direction:"vertical",children:y.jsxs("div",{className:B.clsx("univer-m-0 univer-box-border univer-w-[250px] univer-select-none univer-list-none univer-rounded-lg univer-bg-white univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",B.borderClassName),children:[y.jsxs("div",{className:B.clsx("univer-wrap-anywhere univer-box-border univer-flex univer-items-center univer-justify-between univer-px-4 univer-py-3 univer-text-xs univer-font-medium univer-text-gray-900 dark:!univer-text-white",B.borderTopClassName),children:[y.jsx(mr,{prefix:i.functionName,value:i.functionParameter,active:c,onClick:E}),y.jsxs("div",{className:"univer-flex",children:[y.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-500 univer-outline-none univer-transition-colors hover:univer-bg-gray-200 dark:hover:!univer-bg-gray-600",style:{transform:S?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>h(!S),children:y.jsx(kt,{})}),y.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-600 univer-outline-none univer-transition-colors hover:univer-bg-gray-300 dark:!univer-text-gray-200 dark:hover:!univer-bg-gray-600",onClick:N,children:y.jsx(Nt,{})})]})]}),y.jsx("div",{className:B.clsx("univer-box-border univer-max-h-[350px] univer-overflow-y-auto univer-px-4 univer-pb-3 univer-pt-0",B.scrollbarClassName),style:{height:S?"unset":0,padding:S?"revert-layer":0},children:y.jsxs("div",{className:"univer-mt-3",children:[y.jsx(lt,{title:f.t("formula.prompt.helpExample"),value:`${i.functionName}(${i.functionParameter.map(v=>v.example).join(",")})`}),y.jsx(lt,{title:f.t("formula.prompt.helpAbstract"),value:i.description}),i&&i.functionParameter&&i.functionParameter.map((v,M)=>y.jsx(lt,{className:c===M?"univer-text-primary-500":"",title:v.name,value:`${v.require?u:_} ${v.detail}`},M))]})})]})},"show"):null}const _r=e=>{const t=l.useDependency(J.IEditorService);return l.useEvent(o=>{var r,s;if(e){t.focus(e.getEditorId());const i=[...e.getSelectionRanges()];if(a.Tools.isDefine(o))e.setSelectionRanges([{startOffset:o,endOffset:o}]);else if(!i.length&&!e.docSelectionRenderService.isOnPointerEvent){const c=(s=(r=e.getDocumentData().body)==null?void 0:r.dataStream)!=null?s:`\r
|
|
1
|
+
(function(F,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets-ui"),require("@univerjs/engine-formula"),require("rxjs"),require("@univerjs/docs-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-formula"),require("@univerjs/ui"),require("react/jsx-runtime"),require("react"),require("@univerjs/design"),require("@univerjs/docs"),require("rxjs/operators")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-ui","@univerjs/engine-formula","rxjs","@univerjs/docs-ui","@univerjs/engine-render","@univerjs/sheets","@univerjs/sheets-formula","@univerjs/ui","react/jsx-runtime","react","@univerjs/design","@univerjs/docs","rxjs/operators"],a):(F=typeof globalThis<"u"?globalThis:F||self,a(F.UniverSheetsFormulaUi={},F.UniverCore,F.UniverSheetsUi,F.UniverEngineFormula,F.rxjs,F.UniverDocsUi,F.UniverEngineRender,F.UniverSheets,F.UniverSheetsFormula,F.UniverUi,F.React,F.React,F.UniverDesign,F.UniverDocs,F.rxjs.operators))})(this,(function(F,a,D,R,q,J,j,L,ve,l,y,I,B,ft,Xt){"use strict";var ro=Object.defineProperty;var oo=(F,a,D)=>a in F?ro(F,a,{enumerable:!0,configurable:!0,writable:!0,value:D}):F[a]=D;var Y=(F,a,D)=>oo(F,typeof a!="symbol"?a+"":a,D);const We={id:"sheet.command.paste-formula",type:a.CommandType.COMMAND,handler:async e=>e.get(a.ICommandService).executeCommand(D.SheetPasteCommand.id,{value:D.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA})},Ie={id:"formula-ui.operation.select-editor-formula",type:a.CommandType.OPERATION,handler:(e,t)=>!0};var Qt=Object.getOwnPropertyDescriptor,Jt=(e,t,n,o)=>{for(var r=o>1?void 0:o?Qt(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},en=(e,t)=>(n,o)=>t(n,o,e);const ht="FORMULA_PROMPT_ACTIVATED",Ue=a.createIdentifier("formula-ui.prompt-service");let rt=class{constructor(e){Y(this,"_search$",new q.Subject);Y(this,"_help$",new q.Subject);Y(this,"_navigate$",new q.Subject);Y(this,"_accept$",new q.Subject);Y(this,"_acceptFormulaName$",new q.Subject);Y(this,"search$",this._search$.asObservable());Y(this,"help$",this._help$.asObservable());Y(this,"navigate$",this._navigate$.asObservable());Y(this,"accept$",this._accept$.asObservable());Y(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());Y(this,"_searching",!1);Y(this,"_helping",!1);Y(this,"_sequenceNodes",[]);Y(this,"_isLockedOnSelectionChangeRefString",!1);Y(this,"_isLockedOnSelectionInsertRefString",!1);this._contextService=e}dispose(){this._search$.complete(),this._help$.complete(),this._navigate$.complete(),this._accept$.complete(),this._acceptFormulaName$.complete(),this._sequenceNodes=[]}search(e){this._contextService.setContextValue(ht,e.visible),this._searching=e.visible,this._search$.next(e)}isSearching(){return this._searching}help(e){this._helping=e.visible,this._help$.next(e)}isHelping(){return this._helping}navigate(e){this._navigate$.next(e)}accept(e){this._accept$.next(e)}acceptFormulaName(e){this._acceptFormulaName$.next(e)}getSequenceNodes(){return[...this._sequenceNodes]}setSequenceNodes(e){this._sequenceNodes=e}clearSequenceNodes(){this._sequenceNodes=[]}getCurrentSequenceNode(e){return this._sequenceNodes[this.getCurrentSequenceNodeIndex(e)]}getCurrentSequenceNodeByIndex(e){return this._sequenceNodes[e]}getCurrentSequenceNodeIndex(e){let t=0;const n=this._sequenceNodes[0];for(let o=0,r=this._sequenceNodes.length;o<r;o++){const s=this._sequenceNodes[o];if(typeof s=="string")t++;else{const{endIndex:i}=s;t=i}if(e<=t)return typeof n=="string"&&e!==0?o+1:o}return this._sequenceNodes.length}updateSequenceRef(e,t){const n=this._sequenceNodes[e];if(typeof n=="string"||n.nodeType!==R.sequenceNodeType.REFERENCE)return;const o=t.length-n.token.length,r={...n};r.token=t,r.endIndex+=o,this._sequenceNodes[e]=r;for(let s=e+1,i=this._sequenceNodes.length;s<i;s++){const c=this._sequenceNodes[s];if(typeof c=="string")continue;const d={...c};d.startIndex+=o,d.endIndex+=o,this._sequenceNodes[s]=d}}insertSequenceRef(e,t){const n=t.length,o=this.getCurrentSequenceNodeIndex(e);this._sequenceNodes.splice(o,0,{token:t,startIndex:e,endIndex:e+n-1,nodeType:R.sequenceNodeType.REFERENCE});for(let r=o+1,s=this._sequenceNodes.length;r<s;r++){const i=this._sequenceNodes[r];if(typeof i=="string")continue;const c={...i};c.startIndex+=n,c.endIndex+=n,this._sequenceNodes[r]=c}}insertSequenceString(e,t){const n=this.getCurrentSequenceNodeIndex(e),o=t.split("");this._sequenceNodes.splice(n,0,...o);const r=o.length;for(let s=n+r,i=this._sequenceNodes.length;s<i;s++){const c=this._sequenceNodes[s];if(typeof c=="string")continue;const d={...c};d.startIndex+=r,d.endIndex+=r,this._sequenceNodes[s]=d}}enableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!0}disableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!1}isLockedSelectionChange(){return this._isLockedOnSelectionChangeRefString}enableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!0}disableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!1}isLockedSelectionInsert(){return this._isLockedOnSelectionInsertRefString}};rt=Jt([en(0,a.IContextService)],rt);const gt={id:"formula-ui.operation.help-function",type:a.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ue).help(t),!0)},ce={id:"formula-ui.operation.insert-function",type:a.CommandType.OPERATION,handler:async(e,t)=>{var E,T;const n=e.get(L.SheetsSelectionsService),o=e.get(J.IEditorService),r=n.getCurrentSelections();if(!r||!r.length)return!1;const s=L.getSheetCommandTarget(e.get(a.IUniverInstanceService));if(!s)return!1;const{worksheet:i,unitId:c,subUnitId:d}=s,g=i.getCellMatrix(),{value:p}=t,S=e.get(a.ICommandService);e.get(D.IEditorBridgeService);const h=[],f=[];let u=null,_=0,m=0,C="";if(r.length===1&&(rn(r[0].range)||on(r[0].range)&&pt(g,r[0].range))){const{range:N,primary:v}=r[0],M=(E=v==null?void 0:v.actualRow)!=null?E:N.startRow,x=(T=v==null?void 0:v.actualColumn)!=null?T:N.startColumn;u=N,_=M,m=x;const W=St(g,M,x);W&&(C=R.serializeRange(W))}else r.some(N=>{var x,W;const{range:v,primary:M}=N;if(pt(g,v)){const U=(x=M==null?void 0:M.actualRow)!=null?x:v.startRow,w=(W=M==null?void 0:M.actualColumn)!=null?W:v.startColumn,$=St(g,U,w);if(!$)return u=v,_=U,m=w,!0;const k=R.serializeRange($),O=`=${p}(${k})`;h.push({range:v,primary:{row:U,column:w},formula:O})}else{const{startRow:U,startColumn:w,endRow:$,endColumn:k}=v;if(U===$){const O=sn(g,U,k,i.getColumnCount()-1),A=O===k?k-1:k,b=R.serializeRange({startRow:U,endRow:$,startColumn:w,endColumn:A}),P=`=${p}(${b})`;f.push({range:v,primary:{row:U,column:O},formula:P})}else{let O=-1;for(let b=w;b<=k;b++){const P=cn(g,b,$,i.getRowCount()-1);O=Math.max(O,P)}const A=O===$?$-1:$;for(let b=w;b<=k;b++){const P=R.serializeRange({startRow:U,endRow:A,startColumn:b,endColumn:b}),V=`=${p}(${P})`;f.push({range:v,primary:{row:O,column:b},formula:V})}}}return!1});if(u){const N=L.getCellAtRowCol(_,m,i),v={range:a.Rectangle.clone(u),primary:{startRow:N.startRow,startColumn:N.startColumn,endRow:N.endRow,endColumn:N.endColumn,actualRow:_,actualColumn:m,isMerged:N.isMerged,isMergedMainCell:N.startRow===_&&N.startColumn===m}},M={unitId:c,subUnitId:d,selections:[v]};await S.executeCommand(L.SetSelectionsOperation.id,M);const x=o.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),W=o.getEditor(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);S.syncExecuteCommand(D.SetCellEditVisibleOperation.id,{visible:!0,unitId:c,eventType:j.DeviceInputEventType.Dblclick});const U=`=${p}(${C}`;x==null||x.replaceText(U),W==null||W.replaceText(U,!1)}return h.length===0&&f.length===0?!1:S.executeCommand(ve.InsertFunctionCommand.id,{list:h,listOfRangeHasNumber:f})}};function St(e,t,n){const o=tn(e,t,n);if(o!==t)return{startRow:o,endRow:t-1,startColumn:n,endColumn:n};const r=nn(e,t,n);return r!==n?{startRow:t,endRow:t,startColumn:r,endColumn:n-1}:null}function tn(e,t,n){let o=!1;if(t===0)return t;for(let r=t-1;r>=0;r--){const s=e.getValue(r,n);if(Pe(s)&&!o){if(r===0)return 0;o=!0}else{if(o&&!Pe(s))return r+1;if(o&&r===0)return 0}}return t}function nn(e,t,n){let o=!1;if(n===0)return n;for(let r=n-1;r>=0;r--){const s=e.getValue(t,r);if(Pe(s)&&!o){if(r===0)return 0;o=!0}else{if(o&&!Pe(s))return r+1;if(o&&r===0)return 0}}return n}function Pe(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return!1;const n=t.dataStream,r=n.substring(n.length-2,n.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n;return a.isRealNum(r)}return e&&(e.t===a.CellValueType.NUMBER||a.getCellValueType(e)===a.CellValueType.NUMBER)}function rn(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}function on(e){return e.startRow!==e.endRow&&e.startColumn!==e.endColumn}function pt(e,t){for(let n=t.startRow;n<=t.endRow;n++)for(let o=t.startColumn;o<=t.endColumn;o++)if(Pe(e.getValue(n,o)))return!1;return!0}function sn(e,t,n,o){for(let r=n;r<=o;r++)if(!e.getValue(t,r))return r;return o}function cn(e,t,n,o){for(let r=n;r<=o;r++)if(!e.getValue(r,t))return r;return o}const vt="SHEET_FORMULA_UI_PLUGIN",mt=`${vt}_MORE_FUNCTIONS_COMPONENT`,Ve={id:"formula-ui.operation.more-functions",type:a.CommandType.OPERATION,handler:async e=>(e.get(l.ISidebarService).open({header:{title:"formula.insert.tooltip"},children:{label:mt}}),!0)},ot={id:"formula-ui.operation.change-ref-to-absolute",type:a.CommandType.OPERATION,handler:async e=>!0},Ct={id:"formula-ui.operation.search-function",type:a.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ue).search(t),!0)};var an=Object.getOwnPropertyDescriptor,ln=(e,t,n,o)=>{for(var r=o>1?void 0:o?an(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);F.FormulaReorderController=class extends a.Disposable{constructor(t,n,o,r){super(),this._sheetInterceptorService=t,this._univerInstanceService=n,this._formulaDataModel=o,this._lexerTreeBuilder=r,this._initialize()}_initialize(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>t.id===L.ReorderRangeCommand.id?this._reorderFormula(t.params):{redos:[],undos:[]}}))}_reorderFormula(t){const n=[],o=[],{unitId:r,subUnitId:s,range:i,order:c}=t,d=this._univerInstanceService.getUniverSheetInstance(r),g=d==null?void 0:d.getSheetBySheetId(s);if(!g)return{redos:n,undos:o};const p=g.getCellMatrix(),S=new a.ObjectMatrix,h=new a.ObjectMatrix;let f=!1;return a.Range.foreach(i,(u,_)=>{let m=u;c.hasOwnProperty(u)&&(m=c[u]);const C=p.getValue(m,_);if(C!=null&&C.f||C!=null&&C.si){f=!0;const E=this._formulaDataModel.getFormulaStringByCell(m,_,s,r),T=this._lexerTreeBuilder.moveFormulaRefOffset(E,0,u-m),N=a.Tools.deepClone(C);N.f=T,N.si=null,S.setValue(u,_,N)}else S.setValue(u,_,C);h.setValue(u,_,p.getValue(u,_))}),f?(n.push({id:L.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:s,cellValue:S.getMatrix()}}),o.push({id:L.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:s,cellValue:h.getMatrix()}}),{redos:n,undos:o}):{redos:n,undos:o}}},F.FormulaReorderController=ln([Be(0,a.Inject(L.SheetInterceptorService)),Be(1,a.Inject(a.IUniverInstanceService)),Be(2,a.Inject(R.FormulaDataModel)),Be(3,a.Inject(R.LexerTreeBuilder))],F.FormulaReorderController);const _t="sheets-formula-ui.base.config",It={};var un=Object.getOwnPropertyDescriptor,dn=(e,t,n,o)=>{for(var r=o>1?void 0:o?un(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 st="SHEET_FORMULA_ALERT",fn={[R.ErrorType.DIV_BY_ZERO]:"divByZero",[R.ErrorType.NAME]:"name",[R.ErrorType.VALUE]:"value",[R.ErrorType.NUM]:"num",[R.ErrorType.NA]:"na",[R.ErrorType.CYCLE]:"cycle",[R.ErrorType.REF]:"ref",[R.ErrorType.SPILL]:"spill",[R.ErrorType.CALC]:"calc",[R.ErrorType.ERROR]:"error",[R.ErrorType.CONNECT]:"connect",[R.ErrorType.NULL]:"null"};let it=class extends a.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(q.debounceTime(100)).subscribe(e=>{var t,n,o,r,s;if(e){const c=this._context.unit.getActiveSheet();if(!c)return this._hideAlert();const d=c.getCell(e.location.row,e.location.col),g=(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(a.isICellData(d)){const p=R.extractFormulaError(d,!!g);if(!p){this._hideAlert();return}const S=this._cellAlertManagerService.currentAlert.get(st),h=(s=S==null?void 0:S.alert)==null?void 0:s.location;if(h&&h.row===e.location.row&&h.col===e.location.col&&h.subUnitId===e.location.subUnitId&&h.unitId===e.location.unitId){this._hideAlert();return}this._cellAlertManagerService.showAlert({type:D.CellAlertType.ERROR,title:this._localeService.t("formula.error.title"),message:this._localeService.t(`formula.error.${fn[p]}`),location:e.location,width:200,height:74,key:st});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(st)}};it=dn([Le(1,a.Inject(D.HoverManagerService)),Le(2,a.Inject(D.CellAlertManagerService)),Le(3,a.Inject(a.LocaleService)),Le(4,a.Inject(R.FormulaDataModel)),Le(5,l.IZenZoneService)],it);var hn=Object.getOwnPropertyDescriptor,gn=(e,t,n,o)=>{for(var r=o>1?void 0:o?hn(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Et=(e,t)=>(n,o)=>t(n,o,e);let He=class extends a.Disposable{constructor(e,t){super(),this._autoFillService=e,this._lexerTreeBuilder=t,this._registerAutoFill()}_registerAutoFill(){const e={type:D.DATA_TYPE.FORMULA,priority:1001,match:t=>a.isFormulaString(t==null?void 0:t.f)||a.isFormulaId(t==null?void 0:t.si),isContinue:(t,n)=>t.type===D.DATA_TYPE.FORMULA,applyFunctions:{[D.APPLY_TYPE.COPY]:(t,n,o,r,s)=>{const{data:i,index:c}=t;return this._fillCopyFormula(i,n,o,c,r,s)}}};this._autoFillService.registerRule(e)}_fillCopyFormula(e,t,n,o,r,s){var g,p;const i=pn(r),c=[],d=new Map;for(let S=1;S<=t;S++){const h=(S-1)%e.length,f=o[h],u=a.Tools.deepClone(e[h]);if(u){const _=((g=e[h])==null?void 0:g.f)||"",m=((p=e[h])==null?void 0:p.si)||"",C=a.isFormulaString(_);if(a.isFormulaId(m))u.si=m,u.f=null,u.v=null,u.p=null,u.t=null,c.push(u);else if(C){let T=d.get(h);if(T)u.si=T,u.f=null,u.v=null,u.p=null,u.t=null;else{T=a.generateRandomId(6),d.set(h,T);const{offsetX:N,offsetY:v}=Sn(i,t,n,s,f),M=this._lexerTreeBuilder.moveFormulaRefOffset(_,N,v);u.si=T,u.f=M,u.v=null,u.p=null,u.t=null}c.push(u)}}}return c}};He=gn([Et(0,D.IAutoFillService),Et(1,a.Inject(R.LexerTreeBuilder))],He);function Sn(e,t,n,o,r){const{source:s,target:i}=o,{rows:c}=i,{rows:d}=s;let g=0,p=0;switch(n){case a.Direction.UP:p=c[r]-d[r];break;case a.Direction.RIGHT:g=e;break;case a.Direction.DOWN:p=c[r]-d[r];break;case a.Direction.LEFT:g=-e*t;break}return{offsetX:g,offsetY:p}}function pn(e){let t=0;for(const n in e)e[n].forEach(o=>{t+=o.data.length});return t}var vn=Object.getOwnPropertyDescriptor,mn=(e,t,n,o)=>{for(var r=o>1?void 0:o?vn(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);const Cn="default-paste-formula";let Ke=class extends a.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:D.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:Cn,priority:10,onPasteCells:(e,t,n,o)=>this._onPasteCells(e,t,n,o,!1)}}_onPasteCells(e,t,n,o,r){var h;if([D.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,D.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH].includes(o.pasteType))return{undos:[],redos:[]};const i=this._currentUniverSheet.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),c=t.unitId||i.getUnitId(),d=t.subUnitId||((h=i.getActiveSheet())==null?void 0:h.getSheetId());if(!c||!d)return{undos:[],redos:[]};const g=t.range,p=n,S={copyType:o.copyType||D.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:o.pasteType};return this._injector.invoke(f=>_n(c,d,g,p,f,S,this._lexerTreeBuilder,this._formulaDataModel,r,e))}};Ke=mn([$e(0,a.IUniverInstanceService),$e(1,a.Inject(R.LexerTreeBuilder)),$e(2,D.ISheetClipboardService),$e(3,a.Inject(a.Injector)),$e(4,a.Inject(R.FormulaDataModel))],Ke);function _n(e,t,n,o,r,s,i,c,d=!1,g){const p=[],S=[],h=In(e,t,n,o,s,i,c,g);if(!h.hasValue())return{undos:[],redos:[]};const f={unitId:e,subUnitId:t,cellValue:h.getData()};p.push({id:L.SetRangeValuesMutation.id,params:f});const u=L.SetRangeValuesUndoMutationFactory(r,f);return S.push({id:L.SetRangeValuesMutation.id,params:u}),{undos:S,redos:p}}function In(e,t,n,o,r,s,i,c){return c?r.pasteType===D.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE?yn(e,t,n,o,i,c):r.pasteType===D.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA?Rn(e,t,n,o,s,i,c):Tn(e,t,n,o,r.copyType,s,i,c):En(e,t,n,o,i)}function En(e,t,n,o,r){const s=new a.ObjectMatrix,i=r.getSheetFormulaData(e,t);return o.forValue((c,d,g)=>{var f;const p=n.rows[c],S=n.cols[d],h={};a.isFormulaString(g.v)?(h.v=null,h.f=`${g.v}`,h.si=null,h.p=null,s.setValue(p,S,h)):(f=i==null?void 0:i[p])!=null&&f[S]&&(h.v=g.v,h.f=null,h.si=null,h.p=null,s.setValue(p,S,h))}),s}function yn(e,t,n,o,r,s){var g,p;const i=new a.ObjectMatrix,c=(p=(g=r.getArrayFormulaCellData())==null?void 0:g[s.unitId])==null?void 0:p[s.subUnitId],d=r.getSheetFormulaData(e,t);return o.forValue((S,h,f)=>{var T,N;const u=s.range.rows[S%s.range.rows.length],_=s.range.cols[h%s.range.cols.length],m=n.rows[S],C=n.cols[h],E={};if(a.isFormulaString(f.f)||a.isFormulaId(f.si))E.v=f.v,E.f=null,E.si=null,E.p=null,i.setValue(m,C,E);else if((T=c==null?void 0:c[u])!=null&&T[_]){const v=c[u][_];E.v=v.v,E.f=null,E.si=null,E.p=null,i.setValue(m,C,E)}else if((N=d==null?void 0:d[m])!=null&&N[C]){if(E.v=f.v,E.f=null,E.si=null,E.p=null,f.p){const v=yt(f);v&&(E.v=v)}i.setValue(m,C,E)}}),i}function Rn(e,t,n,o,r,s,i){const c=new a.ObjectMatrix,d=new Map;return o.forValue((g,p,S)=>{const h=n.rows[g],f=n.cols[p],u={};if(a.isFormulaId(S.si)){if(i.unitId!==e||i.subUnitId!==t){const _=s.getFormulaStringByCell(i.range.rows[g%i.range.rows.length],i.range.cols[p%i.range.cols.length],i.subUnitId,i.unitId),m=n.cols[p]-i.range.cols[p%i.range.cols.length],C=n.rows[g]-i.range.rows[g%i.range.rows.length],E=r.moveFormulaRefOffset(_||"",m,C);u.si=null,u.f=E}else u.si=S.si,u.f=null;u.v=null,u.p=null,c.setValue(h,f,u)}else if(a.isFormulaString(S.f)){const _=`${g%i.range.rows.length}_${p%i.range.cols.length}`;let m=d.get(_);if(m)u.si=m,u.f=null;else{m=a.generateRandomId(6),d.set(_,m);const C=n.cols[p]-i.range.cols[p%i.range.cols.length],E=n.rows[g]-i.range.rows[g%i.range.rows.length],T=r.moveFormulaRefOffset(S.f||"",C,E);u.si=m,u.f=T}u.v=null,u.p=null,c.setValue(h,f,u)}else{if(u.v=S.v,u.f=null,u.si=null,u.p=null,S.p){const _=yt(S);_&&(u.v=_)}c.setValue(h,f,u)}}),c}function Tn(e,t,n,o,r,s,i,c){const d=new a.ObjectMatrix,g=new Map,p=i.getSheetFormulaData(e,t),S=[];return r===D.COPY_TYPE.CUT?o.forValue((h,f,u)=>{const _=n.rows[h],m=n.cols[f],C={};if(a.isFormulaId(u.si)){if(a.isFormulaString(u.f))S.push(u.si),C.f=u.f,C.si=u.si;else if(S.includes(u.si))C.f=null,C.si=u.si;else{const E=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[f%c.range.cols.length],c.subUnitId,c.unitId);C.f=E,C.si=null}C.v=null,C.p=null,d.setValue(_,m,C)}else a.isFormulaString(u.f)&&(C.f=u.f,C.si=null,C.v=null,C.p=null,d.setValue(_,m,C))}):o.forValue((h,f,u)=>{var E;const _=n.rows[h],m=n.cols[f],C={};if(a.isFormulaId(u.si)){if(c.unitId!==e||c.subUnitId!==t){const T=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[f%c.range.cols.length],c.subUnitId,c.unitId),N=n.cols[f]-c.range.cols[f%c.range.cols.length],v=n.rows[h]-c.range.rows[h%c.range.rows.length],M=s.moveFormulaRefOffset(T||"",N,v);C.si=null,C.f=M}else C.si=u.si,C.f=null;C.v=null,C.p=null,d.setValue(_,m,C)}else if(a.isFormulaString(u.f)){const T=`${h%c.range.rows.length}_${f%c.range.cols.length}`;let N=g.get(T);if(N)C.si=N,C.f=null;else{N=a.generateRandomId(6),g.set(T,N);const v=n.cols[f]-c.range.cols[f%c.range.cols.length],M=n.rows[h]-c.range.rows[h%c.range.rows.length],x=s.moveFormulaRefOffset(u.f||"",v,M);C.si=N,C.f=x}C.v=null,C.p=null,d.setValue(_,m,C)}else(E=p==null?void 0:p[_])!=null&&E[m]&&(C.v=u.v,C.f=null,C.si=null,C.p=u.p,d.setValue(_,m,C))}),S.length>0&&new a.ObjectMatrix(p).forValue((h,f,u)=>{if(!(c.range.rows.includes(h)&&c.range.cols.includes(f))&&!(n.rows.includes(h)&&n.cols.includes(f))&&S.includes(u==null?void 0:u.si)){const _=i.getFormulaStringByCell(h,f,c.subUnitId,c.unitId);d.setValue(h,f,{f:_,si:null,v:null,p:null})}}),d}function yt(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)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n}}var bn=Object.getOwnPropertyDescriptor,Mn=(e,t,n,o)=>{for(var r=o>1?void 0:o?bn(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 je=class extends a.Disposable{constructor(t,n,o,r,s,i,c,d){super();Y(this,"_previousShape");Y(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(a.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(L.BEFORE_CELL_EDIT,{handler:(t,n,o)=>{var u,_,m,C;const{row:r,col:s,unitId:i,subUnitId:c,worksheet:d}=n,g=this._formulaDataModel.getArrayFormulaRange(),p=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return o(t);let S=null;const h=this._formulaDataModel.getFormulaStringByCell(r,s,c,i);if(h!==null&&(S={f:h}),t.v!=null&&t.v!==""&&((m=(_=(u=p[i])==null?void 0:u[c])==null?void 0:_[r])==null?void 0:m[s])==null)return S?{...t,...S}:o(t);const f=(C=g==null?void 0:g[i])==null?void 0:C[c];return f!=null&&(S=this._displayArrayFormulaRangeShape(f,r,s,i,c,d,S)),S?{...t,...S}:o(t)}})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{(t.id===R.SetFormulaCalculationResultMutation.id||t.id===R.SetArrayFormulaDataMutation.id&&n&&n.remove)&&this._removeArrayFormulaRangeShape()})),this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{L.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 a.ObjectMatrix(t).forValue((g,p,S)=>{var m;if(S==null)return!0;const{startRow:h,startColumn:f,endRow:u,endColumn:_}=S;if(g===n&&p===o)return this._createArrayFormulaRangeShape(S,r),!1;if(n>=h&&n<=u&&o>=f&&o<=_){const C=i.getCell(h,f);if((C==null?void 0:C.v)===R.ErrorType.SPILL)return;const E=(m=d==null?void 0:d[g])==null?void 0:m[p];return E==null||E.f==null?!0:(c==null&&(c={f:E.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(S,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={range:t,primary:null,style:{strokeWidth:1,stroke:this._themeService.getColorFromTheme("primary.600"),fill:new a.ColorKit(this._themeService.getColorFromTheme("white")).setAlpha(0).toString(),widgets:{}}},c=D.attachSelectionWithCoord(i,r),{rowHeaderWidth:d,columnHeaderHeight:g}=r,p=new D.SelectionControl(s,D.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:d,columnHeaderHeight:g});p.updateRangeBySelectionWithCoord(c),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:g}=o[d];if(r>=g){const p={startRow:r,endRow:s,startColumn:i,endColumn:c};this._refreshArrayFormulaRangeShape(t,p);break}}}};je=Mn([Ee(1,a.Inject(L.SheetInterceptorService)),Ee(2,a.Inject(R.FormulaDataModel)),Ee(3,a.Inject(a.ThemeService)),Ee(4,j.IRenderManagerService),Ee(5,a.Inject(D.SheetSkeletonManagerService)),Ee(6,a.ICommandService),Ee(7,a.ILogService)],je);var On=Object.getOwnPropertyDescriptor,Nn=(e,t,n,o)=>{for(var r=o>1?void 0:o?On(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Rt=(e,t)=>(n,o)=>t(n,o,e);const Dn={tl:{size:6,color:"#409f11"}};let qe=class extends a.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(L.INTERCEPTOR_POINT.CELL_CONTENT,{effect:a.InterceptorEffectEnum.Style,handler:(n,o,r)=>{var c,d,g,p;const s=(p=(g=(d=(c=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:c[o.unitId])==null?void 0:d[o.subUnitId])==null?void 0:g[o.row])==null?void 0:p[o.col];return!R.extractFormulaError(n,!!s)||!n||(n===o.rawData&&(n={...o.rawData}),n.markers={...n==null?void 0:n.markers,...Dn}),r(n)},priority:10}))}};qe=Nn([Rt(0,a.Inject(L.SheetInterceptorService)),Rt(1,a.Inject(R.FormulaDataModel))],qe);function xn(){const e=l.useDependency(ve.TriggerCalculationController),t=l.useDependency(a.ICommandService),n=l.useObservable(e.progress$),o=I.useCallback(()=>{t.executeCommand(R.SetFormulaCalculationStopMutation.id)},[t]),r=I.useCallback(()=>{e.clearProgress()},[e]);return y.jsx(l.ProgressBar,{progress:n,onTerminate:o,onClearProgress:r})}function kn(e,t){return Object.keys(e).filter(n=>isNaN(Number(n))&&n!=="DefinedName").map(n=>({label:t.t(`formula.functionType.${n.toLocaleLowerCase()}`),value:`${e[n]}`}))}function Tt(e){if(!e.require&&!e.repeat)return`[${e.name}]`;if(e.require&&!e.repeat)return e.name;if(!e.require&&e.repeat)return`[${e.name},...]`;if(e.require&&e.repeat)return`${e.name},...`}function bt(e){const{prefix:t,value:n}=e;return y.jsxs("div",{children:[y.jsxs("span",{children:[t,"("]}),n&&n.map((o,r)=>y.jsxs("span",{children:[y.jsx("span",{children:Tt(o)}),r===n.length-1?"":","]},r)),")"]})}function Fe(e){const{className:t,value:n,title:o}=e;return y.jsxs("div",{className:"univer-mb-2 univer-text-xs",children:[y.jsx("div",{className:B.clsx("univer-mb-2 univer-font-medium univer-text-gray-500 dark:!univer-text-gray-300",t),children:o}),y.jsx("div",{className:"univer-break-all univer-text-gray-900 dark:!univer-text-white",children:n})]})}function wn(e){const{functionInfo:t,onChange:n}=e;if(!t)return null;const[o,r]=I.useState([]),[s,i]=I.useState(t.functionParameter),[c,d]=I.useState(-1);return y.jsxs("div",{children:[y.jsx("div",{className:B.clsx("univer-h-[364px] univer-overflow-y-auto",B.scrollbarClassName),children:s.map((g,p)=>y.jsxs("div",{children:[y.jsx("div",{className:"univer-text-sm",children:g.name}),y.jsx("div",{className:"univer-mb-2 univer-mt-1"})]},p))}),y.jsx("div",{className:B.clsx("univer-flex-1 univer-p-3",B.borderLeftClassName),children:y.jsx(Fe,{title:c===-1?y.jsx(bt,{prefix:t.functionName,value:s}):s[c].name,value:c===-1?t.description:s[c].detail})})]})}function ye({ref:e,...t}){const{icon:n,id:o,className:r,extend:s,...i}=t,c=`univerjs-icon univerjs-icon-${o} ${r||""}`.trim(),d=I.useRef(`_${Ln()}`);return Mt(n,`${o}`,{defIds:n.defIds,idSuffix:d.current},{ref:e,className:c,...i},s)}function Mt(e,t,n,o,r){return I.createElement(e.tag,{key:t,...An(e,n,r),...o},(Pn(e,n).children||[]).map((s,i)=>Mt(s,`${t}-${e.tag}-${i}`,n,void 0,r)))}function An(e,t,n){const o={...e.attrs};n!=null&&n.colorChannel1&&o.fill==="colorChannel1"&&(o.fill=n.colorChannel1),e.tag==="mask"&&o.id&&(o.id=o.id+t.idSuffix),Object.entries(o).forEach(([s,i])=>{s==="mask"&&typeof i=="string"&&(o[s]=i.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:r}=t;return!r||r.length===0||(e.tag==="use"&&o["xlink:href"]&&(o["xlink:href"]=o["xlink:href"]+t.idSuffix),Object.entries(o).forEach(([s,i])=>{typeof i=="string"&&(o[s]=i.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),o}function Pn(e,t){var o;const{defIds:n}=t;return!n||n.length===0?e:e.tag==="defs"&&((o=e.children)!=null&&o.length)?{...e,children:e.children.map(r=>typeof r.attrs.id=="string"&&n&&n.includes(r.attrs.id)?{...r,attrs:{...r.attrs,id:r.attrs.id+t.idSuffix}}:r)}:e}function Ln(){return Math.random().toString(36).substring(2,8)}ye.displayName="UniverIcon";const $n={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ot=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"check-mark-icon",ref:n,icon:$n}))});Ot.displayName="CheckMarkIcon";const Fn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},Nt=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"close-icon",ref:n,icon:Fn}))});Nt.displayName="CloseIcon";const Wn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Dt=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"delete-icon",ref:n,icon:Wn}))});Dt.displayName="DeleteIcon";const Un={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},xt=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"increase-icon",ref:n,icon:Un}))});xt.displayName="IncreaseIcon";const Vn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.90913 3.57564C6.14345 3.34132 6.52335 3.34132 6.75766 3.57564L10.7577 7.57564C10.992 7.80995 10.992 8.18985 10.7577 8.42417L6.75766 12.4242C6.52335 12.6585 6.14345 12.6585 5.90913 12.4242C5.67482 12.1899 5.67482 11.81 5.90913 11.5756L9.48487 7.9999L5.90913 4.42417C5.67482 4.18985 5.67482 3.80995 5.90913 3.57564Z",fillRule:"evenodd",clipRule:"evenodd"}}]},kt=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"more-icon",ref:n,icon:Vn}))});kt.displayName="MoreIcon";const Bn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6185 12.4423C12.5907 12.2749 12.7773 12.15 12.9343 12.2308L15.4242 13.5126C15.6102 13.6084 15.5544 13.8745 15.3439 13.8955L14.2456 14.184L13.4521 15.1286C13.3495 15.2939 13.085 15.2463 13.0534 15.0568L12.6185 12.4423Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1 3.6C1 2.16406 2.16406 1 3.6 1H12.3C13.7359 1 14.9 2.16406 14.9 3.6V5.81156C14.9003 5.81881 14.9004 5.82609 14.9004 5.8334C14.9004 5.84071 14.9003 5.84799 14.9 5.85524V10.045C14.9003 10.0522 14.9004 10.0595 14.9004 10.0668C14.9004 10.3982 14.6318 10.6668 14.3004 10.6668H11.1668C10.8907 10.6668 10.6668 10.8907 10.6668 11.1668V14.3C10.6668 14.6314 10.3982 14.9 10.0668 14.9L10.05 14.8998L3.6 14.9C2.16406 14.9 1 13.7359 1 12.3V3.6ZM13.2 5.2334C13.4761 5.2334 13.7 5.00954 13.7 4.7334V3.6C13.7 2.8268 13.0732 2.2 12.3 2.2H11.1668C10.8907 2.2 10.6668 2.42386 10.6668 2.7V4.7334C10.6668 5.00954 10.8907 5.2334 11.1668 5.2334H13.2ZM10.6668 6.9334C10.6668 6.65726 10.8907 6.4334 11.1668 6.4334H13.2C13.4761 6.4334 13.7 6.65726 13.7 6.9334V8.9668C13.7 9.24294 13.4761 9.4668 13.2 9.4668H11.1668C10.8907 9.4668 10.6668 9.24294 10.6668 8.9668V6.9334ZM8.9668 5.2334C9.24294 5.2334 9.4668 5.00954 9.4668 4.7334V2.7C9.4668 2.42386 9.24294 2.2 8.9668 2.2H6.9334C6.65726 2.2 6.4334 2.42386 6.4334 2.7V4.7334C6.4334 5.00954 6.65726 5.2334 6.9334 5.2334L8.9668 5.2334ZM6.4334 6.9334C6.4334 6.65726 6.65726 6.4334 6.9334 6.4334L8.9668 6.4334C9.24294 6.4334 9.4668 6.65726 9.4668 6.9334V8.9668C9.4668 9.24294 9.24294 9.4668 8.9668 9.4668L6.9334 9.4668C6.65726 9.4668 6.4334 9.24294 6.4334 8.9668V6.9334ZM4.7334 5.2334C5.00954 5.2334 5.2334 5.00954 5.2334 4.7334V2.7C5.2334 2.42386 5.00954 2.2 4.7334 2.2H3.6C2.8268 2.2 2.2 2.8268 2.2 3.6V4.7334C2.2 5.00954 2.42386 5.2334 2.7 5.2334H4.7334ZM2.2 6.9334C2.2 6.65726 2.42386 6.4334 2.7 6.4334H4.7334C5.00954 6.4334 5.2334 6.65725 5.2334 6.9334V8.9668C5.2334 9.24294 5.00954 9.4668 4.7334 9.4668H2.7C2.42386 9.4668 2.2 9.24294 2.2 8.9668V6.9334ZM5.2334 11.1668C5.2334 10.8907 5.00954 10.6668 4.7334 10.6668H2.7C2.42386 10.6668 2.2 10.8907 2.2 11.1668V12.3C2.2 13.0732 2.8268 13.7 3.6 13.7H4.7334C5.00954 13.7 5.2334 13.4761 5.2334 13.2V11.1668ZM9.4668 11.1668C9.4668 10.8907 9.24294 10.6668 8.9668 10.6668H6.9334C6.65726 10.6668 6.4334 10.8907 6.4334 11.1668V13.2C6.4334 13.4761 6.65726 13.7 6.9334 13.7H8.9668C9.24294 13.7 9.4668 13.4761 9.4668 13.2V11.1668Z",fillRule:"evenodd",clipRule:"evenodd"}}]},wt=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"select-range-icon",ref:n,icon:Bn}))});wt.displayName="SelectRangeIcon";function Hn(e){const{onChange:t}=e,n="-1",[o,r]=I.useState(""),[s,i]=I.useState([]),[c,d]=I.useState(0),[g,p]=I.useState(n),[S,h]=I.useState(0),[f,u]=I.useState(null),_=l.useDependency(ve.IDescriptionService),m=l.useDependency(a.LocaleService),C=l.useDependency(l.ISidebarService),E=l.useObservable(C.sidebarOptions$),T=kn(R.FunctionType,m);T.unshift({label:m.t("formula.moreFunctions.allFunctions"),value:n});const N=m.t("formula.prompt.required"),v=m.t("formula.prompt.optional");I.useEffect(()=>{W(n)},[]),I.useEffect(()=>{x(0)},[s]),I.useEffect(()=>{E!=null&&E.visible&&(r(""),i([]),d(0),p(n),h(0),u(null),W(n))},[E]);const M=O=>{if(o.trim()==="")return O;const A=new RegExp(`(${o.toLocaleUpperCase()})`);return O.split(A).filter(Boolean).map((P,V)=>P.match(A)?y.jsx("span",{className:"univer-text-red-500",children:P},V):P)},x=O=>{if(s.length===0){u(null);return}h(O);const A=_.getFunctionInfo(s[O].name);if(!A){u(null);return}u(A),t(A)};function W(O){p(O);const A=_.getSearchListByType(+O);i(A)}function U(O){r(O);const A=_.getSearchListByName(O);i(A)}function w(O){if(O.stopPropagation(),O.key==="ArrowDown"){const A=c+1;d(A===s.length?0:A)}else if(O.key==="ArrowUp"){const A=c-1;d(A===-1?s.length-1:A)}else O.key==="Enter"&&x(c)}const $=O=>{d(O)},k=()=>{d(-1)};return y.jsxs("div",{children:[y.jsxs("div",{className:"univer-flex univer-items-center univer-justify-between univer-gap-2",children:[y.jsx(B.Select,{value:g,options:T,onChange:W}),y.jsx(B.Input,{placeholder:m.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:w,value:o,onChange:U,size:"small",allowClear:!0})]}),s.length>0&&y.jsx("ul",{className:B.clsx("univer-mb-0 univer-mt-2 univer-box-border univer-max-h-72 univer-w-full univer-select-none univer-list-none univer-overflow-y-auto univer-rounded univer-p-3 univer-outline-none",B.borderClassName,B.scrollbarClassName),onKeyDown:w,tabIndex:-1,children:s.map(({name:O},A)=>y.jsxs("li",{className:B.clsx("univer-relative univer-box-border univer-cursor-pointer univer-rounded univer-px-7 univer-py-1 univer-text-sm univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200 dark:!univer-bg-gray-600":c===A}),onMouseEnter:()=>$(A),onMouseLeave:k,onClick:()=>x(A),children:[S===A&&y.jsx(Ot,{className:"univer-absolute univer-left-1.5 univer-top-1/2 univer-inline-flex -univer-translate-y-1/2 univer-text-base univer-text-primary-600"}),y.jsx("span",{className:"univer-block",children:M(O)})]},A))}),f&&y.jsxs("div",{className:B.clsx("univer-mx-0 univer-my-2 univer-overflow-y-auto",B.scrollbarClassName),children:[y.jsx(Fe,{title:f.functionName,value:f.description}),y.jsx(Fe,{title:m.t("formula.moreFunctions.syntax"),value:y.jsx(bt,{prefix:f.functionName,value:f.functionParameter})}),y.jsx(Fe,{title:m.t("formula.prompt.helpExample"),value:`${f.functionName}(${f.functionParameter.map(O=>O.example).join(",")})`}),f.functionParameter&&f.functionParameter.map(O=>y.jsx(Fe,{title:O.name,value:`${O.require?N:v} ${O.detail}`},O.name))]})]})}function Kn(){const e=D.useActiveWorkbook(),[t,n]=I.useState(!0),[o,r]=I.useState(!1),[s,i]=I.useState(null);l.useDependency(D.IEditorBridgeService);const c=l.useDependency(a.LocaleService),d=l.useDependency(J.IEditorService),g=l.useDependency(a.IUniverInstanceService),p=l.useDependency(a.ICommandService);function S(){n(!t),r(!o)}function h(){const f=L.getSheetCommandTarget(g);if(!f)return;p.executeCommand(D.SetCellEditVisibleOperation.id,{visible:!0,unitId:f.unitId,eventType:j.DeviceInputEventType.Dblclick});const u=d.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),_=d.getEditor(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),m=`=${s==null?void 0:s.functionName}(`;u==null||u.replaceText(m),_==null||_.replaceText(m,!1)}return y.jsxs("div",{"data-u-comp":"sheets-formula-functions-panel",className:"univer-box-border univer-flex univer-h-full univer-flex-col univer-justify-between univer-py-2",children:[t&&y.jsx(Hn,{onChange:i}),o&&y.jsx(wn,{functionInfo:s,onChange:()=>{}}),y.jsxs("div",{className:"univer-flex univer-justify-end",children:[o&&y.jsx(B.Button,{variant:"primary",onClick:S,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.next")}),o&&y.jsx(B.Button,{onClick:S,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.prev")}),t&&!!e&&y.jsx(B.Button,{variant:"primary",onClick:h,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.confirm")})]})]})}function jn(e){return{id:ce.id,title:"SUM",icon:"SumIcon",type:l.MenuItemType.BUTTON,params:{value:"SUM"},hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]})}}function qn(e){return{id:ce.id,title:"COUNT",icon:"CntIcon",type:l.MenuItemType.BUTTON,params:{value:"COUNT"},hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]})}}function Yn(e){return{id:ce.id,title:"AVERAGE",icon:"AvgIcon",type:l.MenuItemType.BUTTON,params:{value:"AVERAGE"},hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]})}}function zn(e){return{id:ce.id,title:"MAX",icon:"MaxIcon",type:l.MenuItemType.BUTTON,params:{value:"MAX"},hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]})}}function Gn(e){return{id:ce.id,title:"MIN",icon:"MinIcon",type:l.MenuItemType.BUTTON,params:{value:"MIN"},hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]})}}function Zn(e){return{id:Ve.id,title:"formula.insert.more",tooltip:"formula.insert.tooltip",type:l.MenuItemType.BUTTON,hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]})}}function Xn(e){return e.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(q.switchMap(o=>o&&e.get(l.IClipboardInterfaceService)?new q.Observable(s=>s.next(!e.get(l.IClipboardInterfaceService).supportClipboard)):q.of(!0)))}function Qn(e){return{id:We.id,type:l.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:Xn(e).pipe(q.combineLatestWith(D.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint],worksheetTypes:[L.WorksheetSetCellValuePermission,L.WorksheetEditPermission]})),q.map(([t,n])=>t||n))}}const Jn={[l.RibbonFormulasGroup.BASIC]:{[`${ce.id}.sum`]:{order:0,menuItemFactory:jn},[`${ce.id}.count`]:{order:1,menuItemFactory:qn},[`${ce.id}.average`]:{order:2,menuItemFactory:Yn},[`${ce.id}.max`]:{order:3,menuItemFactory:zn},[`${ce.id}.min`]:{order:4,menuItemFactory:Gn}},[l.RibbonFormulasGroup.OTHERS]:{[Ve.id]:{order:0,menuItemFactory:Zn}},[D.PASTE_SPECIAL_MENU_ID]:{[We.id]:{order:4,menuItemFactory:Qn}}},er="meta_key_ctrl_And_Shift";function tr(e){return e.getContextValue(a.FOCUSING_DOC)&&e.getContextValue(a.FOCUSING_UNIVER_EDITOR)}const Ye=[l.KeyCode.ARROW_DOWN,l.KeyCode.ARROW_UP,l.KeyCode.ARROW_LEFT,l.KeyCode.ARROW_RIGHT],nr=[...Ye,l.KeyCode.ENTER,l.KeyCode.TAB,l.KeyCode.ESC];function rr(){const e=[];for(const t of nr)e.push({id:Ie.id,binding:t,preconditions:n=>D.whenFormulaEditorActivated(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t}});return e}function or(){const e=[];for(const t of Ye)e.push({id:Ie.id,binding:t|l.MetaKeys.SHIFT,preconditions:n=>D.whenFormulaEditorActivated(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t,metaKey:l.MetaKeys.SHIFT}});return e}function sr(){const e=[];for(const t of Ye)e.push({id:Ie.id,binding:t|l.MetaKeys.CTRL_COMMAND,preconditions:n=>D.whenFormulaEditorActivated(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t,metaKey:l.MetaKeys.CTRL_COMMAND}});return e}function ir(){const e=[];for(const t of Ye)e.push({id:Ie.id,binding:t|l.MetaKeys.SHIFT|l.MetaKeys.CTRL_COMMAND,preconditions:n=>D.whenFormulaEditorActivated(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t,metaKey:er}});return e}const cr={id:ot.id,binding:l.KeyCode.F4,preconditions:e=>D.whenFormulaEditorActivated(e)};function ar(){const e=[];for(const t of[l.KeyCode.ENTER,l.KeyCode.TAB,l.KeyCode.ARROW_DOWN,l.KeyCode.ARROW_UP])e.push({id:Ie.id,binding:t,preconditions:n=>tr(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}const lr={id:ve.QuickSumCommand.id,binding:l.MetaKeys.ALT|l.KeyCode.EQUAL,preconditions:D.whenSheetEditorFocused,mac:l.MetaKeys.CTRL_COMMAND|l.MetaKeys.ALT|l.KeyCode.EQUAL,description:"shortcut.sheets-formula-ui.quick-sum",group:"4_sheet-edit"};var ur=Object.getOwnPropertyDescriptor,dr=(e,t,n,o)=>{for(var r=o>1?void 0:o?ur(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Re=(e,t)=>(n,o)=>t(n,o,e);let ze=class extends a.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(Jn)}_registerCommands(){[We,ce,Ve,Ct,gt,Ie,ot].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...rr(),...or(),...sr(),...ir(),...ar(),lr,cr].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(D.SheetsUIPart.FORMULA_AUX,()=>l.connectInjector(xn,this._injector))),this._componentManager.register(mt,Kn)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[je]))}};ze=dr([Re(0,a.Inject(a.Injector)),Re(1,l.IMenuManagerService),Re(2,a.ICommandService),Re(3,l.IShortcutService),Re(4,l.IUIPartsService),Re(5,j.IRenderManagerService),Re(6,a.Inject(l.ComponentManager))],ze);class ct{constructor(){Y(this,"_currentSelector$",new q.BehaviorSubject(null));Y(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}}var fr=Object.getOwnPropertyDescriptor,hr=(e,t,n,o)=>{for(var r=o>1?void 0:o?fr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},xe=(e,t)=>(n,o)=>t(n,o,e);F.RefSelectionsRenderService=class extends D.BaseSelectionRenderService{constructor(n,o,r,s,i,c,d){super(o,r,s,i,c);Y(this,"_workbookSelections");Y(this,"_eventDisposables");this._context=n,this._contextService=c,this._refSelectionsService=d,this._workbookSelections=this._refSelectionsService.getWorkbookSelections(this._context.unitId),this._initSelectionChangeListener(),this._initSkeletonChangeListener(),this._initUserActionSyncListener(),this._setSelectionStyle(gr(this._themeService)),this._remainLastEnabled=!0,this._highlightHeader=!1}getLocation(){return this._skeleton.getLocation()}setRemainLastEnabled(n){this._remainLastEnabled=n}setSkipLastEnabled(n){this._skipLastEnabled=n}clearLastSelection(){const n=this._selectionControls[this._selectionControls.length-1];n&&(n.dispose(),this._selectionControls.pop())}enableSelectionChanging(){return this._disableSelectionChanging(),this._eventDisposables=this._initCanvasEventListeners(),a.toDisposable(()=>this._disableSelectionChanging())}_disableSelectionChanging(){var n;(n=this._eventDisposables)==null||n.dispose(),this._eventDisposables=null}disableSelectionChanging(){this._disableSelectionChanging()}_initCanvasEventListeners(){const n=this._getSheetObject(),{spreadsheetRowHeader:o,spreadsheetColumnHeader:r,spreadsheet:s,spreadsheetLeftTopPlaceholder:i}=n,{scene:c}=this._context,d=new a.DisposableCollection;return d.add(s==null?void 0:s.onPointerDown$.subscribeEvent((g,p)=>{this.inRefSelectionMode()&&(this._onPointerDown(g,s.zIndex+1,a.RANGE_TYPE.NORMAL,this._getActiveViewport(g)),g.button!==2&&p.stopPropagation())})),d.add(o==null?void 0:o.onPointerDown$.subscribeEvent((g,p)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:h}=D.getCoordByOffset(g.offsetX,g.offsetY,c,S);D.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,a.RANGE_TYPE.ROW)||(this._onPointerDown(g,(s.zIndex||1)+1,a.RANGE_TYPE.ROW,this._getActiveViewport(g),j.ScrollTimerType.Y),g.button!==2&&p.stopPropagation())})),d.add(r==null?void 0:r.onPointerDown$.subscribeEvent((g,p)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:h}=D.getCoordByOffset(g.offsetX,g.offsetY,c,S);D.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,a.RANGE_TYPE.COLUMN)||(this._onPointerDown(g,(s.zIndex||1)+1,a.RANGE_TYPE.COLUMN,this._getActiveViewport(g),j.ScrollTimerType.X),g.button!==2&&p.stopPropagation())})),d.add(i==null?void 0:i.onPointerDown$.subscribeEvent((g,p)=>{if(this._reset(),!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,h=D.getAllSelection(S);this._addSelectionControlByModelData(h),this._selectionMoveStart$.next(this.getSelectionDataWithStyle());const f=c.onPointerUp$.subscribeEvent(()=>{f.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});g.button!==2&&p.stopPropagation()})),d}_addSelectionControlByModelData(n){var c;const o=this._skeleton,r=(c=n.style)!=null?c:D.genNormalSelectionStyle(this._themeService),s=this._scene;return n.style=r,this.newSelectionControl(s,o,n)}_initSelectionChangeListener(){this.disposeWithMe(this._refSelectionsService.selectionSet$.subscribe(n=>{this._reset(),this._skeleton&&this.resetSelectionsByModelData(n||[])}))}_initUserActionSyncListener(){this.disposeWithMe(this.selectionMoveStart$.subscribe(n=>{this._updateSelections(n,L.SelectionMoveType.MOVE_START)})),this.disposeWithMe(this.selectionMoving$.subscribe(n=>{this._updateSelections(n,L.SelectionMoveType.MOVING)})),this.disposeWithMe(this.selectionMoveEnd$.subscribe(n=>{this._updateSelections(n,L.SelectionMoveType.MOVE_END)}))}_updateSelections(n,o){const s=this._context.unit.getActiveSheet().getSheetId();n.length!==0&&this._workbookSelections.setSelections(s,n.map(i=>L.convertSelectionDataToRange(i)),o)}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(n=>{var c;if(!n)return;const{skeleton:o}=n,{scene:r}=this._context,s=r.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN);this._skeleton&&((c=this._skeleton.worksheet)==null?void 0:c.getSheetId())!==o.worksheet.getSheetId()&&this._reset(),this._changeRuntime(o,r,s);const i=this._workbookSelections.getCurrentSelections();this.resetSelectionsByModelData(i)}))}_getActiveViewport(n){const o=this._getSheetObject();return o==null?void 0:o.scene.getActiveViewportByCoord(j.Vector2.FromArray([n.offsetX,n.offsetY]))}_getSheetObject(){return D.getSheetObject(this._context.unit,this._context)}_onPointerDown(n,o=0,r=a.RANGE_TYPE.NORMAL,s,i=j.ScrollTimerType.ALL){var $;this._rangeType=r;const c=this._skeleton,d=this._scene;if(!d||!c)return;s&&(this._activeViewport=s);const{offsetX:g,offsetY:p}=n,S=d.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!S)return;const h=d.getCoordRelativeToViewport(j.Vector2.FromArray([g,p])),{x:f,y:u}=h;this._startViewportPosX=f,this._startViewportPosY=u;const _=d.getScrollXYInfoByViewport(h),{scaleX:m,scaleY:C}=d.getAncestorScale(),E=this._skeleton.getCellByOffset(f,u,m,C,_);if(!E)return;switch(r){case a.RANGE_TYPE.NORMAL:break;case a.RANGE_TYPE.ROW:E.startColumn=0,E.endColumn=this._skeleton.getColumnCount()-1;break;case a.RANGE_TYPE.COLUMN:E.startRow=0,E.endRow=this._skeleton.getRowCount()-1;break;case a.RANGE_TYPE.ALL:E.startRow=0,E.startColumn=0,E.endRow=this._skeleton.getRowCount()-1,E.endColumn=this._skeleton.getColumnCount()-1}const T={range:E,primary:E,style:null};T.range.rangeType=r;const N=D.attachSelectionWithCoord(T,this._skeleton);this._startRangeWhenPointerDown={...N.rangeWithCoord};const v={...N.rangeWithCoord,rangeType:r};let M=this.getActiveSelectionControl();const x=this.getSelectionControls();for(const k of x){if(n.button===2&&a.Rectangle.contains(k.model,v)){M=k;return}if(k.model.isEqual(v)){M=k;break}}this._checkClearPreviousControls(n);const W=M==null?void 0:M.model.currentCell,U=n.shiftKey&&W,w=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;U&&W?this._makeSelectionByTwoCells(W,v,c,r,M):w&&M?M.updateRangeBySelectionWithCoord(N):M=this.newSelectionControl(d,c,T);for(let k=0;k<this.getSelectionControls().length-1;k++)this.getSelectionControls()[k].clearHighlight();this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),d.disableObjectsEvent(),this._clearUpdatingListeners(),this._addEndingListeners(),($=d.getTransformer())==null||$.clearSelectedObjects(),this._setupPointerMoveListener(S,M,r,i,f,u),this._escapeShortcutDisposable=this._shortcutService.forceEscape(),this._scenePointerUpSub=d.onPointerUp$.subscribeEvent(()=>{var k;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(k=this._escapeShortcutDisposable)==null||k.dispose(),this._escapeShortcutDisposable=null})}newSelectionControl(n,o,r){const s=this.getSelectionControls().length,{rowHeaderWidth:i,columnHeaderHeight:c}=o,d=new D.SelectionControl(n,s,this._themeService,{highlightHeader:this._highlightHeader,enableAutoFill:!1,rowHeaderWidth:i,columnHeaderHeight:c}),g=D.attachSelectionWithCoord(r,o);return d.updateRangeBySelectionWithCoord(g),this._selectionControls.push(d),d.setControlExtension({skeleton:o,scene:n,themeService:this._themeService,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),d}},F.RefSelectionsRenderService=hr([xe(1,a.Inject(a.Injector)),xe(2,a.Inject(a.ThemeService)),xe(3,l.IShortcutService),xe(4,a.Inject(D.SheetSkeletonManagerService)),xe(5,a.IContextService),xe(6,L.IRefSelectionsService)],F.RefSelectionsRenderService);function gr(e){const t=D.genNormalSelectionStyle(e);return t.widgets={tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},t}const at=(e,t,n=!0)=>{let o=-1;return e.reduce((r,s,i)=>{if(r.isFinish)return r;const c=r.currentIndex;if(typeof s!="string")r.currentIndex+=s.token.length;else{const d=s.length;r.currentIndex+=d}return(n?r.currentIndex===t:t>c&&t<=r.currentIndex)&&(o=i,r.isFinish=!0),r},{currentIndex:0,isFinish:!1}),o},At=(e,t)=>{const n=e[t];let o=-1;if(!n||typeof n=="string"||n.nodeType!==R.sequenceNodeType.REFERENCE)return-1;for(let r=0;r<=t;r++){const s=e[r];typeof s!="string"&&s.nodeType===R.sequenceNodeType.REFERENCE&&o++}return o},Sr=(e,t=100)=>{I.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])};function Pt(e,t,n){const o=l.useDependency(J.IEditorService),r=I.useMemo(()=>new q.BehaviorSubject({left:-999,top:-999,right:-999,bottom:-999}),[]),s=l.useDependency(l.ISidebarService),i=l.useDependency(a.IUniverInstanceService),c=l.useEvent(()=>{var T;const d=o.getEditor(e);if(!d)return;const g=d.getBoundingClientRect(),{marginTop:p=0,marginBottom:S=0}=d.getDocumentData().documentStyle,h=d.getSkeleton();if(!h)return;const f=(T=h.getSkeletonData())==null?void 0:T.pages[0].height;let{left:u,top:_,right:m,bottom:C}=g;_=_+p,C=f?_+f:C-S;const E=r.getValue();if(!(E.left===u&&E.top===_&&E.right===m&&E.bottom===C))return r.next({left:u-1,right:m+1,top:_-1,bottom:C+1}),g});return I.useEffect(()=>{t&&c()},[e,o,i.unitAdded$,c,t,...n!=null?n:[]]),Sr(c),I.useEffect(()=>{const d=s.scrollEvent$.pipe(q.throttleTime(100)).subscribe(c);return()=>{d.unsubscribe()}},[]),[r,c]}const Te=e=>{const t=I.useRef(e);return t.current=e,t},pr=(e,t,n)=>{const o=l.useDependency(Ue),r=l.useDependency(ve.IDescriptionService),s=l.useDependency(R.LexerTreeBuilder),[i,c]=I.useState(),[d,g]=I.useState(-1),[p,S]=I.useState(!0),h=Te(p),f=I.useRef(t);f.current=t;const u=()=>{c(void 0),g(-1),S(!1)};return I.useEffect(()=>{const _=s.sequenceNodesBuilder(t.slice(1));o.setSequenceNodes(_!=null?_:[])},[t]),I.useEffect(()=>{if(n&&e){const _=n.selectionChange$.pipe(q.debounceTime(50)).subscribe(C=>{if(C.textRanges.length===1){const[E]=C.textRanges;if(E.collapsed&&h.current){const{startOffset:T}=E,N=o.getCurrentSequenceNodeIndex(T-2),v=o.getCurrentSequenceNodeByIndex(N),M=o.getCurrentSequenceNodeByIndex(N+1);if(v)if(typeof v!="string"&&v.nodeType===3&&!r.hasDefinedNameDescription(v.token.trim())&&M===R.matchToken.OPEN_BRACKET){const x=r.getFunctionInfo(v.token);c(x),g(-1);return}else{const x=s.getFunctionAndParameter(`${f.current}A`,T-1);if(x){const{functionName:W,paramIndex:U}=x,w=r.getFunctionInfo(W);c(w),g(U);return}}}}c(void 0),g(-1)}),m=n.selectionChange$.pipe(q.filter(C=>C.textRanges.length===1),q.map(C=>C.textRanges[0].startOffset),q.distinctUntilChanged()).subscribe(()=>{S(!0)});return()=>{_.unsubscribe(),m.unsubscribe()}}},[n,e]),I.useEffect(()=>{e||u()},[e]),{functionInfo:i,paramIndex:d,reset:u}},vr=({onClick:e})=>y.jsx("div",{className:"univer-z-[15] univer-box-border univer-h-[18px] univer-cursor-pointer univer-overflow-visible univer-whitespace-nowrap univer-rounded-l univer-border univer-border-r-0 univer-border-gray-600 univer-bg-primary-600 univer-p-0.5 univer-text-xs univer-font-bold univer-leading-[13px] univer-text-white",onClick:e,children:"?"}),lt=({className:e,title:t,value:n})=>y.jsxs("div",{className:"univer-my-2",children:[y.jsx("div",{className:B.clsx("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",e),children:t}),y.jsx("div",{className:"univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",children:n})]}),mr=e=>{const{prefix:t,value:n,active:o,onClick:r}=e;return y.jsxs("div",{children:[y.jsxs("span",{children:[t,"("]}),n&&n.map((s,i)=>y.jsxs("span",{children:[y.jsx("span",{className:o===i?"univer-text-primary-500":"",onClick:()=>r(i),children:Tt(s)}),i===n.length-1?"":","]},s.name)),")"]})},Lt=()=>{};function Cr(e){const{onParamsSwitch:t=Lt,onClose:n=Lt,isFocus:o,editor:r,formulaText:s}=e,{functionInfo:i,paramIndex:c,reset:d}=pr(o,s,r),g=l.useDependency(D.IEditorBridgeService),p=!l.useObservable(g.helpFunctionVisible$),[S,h]=I.useState(!0),f=l.useDependency(a.LocaleService),u=f.t("formula.prompt.required"),_=f.t("formula.prompt.optional"),m=r.getEditorId(),[C]=Pt(m,!!i,[i,c]);function E(v){t&&t(v)}const T=l.useEvent(v=>{g.helpFunctionVisible$.next(!v)}),N=()=>{T(!0),n()};return i?p?y.jsx(l.RectPopup,{portal:!0,anchorRect$:C,direction:"left-center",children:y.jsx(vr,{onClick:()=>T(!1)})},"hidden"):y.jsx(l.RectPopup,{portal:!0,onClickOutside:()=>d(),anchorRect$:C,direction:"vertical",children:y.jsxs("div",{className:B.clsx("univer-m-0 univer-box-border univer-w-[250px] univer-select-none univer-list-none univer-rounded-lg univer-bg-white univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",B.borderClassName),children:[y.jsxs("div",{className:B.clsx("univer-wrap-anywhere univer-box-border univer-flex univer-items-center univer-justify-between univer-px-4 univer-py-3 univer-text-xs univer-font-medium univer-text-gray-900 dark:!univer-text-white",B.borderTopClassName),children:[y.jsx(mr,{prefix:i.functionName,value:i.functionParameter,active:c,onClick:E}),y.jsxs("div",{className:"univer-flex",children:[y.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-500 univer-outline-none univer-transition-colors hover:univer-bg-gray-200 dark:hover:!univer-bg-gray-600",style:{transform:S?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>h(!S),children:y.jsx(kt,{})}),y.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-600 univer-outline-none univer-transition-colors hover:univer-bg-gray-300 dark:!univer-text-gray-200 dark:hover:!univer-bg-gray-600",onClick:N,children:y.jsx(Nt,{})})]})]}),y.jsx("div",{className:B.clsx("univer-box-border univer-max-h-[350px] univer-overflow-y-auto univer-px-4 univer-pb-3 univer-pt-0",B.scrollbarClassName),style:{height:S?"unset":0,padding:S?"revert-layer":0},children:y.jsxs("div",{className:"univer-mt-3",children:[y.jsx(lt,{title:f.t("formula.prompt.helpExample"),value:`${i.functionName}(${i.functionParameter.map(v=>v.example).join(",")})`}),y.jsx(lt,{title:f.t("formula.prompt.helpAbstract"),value:i.description}),i&&i.functionParameter&&i.functionParameter.map((v,M)=>y.jsx(lt,{className:c===M?"univer-text-primary-500":"",title:v.name,value:`${v.require?u:_} ${v.detail}`},M))]})})]})},"show"):null}const _r=e=>{const t=l.useDependency(J.IEditorService);return l.useEvent(o=>{var r,s;if(e){t.focus(e.getEditorId());const i=[...e.getSelectionRanges()];if(a.Tools.isDefine(o))e.setSelectionRanges([{startOffset:o,endOffset:o}]);else if(!i.length&&!e.docSelectionRenderService.isOnPointerEvent){const c=(s=(r=e.getDocumentData().body)==null?void 0:r.dataStream)!=null?s:`\r
|
|
2
2
|
`,d=Math.max(c.length-2,0);e.setSelectionRanges([{startOffset:d,endOffset:d}])}else e.setSelectionRanges(i)}})};function Ir(e){var r,s;const n=e.get(a.IUniverInstanceService).getCurrentUniverDocInstance();return n!=null&&n.getBody()?{dataStream:(s=(r=n.getBody())==null?void 0:r.dataStream)!=null?s:"",offset:0}:void 0}var de=(e=>(e[e.NOT_SELECT=0]="NOT_SELECT",e[e.NEED_ADD=1]="NEED_ADD",e[e.CAN_EDIT=2]="CAN_EDIT",e[e.EDIT_OTHER_SHEET_REFERENCE=3]="EDIT_OTHER_SHEET_REFERENCE",e[e.EDIT_OTHER_WORKBOOK_REFERENCE=4]="EDIT_OTHER_WORKBOOK_REFERENCE",e))(de||{});function Er(e){var x;const{editorId:t,isFocus:n,disableOnClick:o,unitId:r,subUnitId:s}=e,i=l.useDependency(j.IRenderManagerService),c=l.useDependency(a.IUniverInstanceService),d=i.getRenderById(r),g=i.getRenderById(t),p=g==null?void 0:g.with(J.DocSelectionRenderService),S=l.useDependency(ft.DocSelectionManagerService),h=l.useDependency(a.Injector),[f,u]=I.useState(0),_=l.useDependency(R.LexerTreeBuilder),m=I.useRef(!0),C=d==null?void 0:d.with(F.RefSelectionsRenderService),E=Te(f),T=c.getUnit(r,a.UniverInstanceType.UNIVER_SHEET),N=T==null?void 0:T.getSheetBySheetId(s),v=l.useEvent(W=>{C&&C.setSkipLastEnabled(W===1||W===3||W===4),E.current=W,u(W)}),M=l.useEvent(()=>{var oe,se,ae;const W=c.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET);if(!W)return;const U=W.getActiveSheet(),w=p==null?void 0:p.getActiveTextRange(),$=w!=null&&w.collapsed?w.startOffset:-1,k=Ir(h);if(!k)return;const O=(oe=k==null?void 0:k.dataStream)==null?void 0:oe.slice(0,-2),A=((se=_.sequenceNodesBuilder(O))!=null?se:[]).map(z=>typeof z=="object"?z.nodeType===R.sequenceNodeType.REFERENCE?{...z,range:R.deserializeRangeWithSheetWithCache(z.token)}:{...z,range:void 0}:z),b=O[$-1],P=O[$],V=A.find(z=>typeof z=="object"&&z.nodeType===R.sequenceNodeType.REFERENCE&&$===z.endIndex+2),H=b&&R.matchRefDrawToken(b)&&(!P||R.isFormulaLexerToken(P)&&P!==R.matchToken.OPEN_BRACKET),K=!!V;if((O==null?void 0:O.substring(0,1))==="="&&(H||K))if(K){if(m.current)return;const{sheetName:z,unitId:ee}=V.range,ke=(ae=c.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:ae.getUnitId();ee&&ee!==ke?v(4):!z&&U.getSheetId()===(N==null?void 0:N.getSheetId())||z===U.getName()?v(2):v(3)}else m.current=!1,v(1);else v(0)});return I.useEffect(()=>{const W=S.textSelection$.pipe(q.filter(U=>U.unitId===t)).subscribe(()=>{M()});return()=>W.unsubscribe()},[M,S.textSelection$,t]),I.useEffect(()=>{n||(v(0),m.current=!0)},[n,v]),I.useEffect(()=>{var U;if(!o)return;const W=(U=g==null?void 0:g.mainComponent)==null?void 0:U.onPointerDown$.subscribeEvent(()=>{v(0),m.current=!0});return()=>W==null?void 0:W.unsubscribe()},[o,(x=g==null?void 0:g.mainComponent)==null?void 0:x.onPointerDown$,v]),I.useEffect(()=>{if(!n)return;const W=T==null?void 0:T.activeSheet$.subscribe(()=>{M()}),U=c.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(()=>{M()});return()=>{W==null||W.unsubscribe(),U==null||U.unsubscribe()}},[M,n,T==null?void 0:T.activeSheet$,c.getCurrentTypeOfUnit$]),{isSelecting:f,isSelectingRef:E}}const yr=()=>{const e=l.useDependency(R.LexerTreeBuilder);return I.useCallback(n=>e.sequenceNodesBuilder(n)||[],[e])};function Rr(e,t,n){const o=new a.ColorKit(t).setAlpha(.05).toRgbString();return{id:n,strokeWidth:1,stroke:t,fill:o,widgets:{tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},widgetSize:6,widgetStrokeWidth:1,widgetStroke:e.getColorFromTheme("white")}}function $t(e){var T,N,v;const{unitId:t,subUnitId:n,currentWorkbook:o,refSelections:r,editor:s,refSelectionsService:i,refSelectionsRenderService:c,sheetSkeletonManagerService:d,themeService:g,univerInstanceService:p}=e,S=o.getUnitId(),h=p.getUnit(t,a.UniverInstanceType.UNIVER_SHEET),f=h==null?void 0:h.getActiveSheet(),u=[];if(!h||!f){i.setSelections(u);return}const _=f.getSheetId(),m=M=>{var x;return(x=h==null?void 0:h.getSheetBySheetName(M))==null?void 0:x.getSheetId()};if(!((T=d==null?void 0:d.getWorksheetSkeleton(_))==null?void 0:T.skeleton))return;const E=[];for(let M=0,x=r.length;M<x;M++){const W=r[M],{themeColor:U,token:w,refIndex:$,endIndex:k}=W,O=R.deserializeRangeWithSheet(w),{unitId:A,sheetName:b,range:P}=O,V=m(b);if(!V&&b||S!==t&&A!==S||A&&A!==S||V&&V!==_||!V&&_!==n)continue;const H=L.setEndForRange(P,f.getRowCount(),f.getColumnCount());H.unitId=t,H.sheetId=_,u.push({range:H,primary:null,style:Rr(g,U,$.toString())}),E.push(k)}if(s){const M=(v=(N=s.getSelectionRanges())==null?void 0:N[0])==null?void 0:v.startOffset,x=E.findIndex(W=>W+2===M);x!==-1?c==null||c.setActiveSelectionIndex(x):c==null||c.resetActiveSelectionIndex()}return u}function Tr(e,t){const n=l.useDependency(a.IUniverInstanceService),o=l.useDependency(a.ThemeService),r=l.useDependency(L.IRefSelectionsService),s=l.useDependency(j.IRenderManagerService),i=l.useObservable(I.useMemo(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[n])),c=i?s.getRenderById(i.getUnitId()):null,d=c==null?void 0:c.with(F.RefSelectionsRenderService),g=c==null?void 0:c.with(D.SheetSkeletonManagerService),p=l.useEvent((S,h)=>{const f=n.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET);if(!f||d!=null&&d.selectionMoving)return;const u=$t({unitId:e,subUnitId:t,currentWorkbook:f,refSelections:S,editor:h,refSelectionsService:r,refSelectionsRenderService:d,sheetSkeletonManagerService:g,themeService:o,univerInstanceService:n});if(!u)return;((d==null?void 0:d.getSelectionControls())||[]).length===u.length?d==null||d.resetSelectionsByModelData(u):r.setSelections(u)});return I.useEffect(()=>()=>{d==null||d.resetActiveSelectionIndex()},[d]),p}function Ft(e=""){const t=l.useDependency(ve.IDescriptionService),n=br(),o=l.useDependency(a.ICommandService),r=I.useMemo(()=>e.length,[e]);return l.useEvent((i,c,d=!0,g)=>{const p=i.getDocumentData(),S=i.getEditorId();if(!p)return[];const h=p.body;if(!h)return[];const f=h.dataStream.slice(0,h.dataStream.length-2),u={dataStream:"",...p.body};if(!f.startsWith(e))return[];if(c==null||c.length===0)return u.textRuns=[],o.syncExecuteCommand(J.ReplaceTextRunsCommand.id,{unitId:S,body:a.getBodySlice(u,0,u.dataStream.length-2)}),[];{const{textRuns:_,refSelections:m}=Mr(t,n,c);r&&_.forEach(T=>{T.ed=T.ed+r,T.st=T.st+r}),u.textRuns=[{st:0,ed:1,ts:{fs:11}},..._];const C=c.reduce((T,N)=>typeof N=="string"?`${T}${N}`:`${T}${N.token}`,"");u.dataStream=`${e}${C}\r
|
|
3
3
|
`;let E;if(d){E=i.getSelectionRanges();const T=u.dataStream.length-2+r;E.forEach(N=>{N.startOffset=Math.max(0,Math.min(N.startOffset,T)),N.endOffset=Math.max(0,Math.min(N.endOffset,T))})}return o.syncExecuteCommand(J.ReplaceTextRunsCommand.id,{unitId:S,body:a.getBodySlice(u,0,u.dataStream.length-2),textRanges:g!=null?g:E}),m}})}function br(){const e=l.useDependency(a.ThemeService),t=e.getCurrentTheme();return I.useMemo(()=>{const o=[e.getColorFromTheme("loop-color.1"),e.getColorFromTheme("loop-color.2"),e.getColorFromTheme("loop-color.3"),e.getColorFromTheme("loop-color.4"),e.getColorFromTheme("loop-color.5"),e.getColorFromTheme("loop-color.6"),e.getColorFromTheme("loop-color.7"),e.getColorFromTheme("loop-color.8"),e.getColorFromTheme("loop-color.9"),e.getColorFromTheme("loop-color.10"),e.getColorFromTheme("loop-color.11"),e.getColorFromTheme("loop-color.12")].map(c=>e.isValidThemeColor(c)?e.getColorFromTheme(c):c),r=e.getColorFromTheme("blue.700"),s=e.getColorFromTheme("jiqing.800"),i=e.getColorFromTheme("black");return{formulaRefColors:o,numberColor:r,stringColor:s,plainTextColor:i}},[t])}function Mr(e,t,n){const{formulaRefColors:o,numberColor:r,stringColor:s,plainTextColor:i}=t,c=[],d=[],g=new Map;let p=0;for(let S=0,h=n.length;S<h;S++){const f=n[S];if(typeof f=="string"){const T=c[c.length-1],N=T?T.ed:0,v=N+f.length;c.push({st:N,ed:v,ts:{cl:{rgb:i},fs:11}});continue}if(e.hasDefinedNameDescription(f.token.trim())){c.push({st:f.startIndex,ed:f.endIndex+1,ts:{cl:{rgb:i},fs:11}});continue}const{startIndex:u,endIndex:_,nodeType:m,token:C}=f;let E="";if(m===R.sequenceNodeType.REFERENCE){if(g.has(C))E=g.get(C);else{const T=p%o.length;E=o[T],g.set(C,E),p++}d.push({refIndex:S,themeColor:E,token:C,startIndex:f.startIndex,endIndex:f.endIndex,index:d.length})}else m===R.sequenceNodeType.NUMBER?E=r:(m===R.sequenceNodeType.STRING||m===R.sequenceNodeType.ARRAY)&&(E=s);E&&E.length>0?c.push({st:u,ed:_+1,ts:{cl:{rgb:E},fs:11}}):c.push({st:u,ed:_+1,ts:{cl:{rgb:i},fs:11}})}return{textRuns:c,refSelections:d}}const Or=(e,t,n,o)=>{const r=l.useDependency(a.ICommandService),s=l.useDependency(l.IShortcutService),i=I.useRef(t);i.current=t;const c=I.useRef(o);c.current=o,I.useEffect(()=>{if(!n||!e)return;const g=`sheet.formula-embedding-editor.${n.getEditorId()}`,p=new a.DisposableCollection,S=(u,_)=>{if(c.current){c.current(u,_);return}let m=a.Direction.LEFT;u===l.KeyCode.ARROW_DOWN?m=a.Direction.DOWN:u===l.KeyCode.ARROW_UP?m=a.Direction.UP:u===l.KeyCode.ARROW_RIGHT&&(m=a.Direction.RIGHT),_===l.MetaKeys.SHIFT?r.executeCommand(J.MoveSelectionOperation.id,{direction:m}):r.executeCommand(J.MoveCursorOperation.id,{direction:m})},h=(u,_)=>{let m=a.Direction.DOWN;u===l.KeyCode.ARROW_DOWN?m=a.Direction.DOWN:u===l.KeyCode.ARROW_UP?m=a.Direction.UP:u===l.KeyCode.ARROW_LEFT?m=a.Direction.LEFT:u===l.KeyCode.ARROW_RIGHT&&(m=a.Direction.RIGHT),i.current?_===l.MetaKeys.CTRL_COMMAND?r.executeCommand(D.MoveSelectionCommand.id,{direction:m,jumpOver:D.JumpOver.moveGap,extra:"formula-editor",fromCurrentSelection:i.current===de.NEED_ADD||i.current===de.EDIT_OTHER_SHEET_REFERENCE}):_===l.MetaKeys.SHIFT?r.executeCommand(D.ExpandSelectionCommand.id,{direction:m,extra:"formula-editor"}):_===(l.MetaKeys.CTRL_COMMAND|l.MetaKeys.SHIFT)?r.executeCommand(D.ExpandSelectionCommand.id,{direction:m,jumpOver:D.JumpOver.moveGap,extra:"formula-editor"}):r.executeCommand(D.MoveSelectionCommand.id,{direction:m,extra:"formula-editor",fromCurrentSelection:i.current===de.NEED_ADD||i.current===de.EDIT_OTHER_SHEET_REFERENCE}):S(u,_)};return p.add(r.registerCommand({id:g,type:a.CommandType.OPERATION,handler(u,_){const{keyCode:m,metaKey:C}=_;h(m,C)}})),[{keyCode:l.KeyCode.ARROW_DOWN},{keyCode:l.KeyCode.ARROW_LEFT},{keyCode:l.KeyCode.ARROW_RIGHT},{keyCode:l.KeyCode.ARROW_UP},{keyCode:l.KeyCode.ARROW_DOWN,metaKey:l.MetaKeys.SHIFT},{keyCode:l.KeyCode.ARROW_LEFT,metaKey:l.MetaKeys.SHIFT},{keyCode:l.KeyCode.ARROW_RIGHT,metaKey:l.MetaKeys.SHIFT},{keyCode:l.KeyCode.ARROW_UP,metaKey:l.MetaKeys.SHIFT},{keyCode:l.KeyCode.ARROW_DOWN,metaKey:l.MetaKeys.CTRL_COMMAND},{keyCode:l.KeyCode.ARROW_LEFT,metaKey:l.MetaKeys.CTRL_COMMAND},{keyCode:l.KeyCode.ARROW_RIGHT,metaKey:l.MetaKeys.CTRL_COMMAND},{keyCode:l.KeyCode.ARROW_UP,metaKey:l.MetaKeys.CTRL_COMMAND},{keyCode:l.KeyCode.ARROW_DOWN,metaKey:l.MetaKeys.CTRL_COMMAND|l.MetaKeys.SHIFT},{keyCode:l.KeyCode.ARROW_LEFT,metaKey:l.MetaKeys.CTRL_COMMAND|l.MetaKeys.SHIFT},{keyCode:l.KeyCode.ARROW_RIGHT,metaKey:l.MetaKeys.CTRL_COMMAND|l.MetaKeys.SHIFT},{keyCode:l.KeyCode.ARROW_UP,metaKey:l.MetaKeys.CTRL_COMMAND|l.MetaKeys.SHIFT}].map(({keyCode:u,metaKey:_})=>({id:g,binding:_?u|_:u,preconditions:()=>!0,priority:900,staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keyCode:u,metaKey:_}})).forEach(u=>{p.add(s.registerShortcut(u))}),()=>{p.dispose()}},[r,n,e,s])},Nr=(e,t,n,o,r=!0)=>{var f;const s=l.useDependency(j.IRenderManagerService),i=l.useDependency(a.IContextService),c=l.useDependency(l.IContextMenuService),d=l.useDependency(L.IRefSelectionsService),g=l.useDependency(a.IUniverInstanceService),p=l.useObservable(I.useMemo(()=>g.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[g])),S=s.getRenderById((f=p==null?void 0:p.getUnitId())!=null?f:""),h=S==null?void 0:S.with(F.RefSelectionsRenderService);I.useLayoutEffect(()=>{if(e)return i.setContextValue(a.EDITOR_ACTIVATED,!0),r&&c.disable(),()=>{const u=g.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);(u==null?void 0:u.getUnitId())===o&&i.setContextValue(a.EDITOR_ACTIVATED,!1),r&&c.enable(),d.clear()}},[i,e,d,r,o]),I.useLayoutEffect(()=>{if(e&&t){const u=h==null?void 0:h.enableSelectionChanging();return i.setContextValue(L.REF_SELECTIONS_ENABLED,!0),()=>{i.setContextValue(L.REF_SELECTIONS_ENABLED,!1),u==null||u.dispose()}}},[i,e,h,t]),I.useEffect(()=>{e&&(h==null||h.setSkipLastEnabled(!1))},[e,h])},Dr=(e,t,n)=>{const o=l.useDependency(a.IUniverInstanceService),r=l.useDependency(L.SheetsSelectionsService);return I.useCallback(()=>{if(e){const i=[...r.getWorkbookSelections(t).getSelectionsOfWorksheet(n)],c=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=c==null?void 0:c.getActiveSheet();(c==null?void 0:c.getUnitId())!==t&&o.setCurrentUnitForType(t),d&&d.getSheetId()===n&&r.setSelections(i)}},[e,r,n,t,o])},xr=e=>e.reduce((t,n)=>typeof n=="string"?t+n.length:t+n.token.length,0),ut=e=>e.map(t=>typeof t=="string"?t:t.token).join(""),Ge=(e,t=!1,n="",o=!1)=>!t&&!o?e.map(r=>R.serializeRange(r.range)):e.map(r=>o?R.serializeRangeToRefString(r):r.sheetName!==""&&r.sheetName!==n?R.serializeRangeWithSheet(r.sheetName,r.range):R.serializeRange(r.range)),kr=e=>{var p,S,h;const{editor:t,lexerTreeBuilder:n}=e,o=t==null?void 0:t.getSelectionRanges();if((o==null?void 0:o.length)!==1)return;const s=o[0].startOffset-1,i=((S=(p=t==null?void 0:t.getDocumentData().body)==null?void 0:p.dataStream)!=null?S:`\r
|
|
4
|
-
`).slice(0,-2),c=(h=n.sequenceNodesBuilder(i.slice(1)))!=null?h:[],d=at(c,s,!1),g=At(c,d);return{nodeIndex:d,updatingRefIndex:g,sequenceNodes:c,offset:s}},wr=(()=>{}),Ar=(e,t,n,o,r,s,i,c,d,g=wr)=>{var $;const p=l.useDependency(j.IRenderManagerService),S=l.useDependency(a.IUniverInstanceService),h=l.useDependency(a.ICommandService),f=l.useDependency(ft.DocSelectionManagerService),u=l.useDependency(a.ThemeService),_=l.useDependency(R.LexerTreeBuilder),m=S.getUnit(o),C=l.useEvent((k,O)=>{var A,b,P;return(P=(b=(A=S.getUnit(k))==null?void 0:A.getSheetBySheetId(O))==null?void 0:b.getName())!=null?P:""}),E=I.useMemo(()=>C(o,r),[C,r,o]),T=l.useObservable(m==null?void 0:m.activeSheet$),N=Te({activeSheet:T,sheetName:E}),v=l.useObservable(I.useMemo(()=>S.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[S])),M=p.getRenderById(($=v==null?void 0:v.getUnitId())!=null?$:""),x=M==null?void 0:M.with(F.RefSelectionsRenderService),W=M==null?void 0:M.with(D.SheetSkeletonManagerService),U=l.useDependency(L.IRefSelectionsService),w=l.useEvent((k,O)=>{var K,oe,se,ae,z,ee,ke,we,Xe,fe;const A=kr({editor:d,lexerTreeBuilder:_});if(!A)return;const{nodeIndex:b,updatingRefIndex:P,sequenceNodes:V,offset:H}=A;if(n.current===de.NEED_ADD)if(H!==0){if(b===-1&&V.length)return;const G=k[k.length-1],Q=V.splice(b+1),he=(K=G.sheetId)!=null?K:r,le={range:G,unitId:(oe=G.unitId)!=null?oe:v.getUnitId(),sheetName:C((se=G.unitId)!=null?se:v.getUnitId(),he)},te=he!==r,ie=(v==null?void 0:v.getUnitId())!==o,ge=Ge([le],i&&(te||ie),E,ie);V.push({token:ge[0],nodeType:R.sequenceNodeType.REFERENCE});const be=[...V,...Q],me=ut(be);g(me,xr(V),O)}else{const G=k[k.length-1],Q=(ae=G.sheetId)!=null?ae:r,he={range:G,unitId:(z=G.unitId)!=null?z:v.getUnitId(),sheetName:C((ee=G.unitId)!=null?ee:v.getUnitId(),Q)},le=Q!==r,te=(v==null?void 0:v.getUnitId())!==o,ie=Ge([he],i&&(le||te),E,te);V.unshift({token:ie[0],nodeType:R.sequenceNodeType.REFERENCE});const ge=ut(V);g(ge,ie[0].length,O)}else if(n.current===de.EDIT_OTHER_SHEET_REFERENCE||n.current===de.EDIT_OTHER_WORKBOOK_REFERENCE){const G=k.pop();if(!G)return;const Q=V[b];if(typeof Q=="object"&&Q.nodeType===R.sequenceNodeType.REFERENCE){const he=Q.token;(v==null?void 0:v.getUnitId())!==o?Q.token=R.serializeRangeWithSpreadsheet((ke=v==null?void 0:v.getUnitId())!=null?ke:"",E,G):Q.token=E===(T==null?void 0:T.getName())?R.serializeRange(G):R.serializeRangeWithSheet(T.getName(),G);const te=H+(Q.token.length-he.length);g(R.generateStringWithSequence(V),te,O)}}else{const G=[...k];if(P!==-1){const Z=G.pop();Z&&G.splice(P,0,Z)}let Q=0;const he=V.map(Z=>{var ue,Ae,Me,Oe;if(typeof Z=="string")return Z;if(Z.nodeType===R.sequenceNodeType.REFERENCE){const Ne=R.deserializeRangeWithSheet(Z.token);if(Ne.sheetName||(Ne.sheetName=E),(Ne.unitId||o)!==(v==null?void 0:v.getUnitId())||i&&((ue=N.current.activeSheet)==null?void 0:ue.getName())!==Ne.sheetName)return Z.token;const ne=G[Q];if(Q++,!ne)return"";const Se=(Ae=ne.sheetId)!=null?Ae:r,Qe={range:ne,unitId:(Me=ne.unitId)!=null?Me:v.getUnitId(),sheetName:C((Oe=ne.unitId)!=null?Oe:v.getUnitId(),Se)},Je=(v==null?void 0:v.getUnitId())!==o;return Ge([Qe],i&&(Se!==r||Je),E,Je)[0]}return Z.token});let le="",te;he.forEach((Z,ue)=>{le+=Z,ue===b&&(te=le.length)});const ie=[];for(let Z=Q;Z<=k.length-1;Z++){const ue=k[Z],Ae=(we=ue.sheetId)!=null?we:r,Me={range:ue,unitId:(Xe=ue.unitId)!=null?Xe:v.getUnitId(),sheetName:C((fe=ue.unitId)!=null?fe:v.getUnitId(),Ae)},Oe=(v==null?void 0:v.getUnitId())!==o,ne=Ge([Me],i&&(Ae!==r||Oe),E,Oe);ie.push(ne[0])}const ge=V[V.length-1],be=ge&&(typeof ge=="string"?!1:ge.nodeType===R.sequenceNodeType.REFERENCE),me=`${le}${ie.length&&be?",":""}${ie.join(",")}`;g(me,!ie.length&&te?te:me.length,O)}});I.useEffect(()=>{if(x&&e){let k=!0;const O=(b,P)=>{if(k){k=!1;return}w(b.map(V=>V.rangeWithCoord),P)},A=new a.DisposableCollection;return A.add(x.selectionMoving$.subscribe(b=>{O(b,!1)})),A.add(x.selectionMoveEnd$.subscribe(b=>{O(b,!0)})),()=>{A.dispose()}}},[e,w,x]),I.useEffect(()=>{if(t&&x&&d){const k=new a.DisposableCollection,O=()=>{k.dispose(),x.getSelectionControls().forEach((P,V)=>{k.add(P.selectionScaling$.subscribe(H=>{const K=x.getSelectionDataWithStyle().map(se=>se.rangeWithCoord),oe=K[V];H.sheetId=oe.sheetId,H.unitId=oe.unitId,K[V]=H,w(K,!1)})),k.add(P.selectionMoving$.subscribe(H=>{const K=x.getSelectionDataWithStyle().map(se=>se.rangeWithCoord),oe=K[V];H.sheetId=oe.sheetId,H.unitId=oe.unitId,K[V]=H,w(K,!0)}))})},A=q.merge(d.input$,U.selectionSet$,x.selectionMoveEnd$).pipe(Xt.debounceTime(50)).subscribe(()=>{O()});return()=>{A.unsubscribe(),k.dispose()}}},[d,t,w,x,U.selectionSet$]),x==null||x.getSelectionDataWithStyle(),I.useEffect(()=>{if(c){const k=h.onCommandExecuted(O=>{var b;if(O.id!==L.SetSelectionsOperation.id)return;const A=O.params;if(A.extra==="formula-editor"&&A.selections.length){const P=A.selections[A.selections.length-1];if(P){const V=n.current===de.NEED_ADD,H=((b=x==null?void 0:x.getSelectionDataWithStyle())!=null?b:[]).map(K=>K.rangeWithCoord);V?H.push(P.range):H[H.length-1]=P.range,w(H,!0)}}});return()=>{k.dispose()}}},[h,d,n,_,c,w,x]),I.useEffect(()=>{if(!d)return;const k=f.textSelection$.subscribe(O=>{O.unitId===d.getEditorId()&&$t({unitId:o,subUnitId:r,refSelections:s.current,editor:d,refSelectionsService:U,refSelectionsRenderService:x,sheetSkeletonManagerService:W,themeService:u,univerInstanceService:S,currentWorkbook:v})});return()=>k.unsubscribe()},[f.textSelection$,d,s,x,U,W,r,u,o,S])},Pr=(e,t,n,o,r,s)=>{const i=l.useDependency(a.ICommandService),c=l.useDependency(J.IEditorService),g=l.useDependency(j.IRenderManagerService).getRenderById(t),p=l.useDependency(a.IUniverInstanceService),S=g==null?void 0:g.with(F.RefSelectionsRenderService);I.useEffect(()=>{if(e&&S)if(n){const h=()=>{const _=S.getSelectionControls().length;for(let m=1;m<=_;m++)S.clearLastSelection();return setTimeout(()=>{s()},30)},f=i.onCommandExecuted(_=>{_.id===L.SetWorksheetActiveOperation.id&&h()}),u=p.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(_=>{h()});return()=>{f.dispose(),u.unsubscribe()}}else{const h=i.beforeCommandExecuted(f=>{if(f.id===L.SetWorksheetActiveOperation.id){o(!1),r(),s();const u=c.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);u==null||u.focus()}});return()=>{h.dispose()}}},[e,S])},Lr=(e,t,n)=>{const o=l.useDependency(R.LexerTreeBuilder),r=I.useRef(!0);I.useEffect(()=>{if(e){const s=setTimeout(()=>{r.current=!1},500);return()=>{clearTimeout(s)}}},[e]),I.useEffect(()=>{if(!r.current&&t){const s=o.checkIfAddBracket(n);t(s===0&&n.startsWith(R.operatorToken.EQUALS),`${n}`)}},[n,t])},$r=(e,t=[],n)=>{const o=l.useDependency(ve.IDescriptionService),[r,s]=I.useState([]),[i,c]=I.useState(""),d=I.useRef(-1),g=Te({nodes:t}),p=()=>{s([]),c(""),d.current=-1};return I.useEffect(()=>{if(n&&e){const h=n.input$.pipe(q.debounceTime(300)).subscribe(()=>{const f=n.getSelectionRanges();if(f.length===1){const u=g.current.nodes,_=f[0];if(_.collapsed){const m=at(u,_.startOffset-1,!1);d.current=m;const C=u[m];if(C&&typeof C!="string"&&C.nodeType===R.sequenceNodeType.FUNCTION){d.current=m;const E=C.token,T=o.getSearchListByNameFirstLetter(E);s(T),c(E);return}}}d.current=-1,c(""),s(u=>u!=null&&u.length?[]:u)});return()=>{h.unsubscribe()}}},[n,e]),I.useEffect(()=>{e||p()},[e]),{searchList:r,searchText:i,handlerFormulaReplace:(h,f)=>{const u=[...g.current.nodes];if(d.current!==-1){const _=u.splice(d.current+1),m=u.pop()||"";let C=(typeof m=="string"?m.length:m.token.length)-h.length;return u.push(h),_[0]!==R.matchToken.OPEN_BRACKET&&f!==R.FunctionType.DefinedName&&(u.push(R.matchToken.OPEN_BRACKET),C--),{text:ut([...u,..._]),offset:C}}},reset:p}},Fr=()=>{},Wr=I.forwardRef(Ur);function Ur(e,t){const{isFocus:n,sequenceNodes:o,onSelect:r,editor:s,onClose:i=Fr}=e,c=s.getEditorId(),d=l.useDependency(l.IShortcutService),g=l.useDependency(a.ICommandService),{searchList:p,searchText:S,handlerFormulaReplace:h,reset:f}=$r(n,o,s),u=I.useMemo(()=>!!p.length,[p]),_=I.useRef(void 0),[m,C]=I.useState(0),E=I.useRef(!1),[T]=Pt(c,u,[S,p]),N=Te({searchList:p,active:m}),v=(w,$)=>{const k=h(w,$);k&&(f(),r(k))};function M(w){E.current&&C(w)}function x(){E.current&&C(-1)}I.useEffect(()=>{if(!p.length)return;const w=`sheet.formula-embedding-editor.search_function.${c}`,$=new a.DisposableCollection,k=O=>{const{searchList:A,active:b}=N.current;switch(O){case l.KeyCode.ARROW_UP:{C(P=>{const V=Math.max(0,P-1);return W(V),V});break}case l.KeyCode.ARROW_DOWN:{C(P=>{const V=Math.min(A.length-1,P+1);return W(V),V});break}case l.KeyCode.TAB:case l.KeyCode.ENTER:{const P=A[b];v(P.name,P.functionType);break}case l.KeyCode.ESC:{f(),i();break}}};return $.add(g.registerCommand({id:w,type:a.CommandType.OPERATION,handler(O,A){const{keyCode:b}=A;k(b)}})),[l.KeyCode.ARROW_UP,l.KeyCode.ARROW_DOWN,l.KeyCode.ENTER,l.KeyCode.ESC,l.KeyCode.TAB].map(O=>({id:w,binding:O,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keyCode:O}})).forEach(O=>{$.add(d.registerShortcut(O))}),()=>{$.dispose()}},[p]);function W(w){const $=_.current;if(!$)return;const k=$.children[w];if(!k)return;const A=$.getBoundingClientRect().top,b=$.offsetHeight,P=k.getBoundingClientRect(),V=P.top,H=P.height;if(V>=0&&V>A&&V-A+H<=b)return;const K=k.offsetTop-(b-H)/2;$.scrollTo({top:K,behavior:"smooth"})}const U=I.useMemo(()=>{let w="";return()=>{clearTimeout(w),E.current=!0,w=setTimeout(()=>{E.current=!1},300)}},[]);return p.length>0&&u&&y.jsx(l.RectPopup,{portal:!0,anchorRect$:T,direction:"vertical",children:y.jsx("ul",{ref:w=>{_.current=w,t&&(t.current=w)},"data-u-comp":"sheets-formula-editor",className:B.clsx("univer-m-0 univer-box-border univer-max-h-[400px] univer-w-[250px] univer-list-none univer-overflow-y-auto univer-rounded-lg univer-bg-white univer-p-2 univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",B.borderClassName,B.scrollbarClassName),children:p.map((w,$)=>y.jsxs("li",{className:B.clsx("univer-box-border univer-cursor-pointer univer-rounded univer-px-2 univer-py-1 univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200 dark:!univer-bg-gray-600":m===$}),onMouseEnter:()=>M($),onMouseLeave:x,onMouseMove:U,onClick:()=>{v(w.name,w.functionType),s&&s.focus()},children:[y.jsxs("span",{className:"univer-block univer-overflow-x-hidden univer-text-ellipsis univer-text-xs",children:[y.jsx("span",{className:"univer-text-red-500",children:w.name.substring(0,S.length)}),y.jsx("span",{children:w.name.slice(S.length)})]}),y.jsx("span",{className:"univer-block univer-text-xs univer-text-gray-400",children:w.desc})]},w.name))})})}const Vr=e=>e.startsWith(R.operatorToken.EQUALS)?e.slice(1):"",Wt=()=>{},Ut=I.forwardRef((e,t)=>{var jt,qt,Yt,zt;const{errorText:n,initValue:o,unitId:r,subUnitId:s,isFocus:i=!0,isSupportAcrossSheet:c=!1,onFocus:d=Wt,onBlur:g=Wt,onChange:p,onVerify:S,className:h,editorId:f,moveCursor:u=!0,onFormulaSelectingChange:_,keyboardEventConfig:m,onMoveInEditor:C,resetSelectionOnBlur:E=!0,autoScrollbar:T=!0,isSingle:N=!0,disableSelectionOnClick:v=!1,autofocus:M=!0,disableContextMenu:x,style:W}=e,U=l.useDependency(J.IEditorService),w=I.useRef(null),$=l.useEvent(p);I.useImperativeHandle(t,()=>({isClickOutSide:X=>w.current?!w.current.contains(X.target):!1}));const k=l.useEvent(_),O=I.useRef(null),A=I.useRef(void 0),b=A.current,[P,V]=I.useState(i),H=I.useRef(null),K=I.useMemo(()=>f!=null?f:a.createInternalEditorID(`${D.EMBEDDING_FORMULA_EDITOR}-${a.generateRandomId(4)}`),[]),oe=I.useMemo(()=>n!==void 0,[n]),se=l.useDependency(a.IUniverInstanceService),ae=se.getUnit(K);l.useObservable(ae==null?void 0:ae.change$);const z=yr(),ee=a.BuildTextUtils.transform.getPlainText((qt=(jt=ae==null?void 0:ae.getBody())==null?void 0:jt.dataStream)!=null?qt:""),ke=Te(ee),we=I.useMemo(()=>Vr(ee),[ee]),Xe=I.useMemo(()=>z(we),[we,z]),{isSelecting:fe,isSelectingRef:G}=Er({unitId:r,subUnitId:s,editorId:K,isFocus:P,disableOnClick:v}),Q=I.useRef(""),le=l.useDependency(j.IRenderManagerService).getRenderById(K),te=le==null?void 0:le.with(J.DocSelectionRenderService),ie=te==null?void 0:te.isFocusing,ge=I.useMemo(()=>se.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC),[se]),be=l.useObservable(ge),me=(be==null?void 0:be.getUnitId())===K,Z=I.useRef([]),ue=fe,Me=(zt=(Yt=l.useDependency(a.IConfigService).getConfig(_t))==null?void 0:Yt.functionScreenTips)!=null?zt:!0;l.useUpdateEffect(()=>{$(ee)},[ee,$]);const Oe=Ft("="),Ne=Tr(r,s),ne=l.useEvent((X,re=!0,Ce,pe)=>{if(!A.current)return;Q.current=X;const et=X[0]==="="?X.slice(1):"",_e=z(et),eo=_e.reduce((De,nt)=>typeof nt=="object"?`${De}${nt.token}`:`${De}${nt}`,""),tt=Oe(A.current,eo===et?_e:[],re,pe);if(Z.current=tt,Ce){const De=pe!=null?pe:b==null?void 0:b.getSelectionRanges();if((De==null?void 0:De.length)!==1)return;const to=De[0].startOffset-1,no=at(_e,to,!1),Gt=At(_e,no);if(Gt>=0){const Zt=tt.splice(Gt,1)[0];Zt&&tt.push(Zt)}Ne(P?tt:[],A.current)}});I.useEffect(()=>{P&&ne(ee,!1,!0)},[P]),I.useEffect(()=>{if(P){if(Q.current===ee)return;ne(ee,!1,!0)}},[ee]),Lr(P,S,ee);const Se=_r(b),Qe=Dr(P,r,s);I.useEffect(()=>{var X;k(fe,(X=te==null?void 0:te.isFocusing)!=null?X:!0)},[k,fe]),J.useKeyboardEvent(P,m,b),I.useLayoutEffect(()=>{let X;if(H.current){X=U.register({autofocus:M,editorUnitId:K,initialSnapshot:{id:K,body:{dataStream:`${o}\r
|
|
4
|
+
`).slice(0,-2),c=(h=n.sequenceNodesBuilder(i.slice(1)))!=null?h:[],d=at(c,s,!1),g=At(c,d);return{nodeIndex:d,updatingRefIndex:g,sequenceNodes:c,offset:s}},wr=(()=>{}),Ar=(e,t,n,o,r,s,i,c,d,g=wr)=>{var $;const p=l.useDependency(j.IRenderManagerService),S=l.useDependency(a.IUniverInstanceService),h=l.useDependency(a.ICommandService),f=l.useDependency(ft.DocSelectionManagerService),u=l.useDependency(a.ThemeService),_=l.useDependency(R.LexerTreeBuilder),m=S.getUnit(o),C=l.useEvent((k,O)=>{var A,b,P;return(P=(b=(A=S.getUnit(k))==null?void 0:A.getSheetBySheetId(O))==null?void 0:b.getName())!=null?P:""}),E=I.useMemo(()=>C(o,r),[C,r,o]),T=l.useObservable(m==null?void 0:m.activeSheet$),N=Te({activeSheet:T,sheetName:E}),v=l.useObservable(I.useMemo(()=>S.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[S])),M=p.getRenderById(($=v==null?void 0:v.getUnitId())!=null?$:""),x=M==null?void 0:M.with(F.RefSelectionsRenderService),W=M==null?void 0:M.with(D.SheetSkeletonManagerService),U=l.useDependency(L.IRefSelectionsService),w=l.useEvent((k,O)=>{var K,oe,se,ae,z,ee,ke,we,Xe,fe;const A=kr({editor:d,lexerTreeBuilder:_});if(!A)return;const{nodeIndex:b,updatingRefIndex:P,sequenceNodes:V,offset:H}=A;if(n.current===de.NEED_ADD)if(H!==0){if(b===-1&&V.length)return;const G=k[k.length-1],Q=V.splice(b+1),he=(K=G.sheetId)!=null?K:r,le={range:G,unitId:(oe=G.unitId)!=null?oe:v.getUnitId(),sheetName:C((se=G.unitId)!=null?se:v.getUnitId(),he)},te=he!==r,ie=(v==null?void 0:v.getUnitId())!==o,ge=Ge([le],i&&(te||ie),E,ie);V.push({token:ge[0],nodeType:R.sequenceNodeType.REFERENCE});const be=[...V,...Q],me=ut(be);g(me,xr(V),O)}else{const G=k[k.length-1],Q=(ae=G.sheetId)!=null?ae:r,he={range:G,unitId:(z=G.unitId)!=null?z:v.getUnitId(),sheetName:C((ee=G.unitId)!=null?ee:v.getUnitId(),Q)},le=Q!==r,te=(v==null?void 0:v.getUnitId())!==o,ie=Ge([he],i&&(le||te),E,te);V.unshift({token:ie[0],nodeType:R.sequenceNodeType.REFERENCE});const ge=ut(V);g(ge,ie[0].length,O)}else if(n.current===de.EDIT_OTHER_SHEET_REFERENCE||n.current===de.EDIT_OTHER_WORKBOOK_REFERENCE){const G=k.pop();if(!G)return;const Q=V[b];if(typeof Q=="object"&&Q.nodeType===R.sequenceNodeType.REFERENCE){const he=Q.token;(v==null?void 0:v.getUnitId())!==o?Q.token=R.serializeRangeWithSpreadsheet((ke=v==null?void 0:v.getUnitId())!=null?ke:"",E,G):Q.token=E===(T==null?void 0:T.getName())?R.serializeRange(G):R.serializeRangeWithSheet(T.getName(),G);const te=H+(Q.token.length-he.length);g(R.generateStringWithSequence(V),te,O)}}else{const G=[...k];if(P!==-1){const Z=G.pop();Z&&G.splice(P,0,Z)}let Q=0;const he=V.map(Z=>{var ue,Ae,Me,Oe;if(typeof Z=="string")return Z;if(Z.nodeType===R.sequenceNodeType.REFERENCE){const Ne=R.deserializeRangeWithSheet(Z.token);if(Ne.sheetName||(Ne.sheetName=E),(Ne.unitId||o)!==(v==null?void 0:v.getUnitId())||i&&((ue=N.current.activeSheet)==null?void 0:ue.getName())!==Ne.sheetName)return Z.token;const ne=G[Q];if(Q++,!ne)return"";const Se=(Ae=ne.sheetId)!=null?Ae:r,Qe={range:ne,unitId:(Me=ne.unitId)!=null?Me:v.getUnitId(),sheetName:C((Oe=ne.unitId)!=null?Oe:v.getUnitId(),Se)},Je=(v==null?void 0:v.getUnitId())!==o;return Ge([Qe],i&&(Se!==r||Je),E,Je)[0]}return Z.token});let le="",te;he.forEach((Z,ue)=>{le+=Z,ue===b&&(te=le.length)});const ie=[];for(let Z=Q;Z<=k.length-1;Z++){const ue=k[Z],Ae=(we=ue.sheetId)!=null?we:r,Me={range:ue,unitId:(Xe=ue.unitId)!=null?Xe:v.getUnitId(),sheetName:C((fe=ue.unitId)!=null?fe:v.getUnitId(),Ae)},Oe=(v==null?void 0:v.getUnitId())!==o,ne=Ge([Me],i&&(Ae!==r||Oe),E,Oe);ie.push(ne[0])}const ge=V[V.length-1],be=ge&&(typeof ge=="string"?!1:ge.nodeType===R.sequenceNodeType.REFERENCE),me=`${le}${ie.length&&be?",":""}${ie.join(",")}`;g(me,!ie.length&&te?te:me.length,O)}});I.useEffect(()=>{if(x&&e){let k=!0;const O=(b,P)=>{if(k){k=!1;return}w(b.map(V=>V.rangeWithCoord),P)},A=new a.DisposableCollection;return A.add(x.selectionMoving$.subscribe(b=>{O(b,!1)})),A.add(x.selectionMoveEnd$.subscribe(b=>{O(b,!0)})),()=>{A.dispose()}}},[e,w,x]),I.useEffect(()=>{if(t&&x&&d){const k=new a.DisposableCollection,O=()=>{k.dispose(),x.getSelectionControls().forEach((P,V)=>{k.add(P.selectionScaling$.subscribe(H=>{const K=x.getSelectionDataWithStyle().map(se=>se.rangeWithCoord),oe=K[V];H.sheetId=oe.sheetId,H.unitId=oe.unitId,K[V]=H,w(K,!1)})),k.add(P.selectionMoving$.subscribe(H=>{const K=x.getSelectionDataWithStyle().map(se=>se.rangeWithCoord),oe=K[V];H.sheetId=oe.sheetId,H.unitId=oe.unitId,K[V]=H,w(K,!0)}))})},A=q.merge(d.input$,U.selectionSet$,x.selectionMoveEnd$).pipe(Xt.debounceTime(50)).subscribe(()=>{O()});return()=>{A.unsubscribe(),k.dispose()}}},[d,t,w,x,U.selectionSet$]),x==null||x.getSelectionDataWithStyle(),I.useEffect(()=>{if(c){const k=h.onCommandExecuted(O=>{var b;if(O.id!==L.SetSelectionsOperation.id)return;const A=O.params;if(A.extra==="formula-editor"&&A.selections.length){const P=A.selections[A.selections.length-1];if(P){const V=n.current===de.NEED_ADD,H=((b=x==null?void 0:x.getSelectionDataWithStyle())!=null?b:[]).map(K=>K.rangeWithCoord);V?H.push(P.range):H[H.length-1]=P.range,w(H,!0)}}});return()=>{k.dispose()}}},[h,d,n,_,c,w,x]),I.useEffect(()=>{if(!d)return;const k=f.textSelection$.subscribe(O=>{O.unitId===d.getEditorId()&&$t({unitId:o,subUnitId:r,refSelections:s.current,editor:d,refSelectionsService:U,refSelectionsRenderService:x,sheetSkeletonManagerService:W,themeService:u,univerInstanceService:S,currentWorkbook:v})});return()=>k.unsubscribe()},[f.textSelection$,d,s,x,U,W,r,u,o,S])},Pr=(e,t,n,o,r,s)=>{const i=l.useDependency(a.ICommandService),c=l.useDependency(J.IEditorService),g=l.useDependency(j.IRenderManagerService).getRenderById(t),p=l.useDependency(a.IUniverInstanceService),S=g==null?void 0:g.with(F.RefSelectionsRenderService);I.useEffect(()=>{if(e&&S)if(n){const h=()=>{const _=S.getSelectionControls().length;for(let m=1;m<=_;m++)S.clearLastSelection();return setTimeout(()=>{s()},30)},f=i.onCommandExecuted(_=>{_.id===L.SetWorksheetActiveOperation.id&&h()}),u=p.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(_=>{h()});return()=>{f.dispose(),u.unsubscribe()}}else{const h=i.beforeCommandExecuted(f=>{if(f.id===L.SetWorksheetActiveOperation.id){o(!1),r(),s();const u=c.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);u==null||u.focus()}});return()=>{h.dispose()}}},[e,S])},Lr=(e,t,n)=>{const o=l.useDependency(R.LexerTreeBuilder),r=I.useRef(!0);I.useEffect(()=>{if(e){const s=setTimeout(()=>{r.current=!1},500);return()=>{clearTimeout(s)}}},[e]),I.useEffect(()=>{if(!r.current&&t){const s=o.checkIfAddBracket(n);t(s===0&&n.startsWith(R.operatorToken.EQUALS),`${n}`)}},[n,t])},$r=(e,t=[],n)=>{const o=l.useDependency(ve.IDescriptionService),[r,s]=I.useState([]),[i,c]=I.useState(""),d=I.useRef(-1),g=Te({nodes:t}),p=()=>{s([]),c(""),d.current=-1};return I.useEffect(()=>{if(n&&e){const h=n.input$.pipe(q.debounceTime(300)).subscribe(()=>{const f=n.getSelectionRanges();if(f.length===1){const u=g.current.nodes,_=f[0];if(_.collapsed){const m=at(u,_.startOffset-1,!1);d.current=m;const C=u[m];if(C&&typeof C!="string"&&C.nodeType===R.sequenceNodeType.FUNCTION){d.current=m;const E=C.token,T=o.getSearchListByNameFirstLetter(E);s(T),c(E);return}}}d.current=-1,c(""),s(u=>u!=null&&u.length?[]:u)});return()=>{h.unsubscribe()}}},[n,e]),I.useEffect(()=>{e||p()},[e]),{searchList:r,searchText:i,handlerFormulaReplace:(h,f)=>{const u=[...g.current.nodes];if(d.current!==-1){const _=u.splice(d.current+1),m=u.pop()||"";let C=(typeof m=="string"?m.length:m.token.length)-h.length;return u.push(h),_[0]!==R.matchToken.OPEN_BRACKET&&f!==R.FunctionType.DefinedName&&(u.push(R.matchToken.OPEN_BRACKET),C--),{text:ut([...u,..._]),offset:C}}},reset:p}},Fr=()=>{},Wr=I.forwardRef(Ur);function Ur(e,t){const{isFocus:n,sequenceNodes:o,onSelect:r,editor:s,onClose:i=Fr}=e,c=s.getEditorId(),d=l.useDependency(l.IShortcutService),g=l.useDependency(a.ICommandService),{searchList:p,searchText:S,handlerFormulaReplace:h,reset:f}=$r(n,o,s),u=I.useMemo(()=>!!p.length,[p]),_=I.useRef(void 0),[m,C]=I.useState(0),E=I.useRef(!1),[T]=Pt(c,u,[S,p]),N=Te({searchList:p,active:m}),v=(w,$)=>{const k=h(w,$);k&&(f(),r(k))};function M(w){E.current&&C(w)}function x(){E.current&&C(-1)}I.useEffect(()=>{if(!p.length)return;const w=`sheet.formula-embedding-editor.search_function.${c}`,$=new a.DisposableCollection,k=O=>{const{searchList:A,active:b}=N.current;switch(O){case l.KeyCode.ARROW_UP:{C(P=>{const V=Math.max(0,P-1);return W(V),V});break}case l.KeyCode.ARROW_DOWN:{C(P=>{const V=Math.min(A.length-1,P+1);return W(V),V});break}case l.KeyCode.TAB:case l.KeyCode.ENTER:{const P=A[b];v(P.name,P.functionType);break}case l.KeyCode.ESC:{f(),i();break}}};return $.add(g.registerCommand({id:w,type:a.CommandType.OPERATION,handler(O,A){const{keyCode:b}=A;k(b)}})),[l.KeyCode.ARROW_UP,l.KeyCode.ARROW_DOWN,l.KeyCode.ENTER,l.KeyCode.ESC,l.KeyCode.TAB].map(O=>({id:w,binding:O,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keyCode:O}})).forEach(O=>{$.add(d.registerShortcut(O))}),()=>{$.dispose()}},[p]);function W(w){const $=_.current;if(!$)return;const k=$.children[w];if(!k)return;const A=$.getBoundingClientRect().top,b=$.offsetHeight,P=k.getBoundingClientRect(),V=P.top,H=P.height;if(V>=0&&V>A&&V-A+H<=b)return;const K=k.offsetTop-(b-H)/2;$.scrollTo({top:K,behavior:"smooth"})}const U=I.useMemo(()=>{let w="";return()=>{clearTimeout(w),E.current=!0,w=setTimeout(()=>{E.current=!1},300)}},[]);return p.length>0&&u&&y.jsx(l.RectPopup,{portal:!0,anchorRect$:T,direction:"vertical",children:y.jsx("ul",{ref:w=>{_.current=w,t&&(t.current=w)},"data-u-comp":"sheets-formula-editor",className:B.clsx("univer-m-0 univer-box-border univer-max-h-[400px] univer-w-[250px] univer-list-none univer-overflow-y-auto univer-rounded-lg univer-bg-white univer-p-2 univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",B.borderClassName,B.scrollbarClassName),children:p.map((w,$)=>y.jsxs("li",{className:B.clsx("univer-box-border univer-cursor-pointer univer-rounded univer-px-2 univer-py-1 univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200 dark:!univer-bg-gray-600":m===$}),onMouseEnter:()=>M($),onMouseLeave:x,onMouseMove:U,onClick:()=>{v(w.name,w.functionType),s&&s.focus()},children:[y.jsxs("span",{className:"univer-block univer-truncate univer-text-xs",children:[y.jsx("span",{className:"univer-text-red-500",children:w.name.substring(0,S.length)}),y.jsx("span",{children:w.name.slice(S.length)})]}),y.jsx("span",{className:"univer-block univer-text-xs univer-text-gray-400",children:w.desc})]},w.name))})})}const Vr=e=>e.startsWith(R.operatorToken.EQUALS)?e.slice(1):"",Wt=()=>{},Ut=I.forwardRef((e,t)=>{var jt,qt,Yt,zt;const{errorText:n,initValue:o,unitId:r,subUnitId:s,isFocus:i=!0,isSupportAcrossSheet:c=!1,onFocus:d=Wt,onBlur:g=Wt,onChange:p,onVerify:S,className:h,editorId:f,moveCursor:u=!0,onFormulaSelectingChange:_,keyboardEventConfig:m,onMoveInEditor:C,resetSelectionOnBlur:E=!0,autoScrollbar:T=!0,isSingle:N=!0,disableSelectionOnClick:v=!1,autofocus:M=!0,disableContextMenu:x,style:W}=e,U=l.useDependency(J.IEditorService),w=I.useRef(null),$=l.useEvent(p);I.useImperativeHandle(t,()=>({isClickOutSide:X=>w.current?!w.current.contains(X.target):!1}));const k=l.useEvent(_),O=I.useRef(null),A=I.useRef(void 0),b=A.current,[P,V]=I.useState(i),H=I.useRef(null),K=I.useMemo(()=>f!=null?f:a.createInternalEditorID(`${D.EMBEDDING_FORMULA_EDITOR}-${a.generateRandomId(4)}`),[]),oe=I.useMemo(()=>n!==void 0,[n]),se=l.useDependency(a.IUniverInstanceService),ae=se.getUnit(K);l.useObservable(ae==null?void 0:ae.change$);const z=yr(),ee=a.BuildTextUtils.transform.getPlainText((qt=(jt=ae==null?void 0:ae.getBody())==null?void 0:jt.dataStream)!=null?qt:""),ke=Te(ee),we=I.useMemo(()=>Vr(ee),[ee]),Xe=I.useMemo(()=>z(we),[we,z]),{isSelecting:fe,isSelectingRef:G}=Er({unitId:r,subUnitId:s,editorId:K,isFocus:P,disableOnClick:v}),Q=I.useRef(""),le=l.useDependency(j.IRenderManagerService).getRenderById(K),te=le==null?void 0:le.with(J.DocSelectionRenderService),ie=te==null?void 0:te.isFocusing,ge=I.useMemo(()=>se.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC),[se]),be=l.useObservable(ge),me=(be==null?void 0:be.getUnitId())===K,Z=I.useRef([]),ue=fe,Me=(zt=(Yt=l.useDependency(a.IConfigService).getConfig(_t))==null?void 0:Yt.functionScreenTips)!=null?zt:!0;l.useUpdateEffect(()=>{$(ee)},[ee,$]);const Oe=Ft("="),Ne=Tr(r,s),ne=l.useEvent((X,re=!0,Ce,pe)=>{if(!A.current)return;Q.current=X;const et=X[0]==="="?X.slice(1):"",_e=z(et),eo=_e.reduce((De,nt)=>typeof nt=="object"?`${De}${nt.token}`:`${De}${nt}`,""),tt=Oe(A.current,eo===et?_e:[],re,pe);if(Z.current=tt,Ce){const De=pe!=null?pe:b==null?void 0:b.getSelectionRanges();if((De==null?void 0:De.length)!==1)return;const to=De[0].startOffset-1,no=at(_e,to,!1),Gt=At(_e,no);if(Gt>=0){const Zt=tt.splice(Gt,1)[0];Zt&&tt.push(Zt)}Ne(P?tt:[],A.current)}});I.useEffect(()=>{P&&ne(ee,!1,!0)},[P]),I.useEffect(()=>{if(P){if(Q.current===ee)return;ne(ee,!1,!0)}},[ee]),Lr(P,S,ee);const Se=_r(b),Qe=Dr(P,r,s);I.useEffect(()=>{var X;k(fe,(X=te==null?void 0:te.isFocusing)!=null?X:!0)},[k,fe]),J.useKeyboardEvent(P,m,b),I.useLayoutEffect(()=>{let X;if(H.current){X=U.register({autofocus:M,editorUnitId:K,initialSnapshot:{id:K,body:{dataStream:`${o}\r
|
|
5
5
|
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},H.current);const re=U.getEditor(K);A.current=re,ne(o,!1,!0)}return()=>{X==null||X.dispose()}},[]),I.useLayoutEffect(()=>{i?(V(i),Se()):(E&&(b==null||b.blur(),Qe()),V(i))},[i,b,Se,Qe,E]);const{checkScrollBar:Je}=J.useResize(b,N,T);Nr(P,!!(fe&&me),r,K,x),Or(!!(P&&ie&&u),ue,b,C);const Ht=l.useEvent((X,re,Ce)=>{if(!ie)return;const pe=re!==-1?[{startOffset:re+1,endOffset:re+1,collapsed:!0}]:void 0;ne(`=${X}`,!0,Ce,pe),Ce&&(Se(),re!==-1&&setTimeout(()=>{const et={startOffset:re+1,endOffset:re+1},_e=b==null?void 0:b.render.with(J.DocBackScrollRenderController);_e==null||_e.scrollToRange({...et,collapsed:!0})},50),Je())});Ar(P&&!!(fe&&me),P,G,r,s,Z,c,!!ue,b,Ht),Pr(P&&!!(fe&&me),r,c,V,g,()=>{ne(ke.current,!1,!0)});const Kt=X=>{if(X){const re=b==null?void 0:b.getSelectionRanges();if(re&&re.length===1){const Ce=re[0];if(Ce.collapsed){const pe=X.offset;setTimeout(()=>{b==null||b.setSelectionRanges([{startOffset:Ce.startOffset-pe,endOffset:Ce.endOffset-pe}])},30)}}Se(),ne(`=${X.text}`)}},Jr=()=>{V(!0),d(),Se()};return y.jsxs("div",{className:h,children:[y.jsx("div",{ref:w,className:B.clsx("univer-relative univer-box-border univer-flex univer-h-full univer-w-full univer-items-center univer-justify-around univer-gap-2 univer-rounded-none univer-p-0 univer-ring-1",{"univer-ring-primary-500":P,"univer-ring-red-500":oe}),children:y.jsx("div",{ref:H,className:"univer-relative univer-h-full univer-w-full",onMouseUp:Jr})}),n!==void 0&&y.jsx("div",{className:"univer-my-1 univer-text-xs univer-text-red-500",children:n}),Me&&b&&we!==""&&y.jsx(Cr,{editor:b,isFocus:P,formulaText:ee,onClose:()=>Se()}),Me&&!!b&&y.jsx(Wr,{isFocus:P,sequenceNodes:Xe,onSelect:Kt,ref:O,editor:b})]})});function Br(e,t,n,o){const r=l.useDependency(R.LexerTreeBuilder),s=Ft(""),i=l.useObservable(e==null?void 0:e.getDocumentDataModel().change$),[c,d]=I.useState([]),g=l.useDependency(D.IMarkSelectionService),p=I.useRef(""),S=l.useDependency(a.IUniverInstanceService);return I.useEffect(()=>{if(!e)return;const h=e.getDocumentDataModel().getPlainText();if(p.current===h)return;p.current=h;const f=r.sequenceNodesBuilder(h);d(f!=null?f:[])},[i,e,r]),I.useEffect(()=>{var u,_;if(!e)return;if(!t){const m=e.getDocumentData();e.setDocumentData({...m,body:{...m.body,dataStream:(_=(u=m.body)==null?void 0:u.dataStream)!=null?_:"",textRuns:[]}});return}const h=s(e,c,!1),f=new a.DisposableCollection;return h.forEach(m=>{const C=R.deserializeRangeWithSheet(m.token),E=S.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),T=E==null?void 0:E.getActiveSheet();if(!C.sheetName&&o!==(T==null?void 0:T.getSheetId())||C.sheetName&&(T==null?void 0:T.getName())!==C.sheetName)return;const N=new a.ColorKit(m.themeColor).toRgb(),v=g.addShape({range:C.range,style:{stroke:m.themeColor,fill:`rgba(${N.r}, ${N.g}, ${N.b}, 0.1)`,strokeDash:12},primary:null});v&&f.add(()=>g.removeShape(v))}),()=>{f.dispose()}},[e,t,s,g,c]),{sequenceNodes:c}}function Hr(e){const t=l.useDependency(L.SheetsSelectionsService),{supportAcrossSheet:n=!1,keepSheetReference:o=!1,unitId:r,subUnitId:s,onChange:i}=e,d=l.useDependency(a.IUniverInstanceService).getUnit(r,a.UniverInstanceType.UNIVER_SHEET),g=l.useEvent(i),p=l.useEvent((S,h)=>{const f=d==null?void 0:d.getActiveSheet();if(!f||!n&&f.getSheetId()!==s||!(S!=null&&S.length))return;const u=o?f.getName():f.getSheetId()===s?"":f.getName(),_=S.map(m=>({range:m.range,unitId:r,sheetName:u}));g(_,h)});I.useEffect(()=>{const S=new a.DisposableCollection;return S.add(t.selectionMoveStart$.subscribe(h=>{p(h,!0)})),S.add(t.selectionMoving$.subscribe(h=>{p(h,!1)})),S.add(t.selectionMoveEnd$.subscribe(h=>{p(h,!1)})),()=>{S.dispose()}},[p,t.selectionMoveEnd$,t.selectionMoveStart$,t.selectionMoving$])}const Vt=e=>!e.some(n=>{if(typeof n=="string"){if(n!==R.matchToken.COMMA)return!0}else if(n.nodeType!==R.sequenceNodeType.REFERENCE)return!0;return!1}),Kr=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 jr(e){const{visible:t,initialValue:n,unitId:o,subUnitId:r,maxRangeCount:s=1/0,supportAcrossSheet:i,keepSheetReference:c,onConfirm:d,onClose:g,onShowBySelection:p}=e,S=l.useDependency(a.LocaleService),h=l.useDependency(R.LexerTreeBuilder),[f,u]=I.useState([]),[_,m]=I.useState(0),C=I.useRef(null);I.useEffect(()=>{if(t&&n.length){const v=n.map(M=>M.sheetName?R.serializeRangeWithSheet(M.sheetName,M.range):R.serializeRange(M.range));u(v),m(v.length-1)}else u([""]),m(0)},[t]);const E=(v,M)=>{const x=[...f];x[v]=M,u(x)},T=()=>{u([...f,""]),m(f.length)},N=v=>{f.splice(v,1),u([...f])};return Hr({unitId:o,subUnitId:r,supportAcrossSheet:i,keepSheetReference:c,onChange:(v,M)=>{if(!t&&p!=null&&p(v))return;const x=new Set(f),W=v.map($=>$.sheetName?R.serializeRangeWithSheet($.sheetName,$.range):R.serializeRange($.range)),U=W.filter($=>!x.has($));if(!U.length)return;const w=[...f];if(W.length>1){M||w.splice(_,1),w.push(...U);const $=w.slice(0,s);u($),m($.length-1),requestAnimationFrame(()=>{var k;(k=C.current)==null||k.scrollTo({top:C.current.scrollHeight})})}else{w.splice(_,1,...U);const $=w.slice(0,s);u($),m(_+U.length-1)}}}),y.jsx(B.Dialog,{width:"328px",open:t,title:S.t("rangeSelector.title"),draggable:!0,mask:!1,maskClosable:!1,footer:y.jsxs("footer",{className:"univer-flex univer-gap-2",children:[y.jsx(B.Button,{onClick:g,children:S.t("rangeSelector.cancel")}),y.jsx(B.Button,{variant:"primary",onClick:()=>{d(f.filter(v=>{const M=h.sequenceNodesBuilder(v);return M&&M.length===1&&typeof M[0]!="string"&&M[0].nodeType===R.sequenceNodeType.REFERENCE}).map(v=>R.deserializeRangeWithSheet(v)).map(v=>({...v,range:Kr(v.range)})))},children:S.t("rangeSelector.confirm")})]}),onClose:g,children:y.jsxs("div",{ref:C,className:B.clsx("-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6",B.scrollbarClassName),children:[f.map((v,M)=>y.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-gap-4",children:[y.jsx(B.Input,{className:B.clsx("univer-w-full",{"univer-border-primary-600":_===M}),placeholder:S.t("rangeSelector.placeHolder"),onFocus:()=>m(M),value:v,onChange:x=>E(M,x)}),f.length>1&&y.jsx(Dt,{className:"univer-cursor-pointer",onClick:()=>N(M)})]},M)),f.length<s&&y.jsx("div",{children:y.jsxs(B.Button,{variant:"link",onClick:T,children:[y.jsx(xt,{}),y.jsx("span",{children:S.t("rangeSelector.addAnotherRange")})]})})]})})}function qr(e){return e.split(R.matchToken.COMMA).filter(t=>!!t).map(t=>R.deserializeRangeWithSheet(t))}function Yr(e){return e.map(t=>t.sheetName?R.serializeRangeWithSheet(t.sheetName,t.range):R.serializeRange(t.range)).join(R.matchToken.COMMA)}function dt(e){const[t,n]=I.useState(null),{onVerify:o,selectorRef:r,unitId:s,subUnitId:i,maxRangeCount:c,supportAcrossSheet:d,keepSheetReference:g,autoFocus:p,onChange:S,onRangeSelectorDialogVisibleChange:h,onClickOutside:f,onFocusChange:u,forceShowDialogWhenSelectionChanged:_,hideEditor:m,resetRange:C}=e,[E,T]=I.useState(p!=null?p:!1),[N,v]=I.useState(!1),[M,x]=I.useState([]),W=l.useDependency(a.LocaleService),U=l.useDependency(J.IEditorService),{sequenceNodes:w}=Br(t,E,s,i),$=Te(w),k=l.useDependency(a.ICommandService),O=l.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),U.blur()}),A=l.useEvent(()=>{var b;O(),x(qr((b=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?b:"")),v(!0)});return I.useEffect(()=>{r&&(r.current={get editor(){return t},focus(){U.focus(t.getEditorId())},blur:O,verify:()=>Vt($.current),showDialog:b=>{O(),x(b),v(!0)},hideDialog:()=>{x([]),v(!1)},getValue:()=>{var b;return(b=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?b:""}})},[O,t,U,r,$]),I.useEffect(()=>{var b;o==null||o(Vt(w),(b=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?b:"")},[w]),I.useEffect(()=>{h==null||h(N)},[N]),I.useEffect(()=>{if(N&&C)return()=>{const b={unitId:s,subUnitId:i,selections:C};k.executeCommand(L.SetSelectionsOperation.id,b)}},[N]),y.jsxs(y.Fragment,{children:[m?null:y.jsx(J.RichTextEditor,{isSingle:!0,...e,onFocusChange:(b,P)=>{T(b),u==null||u(b,P)},editorRef:n,onClickOutside:()=>{T(!1),O(),f==null||f()},icon:y.jsx(B.Tooltip,{title:W.t("rangeSelector.buttonTooltip"),placement:"bottom",children:y.jsx(wt,{className:"univer-cursor-pointer dark:!univer-text-gray-300",onClick:A})})}),y.jsx(jr,{initialValue:M,unitId:s,subUnitId:i,visible:N,maxRangeCount:c,onConfirm:b=>{const P=Yr(b),V=a.RichTextBuilder.newEmptyData();V.body.dataStream=P,t==null||t.replaceText(P,!1),S==null||S(V,P),v(!1),x([]),requestAnimationFrame(()=>{O()})},onClose:()=>{v(!1),x([])},supportAcrossSheet:d,keepSheetReference:g,onShowBySelection:b=>E||_?(x(b),v(!0),!1):!0})]})}const zr=()=>{var o,r;const e=l.useDependency(ct),t=l.useObservable(e.currentSelector$),n=I.useRef(null);return I.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]),y.jsx(dt,{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=>R.deserializeRangeWithSheet(d)))!=null?c:[])}})};var Gr=Object.defineProperty,Zr=Object.getOwnPropertyDescriptor,Xr=(e,t,n)=>t in e?Gr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qr=(e,t,n,o)=>{for(var r=o>1?void 0:o?Zr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Ze=(e,t)=>(n,o)=>t(n,o,e),Bt=(e,t,n)=>Xr(e,typeof t!="symbol"?t+"":t,n);F.UniverSheetsFormulaUIPlugin=class extends a.Plugin{constructor(t=It,n,o,r,s){super(),this._config=t,this._injector=n,this._renderManagerService=o,this._configService=r,this._uiPartsService=s;const{menu:i,...c}=a.merge(It,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(_t,c,{merge:!0})}onStarting(){a.registerDependencies(this._injector,[[Ue,{useClass:rt}],[ct],[ze],[He],[Ke],[je],[qe],[F.FormulaReorderController]]),this._initUIPart()}onReady(){[[F.RefSelectionsRenderService]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,t))})}onRendered(){[[it]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,t))}),a.touchDependencies(this._injector,[[ze],[Ke],[qe]])}onSteady(){this._injector.get(He),this._injector.get(F.FormulaReorderController)}_initUIPart(){const t=this._injector.get(l.ComponentManager);this.disposeWithMe(t.register(D.RANGE_SELECTOR_COMPONENT_KEY,dt)),this.disposeWithMe(t.register(D.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,Ut)),this.disposeWithMe(this._uiPartsService.registerComponent(l.BuiltInUIPart.GLOBAL,()=>l.connectInjector(zr,this._injector)))}},Bt(F.UniverSheetsFormulaUIPlugin,"pluginName",vt),Bt(F.UniverSheetsFormulaUIPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),F.UniverSheetsFormulaUIPlugin=Qr([a.DependentOn(R.UniverFormulaEnginePlugin,ve.UniverSheetsFormulaPlugin),Ze(1,a.Inject(a.Injector)),Ze(2,j.IRenderManagerService),Ze(3,a.IConfigService),Ze(4,l.IUIPartsService)],F.UniverSheetsFormulaUIPlugin),F.FORMULA_PROMPT_ACTIVATED=ht,F.FormulaEditor=Ut,F.GlobalRangeSelectorService=ct,F.HelpFunctionOperation=gt,F.InsertFunctionOperation=ce,F.MoreFunctionsOperation=Ve,F.RangeSelector=dt,F.ReferenceAbsoluteOperation=ot,F.SearchFunctionOperation=Ct,F.SelectEditorFormulaOperation=Ie,F.SheetOnlyPasteFormulaCommand=We,Object.defineProperty(F,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-formula-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "DreamNum <developer@univer.ai>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -64,16 +64,16 @@
|
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@univerjs/icons": "^1.0.2",
|
|
67
|
-
"@univerjs/
|
|
68
|
-
"@univerjs/
|
|
69
|
-
"@univerjs/docs-ui": "0.
|
|
70
|
-
"@univerjs/engine-render": "0.
|
|
71
|
-
"@univerjs/
|
|
72
|
-
"@univerjs/sheets": "0.
|
|
73
|
-
"@univerjs/
|
|
74
|
-
"@univerjs/
|
|
75
|
-
"@univerjs/
|
|
76
|
-
"@univerjs/
|
|
67
|
+
"@univerjs/design": "0.11.0",
|
|
68
|
+
"@univerjs/docs": "0.11.0",
|
|
69
|
+
"@univerjs/docs-ui": "0.11.0",
|
|
70
|
+
"@univerjs/engine-render": "0.11.0",
|
|
71
|
+
"@univerjs/sheets": "0.11.0",
|
|
72
|
+
"@univerjs/sheets-formula": "0.11.0",
|
|
73
|
+
"@univerjs/sheets-ui": "0.11.0",
|
|
74
|
+
"@univerjs/engine-formula": "0.11.0",
|
|
75
|
+
"@univerjs/core": "0.11.0",
|
|
76
|
+
"@univerjs/ui": "0.11.0"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"postcss": "^8.5.6",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"typescript": "^5.9.3",
|
|
84
84
|
"vite": "^7.1.12",
|
|
85
85
|
"vitest": "^3.2.4",
|
|
86
|
-
"@univerjs-infra/shared": "0.
|
|
86
|
+
"@univerjs-infra/shared": "0.11.0"
|
|
87
87
|
},
|
|
88
88
|
"scripts": {
|
|
89
89
|
"test": "vitest run",
|