@univerjs/sheets-formula-ui 0.16.1 → 0.17.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 +5 -5
- package/lib/cjs/locale/ca-ES.js +1 -1
- package/lib/cjs/locale/en-US.js +1 -1
- package/lib/cjs/locale/es-ES.js +1 -1
- package/lib/cjs/locale/fa-IR.js +1 -1
- package/lib/cjs/locale/fr-FR.js +1 -1
- package/lib/cjs/locale/ja-JP.js +1 -1
- package/lib/cjs/locale/ko-KR.js +1 -1
- package/lib/cjs/locale/ru-RU.js +1 -1
- package/lib/cjs/locale/sk-SK.js +1 -1
- package/lib/cjs/locale/vi-VN.js +1 -1
- package/lib/cjs/locale/zh-CN.js +1 -1
- package/lib/cjs/locale/zh-TW.js +1 -1
- package/lib/es/index.js +1518 -1559
- package/lib/es/locale/ca-ES.js +1 -6
- package/lib/es/locale/en-US.js +1 -6
- package/lib/es/locale/es-ES.js +1 -6
- package/lib/es/locale/fa-IR.js +1 -6
- package/lib/es/locale/fr-FR.js +1 -6
- package/lib/es/locale/ja-JP.js +1 -6
- package/lib/es/locale/ko-KR.js +1 -6
- package/lib/es/locale/ru-RU.js +1 -6
- package/lib/es/locale/sk-SK.js +1 -6
- package/lib/es/locale/vi-VN.js +1 -6
- package/lib/es/locale/zh-CN.js +1 -6
- package/lib/es/locale/zh-TW.js +1 -6
- package/lib/index.js +1518 -1559
- package/lib/locale/ca-ES.js +1 -6
- package/lib/locale/en-US.js +1 -6
- package/lib/locale/es-ES.js +1 -6
- package/lib/locale/fa-IR.js +1 -6
- package/lib/locale/fr-FR.js +1 -6
- package/lib/locale/ja-JP.js +1 -6
- package/lib/locale/ko-KR.js +1 -6
- package/lib/locale/ru-RU.js +1 -6
- package/lib/locale/sk-SK.js +1 -6
- package/lib/locale/vi-VN.js +1 -6
- package/lib/locale/zh-CN.js +1 -6
- package/lib/locale/zh-TW.js +1 -6
- package/lib/types/index.d.ts +1 -1
- package/lib/types/locale/en-US.d.ts +1 -6
- package/lib/types/menu/menu.d.ts +16 -0
- package/lib/types/plugin.d.ts +3 -1
- package/lib/umd/index.js +5 -5
- package/lib/umd/locale/ca-ES.js +1 -1
- package/lib/umd/locale/en-US.js +1 -1
- package/lib/umd/locale/es-ES.js +1 -1
- package/lib/umd/locale/fa-IR.js +1 -1
- package/lib/umd/locale/fr-FR.js +1 -1
- package/lib/umd/locale/ja-JP.js +1 -1
- package/lib/umd/locale/ko-KR.js +1 -1
- package/lib/umd/locale/ru-RU.js +1 -1
- package/lib/umd/locale/sk-SK.js +1 -1
- package/lib/umd/locale/vi-VN.js +1 -1
- package/lib/umd/locale/zh-CN.js +1 -1
- package/lib/umd/locale/zh-TW.js +1 -1
- package/package.json +13 -13
- package/lib/types/controllers/formula-auto-fill.controller.d.ts +0 -10
- package/lib/types/controllers/menu.d.ts +0 -12
- /package/lib/types/{controllers/config.schema.d.ts → config/config.d.ts} +0 -0
- /package/lib/types/{controllers/menu.schema.d.ts → menu/schema.d.ts} +0 -0
package/lib/umd/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
(function(L,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):(L=typeof globalThis<"u"?globalThis:L||self,a(L.UniverSheetsFormulaUi={},L.UniverCore,L.UniverSheetsUi,L.UniverEngineFormula,L.rxjs,L.UniverDocsUi,L.UniverEngineRender,L.UniverSheets,L.UniverSheetsFormula,L.UniverUi,L.React,L.React,L.UniverDesign,L.UniverDocs,L.rxjs.operators))})(this,(function(L,a,D,T,Q,J,j,A,he,l,R,I,B,pt,tn){"use strict";var ao=Object.defineProperty;var lo=(L,a,D)=>a in L?ao(L,a,{enumerable:!0,configurable:!0,writable:!0,value:D}):L[a]=D;var q=(L,a,D)=>lo(L,typeof a!="symbol"?a+"":a,D);const We={id:"sheet.command.copy-formula-only",type:a.CommandType.COMMAND,handler:async e=>e.get(D.ISheetClipboardService).copy({copyHookType:D.PREDEFINED_HOOK_NAME_COPY.SPECIAL_COPY_FORMULA_ONLY})},Ue={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_PASTE.SPECIAL_PASTE_FORMULA})},Ee={id:"formula-ui.operation.select-editor-formula",type:a.CommandType.OPERATION,handler:(e,t)=>!0};var nn=Object.getOwnPropertyDescriptor,rn=(e,t,n,o)=>{for(var r=o>1?void 0:o?nn(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},on=(e,t)=>(n,o)=>t(n,o,e);const vt="FORMULA_PROMPT_ACTIVATED",Ve=a.createIdentifier("formula-ui.prompt-service");let st=class{constructor(e){q(this,"_search$",new Q.Subject);q(this,"_help$",new Q.Subject);q(this,"_navigate$",new Q.Subject);q(this,"_accept$",new Q.Subject);q(this,"_acceptFormulaName$",new Q.Subject);q(this,"search$",this._search$.asObservable());q(this,"help$",this._help$.asObservable());q(this,"navigate$",this._navigate$.asObservable());q(this,"accept$",this._accept$.asObservable());q(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());q(this,"_searching",!1);q(this,"_helping",!1);q(this,"_sequenceNodes",[]);q(this,"_isLockedOnSelectionChangeRefString",!1);q(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(vt,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!==T.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:T.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}};st=rn([on(0,a.IContextService)],st);const mt={id:"formula-ui.operation.help-function",type:a.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ve).help(t),!0)},ce={id:"formula-ui.operation.insert-function",type:a.CommandType.OPERATION,handler:async(e,t)=>{var _,b;const n=e.get(A.SheetsSelectionsService),o=e.get(J.IEditorService),r=n.getCurrentSelections();if(!r||!r.length)return!1;const s=A.getSheetCommandTarget(e.get(a.IUniverInstanceService));if(!s)return!1;const{worksheet:i,unitId:c,subUnitId:d}=s,f=i.getCellMatrix(),{value:g}=t,p=e.get(a.ICommandService);e.get(D.IEditorBridgeService);const h=[],S=[];let u=null,v=0,E=0,C="";if(r.length===1&&(an(r[0].range)||ln(r[0].range)&&_t(f,r[0].range))){const{range:N,primary:m}=r[0],O=(_=m==null?void 0:m.actualRow)!=null?_:N.startRow,x=(b=m==null?void 0:m.actualColumn)!=null?b:N.startColumn;u=N,v=O,E=x;const U=Ct(f,O,x);U&&(C=T.serializeRange(U))}else r.some(N=>{var x,U;const{range:m,primary:O}=N;if(_t(f,m)){const W=(x=O==null?void 0:O.actualRow)!=null?x:m.startRow,P=(U=O==null?void 0:O.actualColumn)!=null?U:m.startColumn,F=Ct(f,W,P);if(!F)return u=m,v=W,E=P,!0;const w=T.serializeRange(F),$=`=${g}(${w})`;h.push({range:m,primary:{row:W,column:P},formula:$})}else{const{startRow:W,startColumn:P,endRow:F,endColumn:w}=m;if(W===F){const $=un(f,W,w,i.getColumnCount()-1),H=$===w?w-1:w,M=T.serializeRange({startRow:W,endRow:F,startColumn:P,endColumn:H}),y=`=${g}(${M})`;S.push({range:m,primary:{row:W,column:$},formula:y})}else{let $=-1;for(let M=P;M<=w;M++){const y=dn(f,M,F,i.getRowCount()-1);$=Math.max($,y)}const H=$===F?F-1:F;for(let M=P;M<=w;M++){const y=T.serializeRange({startRow:W,endRow:H,startColumn:M,endColumn:M}),k=`=${g}(${y})`;S.push({range:m,primary:{row:$,column:M},formula:k})}}}return!1});if(u){const N=A.getCellAtRowCol(v,E,i),m={range:a.Rectangle.clone(u),primary:{startRow:N.startRow,startColumn:N.startColumn,endRow:N.endRow,endColumn:N.endColumn,actualRow:v,actualColumn:E,isMerged:N.isMerged,isMergedMainCell:N.startRow===v&&N.startColumn===E}},O={unitId:c,subUnitId:d,selections:[m]};await p.executeCommand(A.SetSelectionsOperation.id,O);const x=o.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),U=o.getEditor(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);p.syncExecuteCommand(D.SetCellEditVisibleOperation.id,{visible:!0,unitId:c,eventType:j.DeviceInputEventType.Dblclick});const W=`=${g}(${C}`;x==null||x.replaceText(W),U==null||U.replaceText(W,!1)}return h.length===0&&S.length===0?!1:p.executeCommand(he.InsertFunctionCommand.id,{list:h,listOfRangeHasNumber:S})}};function Ct(e,t,n){const o=sn(e,t,n);if(o!==t)return{startRow:o,endRow:t-1,startColumn:n,endColumn:n};const r=cn(e,t,n);return r!==n?{startRow:t,endRow:t,startColumn:r,endColumn:n-1}:null}function sn(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(xe(s)&&!o){if(r===0)return 0;o=!0}else{if(o&&!xe(s))return r+1;if(o&&r===0)return 0}}return t}function cn(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(xe(s)&&!o){if(r===0)return 0;o=!0}else{if(o&&!xe(s))return r+1;if(o&&r===0)return 0}}return n}function xe(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 an(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}function ln(e){return e.startRow!==e.endRow&&e.startColumn!==e.endColumn}function _t(e,t){for(let n=t.startRow;n<=t.endRow;n++)for(let o=t.startColumn;o<=t.endColumn;o++)if(xe(e.getValue(n,o)))return!1;return!0}function un(e,t,n,o){for(let r=n;r<=o;r++)if(!e.getValue(t,r))return r;return o}function dn(e,t,n,o){for(let r=n;r<=o;r++)if(!e.getValue(r,t))return r;return o}const Et="SHEET_FORMULA_UI_PLUGIN",It=`${Et}_MORE_FUNCTIONS_COMPONENT`,He={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:It}}),!0)},it={id:"formula-ui.operation.change-ref-to-absolute",type:a.CommandType.OPERATION,handler:async e=>!0},yt={id:"formula-ui.operation.search-function",type:a.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ve).search(t),!0)};var fn=Object.getOwnPropertyDescriptor,hn=(e,t,n,o)=>{for(var r=o>1?void 0:o?fn(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);L.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===A.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),f=d==null?void 0:d.getSheetBySheetId(s);if(!f)return{redos:n,undos:o};const g=f.getCellMatrix(),p=new a.ObjectMatrix,h=new a.ObjectMatrix;let S=!1;return a.Range.foreach(i,(u,v)=>{let E=u;c.hasOwnProperty(u)&&(E=c[u]);const C=g.getValue(E,v);if(C!=null&&C.f||C!=null&&C.si){S=!0;const _=this._formulaDataModel.getFormulaStringByCell(E,v,s,r),b=this._lexerTreeBuilder.moveFormulaRefOffset(_,0,u-E),N=a.Tools.deepClone(C);N.f=b,N.si=null,p.setValue(u,v,N)}else p.setValue(u,v,C);h.setValue(u,v,g.getValue(u,v))}),S?(n.push({id:A.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:s,cellValue:p.getMatrix()}}),o.push({id:A.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:s,cellValue:h.getMatrix()}}),{redos:n,undos:o}):{redos:n,undos:o}}},L.FormulaReorderController=hn([Be(0,a.Inject(A.SheetInterceptorService)),Be(1,a.Inject(a.IUniverInstanceService)),Be(2,a.Inject(T.FormulaDataModel)),Be(3,a.Inject(T.LexerTreeBuilder))],L.FormulaReorderController);const Rt="sheets-formula-ui.base.config",Tt={};var gn=Object.getOwnPropertyDescriptor,Sn=(e,t,n,o)=>{for(var r=o>1?void 0:o?gn(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Pe=(e,t)=>(n,o)=>t(n,o,e);const ct="SHEET_FORMULA_ALERT",pn={[T.ErrorType.DIV_BY_ZERO]:"divByZero",[T.ErrorType.NAME]:"name",[T.ErrorType.VALUE]:"value",[T.ErrorType.NUM]:"num",[T.ErrorType.NA]:"na",[T.ErrorType.CYCLE]:"cycle",[T.ErrorType.REF]:"ref",[T.ErrorType.SPILL]:"spill",[T.ErrorType.CALC]:"calc",[T.ErrorType.ERROR]:"error",[T.ErrorType.CONNECT]:"connect",[T.ErrorType.NULL]:"null"};let at=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),f=(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 g=T.extractFormulaError(d,!!f);if(!g){this._hideAlert();return}const p=this._cellAlertManagerService.currentAlert.get(ct),h=(s=p==null?void 0:p.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.${pn[g]}`),location:e.location,width:200,height:74,key:ct});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(ct)}};at=Sn([Pe(1,a.Inject(D.HoverManagerService)),Pe(2,a.Inject(D.CellAlertManagerService)),Pe(3,a.Inject(a.LocaleService)),Pe(4,a.Inject(T.FormulaDataModel)),Pe(5,l.IZenZoneService)],at);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},bt=(e,t)=>(n,o)=>t(n,o,e);let Ke=class extends a.Disposable{constructor(e,t){super(),this._autoFillService=e,this._lexerTreeBuilder=t,this._registerAutoFill()}_registerAutoFill(){const e={type:A.AUTO_FILL_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===A.AUTO_FILL_DATA_TYPE.FORMULA,applyFunctions:{[A.AUTO_FILL_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 f,g;const i=_n(r),c=[],d=new Map;for(let p=1;p<=t;p++){const h=(p-1)%e.length,S=o[h],u=a.Tools.deepClone(e[h]);if(u){const v=((f=e[h])==null?void 0:f.f)||"",E=((g=e[h])==null?void 0:g.si)||"",C=a.isFormulaString(v);if(a.isFormulaId(E))u.si=E,u.f=null,u.v=null,u.p=null,u.t=null,c.push(u);else if(C){let b=d.get(h);if(b)u.si=b,u.f=null,u.v=null,u.p=null,u.t=null;else{b=a.generateRandomId(6),d.set(h,b);const{offsetX:N,offsetY:m}=Cn(i,t,n,s,S),O=this._lexerTreeBuilder.moveFormulaRefOffset(v,N,m);u.si=b,u.f=O,u.v=null,u.p=null,u.t=null}c.push(u)}}}return c}};Ke=mn([bt(0,A.IAutoFillService),bt(1,a.Inject(T.LexerTreeBuilder))],Ke);function Cn(e,t,n,o,r){const{source:s,target:i}=o,{rows:c}=i,{rows:d}=s;let f=0,g=0;switch(n){case a.Direction.UP:g=c[r]-d[r];break;case a.Direction.RIGHT:f=e;break;case a.Direction.DOWN:g=c[r]-d[r];break;case a.Direction.LEFT:f=-e*t;break}return{offsetX:f,offsetY:g}}function _n(e){let t=0;for(const n in e)e[n].forEach(o=>{t+=o.data.length});return t}var En=Object.getOwnPropertyDescriptor,In=(e,t,n,o)=>{for(var r=o>1?void 0:o?En(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 yn="default-paste-formula";let je=class extends a.Disposable{constructor(e,t,n,o,r){super(),this._univerInstanceService=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._copyFormulaOnlyHook())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteFormulaHook())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteWithFormulaHook()))}_copyFormulaOnlyHook(){const e=this;let t=null;return{id:D.PREDEFINED_HOOK_NAME_COPY.SPECIAL_COPY_FORMULA_ONLY,priority:10,onBeforeCopy(n,o){t=e._getWorksheet(n,o)},onCopyCellContent(n,o){if(!t)return"";const r=t.getCellRaw(n,o);return r?a.isFormulaString(r.f)?r.f:a.isFormulaId(r.si)&&e._formulaDataModel.getFormulaStringByCell(n,o,t.getSheetId(),t.getUnitId())||"":""},onAfterCopy(){t=null},getFilteredOutRows(n,o,r){const s=e._getWorksheet(n,o);if(!s)return[];const{startRow:i,endRow:c}=r,d=[];for(let f=i;f<=c;f++)s.getRowFiltered(f)&&d.push(f);return d},handleMatrixOnCell(n,o,r,s,i,c,d){const f=i.getValue(n,o);if(t&&f&&(a.isFormulaString(f.f)||a.isFormulaId(f.si))){const g=a.isFormulaString(f.f)?f.f:e._formulaDataModel.getFormulaStringByCell(n,o,t.getSheetId(),t.getUnitId());c.setValue(r,s,{...a.getEmptyCell(),f:g}),d.setValue(r,s,{...a.getEmptyCell(),f:g,displayV:g})}else i.setValue(n,o,a.getEmptyCell()),c.setValue(r,s,a.getEmptyCell()),d.setValue(r,s,a.getEmptyCell())}}}_pasteFormulaHook(){return{id:D.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA,priority:10,specialPasteInfo:{label:"specialPaste.formula"},onPasteCells:(e,t,n,o)=>this._onPasteCells(e,t,n,o,!0)}}_pasteWithFormulaHook(){return{id:yn,priority:10,onPasteCells:(e,t,n,o)=>this._onPasteCells(e,t,n,o,!1)}}_getWorkbook(e){return e?this._univerInstanceService.getUnit(e,a.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET)}_getWorksheet(e,t){const n=this._getWorkbook(e);return t?n==null?void 0:n.getSheetBySheetId(t):n==null?void 0:n.getActiveSheet()}_onPasteCells(e,t,n,o,r){var h;if([D.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,D.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH].includes(o.pasteType))return{undos:[],redos:[]};const i=this._getWorkbook(),c=t.unitId||(i==null?void 0:i.getUnitId()),d=t.subUnitId||((h=i==null?void 0:i.getActiveSheet())==null?void 0:h.getSheetId());if(!c||!d)return{undos:[],redos:[]};const f=t.range,g=n,p={copyType:o.copyType||D.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:o.pasteType};return this._injector.invoke(S=>Rn(c,d,f,g,S,p,this._lexerTreeBuilder,this._formulaDataModel,r,e))}};je=In([Le(0,a.IUniverInstanceService),Le(1,a.Inject(T.LexerTreeBuilder)),Le(2,D.ISheetClipboardService),Le(3,a.Inject(a.Injector)),Le(4,a.Inject(T.FormulaDataModel))],je);function Rn(e,t,n,o,r,s,i,c,d=!1,f){const g=[],p=[],h=Tn(e,t,n,o,s,i,c,f);if(!h.hasValue())return{undos:[],redos:[]};const S={unitId:e,subUnitId:t,cellValue:h.getData()};g.push({id:A.SetRangeValuesMutation.id,params:S});const u=A.SetRangeValuesUndoMutationFactory(r,S);return p.push({id:A.SetRangeValuesMutation.id,params:u}),{undos:p,redos:g}}function Tn(e,t,n,o,r,s,i,c){return c?r.pasteType===D.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE?Mn(e,t,n,o,i,c):r.pasteType===D.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA?On(e,t,n,o,s,i,c):Nn(e,t,n,o,r.copyType,s,i,c):bn(e,t,n,o,i)}function bn(e,t,n,o,r){const s=new a.ObjectMatrix,i=r.getSheetFormulaData(e,t);return o.forValue((c,d,f)=>{var S;const g=n.rows[c],p=n.cols[d],h={};a.isFormulaString(f.v)?(h.v=null,h.f=`${f.v}`,h.si=null,h.p=null,s.setValue(g,p,h)):(S=i==null?void 0:i[g])!=null&&S[p]&&(h.v=f.v,h.f=null,h.si=null,h.p=null,s.setValue(g,p,h))}),s}function Mn(e,t,n,o,r,s){var f,g;const i=new a.ObjectMatrix,c=(g=(f=r.getArrayFormulaCellData())==null?void 0:f[s.unitId])==null?void 0:g[s.subUnitId],d=r.getSheetFormulaData(e,t);return o.forValue((p,h,S)=>{var b,N;const u=s.range.rows[p%s.range.rows.length],v=s.range.cols[h%s.range.cols.length],E=n.rows[p],C=n.cols[h],_={};if(a.isFormulaString(S.f)||a.isFormulaId(S.si))_.v=S.v,_.f=null,_.si=null,_.p=null,i.setValue(E,C,_);else if((b=c==null?void 0:c[u])!=null&&b[v]){const m=c[u][v];_.v=m.v,_.f=null,_.si=null,_.p=null,i.setValue(E,C,_)}else if((N=d==null?void 0:d[E])!=null&&N[C]){if(_.v=S.v,_.f=null,_.si=null,_.p=null,S.p){const m=Mt(S);m&&(_.v=m)}i.setValue(E,C,_)}}),i}function On(e,t,n,o,r,s,i){const c=new a.ObjectMatrix,d=new Map;return o.forValue((f,g,p)=>{const h=n.rows[f],S=n.cols[g],u={};if(a.isFormulaId(p.si)){if(i.unitId!==e||i.subUnitId!==t){const v=s.getFormulaStringByCell(i.range.rows[f%i.range.rows.length],i.range.cols[g%i.range.cols.length],i.subUnitId,i.unitId),E=n.cols[g]-i.range.cols[g%i.range.cols.length],C=n.rows[f]-i.range.rows[f%i.range.rows.length],_=r.moveFormulaRefOffset(v||"",E,C);u.si=null,u.f=_}else u.si=p.si,u.f=null;u.v=null,u.p=null,c.setValue(h,S,u)}else if(a.isFormulaString(p.f)){const v=`${f%i.range.rows.length}_${g%i.range.cols.length}`;let E=d.get(v);if(E)u.si=E,u.f=null;else{E=a.generateRandomId(6),d.set(v,E);const C=n.cols[g]-i.range.cols[g%i.range.cols.length],_=n.rows[f]-i.range.rows[f%i.range.rows.length],b=r.moveFormulaRefOffset(p.f||"",C,_);u.si=E,u.f=b}u.v=null,u.p=null,c.setValue(h,S,u)}else{if(u.v=p.v,u.f=null,u.si=null,u.p=null,p.p){const v=Mt(p);v&&(u.v=v)}c.setValue(h,S,u)}}),c}function Nn(e,t,n,o,r,s,i,c){const d=new a.ObjectMatrix,f=new Map,g=i.getSheetFormulaData(e,t),p=[];return r===D.COPY_TYPE.CUT?o.forValue((h,S,u)=>{const v=n.rows[h],E=n.cols[S],C={};if(a.isFormulaId(u.si)){if(a.isFormulaString(u.f))p.push(u.si),C.f=u.f,C.si=u.si;else if(p.includes(u.si))C.f=null,C.si=u.si;else{const _=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[S%c.range.cols.length],c.subUnitId,c.unitId);C.f=_,C.si=null}C.v=null,C.p=null,d.setValue(v,E,C)}else a.isFormulaString(u.f)&&(C.f=u.f,C.si=null,C.v=null,C.p=null,d.setValue(v,E,C))}):o.forValue((h,S,u)=>{var _;const v=n.rows[h],E=n.cols[S],C={};if(a.isFormulaId(u.si)){if(c.unitId!==e||c.subUnitId!==t){const b=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[S%c.range.cols.length],c.subUnitId,c.unitId),N=n.cols[S]-c.range.cols[S%c.range.cols.length],m=n.rows[h]-c.range.rows[h%c.range.rows.length],O=s.moveFormulaRefOffset(b||"",N,m);C.si=null,C.f=O}else C.si=u.si,C.f=null;C.v=null,C.p=null,d.setValue(v,E,C)}else if(a.isFormulaString(u.f)){const b=`${h%c.range.rows.length}_${S%c.range.cols.length}`;let N=f.get(b);if(N)C.si=N,C.f=null;else{N=a.generateRandomId(6),f.set(b,N);const m=n.cols[S]-c.range.cols[S%c.range.cols.length],O=n.rows[h]-c.range.rows[h%c.range.rows.length],x=s.moveFormulaRefOffset(u.f||"",m,O);C.si=N,C.f=x}C.v=null,C.p=null,d.setValue(v,E,C)}else(_=g==null?void 0:g[v])!=null&&_[E]&&(C.v=u.v,C.f=null,C.si=null,C.p=u.p,d.setValue(v,E,C))}),p.length>0&&new a.ObjectMatrix(g).forValue((h,S,u)=>{if(!(c.range.rows.includes(h)&&c.range.cols.includes(S))&&!(n.rows.includes(h)&&n.cols.includes(S))&&p.includes(u==null?void 0:u.si)){const v=i.getFormulaStringByCell(h,S,c.subUnitId,c.unitId);d.setValue(h,S,{f:v,si:null,v:null,p:null})}}),d}function Mt(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 Dn=Object.getOwnPropertyDescriptor,kn=(e,t,n,o)=>{for(var r=o>1?void 0:o?Dn(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Ie=(e,t)=>(n,o)=>t(n,o,e);let qe=class extends a.Disposable{constructor(t,n,o,r,s,i,c,d){super();q(this,"_previousShape");q(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(A.BEFORE_CELL_EDIT,{handler:(t,n,o)=>{var u,v,E,C;const{row:r,col:s,unitId:i,subUnitId:c,worksheet:d}=n,f=this._formulaDataModel.getArrayFormulaRange(),g=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return o(t);let p=null;const h=this._formulaDataModel.getFormulaStringByCell(r,s,c,i);if(h!==null&&(p={f:h}),t.v!=null&&t.v!==""&&((E=(v=(u=g[i])==null?void 0:u[c])==null?void 0:v[r])==null?void 0:E[s])==null)return p?{...t,...p}:o(t);const S=(C=f==null?void 0:f[i])==null?void 0:C[c];return S!=null&&(p=this._displayArrayFormulaRangeShape(S,r,s,i,c,d,p)),p?{...t,...p}:o(t)}})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{(t.id===T.SetFormulaCalculationResultMutation.id||t.id===T.SetArrayFormulaDataMutation.id&&n&&n.remove)&&this._removeArrayFormulaRangeShape()})),this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{A.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){return new a.ObjectMatrix(t).forValue((d,f,g)=>{if(g==null)return!0;const{startRow:p,startColumn:h,endRow:S,endColumn:u}=g;if(d===n&&f===o)return this._createArrayFormulaRangeShape(g,r),!1;if(n>=p&&n<=S&&o>=h&&o<=u){const v=i.getCell(p,h);return(v==null?void 0:v.v)===T.ErrorType.SPILL||(v==null?void 0:v.f)==null?void 0:(c==null&&(c={f:v.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(g,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:f}=r,g=new D.SelectionControl(s,D.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:d,columnHeaderHeight:f});g.updateRangeBySelectionWithCoord(c),g.setEvent(!1),this._previousShape=g}_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:f}=o[d];if(r>=f){const g={startRow:r,endRow:s,startColumn:i,endColumn:c};this._refreshArrayFormulaRangeShape(t,g);break}}}};qe=kn([Ie(1,a.Inject(A.SheetInterceptorService)),Ie(2,a.Inject(T.FormulaDataModel)),Ie(3,a.Inject(a.ThemeService)),Ie(4,j.IRenderManagerService),Ie(5,a.Inject(D.SheetSkeletonManagerService)),Ie(6,a.ICommandService),Ie(7,a.ILogService)],qe);var wn=Object.getOwnPropertyDescriptor,An=(e,t,n,o)=>{for(var r=o>1?void 0:o?wn(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Ot=(e,t)=>(n,o)=>t(n,o,e);const xn={tl:{size:6,color:"#409f11"}};let Ye=class extends a.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(A.INTERCEPTOR_POINT.CELL_CONTENT,{effect:a.InterceptorEffectEnum.Style,handler:(n,o,r)=>{var c,d,f,g;const s=(g=(f=(d=(c=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:c[o.unitId])==null?void 0:d[o.subUnitId])==null?void 0:f[o.row])==null?void 0:g[o.col];return!T.extractFormulaError(n,!!s)||!n||(n===o.rawData&&(n={...o.rawData}),n.markers={...n==null?void 0:n.markers,...xn}),r(n)},priority:10}))}};Ye=An([Ot(0,a.Inject(A.SheetInterceptorService)),Ot(1,a.Inject(T.FormulaDataModel))],Ye);function Pn(){const e=l.useDependency(he.TriggerCalculationController),t=l.useDependency(a.ICommandService),n=l.useObservable(e.progress$),o=I.useCallback(()=>{t.executeCommand(T.SetFormulaCalculationStopMutation.id)},[t]),r=I.useCallback(()=>{e.clearProgress()},[e]);return R.jsx(l.ProgressBar,{progress:n,onTerminate:o,onClearProgress:r})}function Ln(e,t){return Object.keys(T.FunctionType).filter(n=>isNaN(Number(n))&&n!=="DefinedName"&&n!=="Table"&&(t||n!=="User")).map(n=>({label:e.t(`formula.functionType.${n.toLocaleLowerCase()}`),value:`${T.FunctionType[n]}`}))}function Nt(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 Dt(e){const{prefix:t,value:n}=e;return R.jsxs("div",{children:[R.jsxs("span",{children:[t,"("]}),n&&n.map((o,r)=>R.jsxs("span",{children:[R.jsx("span",{children:Nt(o)}),r===n.length-1?"":","]},r)),")"]})}function Fe(e){const{className:t,value:n,title:o}=e;return R.jsxs("div",{className:"univer-mb-2 univer-text-xs",children:[R.jsx("div",{className:B.clsx("univer-mb-2 univer-font-medium univer-text-gray-500 dark:!univer-text-gray-300",t),children:o}),R.jsx("div",{className:"univer-break-all univer-text-gray-900 dark:!univer-text-white",children:n})]})}function Fn(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 R.jsxs("div",{children:[R.jsx("div",{className:B.clsx("univer-h-[364px] univer-overflow-y-auto",B.scrollbarClassName),children:s.map((f,g)=>R.jsxs("div",{children:[R.jsx("div",{className:"univer-text-sm",children:f.name}),R.jsx("div",{className:"univer-mb-2 univer-mt-1"})]},g))}),R.jsx("div",{className:B.clsx("univer-flex-1 univer-p-3",B.borderLeftClassName),children:R.jsx(Fe,{title:c===-1?R.jsx(Dt,{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(`_${Un()}`);return kt(n,`${o}`,{defIds:n.defIds,idSuffix:d.current},{ref:e,className:c,...i},s)}function kt(e,t,n,o,r){return I.createElement(e.tag,{key:t,...$n(e,n,r),...o},(Wn(e,n).children||[]).map((s,i)=>kt(s,`${t}-${e.tag}-${i}`,n,void 0,r)))}function $n(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 Wn(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 Un(){return Math.random().toString(36).substring(2,8)}ye.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"}}]},wt=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"check-mark-icon",ref:n,icon:Vn}))});wt.displayName="CheckMarkIcon";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:"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"}}]},At=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"close-icon",ref:n,icon:Hn}))});At.displayName="CloseIcon";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:"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"}}]},xt=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"delete-icon",ref:n,icon:Bn}))});xt.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"}}]},Pt=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"increase-icon",ref:n,icon:Kn}))});Pt.displayName="IncreaseIcon";const jn={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"}}]},Lt=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"more-icon",ref:n,icon:jn}))});Lt.displayName="MoreIcon";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:"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"}}]},Ft=I.forwardRef(function(t,n){return I.createElement(ye,Object.assign({},t,{id:"select-range-icon",ref:n,icon:qn}))});Ft.displayName="SelectRangeIcon";function Yn(e){var M;const n=(M=l.useDependency(a.IConfigService).getConfig(he.PLUGIN_CONFIG_KEY_BASE))==null?void 0:M.function,{onChange:o}=e,r="-1",[s,i]=I.useState(""),[c,d]=I.useState([]),[f,g]=I.useState(0),[p,h]=I.useState(r),[S,u]=I.useState(0),[v,E]=I.useState(null),C=l.useDependency(he.IDescriptionService),_=l.useDependency(a.LocaleService),b=l.useDependency(l.ISidebarService),N=l.useObservable(b.sidebarOptions$),m=Ln(_,!!n).filter(y=>C.getSearchListByType(Number(y.value)).length>0);m.unshift({label:_.t("formula.moreFunctions.allFunctions"),value:r});const O=_.t("formula.prompt.required"),x=_.t("formula.prompt.optional");I.useEffect(()=>{P(r)},[]),I.useEffect(()=>{W(0)},[c]),I.useEffect(()=>{N!=null&&N.visible&&(i(""),d([]),g(0),h(r),u(0),E(null),P(r))},[N]);const U=y=>{if(s.trim()==="")return y;const k=new RegExp(`(${s.toLocaleUpperCase()})`);return y.split(k).filter(Boolean).map((K,z)=>K.match(k)?R.jsx("span",{className:"univer-text-red-500",children:K},z):K)},W=y=>{if(c.length===0){E(null),o(null);return}u(y);const k=C.getFunctionInfo(c[y].name);if(!k){E(null),o(null);return}E(k),o(k)};function P(y){h(y);const k=C.getSearchListByType(+y);d(k)}function F(y){i(y);const k=C.getSearchListByName(y);d(k)}function w(y){if(y.stopPropagation(),y.key==="ArrowDown"){const k=f+1;g(k===c.length?0:k)}else if(y.key==="ArrowUp"){const k=f-1;g(k===-1?c.length-1:k)}else y.key==="Enter"&&W(f)}const $=y=>{g(y)},H=()=>{g(-1)};return R.jsxs("div",{children:[R.jsxs("div",{className:"univer-flex univer-items-center univer-justify-between univer-gap-2",children:[R.jsx(B.Select,{value:p,options:m,onChange:P}),R.jsx(B.Input,{placeholder:_.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:w,value:s,onChange:F,size:"small",allowClear:!0})]}),c.length>0&&R.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:c.map(({name:y},k)=>R.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":f===k}),onMouseEnter:()=>$(k),onMouseLeave:H,onClick:()=>W(k),children:[S===k&&R.jsx(wt,{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"}),R.jsx("span",{className:"univer-block",children:U(y)})]},k))}),v&&R.jsxs("div",{className:B.clsx("univer-mx-0 univer-my-2 univer-overflow-y-auto",B.scrollbarClassName),children:[R.jsx(Fe,{title:v.functionName,value:v.description}),R.jsx(Fe,{title:_.t("formula.moreFunctions.syntax"),value:R.jsx(Dt,{prefix:v.functionName,value:v.functionParameter})}),R.jsx(Fe,{title:_.t("formula.prompt.helpExample"),value:`${v.functionName}(${v.functionParameter.map(y=>y.example).join(",")})`}),v.functionParameter&&v.functionParameter.map(y=>R.jsx(Fe,{title:y.name,value:`${y.require?O:x} ${y.detail}`},y.name))]})]})}function zn(){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),f=l.useDependency(a.IUniverInstanceService),g=l.useDependency(a.ICommandService);function p(){n(!t),r(!o)}function h(){const S=A.getSheetCommandTarget(f);if(!S)return;g.executeCommand(D.SetCellEditVisibleOperation.id,{visible:!0,unitId:S.unitId,eventType:j.DeviceInputEventType.Dblclick});const u=d.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),v=d.getEditor(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),E=`=${s==null?void 0:s.functionName}(`;u==null||u.replaceText(E),v==null||v.replaceText(E,!1)}return R.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&&R.jsx(Yn,{onChange:i}),o&&R.jsx(Fn,{functionInfo:s,onChange:()=>{}}),R.jsxs("div",{className:"univer-flex univer-justify-end",children:[o&&R.jsx(B.Button,{variant:"primary",onClick:p,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.next")}),o&&R.jsx(B.Button,{onClick:p,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.prev")}),t&&!!e&&R.jsx(B.Button,{disabled:!s,variant:"primary",onClick:h,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.confirm")})]})]})}function Gn(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:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function Zn(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:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function Xn(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:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function Qn(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:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function Jn(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:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function er(e){return{id:He.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:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function tr(e){return{id:We.id,type:l.MenuItemType.BUTTON,title:"formula.operation.copyFormulaOnly",disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookCopyPermission],worksheetTypes:[A.WorksheetCopyPermission],rangeTypes:[A.RangeProtectionPermissionViewPoint]}),hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET)}}function nr(e){return{id:Ue.id,type:l.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:D.menuClipboardDisabledObservable(e).pipe(Q.combineLatestWith(D.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint],worksheetTypes:[A.WorksheetSetCellValuePermission,A.WorksheetEditPermission]})),Q.map(([t,n])=>t||n)),hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET)}}const rr={[l.RibbonFormulasGroup.BASIC]:{[`${ce.id}.sum`]:{order:0,menuItemFactory:Gn},[`${ce.id}.count`]:{order:1,menuItemFactory:Zn},[`${ce.id}.average`]:{order:2,menuItemFactory:Xn},[`${ce.id}.max`]:{order:3,menuItemFactory:Qn},[`${ce.id}.min`]:{order:4,menuItemFactory:Jn}},[l.RibbonFormulasGroup.OTHERS]:{[He.id]:{order:0,menuItemFactory:er}},[D.COPY_SPECIAL_MENU_ID]:{[We.id]:{order:0,menuItemFactory:tr}},[D.PASTE_SPECIAL_MENU_ID]:{[Ue.id]:{order:4,menuItemFactory:nr}}},or="meta_key_ctrl_And_Shift";function sr(e){return e.getContextValue(a.FOCUSING_DOC)&&e.getContextValue(a.FOCUSING_UNIVER_EDITOR)}const ze=[l.KeyCode.ARROW_DOWN,l.KeyCode.ARROW_UP,l.KeyCode.ARROW_LEFT,l.KeyCode.ARROW_RIGHT],ir=[...ze,l.KeyCode.ENTER,l.KeyCode.TAB,l.KeyCode.ESC];function cr(){const e=[];for(const t of ir)e.push({id:Ee.id,binding:t,preconditions:n=>D.whenFormulaEditorActivated(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t}});return e}function ar(){const e=[];for(const t of ze)e.push({id:Ee.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 lr(){const e=[];for(const t of ze)e.push({id:Ee.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 ur(){const e=[];for(const t of ze)e.push({id:Ee.id,binding:t|l.MetaKeys.SHIFT|l.MetaKeys.CTRL_COMMAND,preconditions:n=>D.whenFormulaEditorActivated(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t,metaKey:or}});return e}const dr={id:it.id,binding:l.KeyCode.F4,preconditions:e=>D.whenFormulaEditorActivated(e)};function fr(){const e=[];for(const t of[l.KeyCode.ENTER,l.KeyCode.TAB,l.KeyCode.ARROW_DOWN,l.KeyCode.ARROW_UP])e.push({id:Ee.id,binding:t,preconditions:n=>sr(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}const hr={id:he.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 gr=Object.getOwnPropertyDescriptor,Sr=(e,t,n,o)=>{for(var r=o>1?void 0:o?gr(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 Ge=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(rr)}_registerCommands(){[We,Ue,ce,He,yt,mt,Ee,it].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...cr(),...ar(),...lr(),...ur(),...fr(),hr,dr].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(D.SheetsUIPart.FORMULA_AUX,()=>l.connectInjector(Pn,this._injector))),this._componentManager.register(It,zn)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[qe]))}};Ge=Sr([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))],Ge);var pr=Object.getOwnPropertyDescriptor,vr=(e,t,n,o)=>{for(var r=o>1?void 0:o?pr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},lt=(e,t)=>(n,o)=>t(n,o,e);let Ze=class extends a.Disposable{constructor(e,t,n){super(),this._imageFormulaCellInterceptorController=e,this._renderManagerService=t,this._univerInstanceService=n,this._imageFormulaCellInterceptorController.registerRefreshRenderFunction(()=>{const o=this._univerInstanceService.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET);if(!o)return;const r=this._renderManagerService.getRenderById(o.getUnitId());if(!r)return;r.with(D.SheetSkeletonManagerService).reCalculate();const s=r.mainComponent;s&&s.makeDirty()})}};Ze=vr([lt(0,a.Inject(he.ImageFormulaCellInterceptorController)),lt(1,j.IRenderManagerService),lt(2,a.IUniverInstanceService)],Ze);class ut{constructor(){q(this,"_currentSelector$",new Q.BehaviorSubject(null));q(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 mr=Object.getOwnPropertyDescriptor,Cr=(e,t,n,o)=>{for(var r=o>1?void 0:o?mr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},De=(e,t)=>(n,o)=>t(n,o,e);L.RefSelectionsRenderService=class extends D.BaseSelectionRenderService{constructor(n,o,r,s,i,c,d){super(o,r,s,i,c);q(this,"_workbookSelections");q(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(_r(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((f,g)=>{this.inRefSelectionMode()&&(this._onPointerDown(f,s.zIndex+1,a.RANGE_TYPE.NORMAL,this._getActiveViewport(f)),f.button!==2&&g.stopPropagation())})),d.add(o==null?void 0:o.onPointerDown$.subscribeEvent((f,g)=>{if(!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:h}=D.getCoordByOffset(f.offsetX,f.offsetY,c,p);D.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,a.RANGE_TYPE.ROW)||(this._onPointerDown(f,(s.zIndex||1)+1,a.RANGE_TYPE.ROW,this._getActiveViewport(f),j.ScrollTimerType.Y),f.button!==2&&g.stopPropagation())})),d.add(r==null?void 0:r.onPointerDown$.subscribeEvent((f,g)=>{if(!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:h}=D.getCoordByOffset(f.offsetX,f.offsetY,c,p);D.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,a.RANGE_TYPE.COLUMN)||(this._onPointerDown(f,(s.zIndex||1)+1,a.RANGE_TYPE.COLUMN,this._getActiveViewport(f),j.ScrollTimerType.X),f.button!==2&&g.stopPropagation())})),d.add(i==null?void 0:i.onPointerDown$.subscribeEvent((f,g)=>{if(this._reset(),!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,h=D.getAllSelection(p);this._addSelectionControlByModelData(h),this._selectionMoveStart$.next(this.getSelectionDataWithStyle());const S=c.onPointerUp$.subscribeEvent(()=>{S.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});f.button!==2&&g.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,A.SelectionMoveType.MOVE_START)})),this.disposeWithMe(this.selectionMoving$.subscribe(n=>{this._updateSelections(n,A.SelectionMoveType.MOVING)})),this.disposeWithMe(this.selectionMoveEnd$.subscribe(n=>{this._updateSelections(n,A.SelectionMoveType.MOVE_END)}))}_updateSelections(n,o){const s=this._context.unit.getActiveSheet().getSheetId();n.length!==0&&this._workbookSelections.setSelections(s,n.map(i=>A.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 F;this._rangeType=r;const c=this._skeleton,d=this._scene;if(!d||!c)return;s&&(this._activeViewport=s);const{offsetX:f,offsetY:g}=n,p=d.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!p)return;const h=d.getCoordRelativeToViewport(j.Vector2.FromArray([f,g])),{x:S,y:u}=h;this._startViewportPosX=S,this._startViewportPosY=u;const v=d.getScrollXYInfoByViewport(h),{scaleX:E,scaleY:C}=d.getAncestorScale(),_=this._skeleton.getCellByOffset(S,u,E,C,v);if(!_)return;switch(r){case a.RANGE_TYPE.NORMAL:break;case a.RANGE_TYPE.ROW:_.startColumn=0,_.endColumn=this._skeleton.getColumnCount()-1;break;case a.RANGE_TYPE.COLUMN:_.startRow=0,_.endRow=this._skeleton.getRowCount()-1;break;case a.RANGE_TYPE.ALL:_.startRow=0,_.startColumn=0,_.endRow=this._skeleton.getRowCount()-1,_.endColumn=this._skeleton.getColumnCount()-1}let b={range:_,primary:_,style:null};(_.isMerged||_.isMergedMainCell)&&(b={range:{..._,startRow:_.startRow,endRow:_.startRow,startColumn:_.startColumn,endColumn:_.startColumn},primary:{..._,actualRow:_.startRow,actualColumn:_.startColumn,startRow:_.startRow,endRow:_.startRow,startColumn:_.startColumn,endColumn:_.startColumn},style:null}),b.range.rangeType=r;const N=D.attachSelectionWithCoord(b,this._skeleton);this._startRangeWhenPointerDown={...N.rangeWithCoord};const m={...N.rangeWithCoord,rangeType:r};let O=this.getActiveSelectionControl();const x=this.getSelectionControls();for(const w of x){if(n.button===2&&a.Rectangle.contains(w.model,m)){O=w;return}if(w.model.isEqual(m)){O=w;break}}this._checkClearPreviousControls(n);const U=O==null?void 0:O.model.currentCell,W=n.shiftKey&&U,P=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;W&&U?this._makeSelectionByTwoCells(U,m,c,r,O):P&&O?O.updateRangeBySelectionWithCoord(N):O=this.newSelectionControl(d,c,b);for(let w=0;w<this.getSelectionControls().length-1;w++)this.getSelectionControls()[w].clearHighlight();this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),d.disableObjectsEvent(),this._clearUpdatingListeners(),this._addEndingListeners(),(F=d.getTransformer())==null||F.clearSelectedObjects(),this._setupPointerMoveListener(p,O,r,i,S,u),this._escapeShortcutDisposable=this._shortcutService.forceEscape(),this._scenePointerUpSub=d.onPointerUp$.subscribeEvent(()=>{var w;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(w=this._escapeShortcutDisposable)==null||w.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}),f=D.attachSelectionWithCoord(r,o);return d.updateRangeBySelectionWithCoord(f),this._selectionControls.push(d),d.setControlExtension({skeleton:o,scene:n,themeService:this._themeService,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),d}},L.RefSelectionsRenderService=Cr([De(1,a.Inject(a.Injector)),De(2,a.Inject(a.ThemeService)),De(3,l.IShortcutService),De(4,a.Inject(D.SheetSkeletonManagerService)),De(5,a.IContextService),De(6,A.IRefSelectionsService)],L.RefSelectionsRenderService);function _r(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 dt=(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},$t=(e,t)=>{const n=e[t];let o=-1;if(!n||typeof n=="string"||n.nodeType!==T.sequenceNodeType.REFERENCE)return-1;for(let r=0;r<=t;r++){const s=e[r];typeof s!="string"&&s.nodeType===T.sequenceNodeType.REFERENCE&&o++}return o},Er=(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 Wt(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 b;const d=o.getEditor(e);if(!d)return;const f=d.getBoundingClientRect(),{marginTop:g=0,marginBottom:p=0}=d.getDocumentData().documentStyle,h=d.getSkeleton();if(!h)return;const S=(b=h.getSkeletonData())==null?void 0:b.pages[0].height;let{left:u,top:v,right:E,bottom:C}=f;v=v+g,C=S?v+S:C-p;const _=r.getValue();if(!(_.left===u&&_.top===v&&_.right===E&&_.bottom===C))return r.next({left:u-1,right:E+1,top:v-1,bottom:C+1}),f});return I.useEffect(()=>{t&&c()},[e,o,i.unitAdded$,c,t,...n!=null?n:[]]),Er(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},Ir=(e,t,n)=>{const o=l.useDependency(Ve),r=l.useDependency(he.IDescriptionService),s=l.useDependency(T.LexerTreeBuilder),[i,c]=I.useState(),[d,f]=I.useState(-1),[g,p]=I.useState(!0),h=Te(g),S=I.useRef(t);S.current=t;const u=()=>{c(void 0),f(-1),p(!1)};return I.useEffect(()=>{const v=s.sequenceNodesBuilder(t.slice(1));o.setSequenceNodes(v!=null?v:[])},[t]),I.useEffect(()=>{if(n&&e){const v=n.selectionChange$.pipe(Q.debounceTime(50)).subscribe(C=>{if(C.textRanges.length===1){const[_]=C.textRanges;if(_.collapsed&&h.current){const{startOffset:b}=_,N=o.getCurrentSequenceNodeIndex(b-2),m=o.getCurrentSequenceNodeByIndex(N),O=o.getCurrentSequenceNodeByIndex(N+1);if(m)if(typeof m!="string"&&m.nodeType===3&&!r.hasDefinedNameDescription(m.token.trim())&&O===T.matchToken.OPEN_BRACKET){const x=r.getFunctionInfo(m.token);c(x),f(-1);return}else{const x=s.getFunctionAndParameter(`${S.current}A`,b-1);if(x){const{functionName:U,paramIndex:W}=x,P=r.getFunctionInfo(U);c(P),f(W);return}}}}c(void 0),f(-1)}),E=n.selectionChange$.pipe(Q.filter(C=>C.textRanges.length===1),Q.map(C=>C.textRanges[0].startOffset),Q.distinctUntilChanged()).subscribe(()=>{p(!0)});return()=>{v.unsubscribe(),E.unsubscribe()}}},[n,e]),I.useEffect(()=>{e||u()},[e]),{functionInfo:i,paramIndex:d,reset:u}},yr=({onClick:e})=>R.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:"?"}),ft=({className:e,title:t,value:n})=>R.jsxs("div",{className:"univer-my-2",children:[R.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}),R.jsx("div",{className:"univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",children:n})]}),Rr=e=>{const{prefix:t,value:n,active:o,onClick:r}=e;return R.jsxs("div",{children:[R.jsxs("span",{children:[t,"("]}),n&&n.map((s,i)=>R.jsxs("span",{children:[R.jsx("span",{className:o===i?"univer-text-primary-500":"",onClick:()=>r(i),children:Nt(s)}),i===n.length-1?"":","]},s.name)),")"]})},Ut=()=>{};function Tr(e){const{onParamsSwitch:t=Ut,onClose:n=Ut,isFocus:o,editor:r,formulaText:s}=e,{functionInfo:i,paramIndex:c,reset:d}=Ir(o,s,r),f=l.useDependency(D.IEditorBridgeService),g=!l.useObservable(f.helpFunctionVisible$),[p,h]=I.useState(!1),S=l.useDependency(a.LocaleService),u=S.t("formula.prompt.required"),v=S.t("formula.prompt.optional"),E=r.getEditorId(),[C]=Wt(E,!!i,[i,c]);function _(m){t&&t(m)}const b=l.useEvent(m=>{f.helpFunctionVisible$.next(!m)}),N=()=>{b(!0),n()};return i?g?R.jsx(l.RectPopup,{portal:!0,anchorRect$:C,direction:"left-center",children:R.jsx(yr,{onClick:()=>b(!1)})},"hidden"):R.jsx(l.RectPopup,{portal:!0,onClickOutside:()=>d(),anchorRect$:C,direction:"vertical",children:R.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:[R.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:[R.jsx(Rr,{prefix:i.functionName,value:i.functionParameter,active:c,onClick:_}),R.jsxs("div",{className:"univer-flex",children:[R.jsx("div",{className:"univer-ml-2 univer-flex univer-size-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:p?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>h(!p),children:R.jsx(Lt,{})}),R.jsx("div",{className:"univer-ml-2 univer-flex univer-size-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:R.jsx(At,{})})]})]}),R.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:p?"unset":0,padding:p?"revert-layer":0},children:R.jsxs("div",{className:"univer-mt-3",children:[R.jsx(ft,{title:S.t("formula.prompt.helpExample"),value:`${i.functionName}(${i.functionParameter.map(m=>m.example).join(",")})`}),R.jsx(ft,{title:S.t("formula.prompt.helpAbstract"),value:i.description}),i&&i.functionParameter&&i.functionParameter.map((m,O)=>R.jsx(ft,{className:c===O?"univer-text-primary-500":"",title:m.name,value:`${m.require?u:v} ${m.detail}`},O))]})})]})},"show"):null}const br=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
|
-
`,
|
|
3
|
-
`;let
|
|
4
|
-
`).slice(0,-2),c=(h=n.sequenceNodesBuilder(i.slice(1)))!=null?h:[],d=dt(c,s,!1),f=$t(c,d);return{nodeIndex:d,updatingRefIndex:f,sequenceNodes:c,offset:s}},Wr=(()=>{}),Ur=(e,t,n,o,r,s,i,c,d,f=Wr)=>{var F;const g=l.useDependency(j.IRenderManagerService),p=l.useDependency(a.IUniverInstanceService),h=l.useDependency(a.ICommandService),S=l.useDependency(pt.DocSelectionManagerService),u=l.useDependency(a.ThemeService),v=l.useDependency(T.LexerTreeBuilder),E=p.getUnit(o),C=l.useEvent((w,$)=>{var H,M,y;return(y=(M=(H=p.getUnit(w))==null?void 0:H.getSheetBySheetId($))==null?void 0:M.getName())!=null?y:""}),_=I.useMemo(()=>C(o,r),[C,r,o]),b=l.useObservable(E==null?void 0:E.activeSheet$),N=Te({activeSheet:b,sheetName:_}),m=l.useObservable(I.useMemo(()=>p.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[p])),O=g.getRenderById((F=m==null?void 0:m.getUnitId())!=null?F:""),x=O==null?void 0:O.with(L.RefSelectionsRenderService),U=O==null?void 0:O.with(D.SheetSkeletonManagerService),W=l.useDependency(A.IRefSelectionsService),P=l.useEvent((w,$,H)=>{var z,ne,ae,G,ee,ke,we,Je,pe,et;const M=$r({editor:d,lexerTreeBuilder:v});if(!M)return;const{nodeIndex:y,updatingRefIndex:k,sequenceNodes:V,offset:K}=M;if(n.current===Se.NEED_ADD)if(K!==0){if(y===-1&&V.length)return;const Y=w[w.length-1],te=V.splice(y+1),le=(z=Y.sheetId)!=null?z:r,re={range:Y,unitId:(ne=Y.unitId)!=null?ne:m.getUnitId(),sheetName:C((ae=Y.unitId)!=null?ae:m.getUnitId(),le)},ie=le!==r,ue=(m==null?void 0:m.getUnitId())!==o,fe=Xe([re],i&&(ie||ue),_,ue);V.push({token:fe[0],nodeType:T.sequenceNodeType.REFERENCE});const be=[...V,...te],Me=ht(be);f(Me,Fr(V),$)}else{const Y=w[w.length-1],te=(G=Y.sheetId)!=null?G:r,le={range:Y,unitId:(ee=Y.unitId)!=null?ee:m.getUnitId(),sheetName:C((ke=Y.unitId)!=null?ke:m.getUnitId(),te)},re=te!==r,ie=(m==null?void 0:m.getUnitId())!==o,ue=Xe([le],i&&(re||ie),_,ie);V.unshift({token:ue[0],nodeType:T.sequenceNodeType.REFERENCE});const fe=ht(V);f(fe,ue[0].length,$)}else if(n.current===Se.EDIT_OTHER_SHEET_REFERENCE||n.current===Se.EDIT_OTHER_WORKBOOK_REFERENCE){const Y=w.pop();if(!Y)return;const te=V[y];if(typeof te=="object"&&te.nodeType===T.sequenceNodeType.REFERENCE){const le=te.token;(m==null?void 0:m.getUnitId())!==o?te.token=T.serializeRangeWithSpreadsheet((we=m==null?void 0:m.getUnitId())!=null?we:"",_,Y):te.token=_===(b==null?void 0:b.getName())?T.serializeRange(Y):T.serializeRangeWithSheet(b.getName(),Y);const ie=K+(te.token.length-le.length);f(T.generateStringWithSequence(V),ie,$)}}else{const Y=[...w];if(!H&&k!==-1){const Z=Y.pop();Z&&Y.splice(k,0,Z)}let te=0;const le=V.map(Z=>{var ge,me,Ae,Oe;if(typeof Z=="string")return Z;if(Z.nodeType===T.sequenceNodeType.REFERENCE){const de=T.deserializeRangeWithSheet(Z.token);if(de.sheetName||(de.sheetName=_),(de.unitId||o)!==(m==null?void 0:m.getUnitId())||i&&((ge=N.current.activeSheet)==null?void 0:ge.getName())!==de.sheetName)return Z.token;const oe=Y[te];if(te++,!oe)return"";const $e=(me=oe.sheetId)!=null?me:r,St={range:oe,unitId:(Ae=oe.unitId)!=null?Ae:m.getUnitId(),sheetName:C((Oe=oe.unitId)!=null?Oe:m.getUnitId(),$e)},tt=(m==null?void 0:m.getUnitId())!==o;return Xe([St],i&&($e!==r||tt),_,tt)[0]}return Z.token});let re="",ie;le.forEach((Z,ge)=>{re+=Z,ge===y&&(ie=re.length)});const ue=[];for(let Z=te;Z<=w.length-1;Z++){const ge=w[Z],me=(Je=ge.sheetId)!=null?Je:r,Ae={range:ge,unitId:(pe=ge.unitId)!=null?pe:m.getUnitId(),sheetName:C((et=ge.unitId)!=null?et:m.getUnitId(),me)},Oe=(m==null?void 0:m.getUnitId())!==o,oe=Xe([Ae],i&&(me!==r||Oe),_,Oe);ue.push(oe[0])}const fe=V[V.length-1],be=fe&&(typeof fe=="string"?!1:fe.nodeType===T.sequenceNodeType.REFERENCE),Me=`${re}${ue.length&&be?",":""}${ue.join(",")}`;f(Me,!ue.length&&ie?ie:Me.length,$)}});I.useEffect(()=>{if(x&&e){let w=!0,$=0;const H=(y,k)=>{if(w){w=!1,$=y.length;return}const V=y.length>$;k&&($=y.length),P(y.map(K=>K.rangeWithCoord),k,V)},M=new a.DisposableCollection;return M.add(x.selectionMoving$.subscribe(y=>{H(y,!1)})),M.add(x.selectionMoveEnd$.subscribe(y=>{H(y,!0)})),()=>{M.dispose()}}},[e,P,x]),I.useEffect(()=>{if(t&&x&&d){const w=new a.DisposableCollection,$=()=>{w.dispose(),x.getSelectionControls().forEach((y,k)=>{w.add(y.selectionScaling$.subscribe(V=>{const K=x.getSelectionDataWithStyle().map(ne=>ne.rangeWithCoord),z=K[k];V.sheetId=z.sheetId,V.unitId=z.unitId,K[k]=V,P(K,!1)})),w.add(y.selectionMoving$.subscribe(V=>{const K=x.getSelectionDataWithStyle().map(ne=>ne.rangeWithCoord),z=K[k];V.sheetId=z.sheetId,V.unitId=z.unitId,K[k]=V,P(K,!0)}))})},H=Q.merge(d.input$,W.selectionSet$,x.selectionMoveEnd$).pipe(tn.debounceTime(50)).subscribe(()=>{$()});return()=>{H.unsubscribe(),w.dispose()}}},[d,t,P,x,W.selectionSet$]),x==null||x.getSelectionDataWithStyle(),I.useEffect(()=>{if(c){const w=h.onCommandExecuted($=>{var M;if($.id!==A.SetSelectionsOperation.id)return;const H=$.params;if(H.extra==="formula-editor"&&H.selections.length){const y=H.selections[H.selections.length-1];if(y){const{range:k,primary:V}=y;(V!=null&&V.isMergedMainCell||V!=null&&V.isMerged)&&a.Rectangle.contains(V,k)&&(k.startRow=V.startRow,k.endRow=V.startRow,k.startColumn=V.startColumn,k.endColumn=V.startColumn),k.unitId=H.unitId,k.sheetId=H.subUnitId;const K=n.current===Se.NEED_ADD,z=((M=x==null?void 0:x.getSelectionDataWithStyle())!=null?M:[]).map(ne=>ne.rangeWithCoord);K?z.push(k):z[z.length-1]=k,P(z,!0)}}});return()=>{w.dispose()}}},[h,d,n,v,c,P,x]),I.useEffect(()=>{if(!d)return;const w=S.textSelection$.subscribe($=>{$.unitId===d.getEditorId()&&Vt({unitId:o,subUnitId:r,refSelections:s.current,editor:d,refSelectionsService:W,refSelectionsRenderService:x,sheetSkeletonManagerService:U,themeService:u,univerInstanceService:p,currentWorkbook:m})});return()=>w.unsubscribe()},[S.textSelection$,d,s,x,W,U,r,u,o,p])},Vr=(e,t,n,o,r,s)=>{const i=l.useDependency(a.ICommandService),c=l.useDependency(J.IEditorService),f=l.useDependency(j.IRenderManagerService).getRenderById(t),g=l.useDependency(a.IUniverInstanceService),p=f==null?void 0:f.with(L.RefSelectionsRenderService);I.useEffect(()=>{if(e&&p)if(n){const h=()=>{const v=p.getSelectionControls().length;for(let E=1;E<=v;E++)p.clearLastSelection();return setTimeout(()=>{s()},30)},S=i.onCommandExecuted(v=>{v.id===A.SetWorksheetActiveOperation.id&&h()}),u=g.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(v=>{h()});return()=>{S.dispose(),u.unsubscribe()}}else{const h=i.beforeCommandExecuted(S=>{if(S.id===A.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,p])},Hr=(e,t,n)=>{const o=l.useDependency(T.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(T.operatorToken.EQUALS),`${n}`)}},[n,t])},Br=(e,t=[],n)=>{const o=l.useDependency(he.IDescriptionService),[r,s]=I.useState([]),[i,c]=I.useState(""),d=I.useRef(-1),f=Te({nodes:t}),g=()=>{s([]),c(""),d.current=-1};return I.useEffect(()=>{if(n&&e){const h=n.input$.pipe(Q.debounceTime(300)).subscribe(()=>{const S=n.getSelectionRanges();if(S.length===1){const u=f.current.nodes,v=S[0];if(v.collapsed){const E=dt(u,v.startOffset-1,!1);d.current=E;const C=u[E];if(C&&typeof C!="string"&&C.nodeType===T.sequenceNodeType.FUNCTION){d.current=E;const _=C.token,b=o.getSearchListByNameFirstLetter(_);s(b),c(_);return}}}d.current=-1,c(""),s(u=>u!=null&&u.length?[]:u)});return()=>{h.unsubscribe()}}},[n,e]),I.useEffect(()=>{e||g()},[e]),{searchList:r,searchText:i,handlerFormulaReplace:(h,S)=>{const u=[...f.current.nodes];if(d.current!==-1){const v=u.splice(d.current+1),E=u.pop()||"";let C=(typeof E=="string"?E.length:E.token.length)-h.length;return u.push(h),v[0]!==T.matchToken.OPEN_BRACKET&&S!==T.FunctionType.DefinedName&&(u.push(T.matchToken.OPEN_BRACKET),C--),{text:ht([...u,...v]),offset:C}}},reset:g}},Kr=()=>{},jr=I.forwardRef(qr);function qr(e,t){const{isFocus:n,sequenceNodes:o,onSelect:r,editor:s,onClose:i=Kr}=e,c=s.getEditorId(),d=l.useDependency(l.IShortcutService),f=l.useDependency(a.ICommandService),{searchList:g,searchText:p,handlerFormulaReplace:h,reset:S}=Br(n,o,s),u=I.useMemo(()=>!!g.length,[g]),v=I.useRef(void 0),[E,C]=I.useState(0),_=I.useRef(!1),[b]=Wt(c,u,[p,g]),N=Te({searchList:g,active:E}),m=(P,F)=>{const w=h(P,F);w&&(S(),r(w))};function O(P){_.current&&C(P)}function x(){_.current&&C(-1)}I.useEffect(()=>{if(!g.length)return;const P=`sheet.formula-embedding-editor.search_function.${c}`,F=new a.DisposableCollection,w=$=>{const{searchList:H,active:M}=N.current;switch($){case l.KeyCode.ARROW_UP:{C(y=>{const k=Math.max(0,y-1);return U(k),k});break}case l.KeyCode.ARROW_DOWN:{C(y=>{const k=Math.min(H.length-1,y+1);return U(k),k});break}case l.KeyCode.TAB:case l.KeyCode.ENTER:{const y=H[M];m(y.name,y.functionType);break}case l.KeyCode.ESC:{S(),i();break}}};return F.add(f.registerCommand({id:P,type:a.CommandType.OPERATION,handler($,H){const{keyCode:M}=H;w(M)}})),[l.KeyCode.ARROW_UP,l.KeyCode.ARROW_DOWN,l.KeyCode.ENTER,l.KeyCode.ESC,l.KeyCode.TAB].map($=>({id:P,binding:$,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keyCode:$}})).forEach($=>{F.add(d.registerShortcut($))}),()=>{F.dispose()}},[g]);function U(P){const F=v.current;if(!F)return;const w=F.children[P];if(!w)return;const H=F.getBoundingClientRect().top,M=F.offsetHeight,y=w.getBoundingClientRect(),k=y.top,V=y.height;if(k>=0&&k>H&&k-H+V<=M)return;const K=w.offsetTop-(M-V)/2;F.scrollTo({top:K,behavior:"smooth"})}const W=I.useMemo(()=>{let P="";return()=>{clearTimeout(P),_.current=!0,P=setTimeout(()=>{_.current=!1},300)}},[]);return g.length>0&&u&&R.jsx(l.RectPopup,{portal:!0,anchorRect$:b,direction:"vertical",children:R.jsx("ul",{ref:P=>{v.current=P,t&&(t.current=P)},"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:g.map((P,F)=>R.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":E===F}),onMouseEnter:()=>O(F),onMouseLeave:x,onMouseMove:W,onClick:()=>{m(P.name,P.functionType),s&&s.focus()},children:[R.jsxs("span",{className:"univer-block univer-truncate univer-text-xs",children:[R.jsx("span",{className:"univer-text-red-500",children:P.name.substring(0,p.length)}),R.jsx("span",{children:P.name.slice(p.length)})]}),R.jsx("span",{className:"univer-block univer-text-xs univer-text-gray-400",children:P.desc})]},P.name))})})}const Yr=e=>e.startsWith(T.operatorToken.EQUALS)?e.slice(1):"",Bt=()=>{},Kt=I.forwardRef((e,t)=>{var Gt,Zt,Xt,Qt;const{errorText:n,initValue:o,unitId:r,subUnitId:s,isFocus:i=!0,isSupportAcrossSheet:c=!1,onFocus:d=Bt,onBlur:f=Bt,onChange:g,onVerify:p,className:h,editorId:S,moveCursor:u=!0,onFormulaSelectingChange:v,keyboardEventConfig:E,onMoveInEditor:C,resetSelectionOnBlur:_=!0,autoScrollbar:b=!0,isSingle:N=!0,disableSelectionOnClick:m=!1,autofocus:O=!0,disableContextMenu:x,style:U}=e,W=l.useDependency(J.IEditorService),P=I.useRef(null),F=l.useEvent(g);I.useImperativeHandle(t,()=>({isClickOutSide:X=>P.current?!P.current.contains(X.target):!1}));const w=l.useEvent(v),$=I.useRef(null),H=I.useRef(void 0),M=H.current,[y,k]=I.useState(i),V=I.useRef(null),K=I.useMemo(()=>S!=null?S:a.createInternalEditorID(`${D.EMBEDDING_FORMULA_EDITOR}-${a.generateRandomId(4)}`),[]),z=I.useMemo(()=>n!==void 0,[n]),ne=l.useDependency(a.IUniverInstanceService),ae=ne.getUnit(K);l.useObservable(ae==null?void 0:ae.change$);const G=Nr(),ee=a.BuildTextUtils.transform.getPlainText((Zt=(Gt=ae==null?void 0:ae.getBody())==null?void 0:Gt.dataStream)!=null?Zt:""),ke=Te(ee),we=I.useMemo(()=>Yr(ee),[ee]),Je=I.useMemo(()=>G(we),[we,G]),{isSelecting:pe,isSelectingRef:et}=Or({unitId:r,subUnitId:s,editorId:K,isFocus:y,disableOnClick:m}),Y=I.useRef(""),le=l.useDependency(j.IRenderManagerService).getRenderById(K),re=le==null?void 0:le.with(J.DocSelectionRenderService),ie=re==null?void 0:re.isFocusing,ue=I.useMemo(()=>ne.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC),[ne]),fe=l.useObservable(ue),be=(fe==null?void 0:fe.getUnitId())===K,Me=I.useRef([]),Z=pe,me=(Qt=(Xt=l.useDependency(a.IConfigService).getConfig(Rt))==null?void 0:Xt.functionScreenTips)!=null?Qt:!0;l.useUpdateEffect(()=>{F(ee)},[ee,F]);const Ae=Ht("="),Oe=kr(r,s),de=l.useEvent((X,se=!0,Ce,ve)=>{if(!H.current)return;Y.current=X;const nt=X[0]==="="?X.slice(1):"",_e=G(nt),so=_e.reduce((Ne,ot)=>typeof ot=="object"?`${Ne}${ot.token}`:`${Ne}${ot}`,""),rt=Ae(H.current,so===nt?_e:[],se,ve);if(Me.current=rt,Ce){const Ne=ve!=null?ve:M==null?void 0:M.getSelectionRanges();if((Ne==null?void 0:Ne.length)!==1)return;const io=Ne[0].startOffset-1,co=dt(_e,io,!1),Jt=$t(_e,co);if(Jt>=0){const en=rt.splice(Jt,1)[0];en&&rt.push(en)}Oe(y?rt:[],H.current)}});I.useEffect(()=>{y&&de(ee,!1,!0)},[y]),I.useEffect(()=>{if(y){if(Y.current===ee)return;de(ee,!1,!0)}},[ee]),Hr(y,p,ee);const oe=br(M),$e=Lr(y,r,s);I.useEffect(()=>{var X;w(pe,(X=re==null?void 0:re.isFocusing)!=null?X:!0)},[w,pe]),J.useKeyboardEvent(y,E,M),I.useLayoutEffect(()=>{let X;if(V.current){X=W.register({autofocus:O,editorUnitId:K,initialSnapshot:{id:K,body:{dataStream:`${o}\r
|
|
5
|
-
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},V.current);const se=W.getEditor(K);H.current=se,de(o,!1,!0)}return()=>{X==null||X.dispose()}},[]),I.useLayoutEffect(()=>{i?(k(i),oe()):(_&&(M==null||M.blur(),$e()),k(i))},[i,M,oe,$e,_]);const{checkScrollBar:St}=J.useResize(M,N,b);Pr(y,!!(pe&&be),r,K,x),xr(!!(y&&ie&&u),Z,M,C);const tt=l.useEvent((X,se,Ce)=>{if(!ie)return;const ve=se!==-1?[{startOffset:se+1,endOffset:se+1,collapsed:!0}]:void 0;de(`=${X}`,!0,Ce,ve),Ce&&(oe(),se!==-1&&setTimeout(()=>{const nt={startOffset:se+1,endOffset:se+1},_e=M==null?void 0:M.render.with(J.DocBackScrollRenderController);_e==null||_e.scrollToRange({...nt,collapsed:!0})},50),St())});Ur(y&&!!(pe&&be),y,et,r,s,Me,c,!!Z,M,tt),Vr(y&&!!(pe&&be),r,c,k,f,()=>{de(ke.current,!1,!0)});const Yt=X=>{if(X){const se=M==null?void 0:M.getSelectionRanges();if(se&&se.length===1){const Ce=se[0];if(Ce.collapsed){const ve=X.offset;setTimeout(()=>{M==null||M.setSelectionRanges([{startOffset:Ce.startOffset-ve,endOffset:Ce.endOffset-ve}])},30)}}oe(),de(`=${X.text}`)}},zt=()=>{k(!0),d(),oe()};return R.jsxs("div",{className:h,children:[R.jsx("div",{ref:P,className:B.clsx("univer-relative univer-box-border univer-flex univer-size-full univer-items-center univer-justify-around univer-gap-2 univer-rounded-none univer-p-0 univer-ring-1",{"univer-ring-primary-500":y,"univer-ring-red-500":z}),children:R.jsx("div",{ref:V,className:"univer-relative univer-size-full",onMouseUp:zt})}),n!==void 0&&R.jsx("div",{className:"univer-my-1 univer-text-xs univer-text-red-500",children:n}),me&&M&&we!==""&&R.jsx(Tr,{editor:M,isFocus:y,formulaText:ee,onClose:()=>oe()}),me&&!!M&&R.jsx(jr,{isFocus:y,sequenceNodes:Je,onSelect:Yt,ref:$,editor:M})]})});function zr(e,t,n,o){const r=l.useDependency(T.LexerTreeBuilder),s=Ht(""),i=l.useObservable(e==null?void 0:e.getDocumentDataModel().change$),[c,d]=I.useState([]),f=l.useDependency(D.IMarkSelectionService),g=I.useRef(""),p=l.useDependency(a.IUniverInstanceService);return I.useEffect(()=>{if(!e)return;const h=e.getDocumentDataModel().getPlainText();if(g.current===h)return;g.current=h;const S=r.sequenceNodesBuilder(h);d(S!=null?S:[])},[i,e,r]),I.useEffect(()=>{var u,v;if(!e)return;if(!t){const E=e.getDocumentData();e.setDocumentData({...E,body:{...E.body,dataStream:(v=(u=E.body)==null?void 0:u.dataStream)!=null?v:"",textRuns:[]}});return}const h=s(e,c,!1),S=new a.DisposableCollection;return h.forEach(E=>{const C=T.deserializeRangeWithSheet(E.token),_=p.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),b=_==null?void 0:_.getActiveSheet();if(!C.sheetName&&o!==(b==null?void 0:b.getSheetId())||C.sheetName&&(b==null?void 0:b.getName())!==C.sheetName)return;const N=new a.ColorKit(E.themeColor).toRgb(),m=f.addShape({range:C.range,style:{stroke:E.themeColor,fill:`rgba(${N.r}, ${N.g}, ${N.b}, 0.1)`,strokeDash:12},primary:null});m&&S.add(()=>f.removeShape(m))}),()=>{S.dispose()}},[e,t,s,f,c]),{sequenceNodes:c}}function Gr(e){const t=l.useDependency(A.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),f=l.useEvent(i),g=l.useEvent((p,h)=>{const S=d==null?void 0:d.getActiveSheet();if(!S||!n&&S.getSheetId()!==s||!(p!=null&&p.length))return;const u=o?S.getName():S.getSheetId()===s?"":S.getName(),v=p.map(E=>({range:E.range,unitId:r,sheetName:u}));f(v,h)});I.useEffect(()=>{const p=new a.DisposableCollection;return p.add(t.selectionMoveStart$.subscribe(h=>{g(h,!0)})),p.add(t.selectionMoving$.subscribe(h=>{g(h,!1)})),p.add(t.selectionMoveEnd$.subscribe(h=>{g(h,!1)})),()=>{p.dispose()}},[g,t.selectionMoveEnd$,t.selectionMoveStart$,t.selectionMoving$])}const jt=e=>!e.some(n=>{if(typeof n=="string"){if(n!==T.matchToken.COMMA)return!0}else if(n.nodeType!==T.sequenceNodeType.REFERENCE)return!0;return!1}),Zr=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 Xr(e){const{visible:t,initialValue:n,unitId:o,subUnitId:r,maxRangeCount:s=1/0,supportAcrossSheet:i,keepSheetReference:c,onConfirm:d,onClose:f,onShowBySelection:g}=e,p=l.useDependency(a.LocaleService),h=l.useDependency(T.LexerTreeBuilder),[S,u]=I.useState([]),[v,E]=I.useState(0),C=I.useRef(null);I.useEffect(()=>{if(t&&n.length){const m=n.map(O=>O.sheetName?T.serializeRangeWithSheet(O.sheetName,O.range):T.serializeRange(O.range));u(m),E(m.length-1)}else u([""]),E(0)},[t]);const _=(m,O)=>{const x=[...S];x[m]=O,u(x)},b=()=>{u([...S,""]),E(S.length)},N=m=>{S.splice(m,1),u([...S])};return Gr({unitId:o,subUnitId:r,supportAcrossSheet:i,keepSheetReference:c,onChange:(m,O)=>{if(!t&&g!=null&&g(m))return;const x=new Set(S),U=m.map(F=>F.sheetName?T.serializeRangeWithSheet(F.sheetName,F.range):T.serializeRange(F.range)),W=U.filter(F=>!x.has(F));if(!W.length)return;const P=[...S];if(U.length>1){O||P.splice(v,1),P.push(...W);const F=P.slice(0,s);u(F),E(F.length-1),requestAnimationFrame(()=>{var w;(w=C.current)==null||w.scrollTo({top:C.current.scrollHeight})})}else{P.splice(v,1,...W);const F=P.slice(0,s);u(F),E(v+W.length-1)}}}),R.jsx(B.Dialog,{width:"328px",open:t,title:p.t("rangeSelector.title"),draggable:!0,mask:!1,maskClosable:!1,footer:R.jsxs("footer",{className:"univer-flex univer-gap-2",children:[R.jsx(B.Button,{onClick:f,children:p.t("rangeSelector.cancel")}),R.jsx(B.Button,{variant:"primary",onClick:()=>{d(S.filter(m=>{const O=h.sequenceNodesBuilder(m);return O&&O.length===1&&typeof O[0]!="string"&&O[0].nodeType===T.sequenceNodeType.REFERENCE}).map(m=>T.deserializeRangeWithSheet(m)).map(m=>({...m,range:Zr(m.range)})))},children:p.t("rangeSelector.confirm")})]}),onClose:f,children:R.jsxs("div",{ref:C,className:B.clsx("-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6",B.scrollbarClassName),children:[S.map((m,O)=>R.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-gap-4",children:[R.jsx(B.Input,{className:B.clsx("univer-w-full",{"univer-border-primary-600":v===O}),placeholder:p.t("rangeSelector.placeHolder"),onFocus:()=>E(O),value:m,onChange:x=>_(O,x)}),S.length>1&&R.jsx(xt,{className:"univer-cursor-pointer",onClick:()=>N(O)})]},O)),S.length<s&&R.jsx("div",{children:R.jsxs(B.Button,{variant:"link",onClick:b,children:[R.jsx(Pt,{}),R.jsx("span",{children:p.t("rangeSelector.addAnotherRange")})]})})]})})}function Qr(e){return e.split(T.matchToken.COMMA).filter(t=>!!t).map(t=>T.deserializeRangeWithSheet(t))}function Jr(e){return e.map(t=>t.sheetName?T.serializeRangeWithSheet(t.sheetName,t.range):T.serializeRange(t.range)).join(T.matchToken.COMMA)}function gt(e){const[t,n]=I.useState(null),{onVerify:o,selectorRef:r,unitId:s,subUnitId:i,maxRangeCount:c,supportAcrossSheet:d,keepSheetReference:f,autoFocus:g,onChange:p,onRangeSelectorDialogVisibleChange:h,onClickOutside:S,onFocusChange:u,forceShowDialogWhenSelectionChanged:v,hideEditor:E,resetRange:C}=e,[_,b]=I.useState(g!=null?g:!1),[N,m]=I.useState(!1),[O,x]=I.useState([]),U=l.useDependency(a.LocaleService),W=l.useDependency(J.IEditorService),{sequenceNodes:P}=zr(t,_,s,i),F=Te(P),w=l.useDependency(a.ICommandService),$=l.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),W.blur()}),H=l.useEvent(()=>{var M;$(),x(Qr((M=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?M:"")),m(!0)});return I.useEffect(()=>{r&&(r.current={get editor(){return t},focus(){W.focus(t.getEditorId())},blur:$,verify:()=>jt(F.current),showDialog:M=>{$(),x(M),m(!0)},hideDialog:()=>{x([]),m(!1)},getValue:()=>{var M;return(M=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?M:""}})},[$,t,W,r,F]),I.useEffect(()=>{var M;o==null||o(jt(P),(M=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?M:"")},[P]),I.useEffect(()=>{h==null||h(N)},[N]),I.useEffect(()=>{if(N&&C)return()=>{const M={unitId:s,subUnitId:i,selections:C};w.executeCommand(A.SetSelectionsOperation.id,M)}},[N]),R.jsxs(R.Fragment,{children:[E?null:R.jsx(J.RichTextEditor,{isSingle:!0,...e,onFocusChange:(M,y)=>{b(M),u==null||u(M,y)},editorRef:n,onClickOutside:()=>{b(!1),$(),S==null||S()},icon:R.jsx(B.Tooltip,{title:U.t("rangeSelector.buttonTooltip"),placement:"bottom",children:R.jsx(Ft,{className:"univer-cursor-pointer dark:!univer-text-gray-300",onClick:H})})}),R.jsx(Xr,{initialValue:O,unitId:s,subUnitId:i,visible:N,maxRangeCount:c,onConfirm:M=>{const y=Jr(M),k=a.RichTextBuilder.newEmptyData();k.body.dataStream=y,t==null||t.replaceText(y,!1),p==null||p(k,y),m(!1),x([]),requestAnimationFrame(()=>{$()})},onClose:()=>{m(!1),x([])},supportAcrossSheet:d,keepSheetReference:f,onShowBySelection:M=>_||v?(x(M),m(!0),!1):!0})]})}const eo=()=>{var o,r;const e=l.useDependency(ut),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]),R.jsx(gt,{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=>T.deserializeRangeWithSheet(d)))!=null?c:[])}})};var to=Object.defineProperty,no=Object.getOwnPropertyDescriptor,ro=(e,t,n)=>t in e?to(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,oo=(e,t,n,o)=>{for(var r=o>1?void 0:o?no(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Qe=(e,t)=>(n,o)=>t(n,o,e),qt=(e,t,n)=>ro(e,typeof t!="symbol"?t+"":t,n);L.UniverSheetsFormulaUIPlugin=class extends a.Plugin{constructor(t=Tt,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(Tt,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Rt,c,{merge:!0})}onStarting(){a.registerDependencies(this._injector,[[Ve,{useClass:st}],[ut],[Ge],[Ke],[je],[qe],[Ye],[L.FormulaReorderController],[Ze]]),this._initUIPart()}onReady(){[[L.RefSelectionsRenderService]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,t))})}onRendered(){[[at]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,t))}),a.touchDependencies(this._injector,[[Ge],[je],[Ye],[Ze]])}onSteady(){this._injector.get(Ke),this._injector.get(L.FormulaReorderController)}_initUIPart(){const t=this._injector.get(l.ComponentManager);this.disposeWithMe(t.register(D.RANGE_SELECTOR_COMPONENT_KEY,gt)),this.disposeWithMe(t.register(D.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,Kt)),this.disposeWithMe(this._uiPartsService.registerComponent(l.BuiltInUIPart.GLOBAL,()=>l.connectInjector(eo,this._injector)))}},qt(L.UniverSheetsFormulaUIPlugin,"pluginName",Et),qt(L.UniverSheetsFormulaUIPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),L.UniverSheetsFormulaUIPlugin=oo([a.DependentOn(he.UniverSheetsFormulaPlugin),Qe(1,a.Inject(a.Injector)),Qe(2,j.IRenderManagerService),Qe(3,a.IConfigService),Qe(4,l.IUIPartsService)],L.UniverSheetsFormulaUIPlugin),L.FORMULA_PROMPT_ACTIVATED=vt,L.FormulaEditor=Kt,L.GlobalRangeSelectorService=ut,L.HelpFunctionOperation=mt,L.InsertFunctionOperation=ce,L.MoreFunctionsOperation=He,L.RangeSelector=gt,L.ReferenceAbsoluteOperation=it,L.SearchFunctionOperation=yt,L.SelectEditorFormulaOperation=Ee,L.SheetCopyFormulaOnlyCommand=We,L.SheetOnlyPasteFormulaCommand=Ue,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(L,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):(L=typeof globalThis<"u"?globalThis:L||self,a(L.UniverSheetsFormulaUi={},L.UniverCore,L.UniverSheetsUi,L.UniverEngineFormula,L.rxjs,L.UniverDocsUi,L.UniverEngineRender,L.UniverSheets,L.UniverSheetsFormula,L.UniverUi,L.React,L.React,L.UniverDesign,L.UniverDocs,L.rxjs.operators))})(this,(function(L,a,x,E,Q,J,j,V,le,l,T,y,H,mt,nn){"use strict";var uo=Object.defineProperty;var fo=(L,a,x)=>a in L?uo(L,a,{enumerable:!0,configurable:!0,writable:!0,value:x}):L[a]=x;var q=(L,a,x)=>fo(L,typeof a!="symbol"?a+"":a,x);const Be={id:"sheet.command.copy-formula-only",type:a.CommandType.COMMAND,handler:async e=>e.get(x.ISheetClipboardService).copy({copyHookType:x.PREDEFINED_HOOK_NAME_COPY.SPECIAL_COPY_FORMULA_ONLY})},He={id:"sheet.command.paste-formula",type:a.CommandType.COMMAND,handler:async e=>e.get(a.ICommandService).executeCommand(x.SheetPasteCommand.id,{value:x.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA})},Re={id:"formula-ui.operation.select-editor-formula",type:a.CommandType.OPERATION,handler:(e,t)=>!0};var rn=Object.getOwnPropertyDescriptor,on=(e,t,n,o)=>{for(var r=o>1?void 0:o?rn(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},sn=(e,t)=>(n,o)=>t(n,o,e);const Ct="FORMULA_PROMPT_ACTIVATED",Ke=a.createIdentifier("formula-ui.prompt-service");let ct=class{constructor(e){q(this,"_search$",new Q.Subject);q(this,"_help$",new Q.Subject);q(this,"_navigate$",new Q.Subject);q(this,"_accept$",new Q.Subject);q(this,"_acceptFormulaName$",new Q.Subject);q(this,"search$",this._search$.asObservable());q(this,"help$",this._help$.asObservable());q(this,"navigate$",this._navigate$.asObservable());q(this,"accept$",this._accept$.asObservable());q(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());q(this,"_searching",!1);q(this,"_helping",!1);q(this,"_sequenceNodes",[]);q(this,"_isLockedOnSelectionChangeRefString",!1);q(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(Ct,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!==E.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 u={...c};u.startIndex+=o,u.endIndex+=o,this._sequenceNodes[s]=u}}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:E.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 u={...c};u.startIndex+=r,u.endIndex+=r,this._sequenceNodes[s]=u}}enableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!0}disableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!1}isLockedSelectionChange(){return this._isLockedOnSelectionChangeRefString}enableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!0}disableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!1}isLockedSelectionInsert(){return this._isLockedOnSelectionInsertRefString}};ct=on([sn(0,a.IContextService)],ct);const It={id:"formula-ui.operation.help-function",type:a.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ke).help(t),!0)},ee={id:"formula-ui.operation.insert-function",type:a.CommandType.OPERATION,handler:async(e,t)=>{var I,M;const n=e.get(V.SheetsSelectionsService),o=e.get(J.IEditorService),r=n.getCurrentSelections();if(!r||!r.length)return!1;const s=V.getSheetCommandTarget(e.get(a.IUniverInstanceService));if(!s)return!1;const{worksheet:i,unitId:c,subUnitId:u}=s,f=i.getCellMatrix(),{value:S}=t,p=e.get(a.ICommandService);e.get(x.IEditorBridgeService);const h=[],g=[];let d=null,v=0,_=0,C="";if(r.length===1&&(ln(r[0].range)||un(r[0].range)&&_t(f,r[0].range))){const{range:N,primary:m}=r[0],O=(I=m==null?void 0:m.actualRow)!=null?I:N.startRow,A=(M=m==null?void 0:m.actualColumn)!=null?M:N.startColumn;d=N,v=O,_=A;const U=yt(f,O,A);U&&(C=E.serializeRange(U))}else r.some(N=>{var A,U;const{range:m,primary:O}=N;if(_t(f,m)){const $=(A=O==null?void 0:O.actualRow)!=null?A:m.startRow,k=(U=O==null?void 0:O.actualColumn)!=null?U:m.startColumn,P=yt(f,$,k);if(!P)return d=m,v=$,_=k,!0;const w=E.serializeRange(P),F=`=${S}(${w})`;h.push({range:m,primary:{row:$,column:k},formula:F})}else{const{startRow:$,startColumn:k,endRow:P,endColumn:w}=m;if($===P){const F=dn(f,$,w,i.getColumnCount()-1),B=F===w?w-1:w,b=E.serializeRange({startRow:$,endRow:P,startColumn:k,endColumn:B}),R=`=${S}(${b})`;g.push({range:m,primary:{row:$,column:F},formula:R})}else{let F=-1;for(let b=k;b<=w;b++){const R=fn(f,b,P,i.getRowCount()-1);F=Math.max(F,R)}const B=F===P?P-1:P;for(let b=k;b<=w;b++){const R=E.serializeRange({startRow:$,endRow:B,startColumn:b,endColumn:b}),D=`=${S}(${R})`;g.push({range:m,primary:{row:F,column:b},formula:D})}}}return!1});if(d){const N=V.getCellAtRowCol(v,_,i),m={range:a.Rectangle.clone(d),primary:{startRow:N.startRow,startColumn:N.startColumn,endRow:N.endRow,endColumn:N.endColumn,actualRow:v,actualColumn:_,isMerged:N.isMerged,isMergedMainCell:N.startRow===v&&N.startColumn===_}},O={unitId:c,subUnitId:u,selections:[m]};await p.executeCommand(V.SetSelectionsOperation.id,O);const A=o.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),U=o.getEditor(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);p.syncExecuteCommand(x.SetCellEditVisibleOperation.id,{visible:!0,unitId:c,eventType:j.DeviceInputEventType.Dblclick});const $=`=${S}(${C}`;A==null||A.replaceText($),U==null||U.replaceText($,!1)}return h.length===0&&g.length===0?!1:p.executeCommand(le.InsertFunctionCommand.id,{list:h,listOfRangeHasNumber:g})}};function yt(e,t,n){const o=cn(e,t,n);if(o!==t)return{startRow:o,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 o=!1;if(t===0)return t;for(let r=t-1;r>=0;r--){const s=e.getValue(r,n);if(Fe(s)&&!o){if(r===0)return 0;o=!0}else{if(o&&!Fe(s))return r+1;if(o&&r===0)return 0}}return t}function an(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(Fe(s)&&!o){if(r===0)return 0;o=!0}else{if(o&&!Fe(s))return r+1;if(o&&r===0)return 0}}return n}function Fe(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 ln(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}function un(e){return e.startRow!==e.endRow&&e.startColumn!==e.endColumn}function _t(e,t){for(let n=t.startRow;n<=t.endRow;n++)for(let o=t.startColumn;o<=t.endColumn;o++)if(Fe(e.getValue(n,o)))return!1;return!0}function dn(e,t,n,o){for(let r=n;r<=o;r++)if(!e.getValue(t,r))return r;return o}function fn(e,t,n,o){for(let r=n;r<=o;r++)if(!e.getValue(r,t))return r;return o}const Et="SHEET_FORMULA_UI_PLUGIN",Rt=`${Et}_MORE_FUNCTIONS_COMPONENT`,se={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:Rt}}),!0)},at={id:"formula-ui.operation.change-ref-to-absolute",type:a.CommandType.OPERATION,handler:async e=>!0},Tt={id:"formula-ui.operation.search-function",type:a.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ke).search(t),!0)};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},je=(e,t)=>(n,o)=>t(n,o,e);L.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===V.ReorderRangeCommand.id?this._reorderFormula(t.params):{redos:[],undos:[]}}))}_reorderFormula(t){const n=[],o=[],{unitId:r,subUnitId:s,range:i,order:c}=t,u=this._univerInstanceService.getUniverSheetInstance(r),f=u==null?void 0:u.getSheetBySheetId(s);if(!f)return{redos:n,undos:o};const S=f.getCellMatrix(),p=new a.ObjectMatrix,h=new a.ObjectMatrix;let g=!1;return a.Range.foreach(i,(d,v)=>{let _=d;c.hasOwnProperty(d)&&(_=c[d]);const C=S.getValue(_,v);if(C!=null&&C.f||C!=null&&C.si){g=!0;const I=this._formulaDataModel.getFormulaStringByCell(_,v,s,r),M=this._lexerTreeBuilder.moveFormulaRefOffset(I,0,d-_),N=a.Tools.deepClone(C);N.f=M,N.si=null,p.setValue(d,v,N)}else p.setValue(d,v,C);h.setValue(d,v,S.getValue(d,v))}),g?(n.push({id:V.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:s,cellValue:p.getMatrix()}}),o.push({id:V.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:s,cellValue:h.getMatrix()}}),{redos:n,undos:o}):{redos:n,undos:o}}},L.FormulaReorderController=gn([je(0,a.Inject(V.SheetInterceptorService)),je(1,a.Inject(a.IUniverInstanceService)),je(2,a.Inject(E.FormulaDataModel)),je(3,a.Inject(E.LexerTreeBuilder))],L.FormulaReorderController);const bt={name:"@univerjs/sheets-formula-ui",version:"0.17.0"},Mt="sheets-formula-ui.base.config",Ot={};var Sn=Object.getOwnPropertyDescriptor,pn=(e,t,n,o)=>{for(var r=o>1?void 0:o?Sn(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 lt="SHEET_FORMULA_ALERT",vn={[E.ErrorType.DIV_BY_ZERO]:"divByZero",[E.ErrorType.NAME]:"name",[E.ErrorType.VALUE]:"value",[E.ErrorType.NUM]:"num",[E.ErrorType.NA]:"na",[E.ErrorType.CYCLE]:"cycle",[E.ErrorType.REF]:"ref",[E.ErrorType.SPILL]:"spill",[E.ErrorType.CALC]:"calc",[E.ErrorType.ERROR]:"error",[E.ErrorType.CONNECT]:"connect",[E.ErrorType.NULL]:"null"};let ut=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 u=c.getCell(e.location.row,e.location.col),f=(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(u)){const S=E.extractFormulaError(u,!!f);if(!S){this._hideAlert();return}const p=this._cellAlertManagerService.currentAlert.get(lt),h=(s=p==null?void 0:p.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:x.CellAlertType.ERROR,title:this._localeService.t("formula.error.title"),message:this._localeService.t(`formula.error.${vn[S]}`),location:e.location,width:200,height:74,key:lt});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(lt)}};ut=pn([$e(1,a.Inject(x.HoverManagerService)),$e(2,a.Inject(x.CellAlertManagerService)),$e(3,a.Inject(a.LocaleService)),$e(4,a.Inject(E.FormulaDataModel)),$e(5,l.IZenZoneService)],ut);var mn=Object.getOwnPropertyDescriptor,Cn=(e,t,n,o)=>{for(var r=o>1?void 0:o?mn(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Ue=(e,t)=>(n,o)=>t(n,o,e);const In="default-paste-formula";let qe=class extends a.Disposable{constructor(e,t,n,o,r){super(),this._univerInstanceService=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._copyFormulaOnlyHook())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteFormulaHook())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteWithFormulaHook()))}_copyFormulaOnlyHook(){const e=this;let t=null;return{id:x.PREDEFINED_HOOK_NAME_COPY.SPECIAL_COPY_FORMULA_ONLY,priority:10,onBeforeCopy(n,o){t=e._getWorksheet(n,o)},onCopyCellContent(n,o){if(!t)return"";const r=t.getCellRaw(n,o);return r?a.isFormulaString(r.f)?r.f:a.isFormulaId(r.si)&&e._formulaDataModel.getFormulaStringByCell(n,o,t.getSheetId(),t.getUnitId())||"":""},onAfterCopy(){t=null},getFilteredOutRows(n,o,r){const s=e._getWorksheet(n,o);if(!s)return[];const{startRow:i,endRow:c}=r,u=[];for(let f=i;f<=c;f++)s.getRowFiltered(f)&&u.push(f);return u},handleMatrixOnCell(n,o,r,s,i,c,u){const f=i.getValue(n,o);if(t&&f&&(a.isFormulaString(f.f)||a.isFormulaId(f.si))){const S=a.isFormulaString(f.f)?f.f:e._formulaDataModel.getFormulaStringByCell(n,o,t.getSheetId(),t.getUnitId());c.setValue(r,s,{...a.getEmptyCell(),f:S}),u.setValue(r,s,{...a.getEmptyCell(),f:S,displayV:S})}else i.setValue(n,o,a.getEmptyCell()),c.setValue(r,s,a.getEmptyCell()),u.setValue(r,s,a.getEmptyCell())}}}_pasteFormulaHook(){return{id:x.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA,priority:10,specialPasteInfo:{label:"specialPaste.formula"},onPasteCells:(e,t,n,o)=>this._onPasteCells(e,t,n,o,!0)}}_pasteWithFormulaHook(){return{id:In,priority:10,onPasteCells:(e,t,n,o)=>this._onPasteCells(e,t,n,o,!1)}}_getWorkbook(e){return e?this._univerInstanceService.getUnit(e,a.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET)}_getWorksheet(e,t){const n=this._getWorkbook(e);return t?n==null?void 0:n.getSheetBySheetId(t):n==null?void 0:n.getActiveSheet()}_onPasteCells(e,t,n,o,r){var h;if([x.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,x.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH].includes(o.pasteType))return{undos:[],redos:[]};const i=this._getWorkbook(),c=t.unitId||(i==null?void 0:i.getUnitId()),u=t.subUnitId||((h=i==null?void 0:i.getActiveSheet())==null?void 0:h.getSheetId());if(!c||!u)return{undos:[],redos:[]};const f=t.range,S=n,p={copyType:o.copyType||x.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:o.pasteType};return this._injector.invoke(g=>yn(c,u,f,S,g,p,this._lexerTreeBuilder,this._formulaDataModel,r,e))}};qe=Cn([Ue(0,a.IUniverInstanceService),Ue(1,a.Inject(E.LexerTreeBuilder)),Ue(2,x.ISheetClipboardService),Ue(3,a.Inject(a.Injector)),Ue(4,a.Inject(E.FormulaDataModel))],qe);function yn(e,t,n,o,r,s,i,c,u=!1,f){const S=[],p=[],h=_n(e,t,n,o,s,i,c,f);if(!h.hasValue())return{undos:[],redos:[]};const g={unitId:e,subUnitId:t,cellValue:h.getData()};S.push({id:V.SetRangeValuesMutation.id,params:g});const d=V.SetRangeValuesUndoMutationFactory(r,g);return p.push({id:V.SetRangeValuesMutation.id,params:d}),{undos:p,redos:S}}function _n(e,t,n,o,r,s,i,c){return c?r.pasteType===x.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE?Rn(e,t,n,o,i,c):r.pasteType===x.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA?Tn(e,t,n,o,s,i,c):bn(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,u,f)=>{var g;const S=n.rows[c],p=n.cols[u],h={};a.isFormulaString(f.v)?(h.v=null,h.f=`${f.v}`,h.si=null,h.p=null,s.setValue(S,p,h)):(g=i==null?void 0:i[S])!=null&&g[p]&&(h.v=f.v,h.f=null,h.si=null,h.p=null,s.setValue(S,p,h))}),s}function Rn(e,t,n,o,r,s){var f,S;const i=new a.ObjectMatrix,c=(S=(f=r.getArrayFormulaCellData())==null?void 0:f[s.unitId])==null?void 0:S[s.subUnitId],u=r.getSheetFormulaData(e,t);return o.forValue((p,h,g)=>{var M,N;const d=s.range.rows[p%s.range.rows.length],v=s.range.cols[h%s.range.cols.length],_=n.rows[p],C=n.cols[h],I={};if(a.isFormulaString(g.f)||a.isFormulaId(g.si))I.v=g.v,I.f=null,I.si=null,I.p=null,i.setValue(_,C,I);else if((M=c==null?void 0:c[d])!=null&&M[v]){const m=c[d][v];I.v=m.v,I.f=null,I.si=null,I.p=null,i.setValue(_,C,I)}else if((N=u==null?void 0:u[_])!=null&&N[C]){if(I.v=g.v,I.f=null,I.si=null,I.p=null,g.p){const m=Nt(g);m&&(I.v=m)}i.setValue(_,C,I)}}),i}function Tn(e,t,n,o,r,s,i){const c=new a.ObjectMatrix,u=new Map;return o.forValue((f,S,p)=>{const h=n.rows[f],g=n.cols[S],d={};if(a.isFormulaId(p.si)){if(i.unitId!==e||i.subUnitId!==t){const v=s.getFormulaStringByCell(i.range.rows[f%i.range.rows.length],i.range.cols[S%i.range.cols.length],i.subUnitId,i.unitId),_=n.cols[S]-i.range.cols[S%i.range.cols.length],C=n.rows[f]-i.range.rows[f%i.range.rows.length],I=r.moveFormulaRefOffset(v||"",_,C);d.si=null,d.f=I}else d.si=p.si,d.f=null;d.v=null,d.p=null,c.setValue(h,g,d)}else if(a.isFormulaString(p.f)){const v=`${f%i.range.rows.length}_${S%i.range.cols.length}`;let _=u.get(v);if(_)d.si=_,d.f=null;else{_=a.generateRandomId(6),u.set(v,_);const C=n.cols[S]-i.range.cols[S%i.range.cols.length],I=n.rows[f]-i.range.rows[f%i.range.rows.length],M=r.moveFormulaRefOffset(p.f||"",C,I);d.si=_,d.f=M}d.v=null,d.p=null,c.setValue(h,g,d)}else{if(d.v=p.v,d.f=null,d.si=null,d.p=null,p.p){const v=Nt(p);v&&(d.v=v)}c.setValue(h,g,d)}}),c}function bn(e,t,n,o,r,s,i,c){const u=new a.ObjectMatrix,f=new Map,S=i.getSheetFormulaData(e,t),p=[];return r===x.COPY_TYPE.CUT?o.forValue((h,g,d)=>{const v=n.rows[h],_=n.cols[g],C={};if(a.isFormulaId(d.si)){if(a.isFormulaString(d.f))p.push(d.si),C.f=d.f,C.si=d.si;else if(p.includes(d.si))C.f=null,C.si=d.si;else{const I=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[g%c.range.cols.length],c.subUnitId,c.unitId);C.f=I,C.si=null}C.v=null,C.p=null,u.setValue(v,_,C)}else a.isFormulaString(d.f)&&(C.f=d.f,C.si=null,C.v=null,C.p=null,u.setValue(v,_,C))}):o.forValue((h,g,d)=>{var I;const v=n.rows[h],_=n.cols[g],C={};if(a.isFormulaId(d.si)){if(c.unitId!==e||c.subUnitId!==t){const M=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[g%c.range.cols.length],c.subUnitId,c.unitId),N=n.cols[g]-c.range.cols[g%c.range.cols.length],m=n.rows[h]-c.range.rows[h%c.range.rows.length],O=s.moveFormulaRefOffset(M||"",N,m);C.si=null,C.f=O}else C.si=d.si,C.f=null;C.v=null,C.p=null,u.setValue(v,_,C)}else if(a.isFormulaString(d.f)){const M=`${h%c.range.rows.length}_${g%c.range.cols.length}`;let N=f.get(M);if(N)C.si=N,C.f=null;else{N=a.generateRandomId(6),f.set(M,N);const m=n.cols[g]-c.range.cols[g%c.range.cols.length],O=n.rows[h]-c.range.rows[h%c.range.rows.length],A=s.moveFormulaRefOffset(d.f||"",m,O);C.si=N,C.f=A}C.v=null,C.p=null,u.setValue(v,_,C)}else(I=S==null?void 0:S[v])!=null&&I[_]&&(C.v=d.v,C.f=null,C.si=null,C.p=d.p,u.setValue(v,_,C))}),p.length>0&&new a.ObjectMatrix(S).forValue((h,g,d)=>{if(!(c.range.rows.includes(h)&&c.range.cols.includes(g))&&!(n.rows.includes(h)&&n.cols.includes(g))&&p.includes(d==null?void 0:d.si)){const v=i.getFormulaStringByCell(h,g,c.subUnitId,c.unitId);u.setValue(h,g,{f:v,si:null,v:null,p:null})}}),u}function Nt(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 Mn=Object.getOwnPropertyDescriptor,On=(e,t,n,o)=>{for(var r=o>1?void 0:o?Mn(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Te=(e,t)=>(n,o)=>t(n,o,e);let Ye=class extends a.Disposable{constructor(t,n,o,r,s,i,c,u){super();q(this,"_previousShape");q(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=u,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(V.BEFORE_CELL_EDIT,{handler:(t,n,o)=>{var d,v,_,C;const{row:r,col:s,unitId:i,subUnitId:c,worksheet:u}=n,f=this._formulaDataModel.getArrayFormulaRange(),S=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return o(t);let p=null;const h=this._formulaDataModel.getFormulaStringByCell(r,s,c,i);if(h!==null&&(p={f:h}),t.v!=null&&t.v!==""&&((_=(v=(d=S[i])==null?void 0:d[c])==null?void 0:v[r])==null?void 0:_[s])==null)return p?{...t,...p}:o(t);const g=(C=f==null?void 0:f[i])==null?void 0:C[c];return g!=null&&(p=this._displayArrayFormulaRangeShape(g,r,s,i,c,u,p)),p?{...t,...p}:o(t)}})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{(t.id===E.SetFormulaCalculationResultMutation.id||t.id===E.SetArrayFormulaDataMutation.id&&n&&n.remove)&&this._removeArrayFormulaRangeShape()})),this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{V.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){return new a.ObjectMatrix(t).forValue((u,f,S)=>{if(S==null)return!0;const{startRow:p,startColumn:h,endRow:g,endColumn:d}=S;if(u===n&&f===o)return this._createArrayFormulaRangeShape(S,r),!1;if(n>=p&&n<=g&&o>=h&&o<=d){const v=i.getCell(p,h);return(v==null?void 0:v.v)===E.ErrorType.SPILL||(v==null?void 0:v.f)==null?void 0:(c==null&&(c={f:v.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=x.attachSelectionWithCoord(i,r),{rowHeaderWidth:u,columnHeaderHeight:f}=r,S=new x.SelectionControl(s,x.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:u,columnHeaderHeight:f});S.updateRangeBySelectionWithCoord(c),S.setEvent(!1),this._previousShape=S}_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 u=0;u<o.length;u++){const{row:f}=o[u];if(r>=f){const S={startRow:r,endRow:s,startColumn:i,endColumn:c};this._refreshArrayFormulaRangeShape(t,S);break}}}};Ye=On([Te(1,a.Inject(V.SheetInterceptorService)),Te(2,a.Inject(E.FormulaDataModel)),Te(3,a.Inject(a.ThemeService)),Te(4,j.IRenderManagerService),Te(5,a.Inject(x.SheetSkeletonManagerService)),Te(6,a.ICommandService),Te(7,a.ILogService)],Ye);var Nn=Object.getOwnPropertyDescriptor,Dn=(e,t,n,o)=>{for(var r=o>1?void 0:o?Nn(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Dt=(e,t)=>(n,o)=>t(n,o,e);const xn={tl:{size:6,color:"#409f11"}};let ze=class extends a.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(V.INTERCEPTOR_POINT.CELL_CONTENT,{effect:a.InterceptorEffectEnum.Style,handler:(n,o,r)=>{var c,u,f,S;const s=(S=(f=(u=(c=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:c[o.unitId])==null?void 0:u[o.subUnitId])==null?void 0:f[o.row])==null?void 0:S[o.col];return!E.extractFormulaError(n,!!s)||!n||(n===o.rawData&&(n={...o.rawData}),n.markers={...n==null?void 0:n.markers,...xn}),r(n)},priority:10}))}};ze=Dn([Dt(0,a.Inject(V.SheetInterceptorService)),Dt(1,a.Inject(E.FormulaDataModel))],ze);function wn(e){const t=["SUMIF","SUM","AVERAGE","IF","COUNT","SIN","MAX"];let n=t.map(o=>({label:{name:o,selectable:!1},value:o}));try{const o=e.get(le.IDescriptionService),r=t.filter(s=>!!o.getFunctionInfo(s));r.length>0&&(n=r.map(s=>({label:{name:s,selectable:!1},value:s})))}catch{}return{id:`${ee.id}.common`,commandId:ee.id,title:"formula.insert.common",tooltip:"formula.insert.tooltip",icon:"FunctionIcon",type:l.MenuItemType.SELECTOR,selections:n,hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET)}}function pe(e,t,n){return function(r){let s=[];try{s=r.get(le.IDescriptionService).getSearchListByType(e).map(({name:c})=>({label:{name:c,selectable:!1},value:c}))}catch{s=[]}return{id:`${ee.id}.${t}`,commandId:ee.id,title:`formula.functionType.${t}`,tooltip:"formula.insert.tooltip",icon:n,type:l.MenuItemType.SELECTOR,selections:s,hidden$:l.getMenuHiddenObservable(r,a.UniverInstanceType.UNIVER_SHEET)}}}const An=pe(E.FunctionType.Financial,"financial"),kn=pe(E.FunctionType.Logical,"logical"),Ln=pe(E.FunctionType.Text,"text"),Pn=pe(E.FunctionType.Date,"date"),Fn=pe(E.FunctionType.Lookup,"lookup"),$n=pe(E.FunctionType.Math,"math"),Un=pe(E.FunctionType.Statistical,"statistical"),Wn=pe(E.FunctionType.Engineering,"engineering"),Vn=pe(E.FunctionType.Information,"information"),Bn=pe(E.FunctionType.Database,"database");function ge(e){return{id:se.id,title:"formula.moreFunctions.allFunctions",tooltip:"formula.insert.tooltip",type:l.MenuItemType.BUTTON,hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:x.getCurrentRangeDisable$(e,{workbookTypes:[V.WorkbookEditablePermission],worksheetTypes:[V.WorksheetEditPermission,V.WorksheetSetCellValuePermission],rangeTypes:[V.RangeProtectionPermissionEditPoint]})}}function Hn(e){return{id:Be.id,type:l.MenuItemType.BUTTON,title:"formula.operation.copyFormulaOnly",disabled$:x.getCurrentRangeDisable$(e,{workbookTypes:[V.WorkbookCopyPermission],worksheetTypes:[V.WorksheetCopyPermission],rangeTypes:[V.RangeProtectionPermissionViewPoint]}),hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET)}}function Kn(e){return{id:He.id,type:l.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:x.menuClipboardDisabledObservable(e).pipe(Q.combineLatestWith(x.getCurrentRangeDisable$(e,{workbookTypes:[V.WorkbookEditablePermission],rangeTypes:[V.RangeProtectionPermissionEditPoint],worksheetTypes:[V.WorksheetSetCellValuePermission,V.WorksheetEditPermission]})),Q.map(([t,n])=>t||n)),hidden$:l.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET)}}const jn={[l.RibbonFormulasGroup.BASIC]:{[`${ee.id}.common`]:{order:0,menuItemFactory:wn,[se.id]:{order:0,menuItemFactory:ge}},[`${ee.id}.financial`]:{order:1,menuItemFactory:An,[se.id]:{order:0,menuItemFactory:ge}},[`${ee.id}.logical`]:{order:2,menuItemFactory:kn,[se.id]:{order:0,menuItemFactory:ge}},[`${ee.id}.text`]:{order:3,menuItemFactory:Ln,[se.id]:{order:0,menuItemFactory:ge}},[`${ee.id}.date`]:{order:4,menuItemFactory:Pn,[se.id]:{order:0,menuItemFactory:ge}},[`${ee.id}.lookup`]:{order:5,menuItemFactory:Fn,[se.id]:{order:0,menuItemFactory:ge}},[`${ee.id}.math`]:{order:6,menuItemFactory:$n,[se.id]:{order:0,menuItemFactory:ge}},[`${ee.id}.statistical`]:{order:7,menuItemFactory:Un,[se.id]:{order:0,menuItemFactory:ge}},[`${ee.id}.engineering`]:{order:8,menuItemFactory:Wn,[se.id]:{order:0,menuItemFactory:ge}},[`${ee.id}.information`]:{order:9,menuItemFactory:Vn,[se.id]:{order:0,menuItemFactory:ge}},[`${ee.id}.database`]:{order:10,menuItemFactory:Bn,[se.id]:{order:0,menuItemFactory:ge}}},[x.COPY_SPECIAL_MENU_ID]:{[Be.id]:{order:0,menuItemFactory:Hn}},[x.PASTE_SPECIAL_MENU_ID]:{[He.id]:{order:4,menuItemFactory:Kn}}};function qn(){const e=l.useDependency(le.TriggerCalculationController),t=l.useDependency(a.ICommandService),n=l.useObservable(e.progress$),o=y.useCallback(()=>{t.executeCommand(E.SetFormulaCalculationStopMutation.id)},[t]),r=y.useCallback(()=>{e.clearProgress()},[e]);return T.jsx(l.ProgressBar,{progress:n,onTerminate:o,onClearProgress:r})}function Yn(e,t){return Object.keys(E.FunctionType).filter(n=>isNaN(Number(n))&&n!=="DefinedName"&&n!=="Table"&&(t||n!=="User")).map(n=>({label:e.t(`formula.functionType.${n.toLocaleLowerCase()}`),value:`${E.FunctionType[n]}`}))}function xt(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 wt(e){const{prefix:t,value:n}=e;return T.jsxs("div",{children:[T.jsxs("span",{children:[t,"("]}),n&&n.map((o,r)=>T.jsxs("span",{children:[T.jsx("span",{children:xt(o)}),r===n.length-1?"":","]},r)),")"]})}function We(e){const{className:t,value:n,title:o}=e;return T.jsxs("div",{className:"univer-mb-2 univer-text-xs",children:[T.jsx("div",{className:H.clsx("univer-mb-2 univer-font-medium univer-text-gray-500 dark:!univer-text-gray-300",t),children:o}),T.jsx("div",{className:"univer-break-all univer-text-gray-900 dark:!univer-text-white",children:n})]})}function zn(e){const{functionInfo:t,onChange:n}=e;if(!t)return null;const[o,r]=y.useState([]),[s,i]=y.useState(t.functionParameter),[c,u]=y.useState(-1);return T.jsxs("div",{children:[T.jsx("div",{className:H.clsx("univer-h-[364px] univer-overflow-y-auto",H.scrollbarClassName),children:s.map((f,S)=>T.jsxs("div",{children:[T.jsx("div",{className:"univer-text-sm",children:f.name}),T.jsx("div",{className:"univer-mb-2 univer-mt-1"})]},S))}),T.jsx("div",{className:H.clsx("univer-flex-1 univer-p-3",H.borderLeftClassName),children:T.jsx(We,{title:c===-1?T.jsx(wt,{prefix:t.functionName,value:s}):s[c].name,value:c===-1?t.description:s[c].detail})})]})}function be({ref:e,...t}){const{icon:n,id:o,className:r,extend:s,...i}=t,c=`univerjs-icon univerjs-icon-${o} ${r||""}`.trim(),u=y.useRef(`_${Xn()}`);return At(n,`${o}`,{defIds:n.defIds,idSuffix:u.current},{ref:e,className:c,...i},s)}function At(e,t,n,o,r){return y.createElement(e.tag,{key:t,...Gn(e,n,r),...o},(Zn(e,n).children||[]).map((s,i)=>At(s,`${t}-${e.tag}-${i}`,n,void 0,r)))}function Gn(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 Zn(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 Xn(){return Math.random().toString(36).substring(2,8)}be.displayName="UniverIcon";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:"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"}}]},kt=y.forwardRef(function(t,n){return y.createElement(be,Object.assign({},t,{id:"check-mark-icon",ref:n,icon:Qn}))});kt.displayName="CheckMarkIcon";const Jn={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"}}]},Lt=y.forwardRef(function(t,n){return y.createElement(be,Object.assign({},t,{id:"close-icon",ref:n,icon:Jn}))});Lt.displayName="CloseIcon";const er={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"}}]},Pt=y.forwardRef(function(t,n){return y.createElement(be,Object.assign({},t,{id:"delete-icon",ref:n,icon:er}))});Pt.displayName="DeleteIcon";const tr={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"}}]},Ft=y.forwardRef(function(t,n){return y.createElement(be,Object.assign({},t,{id:"increase-icon",ref:n,icon:tr}))});Ft.displayName="IncreaseIcon";const nr={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"}}]},$t=y.forwardRef(function(t,n){return y.createElement(be,Object.assign({},t,{id:"more-icon",ref:n,icon:nr}))});$t.displayName="MoreIcon";const rr={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"}}]},Ut=y.forwardRef(function(t,n){return y.createElement(be,Object.assign({},t,{id:"select-range-icon",ref:n,icon:rr}))});Ut.displayName="SelectRangeIcon";function or(e){var b;const n=(b=l.useDependency(a.IConfigService).getConfig(le.PLUGIN_CONFIG_KEY_BASE))==null?void 0:b.function,{onChange:o}=e,r="-1",[s,i]=y.useState(""),[c,u]=y.useState([]),[f,S]=y.useState(0),[p,h]=y.useState(r),[g,d]=y.useState(0),[v,_]=y.useState(null),C=l.useDependency(le.IDescriptionService),I=l.useDependency(a.LocaleService),M=l.useDependency(l.ISidebarService),N=l.useObservable(M.sidebarOptions$),m=Yn(I,!!n).filter(R=>C.getSearchListByType(Number(R.value)).length>0);m.unshift({label:I.t("formula.moreFunctions.allFunctions"),value:r});const O=I.t("formula.prompt.required"),A=I.t("formula.prompt.optional");y.useEffect(()=>{k(r)},[]),y.useEffect(()=>{$(0)},[c]),y.useEffect(()=>{N!=null&&N.visible&&(i(""),u([]),S(0),h(r),d(0),_(null),k(r))},[N]);const U=R=>{if(s.trim()==="")return R;const D=new RegExp(`(${s.toLocaleUpperCase()})`);return R.split(D).filter(Boolean).map((K,z)=>K.match(D)?T.jsx("span",{className:"univer-text-red-500",children:K},z):K)},$=R=>{if(c.length===0){_(null),o(null);return}d(R);const D=C.getFunctionInfo(c[R].name);if(!D){_(null),o(null);return}_(D),o(D)};function k(R){h(R);const D=C.getSearchListByType(+R);u(D)}function P(R){i(R);const D=C.getSearchListByName(R);u(D)}function w(R){if(R.stopPropagation(),R.key==="ArrowDown"){const D=f+1;S(D===c.length?0:D)}else if(R.key==="ArrowUp"){const D=f-1;S(D===-1?c.length-1:D)}else R.key==="Enter"&&$(f)}const F=R=>{S(R)},B=()=>{S(-1)};return T.jsxs("div",{children:[T.jsxs("div",{className:"univer-flex univer-items-center univer-justify-between univer-gap-2",children:[T.jsx(H.Select,{value:p,options:m,onChange:k}),T.jsx(H.Input,{placeholder:I.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:w,value:s,onChange:P,size:"small",allowClear:!0})]}),c.length>0&&T.jsx("ul",{className:H.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",H.borderClassName,H.scrollbarClassName),onKeyDown:w,tabIndex:-1,children:c.map(({name:R},D)=>T.jsxs("li",{className:H.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":f===D}),onMouseEnter:()=>F(D),onMouseLeave:B,onClick:()=>$(D),children:[g===D&&T.jsx(kt,{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"}),T.jsx("span",{className:"univer-block",children:U(R)})]},D))}),v&&T.jsxs("div",{className:H.clsx("univer-mx-0 univer-my-2 univer-overflow-y-auto",H.scrollbarClassName),children:[T.jsx(We,{title:v.functionName,value:v.description}),T.jsx(We,{title:I.t("formula.moreFunctions.syntax"),value:T.jsx(wt,{prefix:v.functionName,value:v.functionParameter})}),T.jsx(We,{title:I.t("formula.prompt.helpExample"),value:`${v.functionName}(${v.functionParameter.map(R=>R.example).join(",")})`}),v.functionParameter&&v.functionParameter.map(R=>T.jsx(We,{title:R.name,value:`${R.require?O:A} ${R.detail}`},R.name))]})]})}function sr(){const e=x.useActiveWorkbook(),[t,n]=y.useState(!0),[o,r]=y.useState(!1),[s,i]=y.useState(null);l.useDependency(x.IEditorBridgeService);const c=l.useDependency(a.LocaleService),u=l.useDependency(J.IEditorService),f=l.useDependency(a.IUniverInstanceService),S=l.useDependency(a.ICommandService);function p(){n(!t),r(!o)}function h(){const g=V.getSheetCommandTarget(f);if(!g)return;S.executeCommand(x.SetCellEditVisibleOperation.id,{visible:!0,unitId:g.unitId,eventType:j.DeviceInputEventType.Dblclick});const d=u.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),v=u.getEditor(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),_=`=${s==null?void 0:s.functionName}(`;d==null||d.replaceText(_),v==null||v.replaceText(_,!1)}return T.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&&T.jsx(or,{onChange:i}),o&&T.jsx(zn,{functionInfo:s,onChange:()=>{}}),T.jsxs("div",{className:"univer-flex univer-justify-end",children:[o&&T.jsx(H.Button,{variant:"primary",onClick:p,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.next")}),o&&T.jsx(H.Button,{onClick:p,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.prev")}),t&&!!e&&T.jsx(H.Button,{disabled:!s,variant:"primary",onClick:h,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.confirm")})]})]})}const ir="meta_key_ctrl_And_Shift";function cr(e){return e.getContextValue(a.FOCUSING_DOC)&&e.getContextValue(a.FOCUSING_UNIVER_EDITOR)}const Ge=[l.KeyCode.ARROW_DOWN,l.KeyCode.ARROW_UP,l.KeyCode.ARROW_LEFT,l.KeyCode.ARROW_RIGHT],ar=[...Ge,l.KeyCode.ENTER,l.KeyCode.TAB,l.KeyCode.ESC];function lr(){const e=[];for(const t of ar)e.push({id:Re.id,binding:t,preconditions:n=>x.whenFormulaEditorActivated(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t}});return e}function ur(){const e=[];for(const t of Ge)e.push({id:Re.id,binding:t|l.MetaKeys.SHIFT,preconditions:n=>x.whenFormulaEditorActivated(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t,metaKey:l.MetaKeys.SHIFT}});return e}function dr(){const e=[];for(const t of Ge)e.push({id:Re.id,binding:t|l.MetaKeys.CTRL_COMMAND,preconditions:n=>x.whenFormulaEditorActivated(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t,metaKey:l.MetaKeys.CTRL_COMMAND}});return e}function fr(){const e=[];for(const t of Ge)e.push({id:Re.id,binding:t|l.MetaKeys.SHIFT|l.MetaKeys.CTRL_COMMAND,preconditions:n=>x.whenFormulaEditorActivated(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t,metaKey:ir}});return e}const hr={id:at.id,binding:l.KeyCode.F4,preconditions:e=>x.whenFormulaEditorActivated(e)};function gr(){const e=[];for(const t of[l.KeyCode.ENTER,l.KeyCode.TAB,l.KeyCode.ARROW_DOWN,l.KeyCode.ARROW_UP])e.push({id:Re.id,binding:t,preconditions:n=>cr(n),staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}const Sr={id:le.QuickSumCommand.id,binding:l.MetaKeys.ALT|l.KeyCode.EQUAL,preconditions:x.whenSheetEditorFocused,mac:l.MetaKeys.CTRL_COMMAND|l.MetaKeys.ALT|l.KeyCode.EQUAL,description:"shortcut.sheets-formula-ui.quick-sum",group:"4_sheet-edit"};var pr=Object.getOwnPropertyDescriptor,vr=(e,t,n,o)=>{for(var r=o>1?void 0:o?pr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Me=(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(){[Be,He,ee,se,Tt,It,Re,at].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...lr(),...ur(),...dr(),...fr(),...gr(),Sr,hr].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(x.SheetsUIPart.FORMULA_AUX,()=>l.connectInjector(qn,this._injector))),this._componentManager.register(Rt,sr)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[Ye]))}};Ze=vr([Me(0,a.Inject(a.Injector)),Me(1,l.IMenuManagerService),Me(2,a.ICommandService),Me(3,l.IShortcutService),Me(4,l.IUIPartsService),Me(5,j.IRenderManagerService),Me(6,a.Inject(l.ComponentManager))],Ze);var mr=Object.getOwnPropertyDescriptor,Cr=(e,t,n,o)=>{for(var r=o>1?void 0:o?mr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},dt=(e,t)=>(n,o)=>t(n,o,e);let Xe=class extends a.Disposable{constructor(e,t,n){super(),this._imageFormulaCellInterceptorController=e,this._renderManagerService=t,this._univerInstanceService=n,this._imageFormulaCellInterceptorController.registerRefreshRenderFunction(()=>{const o=this._univerInstanceService.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET);if(!o)return;const r=this._renderManagerService.getRenderById(o.getUnitId());if(!r)return;r.with(x.SheetSkeletonManagerService).reCalculate();const s=r.mainComponent;s&&s.makeDirty()})}};Xe=Cr([dt(0,a.Inject(le.ImageFormulaCellInterceptorController)),dt(1,j.IRenderManagerService),dt(2,a.IUniverInstanceService)],Xe);class ft{constructor(){q(this,"_currentSelector$",new Q.BehaviorSubject(null));q(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 Ir=Object.getOwnPropertyDescriptor,yr=(e,t,n,o)=>{for(var r=o>1?void 0:o?Ir(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Ae=(e,t)=>(n,o)=>t(n,o,e);L.RefSelectionsRenderService=class extends x.BaseSelectionRenderService{constructor(n,o,r,s,i,c,u){super(o,r,s,i,c);q(this,"_workbookSelections");q(this,"_eventDisposables");this._context=n,this._contextService=c,this._refSelectionsService=u,this._workbookSelections=this._refSelectionsService.getWorkbookSelections(this._context.unitId),this._initSelectionChangeListener(),this._initSkeletonChangeListener(),this._initUserActionSyncListener(),this._setSelectionStyle(_r(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,u=new a.DisposableCollection;return u.add(s==null?void 0:s.onPointerDown$.subscribeEvent((f,S)=>{this.inRefSelectionMode()&&(this._onPointerDown(f,s.zIndex+1,a.RANGE_TYPE.NORMAL,this._getActiveViewport(f)),f.button!==2&&S.stopPropagation())})),u.add(o==null?void 0:o.onPointerDown$.subscribeEvent((f,S)=>{if(!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:h}=x.getCoordByOffset(f.offsetX,f.offsetY,c,p);x.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,a.RANGE_TYPE.ROW)||(this._onPointerDown(f,(s.zIndex||1)+1,a.RANGE_TYPE.ROW,this._getActiveViewport(f),j.ScrollTimerType.Y),f.button!==2&&S.stopPropagation())})),u.add(r==null?void 0:r.onPointerDown$.subscribeEvent((f,S)=>{if(!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:h}=x.getCoordByOffset(f.offsetX,f.offsetY,c,p);x.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,a.RANGE_TYPE.COLUMN)||(this._onPointerDown(f,(s.zIndex||1)+1,a.RANGE_TYPE.COLUMN,this._getActiveViewport(f),j.ScrollTimerType.X),f.button!==2&&S.stopPropagation())})),u.add(i==null?void 0:i.onPointerDown$.subscribeEvent((f,S)=>{if(this._reset(),!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,h=x.getAllSelection(p);this._addSelectionControlByModelData(h),this._selectionMoveStart$.next(this.getSelectionDataWithStyle());const g=c.onPointerUp$.subscribeEvent(()=>{g.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});f.button!==2&&S.stopPropagation()})),u}_addSelectionControlByModelData(n){var c;const o=this._skeleton,r=(c=n.style)!=null?c:x.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,V.SelectionMoveType.MOVE_START)})),this.disposeWithMe(this.selectionMoving$.subscribe(n=>{this._updateSelections(n,V.SelectionMoveType.MOVING)})),this.disposeWithMe(this.selectionMoveEnd$.subscribe(n=>{this._updateSelections(n,V.SelectionMoveType.MOVE_END)}))}_updateSelections(n,o){const s=this._context.unit.getActiveSheet().getSheetId();n.length!==0&&this._workbookSelections.setSelections(s,n.map(i=>V.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 x.getSheetObject(this._context.unit,this._context)}_onPointerDown(n,o=0,r=a.RANGE_TYPE.NORMAL,s,i=j.ScrollTimerType.ALL){var P;this._rangeType=r;const c=this._skeleton,u=this._scene;if(!u||!c)return;s&&(this._activeViewport=s);const{offsetX:f,offsetY:S}=n,p=u.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!p)return;const h=u.getCoordRelativeToViewport(j.Vector2.FromArray([f,S])),{x:g,y:d}=h;this._startViewportPosX=g,this._startViewportPosY=d;const v=u.getScrollXYInfoByViewport(h),{scaleX:_,scaleY:C}=u.getAncestorScale(),I=this._skeleton.getCellByOffset(g,d,_,C,v);if(!I)return;switch(r){case a.RANGE_TYPE.NORMAL:break;case a.RANGE_TYPE.ROW:I.startColumn=0,I.endColumn=this._skeleton.getColumnCount()-1;break;case a.RANGE_TYPE.COLUMN:I.startRow=0,I.endRow=this._skeleton.getRowCount()-1;break;case a.RANGE_TYPE.ALL:I.startRow=0,I.startColumn=0,I.endRow=this._skeleton.getRowCount()-1,I.endColumn=this._skeleton.getColumnCount()-1}let M={range:I,primary:I,style:null};(I.isMerged||I.isMergedMainCell)&&(M={range:{...I,startRow:I.startRow,endRow:I.startRow,startColumn:I.startColumn,endColumn:I.startColumn},primary:{...I,actualRow:I.startRow,actualColumn:I.startColumn,startRow:I.startRow,endRow:I.startRow,startColumn:I.startColumn,endColumn:I.startColumn},style:null}),M.range.rangeType=r;const N=x.attachSelectionWithCoord(M,this._skeleton);this._startRangeWhenPointerDown={...N.rangeWithCoord};const m={...N.rangeWithCoord,rangeType:r};let O=this.getActiveSelectionControl();const A=this.getSelectionControls();for(const w of A){if(n.button===2&&a.Rectangle.contains(w.model,m)){O=w;return}if(w.model.isEqual(m)){O=w;break}}this._checkClearPreviousControls(n);const U=O==null?void 0:O.model.currentCell,$=n.shiftKey&&U,k=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;$&&U?this._makeSelectionByTwoCells(U,m,c,r,O):k&&O?O.updateRangeBySelectionWithCoord(N):O=this.newSelectionControl(u,c,M);for(let w=0;w<this.getSelectionControls().length-1;w++)this.getSelectionControls()[w].clearHighlight();this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),u.disableObjectsEvent(),this._clearUpdatingListeners(),this._addEndingListeners(),(P=u.getTransformer())==null||P.clearSelectedObjects(),this._setupPointerMoveListener(p,O,r,i,g,d),this._escapeShortcutDisposable=this._shortcutService.forceEscape(),this._scenePointerUpSub=u.onPointerUp$.subscribeEvent(()=>{var w;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(w=this._escapeShortcutDisposable)==null||w.dispose(),this._escapeShortcutDisposable=null})}newSelectionControl(n,o,r){const s=this.getSelectionControls().length,{rowHeaderWidth:i,columnHeaderHeight:c}=o,u=new x.SelectionControl(n,s,this._themeService,{highlightHeader:this._highlightHeader,enableAutoFill:!1,rowHeaderWidth:i,columnHeaderHeight:c}),f=x.attachSelectionWithCoord(r,o);return u.updateRangeBySelectionWithCoord(f),this._selectionControls.push(u),u.setControlExtension({skeleton:o,scene:n,themeService:this._themeService,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),u}},L.RefSelectionsRenderService=yr([Ae(1,a.Inject(a.Injector)),Ae(2,a.Inject(a.ThemeService)),Ae(3,l.IShortcutService),Ae(4,a.Inject(x.SheetSkeletonManagerService)),Ae(5,a.IContextService),Ae(6,V.IRefSelectionsService)],L.RefSelectionsRenderService);function _r(e){const t=x.genNormalSelectionStyle(e);return t.widgets={tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},t}const ht=(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 u=s.length;r.currentIndex+=u}return(n?r.currentIndex===t:t>c&&t<=r.currentIndex)&&(o=i,r.isFinish=!0),r},{currentIndex:0,isFinish:!1}),o},Wt=(e,t)=>{const n=e[t];let o=-1;if(!n||typeof n=="string"||n.nodeType!==E.sequenceNodeType.REFERENCE)return-1;for(let r=0;r<=t;r++){const s=e[r];typeof s!="string"&&s.nodeType===E.sequenceNodeType.REFERENCE&&o++}return o},Er=(e,t=100)=>{y.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 Vt(e,t,n){const o=l.useDependency(J.IEditorService),r=y.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 M;const u=o.getEditor(e);if(!u)return;const f=u.getBoundingClientRect(),{marginTop:S=0,marginBottom:p=0}=u.getDocumentData().documentStyle,h=u.getSkeleton();if(!h)return;const g=(M=h.getSkeletonData())==null?void 0:M.pages[0].height;let{left:d,top:v,right:_,bottom:C}=f;v=v+S,C=g?v+g:C-p;const I=r.getValue();if(!(I.left===d&&I.top===v&&I.right===_&&I.bottom===C))return r.next({left:d-1,right:_+1,top:v-1,bottom:C+1}),f});return y.useEffect(()=>{t&&c()},[e,o,i.unitAdded$,c,t,...n!=null?n:[]]),Er(c),y.useEffect(()=>{const u=s.scrollEvent$.pipe(Q.throttleTime(100)).subscribe(c);return()=>{u.unsubscribe()}},[]),[r,c]}const Oe=e=>{const t=y.useRef(e);return t.current=e,t},Rr=(e,t,n)=>{const o=l.useDependency(Ke),r=l.useDependency(le.IDescriptionService),s=l.useDependency(E.LexerTreeBuilder),[i,c]=y.useState(),[u,f]=y.useState(-1),[S,p]=y.useState(!0),h=Oe(S),g=y.useRef(t);g.current=t;const d=()=>{c(void 0),f(-1),p(!1)};return y.useEffect(()=>{const v=s.sequenceNodesBuilder(t.slice(1));o.setSequenceNodes(v!=null?v:[])},[t]),y.useEffect(()=>{if(n&&e){const v=n.selectionChange$.pipe(Q.debounceTime(50)).subscribe(C=>{if(C.textRanges.length===1){const[I]=C.textRanges;if(I.collapsed&&h.current){const{startOffset:M}=I,N=o.getCurrentSequenceNodeIndex(M-2),m=o.getCurrentSequenceNodeByIndex(N),O=o.getCurrentSequenceNodeByIndex(N+1);if(m)if(typeof m!="string"&&m.nodeType===3&&!r.hasDefinedNameDescription(m.token.trim())&&O===E.matchToken.OPEN_BRACKET){const A=r.getFunctionInfo(m.token);c(A),f(-1);return}else{const A=s.getFunctionAndParameter(`${g.current}A`,M-1);if(A){const{functionName:U,paramIndex:$}=A,k=r.getFunctionInfo(U);c(k),f($);return}}}}c(void 0),f(-1)}),_=n.selectionChange$.pipe(Q.filter(C=>C.textRanges.length===1),Q.map(C=>C.textRanges[0].startOffset),Q.distinctUntilChanged()).subscribe(()=>{p(!0)});return()=>{v.unsubscribe(),_.unsubscribe()}}},[n,e]),y.useEffect(()=>{e||d()},[e]),{functionInfo:i,paramIndex:u,reset:d}},Tr=({onClick:e})=>T.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:"?"}),gt=({className:e,title:t,value:n})=>T.jsxs("div",{className:"univer-my-2",children:[T.jsx("div",{className:H.clsx("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",e),children:t}),T.jsx("div",{className:"univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",children:n})]}),br=e=>{const{prefix:t,value:n,active:o,onClick:r}=e;return T.jsxs("div",{children:[T.jsxs("span",{children:[t,"("]}),n&&n.map((s,i)=>T.jsxs("span",{children:[T.jsx("span",{className:o===i?"univer-text-primary-500":"",onClick:()=>r(i),children:xt(s)}),i===n.length-1?"":","]},s.name)),")"]})},Bt=()=>{};function Mr(e){const{onParamsSwitch:t=Bt,onClose:n=Bt,isFocus:o,editor:r,formulaText:s}=e,{functionInfo:i,paramIndex:c,reset:u}=Rr(o,s,r),f=l.useDependency(x.IEditorBridgeService),S=!l.useObservable(f.helpFunctionVisible$),[p,h]=y.useState(!1),g=l.useDependency(a.LocaleService),d=g.t("formula.prompt.required"),v=g.t("formula.prompt.optional"),_=r.getEditorId(),[C]=Vt(_,!!i,[i,c]);function I(m){t&&t(m)}const M=l.useEvent(m=>{f.helpFunctionVisible$.next(!m)}),N=()=>{M(!0),n()};return i?S?T.jsx(l.RectPopup,{portal:!0,anchorRect$:C,direction:"left-center",children:T.jsx(Tr,{onClick:()=>M(!1)})},"hidden"):T.jsx(l.RectPopup,{portal:!0,onClickOutside:()=>u(),anchorRect$:C,direction:"vertical",children:T.jsxs("div",{className:H.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",H.borderClassName),children:[T.jsxs("div",{className:H.clsx("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",H.borderTopClassName),style:{overflowWrap:"anywhere"},children:[T.jsx(br,{prefix:i.functionName,value:i.functionParameter,active:c,onClick:I}),T.jsxs("div",{className:"univer-flex",children:[T.jsx("div",{className:"univer-ml-2 univer-flex univer-size-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:p?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>h(!p),children:T.jsx($t,{})}),T.jsx("div",{className:"univer-ml-2 univer-flex univer-size-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:T.jsx(Lt,{})})]})]}),T.jsx("div",{className:H.clsx("univer-box-border univer-max-h-[350px] univer-overflow-y-auto univer-px-4 univer-pb-3 univer-pt-0",H.scrollbarClassName),style:{height:p?"unset":0,padding:p?"revert-layer":0},children:T.jsxs("div",{className:"univer-mt-3",children:[T.jsx(gt,{title:g.t("formula.prompt.helpExample"),value:`${i.functionName}(${i.functionParameter.map(m=>m.example).join(",")})`}),T.jsx(gt,{title:g.t("formula.prompt.helpAbstract"),value:i.description}),i&&i.functionParameter&&i.functionParameter.map((m,O)=>T.jsx(gt,{className:c===O?"univer-text-primary-500":"",title:m.name,value:`${m.require?d:v} ${m.detail}`},O))]})})]})},"show"):null}const Or=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
|
+
`,u=Math.max(c.length-2,0);e.setSelectionRanges([{startOffset:u,endOffset:u}])}else e.setSelectionRanges(i)}})};function Nr(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 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 Dr(e){var A;const{editorId:t,isFocus:n,disableOnClick:o,unitId:r,subUnitId:s}=e,i=l.useDependency(j.IRenderManagerService),c=l.useDependency(a.IUniverInstanceService),u=i.getRenderById(r),f=i.getRenderById(t),S=f==null?void 0:f.with(J.DocSelectionRenderService),p=l.useDependency(mt.DocSelectionManagerService),h=l.useDependency(a.Injector),[g,d]=y.useState(0),v=l.useDependency(E.LexerTreeBuilder),_=y.useRef(!0),C=u==null?void 0:u.with(L.RefSelectionsRenderService),I=Oe(g),M=c.getUnit(r,a.UniverInstanceType.UNIVER_SHEET),N=M==null?void 0:M.getSheetBySheetId(s),m=l.useEvent(U=>{C&&C.setSkipLastEnabled(U===1||U===3||U===4),I.current=U,d(U)}),O=l.useEvent(()=>{var z,re,ue;const U=c.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET);if(!U)return;const $=U.getActiveSheet(),k=S==null?void 0:S.getActiveTextRange(),P=k!=null&&k.collapsed?k.startOffset:-1,w=Nr(h);if(!w)return;const F=(z=w==null?void 0:w.dataStream)==null?void 0:z.slice(0,-2),B=((re=v.sequenceNodesBuilder(F))!=null?re:[]).map(G=>typeof G=="object"?G.nodeType===E.sequenceNodeType.REFERENCE?{...G,range:E.deserializeRangeWithSheetWithCache(G.token)}:{...G,range:void 0}:G),b=F[P-1],R=F[P],D=B.find(G=>typeof G=="object"&&G.nodeType===E.sequenceNodeType.REFERENCE&&P===G.endIndex+2),W=b&&E.matchRefDrawToken(b)&&(!R||E.isFormulaLexerToken(R)&&R!==E.matchToken.OPEN_BRACKET),K=!!D;if((F==null?void 0:F.substring(0,1))==="="&&(W||K))if(K){if(_.current)return;const{sheetName:G,unitId:te}=D.range,ke=(ue=c.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:ue.getUnitId();te&&te!==ke?m(4):!G&&$.getSheetId()===(N==null?void 0:N.getSheetId())||G===$.getName()?m(2):m(3)}else _.current=!1,m(1);else m(0)});return y.useEffect(()=>{const U=p.textSelection$.pipe(Q.filter($=>$.unitId===t)).subscribe(()=>{O()});return()=>U.unsubscribe()},[O,p.textSelection$,t]),y.useEffect(()=>{n||(m(0),_.current=!0)},[n,m]),y.useEffect(()=>{var $;if(!o)return;const U=($=f==null?void 0:f.mainComponent)==null?void 0:$.onPointerDown$.subscribeEvent(()=>{m(0),_.current=!0});return()=>U==null?void 0:U.unsubscribe()},[o,(A=f==null?void 0:f.mainComponent)==null?void 0:A.onPointerDown$,m]),y.useEffect(()=>{if(!n)return;const U=M==null?void 0:M.activeSheet$.subscribe(()=>{O()}),$=c.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(()=>{O()});return()=>{U==null||U.unsubscribe(),$==null||$.unsubscribe()}},[O,n,M==null?void 0:M.activeSheet$,c.getCurrentTypeOfUnit$]),{isSelecting:g,isSelectingRef:I}}const xr=()=>{const e=l.useDependency(E.LexerTreeBuilder);return y.useCallback(n=>e.sequenceNodesBuilder(n)||[],[e])};function wr(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 Ht(e){var M,N,m;const{unitId:t,subUnitId:n,currentWorkbook:o,refSelections:r,editor:s,refSelectionsService:i,refSelectionsRenderService:c,sheetSkeletonManagerService:u,themeService:f,univerInstanceService:S}=e,p=o.getUnitId(),h=S.getUnit(t,a.UniverInstanceType.UNIVER_SHEET),g=h==null?void 0:h.getActiveSheet(),d=[];if(!h||!g){i.setSelections(d);return}const v=g.getSheetId(),_=O=>{var A;return(A=h==null?void 0:h.getSheetBySheetName(O))==null?void 0:A.getSheetId()};if(!((M=u==null?void 0:u.getWorksheetSkeleton(v))==null?void 0:M.skeleton))return;const I=[];for(let O=0,A=r.length;O<A;O++){const U=r[O],{themeColor:$,token:k,refIndex:P,endIndex:w}=U,F=E.deserializeRangeWithSheet(k),{unitId:B,sheetName:b,range:R}=F,D=_(b);if(!D&&b||p!==t&&B!==p||B&&B!==p||D&&D!==v||!D&&v!==n)continue;const W=V.setEndForRange(R,g.getRowCount(),g.getColumnCount());W.unitId=t,W.sheetId=v,d.push({range:W,primary:null,style:wr(f,$,P.toString())}),I.push(w)}if(s){const O=(m=(N=s.getSelectionRanges())==null?void 0:N[0])==null?void 0:m.startOffset,A=I.findIndex(U=>U+2===O);A!==-1?c==null||c.setActiveSelectionIndex(A):c==null||c.resetActiveSelectionIndex()}return d}function Ar(e,t){const n=l.useDependency(a.IUniverInstanceService),o=l.useDependency(a.ThemeService),r=l.useDependency(V.IRefSelectionsService),s=l.useDependency(j.IRenderManagerService),i=l.useObservable(y.useMemo(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[n])),c=i?s.getRenderById(i.getUnitId()):null,u=c==null?void 0:c.with(L.RefSelectionsRenderService),f=c==null?void 0:c.with(x.SheetSkeletonManagerService),S=l.useEvent((p,h)=>{const g=n.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET);if(!g||u!=null&&u.selectionMoving)return;const d=Ht({unitId:e,subUnitId:t,currentWorkbook:g,refSelections:p,editor:h,refSelectionsService:r,refSelectionsRenderService:u,sheetSkeletonManagerService:f,themeService:o,univerInstanceService:n});if(!d)return;((u==null?void 0:u.getSelectionControls())||[]).length===d.length?u==null||u.resetSelectionsByModelData(d):r.setSelections(d)});return y.useEffect(()=>()=>{u==null||u.resetActiveSelectionIndex()},[u]),S}function Kt(e=""){const t=l.useDependency(le.IDescriptionService),n=kr(),o=l.useDependency(a.ICommandService),r=y.useMemo(()=>e.length,[e]);return l.useEvent((i,c,u=!0,f)=>{const S=i.getDocumentData(),p=i.getEditorId();if(!S)return[];const h=S.body;if(!h)return[];const g=h.dataStream.slice(0,h.dataStream.length-2),d={dataStream:"",...S.body};if(!g.startsWith(e))return[];if(c==null||c.length===0)return d.textRuns=[],o.syncExecuteCommand(J.ReplaceTextRunsCommand.id,{unitId:p,body:a.getBodySlice(d,0,d.dataStream.length-2)}),[];{const{textRuns:v,refSelections:_}=Lr(t,n,c);r&&v.forEach(M=>{M.ed=M.ed+r,M.st=M.st+r}),d.textRuns=[{st:0,ed:1,ts:{fs:11}},...v];const C=c.reduce((M,N)=>typeof N=="string"?`${M}${N}`:`${M}${N.token}`,"");d.dataStream=`${e}${C}\r
|
|
3
|
+
`;let I;if(u){I=i.getSelectionRanges();const M=d.dataStream.length-2+r;I.forEach(N=>{N.startOffset=Math.max(0,Math.min(N.startOffset,M)),N.endOffset=Math.max(0,Math.min(N.endOffset,M))})}return o.syncExecuteCommand(J.ReplaceTextRunsCommand.id,{unitId:p,body:a.getBodySlice(d,0,d.dataStream.length-2),textRanges:f!=null?f:I}),_}})}function kr(){const e=l.useDependency(a.ThemeService),t=e.getCurrentTheme();return y.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 Lr(e,t,n){const{formulaRefColors:o,numberColor:r,stringColor:s,plainTextColor:i}=t,c=[],u=[],f=new Map;let S=0;for(let p=0,h=n.length;p<h;p++){const g=n[p];if(typeof g=="string"){const M=c[c.length-1],N=M?M.ed:0,m=N+g.length;c.push({st:N,ed:m,ts:{cl:{rgb:i},fs:11}});continue}if(e.hasDefinedNameDescription(g.token.trim())){c.push({st:g.startIndex,ed:g.endIndex+1,ts:{cl:{rgb:i},fs:11}});continue}const{startIndex:d,endIndex:v,nodeType:_,token:C}=g;let I="";if(_===E.sequenceNodeType.REFERENCE){if(f.has(C))I=f.get(C);else{const M=S%o.length;I=o[M],f.set(C,I),S++}u.push({refIndex:p,themeColor:I,token:C,startIndex:g.startIndex,endIndex:g.endIndex,index:u.length})}else _===E.sequenceNodeType.NUMBER?I=r:(_===E.sequenceNodeType.STRING||_===E.sequenceNodeType.ARRAY)&&(I=s);I&&I.length>0?c.push({st:d,ed:v+1,ts:{cl:{rgb:I},fs:11}}):c.push({st:d,ed:v+1,ts:{cl:{rgb:i},fs:11}})}return{textRuns:c,refSelections:u}}const Pr=(e,t,n,o)=>{const r=l.useDependency(a.ICommandService),s=l.useDependency(l.IShortcutService),i=y.useRef(t);i.current=t;const c=y.useRef(o);c.current=o,y.useEffect(()=>{if(!n||!e)return;const f=`sheet.formula-embedding-editor.${n.getEditorId()}`,S=new a.DisposableCollection,p=(d,v)=>{if(c.current){c.current(d,v);return}let _=a.Direction.LEFT;d===l.KeyCode.ARROW_DOWN?_=a.Direction.DOWN:d===l.KeyCode.ARROW_UP?_=a.Direction.UP:d===l.KeyCode.ARROW_RIGHT&&(_=a.Direction.RIGHT),v===l.MetaKeys.SHIFT?r.executeCommand(J.MoveSelectionOperation.id,{direction:_}):r.executeCommand(J.MoveCursorOperation.id,{direction:_})},h=(d,v)=>{let _=a.Direction.DOWN;d===l.KeyCode.ARROW_DOWN?_=a.Direction.DOWN:d===l.KeyCode.ARROW_UP?_=a.Direction.UP:d===l.KeyCode.ARROW_LEFT?_=a.Direction.LEFT:d===l.KeyCode.ARROW_RIGHT&&(_=a.Direction.RIGHT),i.current?v===l.MetaKeys.CTRL_COMMAND?r.executeCommand(x.MoveSelectionCommand.id,{direction:_,jumpOver:x.JumpOver.moveGap,extra:"formula-editor",fromCurrentSelection:i.current===me.NEED_ADD||i.current===me.EDIT_OTHER_SHEET_REFERENCE}):v===l.MetaKeys.SHIFT?r.executeCommand(x.ExpandSelectionCommand.id,{direction:_,extra:"formula-editor"}):v===(l.MetaKeys.CTRL_COMMAND|l.MetaKeys.SHIFT)?r.executeCommand(x.ExpandSelectionCommand.id,{direction:_,jumpOver:x.JumpOver.moveGap,extra:"formula-editor"}):r.executeCommand(x.MoveSelectionCommand.id,{direction:_,extra:"formula-editor",fromCurrentSelection:i.current===me.NEED_ADD||i.current===me.EDIT_OTHER_SHEET_REFERENCE}):p(d,v)};return S.add(r.registerCommand({id:f,type:a.CommandType.OPERATION,handler(d,v){const{keyCode:_,metaKey:C}=v;h(_,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:d,metaKey:v})=>({id:f,binding:v?d|v:d,preconditions:()=>!0,priority:900,staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keyCode:d,metaKey:v}})).forEach(d=>{S.add(s.registerShortcut(d))}),()=>{S.dispose()}},[r,n,e,s])},Fr=(e,t,n,o,r=!0)=>{var g;const s=l.useDependency(j.IRenderManagerService),i=l.useDependency(a.IContextService),c=l.useDependency(l.IContextMenuService),u=l.useDependency(V.IRefSelectionsService),f=l.useDependency(a.IUniverInstanceService),S=l.useObservable(y.useMemo(()=>f.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[f])),p=s.getRenderById((g=S==null?void 0:S.getUnitId())!=null?g:""),h=p==null?void 0:p.with(L.RefSelectionsRenderService);y.useLayoutEffect(()=>{if(e)return i.setContextValue(a.EDITOR_ACTIVATED,!0),r&&c.disable(),()=>{const d=f.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);(d==null?void 0:d.getUnitId())===o&&i.setContextValue(a.EDITOR_ACTIVATED,!1),r&&c.enable(),u.clear()}},[i,e,u,r,o]),y.useLayoutEffect(()=>{if(e&&t){const d=h==null?void 0:h.enableSelectionChanging();return i.setContextValue(V.REF_SELECTIONS_ENABLED,!0),()=>{i.setContextValue(V.REF_SELECTIONS_ENABLED,!1),d==null||d.dispose()}}},[i,e,h,t]),y.useEffect(()=>{e&&(h==null||h.setSkipLastEnabled(!1))},[e,h])},$r=(e,t,n)=>{const o=l.useDependency(a.IUniverInstanceService),r=l.useDependency(V.SheetsSelectionsService);return y.useCallback(()=>{if(e){const i=[...r.getWorkbookSelections(t).getSelectionsOfWorksheet(n)],c=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),u=c==null?void 0:c.getActiveSheet();(c==null?void 0:c.getUnitId())!==t&&o.setCurrentUnitForType(t),u&&u.getSheetId()===n&&r.setSelections(i)}},[e,r,n,t,o])},Ur=e=>e.reduce((t,n)=>typeof n=="string"?t+n.length:t+n.token.length,0),St=e=>e.map(t=>typeof t=="string"?t:t.token).join(""),Qe=(e,t=!1,n="",o=!1)=>!t&&!o?e.map(r=>E.serializeRange(r.range)):e.map(r=>o?E.serializeRangeToRefString(r):r.sheetName!==""&&r.sheetName!==n?E.serializeRangeWithSheet(r.sheetName,r.range):E.serializeRange(r.range)),Wr=e=>{var S,p,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=((p=(S=t==null?void 0:t.getDocumentData().body)==null?void 0:S.dataStream)!=null?p:`\r
|
|
4
|
+
`).slice(0,-2),c=(h=n.sequenceNodesBuilder(i.slice(1)))!=null?h:[],u=ht(c,s,!1),f=Wt(c,u);return{nodeIndex:u,updatingRefIndex:f,sequenceNodes:c,offset:s}},Vr=(()=>{}),Br=(e,t,n,o,r,s,i,c,u,f=Vr)=>{var P;const S=l.useDependency(j.IRenderManagerService),p=l.useDependency(a.IUniverInstanceService),h=l.useDependency(a.ICommandService),g=l.useDependency(mt.DocSelectionManagerService),d=l.useDependency(a.ThemeService),v=l.useDependency(E.LexerTreeBuilder),_=p.getUnit(o),C=l.useEvent((w,F)=>{var B,b,R;return(R=(b=(B=p.getUnit(w))==null?void 0:B.getSheetBySheetId(F))==null?void 0:b.getName())!=null?R:""}),I=y.useMemo(()=>C(o,r),[C,r,o]),M=l.useObservable(_==null?void 0:_.activeSheet$),N=Oe({activeSheet:M,sheetName:I}),m=l.useObservable(y.useMemo(()=>p.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[p])),O=S.getRenderById((P=m==null?void 0:m.getUnitId())!=null?P:""),A=O==null?void 0:O.with(L.RefSelectionsRenderService),U=O==null?void 0:O.with(x.SheetSkeletonManagerService),$=l.useDependency(V.IRefSelectionsService),k=l.useEvent((w,F,B)=>{var z,re,ue,G,te,ke,Le,tt,Ce,nt;const b=Wr({editor:u,lexerTreeBuilder:v});if(!b)return;const{nodeIndex:R,updatingRefIndex:D,sequenceNodes:W,offset:K}=b;if(n.current===me.NEED_ADD)if(K!==0){if(R===-1&&W.length)return;const Y=w[w.length-1],ne=W.splice(R+1),de=(z=Y.sheetId)!=null?z:r,oe={range:Y,unitId:(re=Y.unitId)!=null?re:m.getUnitId(),sheetName:C((ue=Y.unitId)!=null?ue:m.getUnitId(),de)},ae=de!==r,fe=(m==null?void 0:m.getUnitId())!==o,Se=Qe([oe],i&&(ae||fe),I,fe);W.push({token:Se[0],nodeType:E.sequenceNodeType.REFERENCE});const Ne=[...W,...ne],De=St(Ne);f(De,Ur(W),F)}else{const Y=w[w.length-1],ne=(G=Y.sheetId)!=null?G:r,de={range:Y,unitId:(te=Y.unitId)!=null?te:m.getUnitId(),sheetName:C((ke=Y.unitId)!=null?ke:m.getUnitId(),ne)},oe=ne!==r,ae=(m==null?void 0:m.getUnitId())!==o,fe=Qe([de],i&&(oe||ae),I,ae);W.unshift({token:fe[0],nodeType:E.sequenceNodeType.REFERENCE});const Se=St(W);f(Se,fe[0].length,F)}else if(n.current===me.EDIT_OTHER_SHEET_REFERENCE||n.current===me.EDIT_OTHER_WORKBOOK_REFERENCE){const Y=w.pop();if(!Y)return;const ne=W[R];if(typeof ne=="object"&&ne.nodeType===E.sequenceNodeType.REFERENCE){const de=ne.token;(m==null?void 0:m.getUnitId())!==o?ne.token=E.serializeRangeWithSpreadsheet((Le=m==null?void 0:m.getUnitId())!=null?Le:"",I,Y):ne.token=I===(M==null?void 0:M.getName())?E.serializeRange(Y):E.serializeRangeWithSheet(M.getName(),Y);const ae=K+(ne.token.length-de.length);f(E.generateStringWithSequence(W),ae,F)}}else{const Y=[...w];if(!B&&D!==-1){const Z=Y.pop();Z&&Y.splice(D,0,Z)}let ne=0;const de=W.map(Z=>{var ve,ye,Pe,xe;if(typeof Z=="string")return Z;if(Z.nodeType===E.sequenceNodeType.REFERENCE){const he=E.deserializeRangeWithSheet(Z.token);if(he.sheetName||(he.sheetName=I),(he.unitId||o)!==(m==null?void 0:m.getUnitId())||i&&((ve=N.current.activeSheet)==null?void 0:ve.getName())!==he.sheetName)return Z.token;const ie=Y[ne];if(ne++,!ie)return"";const Ve=(ye=ie.sheetId)!=null?ye:r,vt={range:ie,unitId:(Pe=ie.unitId)!=null?Pe:m.getUnitId(),sheetName:C((xe=ie.unitId)!=null?xe:m.getUnitId(),Ve)},rt=(m==null?void 0:m.getUnitId())!==o;return Qe([vt],i&&(Ve!==r||rt),I,rt)[0]}return Z.token});let oe="",ae;de.forEach((Z,ve)=>{oe+=Z,ve===R&&(ae=oe.length)});const fe=[];for(let Z=ne;Z<=w.length-1;Z++){const ve=w[Z],ye=(tt=ve.sheetId)!=null?tt:r,Pe={range:ve,unitId:(Ce=ve.unitId)!=null?Ce:m.getUnitId(),sheetName:C((nt=ve.unitId)!=null?nt:m.getUnitId(),ye)},xe=(m==null?void 0:m.getUnitId())!==o,ie=Qe([Pe],i&&(ye!==r||xe),I,xe);fe.push(ie[0])}const Se=W[W.length-1],Ne=Se&&(typeof Se=="string"?!1:Se.nodeType===E.sequenceNodeType.REFERENCE),De=`${oe}${fe.length&&Ne?",":""}${fe.join(",")}`;f(De,!fe.length&&ae?ae:De.length,F)}});y.useEffect(()=>{if(A&&e){let w=!0,F=0;const B=(R,D)=>{if(w){w=!1,F=R.length;return}const W=R.length>F;D&&(F=R.length),k(R.map(K=>K.rangeWithCoord),D,W)},b=new a.DisposableCollection;return b.add(A.selectionMoving$.subscribe(R=>{B(R,!1)})),b.add(A.selectionMoveEnd$.subscribe(R=>{B(R,!0)})),()=>{b.dispose()}}},[e,k,A]),y.useEffect(()=>{if(t&&A&&u){const w=new a.DisposableCollection,F=()=>{w.dispose(),A.getSelectionControls().forEach((R,D)=>{w.add(R.selectionScaling$.subscribe(W=>{const K=A.getSelectionDataWithStyle().map(re=>re.rangeWithCoord),z=K[D];W.sheetId=z.sheetId,W.unitId=z.unitId,K[D]=W,k(K,!1)})),w.add(R.selectionMoving$.subscribe(W=>{const K=A.getSelectionDataWithStyle().map(re=>re.rangeWithCoord),z=K[D];W.sheetId=z.sheetId,W.unitId=z.unitId,K[D]=W,k(K,!0)}))})},B=Q.merge(u.input$,$.selectionSet$,A.selectionMoveEnd$).pipe(nn.debounceTime(50)).subscribe(()=>{F()});return()=>{B.unsubscribe(),w.dispose()}}},[u,t,k,A,$.selectionSet$]),A==null||A.getSelectionDataWithStyle(),y.useEffect(()=>{if(c){const w=h.onCommandExecuted(F=>{var b;if(F.id!==V.SetSelectionsOperation.id)return;const B=F.params;if(B.extra==="formula-editor"&&B.selections.length){const R=B.selections[B.selections.length-1];if(R){const{range:D,primary:W}=R;(W!=null&&W.isMergedMainCell||W!=null&&W.isMerged)&&a.Rectangle.contains(W,D)&&(D.startRow=W.startRow,D.endRow=W.startRow,D.startColumn=W.startColumn,D.endColumn=W.startColumn),D.unitId=B.unitId,D.sheetId=B.subUnitId;const K=n.current===me.NEED_ADD,z=((b=A==null?void 0:A.getSelectionDataWithStyle())!=null?b:[]).map(re=>re.rangeWithCoord);K?z.push(D):z[z.length-1]=D,k(z,!0)}}});return()=>{w.dispose()}}},[h,u,n,v,c,k,A]),y.useEffect(()=>{if(!u)return;const w=g.textSelection$.subscribe(F=>{F.unitId===u.getEditorId()&&Ht({unitId:o,subUnitId:r,refSelections:s.current,editor:u,refSelectionsService:$,refSelectionsRenderService:A,sheetSkeletonManagerService:U,themeService:d,univerInstanceService:p,currentWorkbook:m})});return()=>w.unsubscribe()},[g.textSelection$,u,s,A,$,U,r,d,o,p])},Hr=(e,t,n,o,r,s)=>{const i=l.useDependency(a.ICommandService),c=l.useDependency(J.IEditorService),f=l.useDependency(j.IRenderManagerService).getRenderById(t),S=l.useDependency(a.IUniverInstanceService),p=f==null?void 0:f.with(L.RefSelectionsRenderService);y.useEffect(()=>{if(e&&p)if(n){const h=()=>{const v=p.getSelectionControls().length;for(let _=1;_<=v;_++)p.clearLastSelection();return setTimeout(()=>{s()},30)},g=i.onCommandExecuted(v=>{v.id===V.SetWorksheetActiveOperation.id&&h()}),d=S.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(v=>{h()});return()=>{g.dispose(),d.unsubscribe()}}else{const h=i.beforeCommandExecuted(g=>{if(g.id===V.SetWorksheetActiveOperation.id){o(!1),r(),s();const d=c.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);d==null||d.focus()}});return()=>{h.dispose()}}},[e,p])},Kr=(e,t,n)=>{const o=l.useDependency(E.LexerTreeBuilder),r=y.useRef(!0);y.useEffect(()=>{if(e){const s=setTimeout(()=>{r.current=!1},500);return()=>{clearTimeout(s)}}},[e]),y.useEffect(()=>{if(!r.current&&t){const s=o.checkIfAddBracket(n);t(s===0&&n.startsWith(E.operatorToken.EQUALS),`${n}`)}},[n,t])},jr=(e,t=[],n)=>{const o=l.useDependency(le.IDescriptionService),[r,s]=y.useState([]),[i,c]=y.useState(""),u=y.useRef(-1),f=Oe({nodes:t}),S=()=>{s([]),c(""),u.current=-1};return y.useEffect(()=>{if(n&&e){const h=n.input$.pipe(Q.debounceTime(300)).subscribe(()=>{const g=n.getSelectionRanges();if(g.length===1){const d=f.current.nodes,v=g[0];if(v.collapsed){const _=ht(d,v.startOffset-1,!1);u.current=_;const C=d[_];if(C&&typeof C!="string"&&C.nodeType===E.sequenceNodeType.FUNCTION){u.current=_;const I=C.token,M=o.getSearchListByNameFirstLetter(I);s(M),c(I);return}}}u.current=-1,c(""),s(d=>d!=null&&d.length?[]:d)});return()=>{h.unsubscribe()}}},[n,e]),y.useEffect(()=>{e||S()},[e]),{searchList:r,searchText:i,handlerFormulaReplace:(h,g)=>{const d=[...f.current.nodes];if(u.current!==-1){const v=d.splice(u.current+1),_=d.pop()||"";let C=(typeof _=="string"?_.length:_.token.length)-h.length;return d.push(h),v[0]!==E.matchToken.OPEN_BRACKET&&g!==E.FunctionType.DefinedName&&(d.push(E.matchToken.OPEN_BRACKET),C--),{text:St([...d,...v]),offset:C}}},reset:S}},qr=()=>{},Yr=y.forwardRef(zr);function zr(e,t){const{isFocus:n,sequenceNodes:o,onSelect:r,editor:s,onClose:i=qr}=e,c=s.getEditorId(),u=l.useDependency(l.IShortcutService),f=l.useDependency(a.ICommandService),{searchList:S,searchText:p,handlerFormulaReplace:h,reset:g}=jr(n,o,s),d=y.useMemo(()=>!!S.length,[S]),v=y.useRef(void 0),[_,C]=y.useState(0),I=y.useRef(!1),[M]=Vt(c,d,[p,S]),N=Oe({searchList:S,active:_}),m=(k,P)=>{const w=h(k,P);w&&(g(),r(w))};function O(k){I.current&&C(k)}function A(){I.current&&C(-1)}y.useEffect(()=>{if(!S.length)return;const k=`sheet.formula-embedding-editor.search_function.${c}`,P=new a.DisposableCollection,w=F=>{const{searchList:B,active:b}=N.current;switch(F){case l.KeyCode.ARROW_UP:{C(R=>{const D=Math.max(0,R-1);return U(D),D});break}case l.KeyCode.ARROW_DOWN:{C(R=>{const D=Math.min(B.length-1,R+1);return U(D),D});break}case l.KeyCode.TAB:case l.KeyCode.ENTER:{const R=B[b];m(R.name,R.functionType);break}case l.KeyCode.ESC:{g(),i();break}}};return P.add(f.registerCommand({id:k,type:a.CommandType.OPERATION,handler(F,B){const{keyCode:b}=B;w(b)}})),[l.KeyCode.ARROW_UP,l.KeyCode.ARROW_DOWN,l.KeyCode.ENTER,l.KeyCode.ESC,l.KeyCode.TAB].map(F=>({id:k,binding:F,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:j.DeviceInputEventType.Keyboard,keyCode:F}})).forEach(F=>{P.add(u.registerShortcut(F))}),()=>{P.dispose()}},[S]);function U(k){const P=v.current;if(!P)return;const w=P.children[k];if(!w)return;const B=P.getBoundingClientRect().top,b=P.offsetHeight,R=w.getBoundingClientRect(),D=R.top,W=R.height;if(D>=0&&D>B&&D-B+W<=b)return;const K=w.offsetTop-(b-W)/2;P.scrollTo({top:K,behavior:"smooth"})}const $=y.useMemo(()=>{let k="";return()=>{clearTimeout(k),I.current=!0,k=setTimeout(()=>{I.current=!1},300)}},[]);return S.length>0&&d&&T.jsx(l.RectPopup,{portal:!0,anchorRect$:M,direction:"vertical",children:T.jsx("ul",{ref:k=>{v.current=k,t&&(t.current=k)},"data-u-comp":"sheets-formula-editor",className:H.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",H.borderClassName,H.scrollbarClassName),children:S.map((k,P)=>T.jsxs("li",{className:H.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":_===P}),onMouseEnter:()=>O(P),onMouseLeave:A,onMouseMove:$,onClick:()=>{m(k.name,k.functionType),s&&s.focus()},children:[T.jsxs("span",{className:"univer-block univer-truncate univer-text-xs",children:[T.jsx("span",{className:"univer-text-red-500",children:k.name.substring(0,p.length)}),T.jsx("span",{children:k.name.slice(p.length)})]}),T.jsx("span",{className:"univer-block univer-text-xs univer-text-gray-400",children:k.desc})]},k.name))})})}const Gr=e=>e.startsWith(E.operatorToken.EQUALS)?e.slice(1):"",jt=()=>{},qt=y.forwardRef((e,t)=>{var Zt,Xt,Qt,Jt;const{errorText:n,initValue:o,unitId:r,subUnitId:s,isFocus:i=!0,isSupportAcrossSheet:c=!1,onFocus:u=jt,onBlur:f=jt,onChange:S,onVerify:p,className:h,editorId:g,moveCursor:d=!0,onFormulaSelectingChange:v,keyboardEventConfig:_,onMoveInEditor:C,resetSelectionOnBlur:I=!0,autoScrollbar:M=!0,isSingle:N=!0,disableSelectionOnClick:m=!1,autofocus:O=!0,disableContextMenu:A,style:U}=e,$=l.useDependency(J.IEditorService),k=y.useRef(null),P=l.useEvent(S);y.useImperativeHandle(t,()=>({isClickOutSide:X=>k.current?!k.current.contains(X.target):!1}));const w=l.useEvent(v),F=y.useRef(null),B=y.useRef(void 0),b=B.current,[R,D]=y.useState(i),W=y.useRef(null),K=y.useMemo(()=>g!=null?g:a.createInternalEditorID(`${x.EMBEDDING_FORMULA_EDITOR}-${a.generateRandomId(4)}`),[]),z=y.useMemo(()=>n!==void 0,[n]),re=l.useDependency(a.IUniverInstanceService),ue=re.getUnit(K);l.useObservable(ue==null?void 0:ue.change$);const G=xr(),te=a.BuildTextUtils.transform.getPlainText((Xt=(Zt=ue==null?void 0:ue.getBody())==null?void 0:Zt.dataStream)!=null?Xt:""),ke=Oe(te),Le=y.useMemo(()=>Gr(te),[te]),tt=y.useMemo(()=>G(Le),[Le,G]),{isSelecting:Ce,isSelectingRef:nt}=Dr({unitId:r,subUnitId:s,editorId:K,isFocus:R,disableOnClick:m}),Y=y.useRef(""),de=l.useDependency(j.IRenderManagerService).getRenderById(K),oe=de==null?void 0:de.with(J.DocSelectionRenderService),ae=oe==null?void 0:oe.isFocusing,fe=y.useMemo(()=>re.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC),[re]),Se=l.useObservable(fe),Ne=(Se==null?void 0:Se.getUnitId())===K,De=y.useRef([]),Z=Ce,ye=(Jt=(Qt=l.useDependency(a.IConfigService).getConfig(Mt))==null?void 0:Qt.functionScreenTips)!=null?Jt:!0;l.useUpdateEffect(()=>{P(te)},[te,P]);const Pe=Kt("="),xe=Ar(r,s),he=l.useEvent((X,ce=!0,_e,Ie)=>{if(!B.current)return;Y.current=X;const ot=X[0]==="="?X.slice(1):"",Ee=G(ot),co=Ee.reduce((we,it)=>typeof it=="object"?`${we}${it.token}`:`${we}${it}`,""),st=Pe(B.current,co===ot?Ee:[],ce,Ie);if(De.current=st,_e){const we=Ie!=null?Ie:b==null?void 0:b.getSelectionRanges();if((we==null?void 0:we.length)!==1)return;const ao=we[0].startOffset-1,lo=ht(Ee,ao,!1),en=Wt(Ee,lo);if(en>=0){const tn=st.splice(en,1)[0];tn&&st.push(tn)}xe(R?st:[],B.current)}});y.useEffect(()=>{R&&he(te,!1,!0)},[R]),y.useEffect(()=>{if(R){if(Y.current===te)return;he(te,!1,!0)}},[te]),Kr(R,p,te);const ie=Or(b),Ve=$r(R,r,s);y.useEffect(()=>{var X;w(Ce,(X=oe==null?void 0:oe.isFocusing)!=null?X:!0)},[w,Ce]),J.useKeyboardEvent(R,_,b),y.useLayoutEffect(()=>{let X;if(W.current){X=$.register({autofocus:O,editorUnitId:K,initialSnapshot:{id:K,body:{dataStream:`${o}\r
|
|
5
|
+
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},W.current);const ce=$.getEditor(K);B.current=ce,he(o,!1,!0)}return()=>{X==null||X.dispose()}},[]),y.useLayoutEffect(()=>{i?(D(i),ie()):(I&&(b==null||b.blur(),Ve()),D(i))},[i,b,ie,Ve,I]);const{checkScrollBar:vt}=J.useResize(b,N,M);Fr(R,!!(Ce&&Ne),r,K,A),Pr(!!(R&&ae&&d),Z,b,C);const rt=l.useEvent((X,ce,_e)=>{if(!ae)return;const Ie=ce!==-1?[{startOffset:ce+1,endOffset:ce+1,collapsed:!0}]:void 0;he(`=${X}`,!0,_e,Ie),_e&&(ie(),ce!==-1&&setTimeout(()=>{const ot={startOffset:ce+1,endOffset:ce+1},Ee=b==null?void 0:b.render.with(J.DocBackScrollRenderController);Ee==null||Ee.scrollToRange({...ot,collapsed:!0})},50),vt())});Br(R&&!!(Ce&&Ne),R,nt,r,s,De,c,!!Z,b,rt),Hr(R&&!!(Ce&&Ne),r,c,D,f,()=>{he(ke.current,!1,!0)});const zt=X=>{if(X){const ce=b==null?void 0:b.getSelectionRanges();if(ce&&ce.length===1){const _e=ce[0];if(_e.collapsed){const Ie=X.offset;setTimeout(()=>{b==null||b.setSelectionRanges([{startOffset:_e.startOffset-Ie,endOffset:_e.endOffset-Ie}])},30)}}ie(),he(`=${X.text}`)}},Gt=()=>{D(!0),u(),ie()};return T.jsxs("div",{className:h,children:[T.jsx("div",{ref:k,className:H.clsx("univer-relative univer-box-border univer-flex univer-size-full univer-items-center univer-justify-around univer-gap-2 univer-rounded-none univer-p-0 univer-ring-1",{"univer-ring-primary-500":R,"univer-ring-red-500":z}),children:T.jsx("div",{ref:W,className:"univer-relative univer-size-full",onMouseUp:Gt})}),n!==void 0&&T.jsx("div",{className:"univer-my-1 univer-text-xs univer-text-red-500",children:n}),ye&&b&&Le!==""&&T.jsx(Mr,{editor:b,isFocus:R,formulaText:te,onClose:()=>ie()}),ye&&!!b&&T.jsx(Yr,{isFocus:R,sequenceNodes:tt,onSelect:zt,ref:F,editor:b})]})});function Zr(e,t,n,o){const r=l.useDependency(E.LexerTreeBuilder),s=Kt(""),i=l.useObservable(e==null?void 0:e.getDocumentDataModel().change$),[c,u]=y.useState([]),f=l.useDependency(x.IMarkSelectionService),S=y.useRef(""),p=l.useDependency(a.IUniverInstanceService);return y.useEffect(()=>{if(!e)return;const h=e.getDocumentDataModel().getPlainText();if(S.current===h)return;S.current=h;const g=r.sequenceNodesBuilder(h);u(g!=null?g:[])},[i,e,r]),y.useEffect(()=>{var d,v;if(!e)return;if(!t){const _=e.getDocumentData();e.setDocumentData({..._,body:{..._.body,dataStream:(v=(d=_.body)==null?void 0:d.dataStream)!=null?v:"",textRuns:[]}});return}const h=s(e,c,!1),g=new a.DisposableCollection;return h.forEach(_=>{const C=E.deserializeRangeWithSheet(_.token),I=p.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),M=I==null?void 0:I.getActiveSheet();if(!C.sheetName&&o!==(M==null?void 0:M.getSheetId())||C.sheetName&&(M==null?void 0:M.getName())!==C.sheetName)return;const N=new a.ColorKit(_.themeColor).toRgb(),m=f.addShape({range:C.range,style:{stroke:_.themeColor,fill:`rgba(${N.r}, ${N.g}, ${N.b}, 0.1)`,strokeDash:12},primary:null});m&&g.add(()=>f.removeShape(m))}),()=>{g.dispose()}},[e,t,s,f,c]),{sequenceNodes:c}}function Xr(e){const t=l.useDependency(V.SheetsSelectionsService),{supportAcrossSheet:n=!1,keepSheetReference:o=!1,unitId:r,subUnitId:s,onChange:i}=e,u=l.useDependency(a.IUniverInstanceService).getUnit(r,a.UniverInstanceType.UNIVER_SHEET),f=l.useEvent(i),S=l.useEvent((p,h)=>{const g=u==null?void 0:u.getActiveSheet();if(!g||!n&&g.getSheetId()!==s||!(p!=null&&p.length))return;const d=o?g.getName():g.getSheetId()===s?"":g.getName(),v=p.map(_=>({range:_.range,unitId:r,sheetName:d}));f(v,h)});y.useEffect(()=>{const p=new a.DisposableCollection;return p.add(t.selectionMoveStart$.subscribe(h=>{S(h,!0)})),p.add(t.selectionMoving$.subscribe(h=>{S(h,!1)})),p.add(t.selectionMoveEnd$.subscribe(h=>{S(h,!1)})),()=>{p.dispose()}},[S,t.selectionMoveEnd$,t.selectionMoveStart$,t.selectionMoving$])}const Yt=e=>!e.some(n=>{if(typeof n=="string"){if(n!==E.matchToken.COMMA)return!0}else if(n.nodeType!==E.sequenceNodeType.REFERENCE)return!0;return!1}),Qr=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:u,onClose:f,onShowBySelection:S}=e,p=l.useDependency(a.LocaleService),h=l.useDependency(E.LexerTreeBuilder),[g,d]=y.useState([]),[v,_]=y.useState(0),C=y.useRef(null);y.useEffect(()=>{if(t&&n.length){const m=n.map(O=>O.sheetName?E.serializeRangeWithSheet(O.sheetName,O.range):E.serializeRange(O.range));d(m),_(m.length-1)}else d([""]),_(0)},[t]);const I=(m,O)=>{const A=[...g];A[m]=O,d(A)},M=()=>{d([...g,""]),_(g.length)},N=m=>{g.splice(m,1),d([...g])};return Xr({unitId:o,subUnitId:r,supportAcrossSheet:i,keepSheetReference:c,onChange:(m,O)=>{if(!t&&S!=null&&S(m))return;const A=new Set(g),U=m.map(P=>P.sheetName?E.serializeRangeWithSheet(P.sheetName,P.range):E.serializeRange(P.range)),$=U.filter(P=>!A.has(P));if(!$.length)return;const k=[...g];if(U.length>1){O||k.splice(v,1),k.push(...$);const P=k.slice(0,s);d(P),_(P.length-1),requestAnimationFrame(()=>{var w;(w=C.current)==null||w.scrollTo({top:C.current.scrollHeight})})}else{k.splice(v,1,...$);const P=k.slice(0,s);d(P),_(v+$.length-1)}}}),T.jsx(H.Dialog,{width:"328px",open:t,title:p.t("rangeSelector.title"),draggable:!0,mask:!1,maskClosable:!1,footer:T.jsxs("footer",{className:"univer-flex univer-gap-2",children:[T.jsx(H.Button,{onClick:f,children:p.t("rangeSelector.cancel")}),T.jsx(H.Button,{variant:"primary",onClick:()=>{u(g.filter(m=>{const O=h.sequenceNodesBuilder(m);return O&&O.length===1&&typeof O[0]!="string"&&O[0].nodeType===E.sequenceNodeType.REFERENCE}).map(m=>E.deserializeRangeWithSheet(m)).map(m=>({...m,range:Qr(m.range)})))},children:p.t("rangeSelector.confirm")})]}),onClose:f,children:T.jsxs("div",{ref:C,className:H.clsx("-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6",H.scrollbarClassName),children:[g.map((m,O)=>T.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-gap-4",children:[T.jsx(H.Input,{className:H.clsx("univer-w-full",{"univer-border-primary-600":v===O}),placeholder:p.t("rangeSelector.placeHolder"),onFocus:()=>_(O),value:m,onChange:A=>I(O,A)}),g.length>1&&T.jsx(Pt,{className:"univer-cursor-pointer",onClick:()=>N(O)})]},O)),g.length<s&&T.jsx("div",{children:T.jsxs(H.Button,{variant:"link",onClick:M,children:[T.jsx(Ft,{}),T.jsx("span",{children:p.t("rangeSelector.addAnotherRange")})]})})]})})}function eo(e){return e.split(E.matchToken.COMMA).filter(t=>!!t).map(t=>E.deserializeRangeWithSheet(t))}function to(e){return e.map(t=>t.sheetName?E.serializeRangeWithSheet(t.sheetName,t.range):E.serializeRange(t.range)).join(E.matchToken.COMMA)}function pt(e){const[t,n]=y.useState(null),{onVerify:o,selectorRef:r,unitId:s,subUnitId:i,maxRangeCount:c,supportAcrossSheet:u,keepSheetReference:f,autoFocus:S,onChange:p,onRangeSelectorDialogVisibleChange:h,onClickOutside:g,onFocusChange:d,forceShowDialogWhenSelectionChanged:v,hideEditor:_,resetRange:C}=e,[I,M]=y.useState(S!=null?S:!1),[N,m]=y.useState(!1),[O,A]=y.useState([]),U=l.useDependency(a.LocaleService),$=l.useDependency(J.IEditorService),{sequenceNodes:k}=Zr(t,I,s,i),P=Oe(k),w=l.useDependency(a.ICommandService),F=l.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),$.blur()}),B=l.useEvent(()=>{var b;F(),A(eo((b=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?b:"")),m(!0)});return y.useEffect(()=>{r&&(r.current={get editor(){return t},focus(){$.focus(t.getEditorId())},blur:F,verify:()=>Yt(P.current),showDialog:b=>{F(),A(b),m(!0)},hideDialog:()=>{A([]),m(!1)},getValue:()=>{var b;return(b=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?b:""}})},[F,t,$,r,P]),y.useEffect(()=>{var b;o==null||o(Yt(k),(b=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?b:"")},[k]),y.useEffect(()=>{h==null||h(N)},[N]),y.useEffect(()=>{if(N&&C)return()=>{const b={unitId:s,subUnitId:i,selections:C};w.executeCommand(V.SetSelectionsOperation.id,b)}},[N]),T.jsxs(T.Fragment,{children:[_?null:T.jsx(J.RichTextEditor,{isSingle:!0,...e,onFocusChange:(b,R)=>{M(b),d==null||d(b,R)},editorRef:n,onClickOutside:()=>{M(!1),F(),g==null||g()},icon:T.jsx(H.Tooltip,{title:U.t("rangeSelector.buttonTooltip"),placement:"bottom",children:T.jsx(Ut,{className:"univer-cursor-pointer dark:!univer-text-gray-300",onClick:B})})}),T.jsx(Jr,{initialValue:O,unitId:s,subUnitId:i,visible:N,maxRangeCount:c,onConfirm:b=>{const R=to(b),D=a.RichTextBuilder.newEmptyData();D.body.dataStream=R,t==null||t.replaceText(R,!1),p==null||p(D,R),m(!1),A([]),requestAnimationFrame(()=>{F()})},onClose:()=>{m(!1),A([])},supportAcrossSheet:u,keepSheetReference:f,onShowBySelection:b=>I||v?(A(b),m(!0),!1):!0})]})}const no=()=>{var o,r;const e=l.useDependency(ft),t=l.useObservable(e.currentSelector$),n=y.useRef(null);return y.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]),T.jsx(pt,{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(u=>E.deserializeRangeWithSheet(u)))!=null?c:[])}})};var ro=Object.defineProperty,oo=Object.getOwnPropertyDescriptor,so=(e,t,n)=>t in e?ro(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,io=(e,t,n,o)=>{for(var r=o>1?void 0:o?oo(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Je=(e,t)=>(n,o)=>t(n,o,e),et=(e,t,n)=>so(e,typeof t!="symbol"?t+"":t,n);L.UniverSheetsFormulaUIPlugin=class extends a.Plugin{constructor(t=Ot,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(Ot,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Mt,c,{merge:!0})}onStarting(){a.registerDependencies(this._injector,[[Ke,{useClass:ct}],[ft],[Ze],[qe],[Ye],[ze],[L.FormulaReorderController],[Xe]]),this._initUIPart()}onReady(){[[L.RefSelectionsRenderService]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,t))})}onRendered(){[[ut]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,t))}),a.touchDependencies(this._injector,[[Ze],[qe],[ze],[Xe]])}onSteady(){this._injector.get(L.FormulaReorderController)}_initUIPart(){const t=this._injector.get(l.ComponentManager);this.disposeWithMe(t.register(x.RANGE_SELECTOR_COMPONENT_KEY,pt)),this.disposeWithMe(t.register(x.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,qt)),this.disposeWithMe(this._uiPartsService.registerComponent(l.BuiltInUIPart.GLOBAL,()=>l.connectInjector(no,this._injector)))}},et(L.UniverSheetsFormulaUIPlugin,"pluginName",Et),et(L.UniverSheetsFormulaUIPlugin,"packageName",bt.name),et(L.UniverSheetsFormulaUIPlugin,"version",bt.version),et(L.UniverSheetsFormulaUIPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),L.UniverSheetsFormulaUIPlugin=io([a.DependentOn(le.UniverSheetsFormulaPlugin),Je(1,a.Inject(a.Injector)),Je(2,j.IRenderManagerService),Je(3,a.IConfigService),Je(4,l.IUIPartsService)],L.UniverSheetsFormulaUIPlugin),L.FORMULA_PROMPT_ACTIVATED=Ct,L.FormulaEditor=qt,L.GlobalRangeSelectorService=ft,L.HelpFunctionOperation=It,L.InsertFunctionOperation=ee,L.MoreFunctionsOperation=se,L.RangeSelector=pt,L.ReferenceAbsoluteOperation=at,L.SearchFunctionOperation=Tt,L.SelectEditorFormulaOperation=Re,L.SheetCopyFormulaOnlyCommand=Be,L.SheetOnlyPasteFormulaCommand=He,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})}));
|