@univerjs/sheets-formula-ui 0.6.10-nightly.202504121606 → 0.6.10-nightly.202504141607

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