@univerjs/sheets-formula-ui 0.5.5 → 0.6.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/lib/cjs/index.js +19 -27
  2. package/lib/es/index.js +1982 -1940
  3. package/lib/types/commands/operations/insert-function.operation.d.ts +7 -1
  4. package/lib/types/views/FormulaPromptContainer.d.ts +16 -2
  5. package/lib/types/views/formula-editor/help-function/HelpFunction.d.ts +1 -2
  6. package/lib/types/views/formula-editor/hooks/useStateRef.d.ts +1 -1
  7. package/lib/types/views/formula-editor/index.d.ts +2 -1
  8. package/lib/types/views/formula-progress/FormulaProgress.d.ts +16 -2
  9. package/lib/types/views/more-functions/MoreFunctions.d.ts +16 -2
  10. package/lib/types/views/more-functions/function-help/FunctionHelp.d.ts +1 -2
  11. package/lib/types/views/more-functions/function-params/FunctionParams.d.ts +1 -1
  12. package/lib/types/views/more-functions/input-params/InputParams.d.ts +1 -2
  13. package/lib/types/views/more-functions/select-function/SelectFunction.d.ts +1 -2
  14. package/lib/types/views/prompt/help-function/HelpFunction.d.ts +16 -2
  15. package/lib/types/views/prompt/search-function/SearchFunction.d.ts +16 -2
  16. package/lib/types/views/range-selector/hooks/useIsFirstRender.d.ts +1 -1
  17. package/lib/types/views/range-selector/index.d.ts +2 -2
  18. package/lib/umd/index.js +21 -29
  19. package/package.json +15 -15
  20. package/lib/types/commands/operations/__tests__/create-command-test-bed.d.ts +0 -13
  21. package/lib/types/commands/operations/__tests__/insert-function.operation.spec.d.ts +0 -16
  22. package/lib/types/controllers/__tests__/create-command-test-bed.d.ts +0 -8
  23. package/lib/types/controllers/__tests__/formula-auto-fill.controller.spec.d.ts +0 -16
  24. package/lib/types/controllers/__tests__/formula-clipboard.controller.spec.d.ts +0 -16
  25. package/lib/types/controllers/__tests__/update-defined-name.controller.spec.d.ts +0 -16
  26. package/lib/types/controllers/__tests__/update-formula.controller.spec.d.ts +0 -16
  27. package/lib/types/controllers/utils/__tests__/utils.spec.d.ts +0 -16
