@univerjs/sheets-formula-ui 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2 -5
- package/lib/cjs/locale/ca-ES.js +39 -0
- package/lib/cjs/locale/en-US.js +1 -3
- package/lib/cjs/locale/es-ES.js +39 -0
- package/lib/cjs/locale/fa-IR.js +7 -9
- package/lib/cjs/locale/fr-FR.js +7 -9
- package/lib/cjs/locale/ko-KR.js +9 -2
- package/lib/cjs/locale/ru-RU.js +7 -9
- package/lib/cjs/locale/vi-VN.js +8 -8
- package/lib/cjs/locale/zh-TW.js +2 -2
- package/lib/es/index.js +374 -380
- package/lib/es/locale/ca-ES.js +7906 -0
- package/lib/es/locale/en-US.js +1 -3
- package/lib/es/locale/es-ES.js +7904 -0
- package/lib/es/locale/fa-IR.js +27 -29
- package/lib/es/locale/fr-FR.js +27 -29
- package/lib/es/locale/ko-KR.js +210 -18
- package/lib/es/locale/ru-RU.js +26 -27
- package/lib/es/locale/vi-VN.js +248 -26
- package/lib/es/locale/zh-TW.js +3 -3
- package/lib/index.js +374 -380
- package/lib/locale/ca-ES.js +7906 -0
- package/lib/locale/en-US.js +1 -3
- package/lib/locale/es-ES.js +7904 -0
- package/lib/locale/fa-IR.js +27 -29
- package/lib/locale/fr-FR.js +27 -29
- package/lib/locale/ko-KR.js +210 -18
- package/lib/locale/ru-RU.js +26 -27
- package/lib/locale/vi-VN.js +248 -26
- package/lib/locale/zh-TW.js +3 -3
- package/lib/types/locale/ca-ES.d.ts +3 -0
- package/lib/types/locale/en-US.d.ts +2 -2
- package/lib/types/locale/es-ES.d.ts +3 -0
- package/lib/types/locale/fa-IR.d.ts +3 -10527
- package/lib/types/locale/fr-FR.d.ts +3 -10527
- package/lib/types/locale/function-list/array/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/array/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/array/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/array/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/array/fr-FR.d.ts +3 -17
- package/lib/types/locale/function-list/array/ja-JP.d.ts +3 -58
- package/lib/types/locale/function-list/array/ko-KR.d.ts +3 -58
- package/lib/types/locale/function-list/array/ru-RU.d.ts +3 -58
- package/lib/types/locale/function-list/array/vi-VN.d.ts +3 -58
- package/lib/types/locale/function-list/array/zh-CN.d.ts +3 -58
- package/lib/types/locale/function-list/array/zh-TW.d.ts +3 -58
- package/lib/types/locale/function-list/compatibility/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/compatibility/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/compatibility/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/compatibility/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/compatibility/fr-FR.d.ts +3 -706
- package/lib/types/locale/function-list/compatibility/ja-JP.d.ts +3 -838
- package/lib/types/locale/function-list/compatibility/ko-KR.d.ts +3 -838
- package/lib/types/locale/function-list/compatibility/ru-RU.d.ts +838 -2
- package/lib/types/locale/function-list/compatibility/vi-VN.d.ts +3 -838
- package/lib/types/locale/function-list/compatibility/zh-CN.d.ts +3 -838
- package/lib/types/locale/function-list/compatibility/zh-TW.d.ts +3 -838
- package/lib/types/locale/function-list/cube/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/cube/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/cube/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/cube/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/cube/fr-FR.d.ts +3 -144
- package/lib/types/locale/function-list/cube/ja-JP.d.ts +3 -144
- package/lib/types/locale/function-list/cube/ko-KR.d.ts +3 -144
- package/lib/types/locale/function-list/cube/ru-RU.d.ts +3 -144
- package/lib/types/locale/function-list/cube/vi-VN.d.ts +3 -144
- package/lib/types/locale/function-list/cube/zh-CN.d.ts +3 -144
- package/lib/types/locale/function-list/cube/zh-TW.d.ts +3 -144
- package/lib/types/locale/function-list/database/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/database/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/database/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/database/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/database/fr-FR.d.ts +3 -234
- package/lib/types/locale/function-list/database/ja-JP.d.ts +3 -282
- package/lib/types/locale/function-list/database/ko-KR.d.ts +3 -282
- package/lib/types/locale/function-list/database/ru-RU.d.ts +3 -282
- package/lib/types/locale/function-list/database/vi-VN.d.ts +3 -282
- package/lib/types/locale/function-list/database/zh-CN.d.ts +3 -282
- package/lib/types/locale/function-list/database/zh-TW.d.ts +3 -282
- package/lib/types/locale/function-list/date/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/date/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/date/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/date/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/date/fr-FR.d.ts +3 -458
- package/lib/types/locale/function-list/date/ja-JP.d.ts +3 -490
- package/lib/types/locale/function-list/date/ko-KR.d.ts +3 -490
- package/lib/types/locale/function-list/date/ru-RU.d.ts +490 -2
- package/lib/types/locale/function-list/date/vi-VN.d.ts +3 -490
- package/lib/types/locale/function-list/date/zh-CN.d.ts +3 -490
- package/lib/types/locale/function-list/date/zh-TW.d.ts +3 -490
- package/lib/types/locale/function-list/engineering/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/engineering/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/engineering/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/engineering/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/engineering/fr-FR.d.ts +3 -894
- package/lib/types/locale/function-list/engineering/ja-JP.d.ts +3 -940
- package/lib/types/locale/function-list/engineering/ko-KR.d.ts +3 -940
- package/lib/types/locale/function-list/engineering/ru-RU.d.ts +940 -2
- package/lib/types/locale/function-list/engineering/vi-VN.d.ts +3 -940
- package/lib/types/locale/function-list/engineering/zh-CN.d.ts +3 -940
- package/lib/types/locale/function-list/engineering/zh-TW.d.ts +3 -940
- package/lib/types/locale/function-list/financial/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/financial/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/financial/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/financial/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/financial/fr-FR.d.ts +3 -1608
- package/lib/types/locale/function-list/financial/ja-JP.d.ts +3 -1608
- package/lib/types/locale/function-list/financial/ko-KR.d.ts +3 -1608
- package/lib/types/locale/function-list/financial/ru-RU.d.ts +1608 -2
- package/lib/types/locale/function-list/financial/vi-VN.d.ts +3 -1608
- package/lib/types/locale/function-list/financial/zh-CN.d.ts +3 -1608
- package/lib/types/locale/function-list/financial/zh-TW.d.ts +3 -1608
- package/lib/types/locale/function-list/information/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/information/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/information/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/information/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/information/fr-FR.d.ts +3 -327
- package/lib/types/locale/function-list/information/ja-JP.d.ts +3 -386
- package/lib/types/locale/function-list/information/ko-KR.d.ts +3 -386
- package/lib/types/locale/function-list/information/ru-RU.d.ts +386 -2
- package/lib/types/locale/function-list/information/vi-VN.d.ts +3 -350
- package/lib/types/locale/function-list/information/zh-CN.d.ts +3 -386
- package/lib/types/locale/function-list/information/zh-TW.d.ts +3 -386
- package/lib/types/locale/function-list/logical/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/logical/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/logical/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/logical/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/logical/fr-FR.d.ts +3 -390
- package/lib/types/locale/function-list/logical/ja-JP.d.ts +3 -390
- package/lib/types/locale/function-list/logical/ko-KR.d.ts +3 -378
- package/lib/types/locale/function-list/logical/ru-RU.d.ts +390 -2
- package/lib/types/locale/function-list/logical/vi-VN.d.ts +3 -390
- package/lib/types/locale/function-list/logical/zh-CN.d.ts +3 -390
- package/lib/types/locale/function-list/logical/zh-TW.d.ts +3 -390
- package/lib/types/locale/function-list/lookup/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/lookup/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/lookup/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/lookup/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/lookup/fr-FR.d.ts +3 -812
- package/lib/types/locale/function-list/lookup/ja-JP.d.ts +3 -808
- package/lib/types/locale/function-list/lookup/ko-KR.d.ts +3 -808
- package/lib/types/locale/function-list/lookup/ru-RU.d.ts +808 -2
- package/lib/types/locale/function-list/lookup/vi-VN.d.ts +3 -754
- package/lib/types/locale/function-list/lookup/zh-CN.d.ts +3 -808
- package/lib/types/locale/function-list/lookup/zh-TW.d.ts +3 -808
- package/lib/types/locale/function-list/math/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/math/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/math/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/math/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/math/fr-FR.d.ts +3 -1388
- package/lib/types/locale/function-list/math/ja-JP.d.ts +3 -1402
- package/lib/types/locale/function-list/math/ko-KR.d.ts +3 -1366
- package/lib/types/locale/function-list/math/ru-RU.d.ts +1402 -2
- package/lib/types/locale/function-list/math/vi-VN.d.ts +3 -1348
- package/lib/types/locale/function-list/math/zh-CN.d.ts +3 -1402
- package/lib/types/locale/function-list/math/zh-TW.d.ts +3 -1402
- package/lib/types/locale/function-list/statistical/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/statistical/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/statistical/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/statistical/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/statistical/fr-FR.d.ts +3 -2068
- package/lib/types/locale/function-list/statistical/ja-JP.d.ts +3 -2308
- package/lib/types/locale/function-list/statistical/ko-KR.d.ts +3 -2184
- package/lib/types/locale/function-list/statistical/ru-RU.d.ts +2308 -2
- package/lib/types/locale/function-list/statistical/vi-VN.d.ts +3 -2236
- package/lib/types/locale/function-list/statistical/zh-CN.d.ts +3 -2308
- package/lib/types/locale/function-list/statistical/zh-TW.d.ts +3 -2308
- package/lib/types/locale/function-list/text/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/text/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/text/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/text/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/text/fr-FR.d.ts +3 -922
- package/lib/types/locale/function-list/text/ja-JP.d.ts +3 -989
- package/lib/types/locale/function-list/text/ko-KR.d.ts +3 -912
- package/lib/types/locale/function-list/text/ru-RU.d.ts +3 -988
- package/lib/types/locale/function-list/text/vi-VN.d.ts +3 -960
- package/lib/types/locale/function-list/text/zh-CN.d.ts +3 -988
- package/lib/types/locale/function-list/text/zh-TW.d.ts +3 -988
- package/lib/types/locale/function-list/univer/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/univer/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/univer/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/univer/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/univer/fr-FR.d.ts +3 -17
- package/lib/types/locale/function-list/univer/ja-JP.d.ts +3 -17
- package/lib/types/locale/function-list/univer/ko-KR.d.ts +3 -17
- package/lib/types/locale/function-list/univer/ru-RU.d.ts +2 -2
- package/lib/types/locale/function-list/univer/vi-VN.d.ts +3 -17
- package/lib/types/locale/function-list/univer/zh-CN.d.ts +3 -17
- package/lib/types/locale/function-list/univer/zh-TW.d.ts +3 -17
- package/lib/types/locale/function-list/web/ca-ES.d.ts +3 -0
- package/lib/types/locale/function-list/web/en-US.d.ts +2 -2
- package/lib/types/locale/function-list/web/es-ES.d.ts +3 -0
- package/lib/types/locale/function-list/web/fa-IR.d.ts +3 -0
- package/lib/types/locale/function-list/web/fr-FR.d.ts +3 -72
- package/lib/types/locale/function-list/web/ja-JP.d.ts +3 -68
- package/lib/types/locale/function-list/web/ko-KR.d.ts +3 -68
- package/lib/types/locale/function-list/web/ru-RU.d.ts +3 -68
- package/lib/types/locale/function-list/web/vi-VN.d.ts +3 -32
- package/lib/types/locale/function-list/web/zh-CN.d.ts +3 -68
- package/lib/types/locale/function-list/web/zh-TW.d.ts +3 -68
- package/lib/types/locale/ko-KR.d.ts +3 -10297
- package/lib/types/locale/ru-RU.d.ts +3 -10526
- package/lib/types/locale/vi-VN.d.ts +3 -10265
- package/lib/types/locale/zh-CN.d.ts +3 -10527
- package/lib/types/locale/zh-TW.d.ts +3 -10527
- package/lib/umd/index.js +2 -5
- package/lib/umd/locale/ca-ES.js +39 -0
- package/lib/umd/locale/en-US.js +1 -3
- package/lib/umd/locale/es-ES.js +39 -0
- package/lib/umd/locale/fa-IR.js +1 -3
- package/lib/umd/locale/fr-FR.js +1 -3
- package/lib/umd/locale/ko-KR.js +9 -2
- package/lib/umd/locale/ru-RU.js +2 -4
- package/lib/umd/locale/vi-VN.js +6 -6
- package/lib/umd/locale/zh-TW.js +2 -2
- package/package.json +13 -13
package/lib/cjs/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";var Xt=Object.defineProperty;var Qt=(e,t,n)=>t in e?Xt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var K=(e,t,n)=>Qt(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),k=require("@univerjs/sheets-ui"),T=require("@univerjs/engine-formula"),q=require("rxjs"),J=require("@univerjs/docs-ui"),B=require("@univerjs/engine-render"),A=require("@univerjs/sheets"),Re=require("@univerjs/sheets-formula"),a=require("@univerjs/ui"),y=require("react/jsx-runtime"),R=require("react"),W=require("@univerjs/design"),bt=require("@univerjs/docs"),Jt=require("rxjs/operators"),Qe={id:"sheet.command.paste-formula",type:l.CommandType.COMMAND,handler:async e=>e.get(l.ICommandService).executeCommand(k.SheetPasteCommand.id,{value:k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA})},xe={id:"formula-ui.operation.select-editor-formula",type:l.CommandType.OPERATION,handler:(e,t)=>!0};var en=Object.getOwnPropertyDescriptor,tn=(e,t,n,s)=>{for(var r=s>1?void 0:s?en(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},nn=(e,t)=>(n,s)=>t(n,s,e);const Tt="FORMULA_PROMPT_ACTIVATED",Je=l.createIdentifier("formula-ui.prompt-service");let it=class{constructor(e){K(this,"_search$",new q.Subject);K(this,"_help$",new q.Subject);K(this,"_navigate$",new q.Subject);K(this,"_accept$",new q.Subject);K(this,"_acceptFormulaName$",new q.Subject);K(this,"search$",this._search$.asObservable());K(this,"help$",this._help$.asObservable());K(this,"navigate$",this._navigate$.asObservable());K(this,"accept$",this._accept$.asObservable());K(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());K(this,"_searching",!1);K(this,"_helping",!1);K(this,"_sequenceNodes",[]);K(this,"_isLockedOnSelectionChangeRefString",!1);K(this,"_isLockedOnSelectionInsertRefString",!1);this._contextService=e}dispose(){this._search$.complete(),this._help$.complete(),this._navigate$.complete(),this._accept$.complete(),this._acceptFormulaName$.complete(),this._sequenceNodes=[]}search(e){this._contextService.setContextValue(Tt,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:c}=o;t=c}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,c=this._sequenceNodes.length;o<c;o++){const i=this._sequenceNodes[o];if(typeof i=="string")continue;const u={...i};u.startIndex+=s,u.endIndex+=s,this._sequenceNodes[o]=u}}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 c=this._sequenceNodes[r];if(typeof c=="string")continue;const i={...c};i.startIndex+=n,i.endIndex+=n,this._sequenceNodes[r]=i}}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,c=this._sequenceNodes.length;o<c;o++){const i=this._sequenceNodes[o];if(typeof i=="string")continue;const u={...i};u.startIndex+=r,u.endIndex+=r,this._sequenceNodes[o]=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}};it=tn([nn(0,l.IContextService)],it);const xt={id:"formula-ui.operation.help-function",type:l.CommandType.OPERATION,handler:async(e,t)=>(e.get(Je).help(t),!0)},de={id:"formula-ui.operation.insert-function",type:l.CommandType.OPERATION,handler:async(e,t)=>{var E,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(l.IUniverInstanceService));if(!o)return!1;const{worksheet:c,unitId:i,subUnitId:u}=o,h=c.getCellMatrix(),{value:m}=t,p=e.get(l.ICommandService);e.get(k.IEditorBridgeService);const f=[],g=[];let d=null,C=0,_=0,v="";if(r.length===1&&(on(r[0].range)||cn(r[0].range)&&vt(h,r[0].range))){const{range:I,primary:S}=r[0],N=(E=S==null?void 0:S.actualRow)!=null?E:I.startRow,F=(b=S==null?void 0:S.actualColumn)!=null?b:I.startColumn;d=I,C=N,_=F;const L=St(h,N,F);L&&(v=T.serializeRange(L))}else r.some(I=>{var F,L;const{range:S,primary:N}=I;if(vt(h,S)){const U=(F=N==null?void 0:N.actualRow)!=null?F:S.startRow,w=(L=N==null?void 0:N.actualColumn)!=null?L:S.startColumn,j=St(h,U,w);if(!j)return d=S,C=U,_=w,!0;const D=T.serializeRange(j),M=`=${m}(${D})`;f.push({range:S,primary:{row:U,column:w},formula:M})}else{const{startRow:U,startColumn:w,endRow:j,endColumn:D}=S;if(U===j){const M=an(h,U,D,c.getColumnCount()-1),x=M===D?D-1:D,O=T.serializeRange({startRow:U,endRow:j,startColumn:w,endColumn:x}),P=`=${m}(${O})`;g.push({range:S,primary:{row:U,column:M},formula:P})}else{let M=-1;for(let O=w;O<=D;O++){const P=ln(h,O,j,c.getRowCount()-1);M=Math.max(M,P)}const x=M===j?j-1:j;for(let O=w;O<=D;O++){const P=T.serializeRange({startRow:U,endRow:x,startColumn:O,endColumn:O}),$=`=${m}(${P})`;g.push({range:S,primary:{row:M,column:O},formula:$})}}}return!1});if(d){const I=A.getCellAtRowCol(C,_,c),S={range:l.Rectangle.clone(d),primary:{startRow:I.startRow,startColumn:I.startColumn,endRow:I.endRow,endColumn:I.endColumn,actualRow:C,actualColumn:_,isMerged:I.isMerged,isMergedMainCell:I.startRow===C&&I.startColumn===_}},N={unitId:i,subUnitId:u,selections:[S]};await p.executeCommand(A.SetSelectionsOperation.id,N);const F=s.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),L=s.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);p.syncExecuteCommand(k.SetCellEditVisibleOperation.id,{visible:!0,unitId:i,eventType:B.DeviceInputEventType.Dblclick});const U=`=${m}(${v}`;F==null||F.replaceText(U),L==null||L.replaceText(U,!1)}return f.length===0&&g.length===0?!1:p.executeCommand(Re.InsertFunctionCommand.id,{list:f,listOfRangeHasNumber:g})}};function St(e,t,n){const s=rn(e,t,n);if(s!==t)return{startRow:s,endRow:t-1,startColumn:n,endColumn:n};const r=sn(e,t,n);return r!==n?{startRow:t,endRow:t,startColumn:r,endColumn:n-1}:null}function rn(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(Pe(o)&&!s){if(r===0)return 0;s=!0}else{if(s&&!Pe(o))return r+1;if(s&&r===0)return 0}}return t}function sn(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(Pe(o)&&!s){if(r===0)return 0;s=!0}else{if(s&&!Pe(o))return r+1;if(s&&r===0)return 0}}return n}function Pe(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return!1;const n=t.dataStream,r=n.substring(n.length-2,n.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n;return l.isRealNum(r)}return e&&(e.t===l.CellValueType.NUMBER||l.getCellValueType(e)===l.CellValueType.NUMBER)}function on(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}function cn(e){return e.startRow!==e.endRow&&e.startColumn!==e.endColumn}function vt(e,t){for(let n=t.startRow;n<=t.endRow;n++)for(let s=t.startColumn;s<=t.endColumn;s++)if(Pe(e.getValue(n,s)))return!1;return!0}function an(e,t,n,s){for(let r=n;r<=s;r++)if(!e.getValue(t,r))return r;return s}function ln(e,t,n,s){for(let r=n;r<=s;r++)if(!e.getValue(r,t))return r;return s}const Mt="SHEET_FORMULA_UI_PLUGIN",Ot=`${Mt}_MORE_FUNCTIONS_COMPONENT`,et={id:"formula-ui.operation.more-functions",type:l.CommandType.OPERATION,handler:async e=>(e.get(a.ISidebarService).open({header:{title:"formula.insert.tooltip"},children:{label:Ot}}),!0)},lt={id:"formula-ui.operation.change-ref-to-absolute",type:l.CommandType.OPERATION,handler:async e=>!0},Nt={id:"formula-ui.operation.search-function",type:l.CommandType.OPERATION,handler:async(e,t)=>(e.get(Je).search(t),!0)};var un=Object.getOwnPropertyDescriptor,dn=(e,t,n,s)=>{for(var r=s>1?void 0:s?un(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},Be=(e,t)=>(n,s)=>t(n,s,e);exports.FormulaReorderController=class extends l.Disposable{constructor(t,n,s,r){super(),this._sheetInterceptorService=t,this._univerInstanceService=n,this._formulaDataModel=s,this._lexerTreeBuilder=r,this._initialize()}_initialize(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>t.id===A.ReorderRangeCommand.id?this._reorderFormula(t.params):{redos:[],undos:[]}}))}_reorderFormula(t){const n=[],s=[],{unitId:r,subUnitId:o,range:c,order:i}=t,u=this._univerInstanceService.getUniverSheetInstance(r),h=u==null?void 0:u.getSheetBySheetId(o);if(!h)return{redos:n,undos:s};const m=h.getCellMatrix(),p=new l.ObjectMatrix,f=new l.ObjectMatrix;let g=!1;return l.Range.foreach(c,(d,C)=>{let _=d;i.hasOwnProperty(d)&&(_=i[d]);const v=m.getValue(_,C);if(v!=null&&v.f||v!=null&&v.si){g=!0;const E=this._formulaDataModel.getFormulaStringByCell(_,C,o,r),b=this._lexerTreeBuilder.moveFormulaRefOffset(E,0,d-_),I=l.Tools.deepClone(v);I.f=b,I.si=null,p.setValue(d,C,I)}else p.setValue(d,C,v);f.setValue(d,C,m.getValue(d,C))}),g?(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=dn([Be(0,l.Inject(A.SheetInterceptorService)),Be(1,l.Inject(l.IUniverInstanceService)),Be(2,l.Inject(T.FormulaDataModel)),Be(3,l.Inject(T.LexerTreeBuilder))],exports.FormulaReorderController);const hn="sheets-formula-ui.base.config",Ct={};function fn(e){return e.getContextValue(l.FOCUSING_DOC)&&e.getContextValue(l.FOCUSING_UNIVER_EDITOR)}function Dt(e,t=!1){return!t&&!(l.isFormulaString(e==null?void 0:e.f)||l.isFormulaId(e==null?void 0:e.si))?null:typeof(e==null?void 0:e.v)=="string"&&T.ERROR_TYPE_SET.has(e.v)?e.v:null}var gn=Object.getOwnPropertyDescriptor,mn=(e,t,n,s)=>{for(var r=s>1?void 0:s?gn(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},ke=(e,t)=>(n,s)=>t(n,s,e);const st="SHEET_FORMULA_ALERT",pn={[T.ErrorType.DIV_BY_ZERO]:"divByZero",[T.ErrorType.NAME]:"name",[T.ErrorType.VALUE]:"value",[T.ErrorType.NUM]:"num",[T.ErrorType.NA]:"na",[T.ErrorType.CYCLE]:"cycle",[T.ErrorType.REF]:"ref",[T.ErrorType.SPILL]:"spill",[T.ErrorType.CALC]:"calc",[T.ErrorType.ERROR]:"error",[T.ErrorType.CONNECT]:"connect",[T.ErrorType.NULL]:"null"};let ct=class extends l.Disposable{constructor(e,t,n,s,r,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=s,this._formulaDataModel=r,this._zenZoneService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(q.debounceTime(100)).subscribe(e=>{var t,n,s,r,o;if(e){const i=this._context.unit.getActiveSheet();if(!i)return;const u=i.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(l.isICellData(u)){const m=Dt(u,!!h);if(!m){this._hideAlert();return}const p=this._cellAlertManagerService.currentAlert.get(st),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)return;this._cellAlertManagerService.showAlert({type:k.CellAlertType.ERROR,title:this._localeService.t("formula.error.title"),message:this._localeService.t(`formula.error.${pn[m]}`),location:e.location,width:200,height:74,key:st});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(st)}};ct=mn([ke(1,l.Inject(k.HoverManagerService)),ke(2,l.Inject(k.CellAlertManagerService)),ke(3,l.Inject(l.LocaleService)),ke(4,l.Inject(T.FormulaDataModel)),ke(5,a.IZenZoneService)],ct);var Sn=Object.getOwnPropertyDescriptor,vn=(e,t,n,s)=>{for(var r=s>1?void 0:s?Sn(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},_t=(e,t)=>(n,s)=>t(n,s,e);let Ye=class extends l.Disposable{constructor(e,t){super(),this._autoFillService=e,this._lexerTreeBuilder=t,this._registerAutoFill()}_registerAutoFill(){const e={type:k.DATA_TYPE.FORMULA,priority:1001,match:t=>l.isFormulaString(t==null?void 0:t.f)||l.isFormulaId(t==null?void 0:t.si),isContinue:(t,n)=>t.type===k.DATA_TYPE.FORMULA,applyFunctions:{[k.APPLY_TYPE.COPY]:(t,n,s,r,o)=>{const{data:c,index:i}=t;return this._fillCopyFormula(c,n,s,i,r,o)}}};this._autoFillService.registerRule(e)}_fillCopyFormula(e,t,n,s,r,o){var h,m;const c=_n(r),i=[],u=new Map;for(let p=1;p<=t;p++){const f=(p-1)%e.length,g=s[f],d=l.Tools.deepClone(e[f]);if(d){const C=((h=e[f])==null?void 0:h.f)||"",_=((m=e[f])==null?void 0:m.si)||"",v=l.isFormulaString(C);if(l.isFormulaId(_))d.si=_,d.f=null,d.v=null,d.p=null,d.t=null,i.push(d);else if(v){let b=u.get(f);if(b)d.si=b,d.f=null,d.v=null,d.p=null,d.t=null;else{b=l.Tools.generateRandomId(6),u.set(f,b);const{offsetX:I,offsetY:S}=Cn(c,t,n,o,g),N=this._lexerTreeBuilder.moveFormulaRefOffset(C,I,S);d.si=b,d.f=N,d.v=null,d.p=null,d.t=null}i.push(d)}}}return i}};Ye=vn([_t(0,k.IAutoFillService),_t(1,l.Inject(T.LexerTreeBuilder))],Ye);function Cn(e,t,n,s,r){const{source:o,target:c}=s,{rows:i}=c,{rows:u}=o;let h=0,m=0;switch(n){case l.Direction.UP:m=i[r]-u[r];break;case l.Direction.RIGHT:h=e;break;case l.Direction.DOWN:m=i[r]-u[r];break;case l.Direction.LEFT:h=-e*t;break}return{offsetX:h,offsetY:m}}function _n(e){let t=0;for(const n in e)e[n].forEach(s=>{t+=s.data.length});return t}var Rn=Object.getOwnPropertyDescriptor,En=(e,t,n,s)=>{for(var r=s>1?void 0:s?Rn(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},Ae=(e,t)=>(n,s)=>t(n,s,e);const In="default-paste-formula";let ze=class extends l.Disposable{constructor(e,t,n,s,r){super(),this._currentUniverSheet=e,this._lexerTreeBuilder=t,this._sheetClipboardService=n,this._injector=s,this._formulaDataModel=r,this._initialize()}_initialize(){this._registerClipboardHook()}_registerClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteFormulaHook())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteWithFormulaHook()))}_pasteFormulaHook(){return{id:k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA,priority:10,specialPasteInfo:{label:"specialPaste.formula"},onPasteCells:(e,t,n,s)=>this._onPasteCells(e,t,n,s,!0)}}_pasteWithFormulaHook(){return{id:In,priority:10,onPasteCells:(e,t,n,s)=>this._onPasteCells(e,t,n,s,!1)}}_onPasteCells(e,t,n,s,r){var f;if([k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH].includes(s.pasteType))return{undos:[],redos:[]};const c=this._currentUniverSheet.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),i=t.unitId||c.getUnitId(),u=t.subUnitId||((f=c.getActiveSheet())==null?void 0:f.getSheetId());if(!i||!u)return{undos:[],redos:[]};const h=t.range,m=n,p={copyType:s.copyType||k.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:s.pasteType};return this._injector.invoke(g=>yn(i,u,h,m,g,p,this._lexerTreeBuilder,this._formulaDataModel,r,e))}};ze=En([Ae(0,l.IUniverInstanceService),Ae(1,l.Inject(T.LexerTreeBuilder)),Ae(2,k.ISheetClipboardService),Ae(3,l.Inject(l.Injector)),Ae(4,l.Inject(T.FormulaDataModel))],ze);function yn(e,t,n,s,r,o,c,i,u=!1,h){const m=[],p=[],f=bn(e,t,n,s,o,c,i,h);if(!f.hasValue())return{undos:[],redos:[]};const g={unitId:e,subUnitId:t,cellValue:f.getData()};m.push({id:A.SetRangeValuesMutation.id,params:g});const d=A.SetRangeValuesUndoMutationFactory(r,g);return p.push({id:A.SetRangeValuesMutation.id,params:d}),{undos:p,redos:m}}function bn(e,t,n,s,r,o,c,i){return i?r.pasteType===k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE?xn(e,t,n,s,c,i):r.pasteType===k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA?Mn(e,t,n,s,o,c,i):On(e,t,n,s,r.copyType,o,c,i):Tn(e,t,n,s,c)}function Tn(e,t,n,s,r){const o=new l.ObjectMatrix,c=r.getSheetFormulaData(e,t);return s.forValue((i,u,h)=>{var g;const m=n.rows[i],p=n.cols[u],f={};l.isFormulaString(h.v)?(f.v=null,f.f=`${h.v}`,f.si=null,f.p=null,o.setValue(m,p,f)):(g=c==null?void 0:c[m])!=null&&g[p]&&(f.v=h.v,f.f=null,f.si=null,f.p=null,o.setValue(m,p,f))}),o}function xn(e,t,n,s,r,o){var h,m;const c=new l.ObjectMatrix,i=(m=(h=r.getArrayFormulaCellData())==null?void 0:h[o.unitId])==null?void 0:m[o.subUnitId],u=r.getSheetFormulaData(e,t);return s.forValue((p,f,g)=>{var b,I;const d=o.range.rows[p%o.range.rows.length],C=o.range.cols[f%o.range.cols.length],_=n.rows[p],v=n.cols[f],E={};if(l.isFormulaString(g.f)||l.isFormulaId(g.si))E.v=g.v,E.f=null,E.si=null,E.p=null,c.setValue(_,v,E);else if((b=i==null?void 0:i[d])!=null&&b[C]){const S=i[d][C];E.v=S.v,E.f=null,E.si=null,E.p=null,c.setValue(_,v,E)}else if((I=u==null?void 0:u[_])!=null&&I[v]){if(E.v=g.v,E.f=null,E.si=null,E.p=null,g.p){const S=wt(g);S&&(E.v=S)}c.setValue(_,v,E)}}),c}function Mn(e,t,n,s,r,o,c){const i=new l.ObjectMatrix,u=new Map;return s.forValue((h,m,p)=>{const f=n.rows[h],g=n.cols[m],d={};if(l.isFormulaId(p.si)){if(c.unitId!==e||c.subUnitId!==t){const C=o.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[m%c.range.cols.length],c.subUnitId,c.unitId),_=n.cols[m]-c.range.cols[m%c.range.cols.length],v=n.rows[h]-c.range.rows[h%c.range.rows.length],E=r.moveFormulaRefOffset(C||"",_,v);d.si=null,d.f=E}else d.si=p.si,d.f=null;d.v=null,d.p=null,i.setValue(f,g,d)}else if(l.isFormulaString(p.f)){const C=`${h%c.range.rows.length}_${m%c.range.cols.length}`;let _=u.get(C);if(_)d.si=_,d.f=null;else{_=l.Tools.generateRandomId(6),u.set(C,_);const v=n.cols[m]-c.range.cols[m%c.range.cols.length],E=n.rows[h]-c.range.rows[h%c.range.rows.length],b=r.moveFormulaRefOffset(p.f||"",v,E);d.si=_,d.f=b}d.v=null,d.p=null,i.setValue(f,g,d)}else{if(d.v=p.v,d.f=null,d.si=null,d.p=null,p.p){const C=wt(p);C&&(d.v=C)}i.setValue(f,g,d)}}),i}function On(e,t,n,s,r,o,c,i){const u=new l.ObjectMatrix,h=new Map,m=c.getSheetFormulaData(e,t),p=[];return r===k.COPY_TYPE.CUT?s.forValue((f,g,d)=>{const C=n.rows[f],_=n.cols[g],v={};if(l.isFormulaId(d.si)){if(l.isFormulaString(d.f))p.push(d.si),v.f=d.f,v.si=d.si;else if(p.includes(d.si))v.f=null,v.si=d.si;else{const E=c.getFormulaStringByCell(i.range.rows[f%i.range.rows.length],i.range.cols[g%i.range.cols.length],i.subUnitId,i.unitId);v.f=E,v.si=null}v.v=null,v.p=null,u.setValue(C,_,v)}else l.isFormulaString(d.f)&&(v.f=d.f,v.si=null,v.v=null,v.p=null,u.setValue(C,_,v))}):s.forValue((f,g,d)=>{var E;const C=n.rows[f],_=n.cols[g],v={};if(l.isFormulaId(d.si)){if(i.unitId!==e||i.subUnitId!==t){const b=c.getFormulaStringByCell(i.range.rows[f%i.range.rows.length],i.range.cols[g%i.range.cols.length],i.subUnitId,i.unitId),I=n.cols[g]-i.range.cols[g%i.range.cols.length],S=n.rows[f]-i.range.rows[f%i.range.rows.length],N=o.moveFormulaRefOffset(b||"",I,S);v.si=null,v.f=N}else v.si=d.si,v.f=null;v.v=null,v.p=null,u.setValue(C,_,v)}else if(l.isFormulaString(d.f)){const b=`${f%i.range.rows.length}_${g%i.range.cols.length}`;let I=h.get(b);if(I)v.si=I,v.f=null;else{I=l.Tools.generateRandomId(6),h.set(b,I);const S=n.cols[g]-i.range.cols[g%i.range.cols.length],N=n.rows[f]-i.range.rows[f%i.range.rows.length],F=o.moveFormulaRefOffset(d.f||"",S,N);v.si=I,v.f=F}v.v=null,v.p=null,u.setValue(C,_,v)}else(E=m==null?void 0:m[C])!=null&&E[_]&&(v.v=d.v,v.f=null,v.si=null,v.p=d.p,u.setValue(C,_,v))}),p.length>0&&new l.ObjectMatrix(m).forValue((f,g,d)=>{if(!(i.range.rows.includes(f)&&i.range.cols.includes(g))&&!(n.rows.includes(f)&&n.cols.includes(g))&&p.includes(d==null?void 0:d.si)){const C=c.getFormulaStringByCell(f,g,i.subUnitId,i.unitId);u.setValue(f,g,{f:C,si:null,v:null,p:null})}}),u}function wt(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return;const n=t.dataStream;return n.substring(n.length-2,n.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n}}var Nn=Object.getOwnPropertyDescriptor,Dn=(e,t,n,s)=>{for(var r=s>1?void 0:s?Nn(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},be=(e,t)=>(n,s)=>t(n,s,e);let Ge=class extends l.Disposable{constructor(t,n,s,r,o,c,i,u){super();K(this,"_previousShape");K(this,"_skeleton");this._context=t,this._sheetInterceptorService=n,this._formulaDataModel=s,this._themeService=r,this._renderManagerService=o,this._sheetSkeletonManagerService=c,this._commandService=i,this._logService=u,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:c,sheetId:i}=t;this._updateArrayFormulaRangeShape(c,i)}}}))}_changeRuntime(t){this._skeleton=t}_initInterceptorEditorStart(){this.disposeWithMe(l.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(A.BEFORE_CELL_EDIT,{handler:(t,n,s)=>{var d,C,_,v;const{row:r,col:o,unitId:c,subUnitId:i,worksheet:u}=n,h=this._formulaDataModel.getArrayFormulaRange(),m=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return s(t);let p=null;const f=this._formulaDataModel.getFormulaStringByCell(r,o,i,c);if(f!==null&&(p={f}),t.v!=null&&t.v!==""&&((_=(C=(d=m[c])==null?void 0:d[i])==null?void 0:C[r])==null?void 0:_[o])==null)return p?{...t,...p}:s(t);const g=(v=h==null?void 0:h[c])==null?void 0:v[i];return g!=null&&(p=this._displayArrayFormulaRangeShape(g,r,o,c,i,u,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,c,i){const u=this._formulaDataModel.getSheetFormulaData(r,o);return new l.ObjectMatrix(t).forValue((h,m,p)=>{var _;if(p==null)return!0;const{startRow:f,startColumn:g,endRow:d,endColumn:C}=p;if(h===n&&m===s)return this._createArrayFormulaRangeShape(p,r),!1;if(n>=f&&n<=d&&s>=g&&s<=C){const v=c.getCell(f,g);if((v==null?void 0:v.v)===T.ErrorType.SPILL)return;const E=(_=u==null?void 0:u[h])==null?void 0:_[m];return E==null||E.f==null?!0:(i==null&&(i={f:E.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(p,r),!1)}}),i}_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 c={range:t,primary:null,style:{strokeWidth:1,stroke:this._themeService.getColorFromTheme("primary.600"),fill:new l.ColorKit(this._themeService.getColorFromTheme("white")).setAlpha(0).toString(),widgets:{}}},i=k.attachSelectionWithCoord(c,r),{rowHeaderWidth:u,columnHeaderHeight:h}=r,m=new k.SelectionControl(o,k.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:u,columnHeaderHeight:h});m.updateRangeBySelectionWithCoord(i),m.setEvent(!1),this._previousShape=m}_removeArrayFormulaRangeShape(){this._previousShape!=null&&(this._previousShape.dispose(),this._previousShape=null)}_refreshArrayFormulaRangeShape(t,n){if(this._previousShape){const{startRow:s,endRow:r,startColumn:o,endColumn:c}=this._previousShape.getRange(),i={startRow:s,endRow:r,startColumn:o,endColumn:c};this._removeArrayFormulaRangeShape(),this._createArrayFormulaRangeShape(i,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:c,endColumn:i}=this._previousShape.getRange();for(let u=0;u<s.length;u++){const{row:h}=s[u];if(r>=h){const m={startRow:r,endRow:o,startColumn:c,endColumn:i};this._refreshArrayFormulaRangeShape(t,m);break}}}};Ge=Dn([be(1,l.Inject(A.SheetInterceptorService)),be(2,l.Inject(T.FormulaDataModel)),be(3,l.Inject(l.ThemeService)),be(4,B.IRenderManagerService),be(5,l.Inject(k.SheetSkeletonManagerService)),be(6,l.ICommandService),be(7,l.ILogService)],Ge);var wn=Object.getOwnPropertyDescriptor,kn=(e,t,n,s)=>{for(var r=s>1?void 0:s?wn(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},Rt=(e,t)=>(n,s)=>t(n,s,e);const An={tl:{size:6,color:"#409f11"}};let Ze=class extends l.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(A.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,handler:(n,s,r)=>{var i,u,h,m;const o=(m=(h=(u=(i=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:i[s.unitId])==null?void 0:u[s.subUnitId])==null?void 0:h[s.row])==null?void 0:m[s.col];return!Dt(n,!!o)||!n||(n===s.rawData&&(n={...s.rawData}),n.markers={...n==null?void 0:n.markers,...An}),r(n)},priority:10}))}};Ze=kn([Rt(0,l.Inject(A.SheetInterceptorService)),Rt(1,l.Inject(T.FormulaDataModel))],Ze);function Fn(){const e=a.useDependency(Re.TriggerCalculationController),t=a.useDependency(l.ICommandService),n=a.useObservable(e.progress$),s=R.useCallback(()=>{t.executeCommand(T.SetFormulaCalculationStopMutation.id)},[t]),r=R.useCallback(()=>{e.clearProgress()},[e]);return y.jsx(a.ProgressBar,{progress:n,onTerminate:s,onClearProgress:r})}function Pn(e,t){return Object.keys(e).filter(n=>isNaN(Number(n))&&n!=="DefinedName").map(n=>({label:t.t(`formula.functionType.${n.toLocaleLowerCase()}`),value:`${e[n]}`}))}function kt(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 At(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:kt(s)}),r===n.length-1?"":","]},r)),")"]})}function Fe(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:W.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 Ln(e){const{functionInfo:t,onChange:n}=e;if(!t)return null;const[s,r]=R.useState([]),[o,c]=R.useState(t.functionParameter),[i,u]=R.useState(-1);return y.jsxs("div",{children:[y.jsx("div",{className:W.clsx("univer-h-[364px] univer-overflow-y-auto",W.scrollbarClassName),children:o.map((h,m)=>y.jsxs("div",{children:[y.jsx("div",{className:"univer-text-sm",children:h.name}),y.jsx("div",{className:"univer-mb-2 univer-mt-1"})]},m))}),y.jsx("div",{className:W.clsx("univer-flex-1 univer-p-3",W.borderLeftClassName),children:y.jsx(Fe,{title:i===-1?y.jsx(At,{prefix:t.functionName,value:o}):o[i].name,value:i===-1?t.description:o[i].detail})})]})}var ue=function(){return ue=Object.assign||function(e){for(var t,n=1,s=arguments.length;n<s;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},ue.apply(this,arguments)},Un=function(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(n[s[r]]=e[s[r]]);return n},Me=R.forwardRef(function(e,t){var n=e.icon,s=e.id,r=e.className,o=e.extend,c=Un(e,["icon","id","className","extend"]),i="univerjs-icon univerjs-icon-".concat(s," ").concat(r||"").trim(),u=R.useRef("_".concat(Wn()));return Ft(n,"".concat(s),{defIds:n.defIds,idSuffix:u.current},ue({ref:t,className:i},c),o)});function Ft(e,t,n,s,r){return R.createElement(e.tag,ue(ue({key:t},$n(e,n,r)),s),(jn(e,n).children||[]).map(function(o,c){return Ft(o,"".concat(t,"-").concat(e.tag,"-").concat(c),n,void 0,r)}))}function $n(e,t,n){var s=ue({},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(function(o){var c=o[0],i=o[1];c==="mask"&&typeof i=="string"&&(s[c]=i.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var r=t.defIds;return!r||r.length===0||(e.tag==="use"&&s["xlink:href"]&&(s["xlink:href"]=s["xlink:href"]+t.idSuffix),Object.entries(s).forEach(function(o){var c=o[0],i=o[1];typeof i=="string"&&(s[c]=i.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),s}function jn(e,t){var n,s=t.defIds;return!s||s.length===0?e:e.tag==="defs"&&(!((n=e.children)===null||n===void 0)&&n.length)?ue(ue({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&s&&s.includes(r.attrs.id)?ue(ue({},r),{attrs:ue(ue({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):e}function Wn(){return Math.random().toString(36).substring(2,8)}Me.displayName="UniverIcon";var Vn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Pt=R.forwardRef(function(e,t){return R.createElement(Me,Object.assign({},e,{id:"check-mark-icon",ref:t,icon:Vn}))});Pt.displayName="CheckMarkIcon";var Hn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},Lt=R.forwardRef(function(e,t){return R.createElement(Me,Object.assign({},e,{id:"close-icon",ref:t,icon:Hn}))});Lt.displayName="CloseIcon";var Bn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ut=R.forwardRef(function(e,t){return R.createElement(Me,Object.assign({},e,{id:"delete-icon",ref:t,icon:Bn}))});Ut.displayName="DeleteIcon";var Kn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},$t=R.forwardRef(function(e,t){return R.createElement(Me,Object.assign({},e,{id:"increase-icon",ref:t,icon:Kn}))});$t.displayName="IncreaseIcon";var qn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.90913 3.57564C6.14345 3.34132 6.52335 3.34132 6.75766 3.57564L10.7577 7.57564C10.992 7.80995 10.992 8.18985 10.7577 8.42417L6.75766 12.4242C6.52335 12.6585 6.14345 12.6585 5.90913 12.4242C5.67482 12.1899 5.67482 11.81 5.90913 11.5756L9.48487 7.9999L5.90913 4.42417C5.67482 4.18985 5.67482 3.80995 5.90913 3.57564Z",fillRule:"evenodd",clipRule:"evenodd"}}]},jt=R.forwardRef(function(e,t){return R.createElement(Me,Object.assign({},e,{id:"more-icon",ref:t,icon:qn}))});jt.displayName="MoreIcon";var Yn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6185 12.4423C12.5907 12.2749 12.7773 12.15 12.9343 12.2308L15.4242 13.5126C15.6102 13.6084 15.5544 13.8745 15.3439 13.8955L14.2456 14.184L13.4521 15.1286C13.3495 15.2939 13.085 15.2463 13.0534 15.0568L12.6185 12.4423Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1 3.6C1 2.16406 2.16406 1 3.6 1H12.3C13.7359 1 14.9 2.16406 14.9 3.6V5.81156C14.9003 5.81881 14.9004 5.82609 14.9004 5.8334C14.9004 5.84071 14.9003 5.84799 14.9 5.85524V10.045C14.9003 10.0522 14.9004 10.0595 14.9004 10.0668C14.9004 10.3982 14.6318 10.6668 14.3004 10.6668H11.1668C10.8907 10.6668 10.6668 10.8907 10.6668 11.1668V14.3C10.6668 14.6314 10.3982 14.9 10.0668 14.9L10.05 14.8998L3.6 14.9C2.16406 14.9 1 13.7359 1 12.3V3.6ZM13.2 5.2334C13.4761 5.2334 13.7 5.00954 13.7 4.7334V3.6C13.7 2.8268 13.0732 2.2 12.3 2.2H11.1668C10.8907 2.2 10.6668 2.42386 10.6668 2.7V4.7334C10.6668 5.00954 10.8907 5.2334 11.1668 5.2334H13.2ZM10.6668 6.9334C10.6668 6.65726 10.8907 6.4334 11.1668 6.4334H13.2C13.4761 6.4334 13.7 6.65726 13.7 6.9334V8.9668C13.7 9.24294 13.4761 9.4668 13.2 9.4668H11.1668C10.8907 9.4668 10.6668 9.24294 10.6668 8.9668V6.9334ZM8.9668 5.2334C9.24294 5.2334 9.4668 5.00954 9.4668 4.7334V2.7C9.4668 2.42386 9.24294 2.2 8.9668 2.2H6.9334C6.65726 2.2 6.4334 2.42386 6.4334 2.7V4.7334C6.4334 5.00954 6.65726 5.2334 6.9334 5.2334L8.9668 5.2334ZM6.4334 6.9334C6.4334 6.65726 6.65726 6.4334 6.9334 6.4334L8.9668 6.4334C9.24294 6.4334 9.4668 6.65726 9.4668 6.9334V8.9668C9.4668 9.24294 9.24294 9.4668 8.9668 9.4668L6.9334 9.4668C6.65726 9.4668 6.4334 9.24294 6.4334 8.9668V6.9334ZM4.7334 5.2334C5.00954 5.2334 5.2334 5.00954 5.2334 4.7334V2.7C5.2334 2.42386 5.00954 2.2 4.7334 2.2H3.6C2.8268 2.2 2.2 2.8268 2.2 3.6V4.7334C2.2 5.00954 2.42386 5.2334 2.7 5.2334H4.7334ZM2.2 6.9334C2.2 6.65726 2.42386 6.4334 2.7 6.4334H4.7334C5.00954 6.4334 5.2334 6.65725 5.2334 6.9334V8.9668C5.2334 9.24294 5.00954 9.4668 4.7334 9.4668H2.7C2.42386 9.4668 2.2 9.24294 2.2 8.9668V6.9334ZM5.2334 11.1668C5.2334 10.8907 5.00954 10.6668 4.7334 10.6668H2.7C2.42386 10.6668 2.2 10.8907 2.2 11.1668V12.3C2.2 13.0732 2.8268 13.7 3.6 13.7H4.7334C5.00954 13.7 5.2334 13.4761 5.2334 13.2V11.1668ZM9.4668 11.1668C9.4668 10.8907 9.24294 10.6668 8.9668 10.6668H6.9334C6.65726 10.6668 6.4334 10.8907 6.4334 11.1668V13.2C6.4334 13.4761 6.65726 13.7 6.9334 13.7H8.9668C9.24294 13.7 9.4668 13.4761 9.4668 13.2V11.1668Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Wt=R.forwardRef(function(e,t){return R.createElement(Me,Object.assign({},e,{id:"select-range-icon",ref:t,icon:Yn}))});Wt.displayName="SelectRangeIcon";function zn(e){const{onChange:t}=e,n="-1",[s,r]=R.useState(""),[o,c]=R.useState([]),[i,u]=R.useState(0),[h,m]=R.useState(n),[p,f]=R.useState(0),[g,d]=R.useState(null),C=a.useDependency(Re.IDescriptionService),_=a.useDependency(l.LocaleService),v=a.useDependency(a.ISidebarService),E=a.useObservable(v.sidebarOptions$),b=Pn(T.FunctionType,_);b.unshift({label:_.t("formula.moreFunctions.allFunctions"),value:n});const I=_.t("formula.prompt.required"),S=_.t("formula.prompt.optional");R.useEffect(()=>{L(n)},[]),R.useEffect(()=>{F(0)},[o]),R.useEffect(()=>{E!=null&&E.visible&&(r(""),c([]),u(0),m(n),f(0),d(null),L(n))},[E]);const N=M=>{if(s.trim()==="")return M;const x=new RegExp(`(${s.toLocaleUpperCase()})`);return M.split(x).filter(Boolean).map((P,$)=>P.match(x)?y.jsx("span",{className:"univer-text-red-500",children:P},$):P)},F=M=>{if(o.length===0){d(null);return}f(M);const x=C.getFunctionInfo(o[M].name);if(!x){d(null);return}d(x),t(x)};function L(M){m(M);const x=C.getSearchListByType(+M);c(x)}function U(M){r(M);const x=C.getSearchListByName(M);c(x)}function w(M){if(M.stopPropagation(),M.key==="ArrowDown"){const x=i+1;u(x===o.length?0:x)}else if(M.key==="ArrowUp"){const x=i-1;u(x===-1?o.length-1:x)}else M.key==="Enter"&&F(i)}const j=M=>{u(M)},D=()=>{u(-1)};return y.jsxs("div",{children:[y.jsxs("div",{className:"univer-flex univer-items-center univer-justify-between univer-gap-2",children:[y.jsx(W.Select,{value:h,options:b,onChange:L}),y.jsx(W.Input,{placeholder:_.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:w,value:s,onChange:U,size:"small",allowClear:!0})]}),o.length>0&&y.jsx("ul",{className:W.clsx("univer-m-0 univer-mt-2 univer-box-border univer-max-h-72 univer-w-full univer-select-none univer-list-none univer-overflow-y-auto univer-rounded univer-p-3 univer-outline-none",W.borderClassName,W.scrollbarClassName),onKeyDown:w,tabIndex:-1,children:o.map(({name:M},x)=>y.jsxs("li",{className:W.clsx("univer-relative univer-box-border univer-cursor-pointer univer-rounded univer-px-7 univer-py-1 univer-text-sm univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200 dark:!univer-bg-gray-600":i===x}),onMouseEnter:()=>j(x),onMouseLeave:D,onClick:()=>F(x),children:[p===x&&y.jsx(Pt,{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:N(M)})]},x))}),g&&y.jsxs("div",{className:W.clsx("univer-mx-0 univer-my-2 univer-overflow-y-auto",W.scrollbarClassName),children:[y.jsx(Fe,{title:g.functionName,value:g.description}),y.jsx(Fe,{title:_.t("formula.moreFunctions.syntax"),value:y.jsx(At,{prefix:g.functionName,value:g.functionParameter})}),y.jsx(Fe,{title:_.t("formula.prompt.helpExample"),value:`${g.functionName}(${g.functionParameter.map(M=>M.example).join(",")})`}),g.functionParameter&&g.functionParameter.map(M=>y.jsx(Fe,{title:M.name,value:`${M.require?I:S} ${M.detail}`},M.name))]})]})}function Gn(){const e=k.useActiveWorkbook(),[t,n]=R.useState(!0),[s,r]=R.useState(!1),[o,c]=R.useState(null);a.useDependency(k.IEditorBridgeService);const i=a.useDependency(l.LocaleService),u=a.useDependency(J.IEditorService),h=a.useDependency(l.IUniverInstanceService),m=a.useDependency(l.ICommandService);function p(){n(!t),r(!s)}function f(){const g=A.getSheetCommandTarget(h);if(!g)return;m.executeCommand(k.SetCellEditVisibleOperation.id,{visible:!0,unitId:g.unitId,eventType:B.DeviceInputEventType.Dblclick});const d=u.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),C=u.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),_=`=${o==null?void 0:o.functionName}(`;d==null||d.replaceText(_),C==null||C.replaceText(_,!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(zn,{onChange:c}),s&&y.jsx(Ln,{functionInfo:o,onChange:()=>{}}),y.jsxs("div",{className:"univer-flex univer-justify-end",children:[s&&y.jsx(W.Button,{variant:"primary",onClick:p,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:i.t("formula.moreFunctions.next")}),s&&y.jsx(W.Button,{onClick:p,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:i.t("formula.moreFunctions.prev")}),t&&!!e&&y.jsx(W.Button,{variant:"primary",onClick:f,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:i.t("formula.moreFunctions.confirm")})]})]})}function Zn(e){return{id:de.id,title:"SUM",icon:"SumIcon",type:a.MenuItemType.BUTTON,params:{value:"SUM"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function Xn(e){return{id:de.id,title:"COUNT",icon:"CntIcon",type:a.MenuItemType.BUTTON,params:{value:"COUNT"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function Qn(e){return{id:de.id,title:"AVERAGE",icon:"AvgIcon",type:a.MenuItemType.BUTTON,params:{value:"AVERAGE"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function Jn(e){return{id:de.id,title:"MAX",icon:"MaxIcon",type:a.MenuItemType.BUTTON,params:{value:"MAX"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function er(e){return{id:de.id,title:"MIN",icon:"MinIcon",type:a.MenuItemType.BUTTON,params:{value:"MIN"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function tr(e){return{id:et.id,title:"formula.insert.more",tooltip:"formula.insert.tooltip",type:a.MenuItemType.BUTTON,hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function nr(e){return e.get(l.IUniverInstanceService).getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(q.switchMap(s=>s&&e.get(a.IClipboardInterfaceService)?new q.Observable(o=>o.next(!e.get(a.IClipboardInterfaceService).supportClipboard)):q.of(!0)))}function rr(e){return{id:Qe.id,type:a.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:nr(e).pipe(q.combineLatestWith(k.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint],worksheetTypes:[A.WorksheetSetCellValuePermission,A.WorksheetEditPermission]})),q.map(([t,n])=>t||n))}}const sr={[a.RibbonFormulasGroup.BASIC]:{[`${de.id}.sum`]:{order:0,menuItemFactory:Zn},[`${de.id}.count`]:{order:1,menuItemFactory:Xn},[`${de.id}.average`]:{order:2,menuItemFactory:Qn},[`${de.id}.max`]:{order:3,menuItemFactory:Jn},[`${de.id}.min`]:{order:4,menuItemFactory:er}},[a.RibbonFormulasGroup.OTHERS]:{[et.id]:{order:0,menuItemFactory:tr}},[k.PASTE_SPECIAL_MENU_ID]:{[Qe.id]:{order:4,menuItemFactory:rr}}},or="meta_key_ctrl_And_Shift",tt=[a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP,a.KeyCode.ARROW_LEFT,a.KeyCode.ARROW_RIGHT],ir=[...tt,a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ESC];function cr(){const e=[];for(const t of ir)e.push({id:xe.id,binding:t,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:B.DeviceInputEventType.Keyboard,keycode:t}});return e}function ar(){const e=[];for(const t of tt)e.push({id:xe.id,binding:t|a.MetaKeys.SHIFT,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:B.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.SHIFT}});return e}function lr(){const e=[];for(const t of tt)e.push({id:xe.id,binding:t|a.MetaKeys.CTRL_COMMAND,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:B.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.CTRL_COMMAND}});return e}function ur(){const e=[];for(const t of tt)e.push({id:xe.id,binding:t|a.MetaKeys.SHIFT|a.MetaKeys.CTRL_COMMAND,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:B.DeviceInputEventType.Keyboard,keycode:t,metaKey:or}});return e}const dr={id:lt.id,binding:a.KeyCode.F4,preconditions:e=>k.whenFormulaEditorActivated(e)};function hr(){const e=[];for(const t of[a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP])e.push({id:xe.id,binding:t,preconditions:n=>fn(n),staticParameters:{eventType:B.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}const fr={id:Re.QuickSumCommand.id,binding:a.MetaKeys.ALT|a.KeyCode.EQUAL,preconditions:k.whenSheetEditorFocused,mac:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.ALT|a.KeyCode.EQUAL,description:"shortcut.sheets-formula-ui.quick-sum",group:"4_sheet-edit"};var gr=Object.getOwnPropertyDescriptor,mr=(e,t,n,s)=>{for(var r=s>1?void 0:s?gr(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},Te=(e,t)=>(n,s)=>t(n,s,e);let Xe=class extends l.Disposable{constructor(e,t,n,s,r,o,c){super(),this._injector=e,this._menuManagerService=t,this._commandService=n,this._shortcutService=s,this._uiPartsService=r,this._renderManagerService=o,this._componentManager=c,this._initialize()}_initialize(){this._registerCommands(),this._registerMenus(),this._registerShortcuts(),this._registerComponents(),this._registerRenderModules()}_registerMenus(){this._menuManagerService.mergeMenu(sr)}_registerCommands(){[Qe,de,et,Nt,xt,xe,lt].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...cr(),...ar(),...lr(),...ur(),...hr(),fr,dr].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(k.SheetsUIPart.FORMULA_AUX,()=>a.connectInjector(Fn,this._injector))),this._componentManager.register(Ot,Gn)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,[Ge]))}};Xe=mr([Te(0,l.Inject(l.Injector)),Te(1,a.IMenuManagerService),Te(2,l.ICommandService),Te(3,a.IShortcutService),Te(4,a.IUIPartsService),Te(5,B.IRenderManagerService),Te(6,l.Inject(a.ComponentManager))],Xe);class ut{constructor(){K(this,"_currentSelector$",new q.BehaviorSubject(null));K(this,"currentSelector$",this._currentSelector$.asObservable())}showRangeSelectorDialog(t){const n=t.callback,s=new Promise(r=>{t.callback=o=>{r(o),n(o)}});return this._currentSelector$.next(t),s}}var pr=Object.getOwnPropertyDescriptor,Sr=(e,t,n,s)=>{for(var r=s>1?void 0:s?pr(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},we=(e,t)=>(n,s)=>t(n,s,e);exports.RefSelectionsRenderService=class extends k.BaseSelectionRenderService{constructor(n,s,r,o,c,i,u){super(s,r,o,c,i);K(this,"_workbookSelections");K(this,"_eventDisposables");this._context=n,this._contextService=i,this._refSelectionsService=u,this._workbookSelections=this._refSelectionsService.getWorkbookSelections(this._context.unitId),this._initSelectionChangeListener(),this._initSkeletonChangeListener(),this._initUserActionSyncListener(),this._setSelectionStyle(vr(this._themeService)),this._remainLastEnabled=!0,this._highlightHeader=!1}getLocation(){return this._skeleton.getLocation()}setRemainLastEnabled(n){this._remainLastEnabled=n}setSkipLastEnabled(n){this._skipLastEnabled=n}clearLastSelection(){const n=this._selectionControls[this._selectionControls.length-1];n&&(n.dispose(),this._selectionControls.pop())}enableSelectionChanging(){return this._disableSelectionChanging(),this._eventDisposables=this._initCanvasEventListeners(),l.toDisposable(()=>this._disableSelectionChanging())}_disableSelectionChanging(){var n;(n=this._eventDisposables)==null||n.dispose(),this._eventDisposables=null}disableSelectionChanging(){this._disableSelectionChanging()}_initCanvasEventListeners(){const n=this._getSheetObject(),{spreadsheetRowHeader:s,spreadsheetColumnHeader:r,spreadsheet:o,spreadsheetLeftTopPlaceholder:c}=n,{scene:i}=this._context,u=new l.DisposableCollection;return u.add(o==null?void 0:o.onPointerDown$.subscribeEvent((h,m)=>{this.inRefSelectionMode()&&(this._onPointerDown(h,o.zIndex+1,l.RANGE_TYPE.NORMAL,this._getActiveViewport(h)),h.button!==2&&m.stopPropagation())})),u.add(s==null?void 0:s.onPointerDown$.subscribeEvent((h,m)=>{if(!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:f}=k.getCoordByOffset(h.offsetX,h.offsetY,i,p);k.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),f,l.RANGE_TYPE.ROW)||(this._onPointerDown(h,(o.zIndex||1)+1,l.RANGE_TYPE.ROW,this._getActiveViewport(h),B.ScrollTimerType.Y),h.button!==2&&m.stopPropagation())})),u.add(r==null?void 0:r.onPointerDown$.subscribeEvent((h,m)=>{if(!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:f}=k.getCoordByOffset(h.offsetX,h.offsetY,i,p);k.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),f,l.RANGE_TYPE.COLUMN)||(this._onPointerDown(h,(o.zIndex||1)+1,l.RANGE_TYPE.COLUMN,this._getActiveViewport(h),B.ScrollTimerType.X),h.button!==2&&m.stopPropagation())})),u.add(c==null?void 0:c.onPointerDown$.subscribeEvent((h,m)=>{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 g=i.onPointerUp$.subscribeEvent(()=>{g.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});h.button!==2&&m.stopPropagation()})),u}_addSelectionControlByModelData(n){var i;const s=this._skeleton,r=(i=n.style)!=null?i: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(c=>A.convertSelectionDataToRange(c)),s)}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(n=>{if(!n)return;const{skeleton:s}=n,{scene:r}=this._context,o=r.getViewport(B.SHEET_VIEWPORT_KEY.VIEW_MAIN);this._skeleton&&this._skeleton.worksheet.getSheetId()!==s.worksheet.getSheetId()&&this._reset(),this._changeRuntime(s,r,o);const c=this._workbookSelections.getCurrentSelections();this.resetSelectionsByModelData(c)}))}_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=l.RANGE_TYPE.NORMAL,o,c=B.ScrollTimerType.ALL){var j;this._rangeType=r;const i=this._skeleton,u=this._scene;if(!u||!i)return;o&&(this._activeViewport=o);const{offsetX:h,offsetY:m}=n,p=u.getViewport(B.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!p)return;const f=u.getCoordRelativeToViewport(B.Vector2.FromArray([h,m])),{x:g,y:d}=f;this._startViewportPosX=g,this._startViewportPosY=d;const C=u.getScrollXYInfoByViewport(f),{scaleX:_,scaleY:v}=u.getAncestorScale(),E=this._skeleton.getCellByOffset(g,d,_,v,C);if(!E)return;switch(r){case l.RANGE_TYPE.NORMAL:break;case l.RANGE_TYPE.ROW:E.startColumn=0,E.endColumn=this._skeleton.getColumnCount()-1;break;case l.RANGE_TYPE.COLUMN:E.startRow=0,E.endRow=this._skeleton.getRowCount()-1;break;case l.RANGE_TYPE.ALL:E.startRow=0,E.startColumn=0,E.endRow=this._skeleton.getRowCount()-1,E.endColumn=this._skeleton.getColumnCount()-1}const b={range:E,primary:E,style:null};b.range.rangeType=r;const I=k.attachSelectionWithCoord(b,this._skeleton);this._startRangeWhenPointerDown={...I.rangeWithCoord};const S={...I.rangeWithCoord,rangeType:r};let N=this.getActiveSelectionControl();const F=this.getSelectionControls();for(const D of F){if(n.button===2&&l.Rectangle.contains(D.model,S)){N=D;return}if(D.model.isEqual(S)){N=D;break}}this._checkClearPreviousControls(n);const L=N==null?void 0:N.model.currentCell,U=n.shiftKey&&L,w=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;U&&L?this._makeSelectionByTwoCells(L,S,i,r,N):w&&N?N.updateRangeBySelectionWithCoord(I):N=this.newSelectionControl(u,i,b);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(),(j=u.getTransformer())==null||j.clearSelectedObjects(),this._setupPointerMoveListener(p,N,r,c,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,s,r){const o=this.getSelectionControls().length,{rowHeaderWidth:c,columnHeaderHeight:i}=s,u=new k.SelectionControl(n,o,this._themeService,{highlightHeader:this._highlightHeader,enableAutoFill:!1,rowHeaderWidth:c,columnHeaderHeight:i}),h=k.attachSelectionWithCoord(r,s);return u.updateRangeBySelectionWithCoord(h),this._selectionControls.push(u),u.setControlExtension({skeleton:s,scene:n,themeService:this._themeService,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),u}};exports.RefSelectionsRenderService=Sr([we(1,l.Inject(l.Injector)),we(2,l.Inject(l.ThemeService)),we(3,a.IShortcutService),we(4,l.Inject(k.SheetSkeletonManagerService)),we(5,l.IContextService),we(6,A.IRefSelectionsService)],exports.RefSelectionsRenderService);function vr(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 dt=(e,t,n=!0)=>{let s=-1;return e.reduce((r,o,c)=>{if(r.isFinish)return r;const i=r.currentIndex;if(typeof o!="string")r.currentIndex+=o.token.length;else{const u=o.length;r.currentIndex+=u}return(n?r.currentIndex===t:t>i&&t<=r.currentIndex)&&(s=c,r.isFinish=!0),r},{currentIndex:0,isFinish:!1}),s},Vt=(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},Cr=(e,t=100)=>{R.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 Ht(e,t,n){const s=a.useDependency(J.IEditorService),r=R.useMemo(()=>new q.BehaviorSubject({left:-999,top:-999,right:-999,bottom:-999}),[]),o=a.useDependency(a.ISidebarService),c=a.useDependency(l.IUniverInstanceService),i=a.useEvent(()=>{var b;const u=s.getEditor(e);if(!u)return;const h=u.getBoundingClientRect(),{marginTop:m=0,marginBottom:p=0}=u.getDocumentData().documentStyle,f=u.getSkeleton();if(!f)return;const g=(b=f.getSkeletonData())==null?void 0:b.pages[0].height;let{left:d,top:C,right:_,bottom:v}=h;C=C+m,v=g?C+g:v-p;const E=r.getValue();if(!(E.left===d&&E.top===C&&E.right===_&&E.bottom===v))return r.next({left:d-1,right:_+1,top:C-1,bottom:v+1}),h});return R.useEffect(()=>{t&&i()},[e,s,c.unitAdded$,i,t,...n!=null?n:[]]),Cr(i),R.useEffect(()=>{const u=o.scrollEvent$.pipe(q.throttleTime(100)).subscribe(i);return()=>{u.unsubscribe()}},[]),[r,i]}const Oe=e=>{const t=R.useRef(e);return t.current=e,t},_r=(e,t,n)=>{const s=a.useDependency(Je),r=a.useDependency(Re.IDescriptionService),o=a.useDependency(T.LexerTreeBuilder),[c,i]=R.useState(),[u,h]=R.useState(-1),[m,p]=R.useState(!0),f=Oe(m),g=R.useRef(t);g.current=t;const d=()=>{i(void 0),h(-1),p(!1)};return R.useEffect(()=>{const C=o.sequenceNodesBuilder(t.slice(1));s.setSequenceNodes(C!=null?C:[])},[t]),R.useEffect(()=>{if(n&&e){const C=n.selectionChange$.pipe(q.debounceTime(50)).subscribe(v=>{if(v.textRanges.length===1){const[E]=v.textRanges;if(E.collapsed&&f.current){const{startOffset:b}=E,I=s.getCurrentSequenceNode(b-2);if(I)if(typeof I!="string"&&I.nodeType===3&&!r.hasDefinedNameDescription(I.token.trim())){const S=r.getFunctionInfo(I.token);i(S),h(-1);return}else{const S=o.getFunctionAndParameter(`${g.current}A`,b-1);if(S){const{functionName:N,paramIndex:F}=S,L=r.getFunctionInfo(N);i(L),h(F);return}}}}i(void 0),h(-1)}),_=n.selectionChange$.pipe(q.filter(v=>v.textRanges.length===1),q.map(v=>v.textRanges[0].startOffset),q.distinctUntilChanged()).subscribe(()=>{p(!0)});return()=>{C.unsubscribe(),_.unsubscribe()}}},[n,e]),R.useEffect(()=>{e||d()},[e]),{functionInfo:c,paramIndex:u,reset:d}},Rr=({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:"?"}),ot=({className:e,title:t,value:n})=>y.jsxs("div",{className:"univer-my-2",children:[y.jsx("div",{className:W.clsx("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",e),children:t}),y.jsx("div",{className:"univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",children:n})]}),Er=e=>{const{prefix:t,value:n,active:s,onClick:r}=e;return y.jsxs("div",{children:[y.jsxs("span",{children:[t,"("]}),n&&n.map((o,c)=>y.jsxs("span",{children:[y.jsx("span",{className:s===c?"univer-text-primary-500":"",onClick:()=>r(c),children:kt(o)}),c===n.length-1?"":","]},o.name)),")"]})},Et=()=>{};function Ir(e){const{onParamsSwitch:t=Et,onClose:n=Et,isFocus:s,editor:r,formulaText:o}=e,{functionInfo:c,paramIndex:i,reset:u}=_r(s,o,r),h=a.useDependency(k.IEditorBridgeService),m=!a.useObservable(h.helpFunctionVisible$),[p,f]=R.useState(!0),g=a.useDependency(l.LocaleService),d=g.t("formula.prompt.required"),C=g.t("formula.prompt.optional"),_=r.getEditorId(),[v]=Ht(_,!!c,[c,i]);function E(S){t&&t(S)}const b=a.useEvent(S=>{h.helpFunctionVisible$.next(!S)}),I=()=>{b(!0),n()};return c?m?y.jsx(a.RectPopup,{portal:!0,anchorRect$:v,direction:"left-center",children:y.jsx(Rr,{onClick:()=>b(!1)})},"hidden"):y.jsx(a.RectPopup,{portal:!0,onClickOutside:()=>u(),anchorRect$:v,direction:"vertical",children:y.jsxs("div",{className:W.clsx("univer-m-0 univer-box-border univer-w-[250px] univer-select-none univer-list-none univer-rounded-lg univer-bg-white univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",W.borderClassName),children:[y.jsxs("div",{className:W.clsx("univer-wrap-anywhere univer-box-border univer-flex univer-items-center univer-justify-between univer-px-4 univer-py-3 univer-text-xs univer-font-medium univer-text-gray-900 dark:!univer-text-white",W.borderTopClassName),children:[y.jsx(Er,{prefix:c.functionName,value:c.functionParameter,active:i,onClick:E}),y.jsxs("div",{className:"univer-flex",children:[y.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-500 univer-outline-none univer-transition-colors hover:univer-bg-gray-200 dark:hover:!univer-bg-gray-600",style:{transform:p?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>f(!p),children:y.jsx(jt,{})}),y.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-600 univer-outline-none univer-transition-colors hover:univer-bg-gray-300 dark:!univer-text-gray-200 dark:hover:!univer-bg-gray-600",onClick:I,children:y.jsx(Lt,{})})]})]}),y.jsx("div",{className:W.clsx("univer-box-border univer-max-h-[350px] univer-overflow-y-auto univer-px-4 univer-pb-3 univer-pt-0",W.scrollbarClassName),style:{height:p?"unset":0,padding:p?"revert-layer":0},children:y.jsxs("div",{className:"univer-mt-3",children:[y.jsx(ot,{title:g.t("formula.prompt.helpExample"),value:`${c.functionName}(${c.functionParameter.map(S=>S.example).join(",")})`}),y.jsx(ot,{title:g.t("formula.prompt.helpAbstract"),value:c.description}),c&&c.functionParameter&&c.functionParameter.map((S,N)=>y.jsx(ot,{className:i===N?"univer-text-primary-500":"",title:S.name,value:`${S.require?d:C} ${S.detail}`},N))]})})]})},"show"):null}const yr=e=>{const t=a.useDependency(J.IEditorService);return a.useEvent(s=>{var r,o;if(e){t.focus(e.getEditorId());const c=[...e.getSelectionRanges()];if(l.Tools.isDefine(s))e.setSelectionRanges([{startOffset:s,endOffset:s}]);else if(!c.length&&!e.docSelectionRenderService.isOnPointerEvent){const i=(o=(r=e.getDocumentData().body)==null?void 0:r.dataStream)!=null?o:`\r
|
|
1
|
+
"use strict";var Xt=Object.defineProperty;var Qt=(e,t,n)=>t in e?Xt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var K=(e,t,n)=>Qt(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),k=require("@univerjs/sheets-ui"),T=require("@univerjs/engine-formula"),q=require("rxjs"),J=require("@univerjs/docs-ui"),B=require("@univerjs/engine-render"),A=require("@univerjs/sheets"),Re=require("@univerjs/sheets-formula"),a=require("@univerjs/ui"),y=require("react/jsx-runtime"),R=require("react"),W=require("@univerjs/design"),bt=require("@univerjs/docs"),Jt=require("rxjs/operators"),Qe={id:"sheet.command.paste-formula",type:l.CommandType.COMMAND,handler:async e=>e.get(l.ICommandService).executeCommand(k.SheetPasteCommand.id,{value:k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA})},xe={id:"formula-ui.operation.select-editor-formula",type:l.CommandType.OPERATION,handler:(e,t)=>!0};var en=Object.getOwnPropertyDescriptor,tn=(e,t,n,s)=>{for(var r=s>1?void 0:s?en(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},nn=(e,t)=>(n,s)=>t(n,s,e);const Tt="FORMULA_PROMPT_ACTIVATED",Je=l.createIdentifier("formula-ui.prompt-service");let it=class{constructor(e){K(this,"_search$",new q.Subject);K(this,"_help$",new q.Subject);K(this,"_navigate$",new q.Subject);K(this,"_accept$",new q.Subject);K(this,"_acceptFormulaName$",new q.Subject);K(this,"search$",this._search$.asObservable());K(this,"help$",this._help$.asObservable());K(this,"navigate$",this._navigate$.asObservable());K(this,"accept$",this._accept$.asObservable());K(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());K(this,"_searching",!1);K(this,"_helping",!1);K(this,"_sequenceNodes",[]);K(this,"_isLockedOnSelectionChangeRefString",!1);K(this,"_isLockedOnSelectionInsertRefString",!1);this._contextService=e}dispose(){this._search$.complete(),this._help$.complete(),this._navigate$.complete(),this._accept$.complete(),this._acceptFormulaName$.complete(),this._sequenceNodes=[]}search(e){this._contextService.setContextValue(Tt,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:c}=o;t=c}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,c=this._sequenceNodes.length;o<c;o++){const i=this._sequenceNodes[o];if(typeof i=="string")continue;const u={...i};u.startIndex+=s,u.endIndex+=s,this._sequenceNodes[o]=u}}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 c=this._sequenceNodes[r];if(typeof c=="string")continue;const i={...c};i.startIndex+=n,i.endIndex+=n,this._sequenceNodes[r]=i}}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,c=this._sequenceNodes.length;o<c;o++){const i=this._sequenceNodes[o];if(typeof i=="string")continue;const u={...i};u.startIndex+=r,u.endIndex+=r,this._sequenceNodes[o]=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}};it=tn([nn(0,l.IContextService)],it);const xt={id:"formula-ui.operation.help-function",type:l.CommandType.OPERATION,handler:async(e,t)=>(e.get(Je).help(t),!0)},de={id:"formula-ui.operation.insert-function",type:l.CommandType.OPERATION,handler:async(e,t)=>{var E,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(l.IUniverInstanceService));if(!o)return!1;const{worksheet:c,unitId:i,subUnitId:u}=o,h=c.getCellMatrix(),{value:m}=t,p=e.get(l.ICommandService);e.get(k.IEditorBridgeService);const f=[],g=[];let d=null,C=0,_=0,v="";if(r.length===1&&(on(r[0].range)||cn(r[0].range)&&vt(h,r[0].range))){const{range:I,primary:S}=r[0],N=(E=S==null?void 0:S.actualRow)!=null?E:I.startRow,F=(b=S==null?void 0:S.actualColumn)!=null?b:I.startColumn;d=I,C=N,_=F;const L=St(h,N,F);L&&(v=T.serializeRange(L))}else r.some(I=>{var F,L;const{range:S,primary:N}=I;if(vt(h,S)){const U=(F=N==null?void 0:N.actualRow)!=null?F:S.startRow,w=(L=N==null?void 0:N.actualColumn)!=null?L:S.startColumn,j=St(h,U,w);if(!j)return d=S,C=U,_=w,!0;const D=T.serializeRange(j),M=`=${m}(${D})`;f.push({range:S,primary:{row:U,column:w},formula:M})}else{const{startRow:U,startColumn:w,endRow:j,endColumn:D}=S;if(U===j){const M=an(h,U,D,c.getColumnCount()-1),x=M===D?D-1:D,O=T.serializeRange({startRow:U,endRow:j,startColumn:w,endColumn:x}),P=`=${m}(${O})`;g.push({range:S,primary:{row:U,column:M},formula:P})}else{let M=-1;for(let O=w;O<=D;O++){const P=ln(h,O,j,c.getRowCount()-1);M=Math.max(M,P)}const x=M===j?j-1:j;for(let O=w;O<=D;O++){const P=T.serializeRange({startRow:U,endRow:x,startColumn:O,endColumn:O}),$=`=${m}(${P})`;g.push({range:S,primary:{row:M,column:O},formula:$})}}}return!1});if(d){const I=A.getCellAtRowCol(C,_,c),S={range:l.Rectangle.clone(d),primary:{startRow:I.startRow,startColumn:I.startColumn,endRow:I.endRow,endColumn:I.endColumn,actualRow:C,actualColumn:_,isMerged:I.isMerged,isMergedMainCell:I.startRow===C&&I.startColumn===_}},N={unitId:i,subUnitId:u,selections:[S]};await p.executeCommand(A.SetSelectionsOperation.id,N);const F=s.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),L=s.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);p.syncExecuteCommand(k.SetCellEditVisibleOperation.id,{visible:!0,unitId:i,eventType:B.DeviceInputEventType.Dblclick});const U=`=${m}(${v}`;F==null||F.replaceText(U),L==null||L.replaceText(U,!1)}return f.length===0&&g.length===0?!1:p.executeCommand(Re.InsertFunctionCommand.id,{list:f,listOfRangeHasNumber:g})}};function St(e,t,n){const s=rn(e,t,n);if(s!==t)return{startRow:s,endRow:t-1,startColumn:n,endColumn:n};const r=sn(e,t,n);return r!==n?{startRow:t,endRow:t,startColumn:r,endColumn:n-1}:null}function rn(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(Pe(o)&&!s){if(r===0)return 0;s=!0}else{if(s&&!Pe(o))return r+1;if(s&&r===0)return 0}}return t}function sn(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(Pe(o)&&!s){if(r===0)return 0;s=!0}else{if(s&&!Pe(o))return r+1;if(s&&r===0)return 0}}return n}function Pe(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return!1;const n=t.dataStream,r=n.substring(n.length-2,n.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n;return l.isRealNum(r)}return e&&(e.t===l.CellValueType.NUMBER||l.getCellValueType(e)===l.CellValueType.NUMBER)}function on(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}function cn(e){return e.startRow!==e.endRow&&e.startColumn!==e.endColumn}function vt(e,t){for(let n=t.startRow;n<=t.endRow;n++)for(let s=t.startColumn;s<=t.endColumn;s++)if(Pe(e.getValue(n,s)))return!1;return!0}function an(e,t,n,s){for(let r=n;r<=s;r++)if(!e.getValue(t,r))return r;return s}function ln(e,t,n,s){for(let r=n;r<=s;r++)if(!e.getValue(r,t))return r;return s}const Mt="SHEET_FORMULA_UI_PLUGIN",Ot=`${Mt}_MORE_FUNCTIONS_COMPONENT`,et={id:"formula-ui.operation.more-functions",type:l.CommandType.OPERATION,handler:async e=>(e.get(a.ISidebarService).open({header:{title:"formula.insert.tooltip"},children:{label:Ot}}),!0)},lt={id:"formula-ui.operation.change-ref-to-absolute",type:l.CommandType.OPERATION,handler:async e=>!0},Nt={id:"formula-ui.operation.search-function",type:l.CommandType.OPERATION,handler:async(e,t)=>(e.get(Je).search(t),!0)};var un=Object.getOwnPropertyDescriptor,dn=(e,t,n,s)=>{for(var r=s>1?void 0:s?un(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},Be=(e,t)=>(n,s)=>t(n,s,e);exports.FormulaReorderController=class extends l.Disposable{constructor(t,n,s,r){super(),this._sheetInterceptorService=t,this._univerInstanceService=n,this._formulaDataModel=s,this._lexerTreeBuilder=r,this._initialize()}_initialize(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>t.id===A.ReorderRangeCommand.id?this._reorderFormula(t.params):{redos:[],undos:[]}}))}_reorderFormula(t){const n=[],s=[],{unitId:r,subUnitId:o,range:c,order:i}=t,u=this._univerInstanceService.getUniverSheetInstance(r),h=u==null?void 0:u.getSheetBySheetId(o);if(!h)return{redos:n,undos:s};const m=h.getCellMatrix(),p=new l.ObjectMatrix,f=new l.ObjectMatrix;let g=!1;return l.Range.foreach(c,(d,C)=>{let _=d;i.hasOwnProperty(d)&&(_=i[d]);const v=m.getValue(_,C);if(v!=null&&v.f||v!=null&&v.si){g=!0;const E=this._formulaDataModel.getFormulaStringByCell(_,C,o,r),b=this._lexerTreeBuilder.moveFormulaRefOffset(E,0,d-_),I=l.Tools.deepClone(v);I.f=b,I.si=null,p.setValue(d,C,I)}else p.setValue(d,C,v);f.setValue(d,C,m.getValue(d,C))}),g?(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=dn([Be(0,l.Inject(A.SheetInterceptorService)),Be(1,l.Inject(l.IUniverInstanceService)),Be(2,l.Inject(T.FormulaDataModel)),Be(3,l.Inject(T.LexerTreeBuilder))],exports.FormulaReorderController);const hn="sheets-formula-ui.base.config",Ct={};function fn(e){return e.getContextValue(l.FOCUSING_DOC)&&e.getContextValue(l.FOCUSING_UNIVER_EDITOR)}function Dt(e,t=!1){return!t&&!(l.isFormulaString(e==null?void 0:e.f)||l.isFormulaId(e==null?void 0:e.si))?null:typeof(e==null?void 0:e.v)=="string"&&T.ERROR_TYPE_SET.has(e.v)?e.v:null}var gn=Object.getOwnPropertyDescriptor,mn=(e,t,n,s)=>{for(var r=s>1?void 0:s?gn(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},ke=(e,t)=>(n,s)=>t(n,s,e);const st="SHEET_FORMULA_ALERT",pn={[T.ErrorType.DIV_BY_ZERO]:"divByZero",[T.ErrorType.NAME]:"name",[T.ErrorType.VALUE]:"value",[T.ErrorType.NUM]:"num",[T.ErrorType.NA]:"na",[T.ErrorType.CYCLE]:"cycle",[T.ErrorType.REF]:"ref",[T.ErrorType.SPILL]:"spill",[T.ErrorType.CALC]:"calc",[T.ErrorType.ERROR]:"error",[T.ErrorType.CONNECT]:"connect",[T.ErrorType.NULL]:"null"};let ct=class extends l.Disposable{constructor(e,t,n,s,r,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=s,this._formulaDataModel=r,this._zenZoneService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(q.debounceTime(100)).subscribe(e=>{var t,n,s,r,o;if(e){const i=this._context.unit.getActiveSheet();if(!i)return;const u=i.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(l.isICellData(u)){const m=Dt(u,!!h);if(!m){this._hideAlert();return}const p=this._cellAlertManagerService.currentAlert.get(st),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)return;this._cellAlertManagerService.showAlert({type:k.CellAlertType.ERROR,title:this._localeService.t("formula.error.title"),message:this._localeService.t(`formula.error.${pn[m]}`),location:e.location,width:200,height:74,key:st});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(st)}};ct=mn([ke(1,l.Inject(k.HoverManagerService)),ke(2,l.Inject(k.CellAlertManagerService)),ke(3,l.Inject(l.LocaleService)),ke(4,l.Inject(T.FormulaDataModel)),ke(5,a.IZenZoneService)],ct);var Sn=Object.getOwnPropertyDescriptor,vn=(e,t,n,s)=>{for(var r=s>1?void 0:s?Sn(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},_t=(e,t)=>(n,s)=>t(n,s,e);let Ye=class extends l.Disposable{constructor(e,t){super(),this._autoFillService=e,this._lexerTreeBuilder=t,this._registerAutoFill()}_registerAutoFill(){const e={type:k.DATA_TYPE.FORMULA,priority:1001,match:t=>l.isFormulaString(t==null?void 0:t.f)||l.isFormulaId(t==null?void 0:t.si),isContinue:(t,n)=>t.type===k.DATA_TYPE.FORMULA,applyFunctions:{[k.APPLY_TYPE.COPY]:(t,n,s,r,o)=>{const{data:c,index:i}=t;return this._fillCopyFormula(c,n,s,i,r,o)}}};this._autoFillService.registerRule(e)}_fillCopyFormula(e,t,n,s,r,o){var h,m;const c=_n(r),i=[],u=new Map;for(let p=1;p<=t;p++){const f=(p-1)%e.length,g=s[f],d=l.Tools.deepClone(e[f]);if(d){const C=((h=e[f])==null?void 0:h.f)||"",_=((m=e[f])==null?void 0:m.si)||"",v=l.isFormulaString(C);if(l.isFormulaId(_))d.si=_,d.f=null,d.v=null,d.p=null,d.t=null,i.push(d);else if(v){let b=u.get(f);if(b)d.si=b,d.f=null,d.v=null,d.p=null,d.t=null;else{b=l.generateRandomId(6),u.set(f,b);const{offsetX:I,offsetY:S}=Cn(c,t,n,o,g),N=this._lexerTreeBuilder.moveFormulaRefOffset(C,I,S);d.si=b,d.f=N,d.v=null,d.p=null,d.t=null}i.push(d)}}}return i}};Ye=vn([_t(0,k.IAutoFillService),_t(1,l.Inject(T.LexerTreeBuilder))],Ye);function Cn(e,t,n,s,r){const{source:o,target:c}=s,{rows:i}=c,{rows:u}=o;let h=0,m=0;switch(n){case l.Direction.UP:m=i[r]-u[r];break;case l.Direction.RIGHT:h=e;break;case l.Direction.DOWN:m=i[r]-u[r];break;case l.Direction.LEFT:h=-e*t;break}return{offsetX:h,offsetY:m}}function _n(e){let t=0;for(const n in e)e[n].forEach(s=>{t+=s.data.length});return t}var Rn=Object.getOwnPropertyDescriptor,En=(e,t,n,s)=>{for(var r=s>1?void 0:s?Rn(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},Ae=(e,t)=>(n,s)=>t(n,s,e);const In="default-paste-formula";let ze=class extends l.Disposable{constructor(e,t,n,s,r){super(),this._currentUniverSheet=e,this._lexerTreeBuilder=t,this._sheetClipboardService=n,this._injector=s,this._formulaDataModel=r,this._initialize()}_initialize(){this._registerClipboardHook()}_registerClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteFormulaHook())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteWithFormulaHook()))}_pasteFormulaHook(){return{id:k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA,priority:10,specialPasteInfo:{label:"specialPaste.formula"},onPasteCells:(e,t,n,s)=>this._onPasteCells(e,t,n,s,!0)}}_pasteWithFormulaHook(){return{id:In,priority:10,onPasteCells:(e,t,n,s)=>this._onPasteCells(e,t,n,s,!1)}}_onPasteCells(e,t,n,s,r){var f;if([k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH].includes(s.pasteType))return{undos:[],redos:[]};const c=this._currentUniverSheet.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),i=t.unitId||c.getUnitId(),u=t.subUnitId||((f=c.getActiveSheet())==null?void 0:f.getSheetId());if(!i||!u)return{undos:[],redos:[]};const h=t.range,m=n,p={copyType:s.copyType||k.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:s.pasteType};return this._injector.invoke(g=>yn(i,u,h,m,g,p,this._lexerTreeBuilder,this._formulaDataModel,r,e))}};ze=En([Ae(0,l.IUniverInstanceService),Ae(1,l.Inject(T.LexerTreeBuilder)),Ae(2,k.ISheetClipboardService),Ae(3,l.Inject(l.Injector)),Ae(4,l.Inject(T.FormulaDataModel))],ze);function yn(e,t,n,s,r,o,c,i,u=!1,h){const m=[],p=[],f=bn(e,t,n,s,o,c,i,h);if(!f.hasValue())return{undos:[],redos:[]};const g={unitId:e,subUnitId:t,cellValue:f.getData()};m.push({id:A.SetRangeValuesMutation.id,params:g});const d=A.SetRangeValuesUndoMutationFactory(r,g);return p.push({id:A.SetRangeValuesMutation.id,params:d}),{undos:p,redos:m}}function bn(e,t,n,s,r,o,c,i){return i?r.pasteType===k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE?xn(e,t,n,s,c,i):r.pasteType===k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA?Mn(e,t,n,s,o,c,i):On(e,t,n,s,r.copyType,o,c,i):Tn(e,t,n,s,c)}function Tn(e,t,n,s,r){const o=new l.ObjectMatrix,c=r.getSheetFormulaData(e,t);return s.forValue((i,u,h)=>{var g;const m=n.rows[i],p=n.cols[u],f={};l.isFormulaString(h.v)?(f.v=null,f.f=`${h.v}`,f.si=null,f.p=null,o.setValue(m,p,f)):(g=c==null?void 0:c[m])!=null&&g[p]&&(f.v=h.v,f.f=null,f.si=null,f.p=null,o.setValue(m,p,f))}),o}function xn(e,t,n,s,r,o){var h,m;const c=new l.ObjectMatrix,i=(m=(h=r.getArrayFormulaCellData())==null?void 0:h[o.unitId])==null?void 0:m[o.subUnitId],u=r.getSheetFormulaData(e,t);return s.forValue((p,f,g)=>{var b,I;const d=o.range.rows[p%o.range.rows.length],C=o.range.cols[f%o.range.cols.length],_=n.rows[p],v=n.cols[f],E={};if(l.isFormulaString(g.f)||l.isFormulaId(g.si))E.v=g.v,E.f=null,E.si=null,E.p=null,c.setValue(_,v,E);else if((b=i==null?void 0:i[d])!=null&&b[C]){const S=i[d][C];E.v=S.v,E.f=null,E.si=null,E.p=null,c.setValue(_,v,E)}else if((I=u==null?void 0:u[_])!=null&&I[v]){if(E.v=g.v,E.f=null,E.si=null,E.p=null,g.p){const S=wt(g);S&&(E.v=S)}c.setValue(_,v,E)}}),c}function Mn(e,t,n,s,r,o,c){const i=new l.ObjectMatrix,u=new Map;return s.forValue((h,m,p)=>{const f=n.rows[h],g=n.cols[m],d={};if(l.isFormulaId(p.si)){if(c.unitId!==e||c.subUnitId!==t){const C=o.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[m%c.range.cols.length],c.subUnitId,c.unitId),_=n.cols[m]-c.range.cols[m%c.range.cols.length],v=n.rows[h]-c.range.rows[h%c.range.rows.length],E=r.moveFormulaRefOffset(C||"",_,v);d.si=null,d.f=E}else d.si=p.si,d.f=null;d.v=null,d.p=null,i.setValue(f,g,d)}else if(l.isFormulaString(p.f)){const C=`${h%c.range.rows.length}_${m%c.range.cols.length}`;let _=u.get(C);if(_)d.si=_,d.f=null;else{_=l.generateRandomId(6),u.set(C,_);const v=n.cols[m]-c.range.cols[m%c.range.cols.length],E=n.rows[h]-c.range.rows[h%c.range.rows.length],b=r.moveFormulaRefOffset(p.f||"",v,E);d.si=_,d.f=b}d.v=null,d.p=null,i.setValue(f,g,d)}else{if(d.v=p.v,d.f=null,d.si=null,d.p=null,p.p){const C=wt(p);C&&(d.v=C)}i.setValue(f,g,d)}}),i}function On(e,t,n,s,r,o,c,i){const u=new l.ObjectMatrix,h=new Map,m=c.getSheetFormulaData(e,t),p=[];return r===k.COPY_TYPE.CUT?s.forValue((f,g,d)=>{const C=n.rows[f],_=n.cols[g],v={};if(l.isFormulaId(d.si)){if(l.isFormulaString(d.f))p.push(d.si),v.f=d.f,v.si=d.si;else if(p.includes(d.si))v.f=null,v.si=d.si;else{const E=c.getFormulaStringByCell(i.range.rows[f%i.range.rows.length],i.range.cols[g%i.range.cols.length],i.subUnitId,i.unitId);v.f=E,v.si=null}v.v=null,v.p=null,u.setValue(C,_,v)}else l.isFormulaString(d.f)&&(v.f=d.f,v.si=null,v.v=null,v.p=null,u.setValue(C,_,v))}):s.forValue((f,g,d)=>{var E;const C=n.rows[f],_=n.cols[g],v={};if(l.isFormulaId(d.si)){if(i.unitId!==e||i.subUnitId!==t){const b=c.getFormulaStringByCell(i.range.rows[f%i.range.rows.length],i.range.cols[g%i.range.cols.length],i.subUnitId,i.unitId),I=n.cols[g]-i.range.cols[g%i.range.cols.length],S=n.rows[f]-i.range.rows[f%i.range.rows.length],N=o.moveFormulaRefOffset(b||"",I,S);v.si=null,v.f=N}else v.si=d.si,v.f=null;v.v=null,v.p=null,u.setValue(C,_,v)}else if(l.isFormulaString(d.f)){const b=`${f%i.range.rows.length}_${g%i.range.cols.length}`;let I=h.get(b);if(I)v.si=I,v.f=null;else{I=l.generateRandomId(6),h.set(b,I);const S=n.cols[g]-i.range.cols[g%i.range.cols.length],N=n.rows[f]-i.range.rows[f%i.range.rows.length],F=o.moveFormulaRefOffset(d.f||"",S,N);v.si=I,v.f=F}v.v=null,v.p=null,u.setValue(C,_,v)}else(E=m==null?void 0:m[C])!=null&&E[_]&&(v.v=d.v,v.f=null,v.si=null,v.p=d.p,u.setValue(C,_,v))}),p.length>0&&new l.ObjectMatrix(m).forValue((f,g,d)=>{if(!(i.range.rows.includes(f)&&i.range.cols.includes(g))&&!(n.rows.includes(f)&&n.cols.includes(g))&&p.includes(d==null?void 0:d.si)){const C=c.getFormulaStringByCell(f,g,i.subUnitId,i.unitId);u.setValue(f,g,{f:C,si:null,v:null,p:null})}}),u}function wt(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return;const n=t.dataStream;return n.substring(n.length-2,n.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n}}var Nn=Object.getOwnPropertyDescriptor,Dn=(e,t,n,s)=>{for(var r=s>1?void 0:s?Nn(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},be=(e,t)=>(n,s)=>t(n,s,e);let Ge=class extends l.Disposable{constructor(t,n,s,r,o,c,i,u){super();K(this,"_previousShape");K(this,"_skeleton");this._context=t,this._sheetInterceptorService=n,this._formulaDataModel=s,this._themeService=r,this._renderManagerService=o,this._sheetSkeletonManagerService=c,this._commandService=i,this._logService=u,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:c,sheetId:i}=t;this._updateArrayFormulaRangeShape(c,i)}}}))}_changeRuntime(t){this._skeleton=t}_initInterceptorEditorStart(){this.disposeWithMe(l.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(A.BEFORE_CELL_EDIT,{handler:(t,n,s)=>{var d,C,_,v;const{row:r,col:o,unitId:c,subUnitId:i,worksheet:u}=n,h=this._formulaDataModel.getArrayFormulaRange(),m=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return s(t);let p=null;const f=this._formulaDataModel.getFormulaStringByCell(r,o,i,c);if(f!==null&&(p={f}),t.v!=null&&t.v!==""&&((_=(C=(d=m[c])==null?void 0:d[i])==null?void 0:C[r])==null?void 0:_[o])==null)return p?{...t,...p}:s(t);const g=(v=h==null?void 0:h[c])==null?void 0:v[i];return g!=null&&(p=this._displayArrayFormulaRangeShape(g,r,o,c,i,u,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,c,i){const u=this._formulaDataModel.getSheetFormulaData(r,o);return new l.ObjectMatrix(t).forValue((h,m,p)=>{var _;if(p==null)return!0;const{startRow:f,startColumn:g,endRow:d,endColumn:C}=p;if(h===n&&m===s)return this._createArrayFormulaRangeShape(p,r),!1;if(n>=f&&n<=d&&s>=g&&s<=C){const v=c.getCell(f,g);if((v==null?void 0:v.v)===T.ErrorType.SPILL)return;const E=(_=u==null?void 0:u[h])==null?void 0:_[m];return E==null||E.f==null?!0:(i==null&&(i={f:E.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(p,r),!1)}}),i}_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 c={range:t,primary:null,style:{strokeWidth:1,stroke:this._themeService.getColorFromTheme("primary.600"),fill:new l.ColorKit(this._themeService.getColorFromTheme("white")).setAlpha(0).toString(),widgets:{}}},i=k.attachSelectionWithCoord(c,r),{rowHeaderWidth:u,columnHeaderHeight:h}=r,m=new k.SelectionControl(o,k.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:u,columnHeaderHeight:h});m.updateRangeBySelectionWithCoord(i),m.setEvent(!1),this._previousShape=m}_removeArrayFormulaRangeShape(){this._previousShape!=null&&(this._previousShape.dispose(),this._previousShape=null)}_refreshArrayFormulaRangeShape(t,n){if(this._previousShape){const{startRow:s,endRow:r,startColumn:o,endColumn:c}=this._previousShape.getRange(),i={startRow:s,endRow:r,startColumn:o,endColumn:c};this._removeArrayFormulaRangeShape(),this._createArrayFormulaRangeShape(i,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:c,endColumn:i}=this._previousShape.getRange();for(let u=0;u<s.length;u++){const{row:h}=s[u];if(r>=h){const m={startRow:r,endRow:o,startColumn:c,endColumn:i};this._refreshArrayFormulaRangeShape(t,m);break}}}};Ge=Dn([be(1,l.Inject(A.SheetInterceptorService)),be(2,l.Inject(T.FormulaDataModel)),be(3,l.Inject(l.ThemeService)),be(4,B.IRenderManagerService),be(5,l.Inject(k.SheetSkeletonManagerService)),be(6,l.ICommandService),be(7,l.ILogService)],Ge);var wn=Object.getOwnPropertyDescriptor,kn=(e,t,n,s)=>{for(var r=s>1?void 0:s?wn(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},Rt=(e,t)=>(n,s)=>t(n,s,e);const An={tl:{size:6,color:"#409f11"}};let Ze=class extends l.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(A.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,handler:(n,s,r)=>{var i,u,h,m;const o=(m=(h=(u=(i=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:i[s.unitId])==null?void 0:u[s.subUnitId])==null?void 0:h[s.row])==null?void 0:m[s.col];return!Dt(n,!!o)||!n||(n===s.rawData&&(n={...s.rawData}),n.markers={...n==null?void 0:n.markers,...An}),r(n)},priority:10}))}};Ze=kn([Rt(0,l.Inject(A.SheetInterceptorService)),Rt(1,l.Inject(T.FormulaDataModel))],Ze);function Fn(){const e=a.useDependency(Re.TriggerCalculationController),t=a.useDependency(l.ICommandService),n=a.useObservable(e.progress$),s=R.useCallback(()=>{t.executeCommand(T.SetFormulaCalculationStopMutation.id)},[t]),r=R.useCallback(()=>{e.clearProgress()},[e]);return y.jsx(a.ProgressBar,{progress:n,onTerminate:s,onClearProgress:r})}function Pn(e,t){return Object.keys(e).filter(n=>isNaN(Number(n))&&n!=="DefinedName").map(n=>({label:t.t(`formula.functionType.${n.toLocaleLowerCase()}`),value:`${e[n]}`}))}function kt(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 At(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:kt(s)}),r===n.length-1?"":","]},r)),")"]})}function Fe(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:W.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 Ln(e){const{functionInfo:t,onChange:n}=e;if(!t)return null;const[s,r]=R.useState([]),[o,c]=R.useState(t.functionParameter),[i,u]=R.useState(-1);return y.jsxs("div",{children:[y.jsx("div",{className:W.clsx("univer-h-[364px] univer-overflow-y-auto",W.scrollbarClassName),children:o.map((h,m)=>y.jsxs("div",{children:[y.jsx("div",{className:"univer-text-sm",children:h.name}),y.jsx("div",{className:"univer-mb-2 univer-mt-1"})]},m))}),y.jsx("div",{className:W.clsx("univer-flex-1 univer-p-3",W.borderLeftClassName),children:y.jsx(Fe,{title:i===-1?y.jsx(At,{prefix:t.functionName,value:o}):o[i].name,value:i===-1?t.description:o[i].detail})})]})}var ue=function(){return ue=Object.assign||function(e){for(var t,n=1,s=arguments.length;n<s;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},ue.apply(this,arguments)},Un=function(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(n[s[r]]=e[s[r]]);return n},Me=R.forwardRef(function(e,t){var n=e.icon,s=e.id,r=e.className,o=e.extend,c=Un(e,["icon","id","className","extend"]),i="univerjs-icon univerjs-icon-".concat(s," ").concat(r||"").trim(),u=R.useRef("_".concat(Wn()));return Ft(n,"".concat(s),{defIds:n.defIds,idSuffix:u.current},ue({ref:t,className:i},c),o)});function Ft(e,t,n,s,r){return R.createElement(e.tag,ue(ue({key:t},$n(e,n,r)),s),(jn(e,n).children||[]).map(function(o,c){return Ft(o,"".concat(t,"-").concat(e.tag,"-").concat(c),n,void 0,r)}))}function $n(e,t,n){var s=ue({},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(function(o){var c=o[0],i=o[1];c==="mask"&&typeof i=="string"&&(s[c]=i.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var r=t.defIds;return!r||r.length===0||(e.tag==="use"&&s["xlink:href"]&&(s["xlink:href"]=s["xlink:href"]+t.idSuffix),Object.entries(s).forEach(function(o){var c=o[0],i=o[1];typeof i=="string"&&(s[c]=i.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),s}function jn(e,t){var n,s=t.defIds;return!s||s.length===0?e:e.tag==="defs"&&(!((n=e.children)===null||n===void 0)&&n.length)?ue(ue({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&s&&s.includes(r.attrs.id)?ue(ue({},r),{attrs:ue(ue({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):e}function Wn(){return Math.random().toString(36).substring(2,8)}Me.displayName="UniverIcon";var Vn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Pt=R.forwardRef(function(e,t){return R.createElement(Me,Object.assign({},e,{id:"check-mark-icon",ref:t,icon:Vn}))});Pt.displayName="CheckMarkIcon";var Hn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},Lt=R.forwardRef(function(e,t){return R.createElement(Me,Object.assign({},e,{id:"close-icon",ref:t,icon:Hn}))});Lt.displayName="CloseIcon";var Bn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ut=R.forwardRef(function(e,t){return R.createElement(Me,Object.assign({},e,{id:"delete-icon",ref:t,icon:Bn}))});Ut.displayName="DeleteIcon";var Kn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},$t=R.forwardRef(function(e,t){return R.createElement(Me,Object.assign({},e,{id:"increase-icon",ref:t,icon:Kn}))});$t.displayName="IncreaseIcon";var qn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.90913 3.57564C6.14345 3.34132 6.52335 3.34132 6.75766 3.57564L10.7577 7.57564C10.992 7.80995 10.992 8.18985 10.7577 8.42417L6.75766 12.4242C6.52335 12.6585 6.14345 12.6585 5.90913 12.4242C5.67482 12.1899 5.67482 11.81 5.90913 11.5756L9.48487 7.9999L5.90913 4.42417C5.67482 4.18985 5.67482 3.80995 5.90913 3.57564Z",fillRule:"evenodd",clipRule:"evenodd"}}]},jt=R.forwardRef(function(e,t){return R.createElement(Me,Object.assign({},e,{id:"more-icon",ref:t,icon:qn}))});jt.displayName="MoreIcon";var Yn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6185 12.4423C12.5907 12.2749 12.7773 12.15 12.9343 12.2308L15.4242 13.5126C15.6102 13.6084 15.5544 13.8745 15.3439 13.8955L14.2456 14.184L13.4521 15.1286C13.3495 15.2939 13.085 15.2463 13.0534 15.0568L12.6185 12.4423Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1 3.6C1 2.16406 2.16406 1 3.6 1H12.3C13.7359 1 14.9 2.16406 14.9 3.6V5.81156C14.9003 5.81881 14.9004 5.82609 14.9004 5.8334C14.9004 5.84071 14.9003 5.84799 14.9 5.85524V10.045C14.9003 10.0522 14.9004 10.0595 14.9004 10.0668C14.9004 10.3982 14.6318 10.6668 14.3004 10.6668H11.1668C10.8907 10.6668 10.6668 10.8907 10.6668 11.1668V14.3C10.6668 14.6314 10.3982 14.9 10.0668 14.9L10.05 14.8998L3.6 14.9C2.16406 14.9 1 13.7359 1 12.3V3.6ZM13.2 5.2334C13.4761 5.2334 13.7 5.00954 13.7 4.7334V3.6C13.7 2.8268 13.0732 2.2 12.3 2.2H11.1668C10.8907 2.2 10.6668 2.42386 10.6668 2.7V4.7334C10.6668 5.00954 10.8907 5.2334 11.1668 5.2334H13.2ZM10.6668 6.9334C10.6668 6.65726 10.8907 6.4334 11.1668 6.4334H13.2C13.4761 6.4334 13.7 6.65726 13.7 6.9334V8.9668C13.7 9.24294 13.4761 9.4668 13.2 9.4668H11.1668C10.8907 9.4668 10.6668 9.24294 10.6668 8.9668V6.9334ZM8.9668 5.2334C9.24294 5.2334 9.4668 5.00954 9.4668 4.7334V2.7C9.4668 2.42386 9.24294 2.2 8.9668 2.2H6.9334C6.65726 2.2 6.4334 2.42386 6.4334 2.7V4.7334C6.4334 5.00954 6.65726 5.2334 6.9334 5.2334L8.9668 5.2334ZM6.4334 6.9334C6.4334 6.65726 6.65726 6.4334 6.9334 6.4334L8.9668 6.4334C9.24294 6.4334 9.4668 6.65726 9.4668 6.9334V8.9668C9.4668 9.24294 9.24294 9.4668 8.9668 9.4668L6.9334 9.4668C6.65726 9.4668 6.4334 9.24294 6.4334 8.9668V6.9334ZM4.7334 5.2334C5.00954 5.2334 5.2334 5.00954 5.2334 4.7334V2.7C5.2334 2.42386 5.00954 2.2 4.7334 2.2H3.6C2.8268 2.2 2.2 2.8268 2.2 3.6V4.7334C2.2 5.00954 2.42386 5.2334 2.7 5.2334H4.7334ZM2.2 6.9334C2.2 6.65726 2.42386 6.4334 2.7 6.4334H4.7334C5.00954 6.4334 5.2334 6.65725 5.2334 6.9334V8.9668C5.2334 9.24294 5.00954 9.4668 4.7334 9.4668H2.7C2.42386 9.4668 2.2 9.24294 2.2 8.9668V6.9334ZM5.2334 11.1668C5.2334 10.8907 5.00954 10.6668 4.7334 10.6668H2.7C2.42386 10.6668 2.2 10.8907 2.2 11.1668V12.3C2.2 13.0732 2.8268 13.7 3.6 13.7H4.7334C5.00954 13.7 5.2334 13.4761 5.2334 13.2V11.1668ZM9.4668 11.1668C9.4668 10.8907 9.24294 10.6668 8.9668 10.6668H6.9334C6.65726 10.6668 6.4334 10.8907 6.4334 11.1668V13.2C6.4334 13.4761 6.65726 13.7 6.9334 13.7H8.9668C9.24294 13.7 9.4668 13.4761 9.4668 13.2V11.1668Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Wt=R.forwardRef(function(e,t){return R.createElement(Me,Object.assign({},e,{id:"select-range-icon",ref:t,icon:Yn}))});Wt.displayName="SelectRangeIcon";function zn(e){const{onChange:t}=e,n="-1",[s,r]=R.useState(""),[o,c]=R.useState([]),[i,u]=R.useState(0),[h,m]=R.useState(n),[p,f]=R.useState(0),[g,d]=R.useState(null),C=a.useDependency(Re.IDescriptionService),_=a.useDependency(l.LocaleService),v=a.useDependency(a.ISidebarService),E=a.useObservable(v.sidebarOptions$),b=Pn(T.FunctionType,_);b.unshift({label:_.t("formula.moreFunctions.allFunctions"),value:n});const I=_.t("formula.prompt.required"),S=_.t("formula.prompt.optional");R.useEffect(()=>{L(n)},[]),R.useEffect(()=>{F(0)},[o]),R.useEffect(()=>{E!=null&&E.visible&&(r(""),c([]),u(0),m(n),f(0),d(null),L(n))},[E]);const N=M=>{if(s.trim()==="")return M;const x=new RegExp(`(${s.toLocaleUpperCase()})`);return M.split(x).filter(Boolean).map((P,$)=>P.match(x)?y.jsx("span",{className:"univer-text-red-500",children:P},$):P)},F=M=>{if(o.length===0){d(null);return}f(M);const x=C.getFunctionInfo(o[M].name);if(!x){d(null);return}d(x),t(x)};function L(M){m(M);const x=C.getSearchListByType(+M);c(x)}function U(M){r(M);const x=C.getSearchListByName(M);c(x)}function w(M){if(M.stopPropagation(),M.key==="ArrowDown"){const x=i+1;u(x===o.length?0:x)}else if(M.key==="ArrowUp"){const x=i-1;u(x===-1?o.length-1:x)}else M.key==="Enter"&&F(i)}const j=M=>{u(M)},D=()=>{u(-1)};return y.jsxs("div",{children:[y.jsxs("div",{className:"univer-flex univer-items-center univer-justify-between univer-gap-2",children:[y.jsx(W.Select,{value:h,options:b,onChange:L}),y.jsx(W.Input,{placeholder:_.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:w,value:s,onChange:U,size:"small",allowClear:!0})]}),o.length>0&&y.jsx("ul",{className:W.clsx("univer-m-0 univer-mt-2 univer-box-border univer-max-h-72 univer-w-full univer-select-none univer-list-none univer-overflow-y-auto univer-rounded univer-p-3 univer-outline-none",W.borderClassName,W.scrollbarClassName),onKeyDown:w,tabIndex:-1,children:o.map(({name:M},x)=>y.jsxs("li",{className:W.clsx("univer-relative univer-box-border univer-cursor-pointer univer-rounded univer-px-7 univer-py-1 univer-text-sm univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200 dark:!univer-bg-gray-600":i===x}),onMouseEnter:()=>j(x),onMouseLeave:D,onClick:()=>F(x),children:[p===x&&y.jsx(Pt,{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:N(M)})]},x))}),g&&y.jsxs("div",{className:W.clsx("univer-mx-0 univer-my-2 univer-overflow-y-auto",W.scrollbarClassName),children:[y.jsx(Fe,{title:g.functionName,value:g.description}),y.jsx(Fe,{title:_.t("formula.moreFunctions.syntax"),value:y.jsx(At,{prefix:g.functionName,value:g.functionParameter})}),y.jsx(Fe,{title:_.t("formula.prompt.helpExample"),value:`${g.functionName}(${g.functionParameter.map(M=>M.example).join(",")})`}),g.functionParameter&&g.functionParameter.map(M=>y.jsx(Fe,{title:M.name,value:`${M.require?I:S} ${M.detail}`},M.name))]})]})}function Gn(){const e=k.useActiveWorkbook(),[t,n]=R.useState(!0),[s,r]=R.useState(!1),[o,c]=R.useState(null);a.useDependency(k.IEditorBridgeService);const i=a.useDependency(l.LocaleService),u=a.useDependency(J.IEditorService),h=a.useDependency(l.IUniverInstanceService),m=a.useDependency(l.ICommandService);function p(){n(!t),r(!s)}function f(){const g=A.getSheetCommandTarget(h);if(!g)return;m.executeCommand(k.SetCellEditVisibleOperation.id,{visible:!0,unitId:g.unitId,eventType:B.DeviceInputEventType.Dblclick});const d=u.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),C=u.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),_=`=${o==null?void 0:o.functionName}(`;d==null||d.replaceText(_),C==null||C.replaceText(_,!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(zn,{onChange:c}),s&&y.jsx(Ln,{functionInfo:o,onChange:()=>{}}),y.jsxs("div",{className:"univer-flex univer-justify-end",children:[s&&y.jsx(W.Button,{variant:"primary",onClick:p,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:i.t("formula.moreFunctions.next")}),s&&y.jsx(W.Button,{onClick:p,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:i.t("formula.moreFunctions.prev")}),t&&!!e&&y.jsx(W.Button,{variant:"primary",onClick:f,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:i.t("formula.moreFunctions.confirm")})]})]})}function Zn(e){return{id:de.id,title:"SUM",icon:"SumIcon",type:a.MenuItemType.BUTTON,params:{value:"SUM"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function Xn(e){return{id:de.id,title:"COUNT",icon:"CntIcon",type:a.MenuItemType.BUTTON,params:{value:"COUNT"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function Qn(e){return{id:de.id,title:"AVERAGE",icon:"AvgIcon",type:a.MenuItemType.BUTTON,params:{value:"AVERAGE"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function Jn(e){return{id:de.id,title:"MAX",icon:"MaxIcon",type:a.MenuItemType.BUTTON,params:{value:"MAX"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function er(e){return{id:de.id,title:"MIN",icon:"MinIcon",type:a.MenuItemType.BUTTON,params:{value:"MIN"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function tr(e){return{id:et.id,title:"formula.insert.more",tooltip:"formula.insert.tooltip",type:a.MenuItemType.BUTTON,hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],worksheetTypes:[A.WorksheetEditPermission,A.WorksheetSetCellValuePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint]})}}function nr(e){return e.get(l.IUniverInstanceService).getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(q.switchMap(s=>s&&e.get(a.IClipboardInterfaceService)?new q.Observable(o=>o.next(!e.get(a.IClipboardInterfaceService).supportClipboard)):q.of(!0)))}function rr(e){return{id:Qe.id,type:a.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:nr(e).pipe(q.combineLatestWith(k.getCurrentRangeDisable$(e,{workbookTypes:[A.WorkbookEditablePermission],rangeTypes:[A.RangeProtectionPermissionEditPoint],worksheetTypes:[A.WorksheetSetCellValuePermission,A.WorksheetEditPermission]})),q.map(([t,n])=>t||n))}}const sr={[a.RibbonFormulasGroup.BASIC]:{[`${de.id}.sum`]:{order:0,menuItemFactory:Zn},[`${de.id}.count`]:{order:1,menuItemFactory:Xn},[`${de.id}.average`]:{order:2,menuItemFactory:Qn},[`${de.id}.max`]:{order:3,menuItemFactory:Jn},[`${de.id}.min`]:{order:4,menuItemFactory:er}},[a.RibbonFormulasGroup.OTHERS]:{[et.id]:{order:0,menuItemFactory:tr}},[k.PASTE_SPECIAL_MENU_ID]:{[Qe.id]:{order:4,menuItemFactory:rr}}},or="meta_key_ctrl_And_Shift",tt=[a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP,a.KeyCode.ARROW_LEFT,a.KeyCode.ARROW_RIGHT],ir=[...tt,a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ESC];function cr(){const e=[];for(const t of ir)e.push({id:xe.id,binding:t,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:B.DeviceInputEventType.Keyboard,keycode:t}});return e}function ar(){const e=[];for(const t of tt)e.push({id:xe.id,binding:t|a.MetaKeys.SHIFT,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:B.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.SHIFT}});return e}function lr(){const e=[];for(const t of tt)e.push({id:xe.id,binding:t|a.MetaKeys.CTRL_COMMAND,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:B.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.CTRL_COMMAND}});return e}function ur(){const e=[];for(const t of tt)e.push({id:xe.id,binding:t|a.MetaKeys.SHIFT|a.MetaKeys.CTRL_COMMAND,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:B.DeviceInputEventType.Keyboard,keycode:t,metaKey:or}});return e}const dr={id:lt.id,binding:a.KeyCode.F4,preconditions:e=>k.whenFormulaEditorActivated(e)};function hr(){const e=[];for(const t of[a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP])e.push({id:xe.id,binding:t,preconditions:n=>fn(n),staticParameters:{eventType:B.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}const fr={id:Re.QuickSumCommand.id,binding:a.MetaKeys.ALT|a.KeyCode.EQUAL,preconditions:k.whenSheetEditorFocused,mac:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.ALT|a.KeyCode.EQUAL,description:"shortcut.sheets-formula-ui.quick-sum",group:"4_sheet-edit"};var gr=Object.getOwnPropertyDescriptor,mr=(e,t,n,s)=>{for(var r=s>1?void 0:s?gr(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},Te=(e,t)=>(n,s)=>t(n,s,e);let Xe=class extends l.Disposable{constructor(e,t,n,s,r,o,c){super(),this._injector=e,this._menuManagerService=t,this._commandService=n,this._shortcutService=s,this._uiPartsService=r,this._renderManagerService=o,this._componentManager=c,this._initialize()}_initialize(){this._registerCommands(),this._registerMenus(),this._registerShortcuts(),this._registerComponents(),this._registerRenderModules()}_registerMenus(){this._menuManagerService.mergeMenu(sr)}_registerCommands(){[Qe,de,et,Nt,xt,xe,lt].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...cr(),...ar(),...lr(),...ur(),...hr(),fr,dr].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(k.SheetsUIPart.FORMULA_AUX,()=>a.connectInjector(Fn,this._injector))),this._componentManager.register(Ot,Gn)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,[Ge]))}};Xe=mr([Te(0,l.Inject(l.Injector)),Te(1,a.IMenuManagerService),Te(2,l.ICommandService),Te(3,a.IShortcutService),Te(4,a.IUIPartsService),Te(5,B.IRenderManagerService),Te(6,l.Inject(a.ComponentManager))],Xe);class ut{constructor(){K(this,"_currentSelector$",new q.BehaviorSubject(null));K(this,"currentSelector$",this._currentSelector$.asObservable())}showRangeSelectorDialog(t){const n=t.callback,s=new Promise(r=>{t.callback=o=>{r(o),n(o)}});return this._currentSelector$.next(t),s}}var pr=Object.getOwnPropertyDescriptor,Sr=(e,t,n,s)=>{for(var r=s>1?void 0:s?pr(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},we=(e,t)=>(n,s)=>t(n,s,e);exports.RefSelectionsRenderService=class extends k.BaseSelectionRenderService{constructor(n,s,r,o,c,i,u){super(s,r,o,c,i);K(this,"_workbookSelections");K(this,"_eventDisposables");this._context=n,this._contextService=i,this._refSelectionsService=u,this._workbookSelections=this._refSelectionsService.getWorkbookSelections(this._context.unitId),this._initSelectionChangeListener(),this._initSkeletonChangeListener(),this._initUserActionSyncListener(),this._setSelectionStyle(vr(this._themeService)),this._remainLastEnabled=!0,this._highlightHeader=!1}getLocation(){return this._skeleton.getLocation()}setRemainLastEnabled(n){this._remainLastEnabled=n}setSkipLastEnabled(n){this._skipLastEnabled=n}clearLastSelection(){const n=this._selectionControls[this._selectionControls.length-1];n&&(n.dispose(),this._selectionControls.pop())}enableSelectionChanging(){return this._disableSelectionChanging(),this._eventDisposables=this._initCanvasEventListeners(),l.toDisposable(()=>this._disableSelectionChanging())}_disableSelectionChanging(){var n;(n=this._eventDisposables)==null||n.dispose(),this._eventDisposables=null}disableSelectionChanging(){this._disableSelectionChanging()}_initCanvasEventListeners(){const n=this._getSheetObject(),{spreadsheetRowHeader:s,spreadsheetColumnHeader:r,spreadsheet:o,spreadsheetLeftTopPlaceholder:c}=n,{scene:i}=this._context,u=new l.DisposableCollection;return u.add(o==null?void 0:o.onPointerDown$.subscribeEvent((h,m)=>{this.inRefSelectionMode()&&(this._onPointerDown(h,o.zIndex+1,l.RANGE_TYPE.NORMAL,this._getActiveViewport(h)),h.button!==2&&m.stopPropagation())})),u.add(s==null?void 0:s.onPointerDown$.subscribeEvent((h,m)=>{if(!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:f}=k.getCoordByOffset(h.offsetX,h.offsetY,i,p);k.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),f,l.RANGE_TYPE.ROW)||(this._onPointerDown(h,(o.zIndex||1)+1,l.RANGE_TYPE.ROW,this._getActiveViewport(h),B.ScrollTimerType.Y),h.button!==2&&m.stopPropagation())})),u.add(r==null?void 0:r.onPointerDown$.subscribeEvent((h,m)=>{if(!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:f}=k.getCoordByOffset(h.offsetX,h.offsetY,i,p);k.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),f,l.RANGE_TYPE.COLUMN)||(this._onPointerDown(h,(o.zIndex||1)+1,l.RANGE_TYPE.COLUMN,this._getActiveViewport(h),B.ScrollTimerType.X),h.button!==2&&m.stopPropagation())})),u.add(c==null?void 0:c.onPointerDown$.subscribeEvent((h,m)=>{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 g=i.onPointerUp$.subscribeEvent(()=>{g.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});h.button!==2&&m.stopPropagation()})),u}_addSelectionControlByModelData(n){var i;const s=this._skeleton,r=(i=n.style)!=null?i: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(c=>A.convertSelectionDataToRange(c)),s)}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(n=>{if(!n)return;const{skeleton:s}=n,{scene:r}=this._context,o=r.getViewport(B.SHEET_VIEWPORT_KEY.VIEW_MAIN);this._skeleton&&this._skeleton.worksheet.getSheetId()!==s.worksheet.getSheetId()&&this._reset(),this._changeRuntime(s,r,o);const c=this._workbookSelections.getCurrentSelections();this.resetSelectionsByModelData(c)}))}_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=l.RANGE_TYPE.NORMAL,o,c=B.ScrollTimerType.ALL){var j;this._rangeType=r;const i=this._skeleton,u=this._scene;if(!u||!i)return;o&&(this._activeViewport=o);const{offsetX:h,offsetY:m}=n,p=u.getViewport(B.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!p)return;const f=u.getCoordRelativeToViewport(B.Vector2.FromArray([h,m])),{x:g,y:d}=f;this._startViewportPosX=g,this._startViewportPosY=d;const C=u.getScrollXYInfoByViewport(f),{scaleX:_,scaleY:v}=u.getAncestorScale(),E=this._skeleton.getCellByOffset(g,d,_,v,C);if(!E)return;switch(r){case l.RANGE_TYPE.NORMAL:break;case l.RANGE_TYPE.ROW:E.startColumn=0,E.endColumn=this._skeleton.getColumnCount()-1;break;case l.RANGE_TYPE.COLUMN:E.startRow=0,E.endRow=this._skeleton.getRowCount()-1;break;case l.RANGE_TYPE.ALL:E.startRow=0,E.startColumn=0,E.endRow=this._skeleton.getRowCount()-1,E.endColumn=this._skeleton.getColumnCount()-1}const b={range:E,primary:E,style:null};b.range.rangeType=r;const I=k.attachSelectionWithCoord(b,this._skeleton);this._startRangeWhenPointerDown={...I.rangeWithCoord};const S={...I.rangeWithCoord,rangeType:r};let N=this.getActiveSelectionControl();const F=this.getSelectionControls();for(const D of F){if(n.button===2&&l.Rectangle.contains(D.model,S)){N=D;return}if(D.model.isEqual(S)){N=D;break}}this._checkClearPreviousControls(n);const L=N==null?void 0:N.model.currentCell,U=n.shiftKey&&L,w=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;U&&L?this._makeSelectionByTwoCells(L,S,i,r,N):w&&N?N.updateRangeBySelectionWithCoord(I):N=this.newSelectionControl(u,i,b);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(),(j=u.getTransformer())==null||j.clearSelectedObjects(),this._setupPointerMoveListener(p,N,r,c,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,s,r){const o=this.getSelectionControls().length,{rowHeaderWidth:c,columnHeaderHeight:i}=s,u=new k.SelectionControl(n,o,this._themeService,{highlightHeader:this._highlightHeader,enableAutoFill:!1,rowHeaderWidth:c,columnHeaderHeight:i}),h=k.attachSelectionWithCoord(r,s);return u.updateRangeBySelectionWithCoord(h),this._selectionControls.push(u),u.setControlExtension({skeleton:s,scene:n,themeService:this._themeService,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),u}};exports.RefSelectionsRenderService=Sr([we(1,l.Inject(l.Injector)),we(2,l.Inject(l.ThemeService)),we(3,a.IShortcutService),we(4,l.Inject(k.SheetSkeletonManagerService)),we(5,l.IContextService),we(6,A.IRefSelectionsService)],exports.RefSelectionsRenderService);function vr(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 dt=(e,t,n=!0)=>{let s=-1;return e.reduce((r,o,c)=>{if(r.isFinish)return r;const i=r.currentIndex;if(typeof o!="string")r.currentIndex+=o.token.length;else{const u=o.length;r.currentIndex+=u}return(n?r.currentIndex===t:t>i&&t<=r.currentIndex)&&(s=c,r.isFinish=!0),r},{currentIndex:0,isFinish:!1}),s},Vt=(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},Cr=(e,t=100)=>{R.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 Ht(e,t,n){const s=a.useDependency(J.IEditorService),r=R.useMemo(()=>new q.BehaviorSubject({left:-999,top:-999,right:-999,bottom:-999}),[]),o=a.useDependency(a.ISidebarService),c=a.useDependency(l.IUniverInstanceService),i=a.useEvent(()=>{var b;const u=s.getEditor(e);if(!u)return;const h=u.getBoundingClientRect(),{marginTop:m=0,marginBottom:p=0}=u.getDocumentData().documentStyle,f=u.getSkeleton();if(!f)return;const g=(b=f.getSkeletonData())==null?void 0:b.pages[0].height;let{left:d,top:C,right:_,bottom:v}=h;C=C+m,v=g?C+g:v-p;const E=r.getValue();if(!(E.left===d&&E.top===C&&E.right===_&&E.bottom===v))return r.next({left:d-1,right:_+1,top:C-1,bottom:v+1}),h});return R.useEffect(()=>{t&&i()},[e,s,c.unitAdded$,i,t,...n!=null?n:[]]),Cr(i),R.useEffect(()=>{const u=o.scrollEvent$.pipe(q.throttleTime(100)).subscribe(i);return()=>{u.unsubscribe()}},[]),[r,i]}const Oe=e=>{const t=R.useRef(e);return t.current=e,t},_r=(e,t,n)=>{const s=a.useDependency(Je),r=a.useDependency(Re.IDescriptionService),o=a.useDependency(T.LexerTreeBuilder),[c,i]=R.useState(),[u,h]=R.useState(-1),[m,p]=R.useState(!0),f=Oe(m),g=R.useRef(t);g.current=t;const d=()=>{i(void 0),h(-1),p(!1)};return R.useEffect(()=>{const C=o.sequenceNodesBuilder(t.slice(1));s.setSequenceNodes(C!=null?C:[])},[t]),R.useEffect(()=>{if(n&&e){const C=n.selectionChange$.pipe(q.debounceTime(50)).subscribe(v=>{if(v.textRanges.length===1){const[E]=v.textRanges;if(E.collapsed&&f.current){const{startOffset:b}=E,I=s.getCurrentSequenceNode(b-2);if(I)if(typeof I!="string"&&I.nodeType===3&&!r.hasDefinedNameDescription(I.token.trim())){const S=r.getFunctionInfo(I.token);i(S),h(-1);return}else{const S=o.getFunctionAndParameter(`${g.current}A`,b-1);if(S){const{functionName:N,paramIndex:F}=S,L=r.getFunctionInfo(N);i(L),h(F);return}}}}i(void 0),h(-1)}),_=n.selectionChange$.pipe(q.filter(v=>v.textRanges.length===1),q.map(v=>v.textRanges[0].startOffset),q.distinctUntilChanged()).subscribe(()=>{p(!0)});return()=>{C.unsubscribe(),_.unsubscribe()}}},[n,e]),R.useEffect(()=>{e||d()},[e]),{functionInfo:c,paramIndex:u,reset:d}},Rr=({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:"?"}),ot=({className:e,title:t,value:n})=>y.jsxs("div",{className:"univer-my-2",children:[y.jsx("div",{className:W.clsx("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",e),children:t}),y.jsx("div",{className:"univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",children:n})]}),Er=e=>{const{prefix:t,value:n,active:s,onClick:r}=e;return y.jsxs("div",{children:[y.jsxs("span",{children:[t,"("]}),n&&n.map((o,c)=>y.jsxs("span",{children:[y.jsx("span",{className:s===c?"univer-text-primary-500":"",onClick:()=>r(c),children:kt(o)}),c===n.length-1?"":","]},o.name)),")"]})},Et=()=>{};function Ir(e){const{onParamsSwitch:t=Et,onClose:n=Et,isFocus:s,editor:r,formulaText:o}=e,{functionInfo:c,paramIndex:i,reset:u}=_r(s,o,r),h=a.useDependency(k.IEditorBridgeService),m=!a.useObservable(h.helpFunctionVisible$),[p,f]=R.useState(!0),g=a.useDependency(l.LocaleService),d=g.t("formula.prompt.required"),C=g.t("formula.prompt.optional"),_=r.getEditorId(),[v]=Ht(_,!!c,[c,i]);function E(S){t&&t(S)}const b=a.useEvent(S=>{h.helpFunctionVisible$.next(!S)}),I=()=>{b(!0),n()};return c?m?y.jsx(a.RectPopup,{portal:!0,anchorRect$:v,direction:"left-center",children:y.jsx(Rr,{onClick:()=>b(!1)})},"hidden"):y.jsx(a.RectPopup,{portal:!0,onClickOutside:()=>u(),anchorRect$:v,direction:"vertical",children:y.jsxs("div",{className:W.clsx("univer-m-0 univer-box-border univer-w-[250px] univer-select-none univer-list-none univer-rounded-lg univer-bg-white univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",W.borderClassName),children:[y.jsxs("div",{className:W.clsx("univer-wrap-anywhere univer-box-border univer-flex univer-items-center univer-justify-between univer-px-4 univer-py-3 univer-text-xs univer-font-medium univer-text-gray-900 dark:!univer-text-white",W.borderTopClassName),children:[y.jsx(Er,{prefix:c.functionName,value:c.functionParameter,active:i,onClick:E}),y.jsxs("div",{className:"univer-flex",children:[y.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-500 univer-outline-none univer-transition-colors hover:univer-bg-gray-200 dark:hover:!univer-bg-gray-600",style:{transform:p?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>f(!p),children:y.jsx(jt,{})}),y.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-600 univer-outline-none univer-transition-colors hover:univer-bg-gray-300 dark:!univer-text-gray-200 dark:hover:!univer-bg-gray-600",onClick:I,children:y.jsx(Lt,{})})]})]}),y.jsx("div",{className:W.clsx("univer-box-border univer-max-h-[350px] univer-overflow-y-auto univer-px-4 univer-pb-3 univer-pt-0",W.scrollbarClassName),style:{height:p?"unset":0,padding:p?"revert-layer":0},children:y.jsxs("div",{className:"univer-mt-3",children:[y.jsx(ot,{title:g.t("formula.prompt.helpExample"),value:`${c.functionName}(${c.functionParameter.map(S=>S.example).join(",")})`}),y.jsx(ot,{title:g.t("formula.prompt.helpAbstract"),value:c.description}),c&&c.functionParameter&&c.functionParameter.map((S,N)=>y.jsx(ot,{className:i===N?"univer-text-primary-500":"",title:S.name,value:`${S.require?d:C} ${S.detail}`},N))]})})]})},"show"):null}const yr=e=>{const t=a.useDependency(J.IEditorService);return a.useEvent(s=>{var r,o;if(e){t.focus(e.getEditorId());const c=[...e.getSelectionRanges()];if(l.Tools.isDefine(s))e.setSelectionRanges([{startOffset:s,endOffset:s}]);else if(!c.length&&!e.docSelectionRenderService.isOnPointerEvent){const i=(o=(r=e.getDocumentData().body)==null?void 0:r.dataStream)!=null?o:`\r
|
|
2
2
|
`,u=Math.max(i.length-2,0);e.setSelectionRanges([{startOffset:u,endOffset:u}])}else e.setSelectionRanges(c)}})};function br(e){var r,o;const n=e.get(l.IUniverInstanceService).getCurrentUniverDocInstance();return n!=null&&n.getBody()?{dataStream:(o=(r=n.getBody())==null?void 0:r.dataStream)!=null?o:"",offset:0}:void 0}var Se=(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))(Se||{});function Tr(e){var F;const{editorId:t,isFocus:n,disableOnClick:s,unitId:r,subUnitId:o}=e,c=a.useDependency(B.IRenderManagerService),i=a.useDependency(l.IUniverInstanceService),u=c.getRenderById(r),h=c.getRenderById(t),m=h==null?void 0:h.with(J.DocSelectionRenderService),p=a.useDependency(bt.DocSelectionManagerService),f=a.useDependency(l.Injector),[g,d]=R.useState(0),C=a.useDependency(T.LexerTreeBuilder),_=R.useRef(!0),v=u==null?void 0:u.with(exports.RefSelectionsRenderService),E=Oe(g),b=i.getUnit(r,l.UniverInstanceType.UNIVER_SHEET),I=b==null?void 0:b.getSheetBySheetId(o),S=a.useEvent(L=>{v&&v.setSkipLastEnabled(L===1||L===3||L===4),E.current=L,d(L)}),N=a.useEvent(()=>{var ne,re,oe;const L=i.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_SHEET);if(!L)return;const U=L.getActiveSheet(),w=m==null?void 0:m.getActiveTextRange(),j=w!=null&&w.collapsed?w.startOffset:-1,D=br(f);if(!D)return;const M=(ne=D==null?void 0:D.dataStream)==null?void 0:ne.slice(0,-2),x=((re=C.sequenceNodesBuilder(M))!=null?re:[]).map(Y=>typeof Y=="object"?Y.nodeType===T.sequenceNodeType.REFERENCE?{...Y,range:T.deserializeRangeWithSheetWithCache(Y.token)}:{...Y,range:void 0}:Y),O=M[j-1],P=M[j],$=x.find(Y=>typeof Y=="object"&&Y.nodeType===T.sequenceNodeType.REFERENCE&&j===Y.endIndex+2),V=O&&T.matchRefDrawToken(O)&&(!P||T.isFormulaLexerToken(P)&&P!==T.matchToken.OPEN_BRACKET),H=!!$;if((M==null?void 0:M.substring(0,1))==="="&&(V||H))if(H){if(_.current)return;const{sheetName:Y,unitId:ee}=$.range;ee!==((oe=i.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:oe.getUnitId())?S(4):!Y&&U.getSheetId()===(I==null?void 0:I.getSheetId())||Y===U.getName()?S(2):S(3)}else _.current=!1,S(1);else S(0)});return R.useEffect(()=>{const L=p.textSelection$.pipe(q.filter(U=>U.unitId===t)).subscribe(()=>{N()});return()=>L.unsubscribe()},[N,p.textSelection$,t]),R.useEffect(()=>{n||(S(0),_.current=!0)},[n,S]),R.useEffect(()=>{var U;if(!s)return;const L=(U=h==null?void 0:h.mainComponent)==null?void 0:U.onPointerDown$.subscribeEvent(()=>{S(0),_.current=!0});return()=>L==null?void 0:L.unsubscribe()},[s,(F=h==null?void 0:h.mainComponent)==null?void 0:F.onPointerDown$,S]),R.useEffect(()=>{if(!n)return;const L=b==null?void 0:b.activeSheet$.subscribe(()=>{N()}),U=i.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).subscribe(()=>{N()});return()=>{L==null||L.unsubscribe(),U==null||U.unsubscribe()}},[N,n,b==null?void 0:b.activeSheet$,i.getCurrentTypeOfUnit$]),{isSelecting:g,isSelectingRef:E}}const xr=()=>{const e=a.useDependency(T.LexerTreeBuilder);return R.useCallback(n=>e.sequenceNodesBuilder(n)||[],[e])};function Mr(e,t,n){const s=new l.ColorKit(t).setAlpha(.05).toRgbString();return{id:n,strokeWidth:1,stroke:t,fill:s,widgets:{tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},widgetSize:6,widgetStrokeWidth:1,widgetStroke:e.getColorFromTheme("white")}}function Bt(e){var b,I,S;const{unitId:t,subUnitId:n,currentWorkbook:s,refSelections:r,editor:o,refSelectionsService:c,refSelectionsRenderService:i,sheetSkeletonManagerService:u,themeService:h,univerInstanceService:m}=e,p=s.getUnitId(),f=m.getUnit(t,l.UniverInstanceType.UNIVER_SHEET),g=f==null?void 0:f.getActiveSheet(),d=[];if(!f||!g){c.setSelections(d);return}const C=g.getSheetId(),_=N=>{var F;return(F=f==null?void 0:f.getSheetBySheetName(N))==null?void 0:F.getSheetId()};if(!((b=u==null?void 0:u.getWorksheetSkeleton(C))==null?void 0:b.skeleton))return;const E=[];for(let N=0,F=r.length;N<F;N++){const L=r[N],{themeColor:U,token:w,refIndex:j,endIndex:D}=L,M=T.deserializeRangeWithSheet(w),{unitId:x,sheetName:O,range:P}=M,$=_(O);if(!$&&O||p!==t&&x!==p||x&&x!==p||$&&$!==C||!$&&C!==n)continue;const V=A.setEndForRange(P,g.getRowCount(),g.getColumnCount());V.unitId=t,V.sheetId=C,d.push({range:V,primary:null,style:Mr(h,U,j.toString())}),E.push(D)}if(o){const N=(S=(I=o.getSelectionRanges())==null?void 0:I[0])==null?void 0:S.startOffset,F=E.findIndex(L=>L+2===N);F!==-1?i==null||i.setActiveSelectionIndex(F):i==null||i.resetActiveSelectionIndex()}return d}function Or(e,t){const n=a.useDependency(l.IUniverInstanceService),s=a.useDependency(l.ThemeService),r=a.useDependency(A.IRefSelectionsService),o=a.useDependency(B.IRenderManagerService),c=a.useObservable(R.useMemo(()=>n.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),[n])),i=c?o.getRenderById(c.getUnitId()):null,u=i==null?void 0:i.with(exports.RefSelectionsRenderService),h=i==null?void 0:i.with(k.SheetSkeletonManagerService),m=a.useEvent((p,f)=>{const g=n.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_SHEET);if(!g||u!=null&&u.selectionMoving)return;const d=Bt({unitId:e,subUnitId:t,currentWorkbook:g,refSelections:p,editor:f,refSelectionsService:r,refSelectionsRenderService:u,sheetSkeletonManagerService:h,themeService:s,univerInstanceService:n});if(!d)return;((u==null?void 0:u.getSelectionControls())||[]).length===d.length?u==null||u.resetSelectionsByModelData(d):r.setSelections(d)});return R.useEffect(()=>()=>{u==null||u.resetActiveSelectionIndex()},[u]),m}function Kt(e=""){const t=a.useDependency(Re.IDescriptionService),n=Nr(),s=a.useDependency(l.ICommandService),r=R.useMemo(()=>e.length,[e]);return a.useEvent((c,i,u=!0,h)=>{const m=c.getDocumentData(),p=c.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(i==null||i.length===0)return d.textRuns=[],s.syncExecuteCommand(J.ReplaceTextRunsCommand.id,{unitId:p,body:l.getBodySlice(d,0,d.dataStream.length-2)}),[];{const{textRuns:C,refSelections:_}=Dr(t,n,i);r&&C.forEach(b=>{b.ed=b.ed+r,b.st=b.st+r}),d.textRuns=[{st:0,ed:1,ts:{fs:11}},...C];const v=i.reduce((b,I)=>typeof I=="string"?`${b}${I}`:`${b}${I.token}`,"");d.dataStream=`${e}${v}\r
|
|
3
3
|
`;let E;if(u){E=c.getSelectionRanges();const b=d.dataStream.length-2+r;E.forEach(I=>{I.startOffset=Math.max(0,Math.min(I.startOffset,b)),I.endOffset=Math.max(0,Math.min(I.endOffset,b))})}return s.syncExecuteCommand(J.ReplaceTextRunsCommand.id,{unitId:p,body:l.getBodySlice(d,0,d.dataStream.length-2),textRanges:h!=null?h:E}),_}})}function Nr(){const e=a.useDependency(l.ThemeService),t=e.getCurrentTheme();return R.useMemo(()=>{const s=[e.getColorFromTheme("loop-color.1"),e.getColorFromTheme("loop-color.2"),e.getColorFromTheme("loop-color.3"),e.getColorFromTheme("loop-color.4"),e.getColorFromTheme("loop-color.5"),e.getColorFromTheme("loop-color.6"),e.getColorFromTheme("loop-color.7"),e.getColorFromTheme("loop-color.8"),e.getColorFromTheme("loop-color.9"),e.getColorFromTheme("loop-color.10"),e.getColorFromTheme("loop-color.11"),e.getColorFromTheme("loop-color.12")].map(i=>e.isValidThemeColor(i)?e.getColorFromTheme(i):i),r=e.getColorFromTheme("blue.700"),o=e.getColorFromTheme("jiqing.800"),c=e.getColorFromTheme("black");return{formulaRefColors:s,numberColor:r,stringColor:o,plainTextColor:c}},[t])}function Dr(e,t,n){const{formulaRefColors:s,numberColor:r,stringColor:o,plainTextColor:c}=t,i=[],u=[],h=new Map;let m=0;for(let p=0,f=n.length;p<f;p++){const g=n[p];if(typeof g=="string"){const b=i[i.length-1],I=b?b.ed:0,S=I+g.length;i.push({st:I,ed:S,ts:{cl:{rgb:c},fs:11}});continue}if(e.hasDefinedNameDescription(g.token.trim())){i.push({st:g.startIndex,ed:g.endIndex+1,ts:{cl:{rgb:c},fs:11}});continue}const{startIndex:d,endIndex:C,nodeType:_,token:v}=g;let E="";if(_===T.sequenceNodeType.REFERENCE){if(h.has(v))E=h.get(v);else{const b=m%s.length;E=s[b],h.set(v,E),m++}u.push({refIndex:p,themeColor:E,token:v,startIndex:g.startIndex,endIndex:g.endIndex,index:u.length})}else _===T.sequenceNodeType.NUMBER?E=r:(_===T.sequenceNodeType.STRING||_===T.sequenceNodeType.ARRAY)&&(E=o);E&&E.length>0?i.push({st:d,ed:C+1,ts:{cl:{rgb:E},fs:11}}):i.push({st:d,ed:C+1,ts:{cl:{rgb:c},fs:11}})}return{textRuns:i,refSelections:u}}const wr=(e,t,n,s)=>{const r=a.useDependency(l.ICommandService),o=a.useDependency(a.IShortcutService),c=R.useRef(t);c.current=t;const i=R.useRef(s);i.current=s,R.useEffect(()=>{if(!n||!e)return;const h=`sheet.formula-embedding-editor.${n.getEditorId()}`,m=new l.DisposableCollection,p=(d,C)=>{if(i.current){i.current(d,C);return}let _=l.Direction.LEFT;d===a.KeyCode.ARROW_DOWN?_=l.Direction.DOWN:d===a.KeyCode.ARROW_UP?_=l.Direction.UP:d===a.KeyCode.ARROW_RIGHT&&(_=l.Direction.RIGHT),C===a.MetaKeys.SHIFT?r.executeCommand(J.MoveSelectionOperation.id,{direction:_}):r.executeCommand(J.MoveCursorOperation.id,{direction:_})},f=(d,C)=>{let _=l.Direction.DOWN;d===a.KeyCode.ARROW_DOWN?_=l.Direction.DOWN:d===a.KeyCode.ARROW_UP?_=l.Direction.UP:d===a.KeyCode.ARROW_LEFT?_=l.Direction.LEFT:d===a.KeyCode.ARROW_RIGHT&&(_=l.Direction.RIGHT),c.current?C===a.MetaKeys.CTRL_COMMAND?r.executeCommand(k.MoveSelectionCommand.id,{direction:_,jumpOver:k.JumpOver.moveGap,extra:"formula-editor",fromCurrentSelection:c.current===Se.NEED_ADD||c.current===Se.EDIT_OTHER_SHEET_REFERENCE}):C===a.MetaKeys.SHIFT?r.executeCommand(k.ExpandSelectionCommand.id,{direction:_,extra:"formula-editor"}):C===(a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT)?r.executeCommand(k.ExpandSelectionCommand.id,{direction:_,jumpOver:k.JumpOver.moveGap,extra:"formula-editor"}):r.executeCommand(k.MoveSelectionCommand.id,{direction:_,extra:"formula-editor",fromCurrentSelection:c.current===Se.NEED_ADD||c.current===Se.EDIT_OTHER_SHEET_REFERENCE}):p(d,C)};return m.add(r.registerCommand({id:h,type:l.CommandType.OPERATION,handler(d,C){const{keyCode:_,metaKey:v}=C;f(_,v)}})),[{keyCode:a.KeyCode.ARROW_DOWN},{keyCode:a.KeyCode.ARROW_LEFT},{keyCode:a.KeyCode.ARROW_RIGHT},{keyCode:a.KeyCode.ARROW_UP},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT}].map(({keyCode:d,metaKey:C})=>({id:h,binding:C?d|C:d,preconditions:()=>!0,priority:900,staticParameters:{eventType:B.DeviceInputEventType.Keyboard,keyCode:d,metaKey:C}})).forEach(d=>{m.add(o.registerShortcut(d))}),()=>{m.dispose()}},[r,n,e,o])},kr=(e,t,n,s=!0)=>{var f;const r=a.useDependency(B.IRenderManagerService),o=a.useDependency(l.IContextService),c=a.useDependency(a.IContextMenuService),i=a.useDependency(A.IRefSelectionsService),u=a.useDependency(l.IUniverInstanceService),h=a.useObservable(R.useMemo(()=>u.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),[u])),m=r.getRenderById((f=h==null?void 0:h.getUnitId())!=null?f:""),p=m==null?void 0:m.with(exports.RefSelectionsRenderService);R.useLayoutEffect(()=>{if(e)return o.setContextValue(l.EDITOR_ACTIVATED,!0),()=>{o.setContextValue(l.EDITOR_ACTIVATED,!1),i.clear()}},[o,e,i]),R.useLayoutEffect(()=>{if(e&&t){const g=p==null?void 0:p.enableSelectionChanging();return o.setContextValue(A.REF_SELECTIONS_ENABLED,!0),()=>{o.setContextValue(A.REF_SELECTIONS_ENABLED,!1),g==null||g.dispose()}}},[o,e,p,t]),R.useEffect(()=>{if(e)return o.setContextValue(l.EDITOR_ACTIVATED,!0),s&&c.disable(),()=>{o.setContextValue(l.EDITOR_ACTIVATED,!1),s&&c.enable()}},[c,o,e,s]),R.useEffect(()=>{e&&(p==null||p.setSkipLastEnabled(!1))},[e,p])},Ar=(e,t,n)=>{const s=a.useDependency(l.IUniverInstanceService),r=a.useDependency(A.SheetsSelectionsService);return R.useCallback(()=>{if(e){const c=[...r.getWorkbookSelections(t).getSelectionsOfWorksheet(n)],i=s.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),u=i==null?void 0:i.getActiveSheet();(i==null?void 0:i.getUnitId())!==t&&s.setCurrentUnitForType(t),u&&u.getSheetId()===n&&r.setSelections(c)}},[e,r,n,t,s])},Fr=e=>e.reduce((t,n)=>typeof n=="string"?t+n.length:t+n.token.length,0),at=e=>e.map(t=>typeof t=="string"?t:t.token).join(""),Ke=(e,t=!1,n="",s=!1)=>!t&&!s?e.map(r=>T.serializeRange(r.range)):e.map(r=>s?T.serializeRangeToRefString(r):r.sheetName!==""&&r.sheetName!==n?T.serializeRangeWithSheet(r.sheetName,r.range):T.serializeRange(r.range)),Pr=e=>{var m,p,f;const{editor:t,lexerTreeBuilder:n}=e,s=t==null?void 0:t.getSelectionRanges();if((s==null?void 0:s.length)!==1)return;const o=s[0].startOffset-1,c=((p=(m=t==null?void 0:t.getDocumentData().body)==null?void 0:m.dataStream)!=null?p:`\r
|
|
4
4
|
`).slice(0,-2),i=(f=n.sequenceNodesBuilder(c.slice(1)))!=null?f:[],u=dt(i,o,!1),h=Vt(i,u);return{nodeIndex:u,updatingRefIndex:h,sequenceNodes:i,offset:o}},Lr=()=>{},Ur=(e,t,n,s,r,o,c,i,u,h=Lr)=>{var j;const m=a.useDependency(B.IRenderManagerService),p=a.useDependency(l.IUniverInstanceService),f=a.useDependency(l.ICommandService),g=a.useDependency(bt.DocSelectionManagerService),d=a.useDependency(l.ThemeService),C=a.useDependency(T.LexerTreeBuilder),_=p.getUnit(s),v=a.useEvent((D,M)=>{var x,O,P;return(P=(O=(x=p.getUnit(D))==null?void 0:x.getSheetBySheetId(M))==null?void 0:O.getName())!=null?P:""}),E=R.useMemo(()=>v(s,r),[v,r,s]),b=a.useObservable(_==null?void 0:_.activeSheet$),I=Oe({activeSheet:b,sheetName:E}),S=a.useObservable(R.useMemo(()=>p.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),[p])),N=m.getRenderById((j=S==null?void 0:S.getUnitId())!=null?j:""),F=N==null?void 0:N.with(exports.RefSelectionsRenderService),L=N==null?void 0:N.with(k.SheetSkeletonManagerService),U=a.useDependency(A.IRefSelectionsService),w=a.useEvent((D,M)=>{var H,ne,re,oe,Y,ee,Le,Ne,Ue,fe;const x=Pr({editor:u,lexerTreeBuilder:C});if(!x)return;const{nodeIndex:O,updatingRefIndex:P,sequenceNodes:$,offset:V}=x;if(n.current===Se.NEED_ADD)if(V!==0){if(O===-1&&$.length)return;const z=D[D.length-1],X=$.splice(O+1),ge=(H=z.sheetId)!=null?H:r,ie={range:z,unitId:(ne=z.unitId)!=null?ne:S.getUnitId(),sheetName:v((re=z.unitId)!=null?re:S.getUnitId(),ge)},Q=ge!==r,se=(S==null?void 0:S.getUnitId())!==s,me=Ke([ie],c&&(Q||se),E,se);$.push({token:me[0],nodeType:T.sequenceNodeType.REFERENCE});const Ee=[...$,...X],ve=at(Ee);h(ve,Fr($),M)}else{const z=D[D.length-1],X=(oe=z.sheetId)!=null?oe:r,ge={range:z,unitId:(Y=z.unitId)!=null?Y:S.getUnitId(),sheetName:v((ee=z.unitId)!=null?ee:S.getUnitId(),X)},ie=X!==r,Q=(S==null?void 0:S.getUnitId())!==s,se=Ke([ge],c&&(ie||Q),E,Q);$.unshift({token:se[0],nodeType:T.sequenceNodeType.REFERENCE});const me=at($);h(me,se[0].length,M)}else if(n.current===Se.EDIT_OTHER_SHEET_REFERENCE||n.current===Se.EDIT_OTHER_WORKBOOK_REFERENCE){const z=D.pop();if(!z)return;const X=$[O];if(typeof X=="object"&&X.nodeType===T.sequenceNodeType.REFERENCE){const ge=X.token;(S==null?void 0:S.getUnitId())!==s?X.token=T.serializeRangeWithSpreadsheet((Le=S==null?void 0:S.getUnitId())!=null?Le:"",E,z):X.token=E===(b==null?void 0:b.getName())?T.serializeRange(z):T.serializeRangeWithSheet(b.getName(),z);const Q=V+(X.token.length-ge.length);h(T.generateStringWithSequence($),Q,M)}}else{const z=[...D];if(P!==-1){const G=z.pop();G&&z.splice(P,0,G)}let X=0;const ge=$.map(G=>{var ce,Ie,De,ae;if(typeof G=="string")return G;if(G.nodeType===T.sequenceNodeType.REFERENCE){const le=T.deserializeRangeWithSheet(G.token);if(le.sheetName||(le.sheetName=E),(le.unitId||s)!==(S==null?void 0:S.getUnitId())||c&&((ce=I.current.activeSheet)==null?void 0:ce.getName())!==le.sheetName)return G.token;const he=z[X];if(X++,!he)return"";const $e=(Ie=he.sheetId)!=null?Ie:r,nt={range:he,unitId:(De=he.unitId)!=null?De:S.getUnitId(),sheetName:v((ae=he.unitId)!=null?ae:S.getUnitId(),$e)},je=(S==null?void 0:S.getUnitId())!==s;return Ke([nt],c&&($e!==r||je),E,je)[0]}return G.token});let ie="",Q;ge.forEach((G,ce)=>{ie+=G,ce===O&&(Q=ie.length)});const se=[];for(let G=X;G<=D.length-1;G++){const ce=D[G],Ie=(Ne=ce.sheetId)!=null?Ne:r,De={range:ce,unitId:(Ue=ce.unitId)!=null?Ue:S.getUnitId(),sheetName:v((fe=ce.unitId)!=null?fe:S.getUnitId(),Ie)},ae=(S==null?void 0:S.getUnitId())!==s,he=Ke([De],c&&(Ie!==r||ae),E,ae);se.push(he[0])}const me=$[$.length-1],Ee=me&&(typeof me=="string"?!1:me.nodeType===T.sequenceNodeType.REFERENCE),ve=`${ie}${se.length&&Ee?",":""}${se.join(",")}`;h(ve,!se.length&&Q?Q:ve.length,M)}});R.useEffect(()=>{if(F&&e){let D=!0;const M=(O,P)=>{if(D){D=!1;return}w(O.map($=>$.rangeWithCoord),P)},x=new l.DisposableCollection;return x.add(F.selectionMoving$.subscribe(O=>{M(O,!1)})),x.add(F.selectionMoveEnd$.subscribe(O=>{M(O,!0)})),()=>{x.dispose()}}},[e,w,F]),R.useEffect(()=>{if(t&&F&&u){const D=new l.DisposableCollection,M=()=>{D.dispose(),F.getSelectionControls().forEach((P,$)=>{D.add(P.selectionScaling$.subscribe(V=>{const H=F.getSelectionDataWithStyle().map(re=>re.rangeWithCoord),ne=H[$];V.sheetId=ne.sheetId,V.unitId=ne.unitId,H[$]=V,w(H,!1)})),D.add(P.selectionMoving$.subscribe(V=>{const H=F.getSelectionDataWithStyle().map(re=>re.rangeWithCoord),ne=H[$];V.sheetId=ne.sheetId,V.unitId=ne.unitId,H[$]=V,w(H,!0)}))})},x=q.merge(u.input$,U.selectionSet$,F.selectionMoveEnd$).pipe(Jt.debounceTime(50)).subscribe(()=>{M()});return()=>{x.unsubscribe(),D.dispose()}}},[u,t,w,F,U.selectionSet$]),F==null||F.getSelectionDataWithStyle(),R.useEffect(()=>{if(i){const D=f.onCommandExecuted(M=>{var O;if(M.id!==A.SetSelectionsOperation.id)return;const x=M.params;if(x.extra==="formula-editor"&&x.selections.length){const P=x.selections[x.selections.length-1];if(P){const $=n.current===Se.NEED_ADD,V=((O=F==null?void 0:F.getSelectionDataWithStyle())!=null?O:[]).map(H=>H.rangeWithCoord);$?V.push(P.range):V[V.length-1]=P.range,w(V,!0)}}});return()=>{D.dispose()}}},[f,u,n,C,i,w,F]),R.useEffect(()=>{if(!u)return;const D=g.textSelection$.subscribe(M=>{M.unitId===u.getEditorId()&&Bt({unitId:s,subUnitId:r,refSelections:o.current,editor:u,refSelectionsService:U,refSelectionsRenderService:F,sheetSkeletonManagerService:L,themeService:d,univerInstanceService:p,currentWorkbook:S})});return()=>D.unsubscribe()},[g.textSelection$,u,o,F,U,L,r,d,s,p])},$r=(e,t,n,s,r,o)=>{const c=a.useDependency(l.ICommandService),i=a.useDependency(J.IEditorService),h=a.useDependency(B.IRenderManagerService).getRenderById(t),m=a.useDependency(l.IUniverInstanceService),p=h==null?void 0:h.with(exports.RefSelectionsRenderService);R.useEffect(()=>{if(e&&p)if(n){const f=()=>{const C=p.getSelectionControls().length;for(let _=1;_<=C;_++)p.clearLastSelection();return setTimeout(()=>{o()},30)},g=c.onCommandExecuted(C=>{C.id===A.SetWorksheetActiveOperation.id&&f()}),d=m.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).subscribe(C=>{f()});return()=>{g.dispose(),d.unsubscribe()}}else{const f=c.beforeCommandExecuted(g=>{if(g.id===A.SetWorksheetActiveOperation.id){s(!1),r(),o();const d=i.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);d==null||d.focus()}});return()=>{f.dispose()}}},[e,p])},jr=(e,t,n)=>{const s=a.useDependency(T.LexerTreeBuilder),r=R.useRef(!0);R.useEffect(()=>{if(e){const o=setTimeout(()=>{r.current=!1},500);return()=>{clearTimeout(o)}}},[e]),R.useEffect(()=>{if(!r.current&&t){const o=s.checkIfAddBracket(n);t(o===0&&n.startsWith(T.operatorToken.EQUALS),`${n}`)}},[n,t])},Wr=(e,t=[],n)=>{const s=a.useDependency(Re.IDescriptionService),[r,o]=R.useState([]),[c,i]=R.useState(""),u=R.useRef(-1),h=Oe({nodes:t}),m=()=>{o([]),i(""),u.current=-1};return R.useEffect(()=>{if(n&&e){const f=n.input$.pipe(q.debounceTime(300)).subscribe(()=>{const g=n.getSelectionRanges();if(g.length===1){const d=h.current.nodes,C=g[0];if(C.collapsed){const _=dt(d,C.startOffset-1,!1);u.current=_;const v=d[_];if(v&&typeof v!="string"&&v.nodeType===T.sequenceNodeType.FUNCTION){u.current=_;const E=v.token,b=s.getSearchListByNameFirstLetter(E);o(b),i(E);return}}}u.current=-1,i(""),o(d=>d!=null&&d.length?[]:d)});return()=>{f.unsubscribe()}}},[n,e]),R.useEffect(()=>{e||m()},[e]),{searchList:r,searchText:c,handlerFormulaReplace:f=>{const g=[...h.current.nodes];if(u.current!==-1){const d=g.splice(u.current+1),C=g.pop()||"";let _=(typeof C=="string"?C.length:C.token.length)-f.length;return g.push(f),d[0]!==T.matchToken.OPEN_BRACKET&&(g.push(T.matchToken.OPEN_BRACKET),_--),{text:at([...g,...d]),offset:_}}},reset:m}},Vr=()=>{},Hr=R.forwardRef(Br);function Br(e,t){const{isFocus:n,sequenceNodes:s,onSelect:r,editor:o,onClose:c=Vr}=e,i=o.getEditorId(),u=a.useDependency(a.IShortcutService),h=a.useDependency(l.ICommandService),{searchList:m,searchText:p,handlerFormulaReplace:f,reset:g}=Wr(n,s,o),d=R.useMemo(()=>!!m.length,[m]),C=R.useRef(void 0),[_,v]=R.useState(0),E=R.useRef(!1),[b]=Ht(i,d,[p,m]),I=Oe({searchList:m,active:_}),S=w=>{const j=f(w);j&&(g(),r(j))};function N(w){E.current&&v(w)}function F(){E.current&&v(-1)}R.useEffect(()=>{if(!m.length)return;const w=`sheet.formula-embedding-editor.search_function.${i}`,j=new l.DisposableCollection,D=M=>{const{searchList:x,active:O}=I.current;switch(M){case a.KeyCode.ARROW_UP:{v(P=>{const $=Math.max(0,P-1);return L($),$});break}case a.KeyCode.ARROW_DOWN:{v(P=>{const $=Math.min(x.length-1,P+1);return L($),$});break}case a.KeyCode.TAB:case a.KeyCode.ENTER:{const P=x[O];S(P.name);break}case a.KeyCode.ESC:{g(),c();break}}};return j.add(h.registerCommand({id:w,type:l.CommandType.OPERATION,handler(M,x){const{keyCode:O}=x;D(O)}})),[a.KeyCode.ARROW_UP,a.KeyCode.ARROW_DOWN,a.KeyCode.ENTER,a.KeyCode.ESC,a.KeyCode.TAB].map(M=>({id:w,binding:M,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:B.DeviceInputEventType.Keyboard,keyCode:M}})).forEach(M=>{j.add(u.registerShortcut(M))}),()=>{j.dispose()}},[m]);function L(w){const j=C.current;if(!j)return;const D=j.children[w];if(!D)return;const x=j.getBoundingClientRect().top,O=j.offsetHeight,P=D.getBoundingClientRect(),$=P.top,V=P.height;if($>=0&&$>x&&$-x+V<=O)return;const H=D.offsetTop-(O-V)/2;j.scrollTo({top:H,behavior:"smooth"})}const U=R.useMemo(()=>{let w="";return()=>{clearTimeout(w),E.current=!0,w=setTimeout(()=>{E.current=!1},300)}},[]);return m.length>0&&d&&y.jsx(a.RectPopup,{portal:!0,anchorRect$:b,direction:"vertical",children:y.jsx("ul",{ref:w=>{C.current=w,t&&(t.current=w)},"data-u-comp":"sheets-formula-editor",className:W.clsx("univer-m-0 univer-box-border univer-max-h-[400px] univer-w-[250px] univer-list-none univer-overflow-y-auto univer-rounded-lg univer-bg-white univer-p-2 univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",W.borderClassName,W.scrollbarClassName),children:m.map((w,j)=>y.jsxs("li",{className:W.clsx("univer-box-border univer-cursor-pointer univer-rounded univer-px-2 univer-py-1 univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200 dark:!univer-bg-gray-600":_===j}),onMouseEnter:()=>N(j),onMouseLeave:F,onMouseMove:U,onClick:()=>{S(w.name),o&&o.focus()},children:[y.jsxs("span",{className:"univer-text-xs",children:[y.jsx("span",{className:"univer-text-red-500",children:w.name.substring(0,p.length)}),y.jsx("span",{children:w.name.slice(p.length)})]}),y.jsx("span",{className:"univer-block univer-text-xs univer-text-gray-400",children:w.desc})]},w.name))})})}const Kr=e=>e.startsWith(T.operatorToken.EQUALS)?e.slice(1):"",It=()=>{},qt=R.forwardRef((e,t)=>{var rt,gt;const{errorText:n,initValue:s,unitId:r,subUnitId:o,isFocus:c=!0,isSupportAcrossSheet:i=!1,onFocus:u=It,onBlur:h=It,onChange:m,onVerify:p,className:f,editorId:g,moveCursor:d=!0,onFormulaSelectingChange:C,keyboardEventConfig:_,onMoveInEditor:v,resetSelectionOnBlur:E=!0,autoScrollbar:b=!0,isSingle:I=!0,disableSelectionOnClick:S=!1,autofocus:N=!0,disableContextMenu:F,style:L}=e,U=a.useDependency(J.IEditorService),w=R.useRef(null),j=a.useEvent(m);R.useImperativeHandle(t,()=>({isClickOutSide:Z=>w.current?!w.current.contains(Z.target):!1}));const D=a.useEvent(C),M=R.useRef(null),x=R.useRef(void 0),O=x.current,[P,$]=R.useState(c),V=R.useRef(null),H=R.useMemo(()=>g!=null?g:l.createInternalEditorID(`${k.EMBEDDING_FORMULA_EDITOR}-${l.generateRandomId(4)}`),[]),ne=R.useMemo(()=>n!==void 0,[n]),re=a.useDependency(l.IUniverInstanceService),oe=re.getUnit(H);a.useObservable(oe==null?void 0:oe.change$);const Y=xr(),ee=l.BuildTextUtils.transform.getPlainText((gt=(rt=oe==null?void 0:oe.getBody())==null?void 0:rt.dataStream)!=null?gt:""),Le=Oe(ee),Ne=R.useMemo(()=>Kr(ee),[ee]),Ue=R.useMemo(()=>Y(Ne),[Ne,Y]),{isSelecting:fe,isSelectingRef:z}=Tr({unitId:r,subUnitId:o,editorId:H,isFocus:P,disableOnClick:S}),X=R.useRef(""),ie=a.useDependency(B.IRenderManagerService).getRenderById(H),Q=ie==null?void 0:ie.with(J.DocSelectionRenderService),se=Q==null?void 0:Q.isFocusing,me=R.useMemo(()=>re.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_DOC),[re]),Ee=a.useObservable(me),ve=(Ee==null?void 0:Ee.getUnitId())===H,G=R.useRef([]),ce=fe;a.useUpdateEffect(()=>{j(ee)},[ee,j]);const Ie=Kt("="),De=Or(r,o),ae=a.useEvent((Z,te=!0,Ce,pe)=>{if(!x.current)return;X.current=Z;const We=Z[0]==="="?Z.slice(1):"",_e=Y(We),zt=_e.reduce((ye,He)=>typeof He=="object"?`${ye}${He.token}`:`${ye}${He}`,""),Ve=Ie(x.current,zt===We?_e:[],te,pe);if(G.current=Ve,Ce){const ye=pe!=null?pe:O==null?void 0:O.getSelectionRanges();if((ye==null?void 0:ye.length)!==1)return;const Gt=ye[0].startOffset-1,Zt=dt(_e,Gt,!1),mt=Vt(_e,Zt);if(mt>=0){const pt=Ve.splice(mt,1)[0];pt&&Ve.push(pt)}De(P?Ve:[],x.current)}});R.useEffect(()=>{P&&ae(ee,!1,!0)},[P]),R.useEffect(()=>{if(P){if(X.current===ee)return;ae(ee,!1,!0)}},[ee]),jr(P,p,ee);const le=yr(O),he=Ar(P,r,o);R.useEffect(()=>{var Z;D(fe,(Z=Q==null?void 0:Q.isFocusing)!=null?Z:!0)},[D,fe]),J.useKeyboardEvent(P,_,O),R.useLayoutEffect(()=>{let Z;if(V.current){Z=U.register({autofocus:N,editorUnitId:H,initialSnapshot:{id:H,body:{dataStream:`${s}\r
|
|
5
|
-
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},V.current);const te=U.getEditor(H);x.current=te,ae(s,!1,!0)}return()=>{Z==null||Z.dispose()}},[]),R.useLayoutEffect(()=>{c?($(c),le()):(E&&(O==null||O.blur(),he()),$(c))},[c,O,le,he,E]);const{checkScrollBar:$e}=J.useResize(O,I,b);kr(P,!!(fe&&ve),r,F),wr(!!(P&&se&&d),ce,O,v);const nt=a.useEvent((Z,te,Ce)=>{if(!se)return;const pe=te!==-1?[{startOffset:te+1,endOffset:te+1,collapsed:!0}]:void 0;ae(`=${Z}`,!0,Ce,pe),Ce&&(le(),te!==-1&&setTimeout(()=>{const We={startOffset:te+1,endOffset:te+1},_e=O==null?void 0:O.render.with(J.DocBackScrollRenderController);_e==null||_e.scrollToRange({...We,collapsed:!0})},50),$e())});Ur(P&&!!(fe&&ve),P,z,r,o,G,i,!!ce,O,nt),$r(P&&!!(fe&&ve),r,i,$,h,()=>{ae(Le.current,!1,!0)});const je=Z=>{if(Z){const te=O==null?void 0:O.getSelectionRanges();if(te&&te.length===1){const Ce=te[0];if(Ce.collapsed){const pe=Z.offset;setTimeout(()=>{O==null||O.setSelectionRanges([{startOffset:Ce.startOffset-pe,endOffset:Ce.endOffset-pe}])},30)}}le(),ae(`=${Z.text}`)}},ft=()=>{$(!0),u(),le()};return y.jsxs("div",{className:f,children:[y.jsx("div",{ref:w,className:W.clsx(`
|
|
6
|
-
univer-relative univer-box-border univer-flex univer-h-full univer-w-full univer-items-center
|
|
7
|
-
univer-justify-around univer-gap-2 univer-rounded-none univer-p-0 univer-ring-1
|
|
8
|
-
`,{"univer-ring-primary-500":P,"univer-ring-red-500":ne}),children:y.jsx("div",{ref:V,className:"univer-relative univer-h-full univer-w-full",onMouseUp:ft})}),n!==void 0?y.jsx("div",{className:"univer-my-1 univer-text-xs univer-text-red-500",children:n}):null,O&&Ne!==""?y.jsx(Ir,{editor:O,isFocus:P,formulaText:ee,onClose:()=>le()}):null,O?y.jsx(Hr,{isFocus:P,sequenceNodes:Ue,onSelect:je,ref:M,editor:O}):null]})});function qr(e,t,n,s){const r=a.useDependency(T.LexerTreeBuilder),o=Kt(""),c=a.useObservable(e==null?void 0:e.getDocumentDataModel().change$),[i,u]=R.useState([]),h=a.useDependency(k.IMarkSelectionService),m=R.useRef(""),p=a.useDependency(l.IUniverInstanceService);return R.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:[])},[c,e,r]),R.useEffect(()=>{var d,C;if(!e)return;if(!t){const _=e.getDocumentData();e.setDocumentData({..._,body:{..._.body,dataStream:(C=(d=_.body)==null?void 0:d.dataStream)!=null?C:"",textRuns:[]}});return}const f=o(e,i,!1),g=new l.DisposableCollection;return f.forEach(_=>{const v=T.deserializeRangeWithSheet(_.token),E=p.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),b=E==null?void 0:E.getActiveSheet();if(!v.sheetName&&s!==(b==null?void 0:b.getSheetId())||v.sheetName&&(b==null?void 0:b.getName())!==v.sheetName)return;const I=new l.ColorKit(_.themeColor).toRgb(),S=h.addShape({range:v.range,style:{stroke:_.themeColor,fill:`rgba(${I.r}, ${I.g}, ${I.b}, 0.1)`,strokeDash:12},primary:null});S&&g.add(()=>h.removeShape(S))}),()=>{g.dispose()}},[e,t,o,h,i]),{sequenceNodes:i}}function Yr(e){const t=a.useDependency(A.SheetsSelectionsService),{supportAcrossSheet:n=!1,unitId:s,subUnitId:r,onChange:o}=e,i=a.useDependency(l.IUniverInstanceService).getUnit(s,l.UniverInstanceType.UNIVER_SHEET),u=a.useEvent(o),h=a.useEvent((m,p)=>{const f=i==null?void 0:i.getActiveSheet();if(!f||!n&&f.getSheetId()!==r||!(m!=null&&m.length))return;const g=m.map(d=>({range:d.range,unitId:s,sheetName:f.getSheetId()===r?"":f.getName()}));u(g,p)});R.useEffect(()=>{const m=new l.DisposableCollection;return m.add(t.selectionMoveStart$.subscribe(p=>{h(p,!0)})),m.add(t.selectionMoving$.subscribe(p=>{h(p,!1)})),m.add(t.selectionMoveEnd$.subscribe(p=>{h(p,!1)})),()=>{m.dispose()}},[h,t.selectionMoveEnd$,t.selectionMoveStart$,t.selectionMoving$])}const yt=e=>!e.some(n=>{if(typeof n=="string"){if(n!==T.matchToken.COMMA)return!0}else if(n.nodeType!==T.sequenceNodeType.REFERENCE)return!0;return!1}),zr=e=>{if(e.endColumn<e.startColumn){const t=e.endColumn;e.endColumn=e.startColumn,e.startColumn=t}if(e.endRow<e.startRow){const t=e.endRow;e.endRow=e.startRow,e.startRow=t}return e};function Gr(e){const{visible:t,initialValue:n,unitId:s,subUnitId:r,maxRangeCount:o=1/0,supportAcrossSheet:c,onConfirm:i,onClose:u,onShowBySelection:h}=e,m=a.useDependency(l.LocaleService),p=a.useDependency(T.LexerTreeBuilder),[f,g]=R.useState([]),[d,C]=R.useState(0),_=R.useRef(null);R.useEffect(()=>{if(t&&n.length){const I=n.map(S=>S.sheetName?T.serializeRangeWithSheet(S.sheetName,S.range):T.serializeRange(S.range));g(I),C(I.length-1)}else g([""]),C(0)},[t]);const v=(I,S)=>{const N=[...f];N[I]=S,g(N)},E=()=>{g([...f,""]),C(f.length)},b=I=>{f.splice(I,1),g([...f])};return Yr({unitId:s,subUnitId:r,supportAcrossSheet:c,onChange:(I,S)=>{if(!t&&h!=null&&h(I))return;const N=new Set(f),F=I.map(w=>w.sheetName?T.serializeRangeWithSheet(w.sheetName,w.range):T.serializeRange(w.range)),L=F.filter(w=>!N.has(w));if(!L.length)return;const U=[...f];if(F.length>1){S||U.splice(d,1),U.push(...L);const w=U.slice(0,o);g(w),C(w.length-1),requestAnimationFrame(()=>{var j;(j=_.current)==null||j.scrollTo({top:_.current.scrollHeight})})}else{U.splice(d,1,...L);const w=U.slice(0,o);g(w),C(d+L.length-1)}}}),y.jsx(W.Dialog,{width:"328px",open:t,title:m.t("rangeSelector.title"),draggable:!0,mask:!1,maskClosable:!1,footer:y.jsxs("footer",{className:"univer-flex univer-gap-2",children:[y.jsx(W.Button,{onClick:u,children:m.t("rangeSelector.cancel")}),y.jsx(W.Button,{variant:"primary",onClick:()=>{i(f.filter(I=>{const S=p.sequenceNodesBuilder(I);return S&&S.length===1&&typeof S[0]!="string"&&S[0].nodeType===T.sequenceNodeType.REFERENCE}).map(I=>T.deserializeRangeWithSheet(I)).map(I=>({...I,range:zr(I.range)})))},children:m.t("rangeSelector.confirm")})]}),onClose:u,children:y.jsxs("div",{ref:_,className:W.clsx("-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6",W.scrollbarClassName),children:[f.map((I,S)=>y.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-gap-4",children:[y.jsx(W.Input,{className:W.clsx("univer-w-full",{"univer-border-primary-600":d===S}),placeholder:m.t("rangeSelector.placeHolder"),onFocus:()=>C(S),value:I,onChange:N=>v(S,N)}),f.length>1&&y.jsx(Ut,{className:"univer-cursor-pointer",onClick:()=>b(S)})]},S)),f.length<o&&y.jsx("div",{children:y.jsxs(W.Button,{variant:"link",onClick:E,children:[y.jsx($t,{}),y.jsx("span",{children:m.t("rangeSelector.addAnotherRange")})]})})]})})}function Zr(e){return e.split(T.matchToken.COMMA).filter(t=>!!t).map(t=>T.deserializeRangeWithSheet(t))}function Xr(e){return e.map(t=>t.sheetName?T.serializeRangeWithSheet(t.sheetName,t.range):T.serializeRange(t.range)).join(T.matchToken.COMMA)}function ht(e){const[t,n]=R.useState(null),{onVerify:s,selectorRef:r,unitId:o,subUnitId:c,maxRangeCount:i,supportAcrossSheet:u,autoFocus:h,onChange:m,onRangeSelectorDialogVisibleChange:p,onClickOutside:f,onFocusChange:g,forceShowDialogWhenSelectionChanged:d,hideEditor:C,resetRange:_}=e,[v,E]=R.useState(h!=null?h:!1),[b,I]=R.useState(!1),[S,N]=R.useState([]),F=a.useDependency(l.LocaleService),L=a.useDependency(J.IEditorService),{sequenceNodes:U}=qr(t,v,o,c),w=Oe(U),j=a.useDependency(l.ICommandService),D=a.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),L.blur()}),M=a.useEvent(()=>{var x;D(),N(Zr((x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:"")),I(!0)});return R.useEffect(()=>{r&&(r.current={get editor(){return t},focus(){L.focus(t.getEditorId())},blur:D,verify:()=>yt(w.current),showDialog:x=>{D(),N(x),I(!0)},hideDialog:()=>{N([]),I(!1)},getValue:()=>{var x;return(x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:""}})},[D,t,L,r,w]),R.useEffect(()=>{var x;s==null||s(yt(U),(x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:"")},[U]),R.useEffect(()=>{p==null||p(b)},[b]),R.useEffect(()=>{if(b&&_)return()=>{const x={unitId:o,subUnitId:c,selections:_};j.executeCommand(A.SetSelectionsOperation.id,x)}},[b]),y.jsxs(y.Fragment,{children:[C?null:y.jsx(J.RichTextEditor,{isSingle:!0,...e,onFocusChange:(x,O)=>{E(x),g==null||g(x,O)},editorRef:n,onClickOutside:()=>{E(!1),D(),f==null||f()},icon:y.jsx(W.Tooltip,{title:F.t("rangeSelector.buttonTooltip"),placement:"bottom",children:y.jsx(Wt,{className:"univer-cursor-pointer dark:!univer-text-gray-300",onClick:M})})}),y.jsx(Gr,{initialValue:S,unitId:o,subUnitId:c,visible:b,maxRangeCount:i,onConfirm:x=>{const O=Xr(x),P=l.RichTextBuilder.newEmptyData();P.body.dataStream=O,t==null||t.replaceText(O,!1),m==null||m(P,O),I(!1),N([]),requestAnimationFrame(()=>{D()})},onClose:()=>{I(!1),N([])},supportAcrossSheet:u,onShowBySelection:x=>v||d?(N(x),I(!0),!1):!0})]})}const Qr=()=>{var s,r;const e=a.useDependency(ut),t=a.useObservable(e.currentSelector$),n=R.useRef(null);return R.useEffect(()=>{var o,c;if(t)return(c=n.current)==null||c.showDialog((o=t.initialValue)!=null?o:[]),()=>{var i;(i=n.current)==null||i.hideDialog()}},[t]),y.jsx(ht,{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,c)=>{var i;t==null||t.callback((i=c==null?void 0:c.split(",").map(u=>T.deserializeRangeWithSheet(u)))!=null?i:[])}})};var Jr=Object.defineProperty,es=Object.getOwnPropertyDescriptor,ts=(e,t,n)=>t in e?Jr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ns=(e,t,n,s)=>{for(var r=s>1?void 0:s?es(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},qe=(e,t)=>(n,s)=>t(n,s,e),Yt=(e,t,n)=>ts(e,typeof t!="symbol"?t+"":t,n);exports.UniverSheetsFormulaUIPlugin=class extends l.Plugin{constructor(t=Ct,n,s,r,o){super(),this._config=t,this._injector=n,this._renderManagerService=s,this._configService=r,this._uiPartsService=o;const{menu:c,...i}=l.merge(Ct,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig(hn,i,{merge:!0})}onStarting(){l.registerDependencies(this._injector,[[Je,{useClass:it}],[ut],[Xe],[Ye],[ze],[Ge],[Ze],[exports.FormulaReorderController]]),this._initUIPart()}onReady(){[[exports.RefSelectionsRenderService]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))})}onRendered(){[[ct]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))}),l.touchDependencies(this._injector,[[Xe],[ze],[Ze]])}onSteady(){this._injector.get(Ye),this._injector.get(exports.FormulaReorderController)}_initUIPart(){const t=this._injector.get(a.ComponentManager);this.disposeWithMe(t.register(k.RANGE_SELECTOR_COMPONENT_KEY,ht)),this.disposeWithMe(t.register(k.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,qt)),this.disposeWithMe(this._uiPartsService.registerComponent(a.BuiltInUIPart.GLOBAL,()=>a.connectInjector(Qr,this._injector)))}};Yt(exports.UniverSheetsFormulaUIPlugin,"pluginName",Mt);Yt(exports.UniverSheetsFormulaUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFormulaUIPlugin=ns([l.DependentOn(T.UniverFormulaEnginePlugin,Re.UniverSheetsFormulaPlugin),qe(1,l.Inject(l.Injector)),qe(2,B.IRenderManagerService),qe(3,l.IConfigService),qe(4,a.IUIPartsService)],exports.UniverSheetsFormulaUIPlugin);exports.FORMULA_PROMPT_ACTIVATED=Tt;exports.FormulaEditor=qt;exports.GlobalRangeSelectorService=ut;exports.HelpFunctionOperation=xt;exports.InsertFunctionOperation=de;exports.MoreFunctionsOperation=et;exports.RangeSelector=ht;exports.ReferenceAbsoluteOperation=lt;exports.SearchFunctionOperation=Nt;exports.SelectEditorFormulaOperation=xe;exports.SheetOnlyPasteFormulaCommand=Qe;
|
|
5
|
+
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},V.current);const te=U.getEditor(H);x.current=te,ae(s,!1,!0)}return()=>{Z==null||Z.dispose()}},[]),R.useLayoutEffect(()=>{c?($(c),le()):(E&&(O==null||O.blur(),he()),$(c))},[c,O,le,he,E]);const{checkScrollBar:$e}=J.useResize(O,I,b);kr(P,!!(fe&&ve),r,F),wr(!!(P&&se&&d),ce,O,v);const nt=a.useEvent((Z,te,Ce)=>{if(!se)return;const pe=te!==-1?[{startOffset:te+1,endOffset:te+1,collapsed:!0}]:void 0;ae(`=${Z}`,!0,Ce,pe),Ce&&(le(),te!==-1&&setTimeout(()=>{const We={startOffset:te+1,endOffset:te+1},_e=O==null?void 0:O.render.with(J.DocBackScrollRenderController);_e==null||_e.scrollToRange({...We,collapsed:!0})},50),$e())});Ur(P&&!!(fe&&ve),P,z,r,o,G,i,!!ce,O,nt),$r(P&&!!(fe&&ve),r,i,$,h,()=>{ae(Le.current,!1,!0)});const je=Z=>{if(Z){const te=O==null?void 0:O.getSelectionRanges();if(te&&te.length===1){const Ce=te[0];if(Ce.collapsed){const pe=Z.offset;setTimeout(()=>{O==null||O.setSelectionRanges([{startOffset:Ce.startOffset-pe,endOffset:Ce.endOffset-pe}])},30)}}le(),ae(`=${Z.text}`)}},ft=()=>{$(!0),u(),le()};return y.jsxs("div",{className:f,children:[y.jsx("div",{ref:w,className:W.clsx("univer-relative univer-box-border univer-flex univer-h-full univer-w-full univer-items-center univer-justify-around univer-gap-2 univer-rounded-none univer-p-0 univer-ring-1",{"univer-ring-primary-500":P,"univer-ring-red-500":ne}),children:y.jsx("div",{ref:V,className:"univer-relative univer-h-full univer-w-full",onMouseUp:ft})}),n!==void 0&&y.jsx("div",{className:"univer-my-1 univer-text-xs univer-text-red-500",children:n}),O&&Ne!==""&&y.jsx(Ir,{editor:O,isFocus:P,formulaText:ee,onClose:()=>le()}),!!O&&y.jsx(Hr,{isFocus:P,sequenceNodes:Ue,onSelect:je,ref:M,editor:O})]})});function qr(e,t,n,s){const r=a.useDependency(T.LexerTreeBuilder),o=Kt(""),c=a.useObservable(e==null?void 0:e.getDocumentDataModel().change$),[i,u]=R.useState([]),h=a.useDependency(k.IMarkSelectionService),m=R.useRef(""),p=a.useDependency(l.IUniverInstanceService);return R.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:[])},[c,e,r]),R.useEffect(()=>{var d,C;if(!e)return;if(!t){const _=e.getDocumentData();e.setDocumentData({..._,body:{..._.body,dataStream:(C=(d=_.body)==null?void 0:d.dataStream)!=null?C:"",textRuns:[]}});return}const f=o(e,i,!1),g=new l.DisposableCollection;return f.forEach(_=>{const v=T.deserializeRangeWithSheet(_.token),E=p.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),b=E==null?void 0:E.getActiveSheet();if(!v.sheetName&&s!==(b==null?void 0:b.getSheetId())||v.sheetName&&(b==null?void 0:b.getName())!==v.sheetName)return;const I=new l.ColorKit(_.themeColor).toRgb(),S=h.addShape({range:v.range,style:{stroke:_.themeColor,fill:`rgba(${I.r}, ${I.g}, ${I.b}, 0.1)`,strokeDash:12},primary:null});S&&g.add(()=>h.removeShape(S))}),()=>{g.dispose()}},[e,t,o,h,i]),{sequenceNodes:i}}function Yr(e){const t=a.useDependency(A.SheetsSelectionsService),{supportAcrossSheet:n=!1,unitId:s,subUnitId:r,onChange:o}=e,i=a.useDependency(l.IUniverInstanceService).getUnit(s,l.UniverInstanceType.UNIVER_SHEET),u=a.useEvent(o),h=a.useEvent((m,p)=>{const f=i==null?void 0:i.getActiveSheet();if(!f||!n&&f.getSheetId()!==r||!(m!=null&&m.length))return;const g=m.map(d=>({range:d.range,unitId:s,sheetName:f.getSheetId()===r?"":f.getName()}));u(g,p)});R.useEffect(()=>{const m=new l.DisposableCollection;return m.add(t.selectionMoveStart$.subscribe(p=>{h(p,!0)})),m.add(t.selectionMoving$.subscribe(p=>{h(p,!1)})),m.add(t.selectionMoveEnd$.subscribe(p=>{h(p,!1)})),()=>{m.dispose()}},[h,t.selectionMoveEnd$,t.selectionMoveStart$,t.selectionMoving$])}const yt=e=>!e.some(n=>{if(typeof n=="string"){if(n!==T.matchToken.COMMA)return!0}else if(n.nodeType!==T.sequenceNodeType.REFERENCE)return!0;return!1}),zr=e=>{if(e.endColumn<e.startColumn){const t=e.endColumn;e.endColumn=e.startColumn,e.startColumn=t}if(e.endRow<e.startRow){const t=e.endRow;e.endRow=e.startRow,e.startRow=t}return e};function Gr(e){const{visible:t,initialValue:n,unitId:s,subUnitId:r,maxRangeCount:o=1/0,supportAcrossSheet:c,onConfirm:i,onClose:u,onShowBySelection:h}=e,m=a.useDependency(l.LocaleService),p=a.useDependency(T.LexerTreeBuilder),[f,g]=R.useState([]),[d,C]=R.useState(0),_=R.useRef(null);R.useEffect(()=>{if(t&&n.length){const I=n.map(S=>S.sheetName?T.serializeRangeWithSheet(S.sheetName,S.range):T.serializeRange(S.range));g(I),C(I.length-1)}else g([""]),C(0)},[t]);const v=(I,S)=>{const N=[...f];N[I]=S,g(N)},E=()=>{g([...f,""]),C(f.length)},b=I=>{f.splice(I,1),g([...f])};return Yr({unitId:s,subUnitId:r,supportAcrossSheet:c,onChange:(I,S)=>{if(!t&&h!=null&&h(I))return;const N=new Set(f),F=I.map(w=>w.sheetName?T.serializeRangeWithSheet(w.sheetName,w.range):T.serializeRange(w.range)),L=F.filter(w=>!N.has(w));if(!L.length)return;const U=[...f];if(F.length>1){S||U.splice(d,1),U.push(...L);const w=U.slice(0,o);g(w),C(w.length-1),requestAnimationFrame(()=>{var j;(j=_.current)==null||j.scrollTo({top:_.current.scrollHeight})})}else{U.splice(d,1,...L);const w=U.slice(0,o);g(w),C(d+L.length-1)}}}),y.jsx(W.Dialog,{width:"328px",open:t,title:m.t("rangeSelector.title"),draggable:!0,mask:!1,maskClosable:!1,footer:y.jsxs("footer",{className:"univer-flex univer-gap-2",children:[y.jsx(W.Button,{onClick:u,children:m.t("rangeSelector.cancel")}),y.jsx(W.Button,{variant:"primary",onClick:()=>{i(f.filter(I=>{const S=p.sequenceNodesBuilder(I);return S&&S.length===1&&typeof S[0]!="string"&&S[0].nodeType===T.sequenceNodeType.REFERENCE}).map(I=>T.deserializeRangeWithSheet(I)).map(I=>({...I,range:zr(I.range)})))},children:m.t("rangeSelector.confirm")})]}),onClose:u,children:y.jsxs("div",{ref:_,className:W.clsx("-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6",W.scrollbarClassName),children:[f.map((I,S)=>y.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-gap-4",children:[y.jsx(W.Input,{className:W.clsx("univer-w-full",{"univer-border-primary-600":d===S}),placeholder:m.t("rangeSelector.placeHolder"),onFocus:()=>C(S),value:I,onChange:N=>v(S,N)}),f.length>1&&y.jsx(Ut,{className:"univer-cursor-pointer",onClick:()=>b(S)})]},S)),f.length<o&&y.jsx("div",{children:y.jsxs(W.Button,{variant:"link",onClick:E,children:[y.jsx($t,{}),y.jsx("span",{children:m.t("rangeSelector.addAnotherRange")})]})})]})})}function Zr(e){return e.split(T.matchToken.COMMA).filter(t=>!!t).map(t=>T.deserializeRangeWithSheet(t))}function Xr(e){return e.map(t=>t.sheetName?T.serializeRangeWithSheet(t.sheetName,t.range):T.serializeRange(t.range)).join(T.matchToken.COMMA)}function ht(e){const[t,n]=R.useState(null),{onVerify:s,selectorRef:r,unitId:o,subUnitId:c,maxRangeCount:i,supportAcrossSheet:u,autoFocus:h,onChange:m,onRangeSelectorDialogVisibleChange:p,onClickOutside:f,onFocusChange:g,forceShowDialogWhenSelectionChanged:d,hideEditor:C,resetRange:_}=e,[v,E]=R.useState(h!=null?h:!1),[b,I]=R.useState(!1),[S,N]=R.useState([]),F=a.useDependency(l.LocaleService),L=a.useDependency(J.IEditorService),{sequenceNodes:U}=qr(t,v,o,c),w=Oe(U),j=a.useDependency(l.ICommandService),D=a.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),L.blur()}),M=a.useEvent(()=>{var x;D(),N(Zr((x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:"")),I(!0)});return R.useEffect(()=>{r&&(r.current={get editor(){return t},focus(){L.focus(t.getEditorId())},blur:D,verify:()=>yt(w.current),showDialog:x=>{D(),N(x),I(!0)},hideDialog:()=>{N([]),I(!1)},getValue:()=>{var x;return(x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:""}})},[D,t,L,r,w]),R.useEffect(()=>{var x;s==null||s(yt(U),(x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:"")},[U]),R.useEffect(()=>{p==null||p(b)},[b]),R.useEffect(()=>{if(b&&_)return()=>{const x={unitId:o,subUnitId:c,selections:_};j.executeCommand(A.SetSelectionsOperation.id,x)}},[b]),y.jsxs(y.Fragment,{children:[C?null:y.jsx(J.RichTextEditor,{isSingle:!0,...e,onFocusChange:(x,O)=>{E(x),g==null||g(x,O)},editorRef:n,onClickOutside:()=>{E(!1),D(),f==null||f()},icon:y.jsx(W.Tooltip,{title:F.t("rangeSelector.buttonTooltip"),placement:"bottom",children:y.jsx(Wt,{className:"univer-cursor-pointer dark:!univer-text-gray-300",onClick:M})})}),y.jsx(Gr,{initialValue:S,unitId:o,subUnitId:c,visible:b,maxRangeCount:i,onConfirm:x=>{const O=Xr(x),P=l.RichTextBuilder.newEmptyData();P.body.dataStream=O,t==null||t.replaceText(O,!1),m==null||m(P,O),I(!1),N([]),requestAnimationFrame(()=>{D()})},onClose:()=>{I(!1),N([])},supportAcrossSheet:u,onShowBySelection:x=>v||d?(N(x),I(!0),!1):!0})]})}const Qr=()=>{var s,r;const e=a.useDependency(ut),t=a.useObservable(e.currentSelector$),n=R.useRef(null);return R.useEffect(()=>{var o,c;if(t)return(c=n.current)==null||c.showDialog((o=t.initialValue)!=null?o:[]),()=>{var i;(i=n.current)==null||i.hideDialog()}},[t]),y.jsx(ht,{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,c)=>{var i;t==null||t.callback((i=c==null?void 0:c.split(",").map(u=>T.deserializeRangeWithSheet(u)))!=null?i:[])}})};var Jr=Object.defineProperty,es=Object.getOwnPropertyDescriptor,ts=(e,t,n)=>t in e?Jr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ns=(e,t,n,s)=>{for(var r=s>1?void 0:s?es(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},qe=(e,t)=>(n,s)=>t(n,s,e),Yt=(e,t,n)=>ts(e,typeof t!="symbol"?t+"":t,n);exports.UniverSheetsFormulaUIPlugin=class extends l.Plugin{constructor(t=Ct,n,s,r,o){super(),this._config=t,this._injector=n,this._renderManagerService=s,this._configService=r,this._uiPartsService=o;const{menu:c,...i}=l.merge(Ct,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig(hn,i,{merge:!0})}onStarting(){l.registerDependencies(this._injector,[[Je,{useClass:it}],[ut],[Xe],[Ye],[ze],[Ge],[Ze],[exports.FormulaReorderController]]),this._initUIPart()}onReady(){[[exports.RefSelectionsRenderService]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))})}onRendered(){[[ct]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))}),l.touchDependencies(this._injector,[[Xe],[ze],[Ze]])}onSteady(){this._injector.get(Ye),this._injector.get(exports.FormulaReorderController)}_initUIPart(){const t=this._injector.get(a.ComponentManager);this.disposeWithMe(t.register(k.RANGE_SELECTOR_COMPONENT_KEY,ht)),this.disposeWithMe(t.register(k.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,qt)),this.disposeWithMe(this._uiPartsService.registerComponent(a.BuiltInUIPart.GLOBAL,()=>a.connectInjector(Qr,this._injector)))}};Yt(exports.UniverSheetsFormulaUIPlugin,"pluginName",Mt);Yt(exports.UniverSheetsFormulaUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFormulaUIPlugin=ns([l.DependentOn(T.UniverFormulaEnginePlugin,Re.UniverSheetsFormulaPlugin),qe(1,l.Inject(l.Injector)),qe(2,B.IRenderManagerService),qe(3,l.IConfigService),qe(4,a.IUIPartsService)],exports.UniverSheetsFormulaUIPlugin);exports.FORMULA_PROMPT_ACTIVATED=Tt;exports.FormulaEditor=qt;exports.GlobalRangeSelectorService=ut;exports.HelpFunctionOperation=xt;exports.InsertFunctionOperation=de;exports.MoreFunctionsOperation=et;exports.RangeSelector=ht;exports.ReferenceAbsoluteOperation=lt;exports.SearchFunctionOperation=Nt;exports.SelectEditorFormulaOperation=xe;exports.SheetOnlyPasteFormulaCommand=Qe;
|