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