@univerjs/sheets-formula-ui 0.6.6 → 0.6.7

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