@univerjs/sheets-formula-ui 0.8.1 → 0.8.2-nightly.202506201607

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