package/lib/umd/index.js CHANGED
@@ -1,33 +1,25 @@
1
- (function(W,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/sheets-ui"),require("@univerjs/engine-formula"),require("rxjs"),require("@univerjs/docs-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-formula"),require("@univerjs/ui"),require("react"),require("@univerjs/design"),require("@univerjs/docs"),require("rxjs/operators")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-ui","@univerjs/engine-formula","rxjs","@univerjs/docs-ui","@univerjs/engine-render","@univerjs/sheets","@univerjs/sheets-formula","@univerjs/ui","react","@univerjs/design","@univerjs/docs","rxjs/operators"],r):(W=typeof globalThis<"u"?globalThis:W||self,r(W.UniverSheetsFormulaUi={},W.UniverCore,W.UniverSheetsUi,W.UniverEngineFormula,W.rxjs,W.UniverDocsUi,W.UniverEngineRender,W.UniverSheets,W.UniverSheetsFormula,W.UniverUi,W.React,W.UniverDesign,W.UniverDocs,W.rxjs.operators))})(this,function(W,r,w,N,G,te,X,K,Ne,E,f,pe,ut,Be){"use strict";var Ss=Object.defineProperty;var gs=(W,r,w)=>r in W?Ss(W,r,{enumerable:!0,configurable:!0,writable:!0,value:w}):W[r]=w;var ee=(W,r,w)=>gs(W,typeof r!="symbol"?r+"":r,w);const Je={id:"sheet.command.paste-formula",type:r.CommandType.COMMAND,handler:async e=>e.get(r.ICommandService).executeCommand(w.SheetPasteCommand.id,{value:w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA})},Pe={id:"formula-ui.operation.select-editor-formula",type:r.CommandType.OPERATION,handler:(e,t)=>!0};var Cn=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Rn=(e,t,n,s)=>{for(var o=s>1?void 0:s?In(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(s?i(t,n,o):i(o))||o);return s&&o&&Cn(t,n,o),o},En=(e,t)=>(n,s)=>t(n,s,e);const xt="FORMULA_PROMPT_ACTIVATED",Ve=r.createIdentifier("formula-ui.prompt-service");let ft=class{constructor(e){ee(this,"_search$",new G.Subject);ee(this,"_help$",new G.Subject);ee(this,"_navigate$",new G.Subject);ee(this,"_accept$",new G.Subject);ee(this,"_acceptFormulaName$",new G.Subject);ee(this,"search$",this._search$.asObservable());ee(this,"help$",this._help$.asObservable());ee(this,"navigate$",this._navigate$.asObservable());ee(this,"accept$",this._accept$.asObservable());ee(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());ee(this,"_searching",!1);ee(this,"_helping",!1);ee(this,"_sequenceNodes",[]);ee(this,"_isLockedOnSelectionChangeRefString",!1);ee(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(xt,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,o=this._sequenceNodes.length;s<o;s++){const c=this._sequenceNodes[s];if(typeof c=="string")t++;else{const{endIndex:i}=c;t=i}if(e<=t)return typeof n=="string"&&e!==0?s+1:s}return this._sequenceNodes.length}updateSequenceRef(e,t){const n=this._sequenceNodes[e];if(typeof n=="string"||n.nodeType!==N.sequenceNodeType.REFERENCE)return;const s=t.length-n.token.length,o={...n};o.token=t,o.endIndex+=s,this._sequenceNodes[e]=o;for(let c=e+1,i=this._sequenceNodes.length;c<i;c++){const a=this._sequenceNodes[c];if(typeof a=="string")continue;const l={...a};l.startIndex+=s,l.endIndex+=s,this._sequenceNodes[c]=l}}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:N.sequenceNodeType.REFERENCE});for(let o=s+1,c=this._sequenceNodes.length;o<c;o++){const i=this._sequenceNodes[o];if(typeof i=="string")continue;const a={...i};a.startIndex+=n,a.endIndex+=n,this._sequenceNodes[o]=a}}insertSequenceString(e,t){const n=this.getCurrentSequenceNodeIndex(e),s=t.split("");this._sequenceNodes.splice(n,0,...s);const o=s.length;for(let c=n+o,i=this._sequenceNodes.length;c<i;c++){const a=this._sequenceNodes[c];if(typeof a=="string")continue;const l={...a};l.startIndex+=o,l.endIndex+=o,this._sequenceNodes[c]=l}}enableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!0}disableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!1}isLockedSelectionChange(){return this._isLockedOnSelectionChangeRefString}enableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!0}disableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!1}isLockedSelectionInsert(){return this._isLockedOnSelectionInsertRefString}};ft=Rn([En(0,r.IContextService)],ft);const Ft={id:"formula-ui.operation.help-function",type:r.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ve).help(t),!0)},Qe={id:"formula-ui.operation.insert-function",type:r.CommandType.OPERATION,handler:async(e,t)=>{var C,_;const n=e.get(K.SheetsSelectionsService),s=e.get(te.IEditorService),o=n.getCurrentSelections();if(!o||!o.length)return!1;const c=K.getSheetCommandTarget(e.get(r.IUniverInstanceService));if(!c)return!1;const{worksheet:i,unitId:a,subUnitId:l}=c,m=i.getCellMatrix(),{value:d}=t,p=e.get(r.ICommandService),h=e.get(w.IEditorBridgeService),g=[];let u=null,S=0,I=0,b="";if(o.length===1&&(Tn(o[0].range)||bn(o[0].range))){const{range:T,primary:x}=o[0],F=(C=x==null?void 0:x.actualRow)!=null?C:T.startRow,P=(_=x==null?void 0:x.actualColumn)!=null?_:T.startColumn;u=T,S=F,I=P;const L=Pt(m,F,P);L&&(b=N.serializeRange(L))}else o.some(T=>{var k,y;const{range:x,primary:F}=T,P=(k=F==null?void 0:F.actualRow)!=null?k:x.startRow,L=(y=F==null?void 0:F.actualColumn)!=null?y:x.startColumn,j=Pt(m,P,L);if(!j)return u=x,S=P,I=L,!0;const O=N.serializeRange(j),M=`=${d}(${O})`;return g.push({range:x,primary:{row:P,column:L},formula:M}),!1});if(u){const T=K.getCellAtRowCol(S,I,i),x={range:r.Rectangle.clone(u),primary:{startRow:T.startRow,startColumn:T.startColumn,endRow:T.endRow,endColumn:T.endColumn,actualRow:S,actualColumn:I,isMerged:T.isMerged,isMergedMainCell:T.startRow===S&&T.startColumn===I}},F={unitId:a,subUnitId:l,selections:[x]};await p.executeCommand(K.SetSelectionsOperation.id,F);const P=s.getEditor(r.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),L=s.getEditor(r.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);h.changeVisible({visible:!0,unitId:a,eventType:X.DeviceInputEventType.Dblclick});const j=`=${d}(${b}`;P==null||P.replaceText(j),L==null||L.replaceText(j,!1)}return g.length===0?!1:p.executeCommand(Ne.InsertFunctionCommand.id,{list:g})}};function Pt(e,t,n){const s=_n(e,t,n);if(s!==t)return{startRow:s,endRow:t-1,startColumn:n,endColumn:n};const o=yn(e,t,n);return o!==n?{startRow:t,endRow:t,startColumn:o,endColumn:n-1}:null}function _n(e,t,n){let s=!1;if(t===0)return t;for(let o=t-1;o>=0;o--){const c=e.getValue(o,n);if(qe(c)&&!s){if(o===0)return 0;s=!0}else{if(s&&!qe(c))return o+1;if(s&&o===0)return 0}}return t}function yn(e,t,n){let s=!1;if(n===0)return n;for(let o=n-1;o>=0;o--){const c=e.getValue(t,o);if(qe(c)&&!s){if(o===0)return 0;s=!0}else{if(s&&!qe(c))return o+1;if(s&&o===0)return 0}}return n}function qe(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return!1;const n=t.dataStream,o=n.substring(n.length-2,n.length)===r.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n;return r.isRealNum(o)}return e&&(e.t===r.CellValueType.NUMBER||r.getCellValueType(e)===r.CellValueType.NUMBER)}function Tn(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}function bn(e){return e.startRow!==e.endRow&&e.startColumn!==e.endColumn}const At="SHEET_FORMULA_UI_PLUGIN",Lt=`${At}_MORE_FUNCTIONS_COMPONENT`,$e={id:"formula-ui.operation.more-functions",type:r.CommandType.OPERATION,handler:async e=>(e.get(E.ISidebarService).open({header:{title:"formula.insert.tooltip"},children:{label:Lt}}),!0)},dt={id:"formula-ui.operation.change-ref-to-absolute",type:r.CommandType.OPERATION,handler:async e=>!0},wt={id:"formula-ui.operation.search-function",type:r.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ve).search(t),!0)};var mt={exports:{}},Ke={};/**
2
- * @license React
3
- * react-jsx-runtime.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var kt;function Nn(){if(kt)return Ke;kt=1;var e=f,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,m){var d,p={},h=null,g=null;m!==void 0&&(h=""+m),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(g=l.ref);for(d in l)s.call(l,d)&&!c.hasOwnProperty(d)&&(p[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)p[d]===void 0&&(p[d]=l[d]);return{$$typeof:t,type:a,key:h,ref:g,props:p,_owner:o.current}}return Ke.Fragment=n,Ke.jsx=i,Ke.jsxs=i,Ke}var jt;function Mn(){return jt||(jt=1,mt.exports=Nn()),mt.exports}var v=Mn(),Se=function(){return Se=Object.assign||function(e){for(var t,n=1,s=arguments.length;n<s;n++){t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},Se.apply(this,arguments)},On=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 o=0,s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]]);return n},Me=f.forwardRef(function(e,t){var n=e.icon,s=e.id,o=e.className,c=e.extend,i=On(e,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(s," ").concat(o||"").trim(),l=f.useRef("_".concat(Fn()));return Ht(n,"".concat(s),{defIds:n.defIds,idSuffix:l.current},Se({ref:t,className:a},i),c)});function Ht(e,t,n,s,o){return f.createElement(e.tag,Se(Se({key:t},Dn(e,n,o)),s),(xn(e,n).children||[]).map(function(c,i){return Ht(c,"".concat(t,"-").concat(e.tag,"-").concat(i),n,void 0,o)}))}function Dn(e,t,n){var s=Se({},e.attrs);n!=null&&n.colorChannel1&&s.fill==="colorChannel1"&&(s.fill=n.colorChannel1);var o=t.defIds;return!o||o.length===0||(e.tag==="use"&&s["xlink:href"]&&(s["xlink:href"]=s["xlink:href"]+t.idSuffix),Object.entries(s).forEach(function(c){var i=c[0],a=c[1];typeof a=="string"&&(s[i]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),s}function xn(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)?Se(Se({},e),{children:e.children.map(function(o){return typeof o.attrs.id=="string"&&s&&s.indexOf(o.attrs.id)>-1?Se(Se({},o),{attrs:Se(Se({},o.attrs),{id:o.attrs.id+t.idSuffix})}):o})}):e}function Fn(){return Math.random().toString(36).substring(2,8)}Me.displayName="UniverIcon";var Pn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Wt=f.forwardRef(function(e,t){return f.createElement(Me,Object.assign({},e,{id:"check-mark-single",ref:t,icon:Pn}))});Wt.displayName="CheckMarkSingle";var An={tag:"svg",attrs:{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"}}]},et=f.forwardRef(function(e,t){return f.createElement(Me,Object.assign({},e,{id:"close-single",ref:t,icon:An}))});et.displayName="CloseSingle";var Ln={tag:"svg",attrs:{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.866699 5.9313.866699H10.069C10.4004.866699 10.669 1.13533 10.669 1.4667 10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667zM1.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.64443 14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443zM6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928 9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171 10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778 9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539 9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263 6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539 5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778 6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Bt=f.forwardRef(function(e,t){return f.createElement(Me,Object.assign({},e,{id:"delete-single",ref:t,icon:Ln}))});Bt.displayName="DeleteSingle";var wn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.75 5.32495C8.75 5.73916 8.41421 6.07495 8 6.07495 7.58579 6.07495 7.25 5.73916 7.25 5.32495 7.25 4.91074 7.58579 4.57495 8 4.57495 8.41421 4.57495 8.75 4.91074 8.75 5.32495zM8.5999 7.52505C8.5999 7.19368 8.33127 6.92505 7.9999 6.92505 7.66853 6.92505 7.3999 7.19368 7.3999 7.52505V11.425C7.3999 11.7564 7.66853 12.025 7.9999 12.025 8.33127 12.025 8.5999 11.7564 8.5999 11.425V7.52505z"}},{tag:"path",attrs:{fill:"currentColor",d:"M0.899902 8.00002C0.899902 4.0788 4.07868 0.900024 7.9999 0.900024C11.9211 0.900024 15.0999 4.0788 15.0999 8.00002C15.0999 11.9212 11.9211 15.1 7.9999 15.1C4.07868 15.1 0.899902 11.9212 0.899902 8.00002ZM7.9999 2.10002C4.74142 2.10002 2.0999 4.74154 2.0999 8.00002C2.0999 11.2585 4.74142 13.9 7.9999 13.9C11.2584 13.9 13.8999 11.2585 13.8999 8.00002C13.8999 4.74154 11.2584 2.10002 7.9999 2.10002Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Vt=f.forwardRef(function(e,t){return f.createElement(Me,Object.assign({},e,{id:"details-single",ref:t,icon:wn}))});Vt.displayName="DetailsSingle";var kn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},Kt=f.forwardRef(function(e,t){return f.createElement(Me,Object.assign({},e,{id:"increase-single",ref:t,icon:kn}))});Kt.displayName="IncreaseSingle";var jn={tag:"svg",attrs:{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"}}]},ht=f.forwardRef(function(e,t){return f.createElement(Me,Object.assign({},e,{id:"more-single",ref:t,icon:jn}))});ht.displayName="MoreSingle";var Hn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6185 12.4423C12.5907 12.2749 12.7773 12.15 12.9343 12.2308L15.4242 13.5126C15.6102 13.6084 15.5544 13.8745 15.3439 13.8955L14.2456 14.184L13.4521 15.1286C13.3495 15.2939 13.085 15.2463 13.0534 15.0568L12.6185 12.4423Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1 3.6C1 2.16406 2.16406 1 3.6 1H12.3C13.7359 1 14.9 2.16406 14.9 3.6V5.81156C14.9003 5.81881 14.9004 5.82609 14.9004 5.8334C14.9004 5.84071 14.9003 5.84799 14.9 5.85524V10.045C14.9003 10.0522 14.9004 10.0595 14.9004 10.0668C14.9004 10.3982 14.6318 10.6668 14.3004 10.6668H11.1668C10.8907 10.6668 10.6668 10.8907 10.6668 11.1668V14.3C10.6668 14.6314 10.3982 14.9 10.0668 14.9L10.05 14.8998L3.6 14.9C2.16406 14.9 1 13.7359 1 12.3V3.6ZM13.2 5.2334C13.4761 5.2334 13.7 5.00954 13.7 4.7334V3.6C13.7 2.8268 13.0732 2.2 12.3 2.2H11.1668C10.8907 2.2 10.6668 2.42386 10.6668 2.7V4.7334C10.6668 5.00954 10.8907 5.2334 11.1668 5.2334H13.2ZM10.6668 6.9334C10.6668 6.65726 10.8907 6.4334 11.1668 6.4334H13.2C13.4761 6.4334 13.7 6.65726 13.7 6.9334V8.9668C13.7 9.24294 13.4761 9.4668 13.2 9.4668H11.1668C10.8907 9.4668 10.6668 9.24294 10.6668 8.9668V6.9334ZM8.9668 5.2334C9.24294 5.2334 9.4668 5.00954 9.4668 4.7334V2.7C9.4668 2.42386 9.24294 2.2 8.9668 2.2H6.9334C6.65726 2.2 6.4334 2.42386 6.4334 2.7V4.7334C6.4334 5.00954 6.65726 5.2334 6.9334 5.2334L8.9668 5.2334ZM6.4334 6.9334C6.4334 6.65726 6.65726 6.4334 6.9334 6.4334L8.9668 6.4334C9.24294 6.4334 9.4668 6.65726 9.4668 6.9334V8.9668C9.4668 9.24294 9.24294 9.4668 8.9668 9.4668L6.9334 9.4668C6.65726 9.4668 6.4334 9.24294 6.4334 8.9668V6.9334ZM4.7334 5.2334C5.00954 5.2334 5.2334 5.00954 5.2334 4.7334V2.7C5.2334 2.42386 5.00954 2.2 4.7334 2.2H3.6C2.8268 2.2 2.2 2.8268 2.2 3.6V4.7334C2.2 5.00954 2.42386 5.2334 2.7 5.2334H4.7334ZM2.2 6.9334C2.2 6.65726 2.42386 6.4334 2.7 6.4334H4.7334C5.00954 6.4334 5.2334 6.65725 5.2334 6.9334V8.9668C5.2334 9.24294 5.00954 9.4668 4.7334 9.4668H2.7C2.42386 9.4668 2.2 9.24294 2.2 8.9668V6.9334ZM5.2334 11.1668C5.2334 10.8907 5.00954 10.6668 4.7334 10.6668H2.7C2.42386 10.6668 2.2 10.8907 2.2 11.1668V12.3C2.2 13.0732 2.8268 13.7 3.6 13.7H4.7334C5.00954 13.7 5.2334 13.4761 5.2334 13.2V11.1668ZM9.4668 11.1668C9.4668 10.8907 9.24294 10.6668 8.9668 10.6668H6.9334C6.65726 10.6668 6.4334 10.8907 6.4334 11.1668V13.2C6.4334 13.4761 6.65726 13.7 6.9334 13.7H8.9668C9.24294 13.7 9.4668 13.4761 9.4668 13.2V11.1668Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ut=f.forwardRef(function(e,t){return f.createElement(Me,Object.assign({},e,{id:"select-range-single",ref:t,icon:Hn}))});Ut.displayName="SelectRangeSingle";function Yt(e){var t,n,s="";if(typeof e=="string"||typeof e=="number")s+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(n=Yt(e[t]))&&(s&&(s+=" "),s+=n)}else for(n in e)e[n]&&(s&&(s+=" "),s+=n);return s}function pt(){for(var e,t,n=0,s="",o=arguments.length;n<o;n++)(e=arguments[n])&&(t=Yt(e))&&(s&&(s+=" "),s+=t);return s}var Wn=Object.defineProperty,Bn=Object.getOwnPropertyDescriptor,Vn=(e,t,n,s)=>{for(var o=s>1?void 0:s?Bn(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(s?i(t,n,o):i(o))||o);return s&&o&&Wn(t,n,o),o},we=(e,t)=>(n,s)=>t(n,s,e);W.RefSelectionsRenderService=class extends w.BaseSelectionRenderService{constructor(n,s,o,c,i,a,l){super(s,o,c,i,a);ee(this,"_workbookSelections");ee(this,"_eventDisposables");this._context=n,this._contextService=a,this._refSelectionsService=l,this._workbookSelections=this._refSelectionsService.getWorkbookSelections(this._context.unitId),this._initSelectionChangeListener(),this._initSkeletonChangeListener(),this._initUserActionSyncListener(),this._setSelectionStyle(Kn(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(),r.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:o,spreadsheet:c,spreadsheetLeftTopPlaceholder:i}=n,{scene:a}=this._context,l=new r.DisposableCollection;return l.add(c==null?void 0:c.onPointerDown$.subscribeEvent((m,d)=>{this.inRefSelectionMode()&&(this._onPointerDown(m,c.zIndex+1,r.RANGE_TYPE.NORMAL,this._getActiveViewport(m)),m.button!==2&&d.stopPropagation())})),l.add(s==null?void 0:s.onPointerDown$.subscribeEvent((m,d)=>{if(!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:h}=w.getCoordByOffset(m.offsetX,m.offsetY,a,p);w.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,r.RANGE_TYPE.ROW)||(this._onPointerDown(m,(c.zIndex||1)+1,r.RANGE_TYPE.ROW,this._getActiveViewport(m),X.ScrollTimerType.Y),m.button!==2&&d.stopPropagation())})),l.add(o==null?void 0:o.onPointerDown$.subscribeEvent((m,d)=>{if(!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:h}=w.getCoordByOffset(m.offsetX,m.offsetY,a,p);w.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,r.RANGE_TYPE.COLUMN)||(this._onPointerDown(m,(c.zIndex||1)+1,r.RANGE_TYPE.COLUMN,this._getActiveViewport(m),X.ScrollTimerType.X),m.button!==2&&d.stopPropagation())})),l.add(i==null?void 0:i.onPointerDown$.subscribeEvent((m,d)=>{if(this._reset(),!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,h=w.getAllSelection(p);this._addSelectionControlByModelData(h),this._selectionMoveStart$.next(this.getSelectionDataWithStyle());const g=a.onPointerUp$.subscribeEvent(()=>{g.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});m.button!==2&&d.stopPropagation()})),l}_addSelectionControlByModelData(n){var a;const s=this._skeleton,o=(a=n.style)!=null?a:w.genNormalSelectionStyle(this._themeService),c=this._scene;return n.style=o,this.newSelectionControl(c,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,K.SelectionMoveType.MOVE_START)})),this.disposeWithMe(this.selectionMoving$.subscribe(n=>{this._updateSelections(n,K.SelectionMoveType.MOVING)})),this.disposeWithMe(this.selectionMoveEnd$.subscribe(n=>{this._updateSelections(n,K.SelectionMoveType.MOVE_END)}))}_updateSelections(n,s){const c=this._context.unit.getActiveSheet().getSheetId();n.length!==0&&this._workbookSelections.setSelections(c,n.map(i=>K.convertSelectionDataToRange(i)),s)}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(n=>{if(!n)return;const{skeleton:s}=n,{scene:o}=this._context,c=o.getViewport(X.SHEET_VIEWPORT_KEY.VIEW_MAIN);this._skeleton&&this._skeleton.worksheet.getSheetId()!==s.worksheet.getSheetId()&&this._reset(),this._changeRuntime(s,o,c);const i=this._workbookSelections.getCurrentSelections();this.resetSelectionsByModelData(i)}))}_getActiveViewport(n){const s=this._getSheetObject();return s==null?void 0:s.scene.getActiveViewportByCoord(X.Vector2.FromArray([n.offsetX,n.offsetY]))}_getSheetObject(){return w.getSheetObject(this._context.unit,this._context)}_onPointerDown(n,s=0,o=r.RANGE_TYPE.NORMAL,c,i=X.ScrollTimerType.ALL){var M;this._rangeType=o;const a=this._skeleton,l=this._scene;if(!l||!a)return;c&&(this._activeViewport=c);const{offsetX:m,offsetY:d}=n,p=l.getViewport(X.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!p)return;const h=l.getCoordRelativeToViewport(X.Vector2.FromArray([m,d])),{x:g,y:u}=h;this._startViewportPosX=g,this._startViewportPosY=u;const S=l.getScrollXYInfoByViewport(h),{scaleX:I,scaleY:b}=l.getAncestorScale(),C=this._skeleton.getCellByOffset(g,u,I,b,S);if(!C)return;switch(o){case r.RANGE_TYPE.NORMAL:break;case r.RANGE_TYPE.ROW:C.startColumn=0,C.endColumn=this._skeleton.getColumnCount()-1;break;case r.RANGE_TYPE.COLUMN:C.startRow=0,C.endRow=this._skeleton.getRowCount()-1;break;case r.RANGE_TYPE.ALL:C.startRow=0,C.startColumn=0,C.endRow=this._skeleton.getRowCount()-1,C.endColumn=this._skeleton.getColumnCount()-1}const _={range:C,primary:C,style:null};_.range.rangeType=o;const T=w.attachSelectionWithCoord(_,this._skeleton);this._startRangeWhenPointerDown={...T.rangeWithCoord};const x={...T.rangeWithCoord,rangeType:o};let F=this.getActiveSelectionControl();const P=this.getSelectionControls();for(const k of P){if(n.button===2&&k.model.isInclude(x)){F=k;return}if(k.model.isEqual(x)){F=k;break}}this._checkClearPreviousControls(n);const L=F==null?void 0:F.model.currentCell,j=n.shiftKey&&L,O=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;j&&L?this._makeSelectionByTwoCells(L,x,a,o,F):O&&F?F.updateRangeBySelectionWithCoord(T):F=this.newSelectionControl(l,a,_);for(let k=0;k<this.getSelectionControls().length-1;k++)this.getSelectionControls()[k].clearHighlight();this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),l.disableObjectsEvent(),this._clearUpdatingListeners(),this._addEndingListeners(),(M=l.getTransformer())==null||M.clearSelectedObjects(),this._setupPointerMoveListener(p,F,o,i,g,u),this._escapeShortcutDisposable=this._shortcutService.forceEscape(),this._scenePointerUpSub=l.onPointerUp$.subscribeEvent(()=>{var k;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(k=this._escapeShortcutDisposable)==null||k.dispose(),this._escapeShortcutDisposable=null})}newSelectionControl(n,s,o){const c=this.getSelectionControls().length,{rowHeaderWidth:i,columnHeaderHeight:a}=s,l=new w.SelectionControl(n,c,this._themeService,{highlightHeader:this._highlightHeader,enableAutoFill:!1,rowHeaderWidth:i,columnHeaderHeight:a}),m=w.attachSelectionWithCoord(o,s);return l.updateRangeBySelectionWithCoord(m),this._selectionControls.push(l),l.setControlExtension({skeleton:s,scene:n,themeService:this._themeService,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),l}},W.RefSelectionsRenderService=Vn([we(1,r.Inject(r.Injector)),we(2,r.Inject(r.ThemeService)),we(3,E.IShortcutService),we(4,r.Inject(w.SheetSkeletonManagerService)),we(5,r.IContextService),we(6,K.IRefSelectionsService)],W.RefSelectionsRenderService);function Kn(e){const t=w.genNormalSelectionStyle(e);return t.widgets={tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},t}const Un=(e,t,n)=>{const o=r.useDependency(X.IRenderManagerService).getRenderById(e),c=o==null?void 0:o.with(W.RefSelectionsRenderService);f.useEffect(()=>{if(n&&c){const i=n.input$.subscribe(a=>{a.content===N.matchToken.COMMA?c.setSkipLastEnabled(!0):c.setSkipLastEnabled(!1)});return()=>{i.unsubscribe()}}},[n,c]),f.useEffect(()=>{c&&(t.endsWith(N.matchToken.COMMA)||c.setSkipLastEnabled(!1))},[t,c])},tt=()=>{const e=r.useDependency(N.LexerTreeBuilder);return f.useCallback(n=>e.sequenceNodesBuilder(n)||[],[e])},Yn=(e,t,n,s,o,c)=>{const i=tt(),a=f.useRef(!0);f.useEffect(()=>{var l,m;if(c){if(a.current){const d=i(e);if(d.length){const p=s(c,d);n&&o(p)}else{const p=c.getDocumentData(),g={dataStream:(m=(l=p.body)==null?void 0:l.dataStream)!=null?m:`${t}\r
10
- `,...p.body};c.setDocumentData({...p,body:g})}a.current=!1}else if(n){const d=i(e),p=s(c,d);o(p)}}},[c,n])},zt=e=>E.useEvent(n=>{var s,o;if(e){e.focus();const c=[...e.getSelectionRanges()];if(r.Tools.isDefine(n))e.setSelectionRanges([{startOffset:n,endOffset:n}]);else if(!c.length&&!e.docSelectionRenderService.isOnPointerEvent){const i=(o=(s=e.getDocumentData().body)==null?void 0:s.dataStream)!=null?o:`\r
11
- `,a=Math.max(i.length-2,0);e.setSelectionRanges([{startOffset:a,endOffset:a}])}}});function zn(e,t,n){const s=e.getCurrentTheme(),o=new r.ColorKit(t).setAlpha(.05).toRgbString();return{id:n,strokeWidth:1,stroke:t,fill:o,widgets:{tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},widgetSize:6,widgetStrokeWidth:1,widgetStroke:s.colorWhite}}function Gt(e){var b,C,_;const{unitId:t,subUnitId:n,refSelections:s,editor:o,refSelectionsService:c,refSelectionsRenderService:i,sheetSkeletonManagerService:a,themeService:l,univerInstanceService:m}=e,d=m.getUnit(t,r.UniverInstanceType.UNIVER_SHEET),p=d==null?void 0:d.getActiveSheet(),h=[];if(!d||!p){c.setSelections(h);return}const g=p.getSheetId(),u=T=>{var x;return(x=d==null?void 0:d.getSheetBySheetName(T))==null?void 0:x.getSheetId()};if(!((b=a==null?void 0:a.getWorksheetSkeleton(g))==null?void 0:b.skeleton))return;const I=[];for(let T=0,x=s.length;T<x;T++){const F=s[T],{themeColor:P,token:L,refIndex:j,endIndex:O}=F,M=N.deserializeRangeWithSheet(L),{unitId:k,sheetName:y,range:R}=M;if(k&&t!==k)continue;const D=u(y);if(D&&D!==g||!D&&g!==n)continue;const A=K.setEndForRange(R,p.getRowCount(),p.getColumnCount());h.push({range:A,primary:null,style:zn(l,P,j.toString())}),I.push(O)}if(o){const T=(_=(C=o.getSelectionRanges())==null?void 0:C[0])==null?void 0:_.startOffset,x=I.findIndex(F=>F+2===T);x!==-1?i==null||i.setActiveSelectionIndex(x):i==null||i.resetActiveSelectionIndex()}return h}function St(e,t){const n=r.useDependency(r.IUniverInstanceService),s=r.useDependency(r.ThemeService),o=r.useDependency(K.IRefSelectionsService),i=r.useDependency(X.IRenderManagerService).getRenderById(e),a=i==null?void 0:i.with(W.RefSelectionsRenderService),l=i==null?void 0:i.with(w.SheetSkeletonManagerService),m=f.useCallback((d,p)=>{const h=Gt({unitId:e,subUnitId:t,refSelections:d,editor:p,refSelectionsService:o,refSelectionsRenderService:a,sheetSkeletonManagerService:l,themeService:s,univerInstanceService:n});if(!h)return;((a==null?void 0:a.getSelectionControls())||[]).length===h.length?a==null||a.resetSelectionsByModelData(h):o.setSelections(h)},[a,o,l,s,e,t,n]);return f.useEffect(()=>()=>{a==null||a.resetActiveSelectionIndex()},[a]),m}function Zt(e=""){const t=r.useDependency(Ne.IDescriptionService),n=Xt(),s=r.useDependency(r.ICommandService),o=f.useMemo(()=>e.length,[e]);return f.useCallback((i,a,l=!0,m)=>{const d=i.getDocumentData(),p=i.getEditorId();if(!d)return[];const h=d.body;if(!h)return[];const g=h.dataStream.slice(0,h.dataStream.length-2),u={dataStream:"",...d.body};if(!g.startsWith(e))return[];if(a==null||a.length===0)return u.textRuns=[],s.syncExecuteCommand(te.ReplaceTextRunsCommand.id,{unitId:p,body:r.getBodySlice(u,0,u.dataStream.length-2)}),[];{const{textRuns:S,refSelections:I}=Jt(t,n,a);o&&S.forEach(_=>{_.ed=_.ed+o,_.st=_.st+o}),u.textRuns=[{st:0,ed:1,ts:{fs:11}},...S];const b=a.reduce((_,T)=>typeof T=="string"?`${_}${T}`:`${_}${T.token}`,"");u.dataStream=`${e}${b}\r
12
- `;let C;if(l){C=i.getSelectionRanges();const _=u.dataStream.length-2+o;C.forEach(T=>{T.startOffset=Math.max(0,Math.min(T.startOffset,_)),T.endOffset=Math.max(0,Math.min(T.endOffset,_))})}return s.syncExecuteCommand(te.ReplaceTextRunsCommand.id,{unitId:p,body:r.getBodySlice(u,0,u.dataStream.length-2),textRanges:m!=null?m:C}),I}},[s,t,n,o,e])}function Xt(){const t=r.useDependency(r.ThemeService).getCurrentTheme();return f.useMemo(()=>{const s=[t.loopColor1,t.loopColor2,t.loopColor3,t.loopColor4,t.loopColor5,t.loopColor6,t.loopColor7,t.loopColor8,t.loopColor9,t.loopColor10,t.loopColor11,t.loopColor12],o=t.hyacinth700,c=t.verdancy800,i=t.colorBlack;return{formulaRefColors:s,numberColor:o,stringColor:c,plainTextColor:i}},[t])}function Jt(e,t,n){const{formulaRefColors:s,numberColor:o,stringColor:c,plainTextColor:i}=t,a=[],l=[],m=new Map;let d=0;for(let p=0,h=n.length;p<h;p++){const g=n[p];if(typeof g=="string"){const _=a[a.length-1],T=_?_.ed:0,x=T+g.length;a.push({st:T,ed:x,ts:{cl:{rgb:i},fs:11}});continue}if(e.hasDefinedNameDescription(g.token.trim())){a.push({st:g.startIndex,ed:g.endIndex+1,ts:{cl:{rgb:i},fs:11}});continue}const{startIndex:u,endIndex:S,nodeType:I,token:b}=g;let C="";if(I===N.sequenceNodeType.REFERENCE){if(m.has(b))C=m.get(b);else{const _=d%s.length;C=s[_],m.set(b,C),d++}l.push({refIndex:p,themeColor:C,token:b,startIndex:g.startIndex,endIndex:g.endIndex,index:l.length})}else I===N.sequenceNodeType.NUMBER?C=o:(I===N.sequenceNodeType.STRING||I===N.sequenceNodeType.ARRAY)&&(C=c);C&&C.length>0?a.push({st:u,ed:S+1,ts:{cl:{rgb:C},fs:11}}):a.push({st:u,ed:S+1,ts:{cl:{rgb:i},fs:11}})}return{textRuns:a,refSelections:l}}function Gn(e){var o,c;const n=e.get(r.IUniverInstanceService).getCurrentUniverDocInstance();return n!=null&&n.getBody()?{dataStream:(c=(o=n.getBody())==null?void 0:o.dataStream)!=null?c:"",offset:0}:void 0}var nt=(e=>(e[e.NOT_SELECT=0]="NOT_SELECT",e[e.NEED_ADD=1]="NEED_ADD",e[e.CAN_EDIT=2]="CAN_EDIT",e))(nt||{});function Zn(e,t,n){var g;const o=r.useDependency(X.IRenderManagerService).getRenderById(e),c=o==null?void 0:o.with(te.DocSelectionRenderService),i=r.useDependency(ut.DocSelectionManagerService),a=r.useDependency(r.Injector),[l,m]=f.useState(0),d=r.useDependency(N.LexerTreeBuilder),p=f.useRef(!0),h=f.useRef(l);return h.current=l,f.useEffect(()=>{const u=i.textSelection$.pipe(G.filter(S=>S.unitId===e),G.map(()=>{const S=c==null?void 0:c.getActiveTextRange();return S!=null&&S.collapsed?S.startOffset:-1})).subscribe(S=>{var L,j;const I=Gn(a);if(!I)return;const b=(L=I==null?void 0:I.dataStream)==null?void 0:L.slice(0,-2),C=(j=d.sequenceNodesBuilder(b))!=null?j:[],_=b[S-1],T=b[S],x=C.findIndex(O=>typeof O=="object"&&O.nodeType===N.sequenceNodeType.REFERENCE&&S===O.endIndex+2),F=_&&N.matchRefDrawToken(_)&&(!T||N.isFormulaLexerToken(T)&&T!==N.matchToken.OPEN_BRACKET),P=x>-1;if((b==null?void 0:b.substring(0,1))==="="&&(F||P))if(P){if(p.current)return;m(2)}else p.current=!1,m(1);else m(0)});return()=>u.unsubscribe()},[i.textSelection$,c,e,a,d]),f.useEffect(()=>{t||(m(0),p.current=!0)},[t]),f.useEffect(()=>{var S;if(!n)return;const u=(S=o==null?void 0:o.mainComponent)==null?void 0:S.onPointerDown$.subscribeEvent(()=>{m(0),p.current=!0});return()=>u==null?void 0:u.unsubscribe()},[n,(g=o==null?void 0:o.mainComponent)==null?void 0:g.onPointerDown$]),{isSelecting:l}}const Qt=(e,t,n,s)=>{const o=r.useDependency(r.ICommandService),c=r.useDependency(E.IShortcutService),i=f.useRef(t);i.current=t;const a=f.useRef(s);a.current=s,f.useEffect(()=>{if(!n||!e)return;const m=`sheet.formula-embedding-editor.${n.getEditorId()}`,d=new r.DisposableCollection,p=(u,S)=>{if(a.current){a.current(u,S);return}let I=r.Direction.LEFT;u===E.KeyCode.ARROW_DOWN?I=r.Direction.DOWN:u===E.KeyCode.ARROW_UP?I=r.Direction.UP:u===E.KeyCode.ARROW_RIGHT&&(I=r.Direction.RIGHT),S===E.MetaKeys.SHIFT?o.executeCommand(te.MoveSelectionOperation.id,{direction:I}):o.executeCommand(te.MoveCursorOperation.id,{direction:I})},h=(u,S)=>{let I=r.Direction.DOWN;u===E.KeyCode.ARROW_DOWN?I=r.Direction.DOWN:u===E.KeyCode.ARROW_UP?I=r.Direction.UP:u===E.KeyCode.ARROW_LEFT?I=r.Direction.LEFT:u===E.KeyCode.ARROW_RIGHT&&(I=r.Direction.RIGHT),i.current?S===E.MetaKeys.CTRL_COMMAND?o.executeCommand(w.MoveSelectionCommand.id,{direction:I,jumpOver:w.JumpOver.moveGap,extra:"formula-editor",fromCurrentSelection:i.current===nt.NEED_ADD}):S===E.MetaKeys.SHIFT?o.executeCommand(w.ExpandSelectionCommand.id,{direction:I,extra:"formula-editor"}):S===(E.MetaKeys.CTRL_COMMAND|E.MetaKeys.SHIFT)?o.executeCommand(w.ExpandSelectionCommand.id,{direction:I,jumpOver:w.JumpOver.moveGap,extra:"formula-editor"}):o.executeCommand(w.MoveSelectionCommand.id,{direction:I,extra:"formula-editor",fromCurrentSelection:i.current===nt.NEED_ADD}):p(u,S)};return d.add(o.registerCommand({id:m,type:r.CommandType.OPERATION,handler(u,S){const{keyCode:I,metaKey:b}=S;h(I,b)}})),[{keyCode:E.KeyCode.ARROW_DOWN},{keyCode:E.KeyCode.ARROW_LEFT},{keyCode:E.KeyCode.ARROW_RIGHT},{keyCode:E.KeyCode.ARROW_UP},{keyCode:E.KeyCode.ARROW_DOWN,metaKey:E.MetaKeys.SHIFT},{keyCode:E.KeyCode.ARROW_LEFT,metaKey:E.MetaKeys.SHIFT},{keyCode:E.KeyCode.ARROW_RIGHT,metaKey:E.MetaKeys.SHIFT},{keyCode:E.KeyCode.ARROW_UP,metaKey:E.MetaKeys.SHIFT},{keyCode:E.KeyCode.ARROW_DOWN,metaKey:E.MetaKeys.CTRL_COMMAND},{keyCode:E.KeyCode.ARROW_LEFT,metaKey:E.MetaKeys.CTRL_COMMAND},{keyCode:E.KeyCode.ARROW_RIGHT,metaKey:E.MetaKeys.CTRL_COMMAND},{keyCode:E.KeyCode.ARROW_UP,metaKey:E.MetaKeys.CTRL_COMMAND},{keyCode:E.KeyCode.ARROW_DOWN,metaKey:E.MetaKeys.CTRL_COMMAND|E.MetaKeys.SHIFT},{keyCode:E.KeyCode.ARROW_LEFT,metaKey:E.MetaKeys.CTRL_COMMAND|E.MetaKeys.SHIFT},{keyCode:E.KeyCode.ARROW_RIGHT,metaKey:E.MetaKeys.CTRL_COMMAND|E.MetaKeys.SHIFT},{keyCode:E.KeyCode.ARROW_UP,metaKey:E.MetaKeys.CTRL_COMMAND|E.MetaKeys.SHIFT}].map(({keyCode:u,metaKey:S})=>({id:m,binding:S?u|S:u,preconditions:()=>!0,priority:900,staticParameters:{eventType:X.DeviceInputEventType.Keyboard,keyCode:u,metaKey:S}})).forEach(u=>{d.add(c.registerShortcut(u))}),()=>{d.dispose()}},[o,n,e,c])},qt=(e,t)=>{const s=r.useDependency(X.IRenderManagerService).getRenderById(e),o=s==null?void 0:s.with(W.RefSelectionsRenderService);f.useEffect(()=>{o&&(t?o==null||o.setRemainLastEnabled(!1):o==null||o.setRemainLastEnabled(!0))},[t,o])},gt=(e,t,n,s=!0)=>{const o=r.useDependency(X.IRenderManagerService),c=r.useDependency(r.IContextService),i=r.useDependency(E.IContextMenuService),a=r.useDependency(K.IRefSelectionsService),l=o.getRenderById(n),m=l==null?void 0:l.with(W.RefSelectionsRenderService);f.useLayoutEffect(()=>{if(e)return c.setContextValue(r.EDITOR_ACTIVATED,!0),()=>{c.setContextValue(r.EDITOR_ACTIVATED,!1),a.clear()}},[c,e,a]),f.useLayoutEffect(()=>{if(e&&t){const d=m==null?void 0:m.enableSelectionChanging();return c.setContextValue(K.REF_SELECTIONS_ENABLED,!0),()=>{c.setContextValue(K.REF_SELECTIONS_ENABLED,!1),d==null||d.dispose()}}},[c,e,m,t]),f.useEffect(()=>{if(e)return c.setContextValue(r.EDITOR_ACTIVATED,!0),s&&i.disable(),()=>{c.setContextValue(r.EDITOR_ACTIVATED,!1),s&&i.enable()}},[i,c,e,s]),f.useEffect(()=>{e&&(m==null||m.setSkipLastEnabled(!1))},[e,m])},Xn=()=>{f.useEffect(()=>()=>{},[])},$t=(e,t,n)=>{const s=r.useDependency(r.IUniverInstanceService),o=r.useDependency(K.SheetsSelectionsService);return f.useCallback(()=>{if(e){const i=[...o.getWorkbookSelections(t).getSelectionsOfWorksheet(n)],a=s.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET),l=a==null?void 0:a.getActiveSheet();l&&l.getSheetId()===n&&o.setSelections(i)}},[e,o,n,t,s])},vt=e=>typeof e=="string"?e===N.matchToken.COMMA:!1,Jn=e=>{if(typeof e=="object")return e.nodeType===N.sequenceNodeType.REFERENCE},Qn=e=>e.filter(t=>vt(t)||Jn(t)),Ct=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},_e=e=>e.map(t=>typeof t=="string"?t:t.token).join("");function en(e,t,n){var s,o;return((o=(s=e.getUnit(t))==null?void 0:s.getSheetBySheetId(n))==null?void 0:o.getName())||""}const Ie=(e,t=!1,n="")=>t?e.map(s=>s.sheetName!==""&&s.sheetName!==n?N.serializeRangeWithSheet(s.sheetName,s.range):N.serializeRange(s.range)):e.map(s=>N.serializeRange(s.range)),tn=(e,t,n,s,o,c,i)=>{const a=r.useDependency(X.IRenderManagerService),l=r.useDependency(r.IUniverInstanceService),m=f.useRef(!1),d=a.getRenderById(t),p=d==null?void 0:d.with(W.RefSelectionsRenderService),h=f.useRef([]),g=f.useMemo(()=>{const S=Qn(s),I=h.current;return S.length===I.length?(I.splice(0),I.push(...S),I):S},[s]);h.current=g;const u=f.useRef();f.useEffect(()=>{if(e&&p){let S=!0;const I=(_,T)=>{var y;if(S||m.current){S=!1;return}const x=[..._],F=l.getUnit(t),P=((y=F==null?void 0:F.getActiveSheet())==null?void 0:y.getName())||"",L=g.map((R,D)=>{if(typeof R=="string"){if(!g[D-1])return null;const H=g[D+1];return vt(R)&&(vt(H)||D===g.length-1)?null:R}else if(R.nodeType===N.sequenceNodeType.REFERENCE){const A=N.deserializeRangeWithSheet(R.token);A.unitId=A.unitId===""?t:A.unitId,A.sheetName=A.sheetName===""?P:A.sheetName;const{unitId:H,sheetName:Z}=A;if(c&&(H!==t||P!==Z))return null;if(H===t&&P===Z){const J=x.shift();if(J&&en(l,t,J.rangeWithCoord.sheetId||"")===Z){const z={...R};return Ct(J.rangeWithCoord),o?z.token=N.serializeRangeWithSheet(P,J.rangeWithCoord):z.token=N.serializeRange(J.rangeWithCoord),z}}return R}return null}).filter(R=>!!R),j=Ie(x.map(R=>{var D,A,H;return{range:R.rangeWithCoord,unitId:(D=R.rangeWithCoord.unitId)!=null?D:"",sheetName:en(l,(A=R.rangeWithCoord.unitId)!=null?A:"",(H=R.rangeWithCoord.sheetId)!=null?H:"")}}),o).join(N.matchToken.COMMA),O=_e(L),M=`${O}${O&&j?N.matchToken.COMMA:""}${j}`,k=m.current;i(M,k?-1:M.length,T)},b=p.selectionMoveEnd$.subscribe(_=>{if(I(_,!0),m.current=!1,u.current){const{result:T,offset:x}=u.current;i(T,x,!0),u.current=void 0}}),C=p.selectionMoving$.pipe(Be.throttleTime(50)).subscribe(_=>{I(_,!1)});return()=>{b.unsubscribe(),C.unsubscribe()}}},[e,g,p,o,c,i,l,t]),f.useEffect(()=>{if(e&&p){const S=new r.DisposableCollection,I=(_,T)=>{var k;let x=0,F=0,P=!1;const L=l.getUnit(t),j=((k=L==null?void 0:L.getActiveSheet())==null?void 0:k.getName())||"",O=g.map(y=>{if(typeof y=="string")return P||(F+=y.length),y;if(y.nodeType===N.sequenceNodeType.REFERENCE){const R=N.deserializeRangeWithSheet(_);if(R.unitId=R.unitId===""?t:R.unitId,R.sheetName=R.sheetName===""?j:R.sheetName,x===T){P=!0;const D={...y,token:_};return o?D.token=N.serializeRangeWithSheet(R.sheetName,R.range):D.token=N.serializeRange(R.range),x++,F+=D.token.length,D}return x++,P||(F+=y.token.length),y}return y}),M=_e(O);u.current={result:M,offset:F},i(M,-1,!1)};let b=0;const C=p.selectionMoveEnd$.subscribe(()=>{b=setTimeout(()=>{S.dispose(),p.getSelectionControls().forEach((T,x)=>{S.add(G.merge(T.selectionMoving$,T.selectionScaling$).pipe(G.map(F=>N.serializeRange(F)),G.distinctUntilChanged()).subscribe(F=>{m.current=!0,I(F,x)}))})},30)});return()=>{C.unsubscribe(),S.dispose(),clearTimeout(b)}}},[e,p,g,i,l,t,o])},It=(e,t,n,s,o,c)=>{const i=r.useDependency(r.ICommandService),a=r.useDependency(te.IEditorService),m=r.useDependency(X.IRenderManagerService).getRenderById(t),d=m==null?void 0:m.with(W.RefSelectionsRenderService);f.useEffect(()=>{if(e&&d)if(n){const p=i.onCommandExecuted(h=>{if(h.id===K.SetWorksheetActiveOperation.id){const g=d.getSelectionControls().length;for(let u=1;u<=g;u++)d.clearLastSelection();setTimeout(()=>{c()},30)}});return()=>{p.dispose()}}else{const p=i.beforeCommandExecuted(h=>{if(h.id===K.SetWorksheetActiveOperation.id){s(!1),o(),c();const g=a.getEditor(r.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);g==null||g.focus()}});return()=>{p.dispose()}}},[e,d])},nn=e=>!e.some(n=>{if(typeof n=="string"){if(n!==N.matchToken.COMMA)return!0}else if(n.nodeType!==N.sequenceNodeType.REFERENCE)return!0;return!1}),qn=(e,t,n)=>{const s=f.useRef(!0);f.useEffect(()=>{if(e){const o=setTimeout(()=>{s.current=!1},500);return()=>{clearTimeout(o)}}},[e]),f.useEffect(()=>{if(!s.current&&t){const o=nn(n);t(o,_e(n))}},[n,t])},Re={sheetRangeSelectorTextWrap:"univer-sheet-range-selector-text-wrap",sheetRangeSelectorPlaceholder:"univer-sheet-range-selector-placeholder",sheetRangeSelectorError:"univer-sheet-range-selector-error",sheetRangeSelectorErrorWrap:"univer-sheet-range-selector-error-wrap",sheetRangeSelectorText:"univer-sheet-range-selector-text",sheetRangeSelectorActive:"univer-sheet-range-selector-active",sheetRangeSelectorIcon:"univer-sheet-range-selector-icon",sheetRangeSelectorDialogItem:"univer-sheet-range-selector-dialog-item",sheetRangeSelectorDialogItemDelete:"univer-sheet-range-selector-dialog-item-delete"},Ue=()=>{};function on(e){const{initValue:t,unitId:n,subUnitId:s,errorText:o,placeholder:c,actions:i,onChange:a=Ue,onVerify:l=Ue,onRangeSelectorDialogVisibleChange:m=Ue,onBlur:d=Ue,onFocus:p=Ue,isFocus:h=!0,isOnlyOneRange:g=!1,isSupportAcrossSheet:u=!1}=e,S=E.useEvent(a),I=r.useDependency(te.IEditorService),b=r.useDependency(r.LocaleService),C=r.useDependency(r.ICommandService),_=r.useDependency(N.LexerTreeBuilder),T=f.useRef(null),[x,F]=f.useState(!1),[P,L]=f.useState(h),j=f.useMemo(()=>r.createInternalEditorID(`${w.RANGE_SELECTOR_SYMBOLS}-${r.generateRandomId(4)}`),[]),O=f.useRef(),M=O.current,k=f.useRef(null),y=r.useDependency(r.IUniverInstanceService),R=f.useMemo(()=>!x&&P,[x,P]),[D,A]=f.useState(()=>typeof t=="string"?t:Ie(t,u).join(N.matchToken.COMMA)),H=f.useMemo(()=>y.getCurrentTypeOfUnit$(r.UniverInstanceType.UNIVER_DOC),[y]),Z=r.useObservable(H),J=(Z==null?void 0:Z.getUnitId())===j,z=f.useRef([]),Y=E.useEvent((V,B)=>{T.current&&!x&&!T.current.contains(V.target)&&B()});i&&(i.handleOutClick=Y);const oe=f.useMemo(()=>D.split(N.matchToken.COMMA).filter(V=>!!V).map(V=>N.deserializeRangeWithSheet(V)),[D]),ae=f.useMemo(()=>o!==void 0,[o]),ne=$t(!x&&P,n,s);f.useMemo(()=>V=>{const B=_.sequenceNodesBuilder(V);if(B){if(nn(B)){const q=B.map(ie=>{if(typeof ie=="string")return ie;if(ie.nodeType===N.sequenceNodeType.REFERENCE){const je={...ie},Te=N.deserializeRangeWithSheet(ie.token);return Te.range=Ct(Te.range),u||(Te.sheetName="",Te.unitId=""),je.token=Ie([Te],u)[0],je}return ie}),$=_e(q);S($)}}else A("")},[u]);const U=zt(M),{checkScrollBar:ge}=te.useResize(M,!0,!0),me=tt(),de=f.useMemo(()=>me(D),[D]),se=Zt(),Ee=St(n,s),le=E.useEvent((V,B=!0,Q=!0)=>{if(!O.current)return;const q=me(V),$=se(O.current,q,B);z.current=$,Q&&Ee($,O.current)});f.useEffect(()=>{const V=C.onCommandExecuted(B=>{var Q,q;if(B.id===ut.RichTextEditingMutation.id){const $=B.params,{unitId:ie}=$;ie===j&&S(r.BuildTextUtils.transform.getPlainText((q=(Q=M==null?void 0:M.getDocumentData().body)==null?void 0:Q.dataStream)!=null?q:""))}});return()=>V.dispose()},[C,M,j,S]);const ve=E.useEvent((V,B,Q)=>{le(V),A(V),Q&&(U(),B!==-1&&setTimeout(()=>{const q={startOffset:B,endOffset:B};M==null||M.setSelectionRanges([q]);const $=M==null?void 0:M.render.with(te.DocBackScrollRenderController);$==null||$.scrollToRange({...q,collapsed:!0})},50),ge())});tn(R,n,s,de,u,g,ve),gt(R,R&&J,n),qt(n,g),Un(n,D,M),qn(R,l,de),Qt(R,0,M),Xn(),It(R,n,u,L,d,()=>{R&&le(D)}),f.useEffect(()=>{if(M){const V=M.input$.pipe(G.throttleTime(100)).subscribe(B=>{var q,$;const Q=(($=(q=B.data.body)==null?void 0:q.dataStream)!=null?$:"").replaceAll(/\n|\r/g,"").replaceAll(/,{2,}/g,",").replaceAll(/(^,)/g,"");le(Q,!1),A(Q)});return()=>{V.unsubscribe()}}},[M]),f.useEffect(()=>{const V=C.onCommandExecuted(B=>{B.id===w.SetCellEditVisibleOperation.id&&(F(!1),m(!1),L(!1),d())});return()=>{V.dispose()}},[u]),f.useLayoutEffect(()=>{let V;if(k.current){V=I.register({autofocus:!0,editorUnitId:j,initialSnapshot:{id:j,body:{dataStream:`${D}\r
13
- `,textRuns:[]},documentStyle:{}}},k.current);const B=I.getEditor(j);O.current=B,le(D,!1,!1)}return()=>{V==null||V.dispose()}},[]),f.useLayoutEffect(()=>{h?(L(h),U()):(M==null||M.blur(),ne(),L(h))},[h,U]),Yn(D,"",P,se,Ee,M);const he=()=>{p(),U(),L(!0)},Ce=V=>{const B=Ie(V,u).join(N.matchToken.COMMA);B||M==null||M.setDocumentData({...M.getDocumentData(),body:{dataStream:`\r
14
- `,textRuns:[]}}),le(B),A(B),F(!1),m(!1),setTimeout(()=>{L(!0),M==null||M.setSelectionRanges([{startOffset:B.length,endOffset:B.length}]),U(),ge()},30)},xe=()=>{F(!1),m(!1),setTimeout(()=>{L(!0),U()},30)},Fe=()=>{ae||(U(),setTimeout(()=>{F(!0),m(!0),L(!1)},30))};return v.jsxs("div",{className:Re.sheetRangeSelector,ref:T,children:[v.jsxs("div",{className:pt(Re.sheetRangeSelectorTextWrap,{[Re.sheetRangeSelectorActive]:P&&!ae,[Re.sheetRangeSelectorError]:ae}),children:[v.jsx("div",{className:Re.sheetRangeSelectorText,ref:k,onMouseUp:he}),v.jsx(pe.Tooltip,{title:b.t("rangeSelector.buttonTooltip"),placement:"bottom",children:v.jsx(Ut,{className:Re.sheetRangeSelectorIcon,onClick:Fe})}),o!==void 0?v.jsx("div",{className:Re.sheetRangeSelectorErrorWrap,children:o}):null,c!==void 0&&!D?v.jsx("div",{className:Re.sheetRangeSelectorPlaceholder,children:c}):null]}),x&&v.jsx($n,{editorId:j,handleConfirm:Ce,handleClose:xe,unitId:n,subUnitId:s,initValue:oe,visible:x,isOnlyOneRange:g,isSupportAcrossSheet:u})]})}function $n(e){const{handleConfirm:t,handleClose:n,visible:s,initValue:o,unitId:c,subUnitId:i,isOnlyOneRange:a,isSupportAcrossSheet:l}=e,m=r.useDependency(r.LocaleService),d=r.useDependency(Ne.IDescriptionService),p=r.useDependency(N.LexerTreeBuilder),g=r.useDependency(X.IRenderManagerService).getRenderById(c),u=g==null?void 0:g.with(W.RefSelectionsRenderService),[S,I]=f.useState(()=>{if(a){const R=o[0];return R?Ie([R],l):[""]}return Ie(o,l)}),[b,C]=f.useState(()=>S.length-1),_=Xt(),T=f.useMemo(()=>S.join(N.matchToken.COMMA),[S]),x=tt(),F=f.useMemo(()=>x(T),[T]),P=f.useMemo(()=>Jt(d,_,F).refSelections,[F]),L=()=>{I([]),setTimeout(()=>{n()},30)},j=(R,D)=>{D?u==null||u.setSkipLastEnabled(!1):u==null||u.setSkipLastEnabled(!0),I(A=>{const H=[...A];return H[R]=D,H})},O=R=>{u==null||u.setSkipLastEnabled(!1),I(D=>{if(D.length===1)return D;const A=[];return D.forEach((H,Z)=>{R!==Z&&A.push(H)}),A})},M=()=>{u==null||u.setSkipLastEnabled(!0),I(R=>(R.push(""),C(R.length-1),[...R]))},k=E.useEvent(R=>{var A;u==null||u.setSkipLastEnabled(!1);const D=R.split(N.matchToken.COMMA).filter(H=>!!H);I(a?[(A=D[0])!=null?A:""]:D)}),y=St(c,i);return tn(b>=0,c,i,F,l,a,k),gt(b>=0,b>=0,c),qt(c,a),It(b>=0,c,l,G.noop,G.noop,()=>y(P)),f.useEffect(()=>{y(P)},[P]),f.useEffect(()=>{(S.length===0||S.length===1&&!S[0])&&(u==null||u.setSkipLastEnabled(!0))},[S]),v.jsx(pe.Dialog,{width:"328px",visible:s,title:m.t("rangeSelector.title"),draggable:!0,closeIcon:v.jsx(et,{}),footer:v.jsxs("footer",{children:[v.jsx(pe.Button,{onClick:L,children:m.t("rangeSelector.cancel")}),v.jsx(pe.Button,{style:{marginLeft:10},onClick:()=>t(S.filter(R=>{const D=p.sequenceNodesBuilder(R);return D&&D.length===1&&typeof D[0]!="string"&&D[0].nodeType===N.sequenceNodeType.REFERENCE}).map(R=>N.deserializeRangeWithSheet(R)).map(R=>({...R,range:Ct(R.range)}))),type:"primary",children:m.t("rangeSelector.confirm")})]}),onClose:L,children:v.jsxs("div",{className:Re.sheetRangeSelectorDialog,children:[S.map((R,D)=>v.jsxs("div",{className:Re.sheetRangeSelectorDialogItem,children:[v.jsx(pe.Input,{affixWrapperStyle:{width:"100%"},placeholder:m.t("rangeSelector.placeHolder"),onFocus:()=>C(D),value:R,onChange:A=>j(D,A)},`input_${D}`),S.length>1&&!a&&v.jsx(Bt,{className:Re.sheetRangeSelectorDialogItemDelete,onClick:()=>O(D)})]},`${R}_${D}`)),!a&&v.jsx("div",{children:v.jsxs(pe.Button,{type:"link",size:"small",onClick:M,children:[v.jsx(Kt,{}),v.jsx("span",{children:m.t("rangeSelector.addAnotherRange")})]})})]})})}function eo(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 Rt(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},...`}const to=(e,t=100)=>{f.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 sn(e,t,n){const s=r.useDependency(te.IEditorService),o=f.useMemo(()=>new G.BehaviorSubject({left:-999,top:-999,right:-999,bottom:-999}),[]),c=r.useDependency(E.ISidebarService),i=r.useDependency(r.IUniverInstanceService),a=E.useEvent(()=>{const l=s.getEditor(e);if(!l)return;const m=l.getBoundingClientRect(),{left:d,top:p,right:h,bottom:g}=m,u=o.getValue();if(!(u.left===d&&u.top===p&&u.right===h&&u.bottom===g))return o.next({left:d-1,right:h+1,top:p-1,bottom:g+1}),m});return f.useEffect(()=>{t&&a()},[e,s,i.unitAdded$,a,t,...n!=null?n:[]]),to(a),f.useEffect(()=>{const l=c.scrollEvent$.pipe(G.throttleTime(100)).subscribe(a);return()=>{l.unsubscribe()}},[]),[o,a]}const Ye=e=>{const t=f.useRef(e);return t.current=e,t},no=(e,t,n)=>{const s=r.useDependency(Ne.IDescriptionService),o=r.useDependency(N.LexerTreeBuilder),[c,i]=f.useState(),[a,l]=f.useState(-1),[m,d]=f.useState(!0),p=Ye(m),h=f.useRef(t);h.current=t;const g=()=>{i(void 0),l(-1),d(!1)};return f.useEffect(()=>{if(n&&e){const u=n.selectionChange$.pipe(G.debounceTime(50)).subscribe(I=>{if(I.textRanges.length===1){const[b]=I.textRanges;if(b.collapsed&&p.current){const C=o.getFunctionAndParameter(`${h.current}A`,b.startOffset-1);if(C){const{functionName:_,paramIndex:T}=C,x=s.getFunctionInfo(_);i(x),l(T);return}}}i(void 0),l(-1)}),S=n.selectionChange$.pipe(G.filter(I=>I.isEditing),G.filter(I=>I.textRanges.length===1),G.map(I=>I.textRanges[0].startOffset),G.distinctUntilChanged()).subscribe(()=>{d(!0)});return()=>{u.unsubscribe(),S.unsubscribe()}}},[n,e]),f.useEffect(()=>{e||g()},[e]),{functionInfo:c,paramIndex:a,reset:g}},ce={formulaHelpFunction:"univer-formula-help-function",formulaHelpFunctionTitle:"univer-formula-help-function-title",formulaHelpFunctionTitleIcons:"univer-formula-help-function-title-icons",formulaHelpFunctionTitleIcon:"univer-formula-help-function-title-icon",formulaHelpFunctionContent:"univer-formula-help-function-content",formulaHelpFunctionContentInner:"univer-formula-help-function-content-inner",formulaHelpFunctionContentParams:"univer-formula-help-function-content-params",formulaHelpFunctionContentParamsTitle:"univer-formula-help-function-content-params-title",formulaHelpFunctionContentParamsDetail:"univer-formula-help-function-content-params-detail",formulaHelpFunctionActive:"univer-formula-help-function-active",formulaHelpDecorator:"univer-formula-help-decorator",formulaHelpParam:"univer-formula-help-param",formulaHelpParamPrefix:"univer-formula-help-param-prefix",formulaHelpParamItem:"univer-formula-help-param-item",formulaHelpParamActive:"univer-formula-help-param-active"},Et=({className:e,title:t,value:n})=>v.jsxs("div",{className:ce.formulaHelpFunctionContentParams,children:[v.jsx("div",{className:`
15
- ${ce.formulaHelpFunctionContentParamsTitle}
1
+ (function(W,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/sheets-ui"),require("@univerjs/engine-formula"),require("rxjs"),require("@univerjs/docs-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-formula"),require("@univerjs/ui"),require("react/jsx-runtime"),require("@univerjs/design"),require("@univerjs/docs"),require("react"),require("rxjs/operators")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-ui","@univerjs/engine-formula","rxjs","@univerjs/docs-ui","@univerjs/engine-render","@univerjs/sheets","@univerjs/sheets-formula","@univerjs/ui","react/jsx-runtime","@univerjs/design","@univerjs/docs","react","rxjs/operators"],s):(W=typeof globalThis<"u"?globalThis:W||self,s(W.UniverSheetsFormulaUi={},W.UniverCore,W.UniverSheetsUi,W.UniverEngineFormula,W.rxjs,W.UniverDocsUi,W.UniverEngineRender,W.UniverSheets,W.UniverSheetsFormula,W.UniverUi,W.React,W.UniverDesign,W.UniverDocs,W.React,W.rxjs.operators))})(this,function(W,s,k,b,q,te,G,j,Ne,_,C,me,lt,u,Be){"use strict";var mr=Object.defineProperty;var pr=(W,s,k)=>s in W?mr(W,s,{enumerable:!0,configurable:!0,writable:!0,value:k}):W[s]=k;var ne=(W,s,k)=>pr(W,typeof s!="symbol"?s+"":s,k);const Ze={id:"sheet.command.paste-formula",type:s.CommandType.COMMAND,handler:async e=>e.get(s.ICommandService).executeCommand(k.SheetPasteCommand.id,{value:k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA})},Ae={id:"formula-ui.operation.select-editor-formula",type:s.CommandType.OPERATION,handler:(e,t)=>!0};var gn=Object.defineProperty,vn=Object.getOwnPropertyDescriptor,Cn=(e,t,n,r)=>{for(var o=r>1?void 0:r?vn(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&gn(t,n,o),o},In=(e,t)=>(n,r)=>t(n,r,e);const Nt="FORMULA_PROMPT_ACTIVATED",Ve=s.createIdentifier("formula-ui.prompt-service");let ut=class{constructor(e){ne(this,"_search$",new q.Subject);ne(this,"_help$",new q.Subject);ne(this,"_navigate$",new q.Subject);ne(this,"_accept$",new q.Subject);ne(this,"_acceptFormulaName$",new q.Subject);ne(this,"search$",this._search$.asObservable());ne(this,"help$",this._help$.asObservable());ne(this,"navigate$",this._navigate$.asObservable());ne(this,"accept$",this._accept$.asObservable());ne(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());ne(this,"_searching",!1);ne(this,"_helping",!1);ne(this,"_sequenceNodes",[]);ne(this,"_isLockedOnSelectionChangeRefString",!1);ne(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(Nt,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 r=0,o=this._sequenceNodes.length;r<o;r++){const c=this._sequenceNodes[r];if(typeof c=="string")t++;else{const{endIndex:i}=c;t=i}if(e<=t)return typeof n=="string"&&e!==0?r+1:r}return this._sequenceNodes.length}updateSequenceRef(e,t){const n=this._sequenceNodes[e];if(typeof n=="string"||n.nodeType!==b.sequenceNodeType.REFERENCE)return;const r=t.length-n.token.length,o={...n};o.token=t,o.endIndex+=r,this._sequenceNodes[e]=o;for(let c=e+1,i=this._sequenceNodes.length;c<i;c++){const a=this._sequenceNodes[c];if(typeof a=="string")continue;const f={...a};f.startIndex+=r,f.endIndex+=r,this._sequenceNodes[c]=f}}insertSequenceRef(e,t){const n=t.length,r=this.getCurrentSequenceNodeIndex(e);this._sequenceNodes.splice(r,0,{token:t,startIndex:e,endIndex:e+n-1,nodeType:b.sequenceNodeType.REFERENCE});for(let o=r+1,c=this._sequenceNodes.length;o<c;o++){const i=this._sequenceNodes[o];if(typeof i=="string")continue;const a={...i};a.startIndex+=n,a.endIndex+=n,this._sequenceNodes[o]=a}}insertSequenceString(e,t){const n=this.getCurrentSequenceNodeIndex(e),r=t.split("");this._sequenceNodes.splice(n,0,...r);const o=r.length;for(let c=n+o,i=this._sequenceNodes.length;c<i;c++){const a=this._sequenceNodes[c];if(typeof a=="string")continue;const f={...a};f.startIndex+=o,f.endIndex+=o,this._sequenceNodes[c]=f}}enableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!0}disableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!1}isLockedSelectionChange(){return this._isLockedOnSelectionChangeRefString}enableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!0}disableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!1}isLockedSelectionInsert(){return this._isLockedOnSelectionInsertRefString}};ut=Cn([In(0,s.IContextService)],ut);const Ot={id:"formula-ui.operation.help-function",type:s.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ve).help(t),!0)},Xe={id:"formula-ui.operation.insert-function",type:s.CommandType.OPERATION,handler:async(e,t)=>{var y,D;const n=e.get(j.SheetsSelectionsService),r=e.get(te.IEditorService),o=n.getCurrentSelections();if(!o||!o.length)return!1;const c=j.getSheetCommandTarget(e.get(s.IUniverInstanceService));if(!c)return!1;const{worksheet:i,unitId:a,subUnitId:f}=c,d=i.getCellMatrix(),{value:h}=t,p=e.get(s.ICommandService),m=e.get(k.IEditorBridgeService),v=[],l=[];let g=null,E=0,R=0,I="";if(o.length===1&&(yn(o[0].range)||Rn(o[0].range)&&Ft(d,o[0].range))){const{range:A,primary:F}=o[0],L=(y=F==null?void 0:F.actualRow)!=null?y:A.startRow,x=(D=F==null?void 0:F.actualColumn)!=null?D:A.startColumn;g=A,E=L,R=x;const w=Dt(d,L,x);w&&(I=b.serializeRange(w))}else o.some(A=>{var x,w;const{range:F,primary:L}=A;if(Ft(d,F)){const N=(x=L==null?void 0:L.actualRow)!=null?x:F.startRow,O=(w=L==null?void 0:L.actualColumn)!=null?w:F.startColumn,$=Dt(d,N,O);if(!$)return g=F,E=N,R=O,!0;const M=b.serializeRange($),S=`=${h}(${M})`;v.push({range:F,primary:{row:N,column:O},formula:S})}else{const{startRow:N,startColumn:O,endRow:$,endColumn:M}=F;if(N===$){const S=Tn(d,N,M,i.getColumnCount()-1),T=S===M?M-1:M,P=b.serializeRange({startRow:N,endRow:$,startColumn:O,endColumn:T}),H=`=${h}(${P})`;l.push({range:F,primary:{row:N,column:S},formula:H})}else{let S=-1;for(let P=O;P<=M;P++){const H=bn(d,P,$,i.getRowCount()-1);S=Math.max(S,H)}const T=S===$?$-1:$;for(let P=O;P<=M;P++){const H=b.serializeRange({startRow:N,endRow:T,startColumn:P,endColumn:P}),V=`=${h}(${H})`;l.push({range:F,primary:{row:S,column:P},formula:V})}}}return!1});if(g){const A=j.getCellAtRowCol(E,R,i),F={range:s.Rectangle.clone(g),primary:{startRow:A.startRow,startColumn:A.startColumn,endRow:A.endRow,endColumn:A.endColumn,actualRow:E,actualColumn:R,isMerged:A.isMerged,isMergedMainCell:A.startRow===E&&A.startColumn===R}},L={unitId:a,subUnitId:f,selections:[F]};await p.executeCommand(j.SetSelectionsOperation.id,L);const x=r.getEditor(s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),w=r.getEditor(s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);m.changeVisible({visible:!0,unitId:a,eventType:G.DeviceInputEventType.Dblclick});const N=`=${h}(${I}`;x==null||x.replaceText(N),w==null||w.replaceText(N,!1)}return v.length===0&&l.length===0?!1:p.executeCommand(Ne.InsertFunctionCommand.id,{list:v,listOfRangeHasNumber:l})}};function Dt(e,t,n){const r=En(e,t,n);if(r!==t)return{startRow:r,endRow:t-1,startColumn:n,endColumn:n};const o=_n(e,t,n);return o!==n?{startRow:t,endRow:t,startColumn:o,endColumn:n-1}:null}function En(e,t,n){let r=!1;if(t===0)return t;for(let o=t-1;o>=0;o--){const c=e.getValue(o,n);if(Ke(c)&&!r){if(o===0)return 0;r=!0}else{if(r&&!Ke(c))return o+1;if(r&&o===0)return 0}}return t}function _n(e,t,n){let r=!1;if(n===0)return n;for(let o=n-1;o>=0;o--){const c=e.getValue(t,o);if(Ke(c)&&!r){if(o===0)return 0;r=!0}else{if(r&&!Ke(c))return o+1;if(r&&o===0)return 0}}return n}function Ke(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return!1;const n=t.dataStream,o=n.substring(n.length-2,n.length)===s.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n;return s.isRealNum(o)}return e&&(e.t===s.CellValueType.NUMBER||s.getCellValueType(e)===s.CellValueType.NUMBER)}function yn(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}function Rn(e){return e.startRow!==e.endRow&&e.startColumn!==e.endColumn}function Ft(e,t){for(let n=t.startRow;n<=t.endRow;n++)for(let r=t.startColumn;r<=t.endColumn;r++)if(Ke(e.getValue(n,r)))return!1;return!0}function Tn(e,t,n,r){for(let o=n;o<=r;o++)if(!e.getValue(t,o))return o;return r}function bn(e,t,n,r){for(let o=n;o<=r;o++)if(!e.getValue(o,t))return o;return r}const Pt="SHEET_FORMULA_UI_PLUGIN",At=`${Pt}_MORE_FUNCTIONS_COMPONENT`,Je={id:"formula-ui.operation.more-functions",type:s.CommandType.OPERATION,handler:async e=>(e.get(_.ISidebarService).open({header:{title:"formula.insert.tooltip"},children:{label:At}}),!0)},ft={id:"formula-ui.operation.change-ref-to-absolute",type:s.CommandType.OPERATION,handler:async e=>!0},Lt={id:"formula-ui.operation.search-function",type:s.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ve).search(t),!0)};var ve=function(){return ve=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},ve.apply(this,arguments)},Mn=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n},Oe=u.forwardRef(function(e,t){var n=e.icon,r=e.id,o=e.className,c=e.extend,i=Mn(e,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(r," ").concat(o||"").trim(),f=u.useRef("_".concat(Dn()));return wt(n,"".concat(r),{defIds:n.defIds,idSuffix:f.current},ve({ref:t,className:a},i),c)});function wt(e,t,n,r,o){return u.createElement(e.tag,ve(ve({key:t},Nn(e,n,o)),r),(On(e,n).children||[]).map(function(c,i){return wt(c,"".concat(t,"-").concat(e.tag,"-").concat(i),n,void 0,o)}))}function Nn(e,t,n){var r=ve({},e.attrs);n!=null&&n.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=n.colorChannel1);var o=t.defIds;return!o||o.length===0||(e.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+t.idSuffix),Object.entries(r).forEach(function(c){var i=c[0],a=c[1];typeof a=="string"&&(r[i]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),r}function On(e,t){var n,r=t.defIds;return!r||r.length===0?e:e.tag==="defs"&&(!((n=e.children)===null||n===void 0)&&n.length)?ve(ve({},e),{children:e.children.map(function(o){return typeof o.attrs.id=="string"&&r&&r.indexOf(o.attrs.id)>-1?ve(ve({},o),{attrs:ve(ve({},o.attrs),{id:o.attrs.id+t.idSuffix})}):o})}):e}function Dn(){return Math.random().toString(36).substring(2,8)}Oe.displayName="UniverIcon";var Fn={tag:"svg",attrs:{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"}}]},$t=u.forwardRef(function(e,t){return u.createElement(Oe,Object.assign({},e,{id:"check-mark-single",ref:t,icon:Fn}))});$t.displayName="CheckMarkSingle";var Pn={tag:"svg",attrs:{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"}}]},Qe=u.forwardRef(function(e,t){return u.createElement(Oe,Object.assign({},e,{id:"close-single",ref:t,icon:Pn}))});Qe.displayName="CloseSingle";var An={tag:"svg",attrs:{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.866699 5.9313.866699H10.069C10.4004.866699 10.669 1.13533 10.669 1.4667 10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667zM1.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.64443 14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443zM6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928 9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171 10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778 9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539 9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263 6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539 5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778 6.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"}}]},kt=u.forwardRef(function(e,t){return u.createElement(Oe,Object.assign({},e,{id:"delete-single",ref:t,icon:An}))});kt.displayName="DeleteSingle";var Ln={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.75 5.32495C8.75 5.73916 8.41421 6.07495 8 6.07495 7.58579 6.07495 7.25 5.73916 7.25 5.32495 7.25 4.91074 7.58579 4.57495 8 4.57495 8.41421 4.57495 8.75 4.91074 8.75 5.32495zM8.5999 7.52505C8.5999 7.19368 8.33127 6.92505 7.9999 6.92505 7.66853 6.92505 7.3999 7.19368 7.3999 7.52505V11.425C7.3999 11.7564 7.66853 12.025 7.9999 12.025 8.33127 12.025 8.5999 11.7564 8.5999 11.425V7.52505z"}},{tag:"path",attrs:{fill:"currentColor",d:"M0.899902 8.00002C0.899902 4.0788 4.07868 0.900024 7.9999 0.900024C11.9211 0.900024 15.0999 4.0788 15.0999 8.00002C15.0999 11.9212 11.9211 15.1 7.9999 15.1C4.07868 15.1 0.899902 11.9212 0.899902 8.00002ZM7.9999 2.10002C4.74142 2.10002 2.0999 4.74154 2.0999 8.00002C2.0999 11.2585 4.74142 13.9 7.9999 13.9C11.2584 13.9 13.8999 11.2585 13.8999 8.00002C13.8999 4.74154 11.2584 2.10002 7.9999 2.10002Z",fillRule:"evenodd",clipRule:"evenodd"}}]},xt=u.forwardRef(function(e,t){return u.createElement(Oe,Object.assign({},e,{id:"details-single",ref:t,icon:Ln}))});xt.displayName="DetailsSingle";var wn={tag:"svg",attrs:{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"}}]},Ht=u.forwardRef(function(e,t){return u.createElement(Oe,Object.assign({},e,{id:"increase-single",ref:t,icon:wn}))});Ht.displayName="IncreaseSingle";var $n={tag:"svg",attrs:{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"}}]},dt=u.forwardRef(function(e,t){return u.createElement(Oe,Object.assign({},e,{id:"more-single",ref:t,icon:$n}))});dt.displayName="MoreSingle";var kn={tag:"svg",attrs:{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=u.forwardRef(function(e,t){return u.createElement(Oe,Object.assign({},e,{id:"select-range-single",ref:t,icon:kn}))});Wt.displayName="SelectRangeSingle";function Bt(e){var t,n,r="";if(typeof e=="string"||typeof e=="number")r+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(n=Bt(e[t]))&&(r&&(r+=" "),r+=n)}else for(n in e)e[n]&&(r&&(r+=" "),r+=n);return r}function ht(){for(var e,t,n=0,r="",o=arguments.length;n<o;n++)(e=arguments[n])&&(t=Bt(e))&&(r&&(r+=" "),r+=t);return r}var xn=Object.defineProperty,Hn=Object.getOwnPropertyDescriptor,Wn=(e,t,n,r)=>{for(var o=r>1?void 0:r?Hn(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&xn(t,n,o),o},$e=(e,t)=>(n,r)=>t(n,r,e);W.RefSelectionsRenderService=class extends k.BaseSelectionRenderService{constructor(n,r,o,c,i,a,f){super(r,o,c,i,a);ne(this,"_workbookSelections");ne(this,"_eventDisposables");this._context=n,this._contextService=a,this._refSelectionsService=f,this._workbookSelections=this._refSelectionsService.getWorkbookSelections(this._context.unitId),this._initSelectionChangeListener(),this._initSkeletonChangeListener(),this._initUserActionSyncListener(),this._setSelectionStyle(Bn(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(),s.toDisposable(()=>this._disableSelectionChanging())}_disableSelectionChanging(){var n;(n=this._eventDisposables)==null||n.dispose(),this._eventDisposables=null}disableSelectionChanging(){this._disableSelectionChanging()}_initCanvasEventListeners(){const n=this._getSheetObject(),{spreadsheetRowHeader:r,spreadsheetColumnHeader:o,spreadsheet:c,spreadsheetLeftTopPlaceholder:i}=n,{scene:a}=this._context,f=new s.DisposableCollection;return f.add(c==null?void 0:c.onPointerDown$.subscribeEvent((d,h)=>{this.inRefSelectionMode()&&(this._onPointerDown(d,c.zIndex+1,s.RANGE_TYPE.NORMAL,this._getActiveViewport(d)),d.button!==2&&h.stopPropagation())})),f.add(r==null?void 0:r.onPointerDown$.subscribeEvent((d,h)=>{if(!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:m}=k.getCoordByOffset(d.offsetX,d.offsetY,a,p);k.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),m,s.RANGE_TYPE.ROW)||(this._onPointerDown(d,(c.zIndex||1)+1,s.RANGE_TYPE.ROW,this._getActiveViewport(d),G.ScrollTimerType.Y),d.button!==2&&h.stopPropagation())})),f.add(o==null?void 0:o.onPointerDown$.subscribeEvent((d,h)=>{if(!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:m}=k.getCoordByOffset(d.offsetX,d.offsetY,a,p);k.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),m,s.RANGE_TYPE.COLUMN)||(this._onPointerDown(d,(c.zIndex||1)+1,s.RANGE_TYPE.COLUMN,this._getActiveViewport(d),G.ScrollTimerType.X),d.button!==2&&h.stopPropagation())})),f.add(i==null?void 0:i.onPointerDown$.subscribeEvent((d,h)=>{if(this._reset(),!this.inRefSelectionMode())return;const p=this._sheetSkeletonManagerService.getCurrent().skeleton,m=k.getAllSelection(p);this._addSelectionControlByModelData(m),this._selectionMoveStart$.next(this.getSelectionDataWithStyle());const v=a.onPointerUp$.subscribeEvent(()=>{v.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});d.button!==2&&h.stopPropagation()})),f}_addSelectionControlByModelData(n){var a;const r=this._skeleton,o=(a=n.style)!=null?a:k.genNormalSelectionStyle(this._themeService),c=this._scene;return n.style=o,this.newSelectionControl(c,r,n)}_initSelectionChangeListener(){this.disposeWithMe(this._refSelectionsService.selectionSet$.subscribe(n=>{this._reset(),this._skeleton&&this.resetSelectionsByModelData(n||[])}))}_initUserActionSyncListener(){this.disposeWithMe(this.selectionMoveStart$.subscribe(n=>{this._updateSelections(n,j.SelectionMoveType.MOVE_START)})),this.disposeWithMe(this.selectionMoving$.subscribe(n=>{this._updateSelections(n,j.SelectionMoveType.MOVING)})),this.disposeWithMe(this.selectionMoveEnd$.subscribe(n=>{this._updateSelections(n,j.SelectionMoveType.MOVE_END)}))}_updateSelections(n,r){const c=this._context.unit.getActiveSheet().getSheetId();n.length!==0&&this._workbookSelections.setSelections(c,n.map(i=>j.convertSelectionDataToRange(i)),r)}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(n=>{if(!n)return;const{skeleton:r}=n,{scene:o}=this._context,c=o.getViewport(G.SHEET_VIEWPORT_KEY.VIEW_MAIN);this._skeleton&&this._skeleton.worksheet.getSheetId()!==r.worksheet.getSheetId()&&this._reset(),this._changeRuntime(r,o,c);const i=this._workbookSelections.getCurrentSelections();this.resetSelectionsByModelData(i)}))}_getActiveViewport(n){const r=this._getSheetObject();return r==null?void 0:r.scene.getActiveViewportByCoord(G.Vector2.FromArray([n.offsetX,n.offsetY]))}_getSheetObject(){return k.getSheetObject(this._context.unit,this._context)}_onPointerDown(n,r=0,o=s.RANGE_TYPE.NORMAL,c,i=G.ScrollTimerType.ALL){var O;this._rangeType=o;const a=this._skeleton,f=this._scene;if(!f||!a)return;c&&(this._activeViewport=c);const{offsetX:d,offsetY:h}=n,p=f.getViewport(G.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!p)return;const m=f.getCoordRelativeToViewport(G.Vector2.FromArray([d,h])),{x:v,y:l}=m;this._startViewportPosX=v,this._startViewportPosY=l;const g=f.getScrollXYInfoByViewport(m),{scaleX:E,scaleY:R}=f.getAncestorScale(),I=this._skeleton.getCellByOffset(v,l,E,R,g);if(!I)return;switch(o){case s.RANGE_TYPE.NORMAL:break;case s.RANGE_TYPE.ROW:I.startColumn=0,I.endColumn=this._skeleton.getColumnCount()-1;break;case s.RANGE_TYPE.COLUMN:I.startRow=0,I.endRow=this._skeleton.getRowCount()-1;break;case s.RANGE_TYPE.ALL:I.startRow=0,I.startColumn=0,I.endRow=this._skeleton.getRowCount()-1,I.endColumn=this._skeleton.getColumnCount()-1}const y={range:I,primary:I,style:null};y.range.rangeType=o;const D=k.attachSelectionWithCoord(y,this._skeleton);this._startRangeWhenPointerDown={...D.rangeWithCoord};const A={...D.rangeWithCoord,rangeType:o};let F=this.getActiveSelectionControl();const L=this.getSelectionControls();for(const $ of L){if(n.button===2&&$.model.isInclude(A)){F=$;return}if($.model.isEqual(A)){F=$;break}}this._checkClearPreviousControls(n);const x=F==null?void 0:F.model.currentCell,w=n.shiftKey&&x,N=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;w&&x?this._makeSelectionByTwoCells(x,A,a,o,F):N&&F?F.updateRangeBySelectionWithCoord(D):F=this.newSelectionControl(f,a,y);for(let $=0;$<this.getSelectionControls().length-1;$++)this.getSelectionControls()[$].clearHighlight();this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),f.disableObjectsEvent(),this._clearUpdatingListeners(),this._addEndingListeners(),(O=f.getTransformer())==null||O.clearSelectedObjects(),this._setupPointerMoveListener(p,F,o,i,v,l),this._escapeShortcutDisposable=this._shortcutService.forceEscape(),this._scenePointerUpSub=f.onPointerUp$.subscribeEvent(()=>{var $;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),($=this._escapeShortcutDisposable)==null||$.dispose(),this._escapeShortcutDisposable=null})}newSelectionControl(n,r,o){const c=this.getSelectionControls().length,{rowHeaderWidth:i,columnHeaderHeight:a}=r,f=new k.SelectionControl(n,c,this._themeService,{highlightHeader:this._highlightHeader,enableAutoFill:!1,rowHeaderWidth:i,columnHeaderHeight:a}),d=k.attachSelectionWithCoord(o,r);return f.updateRangeBySelectionWithCoord(d),this._selectionControls.push(f),f.setControlExtension({skeleton:r,scene:n,themeService:this._themeService,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),f}},W.RefSelectionsRenderService=Wn([$e(1,s.Inject(s.Injector)),$e(2,s.Inject(s.ThemeService)),$e(3,_.IShortcutService),$e(4,s.Inject(k.SheetSkeletonManagerService)),$e(5,s.IContextService),$e(6,j.IRefSelectionsService)],W.RefSelectionsRenderService);function Bn(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 Vn=(e,t,n)=>{const o=s.useDependency(G.IRenderManagerService).getRenderById(e),c=o==null?void 0:o.with(W.RefSelectionsRenderService);u.useEffect(()=>{if(n&&c){const i=n.input$.subscribe(a=>{a.content===b.matchToken.COMMA?c.setSkipLastEnabled(!0):c.setSkipLastEnabled(!1)});return()=>{i.unsubscribe()}}},[n,c]),u.useEffect(()=>{c&&(t.endsWith(b.matchToken.COMMA)||c.setSkipLastEnabled(!1))},[t,c])},et=()=>{const e=s.useDependency(b.LexerTreeBuilder);return u.useCallback(n=>e.sequenceNodesBuilder(n)||[],[e])},Kn=(e,t,n,r,o,c)=>{const i=et(),a=u.useRef(!0);u.useEffect(()=>{var f,d;if(c){if(a.current){const h=i(e);if(h.length){const p=r(c,h);n&&o(p)}else{const p=c.getDocumentData(),v={dataStream:(d=(f=p.body)==null?void 0:f.dataStream)!=null?d:`${t}\r
2
+ `,...p.body};c.setDocumentData({...p,body:v})}a.current=!1}else if(n){const h=i(e),p=r(c,h);o(p)}}},[c,n])},Vt=e=>{const t=s.useDependency(te.IEditorService);return _.useEvent(r=>{var o,c;if(e){t.focus(e.getEditorId());const i=[...e.getSelectionRanges()];if(s.Tools.isDefine(r))e.setSelectionRanges([{startOffset:r,endOffset:r}]);else if(!i.length&&!e.docSelectionRenderService.isOnPointerEvent){const a=(c=(o=e.getDocumentData().body)==null?void 0:o.dataStream)!=null?c:`\r
3
+ `,f=Math.max(a.length-2,0);e.setSelectionRanges([{startOffset:f,endOffset:f}])}}})};function Un(e,t,n){const r=e.getCurrentTheme(),o=new s.ColorKit(t).setAlpha(.05).toRgbString();return{id:n,strokeWidth:1,stroke:t,fill:o,widgets:{tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},widgetSize:6,widgetStrokeWidth:1,widgetStroke:r.colorWhite}}function Kt(e){var R,I,y;const{unitId:t,subUnitId:n,refSelections:r,editor:o,refSelectionsService:c,refSelectionsRenderService:i,sheetSkeletonManagerService:a,themeService:f,univerInstanceService:d}=e,h=d.getUnit(t,s.UniverInstanceType.UNIVER_SHEET),p=h==null?void 0:h.getActiveSheet(),m=[];if(!h||!p){c.setSelections(m);return}const v=p.getSheetId(),l=D=>{var A;return(A=h==null?void 0:h.getSheetBySheetName(D))==null?void 0:A.getSheetId()};if(!((R=a==null?void 0:a.getWorksheetSkeleton(v))==null?void 0:R.skeleton))return;const E=[];for(let D=0,A=r.length;D<A;D++){const F=r[D],{themeColor:L,token:x,refIndex:w,endIndex:N}=F,O=b.deserializeRangeWithSheet(x),{unitId:$,sheetName:M,range:S}=O;if($&&t!==$)continue;const T=l(M);if(T&&T!==v||!T&&v!==n)continue;const P=j.setEndForRange(S,p.getRowCount(),p.getColumnCount());m.push({range:P,primary:null,style:Un(f,L,w.toString())}),E.push(N)}if(o){const D=(y=(I=o.getSelectionRanges())==null?void 0:I[0])==null?void 0:y.startOffset,A=E.findIndex(F=>F+2===D);A!==-1?i==null||i.setActiveSelectionIndex(A):i==null||i.resetActiveSelectionIndex()}return m}function mt(e,t){const n=s.useDependency(s.IUniverInstanceService),r=s.useDependency(s.ThemeService),o=s.useDependency(j.IRefSelectionsService),i=s.useDependency(G.IRenderManagerService).getRenderById(e),a=i==null?void 0:i.with(W.RefSelectionsRenderService),f=i==null?void 0:i.with(k.SheetSkeletonManagerService),d=u.useCallback((h,p)=>{const m=Kt({unitId:e,subUnitId:t,refSelections:h,editor:p,refSelectionsService:o,refSelectionsRenderService:a,sheetSkeletonManagerService:f,themeService:r,univerInstanceService:n});if(!m)return;((a==null?void 0:a.getSelectionControls())||[]).length===m.length?a==null||a.resetSelectionsByModelData(m):o.setSelections(m)},[a,o,f,r,e,t,n]);return u.useEffect(()=>()=>{a==null||a.resetActiveSelectionIndex()},[a]),d}function Ut(e=""){const t=s.useDependency(Ne.IDescriptionService),n=jt(),r=s.useDependency(s.ICommandService),o=u.useMemo(()=>e.length,[e]);return u.useCallback((i,a,f=!0,d)=>{const h=i.getDocumentData(),p=i.getEditorId();if(!h)return[];const m=h.body;if(!m)return[];const v=m.dataStream.slice(0,m.dataStream.length-2),l={dataStream:"",...h.body};if(!v.startsWith(e))return[];if(a==null||a.length===0)return l.textRuns=[],r.syncExecuteCommand(te.ReplaceTextRunsCommand.id,{unitId:p,body:s.getBodySlice(l,0,l.dataStream.length-2)}),[];{const{textRuns:g,refSelections:E}=qt(t,n,a);o&&g.forEach(y=>{y.ed=y.ed+o,y.st=y.st+o}),l.textRuns=[{st:0,ed:1,ts:{fs:11}},...g];const R=a.reduce((y,D)=>typeof D=="string"?`${y}${D}`:`${y}${D.token}`,"");l.dataStream=`${e}${R}\r
4
+ `;let I;if(f){I=i.getSelectionRanges();const y=l.dataStream.length-2+o;I.forEach(D=>{D.startOffset=Math.max(0,Math.min(D.startOffset,y)),D.endOffset=Math.max(0,Math.min(D.endOffset,y))})}return r.syncExecuteCommand(te.ReplaceTextRunsCommand.id,{unitId:p,body:s.getBodySlice(l,0,l.dataStream.length-2),textRanges:d!=null?d:I}),E}},[r,t,n,o,e])}function jt(){const t=s.useDependency(s.ThemeService).getCurrentTheme();return u.useMemo(()=>{const r=[t.loopColor1,t.loopColor2,t.loopColor3,t.loopColor4,t.loopColor5,t.loopColor6,t.loopColor7,t.loopColor8,t.loopColor9,t.loopColor10,t.loopColor11,t.loopColor12],o=t.hyacinth700,c=t.verdancy800,i=t.colorBlack;return{formulaRefColors:r,numberColor:o,stringColor:c,plainTextColor:i}},[t])}function qt(e,t,n){const{formulaRefColors:r,numberColor:o,stringColor:c,plainTextColor:i}=t,a=[],f=[],d=new Map;let h=0;for(let p=0,m=n.length;p<m;p++){const v=n[p];if(typeof v=="string"){const y=a[a.length-1],D=y?y.ed:0,A=D+v.length;a.push({st:D,ed:A,ts:{cl:{rgb:i},fs:11}});continue}if(e.hasDefinedNameDescription(v.token.trim())){a.push({st:v.startIndex,ed:v.endIndex+1,ts:{cl:{rgb:i},fs:11}});continue}const{startIndex:l,endIndex:g,nodeType:E,token:R}=v;let I="";if(E===b.sequenceNodeType.REFERENCE){if(d.has(R))I=d.get(R);else{const y=h%r.length;I=r[y],d.set(R,I),h++}f.push({refIndex:p,themeColor:I,token:R,startIndex:v.startIndex,endIndex:v.endIndex,index:f.length})}else E===b.sequenceNodeType.NUMBER?I=o:(E===b.sequenceNodeType.STRING||E===b.sequenceNodeType.ARRAY)&&(I=c);I&&I.length>0?a.push({st:l,ed:g+1,ts:{cl:{rgb:I},fs:11}}):a.push({st:l,ed:g+1,ts:{cl:{rgb:i},fs:11}})}return{textRuns:a,refSelections:f}}function jn(e){var o,c;const n=e.get(s.IUniverInstanceService).getCurrentUniverDocInstance();return n!=null&&n.getBody()?{dataStream:(c=(o=n.getBody())==null?void 0:o.dataStream)!=null?c:"",offset:0}:void 0}var tt=(e=>(e[e.NOT_SELECT=0]="NOT_SELECT",e[e.NEED_ADD=1]="NEED_ADD",e[e.CAN_EDIT=2]="CAN_EDIT",e))(tt||{});function qn(e,t,n){var v;const o=s.useDependency(G.IRenderManagerService).getRenderById(e),c=o==null?void 0:o.with(te.DocSelectionRenderService),i=s.useDependency(lt.DocSelectionManagerService),a=s.useDependency(s.Injector),[f,d]=u.useState(0),h=s.useDependency(b.LexerTreeBuilder),p=u.useRef(!0),m=u.useRef(f);return m.current=f,u.useEffect(()=>{const l=i.textSelection$.pipe(q.filter(g=>g.unitId===e),q.map(()=>{const g=c==null?void 0:c.getActiveTextRange();return g!=null&&g.collapsed?g.startOffset:-1})).subscribe(g=>{var x,w;const E=jn(a);if(!E)return;const R=(x=E==null?void 0:E.dataStream)==null?void 0:x.slice(0,-2),I=(w=h.sequenceNodesBuilder(R))!=null?w:[],y=R[g-1],D=R[g],A=I.findIndex(N=>typeof N=="object"&&N.nodeType===b.sequenceNodeType.REFERENCE&&g===N.endIndex+2),F=y&&b.matchRefDrawToken(y)&&(!D||b.isFormulaLexerToken(D)&&D!==b.matchToken.OPEN_BRACKET),L=A>-1;if((R==null?void 0:R.substring(0,1))==="="&&(F||L))if(L){if(p.current)return;d(2)}else p.current=!1,d(1);else d(0)});return()=>l.unsubscribe()},[i.textSelection$,c,e,a,h]),u.useEffect(()=>{t||(d(0),p.current=!0)},[t]),u.useEffect(()=>{var g;if(!n)return;const l=(g=o==null?void 0:o.mainComponent)==null?void 0:g.onPointerDown$.subscribeEvent(()=>{d(0),p.current=!0});return()=>l==null?void 0:l.unsubscribe()},[n,(v=o==null?void 0:o.mainComponent)==null?void 0:v.onPointerDown$]),{isSelecting:f}}const Yt=(e,t,n,r)=>{const o=s.useDependency(s.ICommandService),c=s.useDependency(_.IShortcutService),i=u.useRef(t);i.current=t;const a=u.useRef(r);a.current=r,u.useEffect(()=>{if(!n||!e)return;const d=`sheet.formula-embedding-editor.${n.getEditorId()}`,h=new s.DisposableCollection,p=(l,g)=>{if(a.current){a.current(l,g);return}let E=s.Direction.LEFT;l===_.KeyCode.ARROW_DOWN?E=s.Direction.DOWN:l===_.KeyCode.ARROW_UP?E=s.Direction.UP:l===_.KeyCode.ARROW_RIGHT&&(E=s.Direction.RIGHT),g===_.MetaKeys.SHIFT?o.executeCommand(te.MoveSelectionOperation.id,{direction:E}):o.executeCommand(te.MoveCursorOperation.id,{direction:E})},m=(l,g)=>{let E=s.Direction.DOWN;l===_.KeyCode.ARROW_DOWN?E=s.Direction.DOWN:l===_.KeyCode.ARROW_UP?E=s.Direction.UP:l===_.KeyCode.ARROW_LEFT?E=s.Direction.LEFT:l===_.KeyCode.ARROW_RIGHT&&(E=s.Direction.RIGHT),i.current?g===_.MetaKeys.CTRL_COMMAND?o.executeCommand(k.MoveSelectionCommand.id,{direction:E,jumpOver:k.JumpOver.moveGap,extra:"formula-editor",fromCurrentSelection:i.current===tt.NEED_ADD}):g===_.MetaKeys.SHIFT?o.executeCommand(k.ExpandSelectionCommand.id,{direction:E,extra:"formula-editor"}):g===(_.MetaKeys.CTRL_COMMAND|_.MetaKeys.SHIFT)?o.executeCommand(k.ExpandSelectionCommand.id,{direction:E,jumpOver:k.JumpOver.moveGap,extra:"formula-editor"}):o.executeCommand(k.MoveSelectionCommand.id,{direction:E,extra:"formula-editor",fromCurrentSelection:i.current===tt.NEED_ADD}):p(l,g)};return h.add(o.registerCommand({id:d,type:s.CommandType.OPERATION,handler(l,g){const{keyCode:E,metaKey:R}=g;m(E,R)}})),[{keyCode:_.KeyCode.ARROW_DOWN},{keyCode:_.KeyCode.ARROW_LEFT},{keyCode:_.KeyCode.ARROW_RIGHT},{keyCode:_.KeyCode.ARROW_UP},{keyCode:_.KeyCode.ARROW_DOWN,metaKey:_.MetaKeys.SHIFT},{keyCode:_.KeyCode.ARROW_LEFT,metaKey:_.MetaKeys.SHIFT},{keyCode:_.KeyCode.ARROW_RIGHT,metaKey:_.MetaKeys.SHIFT},{keyCode:_.KeyCode.ARROW_UP,metaKey:_.MetaKeys.SHIFT},{keyCode:_.KeyCode.ARROW_DOWN,metaKey:_.MetaKeys.CTRL_COMMAND},{keyCode:_.KeyCode.ARROW_LEFT,metaKey:_.MetaKeys.CTRL_COMMAND},{keyCode:_.KeyCode.ARROW_RIGHT,metaKey:_.MetaKeys.CTRL_COMMAND},{keyCode:_.KeyCode.ARROW_UP,metaKey:_.MetaKeys.CTRL_COMMAND},{keyCode:_.KeyCode.ARROW_DOWN,metaKey:_.MetaKeys.CTRL_COMMAND|_.MetaKeys.SHIFT},{keyCode:_.KeyCode.ARROW_LEFT,metaKey:_.MetaKeys.CTRL_COMMAND|_.MetaKeys.SHIFT},{keyCode:_.KeyCode.ARROW_RIGHT,metaKey:_.MetaKeys.CTRL_COMMAND|_.MetaKeys.SHIFT},{keyCode:_.KeyCode.ARROW_UP,metaKey:_.MetaKeys.CTRL_COMMAND|_.MetaKeys.SHIFT}].map(({keyCode:l,metaKey:g})=>({id:d,binding:g?l|g:l,preconditions:()=>!0,priority:900,staticParameters:{eventType:G.DeviceInputEventType.Keyboard,keyCode:l,metaKey:g}})).forEach(l=>{h.add(c.registerShortcut(l))}),()=>{h.dispose()}},[o,n,e,c])},zt=(e,t)=>{const r=s.useDependency(G.IRenderManagerService).getRenderById(e),o=r==null?void 0:r.with(W.RefSelectionsRenderService);u.useEffect(()=>{o&&(t?o==null||o.setRemainLastEnabled(!1):o==null||o.setRemainLastEnabled(!0))},[t,o])},pt=(e,t,n,r=!0)=>{const o=s.useDependency(G.IRenderManagerService),c=s.useDependency(s.IContextService),i=s.useDependency(_.IContextMenuService),a=s.useDependency(j.IRefSelectionsService),f=o.getRenderById(n),d=f==null?void 0:f.with(W.RefSelectionsRenderService);u.useLayoutEffect(()=>{if(e)return c.setContextValue(s.EDITOR_ACTIVATED,!0),()=>{c.setContextValue(s.EDITOR_ACTIVATED,!1),a.clear()}},[c,e,a]),u.useLayoutEffect(()=>{if(e&&t){const h=d==null?void 0:d.enableSelectionChanging();return c.setContextValue(j.REF_SELECTIONS_ENABLED,!0),()=>{c.setContextValue(j.REF_SELECTIONS_ENABLED,!1),h==null||h.dispose()}}},[c,e,d,t]),u.useEffect(()=>{if(e)return c.setContextValue(s.EDITOR_ACTIVATED,!0),r&&i.disable(),()=>{c.setContextValue(s.EDITOR_ACTIVATED,!1),r&&i.enable()}},[i,c,e,r]),u.useEffect(()=>{e&&(d==null||d.setSkipLastEnabled(!1))},[e,d])},Yn=()=>{u.useEffect(()=>()=>{},[])},Gt=(e,t,n)=>{const r=s.useDependency(s.IUniverInstanceService),o=s.useDependency(j.SheetsSelectionsService);return u.useCallback(()=>{if(e){const i=[...o.getWorkbookSelections(t).getSelectionsOfWorksheet(n)],a=r.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),f=a==null?void 0:a.getActiveSheet();f&&f.getSheetId()===n&&o.setSelections(i)}},[e,o,n,t,r])},St=e=>typeof e=="string"?e===b.matchToken.COMMA:!1,zn=e=>{if(typeof e=="object")return e.nodeType===b.sequenceNodeType.REFERENCE},Gn=e=>e.filter(t=>St(t)||zn(t)),gt=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},_e=e=>e.map(t=>typeof t=="string"?t:t.token).join("");function Zt(e,t,n){var r,o;return((o=(r=e.getUnit(t))==null?void 0:r.getSheetBySheetId(n))==null?void 0:o.getName())||""}const Ie=(e,t=!1,n="")=>t?e.map(r=>r.sheetName!==""&&r.sheetName!==n?b.serializeRangeWithSheet(r.sheetName,r.range):b.serializeRange(r.range)):e.map(r=>b.serializeRange(r.range)),Xt=(e,t,n,r,o,c,i)=>{const a=s.useDependency(G.IRenderManagerService),f=s.useDependency(s.IUniverInstanceService),d=u.useRef(!1),h=a.getRenderById(t),p=h==null?void 0:h.with(W.RefSelectionsRenderService),m=u.useRef([]),v=u.useMemo(()=>{const g=Gn(r),E=m.current;return g.length===E.length?(E.splice(0),E.push(...g),E):g},[r]);m.current=v;const l=u.useRef(void 0);u.useEffect(()=>{if(e&&p){let g=!0;const E=(y,D)=>{var M;if(g||d.current){g=!1;return}const A=[...y],F=f.getUnit(t),L=((M=F==null?void 0:F.getActiveSheet())==null?void 0:M.getName())||"",x=v.map((S,T)=>{if(typeof S=="string"){if(!v[T-1])return null;const H=v[T+1];return St(S)&&(St(H)||T===v.length-1)?null:S}else if(S.nodeType===b.sequenceNodeType.REFERENCE){const P=b.deserializeRangeWithSheet(S.token);P.unitId=P.unitId===""?t:P.unitId,P.sheetName=P.sheetName===""?L:P.sheetName;const{unitId:H,sheetName:V}=P;if(c&&(H!==t||L!==V))return null;if(H===t&&L===V){const Z=A.shift();if(Z&&Zt(f,t,Z.rangeWithCoord.sheetId||"")===V){const z={...S};return gt(Z.rangeWithCoord),o?z.token=b.serializeRangeWithSheet(L,Z.rangeWithCoord):z.token=b.serializeRange(Z.rangeWithCoord),z}}return S}return null}).filter(S=>!!S),w=Ie(A.map(S=>{var T,P,H;return{range:S.rangeWithCoord,unitId:(T=S.rangeWithCoord.unitId)!=null?T:"",sheetName:Zt(f,(P=S.rangeWithCoord.unitId)!=null?P:"",(H=S.rangeWithCoord.sheetId)!=null?H:"")}}),o).join(b.matchToken.COMMA),N=_e(x),O=`${N}${N&&w?b.matchToken.COMMA:""}${w}`,$=d.current;i(O,$?-1:O.length,D)},R=p.selectionMoveEnd$.subscribe(y=>{if(E(y,!0),d.current=!1,l.current){const{result:D,offset:A}=l.current;i(D,A,!0),l.current=void 0}}),I=p.selectionMoving$.pipe(Be.throttleTime(50)).subscribe(y=>{E(y,!1)});return()=>{R.unsubscribe(),I.unsubscribe()}}},[e,v,p,o,c,i,f,t]),u.useEffect(()=>{if(e&&p){const g=new s.DisposableCollection,E=(y,D)=>{var $;let A=0,F=0,L=!1;const x=f.getUnit(t),w=(($=x==null?void 0:x.getActiveSheet())==null?void 0:$.getName())||"",N=v.map(M=>{if(typeof M=="string")return L||(F+=M.length),M;if(M.nodeType===b.sequenceNodeType.REFERENCE){const S=b.deserializeRangeWithSheet(y);if(S.unitId=S.unitId===""?t:S.unitId,S.sheetName=S.sheetName===""?w:S.sheetName,A===D){L=!0;const T={...M,token:y};return o?T.token=b.serializeRangeWithSheet(S.sheetName,S.range):T.token=b.serializeRange(S.range),A++,F+=T.token.length,T}return A++,L||(F+=M.token.length),M}return M}),O=_e(N);l.current={result:O,offset:F},i(O,-1,!1)};let R=0;const I=p.selectionMoveEnd$.subscribe(()=>{R=setTimeout(()=>{g.dispose(),p.getSelectionControls().forEach((D,A)=>{g.add(q.merge(D.selectionMoving$,D.selectionScaling$).pipe(q.map(F=>b.serializeRange(F)),q.distinctUntilChanged()).subscribe(F=>{d.current=!0,E(F,A)}))})},30)});return()=>{I.unsubscribe(),g.dispose(),clearTimeout(R)}}},[e,p,v,i,f,t,o])},vt=(e,t,n,r,o,c)=>{const i=s.useDependency(s.ICommandService),a=s.useDependency(te.IEditorService),d=s.useDependency(G.IRenderManagerService).getRenderById(t),h=d==null?void 0:d.with(W.RefSelectionsRenderService);u.useEffect(()=>{if(e&&h)if(n){const p=i.onCommandExecuted(m=>{if(m.id===j.SetWorksheetActiveOperation.id){const v=h.getSelectionControls().length;for(let l=1;l<=v;l++)h.clearLastSelection();setTimeout(()=>{c()},30)}});return()=>{p.dispose()}}else{const p=i.beforeCommandExecuted(m=>{if(m.id===j.SetWorksheetActiveOperation.id){r(!1),o(),c();const v=a.getEditor(s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);v==null||v.focus()}});return()=>{p.dispose()}}},[e,h])},Jt=e=>!e.some(n=>{if(typeof n=="string"){if(n!==b.matchToken.COMMA)return!0}else if(n.nodeType!==b.sequenceNodeType.REFERENCE)return!0;return!1}),Zn=(e,t,n)=>{const r=u.useRef(!0);u.useEffect(()=>{if(e){const o=setTimeout(()=>{r.current=!1},500);return()=>{clearTimeout(o)}}},[e]),u.useEffect(()=>{if(!r.current&&t){const o=Jt(n);t(o,_e(n))}},[n,t])},Ee={sheetRangeSelectorTextWrap:"univer-sheet-range-selector-text-wrap",sheetRangeSelectorPlaceholder:"univer-sheet-range-selector-placeholder",sheetRangeSelectorError:"univer-sheet-range-selector-error",sheetRangeSelectorErrorWrap:"univer-sheet-range-selector-error-wrap",sheetRangeSelectorText:"univer-sheet-range-selector-text",sheetRangeSelectorActive:"univer-sheet-range-selector-active",sheetRangeSelectorIcon:"univer-sheet-range-selector-icon",sheetRangeSelectorDialogItem:"univer-sheet-range-selector-dialog-item",sheetRangeSelectorDialogItemDelete:"univer-sheet-range-selector-dialog-item-delete"},Ue=()=>{};function Qt(e){const{initValue:t,unitId:n,subUnitId:r,errorText:o,placeholder:c,actions:i,onChange:a=Ue,onVerify:f=Ue,onRangeSelectorDialogVisibleChange:d=Ue,onBlur:h=Ue,onFocus:p=Ue,isFocus:m=!0,isOnlyOneRange:v=!1,isSupportAcrossSheet:l=!1}=e,g=_.useEvent(a),E=s.useDependency(te.IEditorService),R=s.useDependency(s.LocaleService),I=s.useDependency(s.ICommandService),y=s.useDependency(b.LexerTreeBuilder),D=u.useRef(null),[A,F]=u.useState(!1),[L,x]=u.useState(m),w=u.useMemo(()=>s.createInternalEditorID(`${k.RANGE_SELECTOR_SYMBOLS}-${s.generateRandomId(4)}`),[]),N=u.useRef(void 0),O=N.current,$=u.useRef(null),M=s.useDependency(s.IUniverInstanceService),S=u.useMemo(()=>!A&&L,[A,L]),[T,P]=u.useState(()=>typeof t=="string"?t:Ie(t,l).join(b.matchToken.COMMA)),H=u.useMemo(()=>M.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_DOC),[M]),V=s.useObservable(H),Z=(V==null?void 0:V.getUnitId())===w,z=u.useRef([]),K=_.useEvent((B,U)=>{D.current&&!A&&!D.current.contains(B.target)&&U()});i&&(i.handleOutClick=K);const pe=u.useMemo(()=>T.split(b.matchToken.COMMA).filter(B=>!!B).map(B=>b.deserializeRangeWithSheet(B)),[T]),Q=u.useMemo(()=>o!==void 0,[o]),oe=Gt(!A&&L,n,r);u.useMemo(()=>B=>{const U=y.sequenceNodesBuilder(B);if(U){if(Jt(U)){const X=U.map(ce=>{if(typeof ce=="string")return ce;if(ce.nodeType===b.sequenceNodeType.REFERENCE){const xe={...ce},be=b.deserializeRangeWithSheet(ce.token);return be.range=gt(be.range),l||(be.sheetName="",be.unitId=""),xe.token=Ie([be],l)[0],xe}return ce}),ee=_e(X);g(ee)}}else P("")},[l]);const Y=Vt(O),{checkScrollBar:re}=te.useResize(O,!0,!0),de=et(),Ce=u.useMemo(()=>de(T),[T]),se=Ut(),Se=mt(n,r),le=_.useEvent((B,U=!0,J=!0)=>{if(!N.current)return;const X=de(B),ee=se(N.current,X,U);z.current=ee,J&&Se(ee,N.current)});u.useEffect(()=>{const B=I.onCommandExecuted(U=>{var J,X;if(U.id===lt.RichTextEditingMutation.id){const ee=U.params,{unitId:ce}=ee;ce===w&&g(s.BuildTextUtils.transform.getPlainText((X=(J=O==null?void 0:O.getDocumentData().body)==null?void 0:J.dataStream)!=null?X:""))}});return()=>B.dispose()},[I,O,w,g]);const ye=_.useEvent((B,U,J)=>{le(B),P(B),J&&(Y(),U!==-1&&setTimeout(()=>{const X={startOffset:U,endOffset:U};O==null||O.setSelectionRanges([X]);const ee=O==null?void 0:O.render.with(te.DocBackScrollRenderController);ee==null||ee.scrollToRange({...X,collapsed:!0})},50),re())});Xt(S,n,r,Ce,l,v,ye),pt(S,S&&Z,n),zt(n,v),Vn(n,T,O),Zn(S,f,Ce),Yt(S,0,O),Yn(),vt(S,n,l,x,h,()=>{S&&le(T)}),u.useEffect(()=>{if(O){const B=O.input$.pipe(q.throttleTime(100)).subscribe(U=>{var X,ee;const J=((ee=(X=U.data.body)==null?void 0:X.dataStream)!=null?ee:"").replaceAll(/\n|\r/g,"").replaceAll(/,{2,}/g,",").replaceAll(/(^,)/g,"");le(J,!1),P(J)});return()=>{B.unsubscribe()}}},[O]),u.useEffect(()=>{const B=I.onCommandExecuted(U=>{U.id===k.SetCellEditVisibleOperation.id&&(F(!1),d(!1),x(!1),h())});return()=>{B.dispose()}},[l]),u.useLayoutEffect(()=>{let B;if($.current){B=E.register({autofocus:!0,editorUnitId:w,initialSnapshot:{id:w,body:{dataStream:`${T}\r
5
+ `,textRuns:[]},documentStyle:{}}},$.current);const U=E.getEditor(w);N.current=U,le(T,!1,!1)}return()=>{B==null||B.dispose()}},[]),u.useLayoutEffect(()=>{m?(x(m),Y()):(O==null||O.blur(),oe(),x(m))},[m,Y]),Kn(T,"",L,se,Se,O);const he=()=>{p(),Y(),x(!0)},ge=B=>{const U=Ie(B,l).join(b.matchToken.COMMA);U||O==null||O.setDocumentData({...O.getDocumentData(),body:{dataStream:`\r
6
+ `,textRuns:[]}}),le(U),P(U),F(!1),d(!1),setTimeout(()=>{x(!0),O==null||O.setSelectionRanges([{startOffset:U.length,endOffset:U.length}]),Y(),re()},30)},Pe=()=>{F(!1),d(!1),setTimeout(()=>{x(!0),Y()},30)},Te=()=>{Q||(Y(),setTimeout(()=>{F(!0),d(!0),x(!1)},30))};return C.jsxs("div",{className:Ee.sheetRangeSelector,ref:D,children:[C.jsxs("div",{className:ht(Ee.sheetRangeSelectorTextWrap,{[Ee.sheetRangeSelectorActive]:L&&!Q,[Ee.sheetRangeSelectorError]:Q}),children:[C.jsx("div",{className:Ee.sheetRangeSelectorText,ref:$,onMouseUp:he}),C.jsx(me.Tooltip,{title:R.t("rangeSelector.buttonTooltip"),placement:"bottom",children:C.jsx(Wt,{className:Ee.sheetRangeSelectorIcon,onClick:Te})}),o!==void 0?C.jsx("div",{className:Ee.sheetRangeSelectorErrorWrap,children:o}):null,c!==void 0&&!T?C.jsx("div",{className:Ee.sheetRangeSelectorPlaceholder,children:c}):null]}),A&&C.jsx(Xn,{editorId:w,handleConfirm:ge,handleClose:Pe,unitId:n,subUnitId:r,initValue:pe,visible:A,isOnlyOneRange:v,isSupportAcrossSheet:l})]})}function Xn(e){const{handleConfirm:t,handleClose:n,visible:r,initValue:o,unitId:c,subUnitId:i,isOnlyOneRange:a,isSupportAcrossSheet:f}=e,d=s.useDependency(s.LocaleService),h=s.useDependency(Ne.IDescriptionService),p=s.useDependency(b.LexerTreeBuilder),v=s.useDependency(G.IRenderManagerService).getRenderById(c),l=v==null?void 0:v.with(W.RefSelectionsRenderService),[g,E]=u.useState(()=>{if(a){const S=o[0];return S?Ie([S],f):[""]}return Ie(o,f)}),[R,I]=u.useState(()=>g.length-1),y=jt(),D=u.useMemo(()=>g.join(b.matchToken.COMMA),[g]),A=et(),F=u.useMemo(()=>A(D),[D]),L=u.useMemo(()=>qt(h,y,F).refSelections,[F]),x=()=>{E([]),setTimeout(()=>{n()},30)},w=(S,T)=>{T?l==null||l.setSkipLastEnabled(!1):l==null||l.setSkipLastEnabled(!0),E(P=>{const H=[...P];return H[S]=T,H})},N=S=>{l==null||l.setSkipLastEnabled(!1),E(T=>{if(T.length===1)return T;const P=[];return T.forEach((H,V)=>{S!==V&&P.push(H)}),P})},O=()=>{l==null||l.setSkipLastEnabled(!0),E(S=>(S.push(""),I(S.length-1),[...S]))},$=_.useEvent(S=>{var P;l==null||l.setSkipLastEnabled(!1);const T=S.split(b.matchToken.COMMA).filter(H=>!!H);E(a?[(P=T[0])!=null?P:""]:T)}),M=mt(c,i);return Xt(R>=0,c,i,F,f,a,$),pt(R>=0,R>=0,c),zt(c,a),vt(R>=0,c,f,q.noop,q.noop,()=>M(L)),u.useEffect(()=>{M(L)},[L]),u.useEffect(()=>{(g.length===0||g.length===1&&!g[0])&&(l==null||l.setSkipLastEnabled(!0))},[g]),C.jsx(me.Dialog,{width:"328px",visible:r,title:d.t("rangeSelector.title"),draggable:!0,closeIcon:C.jsx(Qe,{}),footer:C.jsxs("footer",{children:[C.jsx(me.Button,{onClick:x,children:d.t("rangeSelector.cancel")}),C.jsx(me.Button,{style:{marginLeft:10},onClick:()=>t(g.filter(S=>{const T=p.sequenceNodesBuilder(S);return T&&T.length===1&&typeof T[0]!="string"&&T[0].nodeType===b.sequenceNodeType.REFERENCE}).map(S=>b.deserializeRangeWithSheet(S)).map(S=>({...S,range:gt(S.range)}))),type:"primary",children:d.t("rangeSelector.confirm")})]}),onClose:x,children:C.jsxs("div",{className:Ee.sheetRangeSelectorDialog,children:[g.map((S,T)=>C.jsxs("div",{className:Ee.sheetRangeSelectorDialogItem,children:[C.jsx(me.Input,{affixWrapperStyle:{width:"100%"},placeholder:d.t("rangeSelector.placeHolder"),onFocus:()=>I(T),value:S,onChange:P=>w(T,P)},`input_${T}`),g.length>1&&!a&&C.jsx(kt,{className:Ee.sheetRangeSelectorDialogItemDelete,onClick:()=>N(T)})]},`${S}_${T}`)),!a&&C.jsx("div",{children:C.jsxs(me.Button,{type:"link",size:"small",onClick:O,children:[C.jsx(Ht,{}),C.jsx("span",{children:d.t("rangeSelector.addAnotherRange")})]})})]})})}function Jn(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 Ct(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},...`}const Qn=(e,t=100)=>{u.useEffect(()=>{let n=null;const r=()=>{n===null&&(n=window.setTimeout(()=>{e(),n=null},t))};return window.addEventListener("scroll",r),window.addEventListener("resize",r),()=>{n!==null&&clearTimeout(n),window.removeEventListener("scroll",r),window.removeEventListener("resize",r)}},[e,t])};function en(e,t,n){const r=s.useDependency(te.IEditorService),o=u.useMemo(()=>new q.BehaviorSubject({left:-999,top:-999,right:-999,bottom:-999}),[]),c=s.useDependency(_.ISidebarService),i=s.useDependency(s.IUniverInstanceService),a=_.useEvent(()=>{const f=r.getEditor(e);if(!f)return;const d=f.getBoundingClientRect(),{left:h,top:p,right:m,bottom:v}=d,l=o.getValue();if(!(l.left===h&&l.top===p&&l.right===m&&l.bottom===v))return o.next({left:h-1,right:m+1,top:p-1,bottom:v+1}),d});return u.useEffect(()=>{t&&a()},[e,r,i.unitAdded$,a,t,...n!=null?n:[]]),Qn(a),u.useEffect(()=>{const f=c.scrollEvent$.pipe(q.throttleTime(100)).subscribe(a);return()=>{f.unsubscribe()}},[]),[o,a]}const je=e=>{const t=u.useRef(e);return t.current=e,t},eo=(e,t,n)=>{const r=s.useDependency(Ne.IDescriptionService),o=s.useDependency(b.LexerTreeBuilder),[c,i]=u.useState(),[a,f]=u.useState(-1),[d,h]=u.useState(!0),p=je(d),m=u.useRef(t);m.current=t;const v=()=>{i(void 0),f(-1),h(!1)};return u.useEffect(()=>{if(n&&e){const l=n.selectionChange$.pipe(q.debounceTime(50)).subscribe(E=>{if(E.textRanges.length===1){const[R]=E.textRanges;if(R.collapsed&&p.current){const I=o.getFunctionAndParameter(`${m.current}A`,R.startOffset-1);if(I){const{functionName:y,paramIndex:D}=I,A=r.getFunctionInfo(y);i(A),f(D);return}}}i(void 0),f(-1)}),g=n.selectionChange$.pipe(q.filter(E=>E.isEditing),q.filter(E=>E.textRanges.length===1),q.map(E=>E.textRanges[0].startOffset),q.distinctUntilChanged()).subscribe(()=>{h(!0)});return()=>{l.unsubscribe(),g.unsubscribe()}}},[n,e]),u.useEffect(()=>{e||v()},[e]),{functionInfo:c,paramIndex:a,reset:v}},ae={formulaHelpFunction:"univer-formula-help-function",formulaHelpFunctionTitle:"univer-formula-help-function-title",formulaHelpFunctionTitleIcons:"univer-formula-help-function-title-icons",formulaHelpFunctionTitleIcon:"univer-formula-help-function-title-icon",formulaHelpFunctionContent:"univer-formula-help-function-content",formulaHelpFunctionContentInner:"univer-formula-help-function-content-inner",formulaHelpFunctionContentParams:"univer-formula-help-function-content-params",formulaHelpFunctionContentParamsTitle:"univer-formula-help-function-content-params-title",formulaHelpFunctionContentParamsDetail:"univer-formula-help-function-content-params-detail",formulaHelpFunctionActive:"univer-formula-help-function-active",formulaHelpDecorator:"univer-formula-help-decorator",formulaHelpParam:"univer-formula-help-param",formulaHelpParamPrefix:"univer-formula-help-param-prefix",formulaHelpParamItem:"univer-formula-help-param-item",formulaHelpParamActive:"univer-formula-help-param-active"},It=({className:e,title:t,value:n})=>C.jsxs("div",{className:ae.formulaHelpFunctionContentParams,children:[C.jsx("div",{className:`
7
+ ${ae.formulaHelpFunctionContentParamsTitle}
16
8
  ${e}
17
- `,children:t}),v.jsx("div",{className:ce.formulaHelpFunctionContentParamsDetail,children:n})]}),oo=e=>{const{prefix:t,value:n,active:s,onClick:o}=e;return v.jsxs("div",{className:ce.formulaHelpParam,children:[v.jsxs("span",{className:ce.formulaHelpParamPrefix,children:[t,"("]}),n&&n.map((c,i)=>v.jsxs("span",{className:ce.formulaHelpParamItem,children:[v.jsx("span",{className:s===i?ce.formulaHelpFunctionActive:ce.formulaHelpParamActive,onClick:()=>o(i),children:Rt(c)}),i===n.length-1?"":","]},c.name)),")"]})},rn=()=>{};function so(e){const{onParamsSwitch:t=rn,onClose:n=rn,isFocus:s,editor:o,formulaText:c}=e,{functionInfo:i,paramIndex:a,reset:l}=no(s,c,o),m=f.useMemo(()=>!!i&&a>=0,[i,a]),[d,p]=f.useState(!0),h=r.useDependency(r.LocaleService),g=h.t("formula.prompt.required"),u=h.t("formula.prompt.optional"),S=o.getEditorId(),[I]=sn(S,m,[i,a]);function b(_){t&&t(_)}const C=()=>{l(),n()};return m&&i?v.jsx(E.RectPopup,{portal:!0,onClickOutside:()=>l(),anchorRect$:I,direction:"vertical",children:v.jsxs("div",{className:ce.formulaHelpFunction,children:[v.jsxs("div",{className:ce.formulaHelpFunctionTitle,children:[v.jsx(oo,{prefix:i.functionName,value:i.functionParameter,active:a,onClick:b}),v.jsxs("div",{className:ce.formulaHelpFunctionTitleIcons,children:[v.jsx("div",{className:ce.formulaHelpFunctionTitleIcon,style:{transform:d?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>p(!d),children:v.jsx(ht,{})}),v.jsx("div",{className:ce.formulaHelpFunctionTitleIcon,onClick:C,children:v.jsx(et,{})})]})]}),v.jsx("div",{className:ce.formulaHelpFunctionContent,style:{height:d?"unset":0,padding:d?"revert-layer":0},children:v.jsxs("div",{className:ce.formulaHelpFunctionContentInner,children:[v.jsx(Et,{title:h.t("formula.prompt.helpExample"),value:`${i.functionName}(${i.functionParameter.map(_=>_.example).join(",")})`}),v.jsx(Et,{title:h.t("formula.prompt.helpAbstract"),value:i.description}),i&&i.functionParameter&&i.functionParameter.map((_,T)=>v.jsx(Et,{className:a===T?ce.formulaHelpFunctionActive:"",title:_.name,value:`${_.require?g:u} ${_.detail}`},T))]})})]})}):null}const cn=(e,t,n=!0)=>{let s=-1;return e.reduce((o,c,i)=>{if(o.isFinish)return o;const a=o.currentIndex;if(typeof c!="string")o.currentIndex+=c.token.length;else{const l=c.length;o.currentIndex+=l}return(n?o.currentIndex===t:t>a&&t<=o.currentIndex)&&(s=i,o.isFinish=!0),o},{currentIndex:0,isFinish:!1}),s},ot=e=>e.reduce((t,n)=>typeof n=="string"?t+n.length:t+n.token.length,0),ro=()=>{},io=(e,t,n,s,o,c,i,a,l,m,d=ro)=>{const p=r.useDependency(X.IRenderManagerService),h=r.useDependency(r.IUniverInstanceService),g=r.useDependency(r.ICommandService),u=Ye(c),S=r.useDependency(ut.DocSelectionManagerService),I=r.useDependency(r.ThemeService),b=h.getUnit(s),C=E.useEvent(y=>{var R,D;return(D=(R=b==null?void 0:b.getSheetBySheetId(y))==null?void 0:R.getName())!=null?D:""}),_=f.useMemo(()=>C(o),[C,o]),T=r.useObservable(b==null?void 0:b.activeSheet$),x=Ye({activeSheet:T,sheetName:_}),F=p.getRenderById(s),P=F==null?void 0:F.with(W.RefSelectionsRenderService),L=F==null?void 0:F.with(w.SheetSkeletonManagerService),j=r.useDependency(K.IRefSelectionsService),O=f.useRef(!1),M=f.useRef(n);M.current=n;const k=f.useRef();f.useEffect(()=>{if(P&&e){let y=!0;const R=(A,H)=>{var ae,ne,U,ge,me,de;if(y){y=!1;return}const Z=m==null?void 0:m.getSelectionRanges();if((Z==null?void 0:Z.length)!==1)return;const z=Z[0].startOffset-1,Y=[...u.current],oe=cn(Y,z,!1);if(M.current===nt.NEED_ADD)if(z!==0){if(oe===-1&&Y.length)return;const se=A[A.length-1],Ee=Y.splice(oe+1),le=(ae=se.rangeWithCoord.sheetId)!=null?ae:o,ve={range:se.rangeWithCoord,unitId:(ne=se.rangeWithCoord.unitId)!=null?ne:s,sheetName:C(le)},Ce=Ie([ve],a&&le!==o,_);Y.push({token:Ce[0],nodeType:N.sequenceNodeType.REFERENCE});const xe=[...Y,...Ee],Fe=_e(xe);d(Fe,ot(Y),H)}else{const se=A[A.length-1],Ee=(U=se.rangeWithCoord.sheetId)!=null?U:o,le={range:se.rangeWithCoord,unitId:(ge=se.rangeWithCoord.unitId)!=null?ge:s,sheetName:C(Ee)},he=Ie([le],a&&Ee!==o);Y.unshift({token:he[0],nodeType:N.sequenceNodeType.REFERENCE});const Ce=_e(Y);d(Ce,he[0].length,H)}else{let se=0;const Ee=Y.map(V=>{var B,Q,q;if(typeof V=="string")return V;if(V.nodeType===N.sequenceNodeType.REFERENCE){const $=N.deserializeRangeWithSheet(V.token);if($.sheetName||($.sheetName=_),a&&((B=x.current.activeSheet)==null?void 0:B.getName())!==$.sheetName)return V.token;const ie=A[se];if(se++,!ie)return"";const je=(Q=ie.rangeWithCoord.sheetId)!=null?Q:o,Te={range:ie.rangeWithCoord,unitId:(q=ie.rangeWithCoord.unitId)!=null?q:s,sheetName:C(je)};return Ie([Te],a,_)[0]}return V.token});let le="",ve;Ee.forEach((V,B)=>{le+=V,B===oe&&(ve=le.length)});const he=[];for(let V=se;V<=A.length-1;V++){const B=A[V],Q=(me=B.rangeWithCoord.sheetId)!=null?me:o,q={range:B.rangeWithCoord,unitId:(de=B.rangeWithCoord.unitId)!=null?de:s,sheetName:C(Q)},ie=Ie([q],a&&Q!==o,_);he.push(ie[0])}const Ce=Y[Y.length-1],xe=Ce&&(typeof Ce=="string"?!1:Ce.nodeType===N.sequenceNodeType.REFERENCE),Fe=`${le}${he.length&&xe?",":""}${he.join(",")}`;d(Fe,!he.length&&ve?ve:Fe.length,H)}},D=new r.DisposableCollection;return D.add(P.selectionMoving$.subscribe(A=>{O.current||R(A,!1)})),D.add(P.selectionMoveEnd$.subscribe(A=>{O.current||R(A,!0)})),()=>{D.dispose()}}},[P,m,a,e,u,o,s,C,_,d,x]),f.useEffect(()=>{if(t&&P&&m){const y=new r.DisposableCollection,R=(H,Z)=>{let J=0,z=0,Y=!1;const{sheetName:oe}=x.current,ae=u.current.map(U=>{var ge;if(typeof U=="string")return Y||(z+=U.length),U;if(U.nodeType===N.sequenceNodeType.REFERENCE){const me=N.deserializeRangeWithSheet(U.token);if(me.unitId||(me.unitId=s),me.sheetName||(me.sheetName=oe),a&&((ge=x.current.activeSheet)==null?void 0:ge.getName())!==me.sheetName)return Y||(z+=U.token.length),U;if(J===Z){Y=!0;const de={...U,token:H};return a&&me.sheetName!==oe?de.token=N.serializeRangeWithSheet(me.sheetName,N.deserializeRangeWithSheet(H).range):de.token=H,z+=de.token.length,J++,de}return Y||(z+=U.token.length),J++,U}return Y||(z+=U.token.length),U}),ne=_e(ae);d(ne,-1,!0),k.current={result:ne,offset:z}},D=()=>{y.dispose(),P.getSelectionControls().forEach((Z,J)=>{y.add(G.merge(Z.selectionMoving$,Z.selectionScaling$).pipe(Be.map(z=>N.serializeRange(z)),Be.distinctUntilChanged(),Be.debounceTime(100)).subscribe(z=>{O.current=!0,R(z,J)}))}),y.add(P.selectionMoveEnd$.subscribe(Z=>{if(O.current=!1,k.current){const{result:J,offset:z}=k.current;d(J,z||-1,!0),k.current=void 0}}))},A=G.merge(m.input$,j.selectionSet$,P.selectionMoveEnd$).pipe(Be.debounceTime(50)).subscribe(()=>{D()});return()=>{A.unsubscribe(),y.dispose()}}},[t,P,m,j.selectionSet$,x,u,d,a,s]),f.useEffect(()=>{if(l){const y=g.onCommandExecuted(R=>{if(R.id!==K.SetSelectionsOperation.id)return;const D=R.params;if(D.extra!=="formula-editor")return;const{selections:A}=D;if(A.length){const H=A[A.length-1];if(H){const Z=H.range,J=o,z={range:Z,unitId:D.unitId===s?"":D.unitId,sheetName:D.subUnitId===J?"":C(J)},Y=[...u.current],ae=Ie([z],a,_)[0];let ne=Y[Y.length-1];if(typeof ne=="object"&&ne.nodeType===N.sequenceNodeType.REFERENCE){ne={...ne},ne.token=ae,ne.endIndex=ne.startIndex+ae.length,Y[Y.length-1]=ne;const U=_e(Y);d(U,ot(Y),!0)}else{const U=ot(Y);Y.push({nodeType:N.sequenceNodeType.REFERENCE,token:ae,startIndex:U,endIndex:U+ae.length});const ge=_e(Y);d(ge,ot(Y),!0)}}}});return()=>{y.dispose()}}},[g,C,d,a,l,u,_,o,s]),f.useEffect(()=>{if(!m)return;const y=S.textSelection$.subscribe(R=>{R.unitId===m.getEditorId()&&Gt({unitId:s,subUnitId:o,refSelections:i.current,editor:m,refSelectionsService:j,refSelectionsRenderService:P,sheetSkeletonManagerService:L,themeService:I,univerInstanceService:h})});return()=>y.unsubscribe()},[S.textSelection$,m,i,P,j,u,L,o,I,s,h])},co=(e,t,n)=>{const s=r.useDependency(N.LexerTreeBuilder),o=f.useRef(!0);f.useEffect(()=>{if(e){const c=setTimeout(()=>{o.current=!1},500);return()=>{clearTimeout(c)}}},[e]),f.useEffect(()=>{if(!o.current&&t){const c=s.checkIfAddBracket(n);t(c===0&&n.startsWith(N.operatorToken.EQUALS),`${n}`)}},[n,t])},ke={sheetEmbeddingFormulaEditorActive:"univer-sheet-embedding-formula-editor-active",sheetEmbeddingFormulaEditorWrap:"univer-sheet-embedding-formula-editor-wrap",sheetEmbeddingFormulaEditorText:"univer-sheet-embedding-formula-editor-text",sheetEmbeddingFormulaEditorError:"univer-sheet-embedding-formula-editor-error",sheetEmbeddingFormulaEditor:"univer-sheet-embedding-formula-editor",sheetEmbeddingFormulaEditorErrorWrap:"univer-sheet-embedding-formula-editor-error-wrap"},ao=(e,t=[],n)=>{const s=r.useDependency(Ne.IDescriptionService),[o,c]=f.useState([]),[i,a]=f.useState(""),l=f.useRef(-1),m=Ye({nodes:t}),d=()=>{c([]),a(""),l.current=-1};return f.useEffect(()=>{if(n&&e){const h=n.input$.pipe(G.debounceTime(300)).subscribe(()=>{const g=n.getSelectionRanges();if(g.length===1){const u=m.current.nodes,S=g[0];if(S.collapsed){const I=cn(u,S.startOffset-1,!1);l.current=I;const b=u[I];if(b&&typeof b!="string"&&b.nodeType===N.sequenceNodeType.FUNCTION){l.current=I;const C=b.token,_=s.getSearchListByNameFirstLetter(C);c(_),a(C);return}}}l.current=-1,a(""),c(u=>u!=null&&u.length?[]:u)});return()=>{h.unsubscribe()}}},[n,e]),f.useEffect(()=>{e||d()},[e]),{searchList:o,searchText:i,handlerFormulaReplace:h=>{const g=[...m.current.nodes];if(l.current!==-1){const u=g.splice(l.current+1),S=g.pop()||"";let I=(typeof S=="string"?S.length:S.token.length)-h.length;return g.push(h),u[0]!==N.matchToken.OPEN_BRACKET&&(g.push(N.matchToken.OPEN_BRACKET),I--),{text:_e([...g,...u]),offset:I}}},reset:d}},Oe={formulaSearchFunction:"univer-formula-search-function",formulaSearchFunctionItem:"univer-formula-search-function-item",formulaSearchFunctionItemName:"univer-formula-search-function-item-name",formulaSearchFunctionItemNameLight:"univer-formula-search-function-item-name-light",formulaSearchFunctionItemDesc:"univer-formula-search-function-item-desc",formulaSearchFunctionItemActive:"univer-formula-search-function-item-active"},lo=()=>{},uo=f.forwardRef(fo);function fo(e,t){const{isFocus:n,sequenceNodes:s,onSelect:o,editor:c,onClose:i=lo}=e,a=c.getEditorId(),l=r.useDependency(E.IShortcutService),m=r.useDependency(r.ICommandService),{searchList:d,searchText:p,handlerFormulaReplace:h,reset:g}=ao(n,s,c),u=f.useMemo(()=>!!d.length,[d]),S=f.useRef(),[I,b]=f.useState(0),C=f.useRef(!1),[_]=sn(a,u,[p,d]),T=Ye({searchList:d,active:I}),x=O=>{const M=h(O);M&&(g(),o(M))};function F(O){C.current&&b(O)}function P(){C.current&&b(-1)}f.useEffect(()=>{if(!d.length)return;const O=`sheet.formula-embedding-editor.search_function.${a}`,M=new r.DisposableCollection,k=y=>{const{searchList:R,active:D}=T.current;switch(y){case E.KeyCode.ARROW_UP:{b(A=>{const H=Math.max(0,A-1);return L(H),H});break}case E.KeyCode.ARROW_DOWN:{b(A=>{const H=Math.min(R.length-1,A+1);return L(H),H});break}case E.KeyCode.TAB:case E.KeyCode.ENTER:{const A=R[D];x(A.name);break}case E.KeyCode.ESC:{g(),i();break}}};return M.add(m.registerCommand({id:O,type:r.CommandType.OPERATION,handler(y,R){const{keyCode:D}=R;k(D)}})),[E.KeyCode.ARROW_UP,E.KeyCode.ARROW_DOWN,E.KeyCode.ENTER,E.KeyCode.ESC,E.KeyCode.TAB].map(y=>({id:O,binding:y,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:X.DeviceInputEventType.Keyboard,keyCode:y}})).forEach(y=>{M.add(l.registerShortcut(y))}),()=>{M.dispose()}},[d]);function L(O){var z;const M=(z=S.current)==null?void 0:z.querySelectorAll(`.${Oe.formulaSearchFunctionItem}`)[O];if(!M)return;const k=M.parentNode;if(!k)return;const R=k.getBoundingClientRect().top,D=k.offsetHeight,A=M.getBoundingClientRect(),H=A.top,Z=A.height;if(H>=0&&H>R&&H-R+Z<=D)return;const J=M.offsetTop-(D-Z)/2;k.scrollTo({top:J,behavior:"smooth"})}const j=f.useMemo(()=>{let O="";return()=>{clearTimeout(O),C.current=!0,O=setTimeout(()=>{C.current=!1},300)}},[]);return d.length>0&&u&&v.jsx(E.RectPopup,{portal:!0,anchorRect$:_,direction:"vertical",children:v.jsx("ul",{className:Oe.formulaSearchFunction,ref:O=>{S.current=O,t&&(t.current=O)},children:d.map((O,M)=>v.jsxs("li",{className:I===M?`
18
- ${Oe.formulaSearchFunctionItem}
19
- ${Oe.formulaSearchFunctionItemActive}
20
- `:Oe.formulaSearchFunctionItem,onMouseEnter:()=>F(M),onMouseLeave:P,onMouseMove:j,onClick:()=>{x(O.name),c&&c.focus()},children:[v.jsxs("span",{className:Oe.formulaSearchFunctionItemName,children:[v.jsx("span",{className:Oe.formulaSearchFunctionItemNameLight,children:O.name.substring(0,p.length)}),v.jsx("span",{children:O.name.slice(p.length)})]}),v.jsx("span",{className:Oe.formulaSearchFunctionItemDesc,children:O.desc})]},O.name))})})}const mo=e=>e.startsWith(N.operatorToken.EQUALS)?e.slice(1):"",_t=()=>{};function an(e){var Ot,vn;const{errorText:t,initValue:n,unitId:s,subUnitId:o,isFocus:c=!0,isSupportAcrossSheet:i=!1,onFocus:a=_t,onBlur:l=_t,onChange:m,onVerify:d,actions:p,className:h,editorId:g,moveCursor:u=!0,onFormulaSelectingChange:S,keyboradEventConfig:I,onMoveInEditor:b,resetSelectionOnBlur:C=!0,autoScrollbar:_=!0,isSingle:T=!0,disableSelectionOnClick:x=!1,disableContextMenu:F}=e,P=r.useDependency(te.IEditorService),L=f.useRef(null),j=E.useEvent(m);p&&(p.handleOutClick=(ue,fe)=>{L.current&&!L.current.contains(ue.target)&&fe()});const O=E.useEvent(S),M=f.useRef(null),k=f.useRef(),y=k.current,[R,D]=f.useState(c),A=f.useRef(null),H=f.useMemo(()=>g!=null?g:r.createInternalEditorID(`${w.EMBEDDING_FORMULA_EDITOR}-${r.generateRandomId(4)}`),[]),Z=f.useMemo(()=>t!==void 0,[t]),J=r.useDependency(r.IUniverInstanceService),z=J.getUnit(H);r.useObservable(z==null?void 0:z.change$);const Y=tt(),oe=r.BuildTextUtils.transform.getPlainText((vn=(Ot=z==null?void 0:z.getBody())==null?void 0:Ot.dataStream)!=null?vn:""),ae=f.useMemo(()=>mo(oe),[oe]),ne=f.useMemo(()=>Y(ae),[ae,Y]),{isSelecting:U}=Zn(H,R,x),ge=f.useRef(""),de=r.useDependency(X.IRenderManagerService).getRenderById(H),se=de==null?void 0:de.with(te.DocSelectionRenderService),Ee=se==null?void 0:se.isFocusing,le=f.useMemo(()=>J.getCurrentTypeOfUnit$(r.UniverInstanceType.UNIVER_DOC),[J]),ve=r.useObservable(le),he=(ve==null?void 0:ve.getUnitId())===H,Ce=f.useRef([]),xe=U;E.useUpdateEffect(()=>{j(oe)},[oe,j]);const Fe=Zt("="),V=St(s,o),B=E.useEvent((ue,fe=!0,be,He)=>{if(!k.current)return;ge.current=ue;const Dt=Y(ue[0]==="="?ue.slice(1):""),We=Fe(k.current,Dt,fe,He);Ce.current=We,be&&V(R?We:[],k.current)});f.useEffect(()=>{R&&B(oe,!1,!0)},[oe,R,B]),co(R,d,oe);const Q=zt(y),q=$t(R,s,o);f.useEffect(()=>{O(U)},[O,U]),te.useKeyboardEvent(R,I,y),f.useLayoutEffect(()=>{let ue;if(A.current){ue=P.register({autofocus:!0,editorUnitId:H,initialSnapshot:{id:H,body:{dataStream:`${n}\r
21
- `,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},A.current);const fe=P.getEditor(H);k.current=fe,B(n,!1,!0)}return()=>{ue==null||ue.dispose()}},[]),f.useLayoutEffect(()=>{c?(D(c),Q()):(C&&(y==null||y.blur(),q()),D(c))},[c,y,Q,q,C]);const{checkScrollBar:$}=te.useResize(y,T,_);gt(R,!!(U&&he),s,F),Qt(R&&u,xe,y,b);const ie=E.useEvent((ue,fe,be)=>{if(!Ee)return;const He=fe!==-1?[{startOffset:fe+1,endOffset:fe+1,collapsed:!0}]:void 0;B(`=${ue}`,!0,be,He),be&&(Q(),fe!==-1&&setTimeout(()=>{const Dt={startOffset:fe+1,endOffset:fe+1},We=y==null?void 0:y.render.with(te.DocBackScrollRenderController);We==null||We.scrollToRange({...Dt,collapsed:!0})},50),$())});io(R&&!!(U&&he),R,U,s,o,ne,Ce,i,!!xe,y,ie),It(R&&!!(U&&he),s,i,D,l,_t);const je=ue=>{if(ue){const fe=y==null?void 0:y.getSelectionRanges();if(fe&&fe.length===1){const be=fe[0];if(be.collapsed){const He=ue.offset;setTimeout(()=>{y==null||y.setSelectionRanges([{startOffset:be.startOffset-He,endOffset:be.endOffset-He}])},30)}}Q(),B(`=${ue.text}`)}},Te=()=>{D(!0),a(),Q()};return v.jsxs("div",{className:pt(ke.sheetEmbeddingFormulaEditor,h),children:[v.jsx("div",{className:pt(ke.sheetEmbeddingFormulaEditorWrap,{[ke.sheetEmbeddingFormulaEditorActive]:R,[ke.sheetEmbeddingFormulaEditorError]:Z}),ref:L,children:v.jsx("div",{className:ke.sheetEmbeddingFormulaEditorText,ref:A,onMouseUp:Te})}),t!==void 0?v.jsx("div",{className:ke.sheetEmbeddingFormulaEditorErrorWrap,children:t}):null,y?v.jsx(so,{editor:y,isFocus:R,formulaText:oe,onClose:()=>Q()}):null,y?v.jsx(uo,{isFocus:R,sequenceNodes:ne,onSelect:je,ref:M,editor:y}):null]})}const ho="sheets-formula-ui.base.config",ln={};function po(e){return e.getContextValue(r.FOCUSING_DOC)&&e.getContextValue(r.FOCUSING_UNIVER_EDITOR)}function un(e,t=!1){return!t&&!(r.isFormulaString(e==null?void 0:e.f)||r.isFormulaId(e==null?void 0:e.si))?null:typeof(e==null?void 0:e.v)=="string"&&N.ERROR_TYPE_SET.has(e.v)?e.v:null}var So=Object.defineProperty,go=Object.getOwnPropertyDescriptor,vo=(e,t,n,s)=>{for(var o=s>1?void 0:s?go(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(s?i(t,n,o):i(o))||o);return s&&o&&So(t,n,o),o},ze=(e,t)=>(n,s)=>t(n,s,e);const yt="SHEET_FORMULA_ALERT",Co={[N.ErrorType.DIV_BY_ZERO]:"divByZero",[N.ErrorType.NAME]:"name",[N.ErrorType.VALUE]:"value",[N.ErrorType.NUM]:"num",[N.ErrorType.NA]:"na",[N.ErrorType.CYCLE]:"cycle",[N.ErrorType.REF]:"ref",[N.ErrorType.SPILL]:"spill",[N.ErrorType.CALC]:"calc",[N.ErrorType.ERROR]:"error",[N.ErrorType.CONNECT]:"connect",[N.ErrorType.NULL]:"null"};let Tt=class extends r.Disposable{constructor(e,t,n,s,o,c){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=s,this._formulaDataModel=o,this._zenZoneService=c,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(G.debounceTime(100)).subscribe(e=>{var t,n,s,o,c;if(e){const a=this._context.unit.getActiveSheet();if(!a)return;const l=a.getCell(e.location.row,e.location.col),m=(o=(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:o[e.location.col];if(r.isICellData(l)){const d=un(l,!!m);if(!d){this._hideAlert();return}const p=this._cellAlertManagerService.currentAlert.get(yt),h=(c=p==null?void 0:p.alert)==null?void 0:c.location;if(h&&h.row===e.location.row&&h.col===e.location.col&&h.subUnitId===e.location.subUnitId&&h.unitId===e.location.unitId)return;this._cellAlertManagerService.showAlert({type:w.CellAlertType.ERROR,title:this._localeService.t("formula.error.title"),message:this._localeService.t(`formula.error.${Co[d]}`),location:e.location,width:200,height:74,key:yt});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(yt)}};Tt=vo([ze(1,r.Inject(w.HoverManagerService)),ze(2,r.Inject(w.CellAlertManagerService)),ze(3,r.Inject(r.LocaleService)),ze(4,r.Inject(N.FormulaDataModel)),ze(5,E.IZenZoneService)],Tt);var Io=Object.defineProperty,Ro=Object.getOwnPropertyDescriptor,Eo=(e,t,n,s)=>{for(var o=s>1?void 0:s?Ro(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(s?i(t,n,o):i(o))||o);return s&&o&&Io(t,n,o),o},fn=(e,t)=>(n,s)=>t(n,s,e);let st=class extends r.Disposable{constructor(e,t){super(),this._autoFillService=e,this._lexerTreeBuilder=t,this._registerAutoFill()}_registerAutoFill(){const e={type:w.DATA_TYPE.FORMULA,priority:1001,match:t=>r.isFormulaString(t==null?void 0:t.f)||r.isFormulaId(t==null?void 0:t.si),isContinue:(t,n)=>t.type===w.DATA_TYPE.FORMULA,applyFunctions:{[w.APPLY_TYPE.COPY]:(t,n,s,o)=>{const{data:c,index:i}=t;return this._fillCopyFormula(c,n,s,i,o)}}};this._autoFillService.registerRule(e)}_fillCopyFormula(e,t,n,s,o){var l,m;const c=yo(o),i=[],a=new Map;for(let d=1;d<=t;d++){const p=(d-1)%e.length,h=r.Tools.deepClone(e[p]);if(h){const g=((l=e[p])==null?void 0:l.f)||"",u=((m=e[p])==null?void 0:m.si)||"",S=r.isFormulaString(g);if(r.isFormulaId(u))h.si=u,h.f=null,h.v=null,h.p=null,h.t=null,i.push(h);else if(S){let b=a.get(p);if(b)h.si=b,h.f=null,h.v=null,h.p=null,h.t=null;else{b=r.Tools.generateRandomId(6),a.set(p,b);const{offsetX:C,offsetY:_}=_o(c,t,n),T=this._lexerTreeBuilder.moveFormulaRefOffset(g,C,_);h.si=b,h.f=T,h.v=null,h.p=null,h.t=null}i.push(h)}}}return i}};st=Eo([fn(0,w.IAutoFillService),fn(1,r.Inject(N.LexerTreeBuilder))],st);function _o(e,t,n){let s=0,o=0;switch(n){case r.Direction.UP:o=-e*t;break;case r.Direction.RIGHT:s=e;break;case r.Direction.DOWN:o=e;break;case r.Direction.LEFT:s=-e*t;break}return{offsetX:s,offsetY:o}}function yo(e){let t=0;for(const n in e)e[n].forEach(s=>{t+=s.data.length});return t}var To=Object.defineProperty,bo=Object.getOwnPropertyDescriptor,No=(e,t,n,s)=>{for(var o=s>1?void 0:s?bo(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(s?i(t,n,o):i(o))||o);return s&&o&&To(t,n,o),o},Ge=(e,t)=>(n,s)=>t(n,s,e);const Mo="default-paste-formula";let rt=class extends r.Disposable{constructor(e,t,n,s,o){super(),this._currentUniverSheet=e,this._lexerTreeBuilder=t,this._sheetClipboardService=n,this._injector=s,this._formulaDataModel=o,this._initialize()}_initialize(){this._registerClipboardHook()}_registerClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteFormulaHook())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteWithFormulaHook()))}_pasteFormulaHook(){return{id:w.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:Mo,priority:10,onPasteCells:(e,t,n,s)=>this._onPasteCells(e,t,n,s,!1)}}_onPasteCells(e,t,n,s,o){var h;if([w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH].includes(s.pasteType))return{undos:[],redos:[]};const i=this._currentUniverSheet.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET),a=t.unitId||i.getUnitId(),l=t.subUnitId||((h=i.getActiveSheet())==null?void 0:h.getSheetId());if(!a||!l)return{undos:[],redos:[]};const m=t.range,d=n,p={copyType:s.copyType||w.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:s.pasteType};return this._injector.invoke(g=>Oo(a,l,m,d,g,p,this._lexerTreeBuilder,this._formulaDataModel,o,e))}};rt=No([Ge(0,r.IUniverInstanceService),Ge(1,r.Inject(N.LexerTreeBuilder)),Ge(2,w.ISheetClipboardService),Ge(3,r.Inject(r.Injector)),Ge(4,r.Inject(N.FormulaDataModel))],rt);function Oo(e,t,n,s,o,c,i,a,l=!1,m){const d=[],p=[],h=Do(e,t,n,s,c,i,a,m),g={unitId:e,subUnitId:t,cellValue:h.getData()};d.push({id:K.SetRangeValuesMutation.id,params:g});const u=K.SetRangeValuesUndoMutationFactory(o,g);return p.push({id:K.SetRangeValuesMutation.id,params:u}),{undos:p,redos:d}}function Do(e,t,n,s,o,c,i,a){return a?o.pasteType===w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE?Fo(e,t,n,s,i,a):o.pasteType===w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA?Po(e,t,n,s,c,i,a):Ao(e,t,n,s,c,i,a):xo(e,t,n,s,i)}function xo(e,t,n,s,o){const c=new r.ObjectMatrix,i=o.getSheetFormulaData(e,t);return s.forValue((a,l,m)=>{var g;const d=n.rows[a],p=n.cols[l],h={};r.isFormulaString(m.v)?(h.v=null,h.f=`${m.v}`,h.si=null,h.p=null,c.setValue(d,p,h)):(g=i==null?void 0:i[d])!=null&&g[p]&&(h.v=m.v,h.f=null,h.si=null,h.p=null,c.setValue(d,p,h))}),c}function Fo(e,t,n,s,o,c){var m,d;const i=new r.ObjectMatrix,a=(d=(m=o.getArrayFormulaCellData())==null?void 0:m[c.unitId])==null?void 0:d[c.subUnitId],l=o.getSheetFormulaData(e,t);return s.forValue((p,h,g)=>{var _,T;const u=c.range.rows[p%c.range.rows.length],S=c.range.cols[h%c.range.cols.length],I=n.rows[p],b=n.cols[h],C={};if(r.isFormulaString(g.f)||r.isFormulaId(g.si))C.v=g.v,C.f=null,C.si=null,C.p=null,i.setValue(I,b,C);else if((_=a==null?void 0:a[u])!=null&&_[S]){const x=a[u][S];C.v=x.v,C.f=null,C.si=null,C.p=null,i.setValue(I,b,C)}else if((T=l==null?void 0:l[I])!=null&&T[b]){if(C.v=g.v,C.f=null,C.si=null,C.p=null,g.p){const x=dn(g);x&&(C.v=x)}i.setValue(I,b,C)}}),i}function Po(e,t,n,s,o,c,i){const a=new r.ObjectMatrix,l=new Map;return s.forValue((m,d,p)=>{const h=n.rows[m],g=n.cols[d],u={};if(r.isFormulaId(p.si)){if(i.unitId!==e||i.subUnitId!==t){const S=c.getFormulaStringByCell(i.range.rows[m%i.range.rows.length],i.range.cols[d%i.range.cols.length],i.subUnitId,i.unitId),I=n.cols[d]-i.range.cols[d%i.range.cols.length],b=n.rows[m]-i.range.rows[m%i.range.rows.length],C=o.moveFormulaRefOffset(S||"",I,b);u.si=null,u.f=C}else u.si=p.si,u.f=null;u.v=null,u.p=null,a.setValue(h,g,u)}else if(r.isFormulaString(p.f)){const S=`${m%i.range.rows.length}_${d%i.range.cols.length}`;let I=l.get(S);if(I)u.si=I,u.f=null;else{I=r.Tools.generateRandomId(6),l.set(S,I);const b=n.cols[d]-i.range.cols[d%i.range.cols.length],C=n.rows[m]-i.range.rows[m%i.range.rows.length],_=o.moveFormulaRefOffset(p.f||"",b,C);u.si=I,u.f=_}u.v=null,u.p=null,a.setValue(h,g,u)}else{if(u.v=p.v,u.f=null,u.si=null,u.p=null,p.p){const S=dn(p);S&&(u.v=S)}a.setValue(h,g,u)}}),a}function Ao(e,t,n,s,o,c,i){const a=new r.ObjectMatrix,l=new Map,m=c.getSheetFormulaData(e,t);return s.forValue((d,p,h)=>{var I;const g=n.rows[d],u=n.cols[p],S={};if(r.isFormulaId(h.si)){if(i.unitId!==e||i.subUnitId!==t){const b=c.getFormulaStringByCell(i.range.rows[d%i.range.rows.length],i.range.cols[p%i.range.cols.length],i.subUnitId,i.unitId),C=n.cols[p]-i.range.cols[p%i.range.cols.length],_=n.rows[d]-i.range.rows[d%i.range.rows.length],T=o.moveFormulaRefOffset(b||"",C,_);S.si=null,S.f=T}else S.si=h.si,S.f=null;S.v=null,S.p=null,a.setValue(g,u,S)}else if(r.isFormulaString(h.f)){const b=`${d%i.range.rows.length}_${p%i.range.cols.length}`;let C=l.get(b);if(C)S.si=C,S.f=null;else{C=r.Tools.generateRandomId(6),l.set(b,C);const _=n.cols[p]-i.range.cols[p%i.range.cols.length],T=n.rows[d]-i.range.rows[d%i.range.rows.length],x=o.moveFormulaRefOffset(h.f||"",_,T);S.si=C,S.f=x}S.v=null,S.p=null,a.setValue(g,u,S)}else(I=m==null?void 0:m[g])!=null&&I[u]&&(S.v=h.v,S.f=null,S.si=null,S.p=h.p,a.setValue(g,u,S))}),a}function dn(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)===r.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n}}var Lo=Object.defineProperty,wo=Object.getOwnPropertyDescriptor,ko=(e,t,n,s)=>{for(var o=s>1?void 0:s?wo(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(s?i(t,n,o):i(o))||o);return s&&o&&Lo(t,n,o),o},Ae=(e,t)=>(n,s)=>t(n,s,e);let it=class extends r.Disposable{constructor(t,n,s,o,c,i,a,l){super();ee(this,"_previousShape");ee(this,"_skeleton");this._context=t,this._sheetInterceptorService=n,this._formulaDataModel=s,this._themeService=o,this._renderManagerService=c,this._sheetSkeletonManagerService=i,this._commandService=a,this._logService=l,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:o}=t,c=(s=(n=this._skeleton)==null?void 0:n.worksheet)==null?void 0:s.getSheetId();if(this._changeRuntime(o),c!==o.worksheet.getSheetId())this._removeArrayFormulaRangeShape();else{const{unitId:i,sheetId:a}=t;this._updateArrayFormulaRangeShape(i,a)}}}))}_changeRuntime(t){this._skeleton=t}_initInterceptorEditorStart(){this.disposeWithMe(r.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(K.BEFORE_CELL_EDIT,{handler:(t,n,s)=>{var u,S,I,b;const{row:o,col:c,unitId:i,subUnitId:a,worksheet:l}=n,m=this._formulaDataModel.getArrayFormulaRange(),d=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return s(t);let p=null;const h=this._formulaDataModel.getFormulaStringByCell(o,c,a,i);if(h!==null&&(p={f:h}),t.v!=null&&t.v!==""&&((I=(S=(u=d[i])==null?void 0:u[a])==null?void 0:S[o])==null?void 0:I[c])==null)return p?{...t,...p}:s(t);const g=(b=m==null?void 0:m[i])==null?void 0:b[a];return g!=null&&(p=this._displayArrayFormulaRangeShape(g,o,c,i,a,l,p)),p?{...t,...p}:s(t)}})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{(t.id===N.SetFormulaCalculationResultMutation.id||t.id===N.SetArrayFormulaDataMutation.id&&n&&n.remove)&&this._removeArrayFormulaRangeShape()})),this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{K.SetWorksheetRowAutoHeightMutation.id===t.id&&requestIdleCallback(()=>{const n=t.params,{unitId:s,subUnitId:o,rowsAutoHeightInfo:c}=n;this._refreshArrayFormulaRangeShapeByRow(s,o,c)})}))}_displayArrayFormulaRangeShape(t,n,s,o,c,i,a){const l=this._formulaDataModel.getSheetFormulaData(o,c);return new r.ObjectMatrix(t).forValue((m,d,p)=>{var I;if(p==null)return!0;const{startRow:h,startColumn:g,endRow:u,endColumn:S}=p;if(m===n&&d===s)return this._createArrayFormulaRangeShape(p,o),!1;if(n>=h&&n<=u&&s>=g&&s<=S){const b=i.getCell(h,g);if((b==null?void 0:b.v)===N.ErrorType.SPILL)return;const C=(I=l==null?void 0:l[m])==null?void 0:I[d];return C==null||C.f==null?!0:(a==null&&(a={f:C.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(p,o),!1)}}),a}_createArrayFormulaRangeShape(t,n){const s=this._renderManagerService.getRenderById(n),o=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!s||!o)return;const{scene:c}=s;if(!c)return;const i=this._themeService.getCurrentTheme(),a={range:t,primary:null,style:{strokeWidth:1,stroke:i.hyacinth700,fill:new r.ColorKit(i.colorWhite).setAlpha(0).toString(),widgets:{}}},l=w.attachSelectionWithCoord(a,o),{rowHeaderWidth:m,columnHeaderHeight:d}=o,p=new w.SelectionControl(c,w.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:m,columnHeaderHeight:d});p.updateRangeBySelectionWithCoord(l),p.setEvent(!1),this._previousShape=p}_removeArrayFormulaRangeShape(){this._previousShape!=null&&(this._previousShape.dispose(),this._previousShape=null)}_refreshArrayFormulaRangeShape(t,n){if(this._previousShape){const{startRow:s,endRow:o,startColumn:c,endColumn:i}=this._previousShape.getRange(),a={startRow:s,endRow:o,startColumn:c,endColumn:i};this._removeArrayFormulaRangeShape(),this._createArrayFormulaRangeShape(a,t)}}_checkCurrentSheet(t,n){const s=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!s)return!1;const o=s.worksheet;return o?o.unitId===t&&o.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:o,endRow:c,startColumn:i,endColumn:a}=this._previousShape.getRange();for(let l=0;l<s.length;l++){const{row:m}=s[l];if(o>=m){const d={startRow:o,endRow:c,startColumn:i,endColumn:a};this._refreshArrayFormulaRangeShape(t,d);break}}}};it=ko([Ae(1,r.Inject(K.SheetInterceptorService)),Ae(2,r.Inject(N.FormulaDataModel)),Ae(3,r.Inject(r.ThemeService)),Ae(4,X.IRenderManagerService),Ae(5,r.Inject(w.SheetSkeletonManagerService)),Ae(6,r.ICommandService),Ae(7,r.ILogService)],it);var jo=Object.defineProperty,Ho=Object.getOwnPropertyDescriptor,Wo=(e,t,n,s)=>{for(var o=s>1?void 0:s?Ho(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(s?i(t,n,o):i(o))||o);return s&&o&&jo(t,n,o),o},mn=(e,t)=>(n,s)=>t(n,s,e);const Bo={tl:{size:6,color:"#409f11"}};let ct=class extends r.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(K.INTERCEPTOR_POINT.CELL_CONTENT,{effect:r.InterceptorEffectEnum.Style,handler:(n,s,o)=>{var a,l,m,d;const c=(d=(m=(l=(a=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:a[s.unitId])==null?void 0:l[s.subUnitId])==null?void 0:m[s.row])==null?void 0:d[s.col];return un(n,!!c)?o({...n,markers:{...n==null?void 0:n.markers,...Bo}}):o(n)},priority:10}))}};ct=Wo([mn(0,r.Inject(K.SheetInterceptorService)),mn(1,r.Inject(N.FormulaDataModel))],ct);function Vo(){const e=r.useDependency(Ne.TriggerCalculationController),t=r.useDependency(r.ICommandService),n=r.useObservable(e.progress$),s=f.useCallback(()=>{t.executeCommand(N.SetFormulaCalculationStopMutation.id)},[t]),o=f.useCallback(()=>{e.clearProgress()},[e]);return v.jsx(E.ProgressBar,{progress:n,onTerminate:s,onClearProgress:o})}const Ko=(e,t=100)=>{f.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])},re={formulaHelpFunction:"univer-formula-help-function",formulaHelpFunctionTitle:"univer-formula-help-function-title",formulaHelpFunctionTitleIcons:"univer-formula-help-function-title-icons",formulaHelpFunctionTitleIcon:"univer-formula-help-function-title-icon",formulaHelpFunctionContent:"univer-formula-help-function-content",formulaHelpFunctionContentInner:"univer-formula-help-function-content-inner",formulaHelpFunctionContentParams:"univer-formula-help-function-content-params",formulaHelpFunctionContentParamsTitle:"univer-formula-help-function-content-params-title",formulaHelpFunctionContentParamsDetail:"univer-formula-help-function-content-params-detail",formulaHelpFunctionActive:"univer-formula-help-function-active",formulaHelpDecorator:"univer-formula-help-decorator",formulaHelpParam:"univer-formula-help-param",formulaHelpParamPrefix:"univer-formula-help-param-prefix",formulaHelpParamItem:"univer-formula-help-param-item",formulaHelpParamActive:"univer-formula-help-param-active"};function Uo(){const[e,t]=f.useState(!1),[n,s]=f.useState(!0),[o,c]=f.useState(!0),[i,a]=f.useState(0),[l,m]=f.useState([0,0]),[d,p]=f.useState({left:0,top:0}),[h,g]=f.useState(null),u=r.useDependency(Ve),S=r.useDependency(r.LocaleService),I=S.t("formula.prompt.required"),b=S.t("formula.prompt.optional"),C=r.useDependency(r.IUniverInstanceService),_=r.useDependency(te.IEditorService),T=r.useDependency(E.ISidebarService),x=r.useInjector();Ko(F),f.useEffect(()=>{const O=u.help$.subscribe(k=>{const{visible:y,paramIndex:R,functionInfo:D}=k;if(!y){t(y);return}const A=P();if(A==null)return;const{left:H,top:Z,height:J}=A;D.description===""&&D.functionParameter.length===0||(m([H,Z+J]),a(R),g(D),p({left:H,top:Z}),t(y))}),M=T.scrollEvent$.pipe(G.throttleTime(100)).subscribe(F);return()=>{O==null||O.unsubscribe(),M.unsubscribe()}},[]);function F(){if(!o)return;const O=P();if(O==null)return;const{left:M,top:k,height:y}=O;m([M,k+y])}function P(){const O=C.getCurrentUniverDocInstance();if(!O)return;const M=O.getUnitId();if(!_.isEditor(M))return;const k=_.getEditor(M);return k==null?void 0:k.getBoundingClientRect()}function L(O){a(O)}function j(){c(!o),x.get(E.ILayoutService).focus()}return v.jsx(v.Fragment,{children:o?v.jsx(pe.Popup,{visible:e,offset:l,children:h?v.jsxs("div",{className:re.formulaHelpFunction,children:[v.jsxs("div",{className:re.formulaHelpFunctionTitle,children:[v.jsx(Yo,{prefix:h.functionName,value:h.functionParameter,active:i,onClick:L}),v.jsxs("div",{className:re.formulaHelpFunctionTitleIcons,children:[v.jsx("div",{className:re.formulaHelpFunctionTitleIcon,style:{transform:n?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>s(!n),children:v.jsx(ht,{})}),v.jsx("div",{className:re.formulaHelpFunctionTitleIcon,onClick:j,children:v.jsx(et,{})})]})]}),v.jsx("div",{className:re.formulaHelpFunctionContent,style:{height:n?"unset":0,padding:n?"revert-layer":0},children:v.jsxs("div",{className:re.formulaHelpFunctionContentInner,children:[v.jsx(bt,{title:S.t("formula.prompt.helpExample"),value:`${h.functionName}(${h.functionParameter.map(O=>O.example).join(",")})`}),v.jsx(bt,{title:S.t("formula.prompt.helpAbstract"),value:h.description}),h&&h.functionParameter&&h.functionParameter.map((O,M)=>v.jsx(bt,{className:i===M?re.formulaHelpFunctionActive:"",title:O.name,value:`${O.require?I:b} ${O.detail}`},M))]})})]}):v.jsx(v.Fragment,{})}):e?v.jsx("div",{className:re.formulaHelpDecorator,onClick:()=>c(!o),style:{left:d.left-24,top:d.top},children:v.jsx(Vt,{})}):v.jsx(v.Fragment,{})})}const bt=e=>v.jsxs("div",{className:re.formulaHelpFunctionContentParams,children:[v.jsx("div",{className:`
22
- ${re.formulaHelpFunctionContentParamsTitle}
23
- ${e.className}
24
- `,children:e.title}),v.jsx("div",{className:re.formulaHelpFunctionContentParamsDetail,children:e.value})]}),Yo=e=>{const{prefix:t,value:n,active:s,onClick:o}=e;return v.jsxs("div",{className:re.formulaHelpParam,children:[v.jsxs("span",{className:re.formulaHelpParamPrefix,children:[t,"("]}),n&&n.map((c,i)=>v.jsxs("span",{className:re.formulaHelpParamItem,children:[v.jsx("span",{className:s===i?re.formulaHelpFunctionActive:re.formulaHelpParamActive,onClick:()=>o(i),children:Rt(c)}),i===n.length-1?"":","]},i)),")"]})},De={formulaSearchFunction:"univer-formula-search-function",formulaSearchFunctionItem:"univer-formula-search-function-item",formulaSearchFunctionItemName:"univer-formula-search-function-item-name",formulaSearchFunctionItemNameLight:"univer-formula-search-function-item-name-light",formulaSearchFunctionItemDesc:"univer-formula-search-function-item-desc",formulaSearchFunctionItemActive:"univer-formula-search-function-item-active"};function zo(){const[e,t]=f.useState(!1),[n,s]=f.useState(0),[o,c]=f.useState([0,0]),[i,a]=f.useState([]),[l,m]=f.useState(""),d=f.useRef(null),p=r.useDependency(Ve),h=r.useDependency(r.IUniverInstanceService),g=r.useDependency(te.IEditorService);f.useEffect(()=>{let C=[],_=0;const T=p.search$.subscribe(P=>{const{visible:L,searchText:j,searchList:O}=P;if(!L){t(L);return}const M=u();if(M==null)return;const{left:k,top:y,height:R}=M;m(j),a(O),C=O,c([k,y+R]),t(L),s(0),_=0}),x=p.navigate$.subscribe(P=>{const{direction:L}=P;if(L===r.Direction.UP){let j=_-1;j=j<0?C.length-1:j,s(j),_=j}else if(L===r.Direction.DOWN){let j=_+1;j=j>=C.length?0:j,s(j),_=j}b(_)}),F=p.accept$.subscribe(P=>{const L=C[_].name;p.acceptFormulaName(L)});return()=>{T==null||T.unsubscribe(),x==null||x.unsubscribe(),F==null||F.unsubscribe()}},[]);function u(){const _=h.getCurrentUniverDocInstance().getUnitId();if(!g.isEditor(_))return;const T=g.getEditor(_);return T==null?void 0:T.getBoundingClientRect()}function S(C){s(C)}function I(){s(-1)}function b(C){var k;const _=(k=d.current)==null?void 0:k.querySelectorAll(`.${De.formulaSearchFunctionItem}`)[C];if(!_)return;const T=_.parentNode;if(!T)return;const F=T.getBoundingClientRect().top,P=T.offsetHeight,L=_.getBoundingClientRect(),j=L.top,O=L.height;if(j>=0&&j>F&&j-F+O<=P)return;const M=_.offsetTop-(P-O)/2;T.scrollTo({top:M,behavior:"smooth"})}return i.length>0&&v.jsx(pe.Popup,{visible:e,offset:o,children:v.jsx("ul",{className:De.formulaSearchFunction,ref:d,children:i.map((C,_)=>v.jsxs("li",{className:n===_?`
9
+ `,children:t}),C.jsx("div",{className:ae.formulaHelpFunctionContentParamsDetail,children:n})]}),to=e=>{const{prefix:t,value:n,active:r,onClick:o}=e;return C.jsxs("div",{className:ae.formulaHelpParam,children:[C.jsxs("span",{className:ae.formulaHelpParamPrefix,children:[t,"("]}),n&&n.map((c,i)=>C.jsxs("span",{className:ae.formulaHelpParamItem,children:[C.jsx("span",{className:r===i?ae.formulaHelpFunctionActive:ae.formulaHelpParamActive,onClick:()=>o(i),children:Ct(c)}),i===n.length-1?"":","]},c.name)),")"]})},tn=()=>{};function no(e){const{onParamsSwitch:t=tn,onClose:n=tn,isFocus:r,editor:o,formulaText:c}=e,{functionInfo:i,paramIndex:a,reset:f}=eo(r,c,o),d=u.useMemo(()=>!!i&&a>=0,[i,a]),[h,p]=u.useState(!0),m=s.useDependency(s.LocaleService),v=m.t("formula.prompt.required"),l=m.t("formula.prompt.optional"),g=o.getEditorId(),[E]=en(g,d,[i,a]);function R(y){t&&t(y)}const I=()=>{f(),n()};return d&&i?C.jsx(_.RectPopup,{portal:!0,onClickOutside:()=>f(),anchorRect$:E,direction:"vertical",children:C.jsxs("div",{className:ae.formulaHelpFunction,children:[C.jsxs("div",{className:ae.formulaHelpFunctionTitle,children:[C.jsx(to,{prefix:i.functionName,value:i.functionParameter,active:a,onClick:R}),C.jsxs("div",{className:ae.formulaHelpFunctionTitleIcons,children:[C.jsx("div",{className:ae.formulaHelpFunctionTitleIcon,style:{transform:h?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>p(!h),children:C.jsx(dt,{})}),C.jsx("div",{className:ae.formulaHelpFunctionTitleIcon,onClick:I,children:C.jsx(Qe,{})})]})]}),C.jsx("div",{className:ae.formulaHelpFunctionContent,style:{height:h?"unset":0,padding:h?"revert-layer":0},children:C.jsxs("div",{className:ae.formulaHelpFunctionContentInner,children:[C.jsx(It,{title:m.t("formula.prompt.helpExample"),value:`${i.functionName}(${i.functionParameter.map(y=>y.example).join(",")})`}),C.jsx(It,{title:m.t("formula.prompt.helpAbstract"),value:i.description}),i&&i.functionParameter&&i.functionParameter.map((y,D)=>C.jsx(It,{className:a===D?ae.formulaHelpFunctionActive:"",title:y.name,value:`${y.require?v:l} ${y.detail}`},D))]})})]})}):null}const nn=(e,t,n=!0)=>{let r=-1;return e.reduce((o,c,i)=>{if(o.isFinish)return o;const a=o.currentIndex;if(typeof c!="string")o.currentIndex+=c.token.length;else{const f=c.length;o.currentIndex+=f}return(n?o.currentIndex===t:t>a&&t<=o.currentIndex)&&(r=i,o.isFinish=!0),o},{currentIndex:0,isFinish:!1}),r},nt=e=>e.reduce((t,n)=>typeof n=="string"?t+n.length:t+n.token.length,0),oo=()=>{},ro=(e,t,n,r,o,c,i,a,f,d,h=oo)=>{const p=s.useDependency(G.IRenderManagerService),m=s.useDependency(s.IUniverInstanceService),v=s.useDependency(s.ICommandService),l=je(c),g=s.useDependency(lt.DocSelectionManagerService),E=s.useDependency(s.ThemeService),R=m.getUnit(r),I=_.useEvent(M=>{var S,T;return(T=(S=R==null?void 0:R.getSheetBySheetId(M))==null?void 0:S.getName())!=null?T:""}),y=u.useMemo(()=>I(o),[I,o]),D=s.useObservable(R==null?void 0:R.activeSheet$),A=je({activeSheet:D,sheetName:y}),F=p.getRenderById(r),L=F==null?void 0:F.with(W.RefSelectionsRenderService),x=F==null?void 0:F.with(k.SheetSkeletonManagerService),w=s.useDependency(j.IRefSelectionsService),N=u.useRef(!1),O=u.useRef(n);O.current=n;const $=u.useRef(void 0);u.useEffect(()=>{if(L&&e){let M=!0;const S=(P,H)=>{var Q,oe,Y,re,de,Ce;if(M){M=!1;return}const V=d==null?void 0:d.getSelectionRanges();if((V==null?void 0:V.length)!==1)return;const z=V[0].startOffset-1,K=[...l.current],pe=nn(K,z,!1);if(O.current===tt.NEED_ADD)if(z!==0){if(pe===-1&&K.length)return;const se=P[P.length-1],Se=K.splice(pe+1),le=(Q=se.rangeWithCoord.sheetId)!=null?Q:o,ye={range:se.rangeWithCoord,unitId:(oe=se.rangeWithCoord.unitId)!=null?oe:r,sheetName:I(le)},ge=Ie([ye],a&&le!==o,y);K.push({token:ge[0],nodeType:b.sequenceNodeType.REFERENCE});const Pe=[...K,...Se],Te=_e(Pe);h(Te,nt(K),H)}else{const se=P[P.length-1],Se=(Y=se.rangeWithCoord.sheetId)!=null?Y:o,le={range:se.rangeWithCoord,unitId:(re=se.rangeWithCoord.unitId)!=null?re:r,sheetName:I(Se)},he=Ie([le],a&&Se!==o);K.unshift({token:he[0],nodeType:b.sequenceNodeType.REFERENCE});const ge=_e(K);h(ge,he[0].length,H)}else{let se=0;const Se=K.map(B=>{var U,J,X;if(typeof B=="string")return B;if(B.nodeType===b.sequenceNodeType.REFERENCE){const ee=b.deserializeRangeWithSheet(B.token);if(ee.sheetName||(ee.sheetName=y),a&&((U=A.current.activeSheet)==null?void 0:U.getName())!==ee.sheetName)return B.token;const ce=P[se];if(se++,!ce)return"";const xe=(J=ce.rangeWithCoord.sheetId)!=null?J:o,be={range:ce.rangeWithCoord,unitId:(X=ce.rangeWithCoord.unitId)!=null?X:r,sheetName:I(xe)};return Ie([be],a,y)[0]}return B.token});let le="",ye;Se.forEach((B,U)=>{le+=B,U===pe&&(ye=le.length)});const he=[];for(let B=se;B<=P.length-1;B++){const U=P[B],J=(de=U.rangeWithCoord.sheetId)!=null?de:o,X={range:U.rangeWithCoord,unitId:(Ce=U.rangeWithCoord.unitId)!=null?Ce:r,sheetName:I(J)},ce=Ie([X],a&&J!==o,y);he.push(ce[0])}const ge=K[K.length-1],Pe=ge&&(typeof ge=="string"?!1:ge.nodeType===b.sequenceNodeType.REFERENCE),Te=`${le}${he.length&&Pe?",":""}${he.join(",")}`;h(Te,!he.length&&ye?ye:Te.length,H)}},T=new s.DisposableCollection;return T.add(L.selectionMoving$.subscribe(P=>{N.current||S(P,!1)})),T.add(L.selectionMoveEnd$.subscribe(P=>{N.current||S(P,!0)})),()=>{T.dispose()}}},[L,d,a,e,l,o,r,I,y,h,A]),u.useEffect(()=>{if(t&&L&&d){const M=new s.DisposableCollection,S=(H,V)=>{let Z=0,z=0,K=!1;const{sheetName:pe}=A.current,Q=l.current.map(Y=>{var re;if(typeof Y=="string")return K||(z+=Y.length),Y;if(Y.nodeType===b.sequenceNodeType.REFERENCE){const de=b.deserializeRangeWithSheet(Y.token);if(de.unitId||(de.unitId=r),de.sheetName||(de.sheetName=pe),a&&((re=A.current.activeSheet)==null?void 0:re.getName())!==de.sheetName)return K||(z+=Y.token.length),Y;if(Z===V){K=!0;const Ce={...Y,token:H};return a&&de.sheetName!==pe?Ce.token=b.serializeRangeWithSheet(de.sheetName,b.deserializeRangeWithSheet(H).range):Ce.token=H,z+=Ce.token.length,Z++,Ce}return K||(z+=Y.token.length),Z++,Y}return K||(z+=Y.token.length),Y}),oe=_e(Q);h(oe,-1,!0),$.current={result:oe,offset:z}},T=()=>{M.dispose(),L.getSelectionControls().forEach((V,Z)=>{M.add(q.merge(V.selectionMoving$,V.selectionScaling$).pipe(Be.map(z=>b.serializeRange(z)),Be.distinctUntilChanged(),Be.debounceTime(100)).subscribe(z=>{N.current=!0,S(z,Z)}))}),M.add(L.selectionMoveEnd$.subscribe(V=>{if(N.current=!1,$.current){const{result:Z,offset:z}=$.current;h(Z,z||-1,!0),$.current=void 0}}))},P=q.merge(d.input$,w.selectionSet$,L.selectionMoveEnd$).pipe(Be.debounceTime(50)).subscribe(()=>{T()});return()=>{P.unsubscribe(),M.dispose()}}},[t,L,d,w.selectionSet$,A,l,h,a,r]),u.useEffect(()=>{if(f){const M=v.onCommandExecuted(S=>{if(S.id!==j.SetSelectionsOperation.id)return;const T=S.params;if(T.extra!=="formula-editor")return;const{selections:P}=T;if(P.length){const H=P[P.length-1];if(H){const V=H.range,Z=o,z={range:V,unitId:T.unitId===r?"":T.unitId,sheetName:T.subUnitId===Z?"":I(Z)},K=[...l.current],Q=Ie([z],a,y)[0];let oe=K[K.length-1];if(typeof oe=="object"&&oe.nodeType===b.sequenceNodeType.REFERENCE){oe={...oe},oe.token=Q,oe.endIndex=oe.startIndex+Q.length,K[K.length-1]=oe;const Y=_e(K);h(Y,nt(K),!0)}else{const Y=nt(K);K.push({nodeType:b.sequenceNodeType.REFERENCE,token:Q,startIndex:Y,endIndex:Y+Q.length});const re=_e(K);h(re,nt(K),!0)}}}});return()=>{M.dispose()}}},[v,I,h,a,f,l,y,o,r]),u.useEffect(()=>{if(!d)return;const M=g.textSelection$.subscribe(S=>{S.unitId===d.getEditorId()&&Kt({unitId:r,subUnitId:o,refSelections:i.current,editor:d,refSelectionsService:w,refSelectionsRenderService:L,sheetSkeletonManagerService:x,themeService:E,univerInstanceService:m})});return()=>M.unsubscribe()},[g.textSelection$,d,i,L,w,l,x,o,E,r,m])},so=(e,t,n)=>{const r=s.useDependency(b.LexerTreeBuilder),o=u.useRef(!0);u.useEffect(()=>{if(e){const c=setTimeout(()=>{o.current=!1},500);return()=>{clearTimeout(c)}}},[e]),u.useEffect(()=>{if(!o.current&&t){const c=r.checkIfAddBracket(n);t(c===0&&n.startsWith(b.operatorToken.EQUALS),`${n}`)}},[n,t])},ke={sheetEmbeddingFormulaEditorActive:"univer-sheet-embedding-formula-editor-active",sheetEmbeddingFormulaEditorWrap:"univer-sheet-embedding-formula-editor-wrap",sheetEmbeddingFormulaEditorText:"univer-sheet-embedding-formula-editor-text",sheetEmbeddingFormulaEditorError:"univer-sheet-embedding-formula-editor-error",sheetEmbeddingFormulaEditor:"univer-sheet-embedding-formula-editor",sheetEmbeddingFormulaEditorErrorWrap:"univer-sheet-embedding-formula-editor-error-wrap"},io=(e,t=[],n)=>{const r=s.useDependency(Ne.IDescriptionService),[o,c]=u.useState([]),[i,a]=u.useState(""),f=u.useRef(-1),d=je({nodes:t}),h=()=>{c([]),a(""),f.current=-1};return u.useEffect(()=>{if(n&&e){const m=n.input$.pipe(q.debounceTime(300)).subscribe(()=>{const v=n.getSelectionRanges();if(v.length===1){const l=d.current.nodes,g=v[0];if(g.collapsed){const E=nn(l,g.startOffset-1,!1);f.current=E;const R=l[E];if(R&&typeof R!="string"&&R.nodeType===b.sequenceNodeType.FUNCTION){f.current=E;const I=R.token,y=r.getSearchListByNameFirstLetter(I);c(y),a(I);return}}}f.current=-1,a(""),c(l=>l!=null&&l.length?[]:l)});return()=>{m.unsubscribe()}}},[n,e]),u.useEffect(()=>{e||h()},[e]),{searchList:o,searchText:i,handlerFormulaReplace:m=>{const v=[...d.current.nodes];if(f.current!==-1){const l=v.splice(f.current+1),g=v.pop()||"";let E=(typeof g=="string"?g.length:g.token.length)-m.length;return v.push(m),l[0]!==b.matchToken.OPEN_BRACKET&&(v.push(b.matchToken.OPEN_BRACKET),E--),{text:_e([...v,...l]),offset:E}}},reset:h}},De={formulaSearchFunction:"univer-formula-search-function",formulaSearchFunctionItem:"univer-formula-search-function-item",formulaSearchFunctionItemName:"univer-formula-search-function-item-name",formulaSearchFunctionItemNameLight:"univer-formula-search-function-item-name-light",formulaSearchFunctionItemDesc:"univer-formula-search-function-item-desc",formulaSearchFunctionItemActive:"univer-formula-search-function-item-active"},co=()=>{},ao=u.forwardRef(lo);function lo(e,t){const{isFocus:n,sequenceNodes:r,onSelect:o,editor:c,onClose:i=co}=e,a=c.getEditorId(),f=s.useDependency(_.IShortcutService),d=s.useDependency(s.ICommandService),{searchList:h,searchText:p,handlerFormulaReplace:m,reset:v}=io(n,r,c),l=u.useMemo(()=>!!h.length,[h]),g=u.useRef(void 0),[E,R]=u.useState(0),I=u.useRef(!1),[y]=en(a,l,[p,h]),D=je({searchList:h,active:E}),A=N=>{const O=m(N);O&&(v(),o(O))};function F(N){I.current&&R(N)}function L(){I.current&&R(-1)}u.useEffect(()=>{if(!h.length)return;const N=`sheet.formula-embedding-editor.search_function.${a}`,O=new s.DisposableCollection,$=M=>{const{searchList:S,active:T}=D.current;switch(M){case _.KeyCode.ARROW_UP:{R(P=>{const H=Math.max(0,P-1);return x(H),H});break}case _.KeyCode.ARROW_DOWN:{R(P=>{const H=Math.min(S.length-1,P+1);return x(H),H});break}case _.KeyCode.TAB:case _.KeyCode.ENTER:{const P=S[T];A(P.name);break}case _.KeyCode.ESC:{v(),i();break}}};return O.add(d.registerCommand({id:N,type:s.CommandType.OPERATION,handler(M,S){const{keyCode:T}=S;$(T)}})),[_.KeyCode.ARROW_UP,_.KeyCode.ARROW_DOWN,_.KeyCode.ENTER,_.KeyCode.ESC,_.KeyCode.TAB].map(M=>({id:N,binding:M,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:G.DeviceInputEventType.Keyboard,keyCode:M}})).forEach(M=>{O.add(f.registerShortcut(M))}),()=>{O.dispose()}},[h]);function x(N){var z;const O=(z=g.current)==null?void 0:z.querySelectorAll(`.${De.formulaSearchFunctionItem}`)[N];if(!O)return;const $=O.parentNode;if(!$)return;const S=$.getBoundingClientRect().top,T=$.offsetHeight,P=O.getBoundingClientRect(),H=P.top,V=P.height;if(H>=0&&H>S&&H-S+V<=T)return;const Z=O.offsetTop-(T-V)/2;$.scrollTo({top:Z,behavior:"smooth"})}const w=u.useMemo(()=>{let N="";return()=>{clearTimeout(N),I.current=!0,N=setTimeout(()=>{I.current=!1},300)}},[]);return h.length>0&&l&&C.jsx(_.RectPopup,{portal:!0,anchorRect$:y,direction:"vertical",children:C.jsx("ul",{className:De.formulaSearchFunction,ref:N=>{g.current=N,t&&(t.current=N)},children:h.map((N,O)=>C.jsxs("li",{className:E===O?`
25
10
  ${De.formulaSearchFunctionItem}
26
11
  ${De.formulaSearchFunctionItemActive}
27
- `:De.formulaSearchFunctionItem,onMouseEnter:()=>S(_),onMouseLeave:I,onClick:()=>p.acceptFormulaName(C.name),children:[v.jsxs("span",{className:De.formulaSearchFunctionItemName,children:[v.jsx("span",{className:De.formulaSearchFunctionItemNameLight,children:C.name.substring(0,l.length)}),v.jsx("span",{children:C.name.slice(l.length)})]}),v.jsx("span",{className:De.formulaSearchFunctionItemDesc,children:C.desc})]},_))})})}function Go(){return v.jsxs(v.Fragment,{children:[v.jsx(zo,{}),v.jsx(Uo,{})]})}const hn={formulaMoreFunctions:"univer-formula-more-functions",formulaMoreFunctionsOperation:"univer-formula-more-functions-operation"};function pn(e){const{prefix:t,value:n}=e;return v.jsxs("div",{children:[v.jsxs("span",{children:[t,"("]}),n&&n.map((s,o)=>v.jsxs("span",{children:[v.jsx("span",{children:Rt(s)}),o===n.length-1?"":","]},o)),")"]})}const Nt={formulaFunctionParams:"univer-formula-function-params",formulaFunctionParamsTitle:"univer-formula-function-params-title",formulaFunctionParamsDetail:"univer-formula-function-params-detail"};function Ze(e){const{className:t,value:n,title:s}=e;return v.jsxs("div",{className:Nt.formulaFunctionParams,children:[v.jsx("div",{className:`
28
- ${Nt.formulaFunctionParamsTitle}
12
+ `:De.formulaSearchFunctionItem,onMouseEnter:()=>F(O),onMouseLeave:L,onMouseMove:w,onClick:()=>{A(N.name),c&&c.focus()},children:[C.jsxs("span",{className:De.formulaSearchFunctionItemName,children:[C.jsx("span",{className:De.formulaSearchFunctionItemNameLight,children:N.name.substring(0,p.length)}),C.jsx("span",{children:N.name.slice(p.length)})]}),C.jsx("span",{className:De.formulaSearchFunctionItemDesc,children:N.desc})]},N.name))})})}const uo=e=>e.startsWith(b.operatorToken.EQUALS)?e.slice(1):"",Et=()=>{};function on(e){var pn,Sn;const{errorText:t,initValue:n,unitId:r,subUnitId:o,isFocus:c=!0,isSupportAcrossSheet:i=!1,onFocus:a=Et,onBlur:f=Et,onChange:d,onVerify:h,actions:p,className:m,editorId:v,moveCursor:l=!0,onFormulaSelectingChange:g,keyboradEventConfig:E,onMoveInEditor:R,resetSelectionOnBlur:I=!0,autoScrollbar:y=!0,isSingle:D=!0,disableSelectionOnClick:A=!1,disableContextMenu:F,style:L}=e,x=s.useDependency(te.IEditorService),w=u.useRef(null),N=_.useEvent(d);p&&(p.handleOutClick=(ue,fe)=>{w.current&&!w.current.contains(ue.target)&&fe()});const O=_.useEvent(g),$=u.useRef(null),M=u.useRef(void 0),S=M.current,[T,P]=u.useState(c),H=u.useRef(null),V=u.useMemo(()=>v!=null?v:s.createInternalEditorID(`${k.EMBEDDING_FORMULA_EDITOR}-${s.generateRandomId(4)}`),[]),Z=u.useMemo(()=>t!==void 0,[t]),z=s.useDependency(s.IUniverInstanceService),K=z.getUnit(V);s.useObservable(K==null?void 0:K.change$);const pe=et(),Q=s.BuildTextUtils.transform.getPlainText((Sn=(pn=K==null?void 0:K.getBody())==null?void 0:pn.dataStream)!=null?Sn:""),oe=u.useMemo(()=>uo(Q),[Q]),Y=u.useMemo(()=>pe(oe),[oe,pe]),{isSelecting:re}=qn(V,T,A),de=u.useRef(""),se=s.useDependency(G.IRenderManagerService).getRenderById(V),Se=se==null?void 0:se.with(te.DocSelectionRenderService),le=Se==null?void 0:Se.isFocusing,ye=u.useMemo(()=>z.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_DOC),[z]),he=s.useObservable(ye),ge=(he==null?void 0:he.getUnitId())===V,Pe=u.useRef([]),Te=re;_.useUpdateEffect(()=>{N(Q)},[Q,N]);const B=Ut("="),U=mt(r,o),J=_.useEvent((ue,fe=!0,Me,He)=>{if(!M.current)return;de.current=ue;const Mt=pe(ue[0]==="="?ue.slice(1):""),We=B(M.current,Mt,fe,He);Pe.current=We,Me&&U(T?We:[],M.current)});u.useEffect(()=>{T&&J(Q,!1,!0)},[Q,T,J]),so(T,h,Q);const X=Vt(S),ee=Gt(T,r,o);u.useEffect(()=>{O(re)},[O,re]),te.useKeyboardEvent(T,E,S),u.useLayoutEffect(()=>{let ue;if(H.current){ue=x.register({autofocus:!0,editorUnitId:V,initialSnapshot:{id:V,body:{dataStream:`${n}\r
13
+ `,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},H.current);const fe=x.getEditor(V);M.current=fe,J(n,!1,!0)}return()=>{ue==null||ue.dispose()}},[]),u.useLayoutEffect(()=>{c?(P(c),X()):(I&&(S==null||S.blur(),ee()),P(c))},[c,S,X,ee,I]);const{checkScrollBar:ce}=te.useResize(S,D,y);pt(T,!!(re&&ge),r,F),Yt(T&&l,Te,S,R);const xe=_.useEvent((ue,fe,Me)=>{if(!le)return;const He=fe!==-1?[{startOffset:fe+1,endOffset:fe+1,collapsed:!0}]:void 0;J(`=${ue}`,!0,Me,He),Me&&(X(),fe!==-1&&setTimeout(()=>{const Mt={startOffset:fe+1,endOffset:fe+1},We=S==null?void 0:S.render.with(te.DocBackScrollRenderController);We==null||We.scrollToRange({...Mt,collapsed:!0})},50),ce())});ro(T&&!!(re&&ge),T,re,r,o,Y,Pe,i,!!Te,S,xe),vt(T&&!!(re&&ge),r,i,P,f,Et);const be=ue=>{if(ue){const fe=S==null?void 0:S.getSelectionRanges();if(fe&&fe.length===1){const Me=fe[0];if(Me.collapsed){const He=ue.offset;setTimeout(()=>{S==null||S.setSelectionRanges([{startOffset:Me.startOffset-He,endOffset:Me.endOffset-He}])},30)}}X(),J(`=${ue.text}`)}},mn=()=>{P(!0),a(),X()};return C.jsxs("div",{style:L,className:ht(ke.sheetEmbeddingFormulaEditor,m),children:[C.jsx("div",{className:ht(ke.sheetEmbeddingFormulaEditorWrap,{[ke.sheetEmbeddingFormulaEditorActive]:T,[ke.sheetEmbeddingFormulaEditorError]:Z}),ref:w,children:C.jsx("div",{className:ke.sheetEmbeddingFormulaEditorText,ref:H,onMouseUp:mn})}),t!==void 0?C.jsx("div",{className:ke.sheetEmbeddingFormulaEditorErrorWrap,children:t}):null,S?C.jsx(no,{editor:S,isFocus:T,formulaText:Q,onClose:()=>X()}):null,S?C.jsx(ao,{isFocus:T,sequenceNodes:Y,onSelect:be,ref:$,editor:S}):null]})}const fo="sheets-formula-ui.base.config",rn={};function ho(e){return e.getContextValue(s.FOCUSING_DOC)&&e.getContextValue(s.FOCUSING_UNIVER_EDITOR)}function sn(e,t=!1){return!t&&!(s.isFormulaString(e==null?void 0:e.f)||s.isFormulaId(e==null?void 0:e.si))?null:typeof(e==null?void 0:e.v)=="string"&&b.ERROR_TYPE_SET.has(e.v)?e.v:null}var mo=Object.defineProperty,po=Object.getOwnPropertyDescriptor,So=(e,t,n,r)=>{for(var o=r>1?void 0:r?po(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&mo(t,n,o),o},qe=(e,t)=>(n,r)=>t(n,r,e);const _t="SHEET_FORMULA_ALERT",go={[b.ErrorType.DIV_BY_ZERO]:"divByZero",[b.ErrorType.NAME]:"name",[b.ErrorType.VALUE]:"value",[b.ErrorType.NUM]:"num",[b.ErrorType.NA]:"na",[b.ErrorType.CYCLE]:"cycle",[b.ErrorType.REF]:"ref",[b.ErrorType.SPILL]:"spill",[b.ErrorType.CALC]:"calc",[b.ErrorType.ERROR]:"error",[b.ErrorType.CONNECT]:"connect",[b.ErrorType.NULL]:"null"};let yt=class extends s.Disposable{constructor(e,t,n,r,o,c){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=r,this._formulaDataModel=o,this._zenZoneService=c,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(q.debounceTime(100)).subscribe(e=>{var t,n,r,o,c;if(e){const a=this._context.unit.getActiveSheet();if(!a)return;const f=a.getCell(e.location.row,e.location.col),d=(o=(r=(n=(t=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:t[e.location.unitId])==null?void 0:n[e.location.subUnitId])==null?void 0:r[e.location.row])==null?void 0:o[e.location.col];if(s.isICellData(f)){const h=sn(f,!!d);if(!h){this._hideAlert();return}const p=this._cellAlertManagerService.currentAlert.get(_t),m=(c=p==null?void 0:p.alert)==null?void 0:c.location;if(m&&m.row===e.location.row&&m.col===e.location.col&&m.subUnitId===e.location.subUnitId&&m.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.${go[h]}`),location:e.location,width:200,height:74,key:_t});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(_t)}};yt=So([qe(1,s.Inject(k.HoverManagerService)),qe(2,s.Inject(k.CellAlertManagerService)),qe(3,s.Inject(s.LocaleService)),qe(4,s.Inject(b.FormulaDataModel)),qe(5,_.IZenZoneService)],yt);var vo=Object.defineProperty,Co=Object.getOwnPropertyDescriptor,Io=(e,t,n,r)=>{for(var o=r>1?void 0:r?Co(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&vo(t,n,o),o},cn=(e,t)=>(n,r)=>t(n,r,e);let ot=class extends s.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=>s.isFormulaString(t==null?void 0:t.f)||s.isFormulaId(t==null?void 0:t.si),isContinue:(t,n)=>t.type===k.DATA_TYPE.FORMULA,applyFunctions:{[k.APPLY_TYPE.COPY]:(t,n,r,o)=>{const{data:c,index:i}=t;return this._fillCopyFormula(c,n,r,i,o)}}};this._autoFillService.registerRule(e)}_fillCopyFormula(e,t,n,r,o){var f,d;const c=_o(o),i=[],a=new Map;for(let h=1;h<=t;h++){const p=(h-1)%e.length,m=s.Tools.deepClone(e[p]);if(m){const v=((f=e[p])==null?void 0:f.f)||"",l=((d=e[p])==null?void 0:d.si)||"",g=s.isFormulaString(v);if(s.isFormulaId(l))m.si=l,m.f=null,m.v=null,m.p=null,m.t=null,i.push(m);else if(g){let R=a.get(p);if(R)m.si=R,m.f=null,m.v=null,m.p=null,m.t=null;else{R=s.Tools.generateRandomId(6),a.set(p,R);const{offsetX:I,offsetY:y}=Eo(c,t,n),D=this._lexerTreeBuilder.moveFormulaRefOffset(v,I,y);m.si=R,m.f=D,m.v=null,m.p=null,m.t=null}i.push(m)}}}return i}};ot=Io([cn(0,k.IAutoFillService),cn(1,s.Inject(b.LexerTreeBuilder))],ot);function Eo(e,t,n){let r=0,o=0;switch(n){case s.Direction.UP:o=-e*t;break;case s.Direction.RIGHT:r=e;break;case s.Direction.DOWN:o=e;break;case s.Direction.LEFT:r=-e*t;break}return{offsetX:r,offsetY:o}}function _o(e){let t=0;for(const n in e)e[n].forEach(r=>{t+=r.data.length});return t}var yo=Object.defineProperty,Ro=Object.getOwnPropertyDescriptor,To=(e,t,n,r)=>{for(var o=r>1?void 0:r?Ro(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&yo(t,n,o),o},Ye=(e,t)=>(n,r)=>t(n,r,e);const bo="default-paste-formula";let rt=class extends s.Disposable{constructor(e,t,n,r,o){super(),this._currentUniverSheet=e,this._lexerTreeBuilder=t,this._sheetClipboardService=n,this._injector=r,this._formulaDataModel=o,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,r)=>this._onPasteCells(e,t,n,r,!0)}}_pasteWithFormulaHook(){return{id:bo,priority:10,onPasteCells:(e,t,n,r)=>this._onPasteCells(e,t,n,r,!1)}}_onPasteCells(e,t,n,r,o){var m;if([k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH].includes(r.pasteType))return{undos:[],redos:[]};const i=this._currentUniverSheet.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),a=t.unitId||i.getUnitId(),f=t.subUnitId||((m=i.getActiveSheet())==null?void 0:m.getSheetId());if(!a||!f)return{undos:[],redos:[]};const d=t.range,h=n,p={copyType:r.copyType||k.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:r.pasteType};return this._injector.invoke(v=>Mo(a,f,d,h,v,p,this._lexerTreeBuilder,this._formulaDataModel,o,e))}};rt=To([Ye(0,s.IUniverInstanceService),Ye(1,s.Inject(b.LexerTreeBuilder)),Ye(2,k.ISheetClipboardService),Ye(3,s.Inject(s.Injector)),Ye(4,s.Inject(b.FormulaDataModel))],rt);function Mo(e,t,n,r,o,c,i,a,f=!1,d){const h=[],p=[],m=No(e,t,n,r,c,i,a,d),v={unitId:e,subUnitId:t,cellValue:m.getData()};h.push({id:j.SetRangeValuesMutation.id,params:v});const l=j.SetRangeValuesUndoMutationFactory(o,v);return p.push({id:j.SetRangeValuesMutation.id,params:l}),{undos:p,redos:h}}function No(e,t,n,r,o,c,i,a){return a?o.pasteType===k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE?Do(e,t,n,r,i,a):o.pasteType===k.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA?Fo(e,t,n,r,c,i,a):Po(e,t,n,r,c,i,a):Oo(e,t,n,r,i)}function Oo(e,t,n,r,o){const c=new s.ObjectMatrix,i=o.getSheetFormulaData(e,t);return r.forValue((a,f,d)=>{var v;const h=n.rows[a],p=n.cols[f],m={};s.isFormulaString(d.v)?(m.v=null,m.f=`${d.v}`,m.si=null,m.p=null,c.setValue(h,p,m)):(v=i==null?void 0:i[h])!=null&&v[p]&&(m.v=d.v,m.f=null,m.si=null,m.p=null,c.setValue(h,p,m))}),c}function Do(e,t,n,r,o,c){var d,h;const i=new s.ObjectMatrix,a=(h=(d=o.getArrayFormulaCellData())==null?void 0:d[c.unitId])==null?void 0:h[c.subUnitId],f=o.getSheetFormulaData(e,t);return r.forValue((p,m,v)=>{var y,D;const l=c.range.rows[p%c.range.rows.length],g=c.range.cols[m%c.range.cols.length],E=n.rows[p],R=n.cols[m],I={};if(s.isFormulaString(v.f)||s.isFormulaId(v.si))I.v=v.v,I.f=null,I.si=null,I.p=null,i.setValue(E,R,I);else if((y=a==null?void 0:a[l])!=null&&y[g]){const A=a[l][g];I.v=A.v,I.f=null,I.si=null,I.p=null,i.setValue(E,R,I)}else if((D=f==null?void 0:f[E])!=null&&D[R]){if(I.v=v.v,I.f=null,I.si=null,I.p=null,v.p){const A=an(v);A&&(I.v=A)}i.setValue(E,R,I)}}),i}function Fo(e,t,n,r,o,c,i){const a=new s.ObjectMatrix,f=new Map;return r.forValue((d,h,p)=>{const m=n.rows[d],v=n.cols[h],l={};if(s.isFormulaId(p.si)){if(i.unitId!==e||i.subUnitId!==t){const g=c.getFormulaStringByCell(i.range.rows[d%i.range.rows.length],i.range.cols[h%i.range.cols.length],i.subUnitId,i.unitId),E=n.cols[h]-i.range.cols[h%i.range.cols.length],R=n.rows[d]-i.range.rows[d%i.range.rows.length],I=o.moveFormulaRefOffset(g||"",E,R);l.si=null,l.f=I}else l.si=p.si,l.f=null;l.v=null,l.p=null,a.setValue(m,v,l)}else if(s.isFormulaString(p.f)){const g=`${d%i.range.rows.length}_${h%i.range.cols.length}`;let E=f.get(g);if(E)l.si=E,l.f=null;else{E=s.Tools.generateRandomId(6),f.set(g,E);const R=n.cols[h]-i.range.cols[h%i.range.cols.length],I=n.rows[d]-i.range.rows[d%i.range.rows.length],y=o.moveFormulaRefOffset(p.f||"",R,I);l.si=E,l.f=y}l.v=null,l.p=null,a.setValue(m,v,l)}else{if(l.v=p.v,l.f=null,l.si=null,l.p=null,p.p){const g=an(p);g&&(l.v=g)}a.setValue(m,v,l)}}),a}function Po(e,t,n,r,o,c,i){const a=new s.ObjectMatrix,f=new Map,d=c.getSheetFormulaData(e,t);return r.forValue((h,p,m)=>{var E;const v=n.rows[h],l=n.cols[p],g={};if(s.isFormulaId(m.si)){if(i.unitId!==e||i.subUnitId!==t){const R=c.getFormulaStringByCell(i.range.rows[h%i.range.rows.length],i.range.cols[p%i.range.cols.length],i.subUnitId,i.unitId),I=n.cols[p]-i.range.cols[p%i.range.cols.length],y=n.rows[h]-i.range.rows[h%i.range.rows.length],D=o.moveFormulaRefOffset(R||"",I,y);g.si=null,g.f=D}else g.si=m.si,g.f=null;g.v=null,g.p=null,a.setValue(v,l,g)}else if(s.isFormulaString(m.f)){const R=`${h%i.range.rows.length}_${p%i.range.cols.length}`;let I=f.get(R);if(I)g.si=I,g.f=null;else{I=s.Tools.generateRandomId(6),f.set(R,I);const y=n.cols[p]-i.range.cols[p%i.range.cols.length],D=n.rows[h]-i.range.rows[h%i.range.rows.length],A=o.moveFormulaRefOffset(m.f||"",y,D);g.si=I,g.f=A}g.v=null,g.p=null,a.setValue(v,l,g)}else(E=d==null?void 0:d[v])!=null&&E[l]&&(g.v=m.v,g.f=null,g.si=null,g.p=m.p,a.setValue(v,l,g))}),a}function an(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)===s.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n}}var Ao=Object.defineProperty,Lo=Object.getOwnPropertyDescriptor,wo=(e,t,n,r)=>{for(var o=r>1?void 0:r?Lo(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&Ao(t,n,o),o},Le=(e,t)=>(n,r)=>t(n,r,e);let st=class extends s.Disposable{constructor(t,n,r,o,c,i,a,f){super();ne(this,"_previousShape");ne(this,"_skeleton");this._context=t,this._sheetInterceptorService=n,this._formulaDataModel=r,this._themeService=o,this._renderManagerService=c,this._sheetSkeletonManagerService=i,this._commandService=a,this._logService=f,this._initSkeletonChangeListener(),this._initInterceptorEditorStart(),this._commandExecutedListener()}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(t=>{var n,r;if(t==null)this._logService.debug("[FormulaEditorShowController]: should not receive currentSkeleton$ as null!");else{const{skeleton:o}=t,c=(r=(n=this._skeleton)==null?void 0:n.worksheet)==null?void 0:r.getSheetId();if(this._changeRuntime(o),c!==o.worksheet.getSheetId())this._removeArrayFormulaRangeShape();else{const{unitId:i,sheetId:a}=t;this._updateArrayFormulaRangeShape(i,a)}}}))}_changeRuntime(t){this._skeleton=t}_initInterceptorEditorStart(){this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(j.BEFORE_CELL_EDIT,{handler:(t,n,r)=>{var l,g,E,R;const{row:o,col:c,unitId:i,subUnitId:a,worksheet:f}=n,d=this._formulaDataModel.getArrayFormulaRange(),h=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return r(t);let p=null;const m=this._formulaDataModel.getFormulaStringByCell(o,c,a,i);if(m!==null&&(p={f:m}),t.v!=null&&t.v!==""&&((E=(g=(l=h[i])==null?void 0:l[a])==null?void 0:g[o])==null?void 0:E[c])==null)return p?{...t,...p}:r(t);const v=(R=d==null?void 0:d[i])==null?void 0:R[a];return v!=null&&(p=this._displayArrayFormulaRangeShape(v,o,c,i,a,f,p)),p?{...t,...p}:r(t)}})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{(t.id===b.SetFormulaCalculationResultMutation.id||t.id===b.SetArrayFormulaDataMutation.id&&n&&n.remove)&&this._removeArrayFormulaRangeShape()})),this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{j.SetWorksheetRowAutoHeightMutation.id===t.id&&requestIdleCallback(()=>{const n=t.params,{unitId:r,subUnitId:o,rowsAutoHeightInfo:c}=n;this._refreshArrayFormulaRangeShapeByRow(r,o,c)})}))}_displayArrayFormulaRangeShape(t,n,r,o,c,i,a){const f=this._formulaDataModel.getSheetFormulaData(o,c);return new s.ObjectMatrix(t).forValue((d,h,p)=>{var E;if(p==null)return!0;const{startRow:m,startColumn:v,endRow:l,endColumn:g}=p;if(d===n&&h===r)return this._createArrayFormulaRangeShape(p,o),!1;if(n>=m&&n<=l&&r>=v&&r<=g){const R=i.getCell(m,v);if((R==null?void 0:R.v)===b.ErrorType.SPILL)return;const I=(E=f==null?void 0:f[d])==null?void 0:E[h];return I==null||I.f==null?!0:(a==null&&(a={f:I.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(p,o),!1)}}),a}_createArrayFormulaRangeShape(t,n){const r=this._renderManagerService.getRenderById(n),o=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!r||!o)return;const{scene:c}=r;if(!c)return;const i=this._themeService.getCurrentTheme(),a={range:t,primary:null,style:{strokeWidth:1,stroke:i.hyacinth700,fill:new s.ColorKit(i.colorWhite).setAlpha(0).toString(),widgets:{}}},f=k.attachSelectionWithCoord(a,o),{rowHeaderWidth:d,columnHeaderHeight:h}=o,p=new k.SelectionControl(c,k.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:d,columnHeaderHeight:h});p.updateRangeBySelectionWithCoord(f),p.setEvent(!1),this._previousShape=p}_removeArrayFormulaRangeShape(){this._previousShape!=null&&(this._previousShape.dispose(),this._previousShape=null)}_refreshArrayFormulaRangeShape(t,n){if(this._previousShape){const{startRow:r,endRow:o,startColumn:c,endColumn:i}=this._previousShape.getRange(),a={startRow:r,endRow:o,startColumn:c,endColumn:i};this._removeArrayFormulaRangeShape(),this._createArrayFormulaRangeShape(a,t)}}_checkCurrentSheet(t,n){const r=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!r)return!1;const o=r.worksheet;return o?o.unitId===t&&o.getSheetId()===n:!1}_updateArrayFormulaRangeShape(t,n){this._checkCurrentSheet(t,n)&&this._previousShape&&this._refreshArrayFormulaRangeShape(t)}_refreshArrayFormulaRangeShapeByRow(t,n,r){if(!this._checkCurrentSheet(t,n)||!this._previousShape)return;const{startRow:o,endRow:c,startColumn:i,endColumn:a}=this._previousShape.getRange();for(let f=0;f<r.length;f++){const{row:d}=r[f];if(o>=d){const h={startRow:o,endRow:c,startColumn:i,endColumn:a};this._refreshArrayFormulaRangeShape(t,h);break}}}};st=wo([Le(1,s.Inject(j.SheetInterceptorService)),Le(2,s.Inject(b.FormulaDataModel)),Le(3,s.Inject(s.ThemeService)),Le(4,G.IRenderManagerService),Le(5,s.Inject(k.SheetSkeletonManagerService)),Le(6,s.ICommandService),Le(7,s.ILogService)],st);var $o=Object.defineProperty,ko=Object.getOwnPropertyDescriptor,xo=(e,t,n,r)=>{for(var o=r>1?void 0:r?ko(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&$o(t,n,o),o},ln=(e,t)=>(n,r)=>t(n,r,e);const Ho={tl:{size:6,color:"#409f11"}};let it=class extends s.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(j.INTERCEPTOR_POINT.CELL_CONTENT,{effect:s.InterceptorEffectEnum.Style,handler:(n,r,o)=>{var a,f,d,h;const c=(h=(d=(f=(a=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:a[r.unitId])==null?void 0:f[r.subUnitId])==null?void 0:d[r.row])==null?void 0:h[r.col];return sn(n,!!c)?o({...n,markers:{...n==null?void 0:n.markers,...Ho}}):o(n)},priority:10}))}};it=xo([ln(0,s.Inject(j.SheetInterceptorService)),ln(1,s.Inject(b.FormulaDataModel))],it);function Wo(){const e=s.useDependency(Ne.TriggerCalculationController),t=s.useDependency(s.ICommandService),n=s.useObservable(e.progress$),r=u.useCallback(()=>{t.executeCommand(b.SetFormulaCalculationStopMutation.id)},[t]),o=u.useCallback(()=>{e.clearProgress()},[e]);return C.jsx(_.ProgressBar,{progress:n,onTerminate:r,onClearProgress:o})}const Bo=(e,t=100)=>{u.useEffect(()=>{let n=null;const r=()=>{n===null&&(n=window.setTimeout(()=>{e(),n=null},t))};return window.addEventListener("scroll",r),window.addEventListener("resize",r),()=>{n!==null&&clearTimeout(n),window.removeEventListener("scroll",r),window.removeEventListener("resize",r)}},[e,t])},ie={formulaHelpFunction:"univer-formula-help-function",formulaHelpFunctionTitle:"univer-formula-help-function-title",formulaHelpFunctionTitleIcons:"univer-formula-help-function-title-icons",formulaHelpFunctionTitleIcon:"univer-formula-help-function-title-icon",formulaHelpFunctionContent:"univer-formula-help-function-content",formulaHelpFunctionContentInner:"univer-formula-help-function-content-inner",formulaHelpFunctionContentParams:"univer-formula-help-function-content-params",formulaHelpFunctionContentParamsTitle:"univer-formula-help-function-content-params-title",formulaHelpFunctionContentParamsDetail:"univer-formula-help-function-content-params-detail",formulaHelpFunctionActive:"univer-formula-help-function-active",formulaHelpDecorator:"univer-formula-help-decorator",formulaHelpParam:"univer-formula-help-param",formulaHelpParamPrefix:"univer-formula-help-param-prefix",formulaHelpParamItem:"univer-formula-help-param-item",formulaHelpParamActive:"univer-formula-help-param-active"};function Vo(){const[e,t]=u.useState(!1),[n,r]=u.useState(!0),[o,c]=u.useState(!0),[i,a]=u.useState(0),[f,d]=u.useState([0,0]),[h,p]=u.useState({left:0,top:0}),[m,v]=u.useState(null),l=s.useDependency(Ve),g=s.useDependency(s.LocaleService),E=g.t("formula.prompt.required"),R=g.t("formula.prompt.optional"),I=s.useDependency(s.IUniverInstanceService),y=s.useDependency(te.IEditorService),D=s.useDependency(_.ISidebarService),A=s.useInjector();Bo(F),u.useEffect(()=>{const N=l.help$.subscribe($=>{const{visible:M,paramIndex:S,functionInfo:T}=$;if(!M){t(M);return}const P=L();if(P==null)return;const{left:H,top:V,height:Z}=P;T.description===""&&T.functionParameter.length===0||(d([H,V+Z]),a(S),v(T),p({left:H,top:V}),t(M))}),O=D.scrollEvent$.pipe(q.throttleTime(100)).subscribe(F);return()=>{N==null||N.unsubscribe(),O.unsubscribe()}},[]);function F(){if(!o)return;const N=L();if(N==null)return;const{left:O,top:$,height:M}=N;d([O,$+M])}function L(){const N=I.getCurrentUniverDocInstance();if(!N)return;const O=N.getUnitId();if(!y.isEditor(O))return;const $=y.getEditor(O);return $==null?void 0:$.getBoundingClientRect()}function x(N){a(N)}function w(){c(!o),A.get(_.ILayoutService).focus()}return C.jsx(C.Fragment,{children:o?C.jsx(me.Popup,{visible:e,offset:f,children:m?C.jsxs("div",{className:ie.formulaHelpFunction,children:[C.jsxs("div",{className:ie.formulaHelpFunctionTitle,children:[C.jsx(Ko,{prefix:m.functionName,value:m.functionParameter,active:i,onClick:x}),C.jsxs("div",{className:ie.formulaHelpFunctionTitleIcons,children:[C.jsx("div",{className:ie.formulaHelpFunctionTitleIcon,style:{transform:n?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>r(!n),children:C.jsx(dt,{})}),C.jsx("div",{className:ie.formulaHelpFunctionTitleIcon,onClick:w,children:C.jsx(Qe,{})})]})]}),C.jsx("div",{className:ie.formulaHelpFunctionContent,style:{height:n?"unset":0,padding:n?"revert-layer":0},children:C.jsxs("div",{className:ie.formulaHelpFunctionContentInner,children:[C.jsx(Rt,{title:g.t("formula.prompt.helpExample"),value:`${m.functionName}(${m.functionParameter.map(N=>N.example).join(",")})`}),C.jsx(Rt,{title:g.t("formula.prompt.helpAbstract"),value:m.description}),m&&m.functionParameter&&m.functionParameter.map((N,O)=>C.jsx(Rt,{className:i===O?ie.formulaHelpFunctionActive:"",title:N.name,value:`${N.require?E:R} ${N.detail}`},O))]})})]}):C.jsx(C.Fragment,{})}):e?C.jsx("div",{className:ie.formulaHelpDecorator,onClick:()=>c(!o),style:{left:h.left-24,top:h.top},children:C.jsx(xt,{})}):C.jsx(C.Fragment,{})})}const Rt=e=>C.jsxs("div",{className:ie.formulaHelpFunctionContentParams,children:[C.jsx("div",{className:`
14
+ ${ie.formulaHelpFunctionContentParamsTitle}
15
+ ${e.className}
16
+ `,children:e.title}),C.jsx("div",{className:ie.formulaHelpFunctionContentParamsDetail,children:e.value})]}),Ko=e=>{const{prefix:t,value:n,active:r,onClick:o}=e;return C.jsxs("div",{className:ie.formulaHelpParam,children:[C.jsxs("span",{className:ie.formulaHelpParamPrefix,children:[t,"("]}),n&&n.map((c,i)=>C.jsxs("span",{className:ie.formulaHelpParamItem,children:[C.jsx("span",{className:r===i?ie.formulaHelpFunctionActive:ie.formulaHelpParamActive,onClick:()=>o(i),children:Ct(c)}),i===n.length-1?"":","]},i)),")"]})},Fe={formulaSearchFunction:"univer-formula-search-function",formulaSearchFunctionItem:"univer-formula-search-function-item",formulaSearchFunctionItemName:"univer-formula-search-function-item-name",formulaSearchFunctionItemNameLight:"univer-formula-search-function-item-name-light",formulaSearchFunctionItemDesc:"univer-formula-search-function-item-desc",formulaSearchFunctionItemActive:"univer-formula-search-function-item-active"};function Uo(){const[e,t]=u.useState(!1),[n,r]=u.useState(0),[o,c]=u.useState([0,0]),[i,a]=u.useState([]),[f,d]=u.useState(""),h=u.useRef(null),p=s.useDependency(Ve),m=s.useDependency(s.IUniverInstanceService),v=s.useDependency(te.IEditorService);u.useEffect(()=>{let I=[],y=0;const D=p.search$.subscribe(L=>{const{visible:x,searchText:w,searchList:N}=L;if(!x){t(x);return}const O=l();if(O==null)return;const{left:$,top:M,height:S}=O;d(w),a(N),I=N,c([$,M+S]),t(x),r(0),y=0}),A=p.navigate$.subscribe(L=>{const{direction:x}=L;if(x===s.Direction.UP){let w=y-1;w=w<0?I.length-1:w,r(w),y=w}else if(x===s.Direction.DOWN){let w=y+1;w=w>=I.length?0:w,r(w),y=w}R(y)}),F=p.accept$.subscribe(L=>{const x=I[y].name;p.acceptFormulaName(x)});return()=>{D==null||D.unsubscribe(),A==null||A.unsubscribe(),F==null||F.unsubscribe()}},[]);function l(){const y=m.getCurrentUniverDocInstance().getUnitId();if(!v.isEditor(y))return;const D=v.getEditor(y);return D==null?void 0:D.getBoundingClientRect()}function g(I){r(I)}function E(){r(-1)}function R(I){var $;const y=($=h.current)==null?void 0:$.querySelectorAll(`.${Fe.formulaSearchFunctionItem}`)[I];if(!y)return;const D=y.parentNode;if(!D)return;const F=D.getBoundingClientRect().top,L=D.offsetHeight,x=y.getBoundingClientRect(),w=x.top,N=x.height;if(w>=0&&w>F&&w-F+N<=L)return;const O=y.offsetTop-(L-N)/2;D.scrollTo({top:O,behavior:"smooth"})}return i.length>0&&C.jsx(me.Popup,{visible:e,offset:o,children:C.jsx("ul",{className:Fe.formulaSearchFunction,ref:h,children:i.map((I,y)=>C.jsxs("li",{className:n===y?`
17
+ ${Fe.formulaSearchFunctionItem}
18
+ ${Fe.formulaSearchFunctionItemActive}
19
+ `:Fe.formulaSearchFunctionItem,onMouseEnter:()=>g(y),onMouseLeave:E,onClick:()=>p.acceptFormulaName(I.name),children:[C.jsxs("span",{className:Fe.formulaSearchFunctionItemName,children:[C.jsx("span",{className:Fe.formulaSearchFunctionItemNameLight,children:I.name.substring(0,f.length)}),C.jsx("span",{children:I.name.slice(f.length)})]}),C.jsx("span",{className:Fe.formulaSearchFunctionItemDesc,children:I.desc})]},y))})})}function jo(){return C.jsxs(C.Fragment,{children:[C.jsx(Uo,{}),C.jsx(Vo,{})]})}const un={formulaMoreFunctions:"univer-formula-more-functions",formulaMoreFunctionsOperation:"univer-formula-more-functions-operation"};function fn(e){const{prefix:t,value:n}=e;return C.jsxs("div",{children:[C.jsxs("span",{children:[t,"("]}),n&&n.map((r,o)=>C.jsxs("span",{children:[C.jsx("span",{children:Ct(r)}),o===n.length-1?"":","]},o)),")"]})}const Tt={formulaFunctionParams:"univer-formula-function-params",formulaFunctionParamsTitle:"univer-formula-function-params-title",formulaFunctionParamsDetail:"univer-formula-function-params-detail"};function ze(e){const{className:t,value:n,title:r}=e;return C.jsxs("div",{className:Tt.formulaFunctionParams,children:[C.jsx("div",{className:`
20
+ ${Tt.formulaFunctionParamsTitle}
29
21
  ${t}
30
- `,children:s}),v.jsx("div",{className:Nt.formulaFunctionParamsDetail,children:n})]})}const Xe={formulaInputParamsList:"univer-formula-input-params-list",formulaInputParamsListItemName:"univer-formula-input-params-list-item-name",formulaInputParamsListItemSelector:"univer-formula-input-params-list-item-selector"};function Zo(e){const{functionInfo:t,onChange:n}=e;if(!t)return null;f.useState([]);const[s,o]=f.useState(t.functionParameter),[c,i]=f.useState(-1);return v.jsxs("div",{className:Xe.formulaInputParams,children:[v.jsx("div",{className:Xe.formulaInputParamsList,children:s.map((a,l)=>v.jsxs("div",{children:[v.jsx("div",{className:Xe.formulaInputParamsListItemName,children:a.name}),v.jsx("div",{className:Xe.formulaInputParamsListItemSelector})]},l))}),v.jsx("div",{className:Xe.formulaInputParamsInfo,children:v.jsx(Ze,{title:c===-1?v.jsx(pn,{prefix:t.functionName,value:s}):s[c].name,value:c===-1?t.description:s[c].detail})})]})}const ye={formulaSelectFunctionSelect:"univer-formula-select-function-select",formulaSelectFunctionResult:"univer-formula-select-function-result",formulaSelectFunctionResultItem:"univer-formula-select-function-result-item",formulaSelectFunctionResultItemNameLight:"univer-formula-select-function-result-item-name-light",formulaSelectFunctionResultItemSelected:"univer-formula-select-function-result-item-selected",formulaSelectFunctionResultItemActive:"univer-formula-select-function-result-item-active",formulaSelectFunctionContent:"univer-formula-select-function-content"};function Xo(e){const{onChange:t}=e,n="-1",[s,o]=f.useState(""),[c,i]=f.useState([]),[a,l]=f.useState(0),[m,d]=f.useState(n),[p,h]=f.useState(0),[g,u]=f.useState(null),S=r.useDependency(Ne.IDescriptionService),I=r.useDependency(r.LocaleService),b=r.useDependency(E.ISidebarService),C=r.useObservable(b.sidebarOptions$),_=eo(N.FunctionType,I);_.unshift({label:I.t("formula.moreFunctions.allFunctions"),value:n});const T=I.t("formula.prompt.required"),x=I.t("formula.prompt.optional");f.useEffect(()=>{L(n)},[]),f.useEffect(()=>{P(0)},[c]),f.useEffect(()=>{C!=null&&C.visible&&(o(""),i([]),l(0),d(n),h(0),u(null),L(n))},[C]);const F=y=>{if(s.trim()==="")return y;const R=new RegExp(`(${s.toLocaleUpperCase()})`);return y.split(R).filter(Boolean).map((A,H)=>A.match(R)?v.jsx("span",{className:ye.formulaSelectFunctionResultItemNameLight,children:A},H):A)},P=y=>{if(c.length===0){u(null);return}h(y);const R=S.getFunctionInfo(c[y].name);if(!R){u(null);return}u(R),t(R)};function L(y){d(y);const R=S.getSearchListByType(+y);i(R)}function j(y){o(y);const R=S.getSearchListByName(y);i(R)}function O(y){if(y.stopPropagation(),y.key==="ArrowDown"){const R=a+1;l(R===c.length?0:R)}else if(y.key==="ArrowUp"){const R=a-1;l(R===-1?c.length-1:R)}else y.key==="Enter"&&P(a)}const M=y=>{l(y)},k=()=>{l(-1)};return v.jsxs("div",{children:[v.jsxs("div",{className:ye.formulaSelectFunctionSelect,children:[v.jsx(pe.Select,{value:m,options:_,onChange:L}),v.jsx(pe.Input,{placeholder:I.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:O,value:s,onChange:j,size:"large",allowClear:!0})]}),v.jsx("ul",{className:ye.formulaSelectFunctionResult,onKeyDown:O,tabIndex:-1,children:c.map(({name:y},R)=>v.jsxs("li",{className:a===R?`
31
- ${ye.formulaSelectFunctionResultItem}
32
- ${ye.formulaSelectFunctionResultItemActive}
33
- `:ye.formulaSelectFunctionResultItem,onMouseEnter:()=>M(R),onMouseLeave:k,onClick:()=>P(R),children:[p===R&&v.jsx(Wt,{className:ye.formulaSelectFunctionResultItemSelected}),v.jsx("span",{className:ye.formulaSelectFunctionResultItemName,children:F(y)})]},R))}),g&&v.jsxs("div",{className:ye.formulaSelectFunctionContent,children:[v.jsx(Ze,{title:g.functionName,value:g.description}),v.jsx(Ze,{title:I.t("formula.moreFunctions.syntax"),value:v.jsx(pn,{prefix:g.functionName,value:g.functionParameter})}),v.jsx(Ze,{title:I.t("formula.prompt.helpExample"),value:`${g.functionName}(${g.functionParameter.map(y=>y.example).join(",")})`}),g.functionParameter&&g.functionParameter.map((y,R)=>v.jsx(Ze,{title:y.name,value:`${y.require?T:x} ${y.detail}`},R))]})]})}function Jo(){const e=w.useActiveWorkbook(),[t,n]=f.useState(!0),[s,o]=f.useState(!1),[c,i]=f.useState(null),a=r.useDependency(w.IEditorBridgeService),l=r.useDependency(r.LocaleService),m=r.useDependency(te.IEditorService),d=r.useDependency(r.IUniverInstanceService);function p(){n(!t),o(!s)}function h(){const g=K.getSheetCommandTarget(d);if(!g)return;a.changeVisible({visible:!0,unitId:g.unitId,eventType:X.DeviceInputEventType.Dblclick});const u=m.getEditor(r.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),S=m.getEditor(r.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),I=`=${c==null?void 0:c.functionName}(`;u==null||u.replaceText(I),S==null||S.replaceText(I,!1)}return v.jsxs("div",{className:hn.formulaMoreFunctions,children:[t&&v.jsx(Xo,{onChange:i}),s&&v.jsx(Zo,{functionInfo:c,onChange:()=>{}}),v.jsxs("div",{className:hn.formulaMoreFunctionsOperation,children:[s&&v.jsx(pe.Button,{type:"primary",size:"small",onClick:p,children:l.t("formula.moreFunctions.next")}),s&&v.jsx(pe.Button,{size:"small",onClick:p,children:l.t("formula.moreFunctions.prev")}),t&&!!e&&v.jsx(pe.Button,{type:"primary",size:"small",onClick:h,children:l.t("formula.moreFunctions.confirm")})]})]})}function Qo(e){return{id:Qe.id,icon:"FunctionSingle",tooltip:"formula.insert.tooltip",type:E.MenuItemType.SELECTOR,selections:[{label:"SUM",value:"SUM",icon:"SumSingle"},{label:"AVERAGE",value:"AVERAGE",icon:"AvgSingle"},{label:"COUNT",value:"COUNT",icon:"CntSingle"},{label:"MAX",value:"MAX",icon:"MaxSingle"},{label:"MIN",value:"MIN",icon:"MinSingle"}],hidden$:E.getMenuHiddenObservable(e,r.UniverInstanceType.UNIVER_SHEET),disabled$:w.getCurrentRangeDisable$(e,{workbookTypes:[K.WorkbookEditablePermission],worksheetTypes:[K.WorksheetEditPermission,K.WorksheetSetCellValuePermission],rangeTypes:[K.RangeProtectionPermissionEditPoint]})}}function qo(e){return{id:$e.id,title:"formula.insert.more",type:E.MenuItemType.BUTTON}}function $o(e){return e.get(r.IUniverInstanceService).getCurrentTypeOfUnit$(r.UniverInstanceType.UNIVER_SHEET).pipe(G.switchMap(s=>s&&e.get(E.IClipboardInterfaceService)?new G.Observable(c=>c.next(!e.get(E.IClipboardInterfaceService).supportClipboard)):G.of(!0)))}function es(e){return{id:Je.id,type:E.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:$o(e).pipe(G.combineLatestWith(w.getCurrentRangeDisable$(e,{workbookTypes:[K.WorkbookEditablePermission],rangeTypes:[K.RangeProtectionPermissionEditPoint],worksheetTypes:[K.WorksheetSetCellValuePermission,K.WorksheetEditPermission]})),G.map(([t,n])=>t||n))}}const ts={[E.RibbonStartGroup.FORMULAS_INSERT]:{[Qe.id]:{order:1,menuItemFactory:Qo,[$e.id]:{order:1,menuItemFactory:qo}}},[w.PASTE_SPECIAL_MENU_ID]:{[Je.id]:{order:4,menuItemFactory:es}}},ns="meta_key_ctrl_And_Shift",at=[E.KeyCode.ARROW_DOWN,E.KeyCode.ARROW_UP,E.KeyCode.ARROW_LEFT,E.KeyCode.ARROW_RIGHT],os=[...at,E.KeyCode.ENTER,E.KeyCode.TAB,E.KeyCode.ESC];function ss(){const e=[];for(const t of os)e.push({id:Pe.id,binding:t,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:X.DeviceInputEventType.Keyboard,keycode:t}});return e}function rs(){const e=[];for(const t of at)e.push({id:Pe.id,binding:t|E.MetaKeys.SHIFT,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:X.DeviceInputEventType.Keyboard,keycode:t,metaKey:E.MetaKeys.SHIFT}});return e}function is(){const e=[];for(const t of at)e.push({id:Pe.id,binding:t|E.MetaKeys.CTRL_COMMAND,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:X.DeviceInputEventType.Keyboard,keycode:t,metaKey:E.MetaKeys.CTRL_COMMAND}});return e}function cs(){const e=[];for(const t of at)e.push({id:Pe.id,binding:t|E.MetaKeys.SHIFT|E.MetaKeys.CTRL_COMMAND,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:X.DeviceInputEventType.Keyboard,keycode:t,metaKey:ns}});return e}const as={id:dt.id,binding:E.KeyCode.F4,preconditions:e=>w.whenFormulaEditorActivated(e)};function ls(){const e=[];for(const t of[E.KeyCode.ENTER,E.KeyCode.TAB,E.KeyCode.ARROW_DOWN,E.KeyCode.ARROW_UP])e.push({id:Pe.id,binding:t,preconditions:n=>po(n),staticParameters:{eventType:X.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}var us=Object.defineProperty,fs=Object.getOwnPropertyDescriptor,ds=(e,t,n,s)=>{for(var o=s>1?void 0:s?fs(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(s?i(t,n,o):i(o))||o);return s&&o&&us(t,n,o),o},Le=(e,t)=>(n,s)=>t(n,s,e);let lt=class extends r.Disposable{constructor(e,t,n,s,o,c,i){super(),this._injector=e,this._menuManagerService=t,this._commandService=n,this._shortcutService=s,this._uiPartsService=o,this._renderManagerService=c,this._componentManager=i,this._initialize()}_initialize(){this._registerCommands(),this._registerMenus(),this._registerShortcuts(),this._registerComponents(),this._registerRenderModules()}_registerMenus(){this._menuManagerService.mergeMenu(ts)}_registerCommands(){[Je,Qe,$e,wt,Ft,Pe,dt].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...ss(),...rs(),...is(),...cs(),...ls(),as].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(E.BuiltInUIPart.CONTENT,()=>r.connectInjector(Go,this._injector))),this.disposeWithMe(this._uiPartsService.registerComponent(w.SheetsUIPart.FORMULA_AUX,()=>r.connectInjector(Vo,this._injector))),this._componentManager.register(Lt,Jo)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(r.UniverInstanceType.UNIVER_SHEET,[it]))}};lt=ds([Le(0,r.Inject(r.Injector)),Le(1,E.IMenuManagerService),Le(2,r.ICommandService),Le(3,E.IShortcutService),Le(4,E.IUIPartsService),Le(5,X.IRenderManagerService),Le(6,r.Inject(E.ComponentManager))],lt);var Sn=Object.defineProperty,ms=Object.getOwnPropertyDescriptor,hs=(e,t,n)=>t in e?Sn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ps=(e,t,n,s)=>{for(var o=s>1?void 0:s?ms(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(s?i(t,n,o):i(o))||o);return s&&o&&Sn(t,n,o),o},Mt=(e,t)=>(n,s)=>t(n,s,e),gn=(e,t,n)=>hs(e,typeof t!="symbol"?t+"":t,n);W.UniverSheetsFormulaUIPlugin=class extends r.Plugin{constructor(t=ln,n,s,o){super(),this._config=t,this._injector=n,this._renderManagerService=s,this._configService=o;const{menu:c,...i}=r.merge(ln,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig(ho,i)}onStarting(){const t=this._injector;[[Ve,{useClass:ft}],[lt],[st],[rt],[it],[ct]].forEach(o=>t.add(o));const s=this._injector.get(E.ComponentManager);s.register(w.RANGE_SELECTOR_COMPONENT_KEY,on),s.register(w.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,an)}onRendered(){[[W.RefSelectionsRenderService],[Tt]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(r.UniverInstanceType.UNIVER_SHEET,t))}),r.touchDependencies(this._injector,[[lt],[rt],[ct]])}onSteady(){this._injector.get(st)}},gn(W.UniverSheetsFormulaUIPlugin,"pluginName",At),gn(W.UniverSheetsFormulaUIPlugin,"type",r.UniverInstanceType.UNIVER_SHEET),W.UniverSheetsFormulaUIPlugin=ps([r.DependentOn(N.UniverFormulaEnginePlugin,Ne.UniverSheetsFormulaPlugin),Mt(1,r.Inject(r.Injector)),Mt(2,X.IRenderManagerService),Mt(3,r.IConfigService)],W.UniverSheetsFormulaUIPlugin),W.FORMULA_PROMPT_ACTIVATED=xt,W.FormulaEditor=an,W.HelpFunctionOperation=Ft,W.InsertFunctionOperation=Qe,W.MoreFunctionsOperation=$e,W.RangeSelector=on,W.ReferenceAbsoluteOperation=dt,W.SearchFunctionOperation=wt,W.SelectEditorFormulaOperation=Pe,W.SheetOnlyPasteFormulaCommand=Je,Object.defineProperty(W,Symbol.toStringTag,{value:"Module"})});
22
+ `,children:r}),C.jsx("div",{className:Tt.formulaFunctionParamsDetail,children:n})]})}const Ge={formulaInputParamsList:"univer-formula-input-params-list",formulaInputParamsListItemName:"univer-formula-input-params-list-item-name",formulaInputParamsListItemSelector:"univer-formula-input-params-list-item-selector"};function qo(e){const{functionInfo:t,onChange:n}=e;if(!t)return null;u.useState([]);const[r,o]=u.useState(t.functionParameter),[c,i]=u.useState(-1);return C.jsxs("div",{className:Ge.formulaInputParams,children:[C.jsx("div",{className:Ge.formulaInputParamsList,children:r.map((a,f)=>C.jsxs("div",{children:[C.jsx("div",{className:Ge.formulaInputParamsListItemName,children:a.name}),C.jsx("div",{className:Ge.formulaInputParamsListItemSelector})]},f))}),C.jsx("div",{className:Ge.formulaInputParamsInfo,children:C.jsx(ze,{title:c===-1?C.jsx(fn,{prefix:t.functionName,value:r}):r[c].name,value:c===-1?t.description:r[c].detail})})]})}const Re={formulaSelectFunctionSelect:"univer-formula-select-function-select",formulaSelectFunctionResult:"univer-formula-select-function-result",formulaSelectFunctionResultItem:"univer-formula-select-function-result-item",formulaSelectFunctionResultItemNameLight:"univer-formula-select-function-result-item-name-light",formulaSelectFunctionResultItemSelected:"univer-formula-select-function-result-item-selected",formulaSelectFunctionResultItemActive:"univer-formula-select-function-result-item-active",formulaSelectFunctionContent:"univer-formula-select-function-content"};function Yo(e){const{onChange:t}=e,n="-1",[r,o]=u.useState(""),[c,i]=u.useState([]),[a,f]=u.useState(0),[d,h]=u.useState(n),[p,m]=u.useState(0),[v,l]=u.useState(null),g=s.useDependency(Ne.IDescriptionService),E=s.useDependency(s.LocaleService),R=s.useDependency(_.ISidebarService),I=s.useObservable(R.sidebarOptions$),y=Jn(b.FunctionType,E);y.unshift({label:E.t("formula.moreFunctions.allFunctions"),value:n});const D=E.t("formula.prompt.required"),A=E.t("formula.prompt.optional");u.useEffect(()=>{x(n)},[]),u.useEffect(()=>{L(0)},[c]),u.useEffect(()=>{I!=null&&I.visible&&(o(""),i([]),f(0),h(n),m(0),l(null),x(n))},[I]);const F=M=>{if(r.trim()==="")return M;const S=new RegExp(`(${r.toLocaleUpperCase()})`);return M.split(S).filter(Boolean).map((P,H)=>P.match(S)?C.jsx("span",{className:Re.formulaSelectFunctionResultItemNameLight,children:P},H):P)},L=M=>{if(c.length===0){l(null);return}m(M);const S=g.getFunctionInfo(c[M].name);if(!S){l(null);return}l(S),t(S)};function x(M){h(M);const S=g.getSearchListByType(+M);i(S)}function w(M){o(M);const S=g.getSearchListByName(M);i(S)}function N(M){if(M.stopPropagation(),M.key==="ArrowDown"){const S=a+1;f(S===c.length?0:S)}else if(M.key==="ArrowUp"){const S=a-1;f(S===-1?c.length-1:S)}else M.key==="Enter"&&L(a)}const O=M=>{f(M)},$=()=>{f(-1)};return C.jsxs("div",{children:[C.jsxs("div",{className:Re.formulaSelectFunctionSelect,children:[C.jsx(me.Select,{value:d,options:y,onChange:x}),C.jsx(me.Input,{placeholder:E.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:N,value:r,onChange:w,size:"large",allowClear:!0})]}),C.jsx("ul",{className:Re.formulaSelectFunctionResult,onKeyDown:N,tabIndex:-1,children:c.map(({name:M},S)=>C.jsxs("li",{className:a===S?`
23
+ ${Re.formulaSelectFunctionResultItem}
24
+ ${Re.formulaSelectFunctionResultItemActive}
25
+ `:Re.formulaSelectFunctionResultItem,onMouseEnter:()=>O(S),onMouseLeave:$,onClick:()=>L(S),children:[p===S&&C.jsx($t,{className:Re.formulaSelectFunctionResultItemSelected}),C.jsx("span",{className:Re.formulaSelectFunctionResultItemName,children:F(M)})]},S))}),v&&C.jsxs("div",{className:Re.formulaSelectFunctionContent,children:[C.jsx(ze,{title:v.functionName,value:v.description}),C.jsx(ze,{title:E.t("formula.moreFunctions.syntax"),value:C.jsx(fn,{prefix:v.functionName,value:v.functionParameter})}),C.jsx(ze,{title:E.t("formula.prompt.helpExample"),value:`${v.functionName}(${v.functionParameter.map(M=>M.example).join(",")})`}),v.functionParameter&&v.functionParameter.map((M,S)=>C.jsx(ze,{title:M.name,value:`${M.require?D:A} ${M.detail}`},S))]})]})}function zo(){const e=k.useActiveWorkbook(),[t,n]=u.useState(!0),[r,o]=u.useState(!1),[c,i]=u.useState(null),a=s.useDependency(k.IEditorBridgeService),f=s.useDependency(s.LocaleService),d=s.useDependency(te.IEditorService),h=s.useDependency(s.IUniverInstanceService);function p(){n(!t),o(!r)}function m(){const v=j.getSheetCommandTarget(h);if(!v)return;a.changeVisible({visible:!0,unitId:v.unitId,eventType:G.DeviceInputEventType.Dblclick});const l=d.getEditor(s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),g=d.getEditor(s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),E=`=${c==null?void 0:c.functionName}(`;l==null||l.replaceText(E),g==null||g.replaceText(E,!1)}return C.jsxs("div",{className:un.formulaMoreFunctions,children:[t&&C.jsx(Yo,{onChange:i}),r&&C.jsx(qo,{functionInfo:c,onChange:()=>{}}),C.jsxs("div",{className:un.formulaMoreFunctionsOperation,children:[r&&C.jsx(me.Button,{type:"primary",size:"small",onClick:p,children:f.t("formula.moreFunctions.next")}),r&&C.jsx(me.Button,{size:"small",onClick:p,children:f.t("formula.moreFunctions.prev")}),t&&!!e&&C.jsx(me.Button,{type:"primary",size:"small",onClick:m,children:f.t("formula.moreFunctions.confirm")})]})]})}function Go(e){return{id:Xe.id,icon:"FunctionSingle",tooltip:"formula.insert.tooltip",type:_.MenuItemType.SELECTOR,selections:[{label:"SUM",value:"SUM",icon:"SumSingle"},{label:"AVERAGE",value:"AVERAGE",icon:"AvgSingle"},{label:"COUNT",value:"COUNT",icon:"CntSingle"},{label:"MAX",value:"MAX",icon:"MaxSingle"},{label:"MIN",value:"MIN",icon:"MinSingle"}],hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:k.getCurrentRangeDisable$(e,{workbookTypes:[j.WorkbookEditablePermission],worksheetTypes:[j.WorksheetEditPermission,j.WorksheetSetCellValuePermission],rangeTypes:[j.RangeProtectionPermissionEditPoint]})}}function Zo(e){return{id:Je.id,title:"formula.insert.more",type:_.MenuItemType.BUTTON}}function Xo(e){return e.get(s.IUniverInstanceService).getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_SHEET).pipe(q.switchMap(r=>r&&e.get(_.IClipboardInterfaceService)?new q.Observable(c=>c.next(!e.get(_.IClipboardInterfaceService).supportClipboard)):q.of(!0)))}function Jo(e){return{id:Ze.id,type:_.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:Xo(e).pipe(q.combineLatestWith(k.getCurrentRangeDisable$(e,{workbookTypes:[j.WorkbookEditablePermission],rangeTypes:[j.RangeProtectionPermissionEditPoint],worksheetTypes:[j.WorksheetSetCellValuePermission,j.WorksheetEditPermission]})),q.map(([t,n])=>t||n))}}const Qo={[_.RibbonStartGroup.FORMULAS_INSERT]:{[Xe.id]:{order:1,menuItemFactory:Go,[Je.id]:{order:1,menuItemFactory:Zo}}},[k.PASTE_SPECIAL_MENU_ID]:{[Ze.id]:{order:4,menuItemFactory:Jo}}},er="meta_key_ctrl_And_Shift",ct=[_.KeyCode.ARROW_DOWN,_.KeyCode.ARROW_UP,_.KeyCode.ARROW_LEFT,_.KeyCode.ARROW_RIGHT],tr=[...ct,_.KeyCode.ENTER,_.KeyCode.TAB,_.KeyCode.ESC];function nr(){const e=[];for(const t of tr)e.push({id:Ae.id,binding:t,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:G.DeviceInputEventType.Keyboard,keycode:t}});return e}function or(){const e=[];for(const t of ct)e.push({id:Ae.id,binding:t|_.MetaKeys.SHIFT,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:G.DeviceInputEventType.Keyboard,keycode:t,metaKey:_.MetaKeys.SHIFT}});return e}function rr(){const e=[];for(const t of ct)e.push({id:Ae.id,binding:t|_.MetaKeys.CTRL_COMMAND,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:G.DeviceInputEventType.Keyboard,keycode:t,metaKey:_.MetaKeys.CTRL_COMMAND}});return e}function sr(){const e=[];for(const t of ct)e.push({id:Ae.id,binding:t|_.MetaKeys.SHIFT|_.MetaKeys.CTRL_COMMAND,preconditions:n=>k.whenFormulaEditorActivated(n),staticParameters:{eventType:G.DeviceInputEventType.Keyboard,keycode:t,metaKey:er}});return e}const ir={id:ft.id,binding:_.KeyCode.F4,preconditions:e=>k.whenFormulaEditorActivated(e)};function cr(){const e=[];for(const t of[_.KeyCode.ENTER,_.KeyCode.TAB,_.KeyCode.ARROW_DOWN,_.KeyCode.ARROW_UP])e.push({id:Ae.id,binding:t,preconditions:n=>ho(n),staticParameters:{eventType:G.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}var ar=Object.defineProperty,lr=Object.getOwnPropertyDescriptor,ur=(e,t,n,r)=>{for(var o=r>1?void 0:r?lr(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&ar(t,n,o),o},we=(e,t)=>(n,r)=>t(n,r,e);let at=class extends s.Disposable{constructor(e,t,n,r,o,c,i){super(),this._injector=e,this._menuManagerService=t,this._commandService=n,this._shortcutService=r,this._uiPartsService=o,this._renderManagerService=c,this._componentManager=i,this._initialize()}_initialize(){this._registerCommands(),this._registerMenus(),this._registerShortcuts(),this._registerComponents(),this._registerRenderModules()}_registerMenus(){this._menuManagerService.mergeMenu(Qo)}_registerCommands(){[Ze,Xe,Je,Lt,Ot,Ae,ft].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...nr(),...or(),...rr(),...sr(),...cr(),ir].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(_.BuiltInUIPart.CONTENT,()=>s.connectInjector(jo,this._injector))),this.disposeWithMe(this._uiPartsService.registerComponent(k.SheetsUIPart.FORMULA_AUX,()=>s.connectInjector(Wo,this._injector))),this._componentManager.register(At,zo)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,[st]))}};at=ur([we(0,s.Inject(s.Injector)),we(1,_.IMenuManagerService),we(2,s.ICommandService),we(3,_.IShortcutService),we(4,_.IUIPartsService),we(5,G.IRenderManagerService),we(6,s.Inject(_.ComponentManager))],at);var dn=Object.defineProperty,fr=Object.getOwnPropertyDescriptor,dr=(e,t,n)=>t in e?dn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,hr=(e,t,n,r)=>{for(var o=r>1?void 0:r?fr(t,n):t,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&dn(t,n,o),o},bt=(e,t)=>(n,r)=>t(n,r,e),hn=(e,t,n)=>dr(e,typeof t!="symbol"?t+"":t,n);W.UniverSheetsFormulaUIPlugin=class extends s.Plugin{constructor(t=rn,n,r,o){super(),this._config=t,this._injector=n,this._renderManagerService=r,this._configService=o;const{menu:c,...i}=s.merge(rn,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig(fo,i)}onStarting(){const t=this._injector;[[Ve,{useClass:ut}],[at],[ot],[rt],[st],[it]].forEach(o=>t.add(o));const r=this._injector.get(_.ComponentManager);r.register(k.RANGE_SELECTOR_COMPONENT_KEY,Qt),r.register(k.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,on)}onRendered(){[[W.RefSelectionsRenderService],[yt]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,t))}),s.touchDependencies(this._injector,[[at],[rt],[it]])}onSteady(){this._injector.get(ot)}},hn(W.UniverSheetsFormulaUIPlugin,"pluginName",Pt),hn(W.UniverSheetsFormulaUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),W.UniverSheetsFormulaUIPlugin=hr([s.DependentOn(b.UniverFormulaEnginePlugin,Ne.UniverSheetsFormulaPlugin),bt(1,s.Inject(s.Injector)),bt(2,G.IRenderManagerService),bt(3,s.IConfigService)],W.UniverSheetsFormulaUIPlugin),W.FORMULA_PROMPT_ACTIVATED=Nt,W.FormulaEditor=on,W.HelpFunctionOperation=Ot,W.InsertFunctionOperation=Xe,W.MoreFunctionsOperation=Je,W.RangeSelector=Qt,W.ReferenceAbsoluteOperation=ft,W.SearchFunctionOperation=Lt,W.SelectEditorFormulaOperation=Ae,W.SheetOnlyPasteFormulaCommand=Ze,Object.defineProperty(W,Symbol.toStringTag,{value:"Module"})});