@univerjs/sheets-formula-ui 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1,26 +1,26 @@
1
- "use strict";var En=Object.defineProperty;var _n=(e,t,n)=>t in e?En(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Z=(e,t,n)=>_n(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),w=require("@univerjs/sheets-ui"),D=require("@univerjs/engine-formula"),V=require("rxjs"),X=require("@univerjs/docs-ui"),K=require("@univerjs/engine-render"),H=require("@univerjs/sheets"),Ne=require("@univerjs/sheets-formula"),a=require("@univerjs/ui"),C=require("react/jsx-runtime"),le=require("@univerjs/design"),St=require("@univerjs/docs"),d=require("react"),jt=require("rxjs/operators"),nt={id:"sheet.command.paste-formula",type:l.CommandType.COMMAND,handler:async e=>e.get(l.ICommandService).executeCommand(w.SheetPasteCommand.id,{value:w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA})},ke={id:"formula-ui.operation.select-editor-formula",type:l.CommandType.OPERATION,handler:(e,t)=>!0};var yn=Object.getOwnPropertyDescriptor,Tn=(e,t,n,o)=>{for(var r=o>1?void 0:o?yn(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},bn=(e,t)=>(n,o)=>t(n,o,e);const Ht="FORMULA_PROMPT_ACTIVATED",Ge=l.createIdentifier("formula-ui.prompt-service");let ht=class{constructor(e){Z(this,"_search$",new V.Subject);Z(this,"_help$",new V.Subject);Z(this,"_navigate$",new V.Subject);Z(this,"_accept$",new V.Subject);Z(this,"_acceptFormulaName$",new V.Subject);Z(this,"search$",this._search$.asObservable());Z(this,"help$",this._help$.asObservable());Z(this,"navigate$",this._navigate$.asObservable());Z(this,"accept$",this._accept$.asObservable());Z(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());Z(this,"_searching",!1);Z(this,"_helping",!1);Z(this,"_sequenceNodes",[]);Z(this,"_isLockedOnSelectionChangeRefString",!1);Z(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(Ht,e.visible),this._searching=e.visible,this._search$.next(e)}isSearching(){return this._searching}help(e){this._helping=e.visible,this._help$.next(e)}isHelping(){return this._helping}navigate(e){this._navigate$.next(e)}accept(e){this._accept$.next(e)}acceptFormulaName(e){this._acceptFormulaName$.next(e)}getSequenceNodes(){return[...this._sequenceNodes]}setSequenceNodes(e){this._sequenceNodes=e}clearSequenceNodes(){this._sequenceNodes=[]}getCurrentSequenceNode(e){return this._sequenceNodes[this.getCurrentSequenceNodeIndex(e)]}getCurrentSequenceNodeByIndex(e){return this._sequenceNodes[e]}getCurrentSequenceNodeIndex(e){let t=0;const n=this._sequenceNodes[0];for(let o=0,r=this._sequenceNodes.length;o<r;o++){const s=this._sequenceNodes[o];if(typeof s=="string")t++;else{const{endIndex:i}=s;t=i}if(e<=t)return typeof n=="string"&&e!==0?o+1:o}return this._sequenceNodes.length}updateSequenceRef(e,t){const n=this._sequenceNodes[e];if(typeof n=="string"||n.nodeType!==D.sequenceNodeType.REFERENCE)return;const o=t.length-n.token.length,r={...n};r.token=t,r.endIndex+=o,this._sequenceNodes[e]=r;for(let s=e+1,i=this._sequenceNodes.length;s<i;s++){const c=this._sequenceNodes[s];if(typeof c=="string")continue;const f={...c};f.startIndex+=o,f.endIndex+=o,this._sequenceNodes[s]=f}}insertSequenceRef(e,t){const n=t.length,o=this.getCurrentSequenceNodeIndex(e);this._sequenceNodes.splice(o,0,{token:t,startIndex:e,endIndex:e+n-1,nodeType:D.sequenceNodeType.REFERENCE});for(let r=o+1,s=this._sequenceNodes.length;r<s;r++){const i=this._sequenceNodes[r];if(typeof i=="string")continue;const c={...i};c.startIndex+=n,c.endIndex+=n,this._sequenceNodes[r]=c}}insertSequenceString(e,t){const n=this.getCurrentSequenceNodeIndex(e),o=t.split("");this._sequenceNodes.splice(n,0,...o);const r=o.length;for(let s=n+r,i=this._sequenceNodes.length;s<i;s++){const c=this._sequenceNodes[s];if(typeof c=="string")continue;const f={...c};f.startIndex+=r,f.endIndex+=r,this._sequenceNodes[s]=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}};ht=Tn([bn(0,l.IContextService)],ht);const Ut={id:"formula-ui.operation.help-function",type:l.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ge).help(t),!0)},ot={id:"formula-ui.operation.insert-function",type:l.CommandType.OPERATION,handler:async(e,t)=>{var E,b;const n=e.get(H.SheetsSelectionsService),o=e.get(X.IEditorService),r=n.getCurrentSelections();if(!r||!r.length)return!1;const s=H.getSheetCommandTarget(e.get(l.IUniverInstanceService));if(!s)return!1;const{worksheet:i,unitId:c,subUnitId:f}=s,m=i.getCellMatrix(),{value:g}=t,S=e.get(l.ICommandService);e.get(w.IEditorBridgeService);const h=[],p=[];let u=null,_=0,I=0,R="";if(r.length===1&&(Nn(r[0].range)||Fn(r[0].range)&&Ot(m,r[0].range))){const{range:T,primary:O}=r[0],F=(E=O==null?void 0:O.actualRow)!=null?E:T.startRow,$=(b=O==null?void 0:O.actualColumn)!=null?b:T.startColumn;u=T,_=F,I=$;const k=Ft(m,F,$);k&&(R=D.serializeRange(k))}else r.some(T=>{var $,k;const{range:O,primary:F}=T;if(Ot(m,O)){const L=($=F==null?void 0:F.actualRow)!=null?$:O.startRow,x=(k=F==null?void 0:F.actualColumn)!=null?k:O.startColumn,M=Ft(m,L,x);if(!M)return u=O,_=L,I=x,!0;const A=D.serializeRange(M),N=`=${g}(${A})`;h.push({range:O,primary:{row:L,column:x},formula:N})}else{const{startRow:L,startColumn:x,endRow:M,endColumn:A}=O;if(L===M){const N=On(m,L,A,i.getColumnCount()-1),v=N===A?A-1:A,y=D.serializeRange({startRow:L,endRow:M,startColumn:x,endColumn:v}),P=`=${g}(${y})`;p.push({range:O,primary:{row:L,column:N},formula:P})}else{let N=-1;for(let y=x;y<=A;y++){const P=Dn(m,y,M,i.getRowCount()-1);N=Math.max(N,P)}const v=N===M?M-1:M;for(let y=x;y<=A;y++){const P=D.serializeRange({startRow:L,endRow:v,startColumn:y,endColumn:y}),j=`=${g}(${P})`;p.push({range:O,primary:{row:N,column:y},formula:j})}}}return!1});if(u){const T=H.getCellAtRowCol(_,I,i),O={range:l.Rectangle.clone(u),primary:{startRow:T.startRow,startColumn:T.startColumn,endRow:T.endRow,endColumn:T.endColumn,actualRow:_,actualColumn:I,isMerged:T.isMerged,isMergedMainCell:T.startRow===_&&T.startColumn===I}},F={unitId:c,subUnitId:f,selections:[O]};await S.executeCommand(H.SetSelectionsOperation.id,F);const $=o.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),k=o.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);S.syncExecuteCommand(w.SetCellEditVisibleOperation.id,{visible:!0,unitId:c,eventType:K.DeviceInputEventType.Dblclick});const L=`=${g}(${R}`;$==null||$.replaceText(L),k==null||k.replaceText(L,!1)}return h.length===0&&p.length===0?!1:S.executeCommand(Ne.InsertFunctionCommand.id,{list:h,listOfRangeHasNumber:p})}};function Ft(e,t,n){const o=Mn(e,t,n);if(o!==t)return{startRow:o,endRow:t-1,startColumn:n,endColumn:n};const r=xn(e,t,n);return r!==n?{startRow:t,endRow:t,startColumn:r,endColumn:n-1}:null}function Mn(e,t,n){let o=!1;if(t===0)return t;for(let r=t-1;r>=0;r--){const s=e.getValue(r,n);if(Ye(s)&&!o){if(r===0)return 0;o=!0}else{if(o&&!Ye(s))return r+1;if(o&&r===0)return 0}}return t}function xn(e,t,n){let o=!1;if(n===0)return n;for(let r=n-1;r>=0;r--){const s=e.getValue(t,r);if(Ye(s)&&!o){if(r===0)return 0;o=!0}else{if(o&&!Ye(s))return r+1;if(o&&r===0)return 0}}return n}function Ye(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return!1;const n=t.dataStream,r=n.substring(n.length-2,n.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n;return l.isRealNum(r)}return e&&(e.t===l.CellValueType.NUMBER||l.getCellValueType(e)===l.CellValueType.NUMBER)}function Nn(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}function Fn(e){return e.startRow!==e.endRow&&e.startColumn!==e.endColumn}function Ot(e,t){for(let n=t.startRow;n<=t.endRow;n++)for(let o=t.startColumn;o<=t.endColumn;o++)if(Ye(e.getValue(n,o)))return!1;return!0}function On(e,t,n,o){for(let r=n;r<=o;r++)if(!e.getValue(t,r))return r;return o}function Dn(e,t,n,o){for(let r=n;r<=o;r++)if(!e.getValue(r,t))return r;return o}const Wt="SHEET_FORMULA_UI_PLUGIN",Bt=`${Wt}_MORE_FUNCTIONS_COMPONENT`,rt={id:"formula-ui.operation.more-functions",type:l.CommandType.OPERATION,handler:async e=>(e.get(a.ISidebarService).open({header:{title:"formula.insert.tooltip"},children:{label:Bt}}),!0)},vt={id:"formula-ui.operation.change-ref-to-absolute",type:l.CommandType.OPERATION,handler:async e=>!0},Vt={id:"formula-ui.operation.search-function",type:l.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ge).search(t),!0)};var he=function(){return he=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},he.apply(this,arguments)},An=function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]]);return n},Fe=d.forwardRef(function(e,t){var n=e.icon,o=e.id,r=e.className,s=e.extend,i=An(e,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(o," ").concat(r||"").trim(),f=d.useRef("_".concat(kn()));return Kt(n,"".concat(o),{defIds:n.defIds,idSuffix:f.current},he({ref:t,className:c},i),s)});function Kt(e,t,n,o,r){return d.createElement(e.tag,he(he({key:t},Pn(e,n,r)),o),(Ln(e,n).children||[]).map(function(s,i){return Kt(s,"".concat(t,"-").concat(e.tag,"-").concat(i),n,void 0,r)}))}function Pn(e,t,n){var o=he({},e.attrs);n!=null&&n.colorChannel1&&o.fill==="colorChannel1"&&(o.fill=n.colorChannel1);var r=t.defIds;return!r||r.length===0||(e.tag==="use"&&o["xlink:href"]&&(o["xlink:href"]=o["xlink:href"]+t.idSuffix),Object.entries(o).forEach(function(s){var i=s[0],c=s[1];typeof c=="string"&&(o[i]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),o}function Ln(e,t){var n,o=t.defIds;return!o||o.length===0?e:e.tag==="defs"&&(!((n=e.children)===null||n===void 0)&&n.length)?he(he({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&o&&o.indexOf(r.attrs.id)>-1?he(he({},r),{attrs:he(he({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):e}function kn(){return Math.random().toString(36).substring(2,8)}Fe.displayName="UniverIcon";var wn={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"}}]},qt=d.forwardRef(function(e,t){return d.createElement(Fe,Object.assign({},e,{id:"check-mark-single",ref:t,icon:wn}))});qt.displayName="CheckMarkSingle";var $n={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"}}]},st=d.forwardRef(function(e,t){return d.createElement(Fe,Object.assign({},e,{id:"close-single",ref:t,icon:$n}))});st.displayName="CloseSingle";var jn={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"}}]},Yt=d.forwardRef(function(e,t){return d.createElement(Fe,Object.assign({},e,{id:"delete-single",ref:t,icon:jn}))});Yt.displayName="DeleteSingle";var Hn={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"}}]},zt=d.forwardRef(function(e,t){return d.createElement(Fe,Object.assign({},e,{id:"details-single",ref:t,icon:Hn}))});zt.displayName="DetailsSingle";var Un={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"}}]},Gt=d.forwardRef(function(e,t){return d.createElement(Fe,Object.assign({},e,{id:"increase-single",ref:t,icon:Un}))});Gt.displayName="IncreaseSingle";var Wn={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"}}]},Ct=d.forwardRef(function(e,t){return d.createElement(Fe,Object.assign({},e,{id:"more-single",ref:t,icon:Wn}))});Ct.displayName="MoreSingle";var Bn={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"}}]},Zt=d.forwardRef(function(e,t){return d.createElement(Fe,Object.assign({},e,{id:"select-range-single",ref:t,icon:Bn}))});Zt.displayName="SelectRangeSingle";function Xt(e){var t,n,o="";if(typeof e=="string"||typeof e=="number")o+=e;else if(typeof e=="object")if(Array.isArray(e)){var r=e.length;for(t=0;t<r;t++)e[t]&&(n=Xt(e[t]))&&(o&&(o+=" "),o+=n)}else for(n in e)e[n]&&(o&&(o+=" "),o+=n);return o}function mt(){for(var e,t,n=0,o="",r=arguments.length;n<r;n++)(e=arguments[n])&&(t=Xt(e))&&(o&&(o+=" "),o+=t);return o}var Vn=Object.getOwnPropertyDescriptor,Kn=(e,t,n,o)=>{for(var r=o>1?void 0:o?Vn(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},we=(e,t)=>(n,o)=>t(n,o,e);exports.RefSelectionsRenderService=class extends w.BaseSelectionRenderService{constructor(n,o,r,s,i,c,f){super(o,r,s,i,c);Z(this,"_workbookSelections");Z(this,"_eventDisposables");this._context=n,this._contextService=c,this._refSelectionsService=f,this._workbookSelections=this._refSelectionsService.getWorkbookSelections(this._context.unitId),this._initSelectionChangeListener(),this._initSkeletonChangeListener(),this._initUserActionSyncListener(),this._setSelectionStyle(qn(this._themeService)),this._remainLastEnabled=!0,this._highlightHeader=!1}getLocation(){return this._skeleton.getLocation()}setRemainLastEnabled(n){this._remainLastEnabled=n}setSkipLastEnabled(n){this._skipLastEnabled=n}clearLastSelection(){const n=this._selectionControls[this._selectionControls.length-1];n&&(n.dispose(),this._selectionControls.pop())}enableSelectionChanging(){return this._disableSelectionChanging(),this._eventDisposables=this._initCanvasEventListeners(),l.toDisposable(()=>this._disableSelectionChanging())}_disableSelectionChanging(){var n;(n=this._eventDisposables)==null||n.dispose(),this._eventDisposables=null}disableSelectionChanging(){this._disableSelectionChanging()}_initCanvasEventListeners(){const n=this._getSheetObject(),{spreadsheetRowHeader:o,spreadsheetColumnHeader:r,spreadsheet:s,spreadsheetLeftTopPlaceholder:i}=n,{scene:c}=this._context,f=new l.DisposableCollection;return f.add(s==null?void 0:s.onPointerDown$.subscribeEvent((m,g)=>{this.inRefSelectionMode()&&(this._onPointerDown(m,s.zIndex+1,l.RANGE_TYPE.NORMAL,this._getActiveViewport(m)),m.button!==2&&g.stopPropagation())})),f.add(o==null?void 0:o.onPointerDown$.subscribeEvent((m,g)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:h}=w.getCoordByOffset(m.offsetX,m.offsetY,c,S);w.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,l.RANGE_TYPE.ROW)||(this._onPointerDown(m,(s.zIndex||1)+1,l.RANGE_TYPE.ROW,this._getActiveViewport(m),K.ScrollTimerType.Y),m.button!==2&&g.stopPropagation())})),f.add(r==null?void 0:r.onPointerDown$.subscribeEvent((m,g)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:h}=w.getCoordByOffset(m.offsetX,m.offsetY,c,S);w.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,l.RANGE_TYPE.COLUMN)||(this._onPointerDown(m,(s.zIndex||1)+1,l.RANGE_TYPE.COLUMN,this._getActiveViewport(m),K.ScrollTimerType.X),m.button!==2&&g.stopPropagation())})),f.add(i==null?void 0:i.onPointerDown$.subscribeEvent((m,g)=>{if(this._reset(),!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,h=w.getAllSelection(S);this._addSelectionControlByModelData(h),this._selectionMoveStart$.next(this.getSelectionDataWithStyle());const p=c.onPointerUp$.subscribeEvent(()=>{p.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});m.button!==2&&g.stopPropagation()})),f}_addSelectionControlByModelData(n){var c;const o=this._skeleton,r=(c=n.style)!=null?c:w.genNormalSelectionStyle(this._themeService),s=this._scene;return n.style=r,this.newSelectionControl(s,o,n)}_initSelectionChangeListener(){this.disposeWithMe(this._refSelectionsService.selectionSet$.subscribe(n=>{this._reset(),this._skeleton&&this.resetSelectionsByModelData(n||[])}))}_initUserActionSyncListener(){this.disposeWithMe(this.selectionMoveStart$.subscribe(n=>{this._updateSelections(n,H.SelectionMoveType.MOVE_START)})),this.disposeWithMe(this.selectionMoving$.subscribe(n=>{this._updateSelections(n,H.SelectionMoveType.MOVING)})),this.disposeWithMe(this.selectionMoveEnd$.subscribe(n=>{this._updateSelections(n,H.SelectionMoveType.MOVE_END)}))}_updateSelections(n,o){const s=this._context.unit.getActiveSheet().getSheetId();n.length!==0&&this._workbookSelections.setSelections(s,n.map(i=>H.convertSelectionDataToRange(i)),o)}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(n=>{if(!n)return;const{skeleton:o}=n,{scene:r}=this._context,s=r.getViewport(K.SHEET_VIEWPORT_KEY.VIEW_MAIN);this._skeleton&&this._skeleton.worksheet.getSheetId()!==o.worksheet.getSheetId()&&this._reset(),this._changeRuntime(o,r,s);const i=this._workbookSelections.getCurrentSelections();this.resetSelectionsByModelData(i)}))}_getActiveViewport(n){const o=this._getSheetObject();return o==null?void 0:o.scene.getActiveViewportByCoord(K.Vector2.FromArray([n.offsetX,n.offsetY]))}_getSheetObject(){return w.getSheetObject(this._context.unit,this._context)}_onPointerDown(n,o=0,r=l.RANGE_TYPE.NORMAL,s,i=K.ScrollTimerType.ALL){var M;this._rangeType=r;const c=this._skeleton,f=this._scene;if(!f||!c)return;s&&(this._activeViewport=s);const{offsetX:m,offsetY:g}=n,S=f.getViewport(K.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!S)return;const h=f.getCoordRelativeToViewport(K.Vector2.FromArray([m,g])),{x:p,y:u}=h;this._startViewportPosX=p,this._startViewportPosY=u;const _=f.getScrollXYInfoByViewport(h),{scaleX:I,scaleY:R}=f.getAncestorScale(),E=this._skeleton.getCellByOffset(p,u,I,R,_);if(!E)return;switch(r){case l.RANGE_TYPE.NORMAL:break;case l.RANGE_TYPE.ROW:E.startColumn=0,E.endColumn=this._skeleton.getColumnCount()-1;break;case l.RANGE_TYPE.COLUMN:E.startRow=0,E.endRow=this._skeleton.getRowCount()-1;break;case l.RANGE_TYPE.ALL:E.startRow=0,E.startColumn=0,E.endRow=this._skeleton.getRowCount()-1,E.endColumn=this._skeleton.getColumnCount()-1}const b={range:E,primary:E,style:null};b.range.rangeType=r;const T=w.attachSelectionWithCoord(b,this._skeleton);this._startRangeWhenPointerDown={...T.rangeWithCoord};const O={...T.rangeWithCoord,rangeType:r};let F=this.getActiveSelectionControl();const $=this.getSelectionControls();for(const A of $){if(n.button===2&&A.model.isInclude(O)){F=A;return}if(A.model.isEqual(O)){F=A;break}}this._checkClearPreviousControls(n);const k=F==null?void 0:F.model.currentCell,L=n.shiftKey&&k,x=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;L&&k?this._makeSelectionByTwoCells(k,O,c,r,F):x&&F?F.updateRangeBySelectionWithCoord(T):F=this.newSelectionControl(f,c,b);for(let A=0;A<this.getSelectionControls().length-1;A++)this.getSelectionControls()[A].clearHighlight();this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),f.disableObjectsEvent(),this._clearUpdatingListeners(),this._addEndingListeners(),(M=f.getTransformer())==null||M.clearSelectedObjects(),this._setupPointerMoveListener(S,F,r,i,p,u),this._escapeShortcutDisposable=this._shortcutService.forceEscape(),this._scenePointerUpSub=f.onPointerUp$.subscribeEvent(()=>{var A;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(A=this._escapeShortcutDisposable)==null||A.dispose(),this._escapeShortcutDisposable=null})}newSelectionControl(n,o,r){const s=this.getSelectionControls().length,{rowHeaderWidth:i,columnHeaderHeight:c}=o,f=new w.SelectionControl(n,s,this._themeService,{highlightHeader:this._highlightHeader,enableAutoFill:!1,rowHeaderWidth:i,columnHeaderHeight:c}),m=w.attachSelectionWithCoord(r,o);return f.updateRangeBySelectionWithCoord(m),this._selectionControls.push(f),f.setControlExtension({skeleton:o,scene:n,themeService:this._themeService,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),f}};exports.RefSelectionsRenderService=Kn([we(1,l.Inject(l.Injector)),we(2,l.Inject(l.ThemeService)),we(3,a.IShortcutService),we(4,l.Inject(w.SheetSkeletonManagerService)),we(5,l.IContextService),we(6,H.IRefSelectionsService)],exports.RefSelectionsRenderService);function qn(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 Yn=(e,t,n)=>{const r=a.useDependency(K.IRenderManagerService).getRenderById(e),s=r==null?void 0:r.with(exports.RefSelectionsRenderService);d.useEffect(()=>{if(n&&s){const i=n.input$.subscribe(c=>{c.content===D.matchToken.COMMA?s.setSkipLastEnabled(!0):s.setSkipLastEnabled(!1)});return()=>{i.unsubscribe()}}},[n,s]),d.useEffect(()=>{s&&(t.endsWith(D.matchToken.COMMA)||s.setSkipLastEnabled(!1))},[t,s])},it=()=>{const e=a.useDependency(D.LexerTreeBuilder);return d.useCallback(n=>e.sequenceNodesBuilder(n)||[],[e])},zn=(e,t,n,o,r,s)=>{const i=it(),c=d.useRef(!0);d.useEffect(()=>{var f,m;if(s){if(c.current){const g=i(e);if(g.length){const S=o(s,g);n&&r(S)}else{const S=s.getDocumentData(),p={dataStream:(m=(f=S.body)==null?void 0:f.dataStream)!=null?m:`${t}\r
2
- `,...S.body};s.setDocumentData({...S,body:p})}c.current=!1}else if(n){const g=i(e),S=o(s,g);r(S)}}},[s,n])},Jt=e=>{const t=a.useDependency(X.IEditorService);return a.useEvent(o=>{var r,s;if(e){t.focus(e.getEditorId());const i=[...e.getSelectionRanges()];if(l.Tools.isDefine(o))e.setSelectionRanges([{startOffset:o,endOffset:o}]);else if(!i.length&&!e.docSelectionRenderService.isOnPointerEvent){const c=(s=(r=e.getDocumentData().body)==null?void 0:r.dataStream)!=null?s:`\r
3
- `,f=Math.max(c.length-2,0);e.setSelectionRanges([{startOffset:f,endOffset:f}])}}})};function Gn(e,t,n){const o=e.getCurrentTheme(),r=new l.ColorKit(t).setAlpha(.05).toRgbString();return{id:n,strokeWidth:1,stroke:t,fill:r,widgets:{tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},widgetSize:6,widgetStrokeWidth:1,widgetStroke:o.colorWhite}}function Qt(e){var R,E,b;const{unitId:t,subUnitId:n,refSelections:o,editor:r,refSelectionsService:s,refSelectionsRenderService:i,sheetSkeletonManagerService:c,themeService:f,univerInstanceService:m}=e,g=m.getUnit(t,l.UniverInstanceType.UNIVER_SHEET),S=g==null?void 0:g.getActiveSheet(),h=[];if(!g||!S){s.setSelections(h);return}const p=S.getSheetId(),u=T=>{var O;return(O=g==null?void 0:g.getSheetBySheetName(T))==null?void 0:O.getSheetId()};if(!((R=c==null?void 0:c.getWorksheetSkeleton(p))==null?void 0:R.skeleton))return;const I=[];for(let T=0,O=o.length;T<O;T++){const F=o[T],{themeColor:$,token:k,refIndex:L,endIndex:x}=F,M=D.deserializeRangeWithSheet(k),{unitId:A,sheetName:N,range:v}=M;if(A&&t!==A)continue;const y=u(N);if(y&&y!==p||!y&&p!==n)continue;const P=H.setEndForRange(v,S.getRowCount(),S.getColumnCount());P.unitId=t,P.sheetId=p,h.push({range:P,primary:null,style:Gn(f,$,L.toString())}),I.push(x)}if(r){const T=(b=(E=r.getSelectionRanges())==null?void 0:E[0])==null?void 0:b.startOffset,O=I.findIndex(F=>F+2===T);O!==-1?i==null||i.setActiveSelectionIndex(O):i==null||i.resetActiveSelectionIndex()}return h}function It(e,t){const n=a.useDependency(l.IUniverInstanceService),o=a.useDependency(l.ThemeService),r=a.useDependency(H.IRefSelectionsService),i=a.useDependency(K.IRenderManagerService).getRenderById(e),c=i==null?void 0:i.with(exports.RefSelectionsRenderService),f=i==null?void 0:i.with(w.SheetSkeletonManagerService),m=a.useEvent((g,S)=>{if(c!=null&&c.selectionMoving)return;const h=Qt({unitId:e,subUnitId:t,refSelections:g,editor:S,refSelectionsService:r,refSelectionsRenderService:c,sheetSkeletonManagerService:f,themeService:o,univerInstanceService:n});if(!h)return;((c==null?void 0:c.getSelectionControls())||[]).length===h.length?c==null||c.resetSelectionsByModelData(h):r.setSelections(h)});return d.useEffect(()=>()=>{c==null||c.resetActiveSelectionIndex()},[c]),m}function en(e=""){const t=a.useDependency(Ne.IDescriptionService),n=tn(),o=a.useDependency(l.ICommandService),r=d.useMemo(()=>e.length,[e]);return d.useCallback((i,c,f=!0,m)=>{const g=i.getDocumentData(),S=i.getEditorId();if(!g)return[];const h=g.body;if(!h)return[];const p=h.dataStream.slice(0,h.dataStream.length-2),u={dataStream:"",...g.body};if(!p.startsWith(e))return[];if(c==null||c.length===0)return u.textRuns=[],o.syncExecuteCommand(X.ReplaceTextRunsCommand.id,{unitId:S,body:l.getBodySlice(u,0,u.dataStream.length-2)}),[];{const{textRuns:_,refSelections:I}=nn(t,n,c);r&&_.forEach(b=>{b.ed=b.ed+r,b.st=b.st+r}),u.textRuns=[{st:0,ed:1,ts:{fs:11}},..._];const R=c.reduce((b,T)=>typeof T=="string"?`${b}${T}`:`${b}${T.token}`,"");u.dataStream=`${e}${R}\r
4
- `;let E;if(f){E=i.getSelectionRanges();const b=u.dataStream.length-2+r;E.forEach(T=>{T.startOffset=Math.max(0,Math.min(T.startOffset,b)),T.endOffset=Math.max(0,Math.min(T.endOffset,b))})}return o.syncExecuteCommand(X.ReplaceTextRunsCommand.id,{unitId:S,body:l.getBodySlice(u,0,u.dataStream.length-2),textRanges:m!=null?m:E}),I}},[o,t,n,r,e])}function tn(){const t=a.useDependency(l.ThemeService).getCurrentTheme();return d.useMemo(()=>{const o=[t.loopColor1,t.loopColor2,t.loopColor3,t.loopColor4,t.loopColor5,t.loopColor6,t.loopColor7,t.loopColor8,t.loopColor9,t.loopColor10,t.loopColor11,t.loopColor12],r=t.hyacinth700,s=t.verdancy800,i=t.colorBlack;return{formulaRefColors:o,numberColor:r,stringColor:s,plainTextColor:i}},[t])}function nn(e,t,n){const{formulaRefColors:o,numberColor:r,stringColor:s,plainTextColor:i}=t,c=[],f=[],m=new Map;let g=0;for(let S=0,h=n.length;S<h;S++){const p=n[S];if(typeof p=="string"){const b=c[c.length-1],T=b?b.ed:0,O=T+p.length;c.push({st:T,ed:O,ts:{cl:{rgb:i},fs:11}});continue}if(e.hasDefinedNameDescription(p.token.trim())){c.push({st:p.startIndex,ed:p.endIndex+1,ts:{cl:{rgb:i},fs:11}});continue}const{startIndex:u,endIndex:_,nodeType:I,token:R}=p;let E="";if(I===D.sequenceNodeType.REFERENCE){if(m.has(R))E=m.get(R);else{const b=g%o.length;E=o[b],m.set(R,E),g++}f.push({refIndex:S,themeColor:E,token:R,startIndex:p.startIndex,endIndex:p.endIndex,index:f.length})}else I===D.sequenceNodeType.NUMBER?E=r:(I===D.sequenceNodeType.STRING||I===D.sequenceNodeType.ARRAY)&&(E=s);E&&E.length>0?c.push({st:u,ed:_+1,ts:{cl:{rgb:E},fs:11}}):c.push({st:u,ed:_+1,ts:{cl:{rgb:i},fs:11}})}return{textRuns:c,refSelections:f}}const je=e=>{const t=d.useRef(e);return t.current=e,t};function Zn(e){var r,s;const n=e.get(l.IUniverInstanceService).getCurrentUniverDocInstance();return n!=null&&n.getBody()?{dataStream:(s=(r=n.getBody())==null?void 0:r.dataStream)!=null?s:"",offset:0}:void 0}var ze=(e=>(e[e.NOT_SELECT=0]="NOT_SELECT",e[e.NEED_ADD=1]="NEED_ADD",e[e.CAN_EDIT=2]="CAN_EDIT",e))(ze||{});function Xn(e){var E;const{editorId:t,isFocus:n,disableOnClick:o,unitId:r}=e,s=a.useDependency(K.IRenderManagerService),i=s.getRenderById(r),c=s.getRenderById(t),f=c==null?void 0:c.with(X.DocSelectionRenderService),m=a.useDependency(St.DocSelectionManagerService),g=a.useDependency(l.Injector),[S,h]=d.useState(0),p=a.useDependency(D.LexerTreeBuilder),u=d.useRef(!0),_=i==null?void 0:i.with(exports.RefSelectionsRenderService),I=je(S),R=a.useEvent(b=>{_&&_.setSkipLastEnabled(b===1),I.current=b,h(b)});return d.useEffect(()=>{const b=m.textSelection$.pipe(V.filter(T=>T.unitId===t),V.map(()=>{const T=f==null?void 0:f.getActiveTextRange();return T!=null&&T.collapsed?T.startOffset:-1})).subscribe(T=>{var N,v;const O=Zn(g);if(!O)return;const F=(N=O==null?void 0:O.dataStream)==null?void 0:N.slice(0,-2),$=(v=p.sequenceNodesBuilder(F))!=null?v:[],k=F[T-1],L=F[T],x=$.findIndex(y=>typeof y=="object"&&y.nodeType===D.sequenceNodeType.REFERENCE&&T===y.endIndex+2),M=k&&D.matchRefDrawToken(k)&&(!L||D.isFormulaLexerToken(L)&&L!==D.matchToken.OPEN_BRACKET),A=x>-1;if((F==null?void 0:F.substring(0,1))==="="&&(M||A))if(A){if(u.current)return;R(2)}else u.current=!1,R(1);else R(0)});return()=>b.unsubscribe()},[m.textSelection$,f,t,g,p,R]),d.useEffect(()=>{n||(R(0),u.current=!0)},[n,R]),d.useEffect(()=>{var T;if(!o)return;const b=(T=c==null?void 0:c.mainComponent)==null?void 0:T.onPointerDown$.subscribeEvent(()=>{R(0),u.current=!0});return()=>b==null?void 0:b.unsubscribe()},[o,(E=c==null?void 0:c.mainComponent)==null?void 0:E.onPointerDown$,R]),{isSelecting:S,isSelectingRef:I}}const on=(e,t,n,o)=>{const r=a.useDependency(l.ICommandService),s=a.useDependency(a.IShortcutService),i=d.useRef(t);i.current=t;const c=d.useRef(o);c.current=o,d.useEffect(()=>{if(!n||!e)return;const m=`sheet.formula-embedding-editor.${n.getEditorId()}`,g=new l.DisposableCollection,S=(u,_)=>{if(c.current){c.current(u,_);return}let I=l.Direction.LEFT;u===a.KeyCode.ARROW_DOWN?I=l.Direction.DOWN:u===a.KeyCode.ARROW_UP?I=l.Direction.UP:u===a.KeyCode.ARROW_RIGHT&&(I=l.Direction.RIGHT),_===a.MetaKeys.SHIFT?r.executeCommand(X.MoveSelectionOperation.id,{direction:I}):r.executeCommand(X.MoveCursorOperation.id,{direction:I})},h=(u,_)=>{let I=l.Direction.DOWN;u===a.KeyCode.ARROW_DOWN?I=l.Direction.DOWN:u===a.KeyCode.ARROW_UP?I=l.Direction.UP:u===a.KeyCode.ARROW_LEFT?I=l.Direction.LEFT:u===a.KeyCode.ARROW_RIGHT&&(I=l.Direction.RIGHT),i.current?_===a.MetaKeys.CTRL_COMMAND?r.executeCommand(w.MoveSelectionCommand.id,{direction:I,jumpOver:w.JumpOver.moveGap,extra:"formula-editor",fromCurrentSelection:i.current===ze.NEED_ADD}):_===a.MetaKeys.SHIFT?r.executeCommand(w.ExpandSelectionCommand.id,{direction:I,extra:"formula-editor"}):_===(a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT)?r.executeCommand(w.ExpandSelectionCommand.id,{direction:I,jumpOver:w.JumpOver.moveGap,extra:"formula-editor"}):r.executeCommand(w.MoveSelectionCommand.id,{direction:I,extra:"formula-editor",fromCurrentSelection:i.current===ze.NEED_ADD}):S(u,_)};return g.add(r.registerCommand({id:m,type:l.CommandType.OPERATION,handler(u,_){const{keyCode:I,metaKey:R}=_;h(I,R)}})),[{keyCode:a.KeyCode.ARROW_DOWN},{keyCode:a.KeyCode.ARROW_LEFT},{keyCode:a.KeyCode.ARROW_RIGHT},{keyCode:a.KeyCode.ARROW_UP},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT}].map(({keyCode:u,metaKey:_})=>({id:m,binding:_?u|_:u,preconditions:()=>!0,priority:900,staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keyCode:u,metaKey:_}})).forEach(u=>{g.add(s.registerShortcut(u))}),()=>{g.dispose()}},[r,n,e,s])},rn=(e,t)=>{const o=a.useDependency(K.IRenderManagerService).getRenderById(e),r=o==null?void 0:o.with(exports.RefSelectionsRenderService);d.useEffect(()=>{r&&(t?r==null||r.setRemainLastEnabled(!1):r==null||r.setRemainLastEnabled(!0))},[t,r])},Rt=(e,t,n,o=!0)=>{const r=a.useDependency(K.IRenderManagerService),s=a.useDependency(l.IContextService),i=a.useDependency(a.IContextMenuService),c=a.useDependency(H.IRefSelectionsService),f=r.getRenderById(n),m=f==null?void 0:f.with(exports.RefSelectionsRenderService);d.useLayoutEffect(()=>{if(e)return s.setContextValue(l.EDITOR_ACTIVATED,!0),()=>{s.setContextValue(l.EDITOR_ACTIVATED,!1),c.clear()}},[s,e,c]),d.useLayoutEffect(()=>{if(e&&t){const g=m==null?void 0:m.enableSelectionChanging();return s.setContextValue(H.REF_SELECTIONS_ENABLED,!0),()=>{s.setContextValue(H.REF_SELECTIONS_ENABLED,!1),g==null||g.dispose()}}},[s,e,m,t]),d.useEffect(()=>{if(e)return s.setContextValue(l.EDITOR_ACTIVATED,!0),o&&i.disable(),()=>{s.setContextValue(l.EDITOR_ACTIVATED,!1),o&&i.enable()}},[i,s,e,o]),d.useEffect(()=>{e&&(m==null||m.setSkipLastEnabled(!1))},[e,m])},Jn=()=>{d.useEffect(()=>()=>{},[])},sn=(e,t,n)=>{const o=a.useDependency(l.IUniverInstanceService),r=a.useDependency(H.SheetsSelectionsService);return d.useCallback(()=>{if(e){const i=[...r.getWorkbookSelections(t).getSelectionsOfWorksheet(n)],c=o.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),f=c==null?void 0:c.getActiveSheet();f&&f.getSheetId()===n&&r.setSelections(i)}},[e,r,n,t,o])},gt=e=>typeof e=="string"?e===D.matchToken.COMMA:!1,Qn=e=>{if(typeof e=="object")return e.nodeType===D.sequenceNodeType.REFERENCE},eo=e=>e.filter(t=>gt(t)||Qn(t)),Et=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},Le=e=>e.map(t=>typeof t=="string"?t:t.token).join("");function Dt(e,t,n){var o,r;return((r=(o=e.getUnit(t))==null?void 0:o.getSheetBySheetId(n))==null?void 0:r.getName())||""}const Ie=(e,t=!1,n="")=>t?e.map(o=>o.sheetName!==""&&o.sheetName!==n?D.serializeRangeWithSheet(o.sheetName,o.range):D.serializeRange(o.range)):e.map(o=>D.serializeRange(o.range)),cn=(e,t,n,o,r,s,i)=>{const c=a.useDependency(K.IRenderManagerService),f=a.useDependency(l.IUniverInstanceService),m=d.useRef(!1),g=c.getRenderById(t),S=g==null?void 0:g.with(exports.RefSelectionsRenderService),h=d.useRef([]),p=d.useMemo(()=>{const _=eo(o),I=h.current;return _.length===I.length?(I.splice(0),I.push(..._),I):_},[o]);h.current=p;const u=d.useRef(void 0);d.useEffect(()=>{if(e&&S){let _=!0;const I=(b,T)=>{var N;if(_||m.current){_=!1;return}const O=[...b],F=f.getUnit(t),$=((N=F==null?void 0:F.getActiveSheet())==null?void 0:N.getName())||"",k=p.map((v,y)=>{if(typeof v=="string"){if(!p[y-1])return null;const j=p[y+1];return gt(v)&&(gt(j)||y===p.length-1)?null:v}else if(v.nodeType===D.sequenceNodeType.REFERENCE){const P=D.deserializeRangeWithSheet(v.token);P.unitId=P.unitId===""?t:P.unitId,P.sheetName=P.sheetName===""?$:P.sheetName;const{unitId:j,sheetName:W}=P;if(s&&(j!==t||$!==W))return null;if(j===t&&$===W){const z=O.shift();if(z&&Dt(f,t,z.rangeWithCoord.sheetId||"")===W){const re={...v};return Et(z.rangeWithCoord),r?re.token=D.serializeRangeWithSheet($,z.rangeWithCoord):re.token=D.serializeRange(z.rangeWithCoord),re}}return v}return null}).filter(v=>!!v),L=Ie(O.map(v=>{var y,P,j;return{range:v.rangeWithCoord,unitId:(y=v.rangeWithCoord.unitId)!=null?y:"",sheetName:Dt(f,(P=v.rangeWithCoord.unitId)!=null?P:"",(j=v.rangeWithCoord.sheetId)!=null?j:"")}}),r).join(D.matchToken.COMMA),x=Le(k),M=`${x}${x&&L?D.matchToken.COMMA:""}${L}`,A=m.current;i(M,A?-1:M.length,T)},R=S.selectionMoveEnd$.subscribe(b=>{if(I(b,!0),m.current=!1,u.current){const{result:T,offset:O}=u.current;i(T,O,!0),u.current=void 0}}),E=S.selectionMoving$.pipe(jt.throttleTime(50)).subscribe(b=>{I(b,!1)});return()=>{R.unsubscribe(),E.unsubscribe()}}},[e,p,S,r,s,i,f,t]),d.useEffect(()=>{if(e&&S){const _=new l.DisposableCollection,I=(b,T)=>{var A;let O=0,F=0,$=!1;const k=f.getUnit(t),L=((A=k==null?void 0:k.getActiveSheet())==null?void 0:A.getName())||"",x=p.map(N=>{if(typeof N=="string")return $||(F+=N.length),N;if(N.nodeType===D.sequenceNodeType.REFERENCE){const v=D.deserializeRangeWithSheet(b);if(v.unitId=v.unitId===""?t:v.unitId,v.sheetName=v.sheetName===""?L:v.sheetName,O===T){$=!0;const y={...N,token:b};return r?y.token=D.serializeRangeWithSheet(v.sheetName,v.range):y.token=D.serializeRange(v.range),O++,F+=y.token.length,y}return O++,$||(F+=N.token.length),N}return N}),M=Le(x);u.current={result:M,offset:F},i(M,-1,!1)};let R=0;const E=S.selectionMoveEnd$.subscribe(()=>{R=setTimeout(()=>{_.dispose(),S.getSelectionControls().forEach((T,O)=>{_.add(V.merge(T.selectionMoving$,T.selectionScaling$).pipe(V.map(F=>D.serializeRange(F)),V.distinctUntilChanged()).subscribe(F=>{m.current=!0,I(F,O)}))})},30)});return()=>{E.unsubscribe(),_.dispose(),clearTimeout(R)}}},[e,S,p,i,f,t,r])},_t=(e,t,n,o,r,s)=>{const i=a.useDependency(l.ICommandService),c=a.useDependency(X.IEditorService),m=a.useDependency(K.IRenderManagerService).getRenderById(t),g=m==null?void 0:m.with(exports.RefSelectionsRenderService);d.useEffect(()=>{if(e&&g)if(n){const S=i.onCommandExecuted(h=>{if(h.id===H.SetWorksheetActiveOperation.id){const p=g.getSelectionControls().length;for(let u=1;u<=p;u++)g.clearLastSelection();setTimeout(()=>{s()},30)}});return()=>{S.dispose()}}else{const S=i.beforeCommandExecuted(h=>{if(h.id===H.SetWorksheetActiveOperation.id){o(!1),r(),s();const p=c.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);p==null||p.focus()}});return()=>{S.dispose()}}},[e,g])},an=e=>!e.some(n=>{if(typeof n=="string"){if(n!==D.matchToken.COMMA)return!0}else if(n.nodeType!==D.sequenceNodeType.REFERENCE)return!0;return!1}),to=(e,t,n)=>{const o=d.useRef(!0);d.useEffect(()=>{if(e){const r=setTimeout(()=>{o.current=!1},500);return()=>{clearTimeout(r)}}},[e]),d.useEffect(()=>{if(!o.current&&t){const r=an(n);t(r,Le(n))}},[n,t])},no="univer-sheet-range-selector-text-wrap",oo="univer-sheet-range-selector-placeholder",ro="univer-sheet-range-selector-error",so="univer-sheet-range-selector-error-wrap",io="univer-sheet-range-selector-text",co="univer-sheet-range-selector-active",ao="univer-sheet-range-selector-icon",lo="univer-sheet-range-selector-dialog-item",uo="univer-sheet-range-selector-dialog-item-delete",Se={sheetRangeSelectorTextWrap:no,sheetRangeSelectorPlaceholder:oo,sheetRangeSelectorError:ro,sheetRangeSelectorErrorWrap:so,sheetRangeSelectorText:io,sheetRangeSelectorActive:co,sheetRangeSelectorIcon:ao,sheetRangeSelectorDialogItem:lo,sheetRangeSelectorDialogItemDelete:uo},We=()=>{};function ln(e){const{initValue:t,unitId:n,subUnitId:o,errorText:r,placeholder:s,actions:i,onChange:c=We,onVerify:f=We,onRangeSelectorDialogVisibleChange:m=We,onBlur:g=We,onFocus:S=We,isFocus:h=!0,isOnlyOneRange:p=!1,isSupportAcrossSheet:u=!1}=e,_=a.useEvent(c),I=a.useDependency(X.IEditorService),R=a.useDependency(l.LocaleService),E=a.useDependency(l.ICommandService),b=a.useDependency(D.LexerTreeBuilder),T=d.useRef(null),[O,F]=d.useState(!1),[$,k]=d.useState(h),L=d.useMemo(()=>l.createInternalEditorID(`${w.RANGE_SELECTOR_SYMBOLS}-${l.generateRandomId(4)}`),[]),x=d.useRef(void 0),M=x.current,A=d.useRef(null),N=a.useDependency(l.IUniverInstanceService),v=d.useMemo(()=>!O&&$,[O,$]),[y,P]=d.useState(()=>typeof t=="string"?t:Ie(t,u).join(D.matchToken.COMMA)),j=d.useMemo(()=>N.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_DOC),[N]),W=a.useObservable(j),z=(W==null?void 0:W.getUnitId())===L,re=d.useRef([]),me=a.useEvent((U,B)=>{T.current&&!O&&!T.current.contains(U.target)&&B()});i&&(i.handleOutClick=me);const Te=d.useMemo(()=>y.split(D.matchToken.COMMA).filter(U=>!!U).map(U=>D.deserializeRangeWithSheet(U)),[y]),q=d.useMemo(()=>r!==void 0,[r]),ue=sn(!O&&$,n,o);d.useMemo(()=>U=>{const B=b.sequenceNodesBuilder(U);if(B){if(an(B)){const ie=B.map(ce=>{if(typeof ce=="string")return ce;if(ce.nodeType===D.sequenceNodeType.REFERENCE){const He={...ce},De=D.deserializeRangeWithSheet(ce.token);return De.range=Et(De.range),u||(De.sheetName="",De.unitId=""),He.token=Ie([De],u)[0],He}return ce}),G=Le(ie);_(G)}}else P("")},[u]);const J=Jt(M),{checkScrollBar:ge}=X.useResize(M,!0,!0),Q=it(),ae=d.useMemo(()=>Q(y),[y]),pe=en(),Oe=It(n,o),fe=a.useEvent((U,B=!0,se=!0)=>{if(!x.current)return;const ie=Q(U),G=pe(x.current,ie,B);re.current=G,se&&Oe(G,x.current)});d.useEffect(()=>{const U=E.onCommandExecuted(B=>{var se,ie;if(B.id===St.RichTextEditingMutation.id){const G=B.params,{unitId:ce}=G;ce===L&&_(l.BuildTextUtils.transform.getPlainText((ie=(se=M==null?void 0:M.getDocumentData().body)==null?void 0:se.dataStream)!=null?ie:""))}});return()=>U.dispose()},[E,M,L,_]);const Y=a.useEvent((U,B,se)=>{fe(U),P(U),se&&(J(),B!==-1&&setTimeout(()=>{const ie={startOffset:B,endOffset:B};M==null||M.setSelectionRanges([ie]);const G=M==null?void 0:M.render.with(X.DocBackScrollRenderController);G==null||G.scrollToRange({...ie,collapsed:!0})},50),ge())});cn(v,n,o,ae,u,p,Y),Rt(v,v&&z,n),rn(n,p),Yn(n,y,M),to(v,f,ae),on(v,0,M),Jn(),_t(v,n,u,k,g,()=>{v&&fe(y)}),d.useEffect(()=>{if(M){const U=M.input$.pipe(V.throttleTime(100)).subscribe(B=>{var ie,G;const se=((G=(ie=B.data.body)==null?void 0:ie.dataStream)!=null?G:"").replaceAll(/\n|\r/g,"").replaceAll(/,{2,}/g,",").replaceAll(/(^,)/g,"");fe(se,!1),P(se)});return()=>{U.unsubscribe()}}},[M]),d.useEffect(()=>{const U=E.onCommandExecuted(B=>{B.id===w.SetCellEditVisibleOperation.id&&(F(!1),m(!1),k(!1),g())});return()=>{U.dispose()}},[u]),d.useLayoutEffect(()=>{let U;if(A.current){U=I.register({autofocus:!0,editorUnitId:L,initialSnapshot:{id:L,body:{dataStream:`${y}\r
5
- `,textRuns:[]},documentStyle:{}}},A.current);const B=I.getEditor(L);x.current=B,fe(y,!1,!1)}return()=>{U==null||U.dispose()}},[]),d.useLayoutEffect(()=>{h?(k(h),J()):(M==null||M.blur(),ue(),k(h))},[h,J]),zn(y,"",$,pe,Oe,M);const de=()=>{S(),J(),k(!0)},Re=U=>{const B=Ie(U,u).join(D.matchToken.COMMA);B||M==null||M.setDocumentData({...M.getDocumentData(),body:{dataStream:`\r
6
- `,textRuns:[]}}),fe(B),P(B),F(!1),m(!1),setTimeout(()=>{k(!0),M==null||M.setSelectionRanges([{startOffset:B.length,endOffset:B.length}]),J(),ge()},30)},ve=()=>{F(!1),m(!1),setTimeout(()=>{k(!0),J()},30)},Ce=()=>{q||(J(),setTimeout(()=>{F(!0),m(!0),k(!1)},30))};return C.jsxs("div",{className:Se.sheetRangeSelector,ref:T,children:[C.jsxs("div",{className:mt(Se.sheetRangeSelectorTextWrap,{[Se.sheetRangeSelectorActive]:$&&!q,[Se.sheetRangeSelectorError]:q}),children:[C.jsx("div",{className:Se.sheetRangeSelectorText,ref:A,onMouseUp:de}),C.jsx(le.Tooltip,{title:R.t("rangeSelector.buttonTooltip"),placement:"bottom",children:C.jsx(Zt,{className:Se.sheetRangeSelectorIcon,onClick:Ce})}),r!==void 0?C.jsx("div",{className:Se.sheetRangeSelectorErrorWrap,children:r}):null,s!==void 0&&!y?C.jsx("div",{className:Se.sheetRangeSelectorPlaceholder,children:s}):null]}),O&&C.jsx(fo,{editorId:L,handleConfirm:Re,handleClose:ve,unitId:n,subUnitId:o,initValue:Te,visible:O,isOnlyOneRange:p,isSupportAcrossSheet:u})]})}function fo(e){const{handleConfirm:t,handleClose:n,visible:o,initValue:r,unitId:s,subUnitId:i,isOnlyOneRange:c,isSupportAcrossSheet:f}=e,m=a.useDependency(l.LocaleService),g=a.useDependency(Ne.IDescriptionService),S=a.useDependency(D.LexerTreeBuilder),p=a.useDependency(K.IRenderManagerService).getRenderById(s),u=p==null?void 0:p.with(exports.RefSelectionsRenderService),[_,I]=d.useState(()=>{if(c){const v=r[0];return v?Ie([v],f):[""]}return Ie(r,f)}),[R,E]=d.useState(()=>_.length-1),b=tn(),T=d.useMemo(()=>_.join(D.matchToken.COMMA),[_]),O=it(),F=d.useMemo(()=>O(T),[T]),$=d.useMemo(()=>nn(g,b,F).refSelections,[F]),k=()=>{I([]),setTimeout(()=>{n()},30)},L=(v,y)=>{y?u==null||u.setSkipLastEnabled(!1):u==null||u.setSkipLastEnabled(!0),I(P=>{const j=[...P];return j[v]=y,j})},x=v=>{u==null||u.setSkipLastEnabled(!1),I(y=>{if(y.length===1)return y;const P=[];return y.forEach((j,W)=>{v!==W&&P.push(j)}),P})},M=()=>{u==null||u.setSkipLastEnabled(!0),I(v=>(v.push(""),E(v.length-1),[...v]))},A=a.useEvent(v=>{var P;u==null||u.setSkipLastEnabled(!1);const y=v.split(D.matchToken.COMMA).filter(j=>!!j);I(c?[(P=y[0])!=null?P:""]:y)}),N=It(s,i);return cn(R>=0,s,i,F,f,c,A),Rt(R>=0,R>=0,s),rn(s,c),_t(R>=0,s,f,V.noop,V.noop,()=>N($)),d.useEffect(()=>{N($)},[$]),d.useEffect(()=>{(_.length===0||_.length===1&&!_[0])&&(u==null||u.setSkipLastEnabled(!0))},[_]),C.jsx(le.Dialog,{width:"328px",visible:o,title:m.t("rangeSelector.title"),draggable:!0,closeIcon:C.jsx(st,{}),footer:C.jsxs("footer",{children:[C.jsx(le.Button,{onClick:k,children:m.t("rangeSelector.cancel")}),C.jsx(le.Button,{style:{marginLeft:10},onClick:()=>t(_.filter(v=>{const y=S.sequenceNodesBuilder(v);return y&&y.length===1&&typeof y[0]!="string"&&y[0].nodeType===D.sequenceNodeType.REFERENCE}).map(v=>D.deserializeRangeWithSheet(v)).map(v=>({...v,range:Et(v.range)}))),type:"primary",children:m.t("rangeSelector.confirm")})]}),onClose:k,children:C.jsxs("div",{className:Se.sheetRangeSelectorDialog,children:[_.map((v,y)=>C.jsxs("div",{className:Se.sheetRangeSelectorDialogItem,children:[C.jsx(le.Input,{affixWrapperStyle:{width:"100%"},placeholder:m.t("rangeSelector.placeHolder"),onFocus:()=>E(y),value:v,onChange:P=>L(y,P)},`input_${y}`),_.length>1&&!c&&C.jsx(Yt,{className:Se.sheetRangeSelectorDialogItemDelete,onClick:()=>x(y)})]},`${v}_${y}`)),!c&&C.jsx("div",{children:C.jsxs(le.Button,{type:"link",size:"small",onClick:M,children:[C.jsx(Gt,{}),C.jsx("span",{children:m.t("rangeSelector.addAnotherRange")})]})})]})})}const yt=(e,t,n=!0)=>{let o=-1;return e.reduce((r,s,i)=>{if(r.isFinish)return r;const c=r.currentIndex;if(typeof s!="string")r.currentIndex+=s.token.length;else{const f=s.length;r.currentIndex+=f}return(n?r.currentIndex===t:t>c&&t<=r.currentIndex)&&(o=i,r.isFinish=!0),r},{currentIndex:0,isFinish:!1}),o},un=(e,t)=>{const n=e[t];let o=-1;if(!n||typeof n=="string"||n.nodeType!==D.sequenceNodeType.REFERENCE)return-1;for(let r=0;r<=t;r++){const s=e[r];typeof s!="string"&&s.nodeType===D.sequenceNodeType.REFERENCE&&o++}return o};function ho(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 Tt(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 mo=(e,t=100)=>{d.useEffect(()=>{let n=null;const o=()=>{n===null&&(n=window.setTimeout(()=>{e(),n=null},t))};return window.addEventListener("scroll",o),window.addEventListener("resize",o),()=>{n!==null&&clearTimeout(n),window.removeEventListener("scroll",o),window.removeEventListener("resize",o)}},[e,t])};function fn(e,t,n){const o=a.useDependency(X.IEditorService),r=d.useMemo(()=>new V.BehaviorSubject({left:-999,top:-999,right:-999,bottom:-999}),[]),s=a.useDependency(a.ISidebarService),i=a.useDependency(l.IUniverInstanceService),c=a.useEvent(()=>{const f=o.getEditor(e);if(!f)return;const m=f.getBoundingClientRect(),{left:g,top:S,right:h,bottom:p}=m,u=r.getValue();if(!(u.left===g&&u.top===S&&u.right===h&&u.bottom===p))return r.next({left:g-1,right:h+1,top:S-1,bottom:p+1}),m});return d.useEffect(()=>{t&&c()},[e,o,i.unitAdded$,c,t,...n!=null?n:[]]),mo(c),d.useEffect(()=>{const f=s.scrollEvent$.pipe(V.throttleTime(100)).subscribe(c);return()=>{f.unsubscribe()}},[]),[r,c]}const go=(e,t,n)=>{const o=a.useDependency(Ne.IDescriptionService),r=a.useDependency(D.LexerTreeBuilder),[s,i]=d.useState(),[c,f]=d.useState(-1),[m,g]=d.useState(!0),S=je(m),h=d.useRef(t);h.current=t;const p=()=>{i(void 0),f(-1),g(!1)};return d.useEffect(()=>{if(n&&e){const u=n.selectionChange$.pipe(V.debounceTime(50)).subscribe(I=>{if(I.textRanges.length===1){const[R]=I.textRanges;if(R.collapsed&&S.current){const E=r.getFunctionAndParameter(`${h.current}A`,R.startOffset-1);if(E){const{functionName:b,paramIndex:T}=E,O=o.getFunctionInfo(b);i(O),f(T);return}}}i(void 0),f(-1)}),_=n.selectionChange$.pipe(V.filter(I=>I.isEditing),V.filter(I=>I.textRanges.length===1),V.map(I=>I.textRanges[0].startOffset),V.distinctUntilChanged()).subscribe(()=>{g(!0)});return()=>{u.unsubscribe(),_.unsubscribe()}}},[n,e]),d.useEffect(()=>{e||p()},[e]),{functionInfo:s,paramIndex:c,reset:p}},po="univer-formula-help-function",So="univer-formula-help-function-title",vo="univer-formula-help-function-title-icons",Co="univer-formula-help-function-title-icon",Io="univer-formula-help-function-content",Ro="univer-formula-help-function-content-inner",Eo="univer-formula-help-function-content-params",_o="univer-formula-help-function-content-params-title",yo="univer-formula-help-function-content-params-detail",To="univer-formula-help-function-active",bo="univer-formula-help-param",Mo="univer-formula-help-param-prefix",xo="univer-formula-help-param-item",No="univer-formula-help-param-active",oe={formulaHelpFunction:po,formulaHelpFunctionTitle:So,formulaHelpFunctionTitleIcons:vo,formulaHelpFunctionTitleIcon:Co,formulaHelpFunctionContent:Io,formulaHelpFunctionContentInner:Ro,formulaHelpFunctionContentParams:Eo,formulaHelpFunctionContentParamsTitle:_o,formulaHelpFunctionContentParamsDetail:yo,formulaHelpFunctionActive:To,formulaHelpParam:bo,formulaHelpParamPrefix:Mo,formulaHelpParamItem:xo,formulaHelpParamActive:No},at=({className:e,title:t,value:n})=>C.jsxs("div",{className:oe.formulaHelpFunctionContentParams,children:[C.jsx("div",{className:`
7
- ${oe.formulaHelpFunctionContentParamsTitle}
1
+ "use strict";var In=Object.defineProperty;var _n=(e,t,n)=>t in e?In(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var X=(e,t,n)=>_n(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),w=require("@univerjs/sheets-ui"),x=require("@univerjs/engine-formula"),q=require("rxjs"),J=require("@univerjs/docs-ui"),K=require("@univerjs/engine-render"),H=require("@univerjs/sheets"),xe=require("@univerjs/sheets-formula"),a=require("@univerjs/ui"),C=require("react/jsx-runtime"),de=require("@univerjs/design"),St=require("@univerjs/docs"),d=require("react"),jt=require("rxjs/operators"),nt={id:"sheet.command.paste-formula",type:l.CommandType.COMMAND,handler:async e=>e.get(l.ICommandService).executeCommand(w.SheetPasteCommand.id,{value:w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA})},we={id:"formula-ui.operation.select-editor-formula",type:l.CommandType.OPERATION,handler:(e,t)=>!0};var yn=Object.getOwnPropertyDescriptor,Tn=(e,t,n,o)=>{for(var r=o>1?void 0:o?yn(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},bn=(e,t)=>(n,o)=>t(n,o,e);const Ht="FORMULA_PROMPT_ACTIVATED",Ge=l.createIdentifier("formula-ui.prompt-service");let ht=class{constructor(e){X(this,"_search$",new q.Subject);X(this,"_help$",new q.Subject);X(this,"_navigate$",new q.Subject);X(this,"_accept$",new q.Subject);X(this,"_acceptFormulaName$",new q.Subject);X(this,"search$",this._search$.asObservable());X(this,"help$",this._help$.asObservable());X(this,"navigate$",this._navigate$.asObservable());X(this,"accept$",this._accept$.asObservable());X(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());X(this,"_searching",!1);X(this,"_helping",!1);X(this,"_sequenceNodes",[]);X(this,"_isLockedOnSelectionChangeRefString",!1);X(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(Ht,e.visible),this._searching=e.visible,this._search$.next(e)}isSearching(){return this._searching}help(e){this._helping=e.visible,this._help$.next(e)}isHelping(){return this._helping}navigate(e){this._navigate$.next(e)}accept(e){this._accept$.next(e)}acceptFormulaName(e){this._acceptFormulaName$.next(e)}getSequenceNodes(){return[...this._sequenceNodes]}setSequenceNodes(e){this._sequenceNodes=e}clearSequenceNodes(){this._sequenceNodes=[]}getCurrentSequenceNode(e){return this._sequenceNodes[this.getCurrentSequenceNodeIndex(e)]}getCurrentSequenceNodeByIndex(e){return this._sequenceNodes[e]}getCurrentSequenceNodeIndex(e){let t=0;const n=this._sequenceNodes[0];for(let o=0,r=this._sequenceNodes.length;o<r;o++){const s=this._sequenceNodes[o];if(typeof s=="string")t++;else{const{endIndex:i}=s;t=i}if(e<=t)return typeof n=="string"&&e!==0?o+1:o}return this._sequenceNodes.length}updateSequenceRef(e,t){const n=this._sequenceNodes[e];if(typeof n=="string"||n.nodeType!==x.sequenceNodeType.REFERENCE)return;const o=t.length-n.token.length,r={...n};r.token=t,r.endIndex+=o,this._sequenceNodes[e]=r;for(let s=e+1,i=this._sequenceNodes.length;s<i;s++){const c=this._sequenceNodes[s];if(typeof c=="string")continue;const u={...c};u.startIndex+=o,u.endIndex+=o,this._sequenceNodes[s]=u}}insertSequenceRef(e,t){const n=t.length,o=this.getCurrentSequenceNodeIndex(e);this._sequenceNodes.splice(o,0,{token:t,startIndex:e,endIndex:e+n-1,nodeType:x.sequenceNodeType.REFERENCE});for(let r=o+1,s=this._sequenceNodes.length;r<s;r++){const i=this._sequenceNodes[r];if(typeof i=="string")continue;const c={...i};c.startIndex+=n,c.endIndex+=n,this._sequenceNodes[r]=c}}insertSequenceString(e,t){const n=this.getCurrentSequenceNodeIndex(e),o=t.split("");this._sequenceNodes.splice(n,0,...o);const r=o.length;for(let s=n+r,i=this._sequenceNodes.length;s<i;s++){const c=this._sequenceNodes[s];if(typeof c=="string")continue;const u={...c};u.startIndex+=r,u.endIndex+=r,this._sequenceNodes[s]=u}}enableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!0}disableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!1}isLockedSelectionChange(){return this._isLockedOnSelectionChangeRefString}enableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!0}disableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!1}isLockedSelectionInsert(){return this._isLockedOnSelectionInsertRefString}};ht=Tn([bn(0,l.IContextService)],ht);const Ut={id:"formula-ui.operation.help-function",type:l.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ge).help(t),!0)},ot={id:"formula-ui.operation.insert-function",type:l.CommandType.OPERATION,handler:async(e,t)=>{var R,T;const n=e.get(H.SheetsSelectionsService),o=e.get(J.IEditorService),r=n.getCurrentSelections();if(!r||!r.length)return!1;const s=H.getSheetCommandTarget(e.get(l.IUniverInstanceService));if(!s)return!1;const{worksheet:i,unitId:c,subUnitId:u}=s,m=i.getCellMatrix(),{value:g}=t,S=e.get(l.ICommandService);e.get(w.IEditorBridgeService);const h=[],p=[];let f=null,_=0,E=0,I="";if(r.length===1&&(Fn(r[0].range)||xn(r[0].range)&&Ot(m,r[0].range))){const{range:N,primary:D}=r[0],O=(R=D==null?void 0:D.actualRow)!=null?R:N.startRow,$=(T=D==null?void 0:D.actualColumn)!=null?T:N.startColumn;f=N,_=O,E=$;const P=xt(m,O,$);P&&(I=x.serializeRange(P))}else r.some(N=>{var $,P;const{range:D,primary:O}=N;if(Ot(m,D)){const L=($=O==null?void 0:O.actualRow)!=null?$:D.startRow,M=(P=O==null?void 0:O.actualColumn)!=null?P:D.startColumn,b=xt(m,L,M);if(!b)return f=D,_=L,E=M,!0;const A=x.serializeRange(b),F=`=${g}(${A})`;h.push({range:D,primary:{row:L,column:M},formula:F})}else{const{startRow:L,startColumn:M,endRow:b,endColumn:A}=D;if(L===b){const F=On(m,L,A,i.getColumnCount()-1),v=F===A?A-1:A,y=x.serializeRange({startRow:L,endRow:b,startColumn:M,endColumn:v}),k=`=${g}(${y})`;p.push({range:D,primary:{row:L,column:F},formula:k})}else{let F=-1;for(let y=M;y<=A;y++){const k=Dn(m,y,b,i.getRowCount()-1);F=Math.max(F,k)}const v=F===b?b-1:b;for(let y=M;y<=A;y++){const k=x.serializeRange({startRow:L,endRow:v,startColumn:y,endColumn:y}),j=`=${g}(${k})`;p.push({range:D,primary:{row:F,column:y},formula:j})}}}return!1});if(f){const N=H.getCellAtRowCol(_,E,i),D={range:l.Rectangle.clone(f),primary:{startRow:N.startRow,startColumn:N.startColumn,endRow:N.endRow,endColumn:N.endColumn,actualRow:_,actualColumn:E,isMerged:N.isMerged,isMergedMainCell:N.startRow===_&&N.startColumn===E}},O={unitId:c,subUnitId:u,selections:[D]};await S.executeCommand(H.SetSelectionsOperation.id,O);const $=o.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),P=o.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);S.syncExecuteCommand(w.SetCellEditVisibleOperation.id,{visible:!0,unitId:c,eventType:K.DeviceInputEventType.Dblclick});const L=`=${g}(${I}`;$==null||$.replaceText(L),P==null||P.replaceText(L,!1)}return h.length===0&&p.length===0?!1:S.executeCommand(xe.InsertFunctionCommand.id,{list:h,listOfRangeHasNumber:p})}};function xt(e,t,n){const o=Mn(e,t,n);if(o!==t)return{startRow:o,endRow:t-1,startColumn:n,endColumn:n};const r=Nn(e,t,n);return r!==n?{startRow:t,endRow:t,startColumn:r,endColumn:n-1}:null}function Mn(e,t,n){let o=!1;if(t===0)return t;for(let r=t-1;r>=0;r--){const s=e.getValue(r,n);if(ze(s)&&!o){if(r===0)return 0;o=!0}else{if(o&&!ze(s))return r+1;if(o&&r===0)return 0}}return t}function Nn(e,t,n){let o=!1;if(n===0)return n;for(let r=n-1;r>=0;r--){const s=e.getValue(t,r);if(ze(s)&&!o){if(r===0)return 0;o=!0}else{if(o&&!ze(s))return r+1;if(o&&r===0)return 0}}return n}function ze(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return!1;const n=t.dataStream,r=n.substring(n.length-2,n.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n;return l.isRealNum(r)}return e&&(e.t===l.CellValueType.NUMBER||l.getCellValueType(e)===l.CellValueType.NUMBER)}function Fn(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}function xn(e){return e.startRow!==e.endRow&&e.startColumn!==e.endColumn}function Ot(e,t){for(let n=t.startRow;n<=t.endRow;n++)for(let o=t.startColumn;o<=t.endColumn;o++)if(ze(e.getValue(n,o)))return!1;return!0}function On(e,t,n,o){for(let r=n;r<=o;r++)if(!e.getValue(t,r))return r;return o}function Dn(e,t,n,o){for(let r=n;r<=o;r++)if(!e.getValue(r,t))return r;return o}const Wt="SHEET_FORMULA_UI_PLUGIN",Bt=`${Wt}_MORE_FUNCTIONS_COMPONENT`,rt={id:"formula-ui.operation.more-functions",type:l.CommandType.OPERATION,handler:async e=>(e.get(a.ISidebarService).open({header:{title:"formula.insert.tooltip"},children:{label:Bt}}),!0)},vt={id:"formula-ui.operation.change-ref-to-absolute",type:l.CommandType.OPERATION,handler:async e=>!0},Vt={id:"formula-ui.operation.search-function",type:l.CommandType.OPERATION,handler:async(e,t)=>(e.get(Ge).search(t),!0)};var ge=function(){return ge=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},ge.apply(this,arguments)},An=function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]]);return n},Oe=d.forwardRef(function(e,t){var n=e.icon,o=e.id,r=e.className,s=e.extend,i=An(e,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(o," ").concat(r||"").trim(),u=d.useRef("_".concat(kn()));return Kt(n,"".concat(o),{defIds:n.defIds,idSuffix:u.current},ge({ref:t,className:c},i),s)});function Kt(e,t,n,o,r){return d.createElement(e.tag,ge(ge({key:t},Pn(e,n,r)),o),(Ln(e,n).children||[]).map(function(s,i){return Kt(s,"".concat(t,"-").concat(e.tag,"-").concat(i),n,void 0,r)}))}function Pn(e,t,n){var o=ge({},e.attrs);n!=null&&n.colorChannel1&&o.fill==="colorChannel1"&&(o.fill=n.colorChannel1),e.tag==="mask"&&o.id&&(o.id=o.id+t.idSuffix),Object.entries(o).forEach(function(s){var i=s[0],c=s[1];i==="mask"&&typeof c=="string"&&(o[i]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var r=t.defIds;return!r||r.length===0||(e.tag==="use"&&o["xlink:href"]&&(o["xlink:href"]=o["xlink:href"]+t.idSuffix),Object.entries(o).forEach(function(s){var i=s[0],c=s[1];typeof c=="string"&&(o[i]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),o}function Ln(e,t){var n,o=t.defIds;return!o||o.length===0?e:e.tag==="defs"&&(!((n=e.children)===null||n===void 0)&&n.length)?ge(ge({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&o&&o.indexOf(r.attrs.id)>-1?ge(ge({},r),{attrs:ge(ge({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):e}function kn(){return Math.random().toString(36).substring(2,8)}Oe.displayName="UniverIcon";var wn={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"}}]},qt=d.forwardRef(function(e,t){return d.createElement(Oe,Object.assign({},e,{id:"check-mark-single",ref:t,icon:wn}))});qt.displayName="CheckMarkSingle";var $n={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"}}]},st=d.forwardRef(function(e,t){return d.createElement(Oe,Object.assign({},e,{id:"close-single",ref:t,icon:$n}))});st.displayName="CloseSingle";var jn={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"}}]},Yt=d.forwardRef(function(e,t){return d.createElement(Oe,Object.assign({},e,{id:"delete-single",ref:t,icon:jn}))});Yt.displayName="DeleteSingle";var Hn={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"}}]},zt=d.forwardRef(function(e,t){return d.createElement(Oe,Object.assign({},e,{id:"details-single",ref:t,icon:Hn}))});zt.displayName="DetailsSingle";var Un={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"}}]},Gt=d.forwardRef(function(e,t){return d.createElement(Oe,Object.assign({},e,{id:"increase-single",ref:t,icon:Un}))});Gt.displayName="IncreaseSingle";var Wn={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"}}]},Ct=d.forwardRef(function(e,t){return d.createElement(Oe,Object.assign({},e,{id:"more-single",ref:t,icon:Wn}))});Ct.displayName="MoreSingle";var Bn={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"}}]},Zt=d.forwardRef(function(e,t){return d.createElement(Oe,Object.assign({},e,{id:"select-range-single",ref:t,icon:Bn}))});Zt.displayName="SelectRangeSingle";function Xt(e){var t,n,o="";if(typeof e=="string"||typeof e=="number")o+=e;else if(typeof e=="object")if(Array.isArray(e)){var r=e.length;for(t=0;t<r;t++)e[t]&&(n=Xt(e[t]))&&(o&&(o+=" "),o+=n)}else for(n in e)e[n]&&(o&&(o+=" "),o+=n);return o}function mt(){for(var e,t,n=0,o="",r=arguments.length;n<r;n++)(e=arguments[n])&&(t=Xt(e))&&(o&&(o+=" "),o+=t);return o}var Vn=Object.getOwnPropertyDescriptor,Kn=(e,t,n,o)=>{for(var r=o>1?void 0:o?Vn(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},$e=(e,t)=>(n,o)=>t(n,o,e);exports.RefSelectionsRenderService=class extends w.BaseSelectionRenderService{constructor(n,o,r,s,i,c,u){super(o,r,s,i,c);X(this,"_workbookSelections");X(this,"_eventDisposables");this._context=n,this._contextService=c,this._refSelectionsService=u,this._workbookSelections=this._refSelectionsService.getWorkbookSelections(this._context.unitId),this._initSelectionChangeListener(),this._initSkeletonChangeListener(),this._initUserActionSyncListener(),this._setSelectionStyle(qn(this._themeService)),this._remainLastEnabled=!0,this._highlightHeader=!1}getLocation(){return this._skeleton.getLocation()}setRemainLastEnabled(n){this._remainLastEnabled=n}setSkipLastEnabled(n){this._skipLastEnabled=n}clearLastSelection(){const n=this._selectionControls[this._selectionControls.length-1];n&&(n.dispose(),this._selectionControls.pop())}enableSelectionChanging(){return this._disableSelectionChanging(),this._eventDisposables=this._initCanvasEventListeners(),l.toDisposable(()=>this._disableSelectionChanging())}_disableSelectionChanging(){var n;(n=this._eventDisposables)==null||n.dispose(),this._eventDisposables=null}disableSelectionChanging(){this._disableSelectionChanging()}_initCanvasEventListeners(){const n=this._getSheetObject(),{spreadsheetRowHeader:o,spreadsheetColumnHeader:r,spreadsheet:s,spreadsheetLeftTopPlaceholder:i}=n,{scene:c}=this._context,u=new l.DisposableCollection;return u.add(s==null?void 0:s.onPointerDown$.subscribeEvent((m,g)=>{this.inRefSelectionMode()&&(this._onPointerDown(m,s.zIndex+1,l.RANGE_TYPE.NORMAL,this._getActiveViewport(m)),m.button!==2&&g.stopPropagation())})),u.add(o==null?void 0:o.onPointerDown$.subscribeEvent((m,g)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:h}=w.getCoordByOffset(m.offsetX,m.offsetY,c,S);w.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,l.RANGE_TYPE.ROW)||(this._onPointerDown(m,(s.zIndex||1)+1,l.RANGE_TYPE.ROW,this._getActiveViewport(m),K.ScrollTimerType.Y),m.button!==2&&g.stopPropagation())})),u.add(r==null?void 0:r.onPointerDown$.subscribeEvent((m,g)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:h}=w.getCoordByOffset(m.offsetX,m.offsetY,c,S);w.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,l.RANGE_TYPE.COLUMN)||(this._onPointerDown(m,(s.zIndex||1)+1,l.RANGE_TYPE.COLUMN,this._getActiveViewport(m),K.ScrollTimerType.X),m.button!==2&&g.stopPropagation())})),u.add(i==null?void 0:i.onPointerDown$.subscribeEvent((m,g)=>{if(this._reset(),!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,h=w.getAllSelection(S);this._addSelectionControlByModelData(h),this._selectionMoveStart$.next(this.getSelectionDataWithStyle());const p=c.onPointerUp$.subscribeEvent(()=>{p.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});m.button!==2&&g.stopPropagation()})),u}_addSelectionControlByModelData(n){var c;const o=this._skeleton,r=(c=n.style)!=null?c:w.genNormalSelectionStyle(this._themeService),s=this._scene;return n.style=r,this.newSelectionControl(s,o,n)}_initSelectionChangeListener(){this.disposeWithMe(this._refSelectionsService.selectionSet$.subscribe(n=>{this._reset(),this._skeleton&&this.resetSelectionsByModelData(n||[])}))}_initUserActionSyncListener(){this.disposeWithMe(this.selectionMoveStart$.subscribe(n=>{this._updateSelections(n,H.SelectionMoveType.MOVE_START)})),this.disposeWithMe(this.selectionMoving$.subscribe(n=>{this._updateSelections(n,H.SelectionMoveType.MOVING)})),this.disposeWithMe(this.selectionMoveEnd$.subscribe(n=>{this._updateSelections(n,H.SelectionMoveType.MOVE_END)}))}_updateSelections(n,o){const s=this._context.unit.getActiveSheet().getSheetId();n.length!==0&&this._workbookSelections.setSelections(s,n.map(i=>H.convertSelectionDataToRange(i)),o)}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(n=>{if(!n)return;const{skeleton:o}=n,{scene:r}=this._context,s=r.getViewport(K.SHEET_VIEWPORT_KEY.VIEW_MAIN);this._skeleton&&this._skeleton.worksheet.getSheetId()!==o.worksheet.getSheetId()&&this._reset(),this._changeRuntime(o,r,s);const i=this._workbookSelections.getCurrentSelections();this.resetSelectionsByModelData(i)}))}_getActiveViewport(n){const o=this._getSheetObject();return o==null?void 0:o.scene.getActiveViewportByCoord(K.Vector2.FromArray([n.offsetX,n.offsetY]))}_getSheetObject(){return w.getSheetObject(this._context.unit,this._context)}_onPointerDown(n,o=0,r=l.RANGE_TYPE.NORMAL,s,i=K.ScrollTimerType.ALL){var b;this._rangeType=r;const c=this._skeleton,u=this._scene;if(!u||!c)return;s&&(this._activeViewport=s);const{offsetX:m,offsetY:g}=n,S=u.getViewport(K.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!S)return;const h=u.getCoordRelativeToViewport(K.Vector2.FromArray([m,g])),{x:p,y:f}=h;this._startViewportPosX=p,this._startViewportPosY=f;const _=u.getScrollXYInfoByViewport(h),{scaleX:E,scaleY:I}=u.getAncestorScale(),R=this._skeleton.getCellByOffset(p,f,E,I,_);if(!R)return;switch(r){case l.RANGE_TYPE.NORMAL:break;case l.RANGE_TYPE.ROW:R.startColumn=0,R.endColumn=this._skeleton.getColumnCount()-1;break;case l.RANGE_TYPE.COLUMN:R.startRow=0,R.endRow=this._skeleton.getRowCount()-1;break;case l.RANGE_TYPE.ALL:R.startRow=0,R.startColumn=0,R.endRow=this._skeleton.getRowCount()-1,R.endColumn=this._skeleton.getColumnCount()-1}const T={range:R,primary:R,style:null};T.range.rangeType=r;const N=w.attachSelectionWithCoord(T,this._skeleton);this._startRangeWhenPointerDown={...N.rangeWithCoord};const D={...N.rangeWithCoord,rangeType:r};let O=this.getActiveSelectionControl();const $=this.getSelectionControls();for(const A of $){if(n.button===2&&A.model.isInclude(D)){O=A;return}if(A.model.isEqual(D)){O=A;break}}this._checkClearPreviousControls(n);const P=O==null?void 0:O.model.currentCell,L=n.shiftKey&&P,M=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;L&&P?this._makeSelectionByTwoCells(P,D,c,r,O):M&&O?O.updateRangeBySelectionWithCoord(N):O=this.newSelectionControl(u,c,T);for(let A=0;A<this.getSelectionControls().length-1;A++)this.getSelectionControls()[A].clearHighlight();this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),u.disableObjectsEvent(),this._clearUpdatingListeners(),this._addEndingListeners(),(b=u.getTransformer())==null||b.clearSelectedObjects(),this._setupPointerMoveListener(S,O,r,i,p,f),this._escapeShortcutDisposable=this._shortcutService.forceEscape(),this._scenePointerUpSub=u.onPointerUp$.subscribeEvent(()=>{var A;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(A=this._escapeShortcutDisposable)==null||A.dispose(),this._escapeShortcutDisposable=null})}newSelectionControl(n,o,r){const s=this.getSelectionControls().length,{rowHeaderWidth:i,columnHeaderHeight:c}=o,u=new w.SelectionControl(n,s,this._themeService,{highlightHeader:this._highlightHeader,enableAutoFill:!1,rowHeaderWidth:i,columnHeaderHeight:c}),m=w.attachSelectionWithCoord(r,o);return u.updateRangeBySelectionWithCoord(m),this._selectionControls.push(u),u.setControlExtension({skeleton:o,scene:n,themeService:this._themeService,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),u}};exports.RefSelectionsRenderService=Kn([$e(1,l.Inject(l.Injector)),$e(2,l.Inject(l.ThemeService)),$e(3,a.IShortcutService),$e(4,l.Inject(w.SheetSkeletonManagerService)),$e(5,l.IContextService),$e(6,H.IRefSelectionsService)],exports.RefSelectionsRenderService);function qn(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 Yn=(e,t,n)=>{const r=a.useDependency(K.IRenderManagerService).getRenderById(e),s=r==null?void 0:r.with(exports.RefSelectionsRenderService);d.useEffect(()=>{if(n&&s){const i=n.input$.subscribe(c=>{c.content===x.matchToken.COMMA?s.setSkipLastEnabled(!0):s.setSkipLastEnabled(!1)});return()=>{i.unsubscribe()}}},[n,s]),d.useEffect(()=>{s&&(t.endsWith(x.matchToken.COMMA)||s.setSkipLastEnabled(!1))},[t,s])},it=()=>{const e=a.useDependency(x.LexerTreeBuilder);return d.useCallback(n=>e.sequenceNodesBuilder(n)||[],[e])},zn=(e,t,n,o,r,s)=>{const i=it(),c=d.useRef(!0);d.useEffect(()=>{var u,m;if(s){if(c.current){const g=i(e);if(g.length){const S=o(s,g);n&&r(S)}else{const S=s.getDocumentData(),p={dataStream:(m=(u=S.body)==null?void 0:u.dataStream)!=null?m:`${t}\r
2
+ `,...S.body};s.setDocumentData({...S,body:p})}c.current=!1}else if(n){const g=i(e),S=o(s,g);r(S)}}},[s,n])},Jt=e=>{const t=a.useDependency(J.IEditorService);return a.useEvent(o=>{var r,s;if(e){t.focus(e.getEditorId());const i=[...e.getSelectionRanges()];if(l.Tools.isDefine(o))e.setSelectionRanges([{startOffset:o,endOffset:o}]);else if(!i.length&&!e.docSelectionRenderService.isOnPointerEvent){const c=(s=(r=e.getDocumentData().body)==null?void 0:r.dataStream)!=null?s:`\r
3
+ `,u=Math.max(c.length-2,0);e.setSelectionRanges([{startOffset:u,endOffset:u}])}}})};function Gn(e,t,n){const o=e.getCurrentTheme(),r=new l.ColorKit(t).setAlpha(.05).toRgbString();return{id:n,strokeWidth:1,stroke:t,fill:r,widgets:{tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},widgetSize:6,widgetStrokeWidth:1,widgetStroke:o.colorWhite}}function Qt(e){var I,R,T;const{unitId:t,subUnitId:n,refSelections:o,editor:r,refSelectionsService:s,refSelectionsRenderService:i,sheetSkeletonManagerService:c,themeService:u,univerInstanceService:m}=e,g=m.getUnit(t,l.UniverInstanceType.UNIVER_SHEET),S=g==null?void 0:g.getActiveSheet(),h=[];if(!g||!S){s.setSelections(h);return}const p=S.getSheetId(),f=N=>{var D;return(D=g==null?void 0:g.getSheetBySheetName(N))==null?void 0:D.getSheetId()};if(!((I=c==null?void 0:c.getWorksheetSkeleton(p))==null?void 0:I.skeleton))return;const E=[];for(let N=0,D=o.length;N<D;N++){const O=o[N],{themeColor:$,token:P,refIndex:L,endIndex:M}=O,b=x.deserializeRangeWithSheet(P),{unitId:A,sheetName:F,range:v}=b;if(A&&t!==A)continue;const y=f(F);if(y&&y!==p||!y&&p!==n)continue;const k=H.setEndForRange(v,S.getRowCount(),S.getColumnCount());k.unitId=t,k.sheetId=p,h.push({range:k,primary:null,style:Gn(u,$,L.toString())}),E.push(M)}if(r){const N=(T=(R=r.getSelectionRanges())==null?void 0:R[0])==null?void 0:T.startOffset,D=E.findIndex(O=>O+2===N);D!==-1?i==null||i.setActiveSelectionIndex(D):i==null||i.resetActiveSelectionIndex()}return h}function Et(e,t){const n=a.useDependency(l.IUniverInstanceService),o=a.useDependency(l.ThemeService),r=a.useDependency(H.IRefSelectionsService),i=a.useDependency(K.IRenderManagerService).getRenderById(e),c=i==null?void 0:i.with(exports.RefSelectionsRenderService),u=i==null?void 0:i.with(w.SheetSkeletonManagerService),m=a.useEvent((g,S)=>{if(c!=null&&c.selectionMoving)return;const h=Qt({unitId:e,subUnitId:t,refSelections:g,editor:S,refSelectionsService:r,refSelectionsRenderService:c,sheetSkeletonManagerService:u,themeService:o,univerInstanceService:n});if(!h)return;((c==null?void 0:c.getSelectionControls())||[]).length===h.length?c==null||c.resetSelectionsByModelData(h):r.setSelections(h)});return d.useEffect(()=>()=>{c==null||c.resetActiveSelectionIndex()},[c]),m}function en(e=""){const t=a.useDependency(xe.IDescriptionService),n=tn(),o=a.useDependency(l.ICommandService),r=d.useMemo(()=>e.length,[e]);return d.useCallback((i,c,u=!0,m)=>{const g=i.getDocumentData(),S=i.getEditorId();if(!g)return[];const h=g.body;if(!h)return[];const p=h.dataStream.slice(0,h.dataStream.length-2),f={dataStream:"",...g.body};if(!p.startsWith(e))return[];if(c==null||c.length===0)return f.textRuns=[],o.syncExecuteCommand(J.ReplaceTextRunsCommand.id,{unitId:S,body:l.getBodySlice(f,0,f.dataStream.length-2)}),[];{const{textRuns:_,refSelections:E}=nn(t,n,c);r&&_.forEach(T=>{T.ed=T.ed+r,T.st=T.st+r}),f.textRuns=[{st:0,ed:1,ts:{fs:11}},..._];const I=c.reduce((T,N)=>typeof N=="string"?`${T}${N}`:`${T}${N.token}`,"");f.dataStream=`${e}${I}\r
4
+ `;let R;if(u){R=i.getSelectionRanges();const T=f.dataStream.length-2+r;R.forEach(N=>{N.startOffset=Math.max(0,Math.min(N.startOffset,T)),N.endOffset=Math.max(0,Math.min(N.endOffset,T))})}return o.syncExecuteCommand(J.ReplaceTextRunsCommand.id,{unitId:S,body:l.getBodySlice(f,0,f.dataStream.length-2),textRanges:m!=null?m:R}),E}},[o,t,n,r,e])}function tn(){const t=a.useDependency(l.ThemeService).getCurrentTheme();return d.useMemo(()=>{const o=[t.loopColor1,t.loopColor2,t.loopColor3,t.loopColor4,t.loopColor5,t.loopColor6,t.loopColor7,t.loopColor8,t.loopColor9,t.loopColor10,t.loopColor11,t.loopColor12],r=t.hyacinth700,s=t.verdancy800,i=t.colorBlack;return{formulaRefColors:o,numberColor:r,stringColor:s,plainTextColor:i}},[t])}function nn(e,t,n){const{formulaRefColors:o,numberColor:r,stringColor:s,plainTextColor:i}=t,c=[],u=[],m=new Map;let g=0;for(let S=0,h=n.length;S<h;S++){const p=n[S];if(typeof p=="string"){const T=c[c.length-1],N=T?T.ed:0,D=N+p.length;c.push({st:N,ed:D,ts:{cl:{rgb:i},fs:11}});continue}if(e.hasDefinedNameDescription(p.token.trim())){c.push({st:p.startIndex,ed:p.endIndex+1,ts:{cl:{rgb:i},fs:11}});continue}const{startIndex:f,endIndex:_,nodeType:E,token:I}=p;let R="";if(E===x.sequenceNodeType.REFERENCE){if(m.has(I))R=m.get(I);else{const T=g%o.length;R=o[T],m.set(I,R),g++}u.push({refIndex:S,themeColor:R,token:I,startIndex:p.startIndex,endIndex:p.endIndex,index:u.length})}else E===x.sequenceNodeType.NUMBER?R=r:(E===x.sequenceNodeType.STRING||E===x.sequenceNodeType.ARRAY)&&(R=s);R&&R.length>0?c.push({st:f,ed:_+1,ts:{cl:{rgb:R},fs:11}}):c.push({st:f,ed:_+1,ts:{cl:{rgb:i},fs:11}})}return{textRuns:c,refSelections:u}}const He=e=>{const t=d.useRef(e);return t.current=e,t};function Zn(e){var r,s;const n=e.get(l.IUniverInstanceService).getCurrentUniverDocInstance();return n!=null&&n.getBody()?{dataStream:(s=(r=n.getBody())==null?void 0:r.dataStream)!=null?s:"",offset:0}:void 0}var Fe=(e=>(e[e.NOT_SELECT=0]="NOT_SELECT",e[e.NEED_ADD=1]="NEED_ADD",e[e.CAN_EDIT=2]="CAN_EDIT",e[e.EDIT_OTHER_SHEET_REFERENCE=3]="EDIT_OTHER_SHEET_REFERENCE",e))(Fe||{});function Xn(e){var $;const{editorId:t,isFocus:n,disableOnClick:o,unitId:r,subUnitId:s}=e,i=a.useDependency(K.IRenderManagerService),c=a.useDependency(l.IUniverInstanceService),u=i.getRenderById(r),m=i.getRenderById(t),g=m==null?void 0:m.with(J.DocSelectionRenderService),S=a.useDependency(St.DocSelectionManagerService),h=a.useDependency(l.Injector),[p,f]=d.useState(0),_=a.useDependency(x.LexerTreeBuilder),E=d.useRef(!0),I=u==null?void 0:u.with(exports.RefSelectionsRenderService),R=He(p),T=c.getUnit(r,l.UniverInstanceType.UNIVER_SHEET),N=T==null?void 0:T.getSheetBySheetId(s),D=a.useEvent(P=>{I&&I.setSkipLastEnabled(P===1||P===3),R.current=P,f(P)}),O=a.useEvent(()=>{var Y,ee;if(!T)return;const P=T.getActiveSheet(),L=g==null?void 0:g.getActiveTextRange(),M=L!=null&&L.collapsed?L.startOffset:-1,b=Zn(h);if(!b)return;const A=(Y=b==null?void 0:b.dataStream)==null?void 0:Y.slice(0,-2),F=((ee=_.sequenceNodesBuilder(A))!=null?ee:[]).map(z=>typeof z=="object"?z.nodeType===x.sequenceNodeType.REFERENCE?{...z,range:x.deserializeRangeWithSheetWithCache(z.token)}:{...z,range:void 0}:z),v=A[M-1],y=A[M],k=F.find(z=>typeof z=="object"&&z.nodeType===x.sequenceNodeType.REFERENCE&&M===z.endIndex+2),j=v&&x.matchRefDrawToken(v)&&(!y||x.isFormulaLexerToken(y)&&y!==x.matchToken.OPEN_BRACKET),U=!!k;if((A==null?void 0:A.substring(0,1))==="="&&(j||U))if(U){if(E.current)return;!k.range.sheetName&&P.getSheetId()===(N==null?void 0:N.getSheetId())||k.range.sheetName===P.getName()?D(2):D(3)}else E.current=!1,D(1);else D(0)});return d.useEffect(()=>{const P=S.textSelection$.pipe(q.filter(L=>L.unitId===t)).subscribe(()=>{O()});return()=>P.unsubscribe()},[O,S.textSelection$,t]),d.useEffect(()=>{n||(D(0),E.current=!0)},[n,D]),d.useEffect(()=>{var L;if(!o)return;const P=(L=m==null?void 0:m.mainComponent)==null?void 0:L.onPointerDown$.subscribeEvent(()=>{D(0),E.current=!0});return()=>P==null?void 0:P.unsubscribe()},[o,($=m==null?void 0:m.mainComponent)==null?void 0:$.onPointerDown$,D]),d.useEffect(()=>{if(!n)return;const P=T==null?void 0:T.activeSheet$.subscribe(()=>{O()});return()=>P==null?void 0:P.unsubscribe()},[O,n,T==null?void 0:T.activeSheet$]),{isSelecting:p,isSelectingRef:R}}const on=(e,t,n,o)=>{const r=a.useDependency(l.ICommandService),s=a.useDependency(a.IShortcutService),i=d.useRef(t);i.current=t;const c=d.useRef(o);c.current=o,d.useEffect(()=>{if(!n||!e)return;const m=`sheet.formula-embedding-editor.${n.getEditorId()}`,g=new l.DisposableCollection,S=(f,_)=>{if(c.current){c.current(f,_);return}let E=l.Direction.LEFT;f===a.KeyCode.ARROW_DOWN?E=l.Direction.DOWN:f===a.KeyCode.ARROW_UP?E=l.Direction.UP:f===a.KeyCode.ARROW_RIGHT&&(E=l.Direction.RIGHT),_===a.MetaKeys.SHIFT?r.executeCommand(J.MoveSelectionOperation.id,{direction:E}):r.executeCommand(J.MoveCursorOperation.id,{direction:E})},h=(f,_)=>{let E=l.Direction.DOWN;f===a.KeyCode.ARROW_DOWN?E=l.Direction.DOWN:f===a.KeyCode.ARROW_UP?E=l.Direction.UP:f===a.KeyCode.ARROW_LEFT?E=l.Direction.LEFT:f===a.KeyCode.ARROW_RIGHT&&(E=l.Direction.RIGHT),i.current?_===a.MetaKeys.CTRL_COMMAND?r.executeCommand(w.MoveSelectionCommand.id,{direction:E,jumpOver:w.JumpOver.moveGap,extra:"formula-editor",fromCurrentSelection:i.current===Fe.NEED_ADD||i.current===Fe.EDIT_OTHER_SHEET_REFERENCE}):_===a.MetaKeys.SHIFT?r.executeCommand(w.ExpandSelectionCommand.id,{direction:E,extra:"formula-editor"}):_===(a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT)?r.executeCommand(w.ExpandSelectionCommand.id,{direction:E,jumpOver:w.JumpOver.moveGap,extra:"formula-editor"}):r.executeCommand(w.MoveSelectionCommand.id,{direction:E,extra:"formula-editor",fromCurrentSelection:i.current===Fe.NEED_ADD||i.current===Fe.EDIT_OTHER_SHEET_REFERENCE}):S(f,_)};return g.add(r.registerCommand({id:m,type:l.CommandType.OPERATION,handler(f,_){const{keyCode:E,metaKey:I}=_;h(E,I)}})),[{keyCode:a.KeyCode.ARROW_DOWN},{keyCode:a.KeyCode.ARROW_LEFT},{keyCode:a.KeyCode.ARROW_RIGHT},{keyCode:a.KeyCode.ARROW_UP},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT}].map(({keyCode:f,metaKey:_})=>({id:m,binding:_?f|_:f,preconditions:()=>!0,priority:900,staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keyCode:f,metaKey:_}})).forEach(f=>{g.add(s.registerShortcut(f))}),()=>{g.dispose()}},[r,n,e,s])},rn=(e,t)=>{const o=a.useDependency(K.IRenderManagerService).getRenderById(e),r=o==null?void 0:o.with(exports.RefSelectionsRenderService);d.useEffect(()=>{r&&(t?r==null||r.setRemainLastEnabled(!1):r==null||r.setRemainLastEnabled(!0))},[t,r])},Rt=(e,t,n,o=!0)=>{const r=a.useDependency(K.IRenderManagerService),s=a.useDependency(l.IContextService),i=a.useDependency(a.IContextMenuService),c=a.useDependency(H.IRefSelectionsService),u=r.getRenderById(n),m=u==null?void 0:u.with(exports.RefSelectionsRenderService);d.useLayoutEffect(()=>{if(e)return s.setContextValue(l.EDITOR_ACTIVATED,!0),()=>{s.setContextValue(l.EDITOR_ACTIVATED,!1),c.clear()}},[s,e,c]),d.useLayoutEffect(()=>{if(e&&t){const g=m==null?void 0:m.enableSelectionChanging();return s.setContextValue(H.REF_SELECTIONS_ENABLED,!0),()=>{s.setContextValue(H.REF_SELECTIONS_ENABLED,!1),g==null||g.dispose()}}},[s,e,m,t]),d.useEffect(()=>{if(e)return s.setContextValue(l.EDITOR_ACTIVATED,!0),o&&i.disable(),()=>{s.setContextValue(l.EDITOR_ACTIVATED,!1),o&&i.enable()}},[i,s,e,o]),d.useEffect(()=>{e&&(m==null||m.setSkipLastEnabled(!1))},[e,m])},Jn=()=>{d.useEffect(()=>()=>{},[])},sn=(e,t,n)=>{const o=a.useDependency(l.IUniverInstanceService),r=a.useDependency(H.SheetsSelectionsService);return d.useCallback(()=>{if(e){const i=[...r.getWorkbookSelections(t).getSelectionsOfWorksheet(n)],c=o.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),u=c==null?void 0:c.getActiveSheet();u&&u.getSheetId()===n&&r.setSelections(i)}},[e,r,n,t,o])},gt=e=>typeof e=="string"?e===x.matchToken.COMMA:!1,Qn=e=>{if(typeof e=="object")return e.nodeType===x.sequenceNodeType.REFERENCE},eo=e=>e.filter(t=>gt(t)||Qn(t)),It=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},ke=e=>e.map(t=>typeof t=="string"?t:t.token).join("");function Dt(e,t,n){var o,r;return((r=(o=e.getUnit(t))==null?void 0:o.getSheetBySheetId(n))==null?void 0:r.getName())||""}const Ee=(e,t=!1,n="")=>t?e.map(o=>o.sheetName!==""&&o.sheetName!==n?x.serializeRangeWithSheet(o.sheetName,o.range):x.serializeRange(o.range)):e.map(o=>x.serializeRange(o.range)),cn=(e,t,n,o,r,s,i)=>{const c=a.useDependency(K.IRenderManagerService),u=a.useDependency(l.IUniverInstanceService),m=d.useRef(!1),g=c.getRenderById(t),S=g==null?void 0:g.with(exports.RefSelectionsRenderService),h=d.useRef([]),p=d.useMemo(()=>{const _=eo(o),E=h.current;return _.length===E.length?(E.splice(0),E.push(..._),E):_},[o]);h.current=p;const f=d.useRef(void 0);d.useEffect(()=>{if(e&&S){let _=!0;const E=(T,N)=>{var F;if(_||m.current){_=!1;return}const D=[...T],O=u.getUnit(t),$=((F=O==null?void 0:O.getActiveSheet())==null?void 0:F.getName())||"",P=p.map((v,y)=>{if(typeof v=="string"){if(!p[y-1])return null;const j=p[y+1];return gt(v)&&(gt(j)||y===p.length-1)?null:v}else if(v.nodeType===x.sequenceNodeType.REFERENCE){const k=x.deserializeRangeWithSheet(v.token);k.unitId=k.unitId===""?t:k.unitId,k.sheetName=k.sheetName===""?$:k.sheetName;const{unitId:j,sheetName:U}=k;if(s&&(j!==t||$!==U))return null;if(j===t&&$===U){const Y=D.shift();if(Y&&Dt(u,t,Y.rangeWithCoord.sheetId||"")===U){const ee={...v};return It(Y.rangeWithCoord),r?ee.token=x.serializeRangeWithSheet($,Y.rangeWithCoord):ee.token=x.serializeRange(Y.rangeWithCoord),ee}}return v}return null}).filter(v=>!!v),L=Ee(D.map(v=>{var y,k,j;return{range:v.rangeWithCoord,unitId:(y=v.rangeWithCoord.unitId)!=null?y:"",sheetName:Dt(u,(k=v.rangeWithCoord.unitId)!=null?k:"",(j=v.rangeWithCoord.sheetId)!=null?j:"")}}),r).join(x.matchToken.COMMA),M=ke(P),b=`${M}${M&&L?x.matchToken.COMMA:""}${L}`,A=m.current;i(b,A?-1:b.length,N)},I=S.selectionMoveEnd$.subscribe(T=>{if(E(T,!0),m.current=!1,f.current){const{result:N,offset:D}=f.current;i(N,D,!0),f.current=void 0}}),R=S.selectionMoving$.pipe(jt.throttleTime(50)).subscribe(T=>{E(T,!1)});return()=>{I.unsubscribe(),R.unsubscribe()}}},[e,p,S,r,s,i,u,t]),d.useEffect(()=>{if(e&&S){const _=new l.DisposableCollection,E=(T,N)=>{var A;let D=0,O=0,$=!1;const P=u.getUnit(t),L=((A=P==null?void 0:P.getActiveSheet())==null?void 0:A.getName())||"",M=p.map(F=>{if(typeof F=="string")return $||(O+=F.length),F;if(F.nodeType===x.sequenceNodeType.REFERENCE){const v=x.deserializeRangeWithSheet(T);if(v.unitId=v.unitId===""?t:v.unitId,v.sheetName=v.sheetName===""?L:v.sheetName,D===N){$=!0;const y={...F,token:T};return r?y.token=x.serializeRangeWithSheet(v.sheetName,v.range):y.token=x.serializeRange(v.range),D++,O+=y.token.length,y}return D++,$||(O+=F.token.length),F}return F}),b=ke(M);f.current={result:b,offset:O},i(b,-1,!1)};let I=0;const R=S.selectionMoveEnd$.subscribe(()=>{I=setTimeout(()=>{_.dispose(),S.getSelectionControls().forEach((N,D)=>{_.add(q.merge(N.selectionMoving$,N.selectionScaling$).pipe(q.map(O=>x.serializeRange(O)),q.distinctUntilChanged()).subscribe(O=>{m.current=!0,E(O,D)}))})},30)});return()=>{R.unsubscribe(),_.dispose(),clearTimeout(I)}}},[e,S,p,i,u,t,r])},_t=(e,t,n,o,r,s)=>{const i=a.useDependency(l.ICommandService),c=a.useDependency(J.IEditorService),m=a.useDependency(K.IRenderManagerService).getRenderById(t),g=m==null?void 0:m.with(exports.RefSelectionsRenderService);d.useEffect(()=>{if(e&&g)if(n){const S=i.onCommandExecuted(h=>{if(h.id===H.SetWorksheetActiveOperation.id){const p=g.getSelectionControls().length;for(let f=1;f<=p;f++)g.clearLastSelection();setTimeout(()=>{s()},30)}});return()=>{S.dispose()}}else{const S=i.beforeCommandExecuted(h=>{if(h.id===H.SetWorksheetActiveOperation.id){o(!1),r(),s();const p=c.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);p==null||p.focus()}});return()=>{S.dispose()}}},[e,g])},an=e=>!e.some(n=>{if(typeof n=="string"){if(n!==x.matchToken.COMMA)return!0}else if(n.nodeType!==x.sequenceNodeType.REFERENCE)return!0;return!1}),to=(e,t,n)=>{const o=d.useRef(!0);d.useEffect(()=>{if(e){const r=setTimeout(()=>{o.current=!1},500);return()=>{clearTimeout(r)}}},[e]),d.useEffect(()=>{if(!o.current&&t){const r=an(n);t(r,ke(n))}},[n,t])},no="univer-sheet-range-selector-text-wrap",oo="univer-sheet-range-selector-placeholder",ro="univer-sheet-range-selector-error",so="univer-sheet-range-selector-error-wrap",io="univer-sheet-range-selector-text",co="univer-sheet-range-selector-active",ao="univer-sheet-range-selector-icon",lo="univer-sheet-range-selector-dialog-item",uo="univer-sheet-range-selector-dialog-item-delete",Se={sheetRangeSelectorTextWrap:no,sheetRangeSelectorPlaceholder:oo,sheetRangeSelectorError:ro,sheetRangeSelectorErrorWrap:so,sheetRangeSelectorText:io,sheetRangeSelectorActive:co,sheetRangeSelectorIcon:ao,sheetRangeSelectorDialogItem:lo,sheetRangeSelectorDialogItemDelete:uo},Be=()=>{};function ln(e){const{initValue:t,unitId:n,subUnitId:o,errorText:r,placeholder:s,actions:i,onChange:c=Be,onVerify:u=Be,onRangeSelectorDialogVisibleChange:m=Be,onBlur:g=Be,onFocus:S=Be,isFocus:h=!0,isOnlyOneRange:p=!1,isSupportAcrossSheet:f=!1}=e,_=a.useEvent(c),E=a.useDependency(J.IEditorService),I=a.useDependency(l.LocaleService),R=a.useDependency(l.ICommandService),T=a.useDependency(x.LexerTreeBuilder),N=d.useRef(null),[D,O]=d.useState(!1),[$,P]=d.useState(h),L=d.useMemo(()=>l.createInternalEditorID(`${w.RANGE_SELECTOR_SYMBOLS}-${l.generateRandomId(4)}`),[]),M=d.useRef(void 0),b=M.current,A=d.useRef(null),F=a.useDependency(l.IUniverInstanceService),v=d.useMemo(()=>!D&&$,[D,$]),[y,k]=d.useState(()=>typeof t=="string"?t:Ee(t,f).join(x.matchToken.COMMA)),j=d.useMemo(()=>F.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_DOC),[F]),U=a.useObservable(j),Y=(U==null?void 0:U.getUnitId())===L,ee=d.useRef([]),z=a.useEvent((W,V)=>{N.current&&!D&&!N.current.contains(W.target)&&V()});i&&(i.handleOutClick=z);const Te=d.useMemo(()=>y.split(x.matchToken.COMMA).filter(W=>!!W).map(W=>x.deserializeRangeWithSheet(W)),[y]),B=d.useMemo(()=>r!==void 0,[r]),te=sn(!D&&$,n,o);d.useMemo(()=>W=>{const V=T.sequenceNodesBuilder(W);if(V){if(an(V)){const ae=V.map(le=>{if(typeof le=="string")return le;if(le.nodeType===x.sequenceNodeType.REFERENCE){const Ue={...le},Ae=x.deserializeRangeWithSheet(le.token);return Ae.range=It(Ae.range),f||(Ae.sheetName="",Ae.unitId=""),Ue.token=Ee([Ae],f)[0],Ue}return le}),Z=ke(ae);_(Z)}}else k("")},[f]);const Q=Jt(b),{checkScrollBar:ue}=J.useResize(b,!0,!0),ne=it(),fe=d.useMemo(()=>ne(y),[y]),pe=en(),De=Et(n,o),he=a.useEvent((W,V=!0,ce=!0)=>{if(!M.current)return;const ae=ne(W),Z=pe(M.current,ae,V);ee.current=Z,ce&&De(Z,M.current)});d.useEffect(()=>{const W=R.onCommandExecuted(V=>{var ce,ae;if(V.id===St.RichTextEditingMutation.id){const Z=V.params,{unitId:le}=Z;le===L&&_(l.BuildTextUtils.transform.getPlainText((ae=(ce=b==null?void 0:b.getDocumentData().body)==null?void 0:ce.dataStream)!=null?ae:""))}});return()=>W.dispose()},[R,b,L,_]);const G=a.useEvent((W,V,ce)=>{he(W),k(W),ce&&(Q(),V!==-1&&setTimeout(()=>{const ae={startOffset:V,endOffset:V};b==null||b.setSelectionRanges([ae]);const Z=b==null?void 0:b.render.with(J.DocBackScrollRenderController);Z==null||Z.scrollToRange({...ae,collapsed:!0})},50),ue())});cn(v,n,o,fe,f,p,G),Rt(v,v&&Y,n),rn(n,p),Yn(n,y,b),to(v,u,fe),on(v,0,b),Jn(),_t(v,n,f,P,g,()=>{v&&he(y)}),d.useEffect(()=>{if(b){const W=b.input$.pipe(q.throttleTime(100)).subscribe(V=>{var ae,Z;const ce=((Z=(ae=V.data.body)==null?void 0:ae.dataStream)!=null?Z:"").replaceAll(/\n|\r/g,"").replaceAll(/,{2,}/g,",").replaceAll(/(^,)/g,"");he(ce,!1),k(ce)});return()=>{W.unsubscribe()}}},[b]),d.useEffect(()=>{const W=R.onCommandExecuted(V=>{V.id===w.SetCellEditVisibleOperation.id&&(O(!1),m(!1),P(!1),g())});return()=>{W.dispose()}},[f]),d.useLayoutEffect(()=>{let W;if(A.current){W=E.register({autofocus:!0,editorUnitId:L,initialSnapshot:{id:L,body:{dataStream:`${y}\r
5
+ `,textRuns:[]},documentStyle:{}}},A.current);const V=E.getEditor(L);M.current=V,he(y,!1,!1)}return()=>{W==null||W.dispose()}},[]),d.useLayoutEffect(()=>{h?(P(h),Q()):(b==null||b.blur(),te(),P(h))},[h,Q]),zn(y,"",$,pe,De,b);const me=()=>{S(),Q(),P(!0)},Re=W=>{const V=Ee(W,f).join(x.matchToken.COMMA);V||b==null||b.setDocumentData({...b.getDocumentData(),body:{dataStream:`\r
6
+ `,textRuns:[]}}),he(V),k(V),O(!1),m(!1),setTimeout(()=>{P(!0),b==null||b.setSelectionRanges([{startOffset:V.length,endOffset:V.length}]),Q(),ue()},30)},ve=()=>{O(!1),m(!1),setTimeout(()=>{P(!0),Q()},30)},Ce=()=>{B||(Q(),setTimeout(()=>{O(!0),m(!0),P(!1)},30))};return C.jsxs("div",{className:Se.sheetRangeSelector,ref:N,children:[C.jsxs("div",{className:mt(Se.sheetRangeSelectorTextWrap,{[Se.sheetRangeSelectorActive]:$&&!B,[Se.sheetRangeSelectorError]:B}),children:[C.jsx("div",{className:Se.sheetRangeSelectorText,ref:A,onMouseUp:me}),C.jsx(de.Tooltip,{title:I.t("rangeSelector.buttonTooltip"),placement:"bottom",children:C.jsx(Zt,{className:Se.sheetRangeSelectorIcon,onClick:Ce})}),r!==void 0?C.jsx("div",{className:Se.sheetRangeSelectorErrorWrap,children:r}):null,s!==void 0&&!y?C.jsx("div",{className:Se.sheetRangeSelectorPlaceholder,children:s}):null]}),D&&C.jsx(fo,{editorId:L,handleConfirm:Re,handleClose:ve,unitId:n,subUnitId:o,initValue:Te,visible:D,isOnlyOneRange:p,isSupportAcrossSheet:f})]})}function fo(e){const{handleConfirm:t,handleClose:n,visible:o,initValue:r,unitId:s,subUnitId:i,isOnlyOneRange:c,isSupportAcrossSheet:u}=e,m=a.useDependency(l.LocaleService),g=a.useDependency(xe.IDescriptionService),S=a.useDependency(x.LexerTreeBuilder),p=a.useDependency(K.IRenderManagerService).getRenderById(s),f=p==null?void 0:p.with(exports.RefSelectionsRenderService),[_,E]=d.useState(()=>{if(c){const v=r[0];return v?Ee([v],u):[""]}return Ee(r,u)}),[I,R]=d.useState(()=>_.length-1),T=tn(),N=d.useMemo(()=>_.join(x.matchToken.COMMA),[_]),D=it(),O=d.useMemo(()=>D(N),[N]),$=d.useMemo(()=>nn(g,T,O).refSelections,[O]),P=()=>{E([]),setTimeout(()=>{n()},30)},L=(v,y)=>{y?f==null||f.setSkipLastEnabled(!1):f==null||f.setSkipLastEnabled(!0),E(k=>{const j=[...k];return j[v]=y,j})},M=v=>{f==null||f.setSkipLastEnabled(!1),E(y=>{if(y.length===1)return y;const k=[];return y.forEach((j,U)=>{v!==U&&k.push(j)}),k})},b=()=>{f==null||f.setSkipLastEnabled(!0),E(v=>(v.push(""),R(v.length-1),[...v]))},A=a.useEvent(v=>{var k;f==null||f.setSkipLastEnabled(!1);const y=v.split(x.matchToken.COMMA).filter(j=>!!j);E(c?[(k=y[0])!=null?k:""]:y)}),F=Et(s,i);return cn(I>=0,s,i,O,u,c,A),Rt(I>=0,I>=0,s),rn(s,c),_t(I>=0,s,u,q.noop,q.noop,()=>F($)),d.useEffect(()=>{F($)},[$]),d.useEffect(()=>{(_.length===0||_.length===1&&!_[0])&&(f==null||f.setSkipLastEnabled(!0))},[_]),C.jsx(de.Dialog,{width:"328px",visible:o,title:m.t("rangeSelector.title"),draggable:!0,closeIcon:C.jsx(st,{}),footer:C.jsxs("footer",{children:[C.jsx(de.Button,{onClick:P,children:m.t("rangeSelector.cancel")}),C.jsx(de.Button,{style:{marginLeft:10},onClick:()=>t(_.filter(v=>{const y=S.sequenceNodesBuilder(v);return y&&y.length===1&&typeof y[0]!="string"&&y[0].nodeType===x.sequenceNodeType.REFERENCE}).map(v=>x.deserializeRangeWithSheet(v)).map(v=>({...v,range:It(v.range)}))),type:"primary",children:m.t("rangeSelector.confirm")})]}),onClose:P,children:C.jsxs("div",{className:Se.sheetRangeSelectorDialog,children:[_.map((v,y)=>C.jsxs("div",{className:Se.sheetRangeSelectorDialogItem,children:[C.jsx(de.Input,{affixWrapperStyle:{width:"100%"},placeholder:m.t("rangeSelector.placeHolder"),onFocus:()=>R(y),value:v,onChange:k=>L(y,k)},`input_${y}`),_.length>1&&!c&&C.jsx(Yt,{className:Se.sheetRangeSelectorDialogItemDelete,onClick:()=>M(y)})]},`${v}_${y}`)),!c&&C.jsx("div",{children:C.jsxs(de.Button,{type:"link",size:"small",onClick:b,children:[C.jsx(Gt,{}),C.jsx("span",{children:m.t("rangeSelector.addAnotherRange")})]})})]})})}const yt=(e,t,n=!0)=>{let o=-1;return e.reduce((r,s,i)=>{if(r.isFinish)return r;const c=r.currentIndex;if(typeof s!="string")r.currentIndex+=s.token.length;else{const u=s.length;r.currentIndex+=u}return(n?r.currentIndex===t:t>c&&t<=r.currentIndex)&&(o=i,r.isFinish=!0),r},{currentIndex:0,isFinish:!1}),o},un=(e,t)=>{const n=e[t];let o=-1;if(!n||typeof n=="string"||n.nodeType!==x.sequenceNodeType.REFERENCE)return-1;for(let r=0;r<=t;r++){const s=e[r];typeof s!="string"&&s.nodeType===x.sequenceNodeType.REFERENCE&&o++}return o};function ho(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 Tt(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 mo=(e,t=100)=>{d.useEffect(()=>{let n=null;const o=()=>{n===null&&(n=window.setTimeout(()=>{e(),n=null},t))};return window.addEventListener("scroll",o),window.addEventListener("resize",o),()=>{n!==null&&clearTimeout(n),window.removeEventListener("scroll",o),window.removeEventListener("resize",o)}},[e,t])};function fn(e,t,n){const o=a.useDependency(J.IEditorService),r=d.useMemo(()=>new q.BehaviorSubject({left:-999,top:-999,right:-999,bottom:-999}),[]),s=a.useDependency(a.ISidebarService),i=a.useDependency(l.IUniverInstanceService),c=a.useEvent(()=>{const u=o.getEditor(e);if(!u)return;const m=u.getBoundingClientRect(),{left:g,top:S,right:h,bottom:p}=m,f=r.getValue();if(!(f.left===g&&f.top===S&&f.right===h&&f.bottom===p))return r.next({left:g-1,right:h+1,top:S-1,bottom:p+1}),m});return d.useEffect(()=>{t&&c()},[e,o,i.unitAdded$,c,t,...n!=null?n:[]]),mo(c),d.useEffect(()=>{const u=s.scrollEvent$.pipe(q.throttleTime(100)).subscribe(c);return()=>{u.unsubscribe()}},[]),[r,c]}const go=(e,t,n)=>{const o=a.useDependency(xe.IDescriptionService),r=a.useDependency(x.LexerTreeBuilder),[s,i]=d.useState(),[c,u]=d.useState(-1),[m,g]=d.useState(!0),S=He(m),h=d.useRef(t);h.current=t;const p=()=>{i(void 0),u(-1),g(!1)};return d.useEffect(()=>{if(n&&e){const f=n.selectionChange$.pipe(q.debounceTime(50)).subscribe(E=>{if(E.textRanges.length===1){const[I]=E.textRanges;if(I.collapsed&&S.current){const R=r.getFunctionAndParameter(`${h.current}A`,I.startOffset-1);if(R){const{functionName:T,paramIndex:N}=R,D=o.getFunctionInfo(T);i(D),u(N);return}}}i(void 0),u(-1)}),_=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(()=>{g(!0)});return()=>{f.unsubscribe(),_.unsubscribe()}}},[n,e]),d.useEffect(()=>{e||p()},[e]),{functionInfo:s,paramIndex:c,reset:p}},po="univer-formula-help-function",So="univer-formula-help-function-title",vo="univer-formula-help-function-title-icons",Co="univer-formula-help-function-title-icon",Eo="univer-formula-help-function-content",Ro="univer-formula-help-function-content-inner",Io="univer-formula-help-function-content-params",_o="univer-formula-help-function-content-params-title",yo="univer-formula-help-function-content-params-detail",To="univer-formula-help-function-active",bo="univer-formula-help-param",Mo="univer-formula-help-param-prefix",No="univer-formula-help-param-item",Fo="univer-formula-help-param-active",ie={formulaHelpFunction:po,formulaHelpFunctionTitle:So,formulaHelpFunctionTitleIcons:vo,formulaHelpFunctionTitleIcon:Co,formulaHelpFunctionContent:Eo,formulaHelpFunctionContentInner:Ro,formulaHelpFunctionContentParams:Io,formulaHelpFunctionContentParamsTitle:_o,formulaHelpFunctionContentParamsDetail:yo,formulaHelpFunctionActive:To,formulaHelpParam:bo,formulaHelpParamPrefix:Mo,formulaHelpParamItem:No,formulaHelpParamActive:Fo},at=({className:e,title:t,value:n})=>C.jsxs("div",{className:ie.formulaHelpFunctionContentParams,children:[C.jsx("div",{className:`
7
+ ${ie.formulaHelpFunctionContentParamsTitle}
8
8
  ${e}
9
- `,children:t}),C.jsx("div",{className:oe.formulaHelpFunctionContentParamsDetail,children:n})]}),Fo=e=>{const{prefix:t,value:n,active:o,onClick:r}=e;return C.jsxs("div",{className:oe.formulaHelpParam,children:[C.jsxs("span",{className:oe.formulaHelpParamPrefix,children:[t,"("]}),n&&n.map((s,i)=>C.jsxs("span",{className:oe.formulaHelpParamItem,children:[C.jsx("span",{className:o===i?oe.formulaHelpFunctionActive:oe.formulaHelpParamActive,onClick:()=>r(i),children:Tt(s)}),i===n.length-1?"":","]},s.name)),")"]})},At=()=>{};function Oo(e){const{onParamsSwitch:t=At,onClose:n=At,isFocus:o,editor:r,formulaText:s}=e,{functionInfo:i,paramIndex:c,reset:f}=go(o,s,r),m=d.useMemo(()=>!!i&&c>=0,[i,c]),[g,S]=d.useState(!0),h=a.useDependency(l.LocaleService),p=h.t("formula.prompt.required"),u=h.t("formula.prompt.optional"),_=r.getEditorId(),[I]=fn(_,m,[i,c]);function R(b){t&&t(b)}const E=()=>{f(),n()};return m&&i?C.jsx(a.RectPopup,{portal:!0,onClickOutside:()=>f(),anchorRect$:I,direction:"vertical",children:C.jsxs("div",{className:oe.formulaHelpFunction,children:[C.jsxs("div",{className:oe.formulaHelpFunctionTitle,children:[C.jsx(Fo,{prefix:i.functionName,value:i.functionParameter,active:c,onClick:R}),C.jsxs("div",{className:oe.formulaHelpFunctionTitleIcons,children:[C.jsx("div",{className:oe.formulaHelpFunctionTitleIcon,style:{transform:g?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>S(!g),children:C.jsx(Ct,{})}),C.jsx("div",{className:oe.formulaHelpFunctionTitleIcon,onClick:E,children:C.jsx(st,{})})]})]}),C.jsx("div",{className:oe.formulaHelpFunctionContent,style:{height:g?"unset":0,padding:g?"revert-layer":0},children:C.jsxs("div",{className:oe.formulaHelpFunctionContentInner,children:[C.jsx(at,{title:h.t("formula.prompt.helpExample"),value:`${i.functionName}(${i.functionParameter.map(b=>b.example).join(",")})`}),C.jsx(at,{title:h.t("formula.prompt.helpAbstract"),value:i.description}),i&&i.functionParameter&&i.functionParameter.map((b,T)=>C.jsx(at,{className:c===T?oe.formulaHelpFunctionActive:"",title:b.name,value:`${b.require?p:u} ${b.detail}`},T))]})})]})}):null}const Do=e=>e.reduce((t,n)=>typeof n=="string"?t+n.length:t+n.token.length,0),Ao=e=>{var g,S,h;const{editor:t,lexerTreeBuilder:n}=e,o=t==null?void 0:t.getSelectionRanges();if((o==null?void 0:o.length)!==1)return;const s=o[0].startOffset-1,i=((S=(g=t==null?void 0:t.getDocumentData().body)==null?void 0:g.dataStream)!=null?S:`\r
10
- `).slice(0,-2),c=(h=n.sequenceNodesBuilder(i.slice(1)))!=null?h:[],f=yt(c,s,!1),m=un(c,f);return{nodeIndex:f,updatingRefIndex:m,sequenceNodes:c,offset:s}},Po=()=>{},Lo=(e,t,n,o,r,s,i,c,f,m=Po)=>{const g=a.useDependency(K.IRenderManagerService),S=a.useDependency(l.IUniverInstanceService),h=a.useDependency(l.ICommandService),p=a.useDependency(St.DocSelectionManagerService),u=a.useDependency(l.ThemeService),_=a.useDependency(D.LexerTreeBuilder),I=S.getUnit(o),R=a.useEvent(x=>{var M,A;return(A=(M=I==null?void 0:I.getSheetBySheetId(x))==null?void 0:M.getName())!=null?A:""}),E=d.useMemo(()=>R(r),[R,r]),b=a.useObservable(I==null?void 0:I.activeSheet$),T=je({activeSheet:b,sheetName:E}),O=g.getRenderById(o),F=O==null?void 0:O.with(exports.RefSelectionsRenderService),$=O==null?void 0:O.with(w.SheetSkeletonManagerService),k=a.useDependency(H.IRefSelectionsService),L=a.useEvent((x,M)=>{var j,W,z,re,me,Te;const A=Ao({editor:f,lexerTreeBuilder:_});if(!A)return;const{nodeIndex:N,updatingRefIndex:v,sequenceNodes:y,offset:P}=A;if(n.current===ze.NEED_ADD)if(P!==0){if(N===-1&&y.length)return;const q=x[x.length-1],ue=y.splice(N+1),J=(j=q.sheetId)!=null?j:r,ge={range:q,unitId:(W=q.unitId)!=null?W:o,sheetName:R(J)},ae=Ie([ge],i&&J!==r,E);y.push({token:ae[0],nodeType:D.sequenceNodeType.REFERENCE});const pe=[...y,...ue],Oe=Le(pe);m(Oe,Do(y),M)}else{const q=x[x.length-1],ue=(z=q.sheetId)!=null?z:r,J={range:q,unitId:(re=q.unitId)!=null?re:o,sheetName:R(ue)},Q=Ie([J],i&&ue!==r);y.unshift({token:Q[0],nodeType:D.sequenceNodeType.REFERENCE});const ae=Le(y);m(ae,Q[0].length,M)}else{const q=[...x];if(v!==-1){const Y=q.pop();Y&&q.splice(v,0,Y)}let ue=0;const J=y.map(Y=>{var de,Re,ve;if(typeof Y=="string")return Y;if(Y.nodeType===D.sequenceNodeType.REFERENCE){const Ce=D.deserializeRangeWithSheet(Y.token);if(Ce.sheetName||(Ce.sheetName=E),i&&((de=T.current.activeSheet)==null?void 0:de.getName())!==Ce.sheetName)return Y.token;const U=q[ue];if(ue++,!U)return"";const B=(Re=U.sheetId)!=null?Re:r,se={range:U,unitId:(ve=U.unitId)!=null?ve:o,sheetName:R(B)};return Ie([se],i,E)[0]}return Y.token});let ge="",Q;J.forEach((Y,de)=>{ge+=Y,de===N&&(Q=ge.length)});const ae=[];for(let Y=ue;Y<=x.length-1;Y++){const de=x[Y],Re=(me=de.sheetId)!=null?me:r,ve={range:de,unitId:(Te=de.unitId)!=null?Te:o,sheetName:R(Re)},U=Ie([ve],i&&Re!==r,E);ae.push(U[0])}const pe=y[y.length-1],Oe=pe&&(typeof pe=="string"?!1:pe.nodeType===D.sequenceNodeType.REFERENCE),fe=`${ge}${ae.length&&Oe?",":""}${ae.join(",")}`;m(fe,!ae.length&&Q?Q:fe.length,M)}});d.useEffect(()=>{if(F&&e){let x=!0;const M=(N,v)=>{if(x){x=!1;return}L(N.map(y=>y.rangeWithCoord),v)},A=new l.DisposableCollection;return A.add(F.selectionMoving$.subscribe(N=>{M(N,!1)})),A.add(F.selectionMoveEnd$.subscribe(N=>{M(N,!0)})),()=>{A.dispose()}}},[e,L,F]),d.useEffect(()=>{if(t&&F&&f){const x=new l.DisposableCollection,M=()=>{x.dispose(),F.getSelectionControls().forEach((v,y)=>{x.add(v.selectionScaling$.subscribe(P=>{const j=F.getSelectionDataWithStyle().map(z=>z.rangeWithCoord),W=j[y];P.sheetId=W.sheetId,P.unitId=W.unitId,j[y]=P,L(j,!1)})),x.add(v.selectionMoving$.subscribe(P=>{const j=F.getSelectionDataWithStyle().map(z=>z.rangeWithCoord),W=j[y];P.sheetId=W.sheetId,P.unitId=W.unitId,j[y]=P,L(j,!0)}))})},A=V.merge(f.input$,k.selectionSet$,F.selectionMoveEnd$).pipe(jt.debounceTime(50)).subscribe(()=>{M()});return()=>{A.unsubscribe(),x.dispose()}}},[f,t,L,F,k.selectionSet$]),F==null||F.getSelectionDataWithStyle(),d.useEffect(()=>{if(c){const x=h.onCommandExecuted(M=>{var N;if(M.id!==H.SetSelectionsOperation.id)return;const A=M.params;if(A.extra==="formula-editor"&&A.selections.length){const v=A.selections[A.selections.length-1];if(v){const y=n.current===ze.NEED_ADD,P=((N=F==null?void 0:F.getSelectionDataWithStyle())!=null?N:[]).map(j=>j.rangeWithCoord);y?P.push(v.range):P[P.length-1]=v.range,L(P,!0)}}});return()=>{x.dispose()}}},[h,f,n,_,c,L,F]),d.useEffect(()=>{if(!f)return;const x=p.textSelection$.subscribe(M=>{M.unitId===f.getEditorId()&&Qt({unitId:o,subUnitId:r,refSelections:s.current,editor:f,refSelectionsService:k,refSelectionsRenderService:F,sheetSkeletonManagerService:$,themeService:u,univerInstanceService:S})});return()=>x.unsubscribe()},[p.textSelection$,f,s,F,k,$,r,u,o,S])},ko=(e,t,n)=>{const o=a.useDependency(D.LexerTreeBuilder),r=d.useRef(!0);d.useEffect(()=>{if(e){const s=setTimeout(()=>{r.current=!1},500);return()=>{clearTimeout(s)}}},[e]),d.useEffect(()=>{if(!r.current&&t){const s=o.checkIfAddBracket(n);t(s===0&&n.startsWith(D.operatorToken.EQUALS),`${n}`)}},[n,t])},wo="univer-sheet-embedding-formula-editor-active",$o="univer-sheet-embedding-formula-editor-wrap",jo="univer-sheet-embedding-formula-editor-text",Ho="univer-sheet-embedding-formula-editor-error",Uo="univer-sheet-embedding-formula-editor",Wo="univer-sheet-embedding-formula-editor-error-wrap",$e={sheetEmbeddingFormulaEditorActive:wo,sheetEmbeddingFormulaEditorWrap:$o,sheetEmbeddingFormulaEditorText:jo,sheetEmbeddingFormulaEditorError:Ho,sheetEmbeddingFormulaEditor:Uo,sheetEmbeddingFormulaEditorErrorWrap:Wo},Bo=(e,t=[],n)=>{const o=a.useDependency(Ne.IDescriptionService),[r,s]=d.useState([]),[i,c]=d.useState(""),f=d.useRef(-1),m=je({nodes:t}),g=()=>{s([]),c(""),f.current=-1};return d.useEffect(()=>{if(n&&e){const h=n.input$.pipe(V.debounceTime(300)).subscribe(()=>{const p=n.getSelectionRanges();if(p.length===1){const u=m.current.nodes,_=p[0];if(_.collapsed){const I=yt(u,_.startOffset-1,!1);f.current=I;const R=u[I];if(R&&typeof R!="string"&&R.nodeType===D.sequenceNodeType.FUNCTION){f.current=I;const E=R.token,b=o.getSearchListByNameFirstLetter(E);s(b),c(E);return}}}f.current=-1,c(""),s(u=>u!=null&&u.length?[]:u)});return()=>{h.unsubscribe()}}},[n,e]),d.useEffect(()=>{e||g()},[e]),{searchList:r,searchText:i,handlerFormulaReplace:h=>{const p=[...m.current.nodes];if(f.current!==-1){const u=p.splice(f.current+1),_=p.pop()||"";let I=(typeof _=="string"?_.length:_.token.length)-h.length;return p.push(h),u[0]!==D.matchToken.OPEN_BRACKET&&(p.push(D.matchToken.OPEN_BRACKET),I--),{text:Le([...p,...u]),offset:I}}},reset:g}},Vo="univer-formula-search-function",Ko="univer-formula-search-function-item",qo="univer-formula-search-function-item-name",Yo="univer-formula-search-function-item-name-light",zo="univer-formula-search-function-item-desc",Go="univer-formula-search-function-item-active",Me={formulaSearchFunction:Vo,formulaSearchFunctionItem:Ko,formulaSearchFunctionItemName:qo,formulaSearchFunctionItemNameLight:Yo,formulaSearchFunctionItemDesc:zo,formulaSearchFunctionItemActive:Go},Zo=()=>{},Xo=d.forwardRef(Jo);function Jo(e,t){const{isFocus:n,sequenceNodes:o,onSelect:r,editor:s,onClose:i=Zo}=e,c=s.getEditorId(),f=a.useDependency(a.IShortcutService),m=a.useDependency(l.ICommandService),{searchList:g,searchText:S,handlerFormulaReplace:h,reset:p}=Bo(n,o,s),u=d.useMemo(()=>!!g.length,[g]),_=d.useRef(void 0),[I,R]=d.useState(0),E=d.useRef(!1),[b]=fn(c,u,[S,g]),T=je({searchList:g,active:I}),O=x=>{const M=h(x);M&&(p(),r(M))};function F(x){E.current&&R(x)}function $(){E.current&&R(-1)}d.useEffect(()=>{if(!g.length)return;const x=`sheet.formula-embedding-editor.search_function.${c}`,M=new l.DisposableCollection,A=N=>{const{searchList:v,active:y}=T.current;switch(N){case a.KeyCode.ARROW_UP:{R(P=>{const j=Math.max(0,P-1);return k(j),j});break}case a.KeyCode.ARROW_DOWN:{R(P=>{const j=Math.min(v.length-1,P+1);return k(j),j});break}case a.KeyCode.TAB:case a.KeyCode.ENTER:{const P=v[y];O(P.name);break}case a.KeyCode.ESC:{p(),i();break}}};return M.add(m.registerCommand({id:x,type:l.CommandType.OPERATION,handler(N,v){const{keyCode:y}=v;A(y)}})),[a.KeyCode.ARROW_UP,a.KeyCode.ARROW_DOWN,a.KeyCode.ENTER,a.KeyCode.ESC,a.KeyCode.TAB].map(N=>({id:x,binding:N,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keyCode:N}})).forEach(N=>{M.add(f.registerShortcut(N))}),()=>{M.dispose()}},[g]);function k(x){var re;const M=(re=_.current)==null?void 0:re.querySelectorAll(`.${Me.formulaSearchFunctionItem}`)[x];if(!M)return;const A=M.parentNode;if(!A)return;const v=A.getBoundingClientRect().top,y=A.offsetHeight,P=M.getBoundingClientRect(),j=P.top,W=P.height;if(j>=0&&j>v&&j-v+W<=y)return;const z=M.offsetTop-(y-W)/2;A.scrollTo({top:z,behavior:"smooth"})}const L=d.useMemo(()=>{let x="";return()=>{clearTimeout(x),E.current=!0,x=setTimeout(()=>{E.current=!1},300)}},[]);return g.length>0&&u&&C.jsx(a.RectPopup,{portal:!0,anchorRect$:b,direction:"vertical",children:C.jsx("ul",{className:Me.formulaSearchFunction,ref:x=>{_.current=x,t&&(t.current=x)},children:g.map((x,M)=>C.jsxs("li",{className:I===M?`
9
+ `,children:t}),C.jsx("div",{className:ie.formulaHelpFunctionContentParamsDetail,children:n})]}),xo=e=>{const{prefix:t,value:n,active:o,onClick:r}=e;return C.jsxs("div",{className:ie.formulaHelpParam,children:[C.jsxs("span",{className:ie.formulaHelpParamPrefix,children:[t,"("]}),n&&n.map((s,i)=>C.jsxs("span",{className:ie.formulaHelpParamItem,children:[C.jsx("span",{className:o===i?ie.formulaHelpFunctionActive:ie.formulaHelpParamActive,onClick:()=>r(i),children:Tt(s)}),i===n.length-1?"":","]},s.name)),")"]})},At=()=>{};function Oo(e){const{onParamsSwitch:t=At,onClose:n=At,isFocus:o,editor:r,formulaText:s}=e,{functionInfo:i,paramIndex:c,reset:u}=go(o,s,r),m=d.useMemo(()=>!!i&&c>=0,[i,c]),[g,S]=d.useState(!0),h=a.useDependency(l.LocaleService),p=h.t("formula.prompt.required"),f=h.t("formula.prompt.optional"),_=r.getEditorId(),[E]=fn(_,m,[i,c]);function I(T){t&&t(T)}const R=()=>{u(),n()};return m&&i?C.jsx(a.RectPopup,{portal:!0,onClickOutside:()=>u(),anchorRect$:E,direction:"vertical",children:C.jsxs("div",{className:ie.formulaHelpFunction,children:[C.jsxs("div",{className:ie.formulaHelpFunctionTitle,children:[C.jsx(xo,{prefix:i.functionName,value:i.functionParameter,active:c,onClick:I}),C.jsxs("div",{className:ie.formulaHelpFunctionTitleIcons,children:[C.jsx("div",{className:ie.formulaHelpFunctionTitleIcon,style:{transform:g?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>S(!g),children:C.jsx(Ct,{})}),C.jsx("div",{className:ie.formulaHelpFunctionTitleIcon,onClick:R,children:C.jsx(st,{})})]})]}),C.jsx("div",{className:ie.formulaHelpFunctionContent,style:{height:g?"unset":0,padding:g?"revert-layer":0},children:C.jsxs("div",{className:ie.formulaHelpFunctionContentInner,children:[C.jsx(at,{title:h.t("formula.prompt.helpExample"),value:`${i.functionName}(${i.functionParameter.map(T=>T.example).join(",")})`}),C.jsx(at,{title:h.t("formula.prompt.helpAbstract"),value:i.description}),i&&i.functionParameter&&i.functionParameter.map((T,N)=>C.jsx(at,{className:c===N?ie.formulaHelpFunctionActive:"",title:T.name,value:`${T.require?p:f} ${T.detail}`},N))]})})]})}):null}const Do=e=>e.reduce((t,n)=>typeof n=="string"?t+n.length:t+n.token.length,0),Ao=e=>{var g,S,h;const{editor:t,lexerTreeBuilder:n}=e,o=t==null?void 0:t.getSelectionRanges();if((o==null?void 0:o.length)!==1)return;const s=o[0].startOffset-1,i=((S=(g=t==null?void 0:t.getDocumentData().body)==null?void 0:g.dataStream)!=null?S:`\r
10
+ `).slice(0,-2),c=(h=n.sequenceNodesBuilder(i.slice(1)))!=null?h:[],u=yt(c,s,!1),m=un(c,u);return{nodeIndex:u,updatingRefIndex:m,sequenceNodes:c,offset:s}},Po=()=>{},Lo=(e,t,n,o,r,s,i,c,u,m=Po)=>{const g=a.useDependency(K.IRenderManagerService),S=a.useDependency(l.IUniverInstanceService),h=a.useDependency(l.ICommandService),p=a.useDependency(St.DocSelectionManagerService),f=a.useDependency(l.ThemeService),_=a.useDependency(x.LexerTreeBuilder),E=S.getUnit(o),I=a.useEvent(M=>{var b,A;return(A=(b=E==null?void 0:E.getSheetBySheetId(M))==null?void 0:b.getName())!=null?A:""}),R=d.useMemo(()=>I(r),[I,r]),T=a.useObservable(E==null?void 0:E.activeSheet$),N=He({activeSheet:T,sheetName:R}),D=g.getRenderById(o),O=D==null?void 0:D.with(exports.RefSelectionsRenderService),$=D==null?void 0:D.with(w.SheetSkeletonManagerService),P=a.useDependency(H.IRefSelectionsService),L=a.useEvent((M,b)=>{var j,U,Y,ee,z,Te;const A=Ao({editor:u,lexerTreeBuilder:_});if(!A)return;const{nodeIndex:F,updatingRefIndex:v,sequenceNodes:y,offset:k}=A;if(n.current===Fe.NEED_ADD)if(k!==0){if(F===-1&&y.length)return;const B=M[M.length-1],te=y.splice(F+1),Q=(j=B.sheetId)!=null?j:r,ue={range:B,unitId:(U=B.unitId)!=null?U:o,sheetName:I(Q)},fe=Ee([ue],i&&Q!==r,R);y.push({token:fe[0],nodeType:x.sequenceNodeType.REFERENCE});const pe=[...y,...te],De=ke(pe);m(De,Do(y),b)}else{const B=M[M.length-1],te=(Y=B.sheetId)!=null?Y:r,Q={range:B,unitId:(ee=B.unitId)!=null?ee:o,sheetName:I(te)},ne=Ee([Q],i&&te!==r);y.unshift({token:ne[0],nodeType:x.sequenceNodeType.REFERENCE});const fe=ke(y);m(fe,ne[0].length,b)}else if(n.current===Fe.EDIT_OTHER_SHEET_REFERENCE){const B=M.pop();if(!B)return;const te=y[F];if(typeof te=="object"&&te.nodeType===x.sequenceNodeType.REFERENCE){const Q=te.token;te.token=R===(T==null?void 0:T.getName())?x.serializeRange(B):x.serializeRangeWithSheet(T.getName(),B);const ue=k+(te.token.length-Q.length);m(x.generateStringWithSequence(y),ue,b)}}else{const B=[...M];if(v!==-1){const G=B.pop();G&&B.splice(v,0,G)}let te=0;const Q=y.map(G=>{var me,Re,ve;if(typeof G=="string")return G;if(G.nodeType===x.sequenceNodeType.REFERENCE){const Ce=x.deserializeRangeWithSheet(G.token);if(Ce.sheetName||(Ce.sheetName=R),i&&((me=N.current.activeSheet)==null?void 0:me.getName())!==Ce.sheetName)return G.token;const W=B[te];if(te++,!W)return"";const V=(Re=W.sheetId)!=null?Re:r,ce={range:W,unitId:(ve=W.unitId)!=null?ve:o,sheetName:I(V)};return Ee([ce],i,R)[0]}return G.token});let ue="",ne;Q.forEach((G,me)=>{ue+=G,me===F&&(ne=ue.length)});const fe=[];for(let G=te;G<=M.length-1;G++){const me=M[G],Re=(z=me.sheetId)!=null?z:r,ve={range:me,unitId:(Te=me.unitId)!=null?Te:o,sheetName:I(Re)},W=Ee([ve],i&&Re!==r,R);fe.push(W[0])}const pe=y[y.length-1],De=pe&&(typeof pe=="string"?!1:pe.nodeType===x.sequenceNodeType.REFERENCE),he=`${ue}${fe.length&&De?",":""}${fe.join(",")}`;m(he,!fe.length&&ne?ne:he.length,b)}});d.useEffect(()=>{if(O&&e){let M=!0;const b=(F,v)=>{if(M){M=!1;return}L(F.map(y=>y.rangeWithCoord),v)},A=new l.DisposableCollection;return A.add(O.selectionMoving$.subscribe(F=>{b(F,!1)})),A.add(O.selectionMoveEnd$.subscribe(F=>{b(F,!0)})),()=>{A.dispose()}}},[e,L,O]),d.useEffect(()=>{if(t&&O&&u){const M=new l.DisposableCollection,b=()=>{M.dispose(),O.getSelectionControls().forEach((v,y)=>{M.add(v.selectionScaling$.subscribe(k=>{const j=O.getSelectionDataWithStyle().map(Y=>Y.rangeWithCoord),U=j[y];k.sheetId=U.sheetId,k.unitId=U.unitId,j[y]=k,L(j,!1)})),M.add(v.selectionMoving$.subscribe(k=>{const j=O.getSelectionDataWithStyle().map(Y=>Y.rangeWithCoord),U=j[y];k.sheetId=U.sheetId,k.unitId=U.unitId,j[y]=k,L(j,!0)}))})},A=q.merge(u.input$,P.selectionSet$,O.selectionMoveEnd$).pipe(jt.debounceTime(50)).subscribe(()=>{b()});return()=>{A.unsubscribe(),M.dispose()}}},[u,t,L,O,P.selectionSet$]),O==null||O.getSelectionDataWithStyle(),d.useEffect(()=>{if(c){const M=h.onCommandExecuted(b=>{var F;if(b.id!==H.SetSelectionsOperation.id)return;const A=b.params;if(A.extra==="formula-editor"&&A.selections.length){const v=A.selections[A.selections.length-1];if(v){const y=n.current===Fe.NEED_ADD,k=((F=O==null?void 0:O.getSelectionDataWithStyle())!=null?F:[]).map(j=>j.rangeWithCoord);y?k.push(v.range):k[k.length-1]=v.range,L(k,!0)}}});return()=>{M.dispose()}}},[h,u,n,_,c,L,O]),d.useEffect(()=>{if(!u)return;const M=p.textSelection$.subscribe(b=>{b.unitId===u.getEditorId()&&Qt({unitId:o,subUnitId:r,refSelections:s.current,editor:u,refSelectionsService:P,refSelectionsRenderService:O,sheetSkeletonManagerService:$,themeService:f,univerInstanceService:S})});return()=>M.unsubscribe()},[p.textSelection$,u,s,O,P,$,r,f,o,S])},ko=(e,t,n)=>{const o=a.useDependency(x.LexerTreeBuilder),r=d.useRef(!0);d.useEffect(()=>{if(e){const s=setTimeout(()=>{r.current=!1},500);return()=>{clearTimeout(s)}}},[e]),d.useEffect(()=>{if(!r.current&&t){const s=o.checkIfAddBracket(n);t(s===0&&n.startsWith(x.operatorToken.EQUALS),`${n}`)}},[n,t])},wo="univer-sheet-embedding-formula-editor-active",$o="univer-sheet-embedding-formula-editor-wrap",jo="univer-sheet-embedding-formula-editor-text",Ho="univer-sheet-embedding-formula-editor-error",Uo="univer-sheet-embedding-formula-editor",Wo="univer-sheet-embedding-formula-editor-error-wrap",je={sheetEmbeddingFormulaEditorActive:wo,sheetEmbeddingFormulaEditorWrap:$o,sheetEmbeddingFormulaEditorText:jo,sheetEmbeddingFormulaEditorError:Ho,sheetEmbeddingFormulaEditor:Uo,sheetEmbeddingFormulaEditorErrorWrap:Wo},Bo=(e,t=[],n)=>{const o=a.useDependency(xe.IDescriptionService),[r,s]=d.useState([]),[i,c]=d.useState(""),u=d.useRef(-1),m=He({nodes:t}),g=()=>{s([]),c(""),u.current=-1};return d.useEffect(()=>{if(n&&e){const h=n.input$.pipe(q.debounceTime(300)).subscribe(()=>{const p=n.getSelectionRanges();if(p.length===1){const f=m.current.nodes,_=p[0];if(_.collapsed){const E=yt(f,_.startOffset-1,!1);u.current=E;const I=f[E];if(I&&typeof I!="string"&&I.nodeType===x.sequenceNodeType.FUNCTION){u.current=E;const R=I.token,T=o.getSearchListByNameFirstLetter(R);s(T),c(R);return}}}u.current=-1,c(""),s(f=>f!=null&&f.length?[]:f)});return()=>{h.unsubscribe()}}},[n,e]),d.useEffect(()=>{e||g()},[e]),{searchList:r,searchText:i,handlerFormulaReplace:h=>{const p=[...m.current.nodes];if(u.current!==-1){const f=p.splice(u.current+1),_=p.pop()||"";let E=(typeof _=="string"?_.length:_.token.length)-h.length;return p.push(h),f[0]!==x.matchToken.OPEN_BRACKET&&(p.push(x.matchToken.OPEN_BRACKET),E--),{text:ke([...p,...f]),offset:E}}},reset:g}},Vo="univer-formula-search-function",Ko="univer-formula-search-function-item",qo="univer-formula-search-function-item-name",Yo="univer-formula-search-function-item-name-light",zo="univer-formula-search-function-item-desc",Go="univer-formula-search-function-item-active",Me={formulaSearchFunction:Vo,formulaSearchFunctionItem:Ko,formulaSearchFunctionItemName:qo,formulaSearchFunctionItemNameLight:Yo,formulaSearchFunctionItemDesc:zo,formulaSearchFunctionItemActive:Go},Zo=()=>{},Xo=d.forwardRef(Jo);function Jo(e,t){const{isFocus:n,sequenceNodes:o,onSelect:r,editor:s,onClose:i=Zo}=e,c=s.getEditorId(),u=a.useDependency(a.IShortcutService),m=a.useDependency(l.ICommandService),{searchList:g,searchText:S,handlerFormulaReplace:h,reset:p}=Bo(n,o,s),f=d.useMemo(()=>!!g.length,[g]),_=d.useRef(void 0),[E,I]=d.useState(0),R=d.useRef(!1),[T]=fn(c,f,[S,g]),N=He({searchList:g,active:E}),D=M=>{const b=h(M);b&&(p(),r(b))};function O(M){R.current&&I(M)}function $(){R.current&&I(-1)}d.useEffect(()=>{if(!g.length)return;const M=`sheet.formula-embedding-editor.search_function.${c}`,b=new l.DisposableCollection,A=F=>{const{searchList:v,active:y}=N.current;switch(F){case a.KeyCode.ARROW_UP:{I(k=>{const j=Math.max(0,k-1);return P(j),j});break}case a.KeyCode.ARROW_DOWN:{I(k=>{const j=Math.min(v.length-1,k+1);return P(j),j});break}case a.KeyCode.TAB:case a.KeyCode.ENTER:{const k=v[y];D(k.name);break}case a.KeyCode.ESC:{p(),i();break}}};return b.add(m.registerCommand({id:M,type:l.CommandType.OPERATION,handler(F,v){const{keyCode:y}=v;A(y)}})),[a.KeyCode.ARROW_UP,a.KeyCode.ARROW_DOWN,a.KeyCode.ENTER,a.KeyCode.ESC,a.KeyCode.TAB].map(F=>({id:M,binding:F,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keyCode:F}})).forEach(F=>{b.add(u.registerShortcut(F))}),()=>{b.dispose()}},[g]);function P(M){var ee;const b=(ee=_.current)==null?void 0:ee.querySelectorAll(`.${Me.formulaSearchFunctionItem}`)[M];if(!b)return;const A=b.parentNode;if(!A)return;const v=A.getBoundingClientRect().top,y=A.offsetHeight,k=b.getBoundingClientRect(),j=k.top,U=k.height;if(j>=0&&j>v&&j-v+U<=y)return;const Y=b.offsetTop-(y-U)/2;A.scrollTo({top:Y,behavior:"smooth"})}const L=d.useMemo(()=>{let M="";return()=>{clearTimeout(M),R.current=!0,M=setTimeout(()=>{R.current=!1},300)}},[]);return g.length>0&&f&&C.jsx(a.RectPopup,{portal:!0,anchorRect$:T,direction:"vertical",children:C.jsx("ul",{className:Me.formulaSearchFunction,ref:M=>{_.current=M,t&&(t.current=M)},children:g.map((M,b)=>C.jsxs("li",{className:E===b?`
11
11
  ${Me.formulaSearchFunctionItem}
12
12
  ${Me.formulaSearchFunctionItemActive}
13
- `:Me.formulaSearchFunctionItem,onMouseEnter:()=>F(M),onMouseLeave:$,onMouseMove:L,onClick:()=>{O(x.name),s&&s.focus()},children:[C.jsxs("span",{className:Me.formulaSearchFunctionItemName,children:[C.jsx("span",{className:Me.formulaSearchFunctionItemNameLight,children:x.name.substring(0,S.length)}),C.jsx("span",{children:x.name.slice(S.length)})]}),C.jsx("span",{className:Me.formulaSearchFunctionItemDesc,children:x.desc})]},x.name))})})}const Qo=e=>e.startsWith(D.operatorToken.EQUALS)?e.slice(1):"",Pt=()=>{};function dn(e){var bt,Mt;const{errorText:t,initValue:n,unitId:o,subUnitId:r,isFocus:s=!0,isSupportAcrossSheet:i=!1,onFocus:c=Pt,onBlur:f=Pt,onChange:m,onVerify:g,actions:S,className:h,editorId:p,moveCursor:u=!0,onFormulaSelectingChange:_,keyboradEventConfig:I,onMoveInEditor:R,resetSelectionOnBlur:E=!0,autoScrollbar:b=!0,isSingle:T=!0,disableSelectionOnClick:O=!1,disableContextMenu:F,style:$}=e,k=a.useDependency(X.IEditorService),L=d.useRef(null),x=a.useEvent(m);S&&(S.handleOutClick=(te,ne)=>{L.current&&!L.current.contains(te.target)&&ne()});const M=a.useEvent(_),A=d.useRef(null),N=d.useRef(void 0),v=N.current,[y,P]=d.useState(s),j=d.useRef(null),W=d.useMemo(()=>p!=null?p:l.createInternalEditorID(`${w.EMBEDDING_FORMULA_EDITOR}-${l.generateRandomId(4)}`),[]),z=d.useMemo(()=>t!==void 0,[t]),re=a.useDependency(l.IUniverInstanceService),me=re.getUnit(W);a.useObservable(me==null?void 0:me.change$);const Te=it(),q=l.BuildTextUtils.transform.getPlainText((Mt=(bt=me==null?void 0:me.getBody())==null?void 0:bt.dataStream)!=null?Mt:""),ue=je(q),J=d.useMemo(()=>Qo(q),[q]),ge=d.useMemo(()=>Te(J),[J,Te]),{isSelecting:Q,isSelectingRef:ae}=Xn({unitId:o,editorId:W,isFocus:y,disableOnClick:O}),pe=d.useRef(""),fe=a.useDependency(K.IRenderManagerService).getRenderById(W),Y=fe==null?void 0:fe.with(X.DocSelectionRenderService),de=Y==null?void 0:Y.isFocusing,Re=d.useMemo(()=>re.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_DOC),[re]),ve=a.useObservable(Re),Ce=(ve==null?void 0:ve.getUnitId())===W,U=d.useRef([]),B=Q;a.useUpdateEffect(()=>{x(q)},[q,x]);const se=en("="),ie=It(o,r),G=a.useEvent((te,ne=!0,Ee,_e)=>{if(!N.current)return;pe.current=te;const Ue=Te(te[0]==="="?te.slice(1):""),be=se(N.current,Ue,ne,_e);if(U.current=be,Ee){const Ze=_e!=null?_e:v==null?void 0:v.getSelectionRanges();if((Ze==null?void 0:Ze.length)!==1)return;const In=Ze[0].startOffset-1,Rn=yt(Ue,In,!1),xt=un(Ue,Rn);if(xt>=0){const Nt=be.splice(xt,1)[0];Nt&&be.push(Nt)}ie(y?be:[],N.current)}});d.useEffect(()=>{y&&G(q,!1,!0)},[y]),d.useEffect(()=>{if(y){if(pe.current===q)return;G(q,!1,!0)}},[q]),ko(y,g,q);const ce=Jt(v),He=sn(y,o,r);d.useEffect(()=>{M(Q)},[M,Q]),X.useKeyboardEvent(y,I,v),d.useLayoutEffect(()=>{let te;if(j.current){te=k.register({autofocus:!0,editorUnitId:W,initialSnapshot:{id:W,body:{dataStream:`${n}\r
14
- `,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},j.current);const ne=k.getEditor(W);N.current=ne,G(n,!1,!0)}return()=>{te==null||te.dispose()}},[]),d.useLayoutEffect(()=>{s?(P(s),ce()):(E&&(v==null||v.blur(),He()),P(s))},[s,v,ce,He,E]);const{checkScrollBar:De}=X.useResize(v,T,b);Rt(y,!!(Q&&Ce),o,F),on(y&&u,B,v,R);const Sn=a.useEvent((te,ne,Ee)=>{if(!de)return;const _e=ne!==-1?[{startOffset:ne+1,endOffset:ne+1,collapsed:!0}]:void 0;G(`=${te}`,!0,Ee,_e),Ee&&(ce(),ne!==-1&&setTimeout(()=>{const Ue={startOffset:ne+1,endOffset:ne+1},be=v==null?void 0:v.render.with(X.DocBackScrollRenderController);be==null||be.scrollToRange({...Ue,collapsed:!0})},50),De())});Lo(y&&!!(Q&&Ce),y,ae,o,r,U,i,!!B,v,Sn),_t(y&&!!(Q&&Ce),o,i,P,f,()=>{G(ue.current,!1,!0)});const vn=te=>{if(te){const ne=v==null?void 0:v.getSelectionRanges();if(ne&&ne.length===1){const Ee=ne[0];if(Ee.collapsed){const _e=te.offset;setTimeout(()=>{v==null||v.setSelectionRanges([{startOffset:Ee.startOffset-_e,endOffset:Ee.endOffset-_e}])},30)}}ce(),G(`=${te.text}`)}},Cn=()=>{P(!0),c(),ce()};return C.jsxs("div",{style:$,className:mt($e.sheetEmbeddingFormulaEditor,h),children:[C.jsx("div",{className:mt($e.sheetEmbeddingFormulaEditorWrap,{[$e.sheetEmbeddingFormulaEditorActive]:y,[$e.sheetEmbeddingFormulaEditorError]:z}),ref:L,children:C.jsx("div",{className:$e.sheetEmbeddingFormulaEditorText,ref:j,onMouseUp:Cn})}),t!==void 0?C.jsx("div",{className:$e.sheetEmbeddingFormulaEditorErrorWrap,children:t}):null,v?C.jsx(Oo,{editor:v,isFocus:y,formulaText:q,onClose:()=>ce()}):null,v?C.jsx(Xo,{isFocus:y,sequenceNodes:ge,onSelect:vn,ref:A,editor:v}):null]})}const er="sheets-formula-ui.base.config",Lt={};function tr(e){return e.getContextValue(l.FOCUSING_DOC)&&e.getContextValue(l.FOCUSING_UNIVER_EDITOR)}function hn(e,t=!1){return!t&&!(l.isFormulaString(e==null?void 0:e.f)||l.isFormulaId(e==null?void 0:e.si))?null:typeof(e==null?void 0:e.v)=="string"&&D.ERROR_TYPE_SET.has(e.v)?e.v:null}var nr=Object.getOwnPropertyDescriptor,or=(e,t,n,o)=>{for(var r=o>1?void 0:o?nr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Be=(e,t)=>(n,o)=>t(n,o,e);const lt="SHEET_FORMULA_ALERT",rr={[D.ErrorType.DIV_BY_ZERO]:"divByZero",[D.ErrorType.NAME]:"name",[D.ErrorType.VALUE]:"value",[D.ErrorType.NUM]:"num",[D.ErrorType.NA]:"na",[D.ErrorType.CYCLE]:"cycle",[D.ErrorType.REF]:"ref",[D.ErrorType.SPILL]:"spill",[D.ErrorType.CALC]:"calc",[D.ErrorType.ERROR]:"error",[D.ErrorType.CONNECT]:"connect",[D.ErrorType.NULL]:"null"};let pt=class extends l.Disposable{constructor(e,t,n,o,r,s){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=o,this._formulaDataModel=r,this._zenZoneService=s,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(V.debounceTime(100)).subscribe(e=>{var t,n,o,r,s;if(e){const c=this._context.unit.getActiveSheet();if(!c)return;const f=c.getCell(e.location.row,e.location.col),m=(r=(o=(n=(t=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:t[e.location.unitId])==null?void 0:n[e.location.subUnitId])==null?void 0:o[e.location.row])==null?void 0:r[e.location.col];if(l.isICellData(f)){const g=hn(f,!!m);if(!g){this._hideAlert();return}const S=this._cellAlertManagerService.currentAlert.get(lt),h=(s=S==null?void 0:S.alert)==null?void 0:s.location;if(h&&h.row===e.location.row&&h.col===e.location.col&&h.subUnitId===e.location.subUnitId&&h.unitId===e.location.unitId)return;this._cellAlertManagerService.showAlert({type:w.CellAlertType.ERROR,title:this._localeService.t("formula.error.title"),message:this._localeService.t(`formula.error.${rr[g]}`),location:e.location,width:200,height:74,key:lt});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(lt)}};pt=or([Be(1,l.Inject(w.HoverManagerService)),Be(2,l.Inject(w.CellAlertManagerService)),Be(3,l.Inject(l.LocaleService)),Be(4,l.Inject(D.FormulaDataModel)),Be(5,a.IZenZoneService)],pt);var sr=Object.getOwnPropertyDescriptor,ir=(e,t,n,o)=>{for(var r=o>1?void 0:o?sr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},kt=(e,t)=>(n,o)=>t(n,o,e);let Xe=class extends l.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=>l.isFormulaString(t==null?void 0:t.f)||l.isFormulaId(t==null?void 0:t.si),isContinue:(t,n)=>t.type===w.DATA_TYPE.FORMULA,applyFunctions:{[w.APPLY_TYPE.COPY]:(t,n,o,r)=>{const{data:s,index:i}=t;return this._fillCopyFormula(s,n,o,i,r)}}};this._autoFillService.registerRule(e)}_fillCopyFormula(e,t,n,o,r){var f,m;const s=ar(r),i=[],c=new Map;for(let g=1;g<=t;g++){const S=(g-1)%e.length,h=l.Tools.deepClone(e[S]);if(h){const p=((f=e[S])==null?void 0:f.f)||"",u=((m=e[S])==null?void 0:m.si)||"",_=l.isFormulaString(p);if(l.isFormulaId(u))h.si=u,h.f=null,h.v=null,h.p=null,h.t=null,i.push(h);else if(_){let R=c.get(S);if(R)h.si=R,h.f=null,h.v=null,h.p=null,h.t=null;else{R=l.Tools.generateRandomId(6),c.set(S,R);const{offsetX:E,offsetY:b}=cr(s,t,n),T=this._lexerTreeBuilder.moveFormulaRefOffset(p,E,b);h.si=R,h.f=T,h.v=null,h.p=null,h.t=null}i.push(h)}}}return i}};Xe=ir([kt(0,w.IAutoFillService),kt(1,l.Inject(D.LexerTreeBuilder))],Xe);function cr(e,t,n){let o=0,r=0;switch(n){case l.Direction.UP:r=-e*t;break;case l.Direction.RIGHT:o=e;break;case l.Direction.DOWN:r=e;break;case l.Direction.LEFT:o=-e*t;break}return{offsetX:o,offsetY:r}}function ar(e){let t=0;for(const n in e)e[n].forEach(o=>{t+=o.data.length});return t}var lr=Object.getOwnPropertyDescriptor,ur=(e,t,n,o)=>{for(var r=o>1?void 0:o?lr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Ve=(e,t)=>(n,o)=>t(n,o,e);const fr="default-paste-formula";let Je=class extends l.Disposable{constructor(e,t,n,o,r){super(),this._currentUniverSheet=e,this._lexerTreeBuilder=t,this._sheetClipboardService=n,this._injector=o,this._formulaDataModel=r,this._initialize()}_initialize(){this._registerClipboardHook()}_registerClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._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,o)=>this._onPasteCells(e,t,n,o,!0)}}_pasteWithFormulaHook(){return{id:fr,priority:10,onPasteCells:(e,t,n,o)=>this._onPasteCells(e,t,n,o,!1)}}_onPasteCells(e,t,n,o,r){var h;if([w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH].includes(o.pasteType))return{undos:[],redos:[]};const i=this._currentUniverSheet.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),c=t.unitId||i.getUnitId(),f=t.subUnitId||((h=i.getActiveSheet())==null?void 0:h.getSheetId());if(!c||!f)return{undos:[],redos:[]};const m=t.range,g=n,S={copyType:o.copyType||w.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:o.pasteType};return this._injector.invoke(p=>dr(c,f,m,g,p,S,this._lexerTreeBuilder,this._formulaDataModel,r,e))}};Je=ur([Ve(0,l.IUniverInstanceService),Ve(1,l.Inject(D.LexerTreeBuilder)),Ve(2,w.ISheetClipboardService),Ve(3,l.Inject(l.Injector)),Ve(4,l.Inject(D.FormulaDataModel))],Je);function dr(e,t,n,o,r,s,i,c,f=!1,m){const g=[],S=[],h=hr(e,t,n,o,s,i,c,m),p={unitId:e,subUnitId:t,cellValue:h.getData()};g.push({id:H.SetRangeValuesMutation.id,params:p});const u=H.SetRangeValuesUndoMutationFactory(r,p);return S.push({id:H.SetRangeValuesMutation.id,params:u}),{undos:S,redos:g}}function hr(e,t,n,o,r,s,i,c){return c?r.pasteType===w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE?gr(e,t,n,o,i,c):r.pasteType===w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA?pr(e,t,n,o,s,i,c):Sr(e,t,n,o,r.copyType,s,i,c):mr(e,t,n,o,i)}function mr(e,t,n,o,r){const s=new l.ObjectMatrix,i=r.getSheetFormulaData(e,t);return o.forValue((c,f,m)=>{var p;const g=n.rows[c],S=n.cols[f],h={};l.isFormulaString(m.v)?(h.v=null,h.f=`${m.v}`,h.si=null,h.p=null,s.setValue(g,S,h)):(p=i==null?void 0:i[g])!=null&&p[S]&&(h.v=m.v,h.f=null,h.si=null,h.p=null,s.setValue(g,S,h))}),s}function gr(e,t,n,o,r,s){var m,g;const i=new l.ObjectMatrix,c=(g=(m=r.getArrayFormulaCellData())==null?void 0:m[s.unitId])==null?void 0:g[s.subUnitId],f=r.getSheetFormulaData(e,t);return o.forValue((S,h,p)=>{var b,T;const u=s.range.rows[S%s.range.rows.length],_=s.range.cols[h%s.range.cols.length],I=n.rows[S],R=n.cols[h],E={};if(l.isFormulaString(p.f)||l.isFormulaId(p.si))E.v=p.v,E.f=null,E.si=null,E.p=null,i.setValue(I,R,E);else if((b=c==null?void 0:c[u])!=null&&b[_]){const O=c[u][_];E.v=O.v,E.f=null,E.si=null,E.p=null,i.setValue(I,R,E)}else if((T=f==null?void 0:f[I])!=null&&T[R]){if(E.v=p.v,E.f=null,E.si=null,E.p=null,p.p){const O=mn(p);O&&(E.v=O)}i.setValue(I,R,E)}}),i}function pr(e,t,n,o,r,s,i){const c=new l.ObjectMatrix,f=new Map;return o.forValue((m,g,S)=>{const h=n.rows[m],p=n.cols[g],u={};if(l.isFormulaId(S.si)){if(i.unitId!==e||i.subUnitId!==t){const _=s.getFormulaStringByCell(i.range.rows[m%i.range.rows.length],i.range.cols[g%i.range.cols.length],i.subUnitId,i.unitId),I=n.cols[g]-i.range.cols[g%i.range.cols.length],R=n.rows[m]-i.range.rows[m%i.range.rows.length],E=r.moveFormulaRefOffset(_||"",I,R);u.si=null,u.f=E}else u.si=S.si,u.f=null;u.v=null,u.p=null,c.setValue(h,p,u)}else if(l.isFormulaString(S.f)){const _=`${m%i.range.rows.length}_${g%i.range.cols.length}`;let I=f.get(_);if(I)u.si=I,u.f=null;else{I=l.Tools.generateRandomId(6),f.set(_,I);const R=n.cols[g]-i.range.cols[g%i.range.cols.length],E=n.rows[m]-i.range.rows[m%i.range.rows.length],b=r.moveFormulaRefOffset(S.f||"",R,E);u.si=I,u.f=b}u.v=null,u.p=null,c.setValue(h,p,u)}else{if(u.v=S.v,u.f=null,u.si=null,u.p=null,S.p){const _=mn(S);_&&(u.v=_)}c.setValue(h,p,u)}}),c}function Sr(e,t,n,o,r,s,i,c){const f=new l.ObjectMatrix,m=new Map,g=i.getSheetFormulaData(e,t),S=[];return r===w.COPY_TYPE.CUT?o.forValue((h,p,u)=>{const _=n.rows[h],I=n.cols[p],R={};if(l.isFormulaId(u.si)){if(l.isFormulaString(u.f))S.push(u.si),R.f=u.f,R.si=u.si;else if(S.includes(u.si))R.f=null,R.si=u.si;else{const E=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[p%c.range.cols.length],c.subUnitId,c.unitId);R.f=E,R.si=null}R.v=null,R.p=null,f.setValue(_,I,R)}else l.isFormulaString(u.f)&&(R.f=u.f,R.si=null,R.v=null,R.p=null,f.setValue(_,I,R))}):o.forValue((h,p,u)=>{var E;const _=n.rows[h],I=n.cols[p],R={};if(l.isFormulaId(u.si)){if(c.unitId!==e||c.subUnitId!==t){const b=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[p%c.range.cols.length],c.subUnitId,c.unitId),T=n.cols[p]-c.range.cols[p%c.range.cols.length],O=n.rows[h]-c.range.rows[h%c.range.rows.length],F=s.moveFormulaRefOffset(b||"",T,O);R.si=null,R.f=F}else R.si=u.si,R.f=null;R.v=null,R.p=null,f.setValue(_,I,R)}else if(l.isFormulaString(u.f)){const b=`${h%c.range.rows.length}_${p%c.range.cols.length}`;let T=m.get(b);if(T)R.si=T,R.f=null;else{T=l.Tools.generateRandomId(6),m.set(b,T);const O=n.cols[p]-c.range.cols[p%c.range.cols.length],F=n.rows[h]-c.range.rows[h%c.range.rows.length],$=s.moveFormulaRefOffset(u.f||"",O,F);R.si=T,R.f=$}R.v=null,R.p=null,f.setValue(_,I,R)}else(E=g==null?void 0:g[_])!=null&&E[I]&&(R.v=u.v,R.f=null,R.si=null,R.p=u.p,f.setValue(_,I,R))}),S.length>0&&new l.ObjectMatrix(g).forValue((h,p,u)=>{if(!(c.range.rows.includes(h)&&c.range.cols.includes(p))&&!(n.rows.includes(h)&&n.cols.includes(p))&&S.includes(u==null?void 0:u.si)){const _=i.getFormulaStringByCell(h,p,c.subUnitId,c.unitId);f.setValue(h,p,{f:_,si:null,v:null,p:null})}}),f}function mn(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return;const n=t.dataStream;return n.substring(n.length-2,n.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n}}var vr=Object.getOwnPropertyDescriptor,Cr=(e,t,n,o)=>{for(var r=o>1?void 0:o?vr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Ae=(e,t)=>(n,o)=>t(n,o,e);let Qe=class extends l.Disposable{constructor(t,n,o,r,s,i,c,f){super();Z(this,"_previousShape");Z(this,"_skeleton");this._context=t,this._sheetInterceptorService=n,this._formulaDataModel=o,this._themeService=r,this._renderManagerService=s,this._sheetSkeletonManagerService=i,this._commandService=c,this._logService=f,this._initSkeletonChangeListener(),this._initInterceptorEditorStart(),this._commandExecutedListener()}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(t=>{var n,o;if(t==null)this._logService.debug("[FormulaEditorShowController]: should not receive currentSkeleton$ as null!");else{const{skeleton:r}=t,s=(o=(n=this._skeleton)==null?void 0:n.worksheet)==null?void 0:o.getSheetId();if(this._changeRuntime(r),s!==r.worksheet.getSheetId())this._removeArrayFormulaRangeShape();else{const{unitId:i,sheetId:c}=t;this._updateArrayFormulaRangeShape(i,c)}}}))}_changeRuntime(t){this._skeleton=t}_initInterceptorEditorStart(){this.disposeWithMe(l.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(H.BEFORE_CELL_EDIT,{handler:(t,n,o)=>{var u,_,I,R;const{row:r,col:s,unitId:i,subUnitId:c,worksheet:f}=n,m=this._formulaDataModel.getArrayFormulaRange(),g=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return o(t);let S=null;const h=this._formulaDataModel.getFormulaStringByCell(r,s,c,i);if(h!==null&&(S={f:h}),t.v!=null&&t.v!==""&&((I=(_=(u=g[i])==null?void 0:u[c])==null?void 0:_[r])==null?void 0:I[s])==null)return S?{...t,...S}:o(t);const p=(R=m==null?void 0:m[i])==null?void 0:R[c];return p!=null&&(S=this._displayArrayFormulaRangeShape(p,r,s,i,c,f,S)),S?{...t,...S}:o(t)}})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{(t.id===D.SetFormulaCalculationResultMutation.id||t.id===D.SetArrayFormulaDataMutation.id&&n&&n.remove)&&this._removeArrayFormulaRangeShape()})),this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{H.SetWorksheetRowAutoHeightMutation.id===t.id&&requestIdleCallback(()=>{const n=t.params,{unitId:o,subUnitId:r,rowsAutoHeightInfo:s}=n;this._refreshArrayFormulaRangeShapeByRow(o,r,s)})}))}_displayArrayFormulaRangeShape(t,n,o,r,s,i,c){const f=this._formulaDataModel.getSheetFormulaData(r,s);return new l.ObjectMatrix(t).forValue((m,g,S)=>{var I;if(S==null)return!0;const{startRow:h,startColumn:p,endRow:u,endColumn:_}=S;if(m===n&&g===o)return this._createArrayFormulaRangeShape(S,r),!1;if(n>=h&&n<=u&&o>=p&&o<=_){const R=i.getCell(h,p);if((R==null?void 0:R.v)===D.ErrorType.SPILL)return;const E=(I=f==null?void 0:f[m])==null?void 0:I[g];return E==null||E.f==null?!0:(c==null&&(c={f:E.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(S,r),!1)}}),c}_createArrayFormulaRangeShape(t,n){const o=this._renderManagerService.getRenderById(n),r=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!o||!r)return;const{scene:s}=o;if(!s)return;const i=this._themeService.getCurrentTheme(),c={range:t,primary:null,style:{strokeWidth:1,stroke:i.hyacinth700,fill:new l.ColorKit(i.colorWhite).setAlpha(0).toString(),widgets:{}}},f=w.attachSelectionWithCoord(c,r),{rowHeaderWidth:m,columnHeaderHeight:g}=r,S=new w.SelectionControl(s,w.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:m,columnHeaderHeight:g});S.updateRangeBySelectionWithCoord(f),S.setEvent(!1),this._previousShape=S}_removeArrayFormulaRangeShape(){this._previousShape!=null&&(this._previousShape.dispose(),this._previousShape=null)}_refreshArrayFormulaRangeShape(t,n){if(this._previousShape){const{startRow:o,endRow:r,startColumn:s,endColumn:i}=this._previousShape.getRange(),c={startRow:o,endRow:r,startColumn:s,endColumn:i};this._removeArrayFormulaRangeShape(),this._createArrayFormulaRangeShape(c,t)}}_checkCurrentSheet(t,n){const o=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!o)return!1;const r=o.worksheet;return r?r.unitId===t&&r.getSheetId()===n:!1}_updateArrayFormulaRangeShape(t,n){this._checkCurrentSheet(t,n)&&this._previousShape&&this._refreshArrayFormulaRangeShape(t)}_refreshArrayFormulaRangeShapeByRow(t,n,o){if(!this._checkCurrentSheet(t,n)||!this._previousShape)return;const{startRow:r,endRow:s,startColumn:i,endColumn:c}=this._previousShape.getRange();for(let f=0;f<o.length;f++){const{row:m}=o[f];if(r>=m){const g={startRow:r,endRow:s,startColumn:i,endColumn:c};this._refreshArrayFormulaRangeShape(t,g);break}}}};Qe=Cr([Ae(1,l.Inject(H.SheetInterceptorService)),Ae(2,l.Inject(D.FormulaDataModel)),Ae(3,l.Inject(l.ThemeService)),Ae(4,K.IRenderManagerService),Ae(5,l.Inject(w.SheetSkeletonManagerService)),Ae(6,l.ICommandService),Ae(7,l.ILogService)],Qe);var Ir=Object.getOwnPropertyDescriptor,Rr=(e,t,n,o)=>{for(var r=o>1?void 0:o?Ir(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},wt=(e,t)=>(n,o)=>t(n,o,e);const Er={tl:{size:6,color:"#409f11"}};let et=class extends l.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(H.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,handler:(n,o,r)=>{var c,f,m,g;const s=(g=(m=(f=(c=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:c[o.unitId])==null?void 0:f[o.subUnitId])==null?void 0:m[o.row])==null?void 0:g[o.col];return hn(n,!!s)?r({...n,markers:{...n==null?void 0:n.markers,...Er}}):r(n)},priority:10}))}};et=Rr([wt(0,l.Inject(H.SheetInterceptorService)),wt(1,l.Inject(D.FormulaDataModel))],et);function _r(){const e=a.useDependency(Ne.TriggerCalculationController),t=a.useDependency(l.ICommandService),n=a.useObservable(e.progress$),o=d.useCallback(()=>{t.executeCommand(D.SetFormulaCalculationStopMutation.id)},[t]),r=d.useCallback(()=>{e.clearProgress()},[e]);return C.jsx(a.ProgressBar,{progress:n,onTerminate:o,onClearProgress:r})}const yr=(e,t=100)=>{d.useEffect(()=>{let n=null;const o=()=>{n===null&&(n=window.setTimeout(()=>{e(),n=null},t))};return window.addEventListener("scroll",o),window.addEventListener("resize",o),()=>{n!==null&&clearTimeout(n),window.removeEventListener("scroll",o),window.removeEventListener("resize",o)}},[e,t])},Tr="univer-formula-help-function",br="univer-formula-help-function-title",Mr="univer-formula-help-function-title-icons",xr="univer-formula-help-function-title-icon",Nr="univer-formula-help-function-content",Fr="univer-formula-help-function-content-inner",Or="univer-formula-help-function-content-params",Dr="univer-formula-help-function-content-params-title",Ar="univer-formula-help-function-content-params-detail",Pr="univer-formula-help-function-active",Lr="univer-formula-help-decorator",kr="univer-formula-help-param",wr="univer-formula-help-param-prefix",$r="univer-formula-help-param-item",jr="univer-formula-help-param-active",ee={formulaHelpFunction:Tr,formulaHelpFunctionTitle:br,formulaHelpFunctionTitleIcons:Mr,formulaHelpFunctionTitleIcon:xr,formulaHelpFunctionContent:Nr,formulaHelpFunctionContentInner:Fr,formulaHelpFunctionContentParams:Or,formulaHelpFunctionContentParamsTitle:Dr,formulaHelpFunctionContentParamsDetail:Ar,formulaHelpFunctionActive:Pr,formulaHelpDecorator:Lr,formulaHelpParam:kr,formulaHelpParamPrefix:wr,formulaHelpParamItem:$r,formulaHelpParamActive:jr};function Hr(){const[e,t]=d.useState(!1),[n,o]=d.useState(!0),[r,s]=d.useState(!0),[i,c]=d.useState(0),[f,m]=d.useState([0,0]),[g,S]=d.useState({left:0,top:0}),[h,p]=d.useState(null),u=a.useDependency(Ge),_=a.useDependency(l.LocaleService),I=_.t("formula.prompt.required"),R=_.t("formula.prompt.optional"),E=a.useDependency(l.IUniverInstanceService),b=a.useDependency(X.IEditorService),T=a.useDependency(a.ISidebarService),O=a.useInjector();yr(F),d.useEffect(()=>{const x=u.help$.subscribe(A=>{const{visible:N,paramIndex:v,functionInfo:y}=A;if(!N){t(N);return}const P=$();if(P==null)return;const{left:j,top:W,height:z}=P;y.description===""&&y.functionParameter.length===0||(m([j,W+z]),c(v),p(y),S({left:j,top:W}),t(N))}),M=T.scrollEvent$.pipe(V.throttleTime(100)).subscribe(F);return()=>{x==null||x.unsubscribe(),M.unsubscribe()}},[]);function F(){if(!r)return;const x=$();if(x==null)return;const{left:M,top:A,height:N}=x;m([M,A+N])}function $(){const x=E.getCurrentUniverDocInstance();if(!x)return;const M=x.getUnitId();if(!b.isEditor(M))return;const A=b.getEditor(M);return A==null?void 0:A.getBoundingClientRect()}function k(x){c(x)}function L(){s(!r),O.get(a.ILayoutService).focus()}return C.jsx(C.Fragment,{children:r?C.jsx(le.Popup,{visible:e,offset:f,children:h?C.jsxs("div",{className:ee.formulaHelpFunction,children:[C.jsxs("div",{className:ee.formulaHelpFunctionTitle,children:[C.jsx(Ur,{prefix:h.functionName,value:h.functionParameter,active:i,onClick:k}),C.jsxs("div",{className:ee.formulaHelpFunctionTitleIcons,children:[C.jsx("div",{className:ee.formulaHelpFunctionTitleIcon,style:{transform:n?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>o(!n),children:C.jsx(Ct,{})}),C.jsx("div",{className:ee.formulaHelpFunctionTitleIcon,onClick:L,children:C.jsx(st,{})})]})]}),C.jsx("div",{className:ee.formulaHelpFunctionContent,style:{height:n?"unset":0,padding:n?"revert-layer":0},children:C.jsxs("div",{className:ee.formulaHelpFunctionContentInner,children:[C.jsx(ut,{title:_.t("formula.prompt.helpExample"),value:`${h.functionName}(${h.functionParameter.map(x=>x.example).join(",")})`}),C.jsx(ut,{title:_.t("formula.prompt.helpAbstract"),value:h.description}),h&&h.functionParameter&&h.functionParameter.map((x,M)=>C.jsx(ut,{className:i===M?ee.formulaHelpFunctionActive:"",title:x.name,value:`${x.require?I:R} ${x.detail}`},M))]})})]}):C.jsx(C.Fragment,{})}):e?C.jsx("div",{className:ee.formulaHelpDecorator,onClick:()=>s(!r),style:{left:g.left-24,top:g.top},children:C.jsx(zt,{})}):C.jsx(C.Fragment,{})})}const ut=e=>C.jsxs("div",{className:ee.formulaHelpFunctionContentParams,children:[C.jsx("div",{className:`
15
- ${ee.formulaHelpFunctionContentParamsTitle}
13
+ `:Me.formulaSearchFunctionItem,onMouseEnter:()=>O(b),onMouseLeave:$,onMouseMove:L,onClick:()=>{D(M.name),s&&s.focus()},children:[C.jsxs("span",{className:Me.formulaSearchFunctionItemName,children:[C.jsx("span",{className:Me.formulaSearchFunctionItemNameLight,children:M.name.substring(0,S.length)}),C.jsx("span",{children:M.name.slice(S.length)})]}),C.jsx("span",{className:Me.formulaSearchFunctionItemDesc,children:M.desc})]},M.name))})})}const Qo=e=>e.startsWith(x.operatorToken.EQUALS)?e.slice(1):"",Pt=()=>{};function dn(e){var bt,Mt;const{errorText:t,initValue:n,unitId:o,subUnitId:r,isFocus:s=!0,isSupportAcrossSheet:i=!1,onFocus:c=Pt,onBlur:u=Pt,onChange:m,onVerify:g,actions:S,className:h,editorId:p,moveCursor:f=!0,onFormulaSelectingChange:_,keyboradEventConfig:E,onMoveInEditor:I,resetSelectionOnBlur:R=!0,autoScrollbar:T=!0,isSingle:N=!0,disableSelectionOnClick:D=!1,disableContextMenu:O,style:$}=e,P=a.useDependency(J.IEditorService),L=d.useRef(null),M=a.useEvent(m);S&&(S.handleOutClick=(re,se)=>{L.current&&!L.current.contains(re.target)&&se()});const b=a.useEvent(_),A=d.useRef(null),F=d.useRef(void 0),v=F.current,[y,k]=d.useState(s),j=d.useRef(null),U=d.useMemo(()=>p!=null?p:l.createInternalEditorID(`${w.EMBEDDING_FORMULA_EDITOR}-${l.generateRandomId(4)}`),[]),Y=d.useMemo(()=>t!==void 0,[t]),ee=a.useDependency(l.IUniverInstanceService),z=ee.getUnit(U);a.useObservable(z==null?void 0:z.change$);const Te=it(),B=l.BuildTextUtils.transform.getPlainText((Mt=(bt=z==null?void 0:z.getBody())==null?void 0:bt.dataStream)!=null?Mt:""),te=He(B),Q=d.useMemo(()=>Qo(B),[B]),ue=d.useMemo(()=>Te(Q),[Q,Te]),{isSelecting:ne,isSelectingRef:fe}=Xn({unitId:o,subUnitId:r,editorId:U,isFocus:y,disableOnClick:D}),pe=d.useRef(""),he=a.useDependency(K.IRenderManagerService).getRenderById(U),G=he==null?void 0:he.with(J.DocSelectionRenderService),me=G==null?void 0:G.isFocusing,Re=d.useMemo(()=>ee.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_DOC),[ee]),ve=a.useObservable(Re),Ce=(ve==null?void 0:ve.getUnitId())===U,W=d.useRef([]),V=ne;a.useUpdateEffect(()=>{M(B)},[B,M]);const ce=en("="),ae=Et(o,r),Z=a.useEvent((re,se=!0,Ie,_e)=>{if(!F.current)return;pe.current=re;const We=Te(re[0]==="="?re.slice(1):""),be=ce(F.current,We,se,_e);if(W.current=be,Ie){const Ze=_e!=null?_e:v==null?void 0:v.getSelectionRanges();if((Ze==null?void 0:Ze.length)!==1)return;const En=Ze[0].startOffset-1,Rn=yt(We,En,!1),Nt=un(We,Rn);if(Nt>=0){const Ft=be.splice(Nt,1)[0];Ft&&be.push(Ft)}ae(y?be:[],F.current)}});d.useEffect(()=>{y&&Z(B,!1,!0)},[y]),d.useEffect(()=>{if(y){if(pe.current===B)return;Z(B,!1,!0)}},[B]),ko(y,g,B);const le=Jt(v),Ue=sn(y,o,r);d.useEffect(()=>{b(ne)},[b,ne]),J.useKeyboardEvent(y,E,v),d.useLayoutEffect(()=>{let re;if(j.current){re=P.register({autofocus:!0,editorUnitId:U,initialSnapshot:{id:U,body:{dataStream:`${n}\r
14
+ `,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},j.current);const se=P.getEditor(U);F.current=se,Z(n,!1,!0)}return()=>{re==null||re.dispose()}},[]),d.useLayoutEffect(()=>{s?(k(s),le()):(R&&(v==null||v.blur(),Ue()),k(s))},[s,v,le,Ue,R]);const{checkScrollBar:Ae}=J.useResize(v,N,T);Rt(y,!!(ne&&Ce),o,O),on(y&&f,V,v,I);const Sn=a.useEvent((re,se,Ie)=>{if(!me)return;const _e=se!==-1?[{startOffset:se+1,endOffset:se+1,collapsed:!0}]:void 0;Z(`=${re}`,!0,Ie,_e),Ie&&(le(),se!==-1&&setTimeout(()=>{const We={startOffset:se+1,endOffset:se+1},be=v==null?void 0:v.render.with(J.DocBackScrollRenderController);be==null||be.scrollToRange({...We,collapsed:!0})},50),Ae())});Lo(y&&!!(ne&&Ce),y,fe,o,r,W,i,!!V,v,Sn),_t(y&&!!(ne&&Ce),o,i,k,u,()=>{Z(te.current,!1,!0)});const vn=re=>{if(re){const se=v==null?void 0:v.getSelectionRanges();if(se&&se.length===1){const Ie=se[0];if(Ie.collapsed){const _e=re.offset;setTimeout(()=>{v==null||v.setSelectionRanges([{startOffset:Ie.startOffset-_e,endOffset:Ie.endOffset-_e}])},30)}}le(),Z(`=${re.text}`)}},Cn=()=>{k(!0),c(),le()};return C.jsxs("div",{style:$,className:mt(je.sheetEmbeddingFormulaEditor,h),children:[C.jsx("div",{className:mt(je.sheetEmbeddingFormulaEditorWrap,{[je.sheetEmbeddingFormulaEditorActive]:y,[je.sheetEmbeddingFormulaEditorError]:Y}),ref:L,children:C.jsx("div",{className:je.sheetEmbeddingFormulaEditorText,ref:j,onMouseUp:Cn})}),t!==void 0?C.jsx("div",{className:je.sheetEmbeddingFormulaEditorErrorWrap,children:t}):null,v?C.jsx(Oo,{editor:v,isFocus:y,formulaText:B,onClose:()=>le()}):null,v?C.jsx(Xo,{isFocus:y,sequenceNodes:ue,onSelect:vn,ref:A,editor:v}):null]})}const er="sheets-formula-ui.base.config",Lt={};function tr(e){return e.getContextValue(l.FOCUSING_DOC)&&e.getContextValue(l.FOCUSING_UNIVER_EDITOR)}function hn(e,t=!1){return!t&&!(l.isFormulaString(e==null?void 0:e.f)||l.isFormulaId(e==null?void 0:e.si))?null:typeof(e==null?void 0:e.v)=="string"&&x.ERROR_TYPE_SET.has(e.v)?e.v:null}var nr=Object.getOwnPropertyDescriptor,or=(e,t,n,o)=>{for(var r=o>1?void 0:o?nr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Ve=(e,t)=>(n,o)=>t(n,o,e);const lt="SHEET_FORMULA_ALERT",rr={[x.ErrorType.DIV_BY_ZERO]:"divByZero",[x.ErrorType.NAME]:"name",[x.ErrorType.VALUE]:"value",[x.ErrorType.NUM]:"num",[x.ErrorType.NA]:"na",[x.ErrorType.CYCLE]:"cycle",[x.ErrorType.REF]:"ref",[x.ErrorType.SPILL]:"spill",[x.ErrorType.CALC]:"calc",[x.ErrorType.ERROR]:"error",[x.ErrorType.CONNECT]:"connect",[x.ErrorType.NULL]:"null"};let pt=class extends l.Disposable{constructor(e,t,n,o,r,s){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=o,this._formulaDataModel=r,this._zenZoneService=s,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(q.debounceTime(100)).subscribe(e=>{var t,n,o,r,s;if(e){const c=this._context.unit.getActiveSheet();if(!c)return;const u=c.getCell(e.location.row,e.location.col),m=(r=(o=(n=(t=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:t[e.location.unitId])==null?void 0:n[e.location.subUnitId])==null?void 0:o[e.location.row])==null?void 0:r[e.location.col];if(l.isICellData(u)){const g=hn(u,!!m);if(!g){this._hideAlert();return}const S=this._cellAlertManagerService.currentAlert.get(lt),h=(s=S==null?void 0:S.alert)==null?void 0:s.location;if(h&&h.row===e.location.row&&h.col===e.location.col&&h.subUnitId===e.location.subUnitId&&h.unitId===e.location.unitId)return;this._cellAlertManagerService.showAlert({type:w.CellAlertType.ERROR,title:this._localeService.t("formula.error.title"),message:this._localeService.t(`formula.error.${rr[g]}`),location:e.location,width:200,height:74,key:lt});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(lt)}};pt=or([Ve(1,l.Inject(w.HoverManagerService)),Ve(2,l.Inject(w.CellAlertManagerService)),Ve(3,l.Inject(l.LocaleService)),Ve(4,l.Inject(x.FormulaDataModel)),Ve(5,a.IZenZoneService)],pt);var sr=Object.getOwnPropertyDescriptor,ir=(e,t,n,o)=>{for(var r=o>1?void 0:o?sr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},kt=(e,t)=>(n,o)=>t(n,o,e);let Xe=class extends l.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=>l.isFormulaString(t==null?void 0:t.f)||l.isFormulaId(t==null?void 0:t.si),isContinue:(t,n)=>t.type===w.DATA_TYPE.FORMULA,applyFunctions:{[w.APPLY_TYPE.COPY]:(t,n,o,r)=>{const{data:s,index:i}=t;return this._fillCopyFormula(s,n,o,i,r)}}};this._autoFillService.registerRule(e)}_fillCopyFormula(e,t,n,o,r){var u,m;const s=ar(r),i=[],c=new Map;for(let g=1;g<=t;g++){const S=(g-1)%e.length,h=l.Tools.deepClone(e[S]);if(h){const p=((u=e[S])==null?void 0:u.f)||"",f=((m=e[S])==null?void 0:m.si)||"",_=l.isFormulaString(p);if(l.isFormulaId(f))h.si=f,h.f=null,h.v=null,h.p=null,h.t=null,i.push(h);else if(_){let I=c.get(S);if(I)h.si=I,h.f=null,h.v=null,h.p=null,h.t=null;else{I=l.Tools.generateRandomId(6),c.set(S,I);const{offsetX:R,offsetY:T}=cr(s,t,n),N=this._lexerTreeBuilder.moveFormulaRefOffset(p,R,T);h.si=I,h.f=N,h.v=null,h.p=null,h.t=null}i.push(h)}}}return i}};Xe=ir([kt(0,w.IAutoFillService),kt(1,l.Inject(x.LexerTreeBuilder))],Xe);function cr(e,t,n){let o=0,r=0;switch(n){case l.Direction.UP:r=-e*t;break;case l.Direction.RIGHT:o=e;break;case l.Direction.DOWN:r=e;break;case l.Direction.LEFT:o=-e*t;break}return{offsetX:o,offsetY:r}}function ar(e){let t=0;for(const n in e)e[n].forEach(o=>{t+=o.data.length});return t}var lr=Object.getOwnPropertyDescriptor,ur=(e,t,n,o)=>{for(var r=o>1?void 0:o?lr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Ke=(e,t)=>(n,o)=>t(n,o,e);const fr="default-paste-formula";let Je=class extends l.Disposable{constructor(e,t,n,o,r){super(),this._currentUniverSheet=e,this._lexerTreeBuilder=t,this._sheetClipboardService=n,this._injector=o,this._formulaDataModel=r,this._initialize()}_initialize(){this._registerClipboardHook()}_registerClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._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,o)=>this._onPasteCells(e,t,n,o,!0)}}_pasteWithFormulaHook(){return{id:fr,priority:10,onPasteCells:(e,t,n,o)=>this._onPasteCells(e,t,n,o,!1)}}_onPasteCells(e,t,n,o,r){var h;if([w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH].includes(o.pasteType))return{undos:[],redos:[]};const i=this._currentUniverSheet.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),c=t.unitId||i.getUnitId(),u=t.subUnitId||((h=i.getActiveSheet())==null?void 0:h.getSheetId());if(!c||!u)return{undos:[],redos:[]};const m=t.range,g=n,S={copyType:o.copyType||w.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:o.pasteType};return this._injector.invoke(p=>dr(c,u,m,g,p,S,this._lexerTreeBuilder,this._formulaDataModel,r,e))}};Je=ur([Ke(0,l.IUniverInstanceService),Ke(1,l.Inject(x.LexerTreeBuilder)),Ke(2,w.ISheetClipboardService),Ke(3,l.Inject(l.Injector)),Ke(4,l.Inject(x.FormulaDataModel))],Je);function dr(e,t,n,o,r,s,i,c,u=!1,m){const g=[],S=[],h=hr(e,t,n,o,s,i,c,m);if(!h.hasValue())return{undos:[],redos:[]};const p={unitId:e,subUnitId:t,cellValue:h.getData()};g.push({id:H.SetRangeValuesMutation.id,params:p});const f=H.SetRangeValuesUndoMutationFactory(r,p);return S.push({id:H.SetRangeValuesMutation.id,params:f}),{undos:S,redos:g}}function hr(e,t,n,o,r,s,i,c){return c?r.pasteType===w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE?gr(e,t,n,o,i,c):r.pasteType===w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA?pr(e,t,n,o,s,i,c):Sr(e,t,n,o,r.copyType,s,i,c):mr(e,t,n,o,i)}function mr(e,t,n,o,r){const s=new l.ObjectMatrix,i=r.getSheetFormulaData(e,t);return o.forValue((c,u,m)=>{var p;const g=n.rows[c],S=n.cols[u],h={};l.isFormulaString(m.v)?(h.v=null,h.f=`${m.v}`,h.si=null,h.p=null,s.setValue(g,S,h)):(p=i==null?void 0:i[g])!=null&&p[S]&&(h.v=m.v,h.f=null,h.si=null,h.p=null,s.setValue(g,S,h))}),s}function gr(e,t,n,o,r,s){var m,g;const i=new l.ObjectMatrix,c=(g=(m=r.getArrayFormulaCellData())==null?void 0:m[s.unitId])==null?void 0:g[s.subUnitId],u=r.getSheetFormulaData(e,t);return o.forValue((S,h,p)=>{var T,N;const f=s.range.rows[S%s.range.rows.length],_=s.range.cols[h%s.range.cols.length],E=n.rows[S],I=n.cols[h],R={};if(l.isFormulaString(p.f)||l.isFormulaId(p.si))R.v=p.v,R.f=null,R.si=null,R.p=null,i.setValue(E,I,R);else if((T=c==null?void 0:c[f])!=null&&T[_]){const D=c[f][_];R.v=D.v,R.f=null,R.si=null,R.p=null,i.setValue(E,I,R)}else if((N=u==null?void 0:u[E])!=null&&N[I]){if(R.v=p.v,R.f=null,R.si=null,R.p=null,p.p){const D=mn(p);D&&(R.v=D)}i.setValue(E,I,R)}}),i}function pr(e,t,n,o,r,s,i){const c=new l.ObjectMatrix,u=new Map;return o.forValue((m,g,S)=>{const h=n.rows[m],p=n.cols[g],f={};if(l.isFormulaId(S.si)){if(i.unitId!==e||i.subUnitId!==t){const _=s.getFormulaStringByCell(i.range.rows[m%i.range.rows.length],i.range.cols[g%i.range.cols.length],i.subUnitId,i.unitId),E=n.cols[g]-i.range.cols[g%i.range.cols.length],I=n.rows[m]-i.range.rows[m%i.range.rows.length],R=r.moveFormulaRefOffset(_||"",E,I);f.si=null,f.f=R}else f.si=S.si,f.f=null;f.v=null,f.p=null,c.setValue(h,p,f)}else if(l.isFormulaString(S.f)){const _=`${m%i.range.rows.length}_${g%i.range.cols.length}`;let E=u.get(_);if(E)f.si=E,f.f=null;else{E=l.Tools.generateRandomId(6),u.set(_,E);const I=n.cols[g]-i.range.cols[g%i.range.cols.length],R=n.rows[m]-i.range.rows[m%i.range.rows.length],T=r.moveFormulaRefOffset(S.f||"",I,R);f.si=E,f.f=T}f.v=null,f.p=null,c.setValue(h,p,f)}else{if(f.v=S.v,f.f=null,f.si=null,f.p=null,S.p){const _=mn(S);_&&(f.v=_)}c.setValue(h,p,f)}}),c}function Sr(e,t,n,o,r,s,i,c){const u=new l.ObjectMatrix,m=new Map,g=i.getSheetFormulaData(e,t),S=[];return r===w.COPY_TYPE.CUT?o.forValue((h,p,f)=>{const _=n.rows[h],E=n.cols[p],I={};if(l.isFormulaId(f.si)){if(l.isFormulaString(f.f))S.push(f.si),I.f=f.f,I.si=f.si;else if(S.includes(f.si))I.f=null,I.si=f.si;else{const R=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[p%c.range.cols.length],c.subUnitId,c.unitId);I.f=R,I.si=null}I.v=null,I.p=null,u.setValue(_,E,I)}else l.isFormulaString(f.f)&&(I.f=f.f,I.si=null,I.v=null,I.p=null,u.setValue(_,E,I))}):o.forValue((h,p,f)=>{var R;const _=n.rows[h],E=n.cols[p],I={};if(l.isFormulaId(f.si)){if(c.unitId!==e||c.subUnitId!==t){const T=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[p%c.range.cols.length],c.subUnitId,c.unitId),N=n.cols[p]-c.range.cols[p%c.range.cols.length],D=n.rows[h]-c.range.rows[h%c.range.rows.length],O=s.moveFormulaRefOffset(T||"",N,D);I.si=null,I.f=O}else I.si=f.si,I.f=null;I.v=null,I.p=null,u.setValue(_,E,I)}else if(l.isFormulaString(f.f)){const T=`${h%c.range.rows.length}_${p%c.range.cols.length}`;let N=m.get(T);if(N)I.si=N,I.f=null;else{N=l.Tools.generateRandomId(6),m.set(T,N);const D=n.cols[p]-c.range.cols[p%c.range.cols.length],O=n.rows[h]-c.range.rows[h%c.range.rows.length],$=s.moveFormulaRefOffset(f.f||"",D,O);I.si=N,I.f=$}I.v=null,I.p=null,u.setValue(_,E,I)}else(R=g==null?void 0:g[_])!=null&&R[E]&&(I.v=f.v,I.f=null,I.si=null,I.p=f.p,u.setValue(_,E,I))}),S.length>0&&new l.ObjectMatrix(g).forValue((h,p,f)=>{if(!(c.range.rows.includes(h)&&c.range.cols.includes(p))&&!(n.rows.includes(h)&&n.cols.includes(p))&&S.includes(f==null?void 0:f.si)){const _=i.getFormulaStringByCell(h,p,c.subUnitId,c.unitId);u.setValue(h,p,{f:_,si:null,v:null,p:null})}}),u}function mn(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return;const n=t.dataStream;return n.substring(n.length-2,n.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n}}var vr=Object.getOwnPropertyDescriptor,Cr=(e,t,n,o)=>{for(var r=o>1?void 0:o?vr(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Pe=(e,t)=>(n,o)=>t(n,o,e);let Qe=class extends l.Disposable{constructor(t,n,o,r,s,i,c,u){super();X(this,"_previousShape");X(this,"_skeleton");this._context=t,this._sheetInterceptorService=n,this._formulaDataModel=o,this._themeService=r,this._renderManagerService=s,this._sheetSkeletonManagerService=i,this._commandService=c,this._logService=u,this._initSkeletonChangeListener(),this._initInterceptorEditorStart(),this._commandExecutedListener()}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(t=>{var n,o;if(t==null)this._logService.debug("[FormulaEditorShowController]: should not receive currentSkeleton$ as null!");else{const{skeleton:r}=t,s=(o=(n=this._skeleton)==null?void 0:n.worksheet)==null?void 0:o.getSheetId();if(this._changeRuntime(r),s!==r.worksheet.getSheetId())this._removeArrayFormulaRangeShape();else{const{unitId:i,sheetId:c}=t;this._updateArrayFormulaRangeShape(i,c)}}}))}_changeRuntime(t){this._skeleton=t}_initInterceptorEditorStart(){this.disposeWithMe(l.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(H.BEFORE_CELL_EDIT,{handler:(t,n,o)=>{var f,_,E,I;const{row:r,col:s,unitId:i,subUnitId:c,worksheet:u}=n,m=this._formulaDataModel.getArrayFormulaRange(),g=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return o(t);let S=null;const h=this._formulaDataModel.getFormulaStringByCell(r,s,c,i);if(h!==null&&(S={f:h}),t.v!=null&&t.v!==""&&((E=(_=(f=g[i])==null?void 0:f[c])==null?void 0:_[r])==null?void 0:E[s])==null)return S?{...t,...S}:o(t);const p=(I=m==null?void 0:m[i])==null?void 0:I[c];return p!=null&&(S=this._displayArrayFormulaRangeShape(p,r,s,i,c,u,S)),S?{...t,...S}:o(t)}})))}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{(t.id===x.SetFormulaCalculationResultMutation.id||t.id===x.SetArrayFormulaDataMutation.id&&n&&n.remove)&&this._removeArrayFormulaRangeShape()})),this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{H.SetWorksheetRowAutoHeightMutation.id===t.id&&requestIdleCallback(()=>{const n=t.params,{unitId:o,subUnitId:r,rowsAutoHeightInfo:s}=n;this._refreshArrayFormulaRangeShapeByRow(o,r,s)})}))}_displayArrayFormulaRangeShape(t,n,o,r,s,i,c){const u=this._formulaDataModel.getSheetFormulaData(r,s);return new l.ObjectMatrix(t).forValue((m,g,S)=>{var E;if(S==null)return!0;const{startRow:h,startColumn:p,endRow:f,endColumn:_}=S;if(m===n&&g===o)return this._createArrayFormulaRangeShape(S,r),!1;if(n>=h&&n<=f&&o>=p&&o<=_){const I=i.getCell(h,p);if((I==null?void 0:I.v)===x.ErrorType.SPILL)return;const R=(E=u==null?void 0:u[m])==null?void 0:E[g];return R==null||R.f==null?!0:(c==null&&(c={f:R.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(S,r),!1)}}),c}_createArrayFormulaRangeShape(t,n){const o=this._renderManagerService.getRenderById(n),r=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!o||!r)return;const{scene:s}=o;if(!s)return;const i=this._themeService.getCurrentTheme(),c={range:t,primary:null,style:{strokeWidth:1,stroke:i.hyacinth700,fill:new l.ColorKit(i.colorWhite).setAlpha(0).toString(),widgets:{}}},u=w.attachSelectionWithCoord(c,r),{rowHeaderWidth:m,columnHeaderHeight:g}=r,S=new w.SelectionControl(s,w.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:m,columnHeaderHeight:g});S.updateRangeBySelectionWithCoord(u),S.setEvent(!1),this._previousShape=S}_removeArrayFormulaRangeShape(){this._previousShape!=null&&(this._previousShape.dispose(),this._previousShape=null)}_refreshArrayFormulaRangeShape(t,n){if(this._previousShape){const{startRow:o,endRow:r,startColumn:s,endColumn:i}=this._previousShape.getRange(),c={startRow:o,endRow:r,startColumn:s,endColumn:i};this._removeArrayFormulaRangeShape(),this._createArrayFormulaRangeShape(c,t)}}_checkCurrentSheet(t,n){const o=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!o)return!1;const r=o.worksheet;return r?r.unitId===t&&r.getSheetId()===n:!1}_updateArrayFormulaRangeShape(t,n){this._checkCurrentSheet(t,n)&&this._previousShape&&this._refreshArrayFormulaRangeShape(t)}_refreshArrayFormulaRangeShapeByRow(t,n,o){if(!this._checkCurrentSheet(t,n)||!this._previousShape)return;const{startRow:r,endRow:s,startColumn:i,endColumn:c}=this._previousShape.getRange();for(let u=0;u<o.length;u++){const{row:m}=o[u];if(r>=m){const g={startRow:r,endRow:s,startColumn:i,endColumn:c};this._refreshArrayFormulaRangeShape(t,g);break}}}};Qe=Cr([Pe(1,l.Inject(H.SheetInterceptorService)),Pe(2,l.Inject(x.FormulaDataModel)),Pe(3,l.Inject(l.ThemeService)),Pe(4,K.IRenderManagerService),Pe(5,l.Inject(w.SheetSkeletonManagerService)),Pe(6,l.ICommandService),Pe(7,l.ILogService)],Qe);var Er=Object.getOwnPropertyDescriptor,Rr=(e,t,n,o)=>{for(var r=o>1?void 0:o?Er(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},wt=(e,t)=>(n,o)=>t(n,o,e);const Ir={tl:{size:6,color:"#409f11"}};let et=class extends l.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(H.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,handler:(n,o,r)=>{var c,u,m,g;const s=(g=(m=(u=(c=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:c[o.unitId])==null?void 0:u[o.subUnitId])==null?void 0:m[o.row])==null?void 0:g[o.col];return hn(n,!!s)?r({...n,markers:{...n==null?void 0:n.markers,...Ir}}):r(n)},priority:10}))}};et=Rr([wt(0,l.Inject(H.SheetInterceptorService)),wt(1,l.Inject(x.FormulaDataModel))],et);function _r(){const e=a.useDependency(xe.TriggerCalculationController),t=a.useDependency(l.ICommandService),n=a.useObservable(e.progress$),o=d.useCallback(()=>{t.executeCommand(x.SetFormulaCalculationStopMutation.id)},[t]),r=d.useCallback(()=>{e.clearProgress()},[e]);return C.jsx(a.ProgressBar,{progress:n,onTerminate:o,onClearProgress:r})}const yr=(e,t=100)=>{d.useEffect(()=>{let n=null;const o=()=>{n===null&&(n=window.setTimeout(()=>{e(),n=null},t))};return window.addEventListener("scroll",o),window.addEventListener("resize",o),()=>{n!==null&&clearTimeout(n),window.removeEventListener("scroll",o),window.removeEventListener("resize",o)}},[e,t])},Tr="univer-formula-help-function",br="univer-formula-help-function-title",Mr="univer-formula-help-function-title-icons",Nr="univer-formula-help-function-title-icon",Fr="univer-formula-help-function-content",xr="univer-formula-help-function-content-inner",Or="univer-formula-help-function-content-params",Dr="univer-formula-help-function-content-params-title",Ar="univer-formula-help-function-content-params-detail",Pr="univer-formula-help-function-active",Lr="univer-formula-help-decorator",kr="univer-formula-help-param",wr="univer-formula-help-param-prefix",$r="univer-formula-help-param-item",jr="univer-formula-help-param-active",oe={formulaHelpFunction:Tr,formulaHelpFunctionTitle:br,formulaHelpFunctionTitleIcons:Mr,formulaHelpFunctionTitleIcon:Nr,formulaHelpFunctionContent:Fr,formulaHelpFunctionContentInner:xr,formulaHelpFunctionContentParams:Or,formulaHelpFunctionContentParamsTitle:Dr,formulaHelpFunctionContentParamsDetail:Ar,formulaHelpFunctionActive:Pr,formulaHelpDecorator:Lr,formulaHelpParam:kr,formulaHelpParamPrefix:wr,formulaHelpParamItem:$r,formulaHelpParamActive:jr};function Hr(){const[e,t]=d.useState(!1),[n,o]=d.useState(!0),[r,s]=d.useState(!0),[i,c]=d.useState(0),[u,m]=d.useState([0,0]),[g,S]=d.useState({left:0,top:0}),[h,p]=d.useState(null),f=a.useDependency(Ge),_=a.useDependency(l.LocaleService),E=_.t("formula.prompt.required"),I=_.t("formula.prompt.optional"),R=a.useDependency(l.IUniverInstanceService),T=a.useDependency(J.IEditorService),N=a.useDependency(a.ISidebarService),D=a.useInjector();yr(O),d.useEffect(()=>{const M=f.help$.subscribe(A=>{const{visible:F,paramIndex:v,functionInfo:y}=A;if(!F){t(F);return}const k=$();if(k==null)return;const{left:j,top:U,height:Y}=k;y.description===""&&y.functionParameter.length===0||(m([j,U+Y]),c(v),p(y),S({left:j,top:U}),t(F))}),b=N.scrollEvent$.pipe(q.throttleTime(100)).subscribe(O);return()=>{M==null||M.unsubscribe(),b.unsubscribe()}},[]);function O(){if(!r)return;const M=$();if(M==null)return;const{left:b,top:A,height:F}=M;m([b,A+F])}function $(){const M=R.getCurrentUniverDocInstance();if(!M)return;const b=M.getUnitId();if(!T.isEditor(b))return;const A=T.getEditor(b);return A==null?void 0:A.getBoundingClientRect()}function P(M){c(M)}function L(){s(!r),D.get(a.ILayoutService).focus()}return C.jsx(C.Fragment,{children:r?C.jsx(de.Popup,{visible:e,offset:u,children:h?C.jsxs("div",{className:oe.formulaHelpFunction,children:[C.jsxs("div",{className:oe.formulaHelpFunctionTitle,children:[C.jsx(Ur,{prefix:h.functionName,value:h.functionParameter,active:i,onClick:P}),C.jsxs("div",{className:oe.formulaHelpFunctionTitleIcons,children:[C.jsx("div",{className:oe.formulaHelpFunctionTitleIcon,style:{transform:n?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>o(!n),children:C.jsx(Ct,{})}),C.jsx("div",{className:oe.formulaHelpFunctionTitleIcon,onClick:L,children:C.jsx(st,{})})]})]}),C.jsx("div",{className:oe.formulaHelpFunctionContent,style:{height:n?"unset":0,padding:n?"revert-layer":0},children:C.jsxs("div",{className:oe.formulaHelpFunctionContentInner,children:[C.jsx(ut,{title:_.t("formula.prompt.helpExample"),value:`${h.functionName}(${h.functionParameter.map(M=>M.example).join(",")})`}),C.jsx(ut,{title:_.t("formula.prompt.helpAbstract"),value:h.description}),h&&h.functionParameter&&h.functionParameter.map((M,b)=>C.jsx(ut,{className:i===b?oe.formulaHelpFunctionActive:"",title:M.name,value:`${M.require?E:I} ${M.detail}`},b))]})})]}):C.jsx(C.Fragment,{})}):e?C.jsx("div",{className:oe.formulaHelpDecorator,onClick:()=>s(!r),style:{left:g.left-24,top:g.top},children:C.jsx(zt,{})}):C.jsx(C.Fragment,{})})}const ut=e=>C.jsxs("div",{className:oe.formulaHelpFunctionContentParams,children:[C.jsx("div",{className:`
15
+ ${oe.formulaHelpFunctionContentParamsTitle}
16
16
  ${e.className}
17
- `,children:e.title}),C.jsx("div",{className:ee.formulaHelpFunctionContentParamsDetail,children:e.value})]}),Ur=e=>{const{prefix:t,value:n,active:o,onClick:r}=e;return C.jsxs("div",{className:ee.formulaHelpParam,children:[C.jsxs("span",{className:ee.formulaHelpParamPrefix,children:[t,"("]}),n&&n.map((s,i)=>C.jsxs("span",{className:ee.formulaHelpParamItem,children:[C.jsx("span",{className:o===i?ee.formulaHelpFunctionActive:ee.formulaHelpParamActive,onClick:()=>r(i),children:Tt(s)}),i===n.length-1?"":","]},i)),")"]})},Wr="univer-formula-search-function",Br="univer-formula-search-function-item",Vr="univer-formula-search-function-item-name",Kr="univer-formula-search-function-item-name-light",qr="univer-formula-search-function-item-desc",Yr="univer-formula-search-function-item-active",xe={formulaSearchFunction:Wr,formulaSearchFunctionItem:Br,formulaSearchFunctionItemName:Vr,formulaSearchFunctionItemNameLight:Kr,formulaSearchFunctionItemDesc:qr,formulaSearchFunctionItemActive:Yr};function zr(){const[e,t]=d.useState(!1),[n,o]=d.useState(0),[r,s]=d.useState([0,0]),[i,c]=d.useState([]),[f,m]=d.useState(""),g=d.useRef(null),S=a.useDependency(Ge),h=a.useDependency(l.IUniverInstanceService),p=a.useDependency(X.IEditorService);d.useEffect(()=>{let E=[],b=0;const T=S.search$.subscribe($=>{const{visible:k,searchText:L,searchList:x}=$;if(!k){t(k);return}const M=u();if(M==null)return;const{left:A,top:N,height:v}=M;m(L),c(x),E=x,s([A,N+v]),t(k),o(0),b=0}),O=S.navigate$.subscribe($=>{const{direction:k}=$;if(k===l.Direction.UP){let L=b-1;L=L<0?E.length-1:L,o(L),b=L}else if(k===l.Direction.DOWN){let L=b+1;L=L>=E.length?0:L,o(L),b=L}R(b)}),F=S.accept$.subscribe($=>{const k=E[b].name;S.acceptFormulaName(k)});return()=>{T==null||T.unsubscribe(),O==null||O.unsubscribe(),F==null||F.unsubscribe()}},[]);function u(){const b=h.getCurrentUniverDocInstance().getUnitId();if(!p.isEditor(b))return;const T=p.getEditor(b);return T==null?void 0:T.getBoundingClientRect()}function _(E){o(E)}function I(){o(-1)}function R(E){var A;const b=(A=g.current)==null?void 0:A.querySelectorAll(`.${xe.formulaSearchFunctionItem}`)[E];if(!b)return;const T=b.parentNode;if(!T)return;const F=T.getBoundingClientRect().top,$=T.offsetHeight,k=b.getBoundingClientRect(),L=k.top,x=k.height;if(L>=0&&L>F&&L-F+x<=$)return;const M=b.offsetTop-($-x)/2;T.scrollTo({top:M,behavior:"smooth"})}return i.length>0&&C.jsx(le.Popup,{visible:e,offset:r,children:C.jsx("ul",{className:xe.formulaSearchFunction,ref:g,children:i.map((E,b)=>C.jsxs("li",{className:n===b?`
18
- ${xe.formulaSearchFunctionItem}
19
- ${xe.formulaSearchFunctionItemActive}
20
- `:xe.formulaSearchFunctionItem,onMouseEnter:()=>_(b),onMouseLeave:I,onClick:()=>S.acceptFormulaName(E.name),children:[C.jsxs("span",{className:xe.formulaSearchFunctionItemName,children:[C.jsx("span",{className:xe.formulaSearchFunctionItemNameLight,children:E.name.substring(0,f.length)}),C.jsx("span",{children:E.name.slice(f.length)})]}),C.jsx("span",{className:xe.formulaSearchFunctionItemDesc,children:E.desc})]},b))})})}function Gr(){return C.jsxs(C.Fragment,{children:[C.jsx(zr,{}),C.jsx(Hr,{})]})}const Zr="univer-formula-more-functions",Xr="univer-formula-more-functions-operation",$t={formulaMoreFunctions:Zr,formulaMoreFunctionsOperation:Xr};function gn(e){const{prefix:t,value:n}=e;return C.jsxs("div",{children:[C.jsxs("span",{children:[t,"("]}),n&&n.map((o,r)=>C.jsxs("span",{children:[C.jsx("span",{children:Tt(o)}),r===n.length-1?"":","]},r)),")"]})}const Jr="univer-formula-function-params",Qr="univer-formula-function-params-title",es="univer-formula-function-params-detail",ft={formulaFunctionParams:Jr,formulaFunctionParamsTitle:Qr,formulaFunctionParamsDetail:es};function qe(e){const{className:t,value:n,title:o}=e;return C.jsxs("div",{className:ft.formulaFunctionParams,children:[C.jsx("div",{className:`
17
+ `,children:e.title}),C.jsx("div",{className:oe.formulaHelpFunctionContentParamsDetail,children:e.value})]}),Ur=e=>{const{prefix:t,value:n,active:o,onClick:r}=e;return C.jsxs("div",{className:oe.formulaHelpParam,children:[C.jsxs("span",{className:oe.formulaHelpParamPrefix,children:[t,"("]}),n&&n.map((s,i)=>C.jsxs("span",{className:oe.formulaHelpParamItem,children:[C.jsx("span",{className:o===i?oe.formulaHelpFunctionActive:oe.formulaHelpParamActive,onClick:()=>r(i),children:Tt(s)}),i===n.length-1?"":","]},i)),")"]})},Wr="univer-formula-search-function",Br="univer-formula-search-function-item",Vr="univer-formula-search-function-item-name",Kr="univer-formula-search-function-item-name-light",qr="univer-formula-search-function-item-desc",Yr="univer-formula-search-function-item-active",Ne={formulaSearchFunction:Wr,formulaSearchFunctionItem:Br,formulaSearchFunctionItemName:Vr,formulaSearchFunctionItemNameLight:Kr,formulaSearchFunctionItemDesc:qr,formulaSearchFunctionItemActive:Yr};function zr(){const[e,t]=d.useState(!1),[n,o]=d.useState(0),[r,s]=d.useState([0,0]),[i,c]=d.useState([]),[u,m]=d.useState(""),g=d.useRef(null),S=a.useDependency(Ge),h=a.useDependency(l.IUniverInstanceService),p=a.useDependency(J.IEditorService);d.useEffect(()=>{let R=[],T=0;const N=S.search$.subscribe($=>{const{visible:P,searchText:L,searchList:M}=$;if(!P){t(P);return}const b=f();if(b==null)return;const{left:A,top:F,height:v}=b;m(L),c(M),R=M,s([A,F+v]),t(P),o(0),T=0}),D=S.navigate$.subscribe($=>{const{direction:P}=$;if(P===l.Direction.UP){let L=T-1;L=L<0?R.length-1:L,o(L),T=L}else if(P===l.Direction.DOWN){let L=T+1;L=L>=R.length?0:L,o(L),T=L}I(T)}),O=S.accept$.subscribe($=>{const P=R[T].name;S.acceptFormulaName(P)});return()=>{N==null||N.unsubscribe(),D==null||D.unsubscribe(),O==null||O.unsubscribe()}},[]);function f(){const T=h.getCurrentUniverDocInstance().getUnitId();if(!p.isEditor(T))return;const N=p.getEditor(T);return N==null?void 0:N.getBoundingClientRect()}function _(R){o(R)}function E(){o(-1)}function I(R){var A;const T=(A=g.current)==null?void 0:A.querySelectorAll(`.${Ne.formulaSearchFunctionItem}`)[R];if(!T)return;const N=T.parentNode;if(!N)return;const O=N.getBoundingClientRect().top,$=N.offsetHeight,P=T.getBoundingClientRect(),L=P.top,M=P.height;if(L>=0&&L>O&&L-O+M<=$)return;const b=T.offsetTop-($-M)/2;N.scrollTo({top:b,behavior:"smooth"})}return i.length>0&&C.jsx(de.Popup,{visible:e,offset:r,children:C.jsx("ul",{className:Ne.formulaSearchFunction,ref:g,children:i.map((R,T)=>C.jsxs("li",{className:n===T?`
18
+ ${Ne.formulaSearchFunctionItem}
19
+ ${Ne.formulaSearchFunctionItemActive}
20
+ `:Ne.formulaSearchFunctionItem,onMouseEnter:()=>_(T),onMouseLeave:E,onClick:()=>S.acceptFormulaName(R.name),children:[C.jsxs("span",{className:Ne.formulaSearchFunctionItemName,children:[C.jsx("span",{className:Ne.formulaSearchFunctionItemNameLight,children:R.name.substring(0,u.length)}),C.jsx("span",{children:R.name.slice(u.length)})]}),C.jsx("span",{className:Ne.formulaSearchFunctionItemDesc,children:R.desc})]},T))})})}function Gr(){return C.jsxs(C.Fragment,{children:[C.jsx(zr,{}),C.jsx(Hr,{})]})}const Zr="univer-formula-more-functions",Xr="univer-formula-more-functions-operation",$t={formulaMoreFunctions:Zr,formulaMoreFunctionsOperation:Xr};function gn(e){const{prefix:t,value:n}=e;return C.jsxs("div",{children:[C.jsxs("span",{children:[t,"("]}),n&&n.map((o,r)=>C.jsxs("span",{children:[C.jsx("span",{children:Tt(o)}),r===n.length-1?"":","]},r)),")"]})}const Jr="univer-formula-function-params",Qr="univer-formula-function-params-title",es="univer-formula-function-params-detail",ft={formulaFunctionParams:Jr,formulaFunctionParamsTitle:Qr,formulaFunctionParamsDetail:es};function Ye(e){const{className:t,value:n,title:o}=e;return C.jsxs("div",{className:ft.formulaFunctionParams,children:[C.jsx("div",{className:`
21
21
  ${ft.formulaFunctionParamsTitle}
22
22
  ${t}
23
- `,children:o}),C.jsx("div",{className:ft.formulaFunctionParamsDetail,children:n})]})}const ts="univer-formula-input-params-list",ns="univer-formula-input-params-list-item-name",os="univer-formula-input-params-list-item-selector",Ke={formulaInputParamsList:ts,formulaInputParamsListItemName:ns,formulaInputParamsListItemSelector:os};function rs(e){const{functionInfo:t,onChange:n}=e;if(!t)return null;const[o,r]=d.useState([]),[s,i]=d.useState(t.functionParameter),[c,f]=d.useState(-1);return C.jsxs("div",{className:Ke.formulaInputParams,children:[C.jsx("div",{className:Ke.formulaInputParamsList,children:s.map((m,g)=>C.jsxs("div",{children:[C.jsx("div",{className:Ke.formulaInputParamsListItemName,children:m.name}),C.jsx("div",{className:Ke.formulaInputParamsListItemSelector})]},g))}),C.jsx("div",{className:Ke.formulaInputParamsInfo,children:C.jsx(qe,{title:c===-1?C.jsx(gn,{prefix:t.functionName,value:s}):s[c].name,value:c===-1?t.description:s[c].detail})})]})}const ss="univer-formula-select-function-select",is="univer-formula-select-function-result",cs="univer-formula-select-function-result-item",as="univer-formula-select-function-result-item-name-light",ls="univer-formula-select-function-result-item-selected",us="univer-formula-select-function-result-item-active",fs="univer-formula-select-function-content",ye={formulaSelectFunctionSelect:ss,formulaSelectFunctionResult:is,formulaSelectFunctionResultItem:cs,formulaSelectFunctionResultItemNameLight:as,formulaSelectFunctionResultItemSelected:ls,formulaSelectFunctionResultItemActive:us,formulaSelectFunctionContent:fs};function ds(e){const{onChange:t}=e,n="-1",[o,r]=d.useState(""),[s,i]=d.useState([]),[c,f]=d.useState(0),[m,g]=d.useState(n),[S,h]=d.useState(0),[p,u]=d.useState(null),_=a.useDependency(Ne.IDescriptionService),I=a.useDependency(l.LocaleService),R=a.useDependency(a.ISidebarService),E=a.useObservable(R.sidebarOptions$),b=ho(D.FunctionType,I);b.unshift({label:I.t("formula.moreFunctions.allFunctions"),value:n});const T=I.t("formula.prompt.required"),O=I.t("formula.prompt.optional");d.useEffect(()=>{k(n)},[]),d.useEffect(()=>{$(0)},[s]),d.useEffect(()=>{E!=null&&E.visible&&(r(""),i([]),f(0),g(n),h(0),u(null),k(n))},[E]);const F=N=>{if(o.trim()==="")return N;const v=new RegExp(`(${o.toLocaleUpperCase()})`);return N.split(v).filter(Boolean).map((P,j)=>P.match(v)?C.jsx("span",{className:ye.formulaSelectFunctionResultItemNameLight,children:P},j):P)},$=N=>{if(s.length===0){u(null);return}h(N);const v=_.getFunctionInfo(s[N].name);if(!v){u(null);return}u(v),t(v)};function k(N){g(N);const v=_.getSearchListByType(+N);i(v)}function L(N){r(N);const v=_.getSearchListByName(N);i(v)}function x(N){if(N.stopPropagation(),N.key==="ArrowDown"){const v=c+1;f(v===s.length?0:v)}else if(N.key==="ArrowUp"){const v=c-1;f(v===-1?s.length-1:v)}else N.key==="Enter"&&$(c)}const M=N=>{f(N)},A=()=>{f(-1)};return C.jsxs("div",{children:[C.jsxs("div",{className:ye.formulaSelectFunctionSelect,children:[C.jsx(le.Select,{value:m,options:b,onChange:k}),C.jsx(le.Input,{placeholder:I.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:x,value:o,onChange:L,size:"large",allowClear:!0})]}),C.jsx("ul",{className:ye.formulaSelectFunctionResult,onKeyDown:x,tabIndex:-1,children:s.map(({name:N},v)=>C.jsxs("li",{className:c===v?`
23
+ `,children:o}),C.jsx("div",{className:ft.formulaFunctionParamsDetail,children:n})]})}const ts="univer-formula-input-params-list",ns="univer-formula-input-params-list-item-name",os="univer-formula-input-params-list-item-selector",qe={formulaInputParamsList:ts,formulaInputParamsListItemName:ns,formulaInputParamsListItemSelector:os};function rs(e){const{functionInfo:t,onChange:n}=e;if(!t)return null;const[o,r]=d.useState([]),[s,i]=d.useState(t.functionParameter),[c,u]=d.useState(-1);return C.jsxs("div",{className:qe.formulaInputParams,children:[C.jsx("div",{className:qe.formulaInputParamsList,children:s.map((m,g)=>C.jsxs("div",{children:[C.jsx("div",{className:qe.formulaInputParamsListItemName,children:m.name}),C.jsx("div",{className:qe.formulaInputParamsListItemSelector})]},g))}),C.jsx("div",{className:qe.formulaInputParamsInfo,children:C.jsx(Ye,{title:c===-1?C.jsx(gn,{prefix:t.functionName,value:s}):s[c].name,value:c===-1?t.description:s[c].detail})})]})}const ss="univer-formula-select-function-select",is="univer-formula-select-function-result",cs="univer-formula-select-function-result-item",as="univer-formula-select-function-result-item-name-light",ls="univer-formula-select-function-result-item-selected",us="univer-formula-select-function-result-item-active",fs="univer-formula-select-function-content",ye={formulaSelectFunctionSelect:ss,formulaSelectFunctionResult:is,formulaSelectFunctionResultItem:cs,formulaSelectFunctionResultItemNameLight:as,formulaSelectFunctionResultItemSelected:ls,formulaSelectFunctionResultItemActive:us,formulaSelectFunctionContent:fs};function ds(e){const{onChange:t}=e,n="-1",[o,r]=d.useState(""),[s,i]=d.useState([]),[c,u]=d.useState(0),[m,g]=d.useState(n),[S,h]=d.useState(0),[p,f]=d.useState(null),_=a.useDependency(xe.IDescriptionService),E=a.useDependency(l.LocaleService),I=a.useDependency(a.ISidebarService),R=a.useObservable(I.sidebarOptions$),T=ho(x.FunctionType,E);T.unshift({label:E.t("formula.moreFunctions.allFunctions"),value:n});const N=E.t("formula.prompt.required"),D=E.t("formula.prompt.optional");d.useEffect(()=>{P(n)},[]),d.useEffect(()=>{$(0)},[s]),d.useEffect(()=>{R!=null&&R.visible&&(r(""),i([]),u(0),g(n),h(0),f(null),P(n))},[R]);const O=F=>{if(o.trim()==="")return F;const v=new RegExp(`(${o.toLocaleUpperCase()})`);return F.split(v).filter(Boolean).map((k,j)=>k.match(v)?C.jsx("span",{className:ye.formulaSelectFunctionResultItemNameLight,children:k},j):k)},$=F=>{if(s.length===0){f(null);return}h(F);const v=_.getFunctionInfo(s[F].name);if(!v){f(null);return}f(v),t(v)};function P(F){g(F);const v=_.getSearchListByType(+F);i(v)}function L(F){r(F);const v=_.getSearchListByName(F);i(v)}function M(F){if(F.stopPropagation(),F.key==="ArrowDown"){const v=c+1;u(v===s.length?0:v)}else if(F.key==="ArrowUp"){const v=c-1;u(v===-1?s.length-1:v)}else F.key==="Enter"&&$(c)}const b=F=>{u(F)},A=()=>{u(-1)};return C.jsxs("div",{children:[C.jsxs("div",{className:ye.formulaSelectFunctionSelect,children:[C.jsx(de.Select,{value:m,options:T,onChange:P}),C.jsx(de.Input,{placeholder:E.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:M,value:o,onChange:L,size:"large",allowClear:!0})]}),C.jsx("ul",{className:ye.formulaSelectFunctionResult,onKeyDown:M,tabIndex:-1,children:s.map(({name:F},v)=>C.jsxs("li",{className:c===v?`
24
24
  ${ye.formulaSelectFunctionResultItem}
25
25
  ${ye.formulaSelectFunctionResultItemActive}
26
- `:ye.formulaSelectFunctionResultItem,onMouseEnter:()=>M(v),onMouseLeave:A,onClick:()=>$(v),children:[S===v&&C.jsx(qt,{className:ye.formulaSelectFunctionResultItemSelected}),C.jsx("span",{className:ye.formulaSelectFunctionResultItemName,children:F(N)})]},v))}),p&&C.jsxs("div",{className:ye.formulaSelectFunctionContent,children:[C.jsx(qe,{title:p.functionName,value:p.description}),C.jsx(qe,{title:I.t("formula.moreFunctions.syntax"),value:C.jsx(gn,{prefix:p.functionName,value:p.functionParameter})}),C.jsx(qe,{title:I.t("formula.prompt.helpExample"),value:`${p.functionName}(${p.functionParameter.map(N=>N.example).join(",")})`}),p.functionParameter&&p.functionParameter.map((N,v)=>C.jsx(qe,{title:N.name,value:`${N.require?T:O} ${N.detail}`},v))]})]})}function hs(){const e=w.useActiveWorkbook(),[t,n]=d.useState(!0),[o,r]=d.useState(!1),[s,i]=d.useState(null);a.useDependency(w.IEditorBridgeService);const c=a.useDependency(l.LocaleService),f=a.useDependency(X.IEditorService),m=a.useDependency(l.IUniverInstanceService),g=a.useDependency(l.ICommandService);function S(){n(!t),r(!o)}function h(){const p=H.getSheetCommandTarget(m);if(!p)return;g.executeCommand(w.SetCellEditVisibleOperation.id,{visible:!0,unitId:p.unitId,eventType:K.DeviceInputEventType.Dblclick});const u=f.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),_=f.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),I=`=${s==null?void 0:s.functionName}(`;u==null||u.replaceText(I),_==null||_.replaceText(I,!1)}return C.jsxs("div",{className:$t.formulaMoreFunctions,children:[t&&C.jsx(ds,{onChange:i}),o&&C.jsx(rs,{functionInfo:s,onChange:()=>{}}),C.jsxs("div",{className:$t.formulaMoreFunctionsOperation,children:[o&&C.jsx(le.Button,{type:"primary",size:"small",onClick:S,children:c.t("formula.moreFunctions.next")}),o&&C.jsx(le.Button,{size:"small",onClick:S,children:c.t("formula.moreFunctions.prev")}),t&&!!e&&C.jsx(le.Button,{type:"primary",size:"small",onClick:h,children:c.t("formula.moreFunctions.confirm")})]})]})}function ms(e){return{id:ot.id,icon:"FunctionSingle",tooltip:"formula.insert.tooltip",type:a.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$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:w.getCurrentRangeDisable$(e,{workbookTypes:[H.WorkbookEditablePermission],worksheetTypes:[H.WorksheetEditPermission,H.WorksheetSetCellValuePermission],rangeTypes:[H.RangeProtectionPermissionEditPoint]})}}function gs(e){return{id:rt.id,title:"formula.insert.more",type:a.MenuItemType.BUTTON}}function ps(e){return e.get(l.IUniverInstanceService).getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(V.switchMap(o=>o&&e.get(a.IClipboardInterfaceService)?new V.Observable(s=>s.next(!e.get(a.IClipboardInterfaceService).supportClipboard)):V.of(!0)))}function Ss(e){return{id:nt.id,type:a.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:ps(e).pipe(V.combineLatestWith(w.getCurrentRangeDisable$(e,{workbookTypes:[H.WorkbookEditablePermission],rangeTypes:[H.RangeProtectionPermissionEditPoint],worksheetTypes:[H.WorksheetSetCellValuePermission,H.WorksheetEditPermission]})),V.map(([t,n])=>t||n))}}const vs={[a.RibbonStartGroup.FORMULAS_INSERT]:{[ot.id]:{order:1,menuItemFactory:ms,[rt.id]:{order:1,menuItemFactory:gs}}},[w.PASTE_SPECIAL_MENU_ID]:{[nt.id]:{order:4,menuItemFactory:Ss}}},Cs="meta_key_ctrl_And_Shift",ct=[a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP,a.KeyCode.ARROW_LEFT,a.KeyCode.ARROW_RIGHT],Is=[...ct,a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ESC];function Rs(){const e=[];for(const t of Is)e.push({id:ke.id,binding:t,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keycode:t}});return e}function Es(){const e=[];for(const t of ct)e.push({id:ke.id,binding:t|a.MetaKeys.SHIFT,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.SHIFT}});return e}function _s(){const e=[];for(const t of ct)e.push({id:ke.id,binding:t|a.MetaKeys.CTRL_COMMAND,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.CTRL_COMMAND}});return e}function ys(){const e=[];for(const t of ct)e.push({id:ke.id,binding:t|a.MetaKeys.SHIFT|a.MetaKeys.CTRL_COMMAND,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keycode:t,metaKey:Cs}});return e}const Ts={id:vt.id,binding:a.KeyCode.F4,preconditions:e=>w.whenFormulaEditorActivated(e)};function bs(){const e=[];for(const t of[a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP])e.push({id:ke.id,binding:t,preconditions:n=>tr(n),staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}var Ms=Object.getOwnPropertyDescriptor,xs=(e,t,n,o)=>{for(var r=o>1?void 0:o?Ms(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Pe=(e,t)=>(n,o)=>t(n,o,e);let tt=class extends l.Disposable{constructor(e,t,n,o,r,s,i){super(),this._injector=e,this._menuManagerService=t,this._commandService=n,this._shortcutService=o,this._uiPartsService=r,this._renderManagerService=s,this._componentManager=i,this._initialize()}_initialize(){this._registerCommands(),this._registerMenus(),this._registerShortcuts(),this._registerComponents(),this._registerRenderModules()}_registerMenus(){this._menuManagerService.mergeMenu(vs)}_registerCommands(){[nt,ot,rt,Vt,Ut,ke,vt].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...Rs(),...Es(),..._s(),...ys(),...bs(),Ts].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(a.BuiltInUIPart.CONTENT,()=>a.connectInjector(Gr,this._injector))),this.disposeWithMe(this._uiPartsService.registerComponent(w.SheetsUIPart.FORMULA_AUX,()=>a.connectInjector(_r,this._injector))),this._componentManager.register(Bt,hs)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,[Qe]))}};tt=xs([Pe(0,l.Inject(l.Injector)),Pe(1,a.IMenuManagerService),Pe(2,l.ICommandService),Pe(3,a.IShortcutService),Pe(4,a.IUIPartsService),Pe(5,K.IRenderManagerService),Pe(6,l.Inject(a.ComponentManager))],tt);var Ns=Object.defineProperty,Fs=Object.getOwnPropertyDescriptor,Os=(e,t,n)=>t in e?Ns(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ds=(e,t,n,o)=>{for(var r=o>1?void 0:o?Fs(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},dt=(e,t)=>(n,o)=>t(n,o,e),pn=(e,t,n)=>Os(e,typeof t!="symbol"?t+"":t,n);exports.UniverSheetsFormulaUIPlugin=class extends l.Plugin{constructor(t=Lt,n,o,r){super(),this._config=t,this._injector=n,this._renderManagerService=o,this._configService=r;const{menu:s,...i}=l.merge(Lt,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(er,i)}onStarting(){const t=this._injector;[[Ge,{useClass:ht}],[tt],[Xe],[Je],[Qe],[et]].forEach(r=>t.add(r));const o=this._injector.get(a.ComponentManager);o.register(w.RANGE_SELECTOR_COMPONENT_KEY,ln),o.register(w.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,dn)}onRendered(){[[exports.RefSelectionsRenderService],[pt]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))}),l.touchDependencies(this._injector,[[tt],[Je],[et]])}onSteady(){this._injector.get(Xe)}};pn(exports.UniverSheetsFormulaUIPlugin,"pluginName",Wt);pn(exports.UniverSheetsFormulaUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFormulaUIPlugin=Ds([l.DependentOn(D.UniverFormulaEnginePlugin,Ne.UniverSheetsFormulaPlugin),dt(1,l.Inject(l.Injector)),dt(2,K.IRenderManagerService),dt(3,l.IConfigService)],exports.UniverSheetsFormulaUIPlugin);exports.FORMULA_PROMPT_ACTIVATED=Ht;exports.FormulaEditor=dn;exports.HelpFunctionOperation=Ut;exports.InsertFunctionOperation=ot;exports.MoreFunctionsOperation=rt;exports.RangeSelector=ln;exports.ReferenceAbsoluteOperation=vt;exports.SearchFunctionOperation=Vt;exports.SelectEditorFormulaOperation=ke;exports.SheetOnlyPasteFormulaCommand=nt;
26
+ `:ye.formulaSelectFunctionResultItem,onMouseEnter:()=>b(v),onMouseLeave:A,onClick:()=>$(v),children:[S===v&&C.jsx(qt,{className:ye.formulaSelectFunctionResultItemSelected}),C.jsx("span",{className:ye.formulaSelectFunctionResultItemName,children:O(F)})]},v))}),p&&C.jsxs("div",{className:ye.formulaSelectFunctionContent,children:[C.jsx(Ye,{title:p.functionName,value:p.description}),C.jsx(Ye,{title:E.t("formula.moreFunctions.syntax"),value:C.jsx(gn,{prefix:p.functionName,value:p.functionParameter})}),C.jsx(Ye,{title:E.t("formula.prompt.helpExample"),value:`${p.functionName}(${p.functionParameter.map(F=>F.example).join(",")})`}),p.functionParameter&&p.functionParameter.map((F,v)=>C.jsx(Ye,{title:F.name,value:`${F.require?N:D} ${F.detail}`},v))]})]})}function hs(){const e=w.useActiveWorkbook(),[t,n]=d.useState(!0),[o,r]=d.useState(!1),[s,i]=d.useState(null);a.useDependency(w.IEditorBridgeService);const c=a.useDependency(l.LocaleService),u=a.useDependency(J.IEditorService),m=a.useDependency(l.IUniverInstanceService),g=a.useDependency(l.ICommandService);function S(){n(!t),r(!o)}function h(){const p=H.getSheetCommandTarget(m);if(!p)return;g.executeCommand(w.SetCellEditVisibleOperation.id,{visible:!0,unitId:p.unitId,eventType:K.DeviceInputEventType.Dblclick});const f=u.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),_=u.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),E=`=${s==null?void 0:s.functionName}(`;f==null||f.replaceText(E),_==null||_.replaceText(E,!1)}return C.jsxs("div",{className:$t.formulaMoreFunctions,children:[t&&C.jsx(ds,{onChange:i}),o&&C.jsx(rs,{functionInfo:s,onChange:()=>{}}),C.jsxs("div",{className:$t.formulaMoreFunctionsOperation,children:[o&&C.jsx(de.Button,{type:"primary",size:"small",onClick:S,children:c.t("formula.moreFunctions.next")}),o&&C.jsx(de.Button,{size:"small",onClick:S,children:c.t("formula.moreFunctions.prev")}),t&&!!e&&C.jsx(de.Button,{type:"primary",size:"small",onClick:h,children:c.t("formula.moreFunctions.confirm")})]})]})}function ms(e){return{id:ot.id,icon:"FunctionSingle",tooltip:"formula.insert.tooltip",type:a.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$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:w.getCurrentRangeDisable$(e,{workbookTypes:[H.WorkbookEditablePermission],worksheetTypes:[H.WorksheetEditPermission,H.WorksheetSetCellValuePermission],rangeTypes:[H.RangeProtectionPermissionEditPoint]})}}function gs(e){return{id:rt.id,title:"formula.insert.more",type:a.MenuItemType.BUTTON}}function ps(e){return e.get(l.IUniverInstanceService).getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(q.switchMap(o=>o&&e.get(a.IClipboardInterfaceService)?new q.Observable(s=>s.next(!e.get(a.IClipboardInterfaceService).supportClipboard)):q.of(!0)))}function Ss(e){return{id:nt.id,type:a.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:ps(e).pipe(q.combineLatestWith(w.getCurrentRangeDisable$(e,{workbookTypes:[H.WorkbookEditablePermission],rangeTypes:[H.RangeProtectionPermissionEditPoint],worksheetTypes:[H.WorksheetSetCellValuePermission,H.WorksheetEditPermission]})),q.map(([t,n])=>t||n))}}const vs={[a.RibbonStartGroup.FORMULAS_INSERT]:{[ot.id]:{order:1,menuItemFactory:ms,[rt.id]:{order:1,menuItemFactory:gs}}},[w.PASTE_SPECIAL_MENU_ID]:{[nt.id]:{order:4,menuItemFactory:Ss}}},Cs="meta_key_ctrl_And_Shift",ct=[a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP,a.KeyCode.ARROW_LEFT,a.KeyCode.ARROW_RIGHT],Es=[...ct,a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ESC];function Rs(){const e=[];for(const t of Es)e.push({id:we.id,binding:t,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keycode:t}});return e}function Is(){const e=[];for(const t of ct)e.push({id:we.id,binding:t|a.MetaKeys.SHIFT,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.SHIFT}});return e}function _s(){const e=[];for(const t of ct)e.push({id:we.id,binding:t|a.MetaKeys.CTRL_COMMAND,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.CTRL_COMMAND}});return e}function ys(){const e=[];for(const t of ct)e.push({id:we.id,binding:t|a.MetaKeys.SHIFT|a.MetaKeys.CTRL_COMMAND,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keycode:t,metaKey:Cs}});return e}const Ts={id:vt.id,binding:a.KeyCode.F4,preconditions:e=>w.whenFormulaEditorActivated(e)};function bs(){const e=[];for(const t of[a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP])e.push({id:we.id,binding:t,preconditions:n=>tr(n),staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}var Ms=Object.getOwnPropertyDescriptor,Ns=(e,t,n,o)=>{for(var r=o>1?void 0:o?Ms(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},Le=(e,t)=>(n,o)=>t(n,o,e);let tt=class extends l.Disposable{constructor(e,t,n,o,r,s,i){super(),this._injector=e,this._menuManagerService=t,this._commandService=n,this._shortcutService=o,this._uiPartsService=r,this._renderManagerService=s,this._componentManager=i,this._initialize()}_initialize(){this._registerCommands(),this._registerMenus(),this._registerShortcuts(),this._registerComponents(),this._registerRenderModules()}_registerMenus(){this._menuManagerService.mergeMenu(vs)}_registerCommands(){[nt,ot,rt,Vt,Ut,we,vt].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...Rs(),...Is(),..._s(),...ys(),...bs(),Ts].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(a.BuiltInUIPart.CONTENT,()=>a.connectInjector(Gr,this._injector))),this.disposeWithMe(this._uiPartsService.registerComponent(w.SheetsUIPart.FORMULA_AUX,()=>a.connectInjector(_r,this._injector))),this._componentManager.register(Bt,hs)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,[Qe]))}};tt=Ns([Le(0,l.Inject(l.Injector)),Le(1,a.IMenuManagerService),Le(2,l.ICommandService),Le(3,a.IShortcutService),Le(4,a.IUIPartsService),Le(5,K.IRenderManagerService),Le(6,l.Inject(a.ComponentManager))],tt);var Fs=Object.defineProperty,xs=Object.getOwnPropertyDescriptor,Os=(e,t,n)=>t in e?Fs(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ds=(e,t,n,o)=>{for(var r=o>1?void 0:o?xs(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(r=i(r)||r);return r},dt=(e,t)=>(n,o)=>t(n,o,e),pn=(e,t,n)=>Os(e,typeof t!="symbol"?t+"":t,n);exports.UniverSheetsFormulaUIPlugin=class extends l.Plugin{constructor(t=Lt,n,o,r){super(),this._config=t,this._injector=n,this._renderManagerService=o,this._configService=r;const{menu:s,...i}=l.merge(Lt,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(er,i)}onStarting(){const t=this._injector;[[Ge,{useClass:ht}],[tt],[Xe],[Je],[Qe],[et]].forEach(r=>t.add(r));const o=this._injector.get(a.ComponentManager);o.register(w.RANGE_SELECTOR_COMPONENT_KEY,ln),o.register(w.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,dn)}onRendered(){[[exports.RefSelectionsRenderService],[pt]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))}),l.touchDependencies(this._injector,[[tt],[Je],[et]])}onSteady(){this._injector.get(Xe)}};pn(exports.UniverSheetsFormulaUIPlugin,"pluginName",Wt);pn(exports.UniverSheetsFormulaUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFormulaUIPlugin=Ds([l.DependentOn(x.UniverFormulaEnginePlugin,xe.UniverSheetsFormulaPlugin),dt(1,l.Inject(l.Injector)),dt(2,K.IRenderManagerService),dt(3,l.IConfigService)],exports.UniverSheetsFormulaUIPlugin);exports.FORMULA_PROMPT_ACTIVATED=Ht;exports.FormulaEditor=dn;exports.HelpFunctionOperation=Ut;exports.InsertFunctionOperation=ot;exports.MoreFunctionsOperation=rt;exports.RangeSelector=ln;exports.ReferenceAbsoluteOperation=vt;exports.SearchFunctionOperation=Vt;exports.SelectEditorFormulaOperation=we;exports.SheetOnlyPasteFormulaCommand=nt;