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