@univerjs/sheets-formula-ui 0.7.0-beta.0 → 0.7.0-nightly.202504301607
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 +8 -11
- package/lib/es/index.js +338 -341
- package/lib/index.css +1 -1
- package/lib/index.js +338 -341
- package/lib/umd/index.js +8 -11
- package/package.json +13 -14
- package/LICENSE +0 -176
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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,A,T,j,Z,H,B,me,l,I,re,m,lt,jt){"use strict";var Xr=Object.defineProperty;var Jr=($,a,A)=>a in $?Xr($,a,{enumerable:!0,configurable:!0,writable:!0,value:A}):$[a]=A;var q=($,a,A)=>Jr($,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){q(this,"_search$",new j.Subject);q(this,"_help$",new j.Subject);q(this,"_navigate$",new j.Subject);q(this,"_accept$",new j.Subject);q(this,"_acceptFormulaName$",new j.Subject);q(this,"search$",this._search$.asObservable());q(this,"help$",this._help$.asObservable());q(this,"navigate$",this._navigate$.asObservable());q(this,"accept$",this._accept$.asObservable());q(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());q(this,"_searching",!1);q(this,"_helping",!1);q(this,"_sequenceNodes",[]);q(this,"_isLockedOnSelectionChangeRefString",!1);q(this,"_isLockedOnSelectionInsertRefString",!1);this._contextService=e}dispose(){this._search$.complete(),this._help$.complete(),this._navigate$.complete(),this._accept$.complete(),this._acceptFormulaName$.complete(),this._sequenceNodes=[]}search(e){this._contextService.setContextValue(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)},$e={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(Z.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:v}=t,S=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 L=ft(h,O,k);L&&(C=T.serializeRange(L))}else r.some(y=>{var k,L;const{range:b,primary:O}=y;if(ht(h,b)){const F=(k=O==null?void 0:O.actualRow)!=null?k:b.startRow,w=(L=O==null?void 0:O.actualColumn)!=null?L:b.startColumn,W=ft(h,F,w);if(!W)return u=b,_=F,p=w,!0;const x=T.serializeRange(W),N=`=${v}(${x})`;f.push({range:b,primary:{row:F,column:w},formula:N})}else{const{startRow:F,startColumn:w,endRow:W,endColumn:x}=b;if(F===W){const N=Qt(h,F,x,i.getColumnCount()-1),M=N===x?x-1:x,D=T.serializeRange({startRow:F,endRow:W,startColumn:w,endColumn:M}),P=`=${v}(${D})`;g.push({range:b,primary:{row:F,column:N},formula:P})}else{let N=-1;for(let D=w;D<=x;D++){const P=en(h,D,W,i.getRowCount()-1);N=Math.max(N,P)}const M=N===W?W-1:W;for(let D=w;D<=x;D++){const P=T.serializeRange({startRow:F,endRow:M,startColumn:D,endColumn:D}),V=`=${v}(${P})`;g.push({range:b,primary:{row:N,column:D},formula:V})}}}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 S.executeCommand(B.SetSelectionsOperation.id,O);const k=s.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),L=s.getEditor(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);S.syncExecuteCommand(A.SetCellEditVisibleOperation.id,{visible:!0,unitId:c,eventType:H.DeviceInputEventType.Dblclick});const F=`=${v}(${C}`;k==null||k.replaceText(F),L==null||L.replaceText(F,!1)}return f.length===0&&g.length===0?!1:S.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",vt=`${gt}_MORE_FUNCTIONS_COMPONENT`,Fe={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:vt}}),!0)},Qe={id:"formula-ui.operation.change-ref-to-absolute",type:a.CommandType.OPERATION,handler:async e=>!0},St={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(Z.IEditorService),r=m.useMemo(()=>new j.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:v=0,marginBottom:S=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;_=_+v,C=g?_+g:C-S;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(j.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,v]=m.useState(!0),S=Ee(h),f=m.useRef(t);f.current=t;const g=()=>{i(void 0),d(-1),v(!1)};return m.useEffect(()=>{if(n&&e){const u=n.selectionChange$.pipe(j.debounceTime(50)).subscribe(p=>{if(p.textRanges.length===1){const[C]=p.textRanges;if(C.collapsed&&S.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(j.filter(p=>p.isEditing),j.filter(p=>p.textRanges.length===1),j.map(p=>p.textRanges[0].startOffset),j.distinctUntilChanged()).subscribe(()=>{v(!0)});return()=>{u.unsubscribe(),_.unsubscribe()}}},[n,e]),m.useEffect(()=>{e||g()},[e]),{functionInfo:o,paramIndex:c,reset:g}},vn=({onClick:e})=>I.jsx("div",{className:`
|
|
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,A,T,j,Z,H,B,me,l,I,ee,m,lt,jt){"use strict";var Xr=Object.defineProperty;var Jr=($,a,A)=>a in $?Xr($,a,{enumerable:!0,configurable:!0,writable:!0,value:A}):$[a]=A;var q=($,a,A)=>Jr($,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){q(this,"_search$",new j.Subject);q(this,"_help$",new j.Subject);q(this,"_navigate$",new j.Subject);q(this,"_accept$",new j.Subject);q(this,"_acceptFormulaName$",new j.Subject);q(this,"search$",this._search$.asObservable());q(this,"help$",this._help$.asObservable());q(this,"navigate$",this._navigate$.asObservable());q(this,"accept$",this._accept$.asObservable());q(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());q(this,"_searching",!1);q(this,"_helping",!1);q(this,"_sequenceNodes",[]);q(this,"_isLockedOnSelectionChangeRefString",!1);q(this,"_isLockedOnSelectionInsertRefString",!1);this._contextService=e}dispose(){this._search$.complete(),this._help$.complete(),this._navigate$.complete(),this._accept$.complete(),this._acceptFormulaName$.complete(),this._sequenceNodes=[]}search(e){this._contextService.setContextValue(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)},$e={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(Z.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:v}=t,S=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 L=ft(h,O,k);L&&(C=T.serializeRange(L))}else r.some(y=>{var k,L;const{range:b,primary:O}=y;if(ht(h,b)){const F=(k=O==null?void 0:O.actualRow)!=null?k:b.startRow,w=(L=O==null?void 0:O.actualColumn)!=null?L:b.startColumn,W=ft(h,F,w);if(!W)return u=b,_=F,p=w,!0;const x=T.serializeRange(W),N=`=${v}(${x})`;f.push({range:b,primary:{row:F,column:w},formula:N})}else{const{startRow:F,startColumn:w,endRow:W,endColumn:x}=b;if(F===W){const N=Qt(h,F,x,i.getColumnCount()-1),M=N===x?x-1:x,D=T.serializeRange({startRow:F,endRow:W,startColumn:w,endColumn:M}),P=`=${v}(${D})`;g.push({range:b,primary:{row:F,column:N},formula:P})}else{let N=-1;for(let D=w;D<=x;D++){const P=en(h,D,W,i.getRowCount()-1);N=Math.max(N,P)}const M=N===W?W-1:W;for(let D=w;D<=x;D++){const P=T.serializeRange({startRow:F,endRow:M,startColumn:D,endColumn:D}),V=`=${v}(${P})`;g.push({range:b,primary:{row:N,column:D},formula:V})}}}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 S.executeCommand(B.SetSelectionsOperation.id,O);const k=s.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),L=s.getEditor(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);S.syncExecuteCommand(A.SetCellEditVisibleOperation.id,{visible:!0,unitId:c,eventType:H.DeviceInputEventType.Dblclick});const F=`=${v}(${C}`;k==null||k.replaceText(F),L==null||L.replaceText(F,!1)}return f.length===0&&g.length===0?!1:S.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",vt=`${gt}_MORE_FUNCTIONS_COMPONENT`,Fe={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:vt}}),!0)},Qe={id:"formula-ui.operation.change-ref-to-absolute",type:a.CommandType.OPERATION,handler:async e=>!0},St={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(Z.IEditorService),r=m.useMemo(()=>new j.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:v=0,marginBottom:S=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;_=_+v,C=g?_+g:C-S;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(j.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,v]=m.useState(!0),S=Ee(h),f=m.useRef(t);f.current=t;const g=()=>{i(void 0),d(-1),v(!1)};return m.useEffect(()=>{if(n&&e){const u=n.selectionChange$.pipe(j.debounceTime(50)).subscribe(p=>{if(p.textRanges.length===1){const[C]=p.textRanges;if(C.collapsed&&S.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(j.filter(p=>p.isEditing),j.filter(p=>p.textRanges.length===1),j.map(p=>p.textRanges[0].startOffset),j.distinctUntilChanged()).subscribe(()=>{v(!0)});return()=>{u.unsubscribe(),_.unsubscribe()}}},[n,e]),m.useEffect(()=>{e||g()},[e]),{functionInfo:o,paramIndex:c,reset:g}},vn=({onClick:e})=>I.jsx("div",{className:`
|
|
2
2
|
univer-z-[15] univer-box-border univer-h-[18px] univer-cursor-pointer univer-overflow-visible
|
|
3
3
|
univer-whitespace-nowrap univer-rounded-l univer-border univer-border-r-0 univer-border-[#5790f6]
|
|
4
4
|
univer-bg-[#1a73e8] univer-p-0.5 univer-text-[11px] univer-font-bold univer-leading-[13px]
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
univer-box-border univer-max-h-[350px] univer-overflow-y-auto univer-px-4 univer-pb-3
|
|
33
33
|
univer-pt-0
|
|
34
34
|
`,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(Z.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
|
|
35
|
-
`,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);$.RefSelectionsRenderService=class extends A.BaseSelectionRenderService{constructor(n,s,r,o,i,c,d){super(s,r,o,i,c);q(this,"_workbookSelections");q(this,"_eventDisposables");this._context=n,this._contextService=c,this._refSelectionsService=d,this._workbookSelections=this._refSelectionsService.getWorkbookSelections(this._context.unitId),this._initSelectionChangeListener(),this._initSkeletonChangeListener(),this._initUserActionSyncListener(),this._setSelectionStyle(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,v)=>{this.inRefSelectionMode()&&(this._onPointerDown(h,o.zIndex+1,a.RANGE_TYPE.NORMAL,this._getActiveViewport(h)),h.button!==2&&v.stopPropagation())})),d.add(s==null?void 0:s.onPointerDown$.subscribeEvent((h,v)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:f}=A.getCoordByOffset(h.offsetX,h.offsetY,c,S);A.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),f,a.RANGE_TYPE.ROW)||(this._onPointerDown(h,(o.zIndex||1)+1,a.RANGE_TYPE.ROW,this._getActiveViewport(h),H.ScrollTimerType.Y),h.button!==2&&v.stopPropagation())})),d.add(r==null?void 0:r.onPointerDown$.subscribeEvent((h,v)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:f}=A.getCoordByOffset(h.offsetX,h.offsetY,c,S);A.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),f,a.RANGE_TYPE.COLUMN)||(this._onPointerDown(h,(o.zIndex||1)+1,a.RANGE_TYPE.COLUMN,this._getActiveViewport(h),H.ScrollTimerType.X),h.button!==2&&v.stopPropagation())})),d.add(i==null?void 0:i.onPointerDown$.subscribeEvent((h,v)=>{if(this._reset(),!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,f=A.getAllSelection(S);this._addSelectionControlByModelData(f),this._selectionMoveStart$.next(this.getSelectionDataWithStyle());const g=c.onPointerUp$.subscribeEvent(()=>{g.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});h.button!==2&&v.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(H.SHEET_VIEWPORT_KEY.VIEW_MAIN);this._skeleton&&this._skeleton.worksheet.getSheetId()!==s.worksheet.getSheetId()&&this._reset(),this._changeRuntime(s,r,o);const i=this._workbookSelections.getCurrentSelections();this.resetSelectionsByModelData(i)}))}_getActiveViewport(n){const s=this._getSheetObject();return s==null?void 0:s.scene.getActiveViewportByCoord(H.Vector2.FromArray([n.offsetX,n.offsetY]))}_getSheetObject(){return A.getSheetObject(this._context.unit,this._context)}_onPointerDown(n,s=0,r=a.RANGE_TYPE.NORMAL,o,i=H.ScrollTimerType.ALL){var W;this._rangeType=r;const c=this._skeleton,d=this._scene;if(!d||!c)return;o&&(this._activeViewport=o);const{offsetX:h,offsetY:v}=n,S=d.getViewport(H.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!S)return;const f=d.getCoordRelativeToViewport(H.Vector2.FromArray([h,v])),{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 L=O==null?void 0:O.model.currentCell,F=n.shiftKey&&L,w=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;F&&L?this._makeSelectionByTwoCells(L,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(),(W=d.getTransformer())==null||W.clearSelectedObjects(),this._setupPointerMoveListener(S,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}},$.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)],$.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(H.IRenderManagerService),c=l.useDependency(a.IUniverInstanceService),d=i.getRenderById(r),h=i.getRenderById(t),v=h==null?void 0:h.with(Z.DocSelectionRenderService),S=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($.RefSelectionsRenderService),E=Ee(g),R=c.getUnit(r,a.UniverInstanceType.UNIVER_SHEET),y=R==null?void 0:R.getSheetBySheetId(o),b=l.useEvent(L=>{C&&C.setSkipLastEnabled(L===1||L===3),E.current=L,u(L)}),O=l.useEvent(()=>{var K,ne;if(!R)return;const L=R.getActiveSheet(),F=v==null?void 0:v.getActiveTextRange(),w=F!=null&&F.collapsed?F.startOffset:-1,W=yn(f);if(!W)return;const x=(K=W==null?void 0:W.dataStream)==null?void 0:K.slice(0,-2),N=((ne=_.sequenceNodesBuilder(x))!=null?ne:[]).map(Y=>typeof Y=="object"?Y.nodeType===T.sequenceNodeType.REFERENCE?{...Y,range:T.deserializeRangeWithSheetWithCache(Y.token)}:{...Y,range:void 0}:Y),M=x[w-1],D=x[w],P=N.find(Y=>typeof Y=="object"&&Y.nodeType===T.sequenceNodeType.REFERENCE&&w===Y.endIndex+2),V=M&&T.matchRefDrawToken(M)&&(!D||T.isFormulaLexerToken(D)&&D!==T.matchToken.OPEN_BRACKET),U=!!P;if((x==null?void 0:x.substring(0,1))==="="&&(V||U))if(U){if(p.current)return;!P.range.sheetName&&L.getSheetId()===(y==null?void 0:y.getSheetId())||P.range.sheetName===L.getName()?b(2):b(3)}else p.current=!1,b(1);else b(0)});return m.useEffect(()=>{const L=S.textSelection$.pipe(j.filter(F=>F.unitId===t)).subscribe(()=>{O()});return()=>L.unsubscribe()},[O,S.textSelection$,t]),m.useEffect(()=>{n||(b(0),p.current=!0)},[n,b]),m.useEffect(()=>{var F;if(!s)return;const L=(F=h==null?void 0:h.mainComponent)==null?void 0:F.onPointerDown$.subscribeEvent(()=>{b(0),p.current=!0});return()=>L==null?void 0:L.unsubscribe()},[s,(k=h==null?void 0:h.mainComponent)==null?void 0:k.onPointerDown$,b]),m.useEffect(()=>{if(!n)return;const L=R==null?void 0:R.activeSheet$.subscribe(()=>{O()});return()=>L==null?void 0:L.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=e.getCurrentTheme(),r=new a.ColorKit(t).setAlpha(.05).toRgbString();return{id:n,strokeWidth:1,stroke:t,fill:r,widgets:{tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},widgetSize:6,widgetStrokeWidth:1,widgetStroke:s.colorWhite}}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:v}=e,S=s.getUnitId(),f=v.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 L=r[O],{themeColor:F,token:w,refIndex:W,endIndex:x}=L,N=T.deserializeRangeWithSheet(w),{unitId:M,sheetName:D,range:P}=N,V=p(D);if(S!==t&&M!==S||M&&M!==S||V&&V!==_||!V&&_!==n)continue;const U=B.setEndForRange(P,g.getRowCount(),g.getColumnCount());U.unitId=t,U.sheetId=_,u.push({range:U,primary:null,style:bn(h,F,W.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(L=>L+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(H.IRenderManagerService).getRenderById(e),c=i==null?void 0:i.with($.RefSelectionsRenderService),d=i==null?void 0:i.with(A.SheetSkeletonManagerService),h=l.useEvent((v,S)=>{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:v,editor:S,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 v=i.getDocumentData(),S=i.getEditorId();if(!v)return[];const f=v.body;if(!f)return[];const g=f.dataStream.slice(0,f.dataStream.length-2),u={dataStream:"",...v.body};if(!g.startsWith(e))return[];if(c==null||c.length===0)return u.textRuns=[],s.syncExecuteCommand(Z.ReplaceTextRunsCommand.id,{unitId:S,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
|
|
35
|
+
`,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);$.RefSelectionsRenderService=class extends A.BaseSelectionRenderService{constructor(n,s,r,o,i,c,d){super(s,r,o,i,c);q(this,"_workbookSelections");q(this,"_eventDisposables");this._context=n,this._contextService=c,this._refSelectionsService=d,this._workbookSelections=this._refSelectionsService.getWorkbookSelections(this._context.unitId),this._initSelectionChangeListener(),this._initSkeletonChangeListener(),this._initUserActionSyncListener(),this._setSelectionStyle(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,v)=>{this.inRefSelectionMode()&&(this._onPointerDown(h,o.zIndex+1,a.RANGE_TYPE.NORMAL,this._getActiveViewport(h)),h.button!==2&&v.stopPropagation())})),d.add(s==null?void 0:s.onPointerDown$.subscribeEvent((h,v)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:f}=A.getCoordByOffset(h.offsetX,h.offsetY,c,S);A.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),f,a.RANGE_TYPE.ROW)||(this._onPointerDown(h,(o.zIndex||1)+1,a.RANGE_TYPE.ROW,this._getActiveViewport(h),H.ScrollTimerType.Y),h.button!==2&&v.stopPropagation())})),d.add(r==null?void 0:r.onPointerDown$.subscribeEvent((h,v)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:f}=A.getCoordByOffset(h.offsetX,h.offsetY,c,S);A.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),f,a.RANGE_TYPE.COLUMN)||(this._onPointerDown(h,(o.zIndex||1)+1,a.RANGE_TYPE.COLUMN,this._getActiveViewport(h),H.ScrollTimerType.X),h.button!==2&&v.stopPropagation())})),d.add(i==null?void 0:i.onPointerDown$.subscribeEvent((h,v)=>{if(this._reset(),!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,f=A.getAllSelection(S);this._addSelectionControlByModelData(f),this._selectionMoveStart$.next(this.getSelectionDataWithStyle());const g=c.onPointerUp$.subscribeEvent(()=>{g.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});h.button!==2&&v.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(H.SHEET_VIEWPORT_KEY.VIEW_MAIN);this._skeleton&&this._skeleton.worksheet.getSheetId()!==s.worksheet.getSheetId()&&this._reset(),this._changeRuntime(s,r,o);const i=this._workbookSelections.getCurrentSelections();this.resetSelectionsByModelData(i)}))}_getActiveViewport(n){const s=this._getSheetObject();return s==null?void 0:s.scene.getActiveViewportByCoord(H.Vector2.FromArray([n.offsetX,n.offsetY]))}_getSheetObject(){return A.getSheetObject(this._context.unit,this._context)}_onPointerDown(n,s=0,r=a.RANGE_TYPE.NORMAL,o,i=H.ScrollTimerType.ALL){var W;this._rangeType=r;const c=this._skeleton,d=this._scene;if(!d||!c)return;o&&(this._activeViewport=o);const{offsetX:h,offsetY:v}=n,S=d.getViewport(H.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!S)return;const f=d.getCoordRelativeToViewport(H.Vector2.FromArray([h,v])),{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 L=O==null?void 0:O.model.currentCell,F=n.shiftKey&&L,w=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;F&&L?this._makeSelectionByTwoCells(L,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(),(W=d.getTransformer())==null||W.clearSelectedObjects(),this._setupPointerMoveListener(S,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}},$.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)],$.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(H.IRenderManagerService),c=l.useDependency(a.IUniverInstanceService),d=i.getRenderById(r),h=i.getRenderById(t),v=h==null?void 0:h.with(Z.DocSelectionRenderService),S=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($.RefSelectionsRenderService),E=Ee(g),R=c.getUnit(r,a.UniverInstanceType.UNIVER_SHEET),y=R==null?void 0:R.getSheetBySheetId(o),b=l.useEvent(L=>{C&&C.setSkipLastEnabled(L===1||L===3),E.current=L,u(L)}),O=l.useEvent(()=>{var K,re;if(!R)return;const L=R.getActiveSheet(),F=v==null?void 0:v.getActiveTextRange(),w=F!=null&&F.collapsed?F.startOffset:-1,W=yn(f);if(!W)return;const x=(K=W==null?void 0:W.dataStream)==null?void 0:K.slice(0,-2),N=((re=_.sequenceNodesBuilder(x))!=null?re:[]).map(Y=>typeof Y=="object"?Y.nodeType===T.sequenceNodeType.REFERENCE?{...Y,range:T.deserializeRangeWithSheetWithCache(Y.token)}:{...Y,range:void 0}:Y),M=x[w-1],D=x[w],P=N.find(Y=>typeof Y=="object"&&Y.nodeType===T.sequenceNodeType.REFERENCE&&w===Y.endIndex+2),V=M&&T.matchRefDrawToken(M)&&(!D||T.isFormulaLexerToken(D)&&D!==T.matchToken.OPEN_BRACKET),U=!!P;if((x==null?void 0:x.substring(0,1))==="="&&(V||U))if(U){if(p.current)return;!P.range.sheetName&&L.getSheetId()===(y==null?void 0:y.getSheetId())||P.range.sheetName===L.getName()?b(2):b(3)}else p.current=!1,b(1);else b(0)});return m.useEffect(()=>{const L=S.textSelection$.pipe(j.filter(F=>F.unitId===t)).subscribe(()=>{O()});return()=>L.unsubscribe()},[O,S.textSelection$,t]),m.useEffect(()=>{n||(b(0),p.current=!0)},[n,b]),m.useEffect(()=>{var F;if(!s)return;const L=(F=h==null?void 0:h.mainComponent)==null?void 0:F.onPointerDown$.subscribeEvent(()=>{b(0),p.current=!0});return()=>L==null?void 0:L.unsubscribe()},[s,(k=h==null?void 0:h.mainComponent)==null?void 0:k.onPointerDown$,b]),m.useEffect(()=>{if(!n)return;const L=R==null?void 0:R.activeSheet$.subscribe(()=>{O()});return()=>L==null?void 0:L.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=e.getCurrentTheme(),r=new a.ColorKit(t).setAlpha(.05).toRgbString();return{id:n,strokeWidth:1,stroke:t,fill:r,widgets:{tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},widgetSize:6,widgetStrokeWidth:1,widgetStroke:s.colorWhite}}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:v}=e,S=s.getUnitId(),f=v.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 L=r[O],{themeColor:F,token:w,refIndex:W,endIndex:x}=L,N=T.deserializeRangeWithSheet(w),{unitId:M,sheetName:D,range:P}=N,V=p(D);if(S!==t&&M!==S||M&&M!==S||V&&V!==_||!V&&_!==n)continue;const U=B.setEndForRange(P,g.getRowCount(),g.getColumnCount());U.unitId=t,U.sheetId=_,u.push({range:U,primary:null,style:bn(h,F,W.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(L=>L+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(H.IRenderManagerService).getRenderById(e),c=i==null?void 0:i.with($.RefSelectionsRenderService),d=i==null?void 0:i.with(A.SheetSkeletonManagerService),h=l.useEvent((v,S)=>{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:v,editor:S,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 v=i.getDocumentData(),S=i.getEditorId();if(!v)return[];const f=v.body;if(!f)return[];const g=f.dataStream.slice(0,f.dataStream.length-2),u={dataStream:"",...v.body};if(!g.startsWith(e))return[];if(c==null||c.length===0)return u.textRuns=[],s.syncExecuteCommand(Z.ReplaceTextRunsCommand.id,{unitId:S,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
|
|
36
36
|
`;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(Z.ReplaceTextRunsCommand.id,{unitId:S,body:a.getBodySlice(u,0,u.dataStream.length-2),textRanges:h!=null?h:E}),p}})}function Mn(){const t=l.useDependency(a.ThemeService).getCurrentTheme();return m.useMemo(()=>{const s=[t.loopColor1,t.loopColor2,t.loopColor3,t.loopColor4,t.loopColor5,t.loopColor6,t.loopColor7,t.loopColor8,t.loopColor9,t.loopColor10,t.loopColor11,t.loopColor12],r=t.hyacinth700,o=t.verdancy800,i=t.colorBlack;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 v=0;for(let S=0,f=n.length;S<f;S++){const g=n[S];if(typeof g=="string"){const R=c[c.length-1],y=R?R.ed:0,b=y+g.length;c.push({st:y,ed:b,ts:{cl:{rgb:i},fs:11}});continue}if(e.hasDefinedNameDescription(g.token.trim())){c.push({st:g.startIndex,ed:g.endIndex+1,ts:{cl:{rgb:i},fs:11}});continue}const{startIndex:u,endIndex:_,nodeType:p,token:C}=g;let E="";if(p===T.sequenceNodeType.REFERENCE){if(h.has(C))E=h.get(C);else{const R=v%s.length;E=s[R],h.set(C,E),v++}d.push({refIndex:S,themeColor:E,token:C,startIndex:g.startIndex,endIndex:g.endIndex,index:d.length})}else p===T.sequenceNodeType.NUMBER?E=r:(p===T.sequenceNodeType.STRING||p===T.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()}`,v=new a.DisposableCollection,S=(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(Z.MoveSelectionOperation.id,{direction:p}):r.executeCommand(Z.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(A.MoveSelectionCommand.id,{direction:p,jumpOver:A.JumpOver.moveGap,extra:"formula-editor",fromCurrentSelection:i.current===ge.NEED_ADD||i.current===ge.EDIT_OTHER_SHEET_REFERENCE}):_===l.MetaKeys.SHIFT?r.executeCommand(A.ExpandSelectionCommand.id,{direction:p,extra:"formula-editor"}):_===(l.MetaKeys.CTRL_COMMAND|l.MetaKeys.SHIFT)?r.executeCommand(A.ExpandSelectionCommand.id,{direction:p,jumpOver:A.JumpOver.moveGap,extra:"formula-editor"}):r.executeCommand(A.MoveSelectionCommand.id,{direction:p,extra:"formula-editor",fromCurrentSelection:i.current===ge.NEED_ADD||i.current===ge.EDIT_OTHER_SHEET_REFERENCE}):S(u,_)};return v.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:H.DeviceInputEventType.Keyboard,keyCode:u,metaKey:_}})).forEach(u=>{v.add(o.registerShortcut(u))}),()=>{v.dispose()}},[r,n,e,o])},Dn=(e,t,n,s=!0)=>{var f;const r=l.useDependency(H.IRenderManagerService),o=l.useDependency(a.IContextService),i=l.useDependency(l.IContextMenuService),c=l.useDependency(B.IRefSelectionsService),d=l.useDependency(a.IUniverInstanceService),h=l.useObservable(m.useMemo(()=>d.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[d])),v=r.getRenderById((f=h==null?void 0:h.getUnitId())!=null?f:""),S=v==null?void 0:v.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=S==null?void 0:S.enableSelectionChanging();return o.setContextValue(B.REF_SELECTIONS_ENABLED,!0),()=>{o.setContextValue(B.REF_SELECTIONS_ENABLED,!1),g==null||g.dispose()}}},[o,e,S,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&&(S==null||S.setSkipLastEnabled(!1))},[e,S])},xn=(e,t,n)=>{const s=l.useDependency(a.IUniverInstanceService),r=l.useDependency(B.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(""),We=(e,t=!1,n="",s=!1)=>!t&&!s?e.map(r=>T.serializeRange(r.range)):e.map(r=>s?T.serializeRangeToRefString(r):r.sheetName!==""&&r.sheetName!==n?T.serializeRangeWithSheet(r.sheetName,r.range):T.serializeRange(r.range)),wn=e=>{var v,S,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=((S=(v=t==null?void 0:t.getDocumentData().body)==null?void 0:v.dataStream)!=null?S:`\r
|
|
37
|
-
`).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 W;const v=l.useDependency(H.IRenderManagerService),S=l.useDependency(a.IUniverInstanceService),f=l.useDependency(a.ICommandService),g=l.useDependency(lt.DocSelectionManagerService),u=l.useDependency(a.ThemeService),_=l.useDependency(T.LexerTreeBuilder),p=S.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(()=>S.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[S])),O=v.getRenderById((W=b==null?void 0:b.getUnitId())!=null?W:""),k=O==null?void 0:O.with($.RefSelectionsRenderService),L=O==null?void 0:O.with(A.SheetSkeletonManagerService),F=l.useDependency(B.IRefSelectionsService),w=l.useEvent((x,N)=>{var K,
|
|
37
|
+
`).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 W;const v=l.useDependency(H.IRenderManagerService),S=l.useDependency(a.IUniverInstanceService),f=l.useDependency(a.ICommandService),g=l.useDependency(lt.DocSelectionManagerService),u=l.useDependency(a.ThemeService),_=l.useDependency(T.LexerTreeBuilder),p=S.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(()=>S.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[S])),O=v.getRenderById((W=b==null?void 0:b.getUnitId())!=null?W:""),k=O==null?void 0:O.with($.RefSelectionsRenderService),L=O==null?void 0:O.with(A.SheetSkeletonManagerService),F=l.useDependency(B.IRefSelectionsService),w=l.useEvent((x,N)=>{var K,re,Y,ue,Ne,te;const M=wn({editor:d,lexerTreeBuilder:_});if(!M)return;const{nodeIndex:D,updatingRefIndex:P,sequenceNodes:V,offset:U}=M;if(n.current===ge.NEED_ADD)if(U!==0){if(D===-1&&V.length)return;const X=x[x.length-1],J=V.splice(D+1),ce=(K=X.sheetId)!=null?K:r,Q={range:X,unitId:(re=X.unitId)!=null?re:b.getUnitId(),sheetName:C(ce)},ae=ce!==r,oe=(b==null?void 0:b.getUnitId())!==s,De=We([Q],i&&(ae||oe),E,oe);V.push({token:De[0],nodeType:T.sequenceNodeType.REFERENCE});const Re=[...V,...J],ie=nt(Re);h(ie,An(V),N)}else{const X=x[x.length-1],J=(Y=X.sheetId)!=null?Y:r,ce={range:X,unitId:(ue=X.unitId)!=null?ue:s,sheetName:C(J)},ae=We([ce],i&&J!==r);V.unshift({token:ae[0],nodeType:T.sequenceNodeType.REFERENCE});const oe=nt(V);h(oe,ae[0].length,N)}else if(n.current===ge.EDIT_OTHER_SHEET_REFERENCE){const X=x.pop();if(!X)return;const J=V[D];if(typeof J=="object"&&J.nodeType===T.sequenceNodeType.REFERENCE){const ce=J.token;J.token=E===(R==null?void 0:R.getName())?T.serializeRange(X):T.serializeRangeWithSheet(R.getName(),X);const Q=U+(J.token.length-ce.length);h(T.generateStringWithSequence(V),Q,N)}}else{const X=[...x];if(P!==-1){const G=X.pop();G&&X.splice(P,0,G)}let J=0;const ce=V.map(G=>{var le,de,ve;if(typeof G=="string")return G;if(G.nodeType===T.sequenceNodeType.REFERENCE){const be=T.deserializeRangeWithSheet(G.token);if(be.sheetName||(be.sheetName=E),i&&((le=y.current.activeSheet)==null?void 0:le.getName())!==be.sheetName)return G.token;const fe=X[J];if(J++,!fe)return"";const ct=(de=fe.sheetId)!=null?de:r,at={range:fe,unitId:(ve=fe.unitId)!=null?ve:s,sheetName:C(ct)};return We([at],i,E)[0]}return G.token});let Q="",ae;ce.forEach((G,le)=>{Q+=G,le===D&&(ae=Q.length)});const oe=[];for(let G=J;G<=x.length-1;G++){const le=x[G],de=(Ne=le.sheetId)!=null?Ne:r,ve={range:le,unitId:(te=le.unitId)!=null?te:s,sheetName:C(de)},fe=We([ve],i&&de!==r,E);oe.push(fe[0])}const De=V[V.length-1],Re=De&&(typeof De=="string"?!1:De.nodeType===T.sequenceNodeType.REFERENCE),ie=`${Q}${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,P)=>{if(x){x=!1;return}w(D.map(V=>V.rangeWithCoord),P)},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((P,V)=>{x.add(P.selectionScaling$.subscribe(U=>{const K=k.getSelectionDataWithStyle().map(Y=>Y.rangeWithCoord),re=K[V];U.sheetId=re.sheetId,U.unitId=re.unitId,K[V]=U,w(K,!1)})),x.add(P.selectionMoving$.subscribe(U=>{const K=k.getSelectionDataWithStyle().map(Y=>Y.rangeWithCoord),re=K[V];U.sheetId=re.sheetId,U.unitId=re.unitId,K[V]=U,w(K,!0)}))})},M=j.merge(d.input$,F.selectionSet$,k.selectionMoveEnd$).pipe(jt.debounceTime(50)).subscribe(()=>{N()});return()=>{M.unsubscribe(),x.dispose()}}},[d,t,w,k,F.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 P=M.selections[M.selections.length-1];if(P){const V=n.current===ge.NEED_ADD,U=((D=k==null?void 0:k.getSelectionDataWithStyle())!=null?D:[]).map(K=>K.rangeWithCoord);V?U.push(P.range):U[U.length-1]=P.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:F,refSelectionsRenderService:k,sheetSkeletonManagerService:L,themeService:u,univerInstanceService:S,currentWorkbook:b})});return()=>x.unsubscribe()},[g.textSelection$,d,o,k,F,L,r,u,s,S])},Pn=(e,t,n,s,r,o)=>{const i=l.useDependency(a.ICommandService),c=l.useDependency(Z.IEditorService),h=l.useDependency(H.IRenderManagerService).getRenderById(t),v=l.useDependency(a.IUniverInstanceService),S=h==null?void 0:h.with($.RefSelectionsRenderService);m.useEffect(()=>{if(e&&S)if(n){const f=()=>{const _=S.getSelectionControls().length;for(let p=1;p<=_;p++)S.clearLastSelection();return setTimeout(()=>{o()},30)},g=i.onCommandExecuted(_=>{_.id===B.SetWorksheetActiveOperation.id&&f()}),u=v.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,S])},$n=(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])},Fn=(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}),v=()=>{o([]),c(""),d.current=-1};return m.useEffect(()=>{if(n&&e){const f=n.input$.pipe(j.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||v()},[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:v}},Wn=()=>{},Vn=m.forwardRef(Bn);function Bn(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:v,searchText:S,handlerFormulaReplace:f,reset:g}=Fn(n,s,o),u=m.useMemo(()=>!!v.length,[v]),_=m.useRef(void 0),[p,C]=m.useState(0),E=m.useRef(!1),[R]=Tt(c,u,[S,v]),y=Ee({searchList:v,active:p}),b=w=>{const W=f(w);W&&(g(),r(W))};function O(w){E.current&&C(w)}function k(){E.current&&C(-1)}m.useEffect(()=>{if(!v.length)return;const w=`sheet.formula-embedding-editor.search_function.${c}`,W=new a.DisposableCollection,x=N=>{const{searchList:M,active:D}=y.current;switch(N){case l.KeyCode.ARROW_UP:{C(P=>{const V=Math.max(0,P-1);return L(V),V});break}case l.KeyCode.ARROW_DOWN:{C(P=>{const V=Math.min(M.length-1,P+1);return L(V),V});break}case l.KeyCode.TAB:case l.KeyCode.ENTER:{const P=M[D];b(P.name);break}case l.KeyCode.ESC:{g(),i();break}}};return W.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:H.DeviceInputEventType.Keyboard,keyCode:N}})).forEach(N=>{W.add(d.registerShortcut(N))}),()=>{W.dispose()}},[v]);function L(w){const W=_.current;if(!W)return;const x=W.children[w];if(!x)return;const M=W.getBoundingClientRect().top,D=W.offsetHeight,P=x.getBoundingClientRect(),V=P.top,U=P.height;if(V>=0&&V>M&&V-M+U<=D)return;const K=x.offsetTop-(D-U)/2;W.scrollTo({top:K,behavior:"smooth"})}const F=m.useMemo(()=>{let w="";return()=>{clearTimeout(w),E.current=!0,w=setTimeout(()=>{E.current=!1},300)}},[]);return v.length>0&&u&&I.jsx(l.RectPopup,{portal:!0,anchorRect$:R,direction:"vertical",children:I.jsx("ul",{className:`
|
|
38
38
|
univer-m-0 univer-box-border univer-max-h-[400px] univer-w-[250px] univer-list-none
|
|
39
39
|
univer-overflow-y-auto univer-rounded-lg univer-border univer-border-solid univer-border-gray-200
|
|
40
40
|
univer-bg-white univer-p-2 univer-leading-5 univer-shadow-md univer-outline-none
|
|
@@ -42,17 +42,14 @@
|
|
|
42
42
|
univer-box-border univer-cursor-pointer univer-rounded univer-px-2 univer-py-1
|
|
43
43
|
univer-text-gray-900 univer-transition-colors
|
|
44
44
|
${p===W?"univer-bg-gray-200":""}
|
|
45
|
-
`,onMouseEnter:()=>O(W),onMouseLeave:k,onMouseMove:F,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,S.length)}),I.jsx("span",{children:w.name.slice(S.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:v,onVerify:S,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:L}=e,F=l.useDependency(Z.IEditorService),w=m.useRef(null),W=l.useEvent(v);m.useImperativeHandle(t,()=>({isClickOutSide:z=>w.current?!w.current.contains(z.target):!1}));const x=l.useEvent(_),N=m.useRef(null),M=m.useRef(void 0),D=M.current,[P,V]=m.useState(i),U=m.useRef(null),K=m.useMemo(()=>g!=null?g:a.createInternalEditorID(`${A.EMBEDDING_FORMULA_EDITOR}-${a.generateRandomId(4)}`),[]),
|
|
46
|
-
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},U.current);const
|
|
45
|
+
`,onMouseEnter:()=>O(W),onMouseLeave:k,onMouseMove:F,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,S.length)}),I.jsx("span",{children:w.name.slice(S.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:v,onVerify:S,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:L}=e,F=l.useDependency(Z.IEditorService),w=m.useRef(null),W=l.useEvent(v);m.useImperativeHandle(t,()=>({isClickOutSide:z=>w.current?!w.current.contains(z.target):!1}));const x=l.useEvent(_),N=m.useRef(null),M=m.useRef(void 0),D=M.current,[P,V]=m.useState(i),U=m.useRef(null),K=m.useMemo(()=>g!=null?g:a.createInternalEditorID(`${A.EMBEDDING_FORMULA_EDITOR}-${a.generateRandomId(4)}`),[]),re=m.useMemo(()=>n!==void 0,[n]),Y=l.useDependency(a.IUniverInstanceService),ue=Y.getUnit(K);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:""),X=Ee(te),J=m.useMemo(()=>Un(te),[te]),ce=m.useMemo(()=>Ne(J),[J,Ne]),{isSelecting:Q,isSelectingRef:ae}=In({unitId:r,subUnitId:o,editorId:K,isFocus:P,disableOnClick:b}),oe=m.useRef(""),Re=l.useDependency(H.IRenderManagerService).getRenderById(K),ie=Re==null?void 0:Re.with(Z.DocSelectionRenderService),G=ie==null?void 0:ie.isFocusing,le=m.useMemo(()=>Y.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC),[Y]),de=l.useObservable(le),ve=(de==null?void 0:de.getUnitId())===K,be=m.useRef([]),fe=Q;l.useUpdateEffect(()=>{W(te)},[te,W]);const ct=Nt("="),at=Tn(r,o),Te=l.useEvent((z,ne=!0,Se,he)=>{if(!M.current)return;oe.current=z;const ze=z[0]==="="?z.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,Se){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(P?Ge:[],M.current)}});m.useEffect(()=>{P&&Te(te,!1,!0)},[P]),m.useEffect(()=>{if(P){if(oe.current===te)return;Te(te,!1,!0)}},[te]),$n(P,S,te);const xe=mn(D),Vt=xn(P,r,o);m.useEffect(()=>{var z;x(Q,(z=ie==null?void 0:ie.isFocusing)!=null?z:!0)},[x,Q]),Z.useKeyboardEvent(P,p,D),m.useLayoutEffect(()=>{let z;if(U.current){z=F.register({autofocus:O,editorUnitId:K,initialSnapshot:{id:K,body:{dataStream:`${s}\r
|
|
46
|
+
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},U.current);const ne=F.getEditor(K);M.current=ne,Te(s,!1,!0)}return()=>{z==null||z.dispose()}},[]),m.useLayoutEffect(()=>{i?(V(i),xe()):(E&&(D==null||D.blur(),Vt()),V(i))},[i,D,xe,Vt,E]);const{checkScrollBar:Kr}=Z.useResize(D,y,R);Dn(P,!!(Q&&ve),r,k),Nn(!!(P&&G&&u),fe,D,C);const jr=l.useEvent((z,ne,Se)=>{if(!G)return;const he=ne!==-1?[{startOffset:ne+1,endOffset:ne+1,collapsed:!0}]:void 0;Te(`=${z}`,!0,Se,he),Se&&(xe(),ne!==-1&&setTimeout(()=>{const ze={startOffset:ne+1,endOffset:ne+1},pe=D==null?void 0:D.render.with(Z.DocBackScrollRenderController);pe==null||pe.scrollToRange({...ze,collapsed:!0})},50),Kr())});Ln(P&&!!(Q&&ve),P,ae,r,o,be,c,!!fe,D,jr),Pn(P&&!!(Q&&ve),r,c,V,h,()=>{Te(X.current,!1,!0)});const qr=z=>{if(z){const ne=D==null?void 0:D.getSelectionRanges();if(ne&&ne.length===1){const Se=ne[0];if(Se.collapsed){const he=z.offset;setTimeout(()=>{D==null||D.setSelectionRanges([{startOffset:Se.startOffset-he,endOffset:Se.endOffset-he}])},30)}}xe(),Te(`=${z.text}`)}},Yr=()=>{V(!0),d(),xe()};return I.jsxs("div",{style:L,className:f,children:[I.jsx("div",{className:ee.clsx(`
|
|
47
47
|
univer-relative univer-box-border univer-flex univer-h-full univer-w-full univer-items-center
|
|
48
48
|
univer-justify-around univer-gap-2 univer-rounded-none univer-border-none univer-p-0
|
|
49
|
-
`,{"univer-border-primary-500":P,"univer-border-red-500":ne}),ref:w,children:I.jsx("div",{className:"univer-relative univer-h-full univer-w-full",ref:U,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:P,formulaText:ee,onClose:()=>xe()}):null,D?I.jsx(Vn,{isFocus:P,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),v=m.useRef(""),S=l.useDependency(a.IUniverInstanceService);return m.useEffect(()=>{if(!e)return;const f=e.getDocumentDataModel().getPlainText();if(v.current===f)return;v.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=S.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((v,S)=>{const f=c==null?void 0:c.getActiveSheet();if(!f||!n&&f.getSheetId()!==r||!(v!=null&&v.length))return;const g=v.map(u=>({range:u.range,unitId:s,sheetName:f.getSheetId()===r?"":f.getName()}));d(g,S)});m.useEffect(()=>{const v=new a.DisposableCollection;return v.add(t.selectionMoveStart$.subscribe(S=>{h(S,!0)})),v.add(t.selectionMoving$.subscribe(S=>{h(S,!1)})),v.add(t.selectionMoveEnd$.subscribe(S=>{h(S,!1)})),()=>{v.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,v=l.useDependency(a.LocaleService),S=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)),L=k.filter(w=>!O.has(w));if(!L.length)return;const F=[...f];if(k.length>1){b||F.splice(u,1),F.push(...L);const w=F.slice(0,o);g(w),_(w.length-1),requestAnimationFrame(()=>{var W;(W=p.current)==null||W.scrollTo({top:p.current.scrollHeight})})}else{F.splice(u,1,...L);const w=F.slice(0,o);g(w),_(u+L.length-1)}}}),I.jsx(re.Dialog,{width:"328px",open:t,title:v.t("rangeSelector.title"),draggable:!0,mask:!1,maskClosable:!1,footer:I.jsxs("footer",{children:[I.jsx(re.Button,{onClick:d,children:v.t("rangeSelector.cancel")}),I.jsx(re.Button,{style:{marginLeft:10},variant:"primary",onClick:()=>{c(f.filter(y=>{const b=S.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:v.t("rangeSelector.confirm")})]}),onClose:d,children:I.jsxs("div",{ref:p,className:`
|
|
50
|
-
-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6 univer-scrollbar-thin
|
|
51
|
-
univer-scrollbar-track-transparent univer-scrollbar-thumb-[#73737366]
|
|
52
|
-
`,children:[f.map((y,b)=>I.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-justify-start univer-gap-4",children:[I.jsx(re.Input,{className:"univer-w-full",placeholder:v.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(re.Button,{variant:"link",onClick:E,children:[I.jsx(yt,{}),I.jsx("span",{children:v.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:v,onRangeSelectorDialogVisibleChange:S,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),L=l.useDependency(Z.IEditorService),{sequenceNodes:F}=Hn(t,C,o,i),w=Ee(F),W=l.useDependency(a.ICommandService),x=l.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),L.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(){L.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,L,r,w]),m.useEffect(()=>{var M;s==null||s(At(F),(M=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?M:"")},[F]),m.useEffect(()=>{S==null||S(R)},[R]),m.useEffect(()=>{if(R&&p)return()=>{const M={unitId:o,subUnitId:i,selections:p};W.executeCommand(B.SetSelectionsOperation.id,M)}},[R]),I.jsxs(I.Fragment,{children:[_?null:I.jsx(Z.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(re.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),P=a.RichTextBuilder.newEmptyData();P.body.dataStream=D,t==null||t.replaceText(D,!1),v==null||v(P,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(){q(this,"_currentSelector$",new j.BehaviorSubject(null));q(this,"currentSelector$",this._currentSelector$.asObservable())}showRangeSelectorDialog(t){const n=t.callback,s=new Promise(r=>{t.callback=o=>{r(o),n(o)}});return this._currentSelector$.next(t),s}}var 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},Ve=(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===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 v=h.getCellMatrix(),S=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=v.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,S.setValue(u,_,y)}else S.setValue(u,_,C);f.setValue(u,_,v.getValue(u,_))}),g?(n.push({id:B.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:o,cellValue:S.getMatrix()}}),s.push({id:B.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:o,cellValue:f.getMatrix()}}),{redos:n,undos:s}):{redos:n,undos:s}}},$.FormulaReorderController=Zn([Ve(0,a.Inject(B.SheetInterceptorService)),Ve(1,a.Inject(a.IUniverInstanceService)),Ve(2,a.Inject(T.FormulaDataModel)),Ve(3,a.Inject(T.LexerTreeBuilder))],$.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(j.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 v=kt(d,!!h);if(!v){this._hideAlert();return}const S=this._cellAlertManagerService.currentAlert.get(ot),f=(o=S==null?void 0:S.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[v]}`),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,v;const i=or(r),c=[],d=new Map;for(let S=1;S<=t;S++){const f=(S-1)%e.length,g=s[f],u=a.Tools.deepClone(e[f]);if(u){const _=((h=e[f])==null?void 0:h.f)||"",p=((v=e[f])==null?void 0:v.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,v=0;switch(n){case a.Direction.UP:v=c[r]-d[r];break;case a.Direction.RIGHT:h=e;break;case a.Direction.DOWN:v=c[r]-d[r];break;case a.Direction.LEFT:h=-e*t;break}return{offsetX:h,offsetY:v}}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,v=n,S={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,v,g,S,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 v=[],S=[],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()};v.push({id:B.SetRangeValuesMutation.id,params:g});const u=B.SetRangeValuesUndoMutationFactory(r,g);return S.push({id:B.SetRangeValuesMutation.id,params:u}),{undos:S,redos:v}}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 v=n.rows[c],S=n.cols[d],f={};a.isFormulaString(h.v)?(f.v=null,f.f=`${h.v}`,f.si=null,f.p=null,o.setValue(v,S,f)):(g=i==null?void 0:i[v])!=null&&g[S]&&(f.v=h.v,f.f=null,f.si=null,f.p=null,o.setValue(v,S,f))}),o}function fr(e,t,n,s,r,o){var h,v;const i=new a.ObjectMatrix,c=(v=(h=r.getArrayFormulaCellData())==null?void 0:h[o.unitId])==null?void 0:v[o.subUnitId],d=r.getSheetFormulaData(e,t);return s.forValue((S,f,g)=>{var R,y;const u=o.range.rows[S%o.range.rows.length],_=o.range.cols[f%o.range.cols.length],p=n.rows[S],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,v,S)=>{const f=n.rows[h],g=n.cols[v],u={};if(a.isFormulaId(S.si)){if(i.unitId!==e||i.subUnitId!==t){const _=o.getFormulaStringByCell(i.range.rows[h%i.range.rows.length],i.range.cols[v%i.range.cols.length],i.subUnitId,i.unitId),p=n.cols[v]-i.range.cols[v%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=S.si,u.f=null;u.v=null,u.p=null,c.setValue(f,g,u)}else if(a.isFormulaString(S.f)){const _=`${h%i.range.rows.length}_${v%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[v]-i.range.cols[v%i.range.cols.length],E=n.rows[h]-i.range.rows[h%i.range.rows.length],R=r.moveFormulaRefOffset(S.f||"",C,E);u.si=p,u.f=R}u.v=null,u.p=null,c.setValue(f,g,u)}else{if(u.v=S.v,u.f=null,u.si=null,u.p=null,S.p){const _=Pt(S);_&&(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,v=i.getSheetFormulaData(e,t),S=[];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))S.push(u.si),C.f=u.f,C.si=u.si;else if(S.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=v==null?void 0:v[_])!=null&&E[p]&&(C.v=u.v,C.f=null,C.si=null,C.p=u.p,d.setValue(_,p,C))}),S.length>0&&new a.ObjectMatrix(v).forValue((f,g,u)=>{if(!(c.range.rows.includes(f)&&c.range.cols.includes(g))&&!(n.rows.includes(f)&&n.cols.includes(g))&&S.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 vr=Object.getOwnPropertyDescriptor,Sr=(e,t,n,s)=>{for(var r=s>1?void 0:s?vr(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();q(this,"_previousShape");q(this,"_skeleton");this._context=t,this._sheetInterceptorService=n,this._formulaDataModel=s,this._themeService=r,this._renderManagerService=o,this._sheetSkeletonManagerService=i,this._commandService=c,this._logService=d,this._initSkeletonChangeListener(),this._initInterceptorEditorStart(),this._commandExecutedListener()}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(t=>{var n,s;if(t==null)this._logService.debug("[FormulaEditorShowController]: should not receive currentSkeleton$ as null!");else{const{skeleton:r}=t,o=(s=(n=this._skeleton)==null?void 0:n.worksheet)==null?void 0:s.getSheetId();if(this._changeRuntime(r),o!==r.worksheet.getSheetId())this._removeArrayFormulaRangeShape();else{const{unitId:i,sheetId:c}=t;this._updateArrayFormulaRangeShape(i,c)}}}))}_changeRuntime(t){this._skeleton=t}_initInterceptorEditorStart(){this.disposeWithMe(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(),v=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return s(t);let S=null;const f=this._formulaDataModel.getFormulaStringByCell(r,o,c,i);if(f!==null&&(S={f}),t.v!=null&&t.v!==""&&((p=(_=(u=v[i])==null?void 0:u[c])==null?void 0:_[r])==null?void 0:p[o])==null)return S?{...t,...S}:s(t);const g=(C=h==null?void 0:h[i])==null?void 0:C[c];return g!=null&&(S=this._displayArrayFormulaRangeShape(g,r,o,i,c,d,S)),S?{...t,...S}: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,v,S)=>{var p;if(S==null)return!0;const{startRow:f,startColumn:g,endRow:u,endColumn:_}=S;if(h===n&&v===s)return this._createArrayFormulaRangeShape(S,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[v];return E==null||E.f==null?!0:(c==null&&(c={f:E.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(S,r),!1)}}),c}_createArrayFormulaRangeShape(t,n){const s=this._renderManagerService.getRenderById(n),r=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!s||!r)return;const{scene:o}=s;if(!o)return;const i=this._themeService.getCurrentTheme(),c={range:t,primary:null,style:{strokeWidth:1,stroke:i.hyacinth700,fill:new a.ColorKit(i.colorWhite).setAlpha(0).toString(),widgets:{}}},d=A.attachSelectionWithCoord(c,r),{rowHeaderWidth:h,columnHeaderHeight:v}=r,S=new A.SelectionControl(o,A.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:h,columnHeaderHeight:v});S.updateRangeBySelectionWithCoord(d),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 v={startRow:r,endRow:o,startColumn:i,endColumn:c};this._refreshArrayFormulaRangeShape(t,v);break}}}};He=Sr([ye(1,a.Inject(B.SheetInterceptorService)),ye(2,a.Inject(T.FormulaDataModel)),ye(3,a.Inject(a.ThemeService)),ye(4,H.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},$t=(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,v;const o=(v=(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:v[s.col];return kt(n,!!o)?r({...n,markers:{...n==null?void 0:n.markers,...Cr}}):r(n)},priority:10}))}};Ke=mr([$t(0,a.Inject(B.SheetInterceptorService)),$t(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 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: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:`
|
|
49
|
+
`,{"univer-border-primary-500":P,"univer-border-red-500":re}),ref:w,children:I.jsx("div",{className:"univer-relative univer-h-full univer-w-full",ref:U,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:P,formulaText:te,onClose:()=>xe()}):null,D?I.jsx(Vn,{isFocus:P,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),v=m.useRef(""),S=l.useDependency(a.IUniverInstanceService);return m.useEffect(()=>{if(!e)return;const f=e.getDocumentDataModel().getPlainText();if(v.current===f)return;v.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=S.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((v,S)=>{const f=c==null?void 0:c.getActiveSheet();if(!f||!n&&f.getSheetId()!==r||!(v!=null&&v.length))return;const g=v.map(u=>({range:u.range,unitId:s,sheetName:f.getSheetId()===r?"":f.getName()}));d(g,S)});m.useEffect(()=>{const v=new a.DisposableCollection;return v.add(t.selectionMoveStart$.subscribe(S=>{h(S,!0)})),v.add(t.selectionMoving$.subscribe(S=>{h(S,!1)})),v.add(t.selectionMoveEnd$.subscribe(S=>{h(S,!1)})),()=>{v.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,v=l.useDependency(a.LocaleService),S=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)),L=k.filter(w=>!O.has(w));if(!L.length)return;const F=[...f];if(k.length>1){b||F.splice(u,1),F.push(...L);const w=F.slice(0,o);g(w),_(w.length-1),requestAnimationFrame(()=>{var W;(W=p.current)==null||W.scrollTo({top:p.current.scrollHeight})})}else{F.splice(u,1,...L);const w=F.slice(0,o);g(w),_(u+L.length-1)}}}),I.jsx(ee.Dialog,{width:"328px",open:t,title:v.t("rangeSelector.title"),draggable:!0,mask:!1,maskClosable:!1,footer:I.jsxs("footer",{children:[I.jsx(ee.Button,{onClick:d,children:v.t("rangeSelector.cancel")}),I.jsx(ee.Button,{style:{marginLeft:10},variant:"primary",onClick:()=>{c(f.filter(y=>{const b=S.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:v.t("rangeSelector.confirm")})]}),onClose:d,children:I.jsxs("div",{ref:p,className:ee.clsx("-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6",ee.scrollbarClassName),children:[f.map((y,b)=>I.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-justify-start univer-gap-4",children:[I.jsx(ee.Input,{className:"univer-w-full",placeholder:v.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(ee.Button,{variant:"link",onClick:E,children:[I.jsx(yt,{}),I.jsx("span",{children:v.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:v,onRangeSelectorDialogVisibleChange:S,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),L=l.useDependency(Z.IEditorService),{sequenceNodes:F}=Hn(t,C,o,i),w=Ee(F),W=l.useDependency(a.ICommandService),x=l.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),L.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(){L.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,L,r,w]),m.useEffect(()=>{var M;s==null||s(At(F),(M=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?M:"")},[F]),m.useEffect(()=>{S==null||S(R)},[R]),m.useEffect(()=>{if(R&&p)return()=>{const M={unitId:o,subUnitId:i,selections:p};W.executeCommand(B.SetSelectionsOperation.id,M)}},[R]),I.jsxs(I.Fragment,{children:[_?null:I.jsx(Z.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(ee.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),P=a.RichTextBuilder.newEmptyData();P.body.dataStream=D,t==null||t.replaceText(D,!1),v==null||v(P,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(){q(this,"_currentSelector$",new j.BehaviorSubject(null));q(this,"currentSelector$",this._currentSelector$.asObservable())}showRangeSelectorDialog(t){const n=t.callback,s=new Promise(r=>{t.callback=o=>{r(o),n(o)}});return this._currentSelector$.next(t),s}}var 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},Ve=(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===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 v=h.getCellMatrix(),S=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=v.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,S.setValue(u,_,y)}else S.setValue(u,_,C);f.setValue(u,_,v.getValue(u,_))}),g?(n.push({id:B.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:o,cellValue:S.getMatrix()}}),s.push({id:B.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:o,cellValue:f.getMatrix()}}),{redos:n,undos:s}):{redos:n,undos:s}}},$.FormulaReorderController=Zn([Ve(0,a.Inject(B.SheetInterceptorService)),Ve(1,a.Inject(a.IUniverInstanceService)),Ve(2,a.Inject(T.FormulaDataModel)),Ve(3,a.Inject(T.LexerTreeBuilder))],$.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(j.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 v=kt(d,!!h);if(!v){this._hideAlert();return}const S=this._cellAlertManagerService.currentAlert.get(ot),f=(o=S==null?void 0:S.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[v]}`),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,v;const i=or(r),c=[],d=new Map;for(let S=1;S<=t;S++){const f=(S-1)%e.length,g=s[f],u=a.Tools.deepClone(e[f]);if(u){const _=((h=e[f])==null?void 0:h.f)||"",p=((v=e[f])==null?void 0:v.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,v=0;switch(n){case a.Direction.UP:v=c[r]-d[r];break;case a.Direction.RIGHT:h=e;break;case a.Direction.DOWN:v=c[r]-d[r];break;case a.Direction.LEFT:h=-e*t;break}return{offsetX:h,offsetY:v}}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,v=n,S={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,v,g,S,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 v=[],S=[],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()};v.push({id:B.SetRangeValuesMutation.id,params:g});const u=B.SetRangeValuesUndoMutationFactory(r,g);return S.push({id:B.SetRangeValuesMutation.id,params:u}),{undos:S,redos:v}}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 v=n.rows[c],S=n.cols[d],f={};a.isFormulaString(h.v)?(f.v=null,f.f=`${h.v}`,f.si=null,f.p=null,o.setValue(v,S,f)):(g=i==null?void 0:i[v])!=null&&g[S]&&(f.v=h.v,f.f=null,f.si=null,f.p=null,o.setValue(v,S,f))}),o}function fr(e,t,n,s,r,o){var h,v;const i=new a.ObjectMatrix,c=(v=(h=r.getArrayFormulaCellData())==null?void 0:h[o.unitId])==null?void 0:v[o.subUnitId],d=r.getSheetFormulaData(e,t);return s.forValue((S,f,g)=>{var R,y;const u=o.range.rows[S%o.range.rows.length],_=o.range.cols[f%o.range.cols.length],p=n.rows[S],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,v,S)=>{const f=n.rows[h],g=n.cols[v],u={};if(a.isFormulaId(S.si)){if(i.unitId!==e||i.subUnitId!==t){const _=o.getFormulaStringByCell(i.range.rows[h%i.range.rows.length],i.range.cols[v%i.range.cols.length],i.subUnitId,i.unitId),p=n.cols[v]-i.range.cols[v%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=S.si,u.f=null;u.v=null,u.p=null,c.setValue(f,g,u)}else if(a.isFormulaString(S.f)){const _=`${h%i.range.rows.length}_${v%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[v]-i.range.cols[v%i.range.cols.length],E=n.rows[h]-i.range.rows[h%i.range.rows.length],R=r.moveFormulaRefOffset(S.f||"",C,E);u.si=p,u.f=R}u.v=null,u.p=null,c.setValue(f,g,u)}else{if(u.v=S.v,u.f=null,u.si=null,u.p=null,S.p){const _=Pt(S);_&&(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,v=i.getSheetFormulaData(e,t),S=[];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))S.push(u.si),C.f=u.f,C.si=u.si;else if(S.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=v==null?void 0:v[_])!=null&&E[p]&&(C.v=u.v,C.f=null,C.si=null,C.p=u.p,d.setValue(_,p,C))}),S.length>0&&new a.ObjectMatrix(v).forValue((f,g,u)=>{if(!(c.range.rows.includes(f)&&c.range.cols.includes(g))&&!(n.rows.includes(f)&&n.cols.includes(g))&&S.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 vr=Object.getOwnPropertyDescriptor,Sr=(e,t,n,s)=>{for(var r=s>1?void 0:s?vr(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();q(this,"_previousShape");q(this,"_skeleton");this._context=t,this._sheetInterceptorService=n,this._formulaDataModel=s,this._themeService=r,this._renderManagerService=o,this._sheetSkeletonManagerService=i,this._commandService=c,this._logService=d,this._initSkeletonChangeListener(),this._initInterceptorEditorStart(),this._commandExecutedListener()}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(t=>{var n,s;if(t==null)this._logService.debug("[FormulaEditorShowController]: should not receive currentSkeleton$ as null!");else{const{skeleton:r}=t,o=(s=(n=this._skeleton)==null?void 0:n.worksheet)==null?void 0:s.getSheetId();if(this._changeRuntime(r),o!==r.worksheet.getSheetId())this._removeArrayFormulaRangeShape();else{const{unitId:i,sheetId:c}=t;this._updateArrayFormulaRangeShape(i,c)}}}))}_changeRuntime(t){this._skeleton=t}_initInterceptorEditorStart(){this.disposeWithMe(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(),v=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return s(t);let S=null;const f=this._formulaDataModel.getFormulaStringByCell(r,o,c,i);if(f!==null&&(S={f}),t.v!=null&&t.v!==""&&((p=(_=(u=v[i])==null?void 0:u[c])==null?void 0:_[r])==null?void 0:p[o])==null)return S?{...t,...S}:s(t);const g=(C=h==null?void 0:h[i])==null?void 0:C[c];return g!=null&&(S=this._displayArrayFormulaRangeShape(g,r,o,i,c,d,S)),S?{...t,...S}: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,v,S)=>{var p;if(S==null)return!0;const{startRow:f,startColumn:g,endRow:u,endColumn:_}=S;if(h===n&&v===s)return this._createArrayFormulaRangeShape(S,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[v];return E==null||E.f==null?!0:(c==null&&(c={f:E.f,isInArrayFormulaRange:!0}),this._createArrayFormulaRangeShape(S,r),!1)}}),c}_createArrayFormulaRangeShape(t,n){const s=this._renderManagerService.getRenderById(n),r=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!s||!r)return;const{scene:o}=s;if(!o)return;const i=this._themeService.getCurrentTheme(),c={range:t,primary:null,style:{strokeWidth:1,stroke:i.hyacinth700,fill:new a.ColorKit(i.colorWhite).setAlpha(0).toString(),widgets:{}}},d=A.attachSelectionWithCoord(c,r),{rowHeaderWidth:h,columnHeaderHeight:v}=r,S=new A.SelectionControl(o,A.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:h,columnHeaderHeight:v});S.updateRangeBySelectionWithCoord(d),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 v={startRow:r,endRow:o,startColumn:i,endColumn:c};this._refreshArrayFormulaRangeShape(t,v);break}}}};He=Sr([ye(1,a.Inject(B.SheetInterceptorService)),ye(2,a.Inject(T.FormulaDataModel)),ye(3,a.Inject(a.ThemeService)),ye(4,H.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},$t=(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,v;const o=(v=(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:v[s.col];return kt(n,!!o)?r({...n,markers:{...n==null?void 0:n.markers,...Cr}}):r(n)},priority:10}))}};Ke=mr([$t(0,a.Inject(B.SheetInterceptorService)),$t(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 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: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:`
|
|
53
50
|
univer-mb-2 univer-font-medium univer-text-gray-500
|
|
54
51
|
${t}
|
|
55
|
-
`,children:s}),I.jsx("div",{className:"univer-font-normal univer-text-gray-900",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,v)=>I.jsxs("div",{children:[I.jsx("div",{className:"univer-text-sm",children:h.name}),I.jsx("div",{className:"univer-mb-2 univer-mt-1"})]},v))}),I.jsx("div",{className:"univer-flex-1 univer-border-l univer-border-solid univer-border-gray-200 univer-p-3",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,v]=m.useState(n),[S,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(()=>{L(n)},[]),m.useEffect(()=>{k(0)},[o]),m.useEffect(()=>{E!=null&&E.visible&&(r(""),i([]),d(0),v(n),f(0),u(null),L(n))},[E]);const O=N=>{if(s.trim()==="")return N;const M=new RegExp(`(${s.toLocaleUpperCase()})`);return N.split(M).filter(Boolean).map((P,V)=>P.match(M)?I.jsx("span",{className:"univer-text-red-500",children:P},V):P)},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 L(N){v(N);const M=_.getSearchListByType(+N);i(M)}function F(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 W=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(
|
|
52
|
+
`,children:s}),I.jsx("div",{className:"univer-font-normal univer-text-gray-900",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,v)=>I.jsxs("div",{children:[I.jsx("div",{className:"univer-text-sm",children:h.name}),I.jsx("div",{className:"univer-mb-2 univer-mt-1"})]},v))}),I.jsx("div",{className:"univer-flex-1 univer-border-l univer-border-solid univer-border-gray-200 univer-p-3",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,v]=m.useState(n),[S,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(()=>{L(n)},[]),m.useEffect(()=>{k(0)},[o]),m.useEffect(()=>{E!=null&&E.visible&&(r(""),i([]),d(0),v(n),f(0),u(null),L(n))},[E]);const O=N=>{if(s.trim()==="")return N;const M=new RegExp(`(${s.toLocaleUpperCase()})`);return N.split(M).filter(Boolean).map((P,V)=>P.match(M)?I.jsx("span",{className:"univer-text-red-500",children:P},V):P)},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 L(N){v(N);const M=_.getSearchListByType(+N);i(M)}function F(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 W=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(ee.Select,{value:h,options:R,onChange:L}),I.jsx(ee.Input,{placeholder:p.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:w,value:s,onChange:F,size:"small",allowClear:!0})]}),I.jsx("ul",{className:`
|
|
56
53
|
univer-mx-0 univer-mb-0 univer-mt-2 univer-box-border univer-max-h-[364px] univer-w-full
|
|
57
54
|
univer-select-none univer-list-none univer-overflow-y-auto univer-rounded univer-border
|
|
58
55
|
univer-border-solid univer-border-gray-200 univer-p-3 univer-outline-none
|
|
@@ -65,4 +62,4 @@
|
|
|
65
62
|
`,onMouseEnter:()=>W(M),onMouseLeave:x,onClick:()=>k(M),children:[S===M&&I.jsx(Ct,{className:`
|
|
66
63
|
univer-absolute univer-left-1.5 univer-top-1/2 univer-inline-flex
|
|
67
64
|
univer--translate-y-1/2 univer-text-base univer-text-green-500
|
|
68
|
-
`}),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(Ft,{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(Z.IEditorService),h=l.useDependency(a.IUniverInstanceService),v=l.useDependency(a.ICommandService);function S(){n(!t),r(!s)}function f(){const g=B.getSheetCommandTarget(h);if(!g)return;v.executeCommand(A.SetCellEditVisibleOperation.id,{visible:!0,unitId:g.unitId,eventType:H.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(
|
|
65
|
+
`}),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(Ft,{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(Z.IEditorService),h=l.useDependency(a.IUniverInstanceService),v=l.useDependency(a.ICommandService);function S(){n(!t),r(!s)}function f(){const g=B.getSheetCommandTarget(h);if(!g)return;v.executeCommand(A.SetCellEditVisibleOperation.id,{visible:!0,unitId:g.unitId,eventType:H.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(ee.Button,{variant:"primary",onClick:S,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.next")}),s&&I.jsx(ee.Button,{onClick:S,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.prev")}),t&&!!e&&I.jsx(ee.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:$e.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:Fe.id,title:"formula.insert.more",type:l.MenuItemType.BUTTON}}function Tr(e){return e.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(j.switchMap(s=>s&&e.get(l.IClipboardInterfaceService)?new j.Observable(o=>o.next(!e.get(l.IClipboardInterfaceService).supportClipboard)):j.of(!0)))}function Mr(e){return{id:Pe.id,type:l.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:Tr(e).pipe(j.combineLatestWith(A.getCurrentRangeDisable$(e,{workbookTypes:[B.WorkbookEditablePermission],rangeTypes:[B.RangeProtectionPermissionEditPoint],worksheetTypes:[B.WorksheetSetCellValuePermission,B.WorksheetEditPermission]})),j.map(([t,n])=>t||n))}}const Or={[l.RibbonStartGroup.FORMULAS_INSERT]:{[$e.id]:{order:1,menuItemFactory:Rr,[Fe.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:H.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:H.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:H.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:H.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:H.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}var $r=Object.getOwnPropertyDescriptor,Fr=(e,t,n,s)=>{for(var r=s>1?void 0:s?$r(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,$e,Fe,St,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(vt,Ir)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[He]))}};qe=Fr([Ie(0,a.Inject(a.Injector)),Ie(1,l.IMenuManagerService),Ie(2,a.ICommandService),Ie(3,l.IShortcutService),Ie(4,l.IUIPartsService),Ie(5,H.IRenderManagerService),Ie(6,a.Inject(l.ComponentManager))],qe);const Wr=()=>{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 Vr=Object.defineProperty,Br=Object.getOwnPropertyDescriptor,Ur=(e,t,n)=>t in e?Vr(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),Wt=(e,t,n)=>Ur(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,[[Xe,{useClass:Je}],[st],[qe],[Be],[Ue],[He],[Ke],[$.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,[[qe],[Ue],[Ke]])}onSteady(){this._injector.get(Be),this._injector.get($.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(Wr,this._injector)))}},Wt($.UniverSheetsFormulaUIPlugin,"pluginName",gt),Wt($.UniverSheetsFormulaUIPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),$.UniverSheetsFormulaUIPlugin=Hr([a.DependentOn(T.UniverFormulaEnginePlugin,me.UniverSheetsFormulaPlugin),Ye(1,a.Inject(a.Injector)),Ye(2,H.IRenderManagerService),Ye(3,a.IConfigService),Ye(4,l.IUIPartsService)],$.UniverSheetsFormulaUIPlugin),$.FORMULA_PROMPT_ACTIVATED=ut,$.FormulaEditor=xt,$.GlobalRangeSelectorService=st,$.HelpFunctionOperation=dt,$.InsertFunctionOperation=$e,$.MoreFunctionsOperation=Fe,$.RangeSelector=rt,$.ReferenceAbsoluteOperation=Qe,$.SearchFunctionOperation=St,$.SelectEditorFormulaOperation=Ce,$.SheetOnlyPasteFormulaCommand=Pe,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-formula-ui",
|
|
3
|
-
"version": "0.7.0-
|
|
3
|
+
"version": "0.7.0-nightly.202504301607",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "DreamNum <developer@univer.ai>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -63,26 +63,25 @@
|
|
|
63
63
|
"rxjs": ">=7.0.0"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@univerjs/icons": "^0.3.
|
|
67
|
-
"@univerjs/core": "0.7.0-
|
|
68
|
-
"@univerjs/design": "0.7.0-
|
|
69
|
-
"@univerjs/docs": "0.7.0-
|
|
70
|
-
"@univerjs/docs
|
|
71
|
-
"@univerjs/engine-formula": "0.7.0-
|
|
72
|
-
"@univerjs/
|
|
73
|
-
"@univerjs/
|
|
74
|
-
"@univerjs/sheets-
|
|
75
|
-
"@univerjs/sheets-
|
|
76
|
-
"@univerjs/ui": "0.7.0-
|
|
66
|
+
"@univerjs/icons": "^0.3.24",
|
|
67
|
+
"@univerjs/core": "0.7.0-nightly.202504301607",
|
|
68
|
+
"@univerjs/design": "0.7.0-nightly.202504301607",
|
|
69
|
+
"@univerjs/docs-ui": "0.7.0-nightly.202504301607",
|
|
70
|
+
"@univerjs/docs": "0.7.0-nightly.202504301607",
|
|
71
|
+
"@univerjs/engine-formula": "0.7.0-nightly.202504301607",
|
|
72
|
+
"@univerjs/sheets": "0.7.0-nightly.202504301607",
|
|
73
|
+
"@univerjs/engine-render": "0.7.0-nightly.202504301607",
|
|
74
|
+
"@univerjs/sheets-formula": "0.7.0-nightly.202504301607",
|
|
75
|
+
"@univerjs/sheets-ui": "0.7.0-nightly.202504301607",
|
|
76
|
+
"@univerjs/ui": "0.7.0-nightly.202504301607"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"less": "^4.3.0",
|
|
80
79
|
"postcss": "^8.5.3",
|
|
81
80
|
"react": "18.3.1",
|
|
82
81
|
"rxjs": "^7.8.1",
|
|
83
82
|
"tailwindcss": "^3.4.17",
|
|
84
83
|
"typescript": "^5.8.3",
|
|
85
|
-
"vite": "^6.3.
|
|
84
|
+
"vite": "^6.3.4",
|
|
86
85
|
"vitest": "^3.1.2",
|
|
87
86
|
"@univerjs-infra/shared": "0.7.0-beta.0"
|
|
88
87
|
},
|