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