@univerjs/sheets-formula-ui 0.7.0 → 0.8.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +7 -7
- package/lib/cjs/locale/en-US.js +1 -1
- package/lib/cjs/locale/fa-IR.js +1 -1
- package/lib/cjs/locale/fr-FR.js +1 -1
- package/lib/cjs/locale/ru-RU.js +1 -1
- package/lib/cjs/locale/vi-VN.js +1 -1
- package/lib/cjs/locale/zh-CN.js +1 -1
- package/lib/cjs/locale/zh-TW.js +1 -1
- package/lib/es/index.js +1434 -1359
- package/lib/es/locale/en-US.js +5 -0
- package/lib/es/locale/fa-IR.js +5 -0
- package/lib/es/locale/fr-FR.js +5 -0
- package/lib/es/locale/ru-RU.js +5 -0
- package/lib/es/locale/vi-VN.js +5 -0
- package/lib/es/locale/zh-CN.js +5 -0
- package/lib/es/locale/zh-TW.js +5 -0
- package/lib/index.css +1 -1
- package/lib/index.js +1434 -1359
- package/lib/locale/en-US.js +5 -0
- package/lib/locale/fa-IR.js +5 -0
- package/lib/locale/fr-FR.js +5 -0
- package/lib/locale/ru-RU.js +5 -0
- package/lib/locale/vi-VN.js +5 -0
- package/lib/locale/zh-CN.js +5 -0
- package/lib/locale/zh-TW.js +5 -0
- package/lib/types/controllers/menu.d.ts +6 -0
- package/lib/types/controllers/shortcuts/quick-sum.shortcut.d.ts +2 -0
- package/lib/types/locale/en-US.d.ts +5 -0
- package/lib/types/locale/fa-IR.d.ts +5 -0
- package/lib/types/locale/fr-FR.d.ts +5 -0
- package/lib/types/locale/ru-RU.d.ts +5 -0
- package/lib/types/locale/vi-VN.d.ts +5 -0
- package/lib/types/locale/zh-CN.d.ts +5 -0
- package/lib/types/locale/zh-TW.d.ts +5 -0
- package/lib/umd/index.js +7 -7
- package/lib/umd/locale/en-US.js +1 -1
- package/lib/umd/locale/fa-IR.js +1 -1
- package/lib/umd/locale/fr-FR.js +1 -1
- package/lib/umd/locale/ru-RU.js +1 -1
- package/lib/umd/locale/vi-VN.js +1 -1
- package/lib/umd/locale/zh-CN.js +1 -1
- package/lib/umd/locale/zh-TW.js +1 -1
- package/package.json +13 -13
package/lib/cjs/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";var Xt=Object.defineProperty;var Jt=(e,t,n)=>t in e?Xt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var q=(e,t,n)=>Jt(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),w=require("@univerjs/sheets-ui"),T=require("@univerjs/engine-formula"),K=require("rxjs"),J=require("@univerjs/docs-ui"),H=require("@univerjs/engine-render"),$=require("@univerjs/sheets"),ye=require("@univerjs/sheets-formula"),l=require("@univerjs/ui"),y=require("react/jsx-runtime"),W=require("@univerjs/design"),p=require("react"),Rt=require("@univerjs/docs"),Qt=require("rxjs/operators"),qe={id:"sheet.command.paste-formula",type:a.CommandType.COMMAND,handler:async e=>e.get(a.ICommandService).executeCommand(w.SheetPasteCommand.id,{value:w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA})},Ie={id:"formula-ui.operation.select-editor-formula",type:a.CommandType.OPERATION,handler:(e,t)=>!0};var en=Object.getOwnPropertyDescriptor,tn=(e,t,n,s)=>{for(var r=s>1?void 0:s?en(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},nn=(e,t)=>(n,s)=>t(n,s,e);const Et="FORMULA_PROMPT_ACTIVATED",rt=a.createIdentifier("formula-ui.prompt-service");let et=class{constructor(e){q(this,"_search$",new K.Subject);q(this,"_help$",new K.Subject);q(this,"_navigate$",new K.Subject);q(this,"_accept$",new K.Subject);q(this,"_acceptFormulaName$",new K.Subject);q(this,"search$",this._search$.asObservable());q(this,"help$",this._help$.asObservable());q(this,"navigate$",this._navigate$.asObservable());q(this,"accept$",this._accept$.asObservable());q(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());q(this,"_searching",!1);q(this,"_helping",!1);q(this,"_sequenceNodes",[]);q(this,"_isLockedOnSelectionChangeRefString",!1);q(this,"_isLockedOnSelectionInsertRefString",!1);this._contextService=e}dispose(){this._search$.complete(),this._help$.complete(),this._navigate$.complete(),this._accept$.complete(),this._acceptFormulaName$.complete(),this._sequenceNodes=[]}search(e){this._contextService.setContextValue(Et,e.visible),this._searching=e.visible,this._search$.next(e)}isSearching(){return this._searching}help(e){this._helping=e.visible,this._help$.next(e)}isHelping(){return this._helping}navigate(e){this._navigate$.next(e)}accept(e){this._accept$.next(e)}acceptFormulaName(e){this._acceptFormulaName$.next(e)}getSequenceNodes(){return[...this._sequenceNodes]}setSequenceNodes(e){this._sequenceNodes=e}clearSequenceNodes(){this._sequenceNodes=[]}getCurrentSequenceNode(e){return this._sequenceNodes[this.getCurrentSequenceNodeIndex(e)]}getCurrentSequenceNodeByIndex(e){return this._sequenceNodes[e]}getCurrentSequenceNodeIndex(e){let t=0;const n=this._sequenceNodes[0];for(let s=0,r=this._sequenceNodes.length;s<r;s++){const o=this._sequenceNodes[s];if(typeof o=="string")t++;else{const{endIndex:i}=o;t=i}if(e<=t)return typeof n=="string"&&e!==0?s+1:s}return this._sequenceNodes.length}updateSequenceRef(e,t){const n=this._sequenceNodes[e];if(typeof n=="string"||n.nodeType!==T.sequenceNodeType.REFERENCE)return;const s=t.length-n.token.length,r={...n};r.token=t,r.endIndex+=s,this._sequenceNodes[e]=r;for(let o=e+1,i=this._sequenceNodes.length;o<i;o++){const c=this._sequenceNodes[o];if(typeof c=="string")continue;const d={...c};d.startIndex+=s,d.endIndex+=s,this._sequenceNodes[o]=d}}insertSequenceRef(e,t){const n=t.length,s=this.getCurrentSequenceNodeIndex(e);this._sequenceNodes.splice(s,0,{token:t,startIndex:e,endIndex:e+n-1,nodeType:T.sequenceNodeType.REFERENCE});for(let r=s+1,o=this._sequenceNodes.length;r<o;r++){const i=this._sequenceNodes[r];if(typeof i=="string")continue;const c={...i};c.startIndex+=n,c.endIndex+=n,this._sequenceNodes[r]=c}}insertSequenceString(e,t){const n=this.getCurrentSequenceNodeIndex(e),s=t.split("");this._sequenceNodes.splice(n,0,...s);const r=s.length;for(let o=n+r,i=this._sequenceNodes.length;o<i;o++){const c=this._sequenceNodes[o];if(typeof c=="string")continue;const d={...c};d.startIndex+=r,d.endIndex+=r,this._sequenceNodes[o]=d}}enableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!0}disableLockedSelectionChange(){this._isLockedOnSelectionChangeRefString=!1}isLockedSelectionChange(){return this._isLockedOnSelectionChangeRefString}enableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!0}disableLockedSelectionInsert(){this._isLockedOnSelectionInsertRefString=!1}isLockedSelectionInsert(){return this._isLockedOnSelectionInsertRefString}};et=tn([nn(0,a.IContextService)],et);const yt={id:"formula-ui.operation.help-function",type:a.CommandType.OPERATION,handler:async(e,t)=>(e.get(rt).help(t),!0)},Ye={id:"formula-ui.operation.insert-function",type:a.CommandType.OPERATION,handler:async(e,t)=>{var R,I;const n=e.get($.SheetsSelectionsService),s=e.get(J.IEditorService),r=n.getCurrentSelections();if(!r||!r.length)return!1;const o=$.getSheetCommandTarget(e.get(a.IUniverInstanceService));if(!o)return!1;const{worksheet:i,unitId:c,subUnitId:d}=o,f=i.getCellMatrix(),{value:m}=t,S=e.get(a.ICommandService);e.get(w.IEditorBridgeService);const h=[],g=[];let u=null,_=0,v=0,C="";if(r.length===1&&(on(r[0].range)||cn(r[0].range)&>(f,r[0].range))){const{range:E,primary:b}=r[0],M=(R=b==null?void 0:b.actualRow)!=null?R:E.startRow,F=(I=b==null?void 0:b.actualColumn)!=null?I:E.startColumn;u=E,_=M,v=F;const L=ft(f,M,F);L&&(C=T.serializeRange(L))}else r.some(E=>{var F,L;const{range:b,primary:M}=E;if(gt(f,b)){const P=(F=M==null?void 0:M.actualRow)!=null?F:b.startRow,A=(L=M==null?void 0:M.actualColumn)!=null?L:b.startColumn,j=ft(f,P,A);if(!j)return u=b,_=P,v=A,!0;const D=T.serializeRange(j),O=`=${m}(${D})`;h.push({range:b,primary:{row:P,column:A},formula:O})}else{const{startRow:P,startColumn:A,endRow:j,endColumn:D}=b;if(P===j){const O=an(f,P,D,i.getColumnCount()-1),x=O===D?D-1:D,N=T.serializeRange({startRow:P,endRow:j,startColumn:A,endColumn:x}),k=`=${m}(${N})`;g.push({range:b,primary:{row:P,column:O},formula:k})}else{let O=-1;for(let N=A;N<=D;N++){const k=ln(f,N,j,i.getRowCount()-1);O=Math.max(O,k)}const x=O===j?j-1:j;for(let N=A;N<=D;N++){const k=T.serializeRange({startRow:P,endRow:x,startColumn:N,endColumn:N}),U=`=${m}(${k})`;g.push({range:b,primary:{row:O,column:N},formula:U})}}}return!1});if(u){const E=$.getCellAtRowCol(_,v,i),b={range:a.Rectangle.clone(u),primary:{startRow:E.startRow,startColumn:E.startColumn,endRow:E.endRow,endColumn:E.endColumn,actualRow:_,actualColumn:v,isMerged:E.isMerged,isMergedMainCell:E.startRow===_&&E.startColumn===v}},M={unitId:c,subUnitId:d,selections:[b]};await S.executeCommand($.SetSelectionsOperation.id,M);const F=s.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),L=s.getEditor(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);S.syncExecuteCommand(w.SetCellEditVisibleOperation.id,{visible:!0,unitId:c,eventType:H.DeviceInputEventType.Dblclick});const P=`=${m}(${C}`;F==null||F.replaceText(P),L==null||L.replaceText(P,!1)}return h.length===0&&g.length===0?!1:S.executeCommand(ye.InsertFunctionCommand.id,{list:h,listOfRangeHasNumber:g})}};function ft(e,t,n){const s=rn(e,t,n);if(s!==t)return{startRow:s,endRow:t-1,startColumn:n,endColumn:n};const r=sn(e,t,n);return r!==n?{startRow:t,endRow:t,startColumn:r,endColumn:n-1}:null}function rn(e,t,n){let s=!1;if(t===0)return t;for(let r=t-1;r>=0;r--){const o=e.getValue(r,n);if(Fe(o)&&!s){if(r===0)return 0;s=!0}else{if(s&&!Fe(o))return r+1;if(s&&r===0)return 0}}return t}function sn(e,t,n){let s=!1;if(n===0)return n;for(let r=n-1;r>=0;r--){const o=e.getValue(t,r);if(Fe(o)&&!s){if(r===0)return 0;s=!0}else{if(s&&!Fe(o))return r+1;if(s&&r===0)return 0}}return n}function Fe(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return!1;const n=t.dataStream,r=n.substring(n.length-2,n.length)===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 on(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}function cn(e){return e.startRow!==e.endRow&&e.startColumn!==e.endColumn}function gt(e,t){for(let n=t.startRow;n<=t.endRow;n++)for(let s=t.startColumn;s<=t.endColumn;s++)if(Fe(e.getValue(n,s)))return!1;return!0}function an(e,t,n,s){for(let r=n;r<=s;r++)if(!e.getValue(t,r))return r;return s}function ln(e,t,n,s){for(let r=n;r<=s;r++)if(!e.getValue(r,t))return r;return s}const It="SHEET_FORMULA_UI_PLUGIN",bt=`${It}_MORE_FUNCTIONS_COMPONENT`,ze={id:"formula-ui.operation.more-functions",type:a.CommandType.OPERATION,handler:async e=>(e.get(l.ISidebarService).open({header:{title:"formula.insert.tooltip"},children:{label:bt}}),!0)},st={id:"formula-ui.operation.change-ref-to-absolute",type:a.CommandType.OPERATION,handler:async e=>!0},Tt={id:"formula-ui.operation.search-function",type:a.CommandType.OPERATION,handler:async(e,t)=>(e.get(rt).search(t),!0)},ot=(e,t,n=!0)=>{let s=-1;return e.reduce((r,o,i)=>{if(r.isFinish)return r;const c=r.currentIndex;if(typeof o!="string")r.currentIndex+=o.token.length;else{const d=o.length;r.currentIndex+=d}return(n?r.currentIndex===t:t>c&&t<=r.currentIndex)&&(s=i,r.isFinish=!0),r},{currentIndex:0,isFinish:!1}),s},xt=(e,t)=>{const n=e[t];let s=-1;if(!n||typeof n=="string"||n.nodeType!==T.sequenceNodeType.REFERENCE)return-1;for(let r=0;r<=t;r++){const o=e[r];typeof o!="string"&&o.nodeType===T.sequenceNodeType.REFERENCE&&s++}return s};var se=function(){return se=Object.assign||function(e){for(var t,n=1,s=arguments.length;n<s;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},se.apply(this,arguments)},un=function(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(n[s[r]]=e[s[r]]);return n},be=p.forwardRef(function(e,t){var n=e.icon,s=e.id,r=e.className,o=e.extend,i=un(e,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(s," ").concat(r||"").trim(),d=p.useRef("_".concat(fn()));return Mt(n,"".concat(s),{defIds:n.defIds,idSuffix:d.current},se({ref:t,className:c},i),o)});function Mt(e,t,n,s,r){return p.createElement(e.tag,se(se({key:t},dn(e,n,r)),s),(hn(e,n).children||[]).map(function(o,i){return Mt(o,"".concat(t,"-").concat(e.tag,"-").concat(i),n,void 0,r)}))}function dn(e,t,n){var s=se({},e.attrs);n!=null&&n.colorChannel1&&s.fill==="colorChannel1"&&(s.fill=n.colorChannel1),e.tag==="mask"&&s.id&&(s.id=s.id+t.idSuffix),Object.entries(s).forEach(function(o){var i=o[0],c=o[1];i==="mask"&&typeof c=="string"&&(s[i]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var r=t.defIds;return!r||r.length===0||(e.tag==="use"&&s["xlink:href"]&&(s["xlink:href"]=s["xlink:href"]+t.idSuffix),Object.entries(s).forEach(function(o){var i=o[0],c=o[1];typeof c=="string"&&(s[i]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),s}function hn(e,t){var n,s=t.defIds;return!s||s.length===0?e:e.tag==="defs"&&(!((n=e.children)===null||n===void 0)&&n.length)?se(se({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&s&&s.indexOf(r.attrs.id)>-1?se(se({},r),{attrs:se(se({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):e}function fn(){return Math.random().toString(36).substring(2,8)}be.displayName="UniverIcon";var gn={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"}}]},Ot=p.forwardRef(function(e,t){return p.createElement(be,Object.assign({},e,{id:"check-mark-single",ref:t,icon:gn}))});Ot.displayName="CheckMarkSingle";var mn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},Nt=p.forwardRef(function(e,t){return p.createElement(be,Object.assign({},e,{id:"close-single",ref:t,icon:mn}))});Nt.displayName="CloseSingle";var Sn={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"}}]},Dt=p.forwardRef(function(e,t){return p.createElement(be,Object.assign({},e,{id:"delete-single",ref:t,icon:Sn}))});Dt.displayName="DeleteSingle";var vn={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"}}]},At=p.forwardRef(function(e,t){return p.createElement(be,Object.assign({},e,{id:"increase-single",ref:t,icon:vn}))});At.displayName="IncreaseSingle";var pn={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"}}]},wt=p.forwardRef(function(e,t){return p.createElement(be,Object.assign({},e,{id:"more-single",ref:t,icon:pn}))});wt.displayName="MoreSingle";var Cn={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"}}]},Ft=p.forwardRef(function(e,t){return p.createElement(be,Object.assign({},e,{id:"select-range-single",ref:t,icon:Cn}))});Ft.displayName="SelectRangeSingle";function _n(e,t){return Object.keys(e).filter(n=>isNaN(Number(n))&&n!=="DefinedName").map(n=>({label:t.t(`formula.functionType.${n.toLocaleLowerCase()}`),value:`${e[n]}`}))}function kt(e){if(!e.require&&!e.repeat)return`[${e.name}]`;if(e.require&&!e.repeat)return e.name;if(!e.require&&e.repeat)return`[${e.name},...]`;if(e.require&&e.repeat)return`${e.name},...`}const Rn=(e,t=100)=>{p.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 Lt(e,t,n){const s=l.useDependency(J.IEditorService),r=p.useMemo(()=>new K.BehaviorSubject({left:-999,top:-999,right:-999,bottom:-999}),[]),o=l.useDependency(l.ISidebarService),i=l.useDependency(a.IUniverInstanceService),c=l.useEvent(()=>{var I;const d=s.getEditor(e);if(!d)return;const f=d.getBoundingClientRect(),{marginTop:m=0,marginBottom:S=0}=d.getDocumentData().documentStyle,h=d.getSkeleton();if(!h)return;const g=(I=h.getSkeletonData())==null?void 0:I.pages[0].height;let{left:u,top:_,right:v,bottom:C}=f;_=_+m,C=g?_+g:C-S;const R=r.getValue();if(!(R.left===u&&R.top===_&&R.right===v&&R.bottom===C))return r.next({left:u-1,right:v+1,top:_-1,bottom:C+1}),f});return p.useEffect(()=>{t&&c()},[e,s,i.unitAdded$,c,t,...n!=null?n:[]]),Rn(c),p.useEffect(()=>{const d=o.scrollEvent$.pipe(K.throttleTime(100)).subscribe(c);return()=>{d.unsubscribe()}},[]),[r,c]}const Te=e=>{const t=p.useRef(e);return t.current=e,t},En=(e,t,n)=>{const s=l.useDependency(ye.IDescriptionService),r=l.useDependency(T.LexerTreeBuilder),[o,i]=p.useState(),[c,d]=p.useState(-1),[f,m]=p.useState(!0),S=Te(f),h=p.useRef(t);h.current=t;const g=()=>{i(void 0),d(-1),m(!1)};return p.useEffect(()=>{if(n&&e){const u=n.selectionChange$.pipe(K.debounceTime(50)).subscribe(v=>{if(v.textRanges.length===1){const[C]=v.textRanges;if(C.collapsed&&S.current){const R=r.getFunctionAndParameter(`${h.current}A`,C.startOffset-1);if(R){const{functionName:I,paramIndex:E}=R,b=s.getFunctionInfo(I);i(b),d(E);return}}}i(void 0),d(-1)}),_=n.selectionChange$.pipe(K.filter(v=>v.isEditing),K.filter(v=>v.textRanges.length===1),K.map(v=>v.textRanges[0].startOffset),K.distinctUntilChanged()).subscribe(()=>{m(!0)});return()=>{u.unsubscribe(),_.unsubscribe()}}},[n,e]),p.useEffect(()=>{e||g()},[e]),{functionInfo:o,paramIndex:c,reset:g}},yn=({onClick:e})=>y.jsx("div",{className:"univer-z-[15] univer-box-border univer-h-[18px] univer-cursor-pointer univer-overflow-visible univer-whitespace-nowrap univer-rounded-l univer-border univer-border-r-0 univer-border-gray-600 univer-bg-primary-600 univer-p-0.5 univer-text-xs univer-font-bold univer-leading-[13px] univer-text-white",onClick:e,children:"?"}),Je=({className:e,title:t,value:n})=>y.jsxs("div",{className:"univer-my-2",children:[y.jsx("div",{className:W.clsx("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:univer-text-white",e),children:t}),y.jsx("div",{className:"univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",children:n})]}),In=e=>{const{prefix:t,value:n,active:s,onClick:r}=e;return y.jsxs("div",{children:[y.jsxs("span",{children:[t,"("]}),n&&n.map((o,i)=>y.jsxs("span",{children:[y.jsx("span",{className:s===i?"univer-text-primary-500":"",onClick:()=>r(i),children:kt(o)}),i===n.length-1?"":","]},o.name)),")"]})},mt=()=>{};function bn(e){const{onParamsSwitch:t=mt,onClose:n=mt,isFocus:s,editor:r,formulaText:o}=e,{functionInfo:i,paramIndex:c,reset:d}=En(s,o,r),f=p.useMemo(()=>!!i&&c>=0,[i,c]),m=l.useDependency(w.IEditorBridgeService),S=!l.useObservable(m.helpFunctionVisible$),[h,g]=p.useState(!0),u=l.useDependency(a.LocaleService),_=u.t("formula.prompt.required"),v=u.t("formula.prompt.optional"),C=r.getEditorId(),[R]=Lt(C,f,[i,c]);function I(M){t&&t(M)}const E=l.useEvent(M=>{m.helpFunctionVisible$.next(!M)}),b=()=>{E(!0),n()};return f&&i?S?y.jsx(l.RectPopup,{portal:!0,anchorRect$:R,direction:"left-center",children:y.jsx(yn,{onClick:()=>E(!1)})},"hidden"):y.jsx(l.RectPopup,{portal:!0,onClickOutside:()=>d(),anchorRect$:R,direction:"vertical",children:y.jsxs("div",{className:W.clsx("univer-m-0 univer-box-border univer-w-[250px] univer-select-none univer-list-none univer-rounded-lg univer-bg-white univer-leading-5 univer-shadow-md univer-outline-none",W.borderClassName),children:[y.jsxs("div",{className:W.clsx("univer-box-border univer-flex univer-items-center univer-justify-between univer-px-4 univer-py-3 univer-text-xs univer-font-medium univer-text-gray-900 univer-wrap-anywhere dark:univer-text-white",W.borderTopClassName),children:[y.jsx(In,{prefix:i.functionName,value:i.functionParameter,active:c,onClick:I}),y.jsxs("div",{className:"univer-flex",children:[y.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-500 univer-outline-none univer-transition-colors hover:univer-bg-gray-200",style:{transform:h?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>g(!h),children:y.jsx(wt,{})}),y.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-600 univer-outline-none univer-transition-colors dark:univer-text-gray-200 hover:univer-bg-gray-300",onClick:b,children:y.jsx(Nt,{})})]})]}),y.jsx("div",{className:"univer-box-border univer-max-h-[350px] univer-overflow-y-auto univer-px-4 univer-pb-3 univer-pt-0",style:{height:h?"unset":0,padding:h?"revert-layer":0},children:y.jsxs("div",{className:"univer-mt-3",children:[y.jsx(Je,{title:u.t("formula.prompt.helpExample"),value:`${i.functionName}(${i.functionParameter.map(M=>M.example).join(",")})`}),y.jsx(Je,{title:u.t("formula.prompt.helpAbstract"),value:i.description}),i&&i.functionParameter&&i.functionParameter.map((M,F)=>y.jsx(Je,{className:c===F?"univer-text-primary-500":"",title:M.name,value:`${M.require?_:v} ${M.detail}`},F))]})})]})},"show"):null}const Tn=e=>{const t=l.useDependency(J.IEditorService);return l.useEvent(s=>{var r,o;if(e){t.focus(e.getEditorId());const i=[...e.getSelectionRanges()];if(a.Tools.isDefine(s))e.setSelectionRanges([{startOffset:s,endOffset:s}]);else if(!i.length&&!e.docSelectionRenderService.isOnPointerEvent){const c=(o=(r=e.getDocumentData().body)==null?void 0:r.dataStream)!=null?o:`\r
|
|
2
|
-
`,d=Math.max(c.length-2,0);e.setSelectionRanges([{startOffset:d,endOffset:d}])}else e.setSelectionRanges(i)}})};var xn=Object.getOwnPropertyDescriptor,Mn=(e,t,n,s)=>{for(var r=s>1?void 0:s?xn(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Ne=(e,t)=>(n,s)=>t(n,s,e);exports.RefSelectionsRenderService=class extends w.BaseSelectionRenderService{constructor(n,s,r,o,i,c,d){super(s,r,o,i,c);q(this,"_workbookSelections");q(this,"_eventDisposables");this._context=n,this._contextService=c,this._refSelectionsService=d,this._workbookSelections=this._refSelectionsService.getWorkbookSelections(this._context.unitId),this._initSelectionChangeListener(),this._initSkeletonChangeListener(),this._initUserActionSyncListener(),this._setSelectionStyle(On(this._themeService)),this._remainLastEnabled=!0,this._highlightHeader=!1}getLocation(){return this._skeleton.getLocation()}setRemainLastEnabled(n){this._remainLastEnabled=n}setSkipLastEnabled(n){this._skipLastEnabled=n}clearLastSelection(){const n=this._selectionControls[this._selectionControls.length-1];n&&(n.dispose(),this._selectionControls.pop())}enableSelectionChanging(){return this._disableSelectionChanging(),this._eventDisposables=this._initCanvasEventListeners(),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((f,m)=>{this.inRefSelectionMode()&&(this._onPointerDown(f,o.zIndex+1,a.RANGE_TYPE.NORMAL,this._getActiveViewport(f)),f.button!==2&&m.stopPropagation())})),d.add(s==null?void 0:s.onPointerDown$.subscribeEvent((f,m)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:h}=w.getCoordByOffset(f.offsetX,f.offsetY,c,S);w.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,a.RANGE_TYPE.ROW)||(this._onPointerDown(f,(o.zIndex||1)+1,a.RANGE_TYPE.ROW,this._getActiveViewport(f),H.ScrollTimerType.Y),f.button!==2&&m.stopPropagation())})),d.add(r==null?void 0:r.onPointerDown$.subscribeEvent((f,m)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:h}=w.getCoordByOffset(f.offsetX,f.offsetY,c,S);w.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,a.RANGE_TYPE.COLUMN)||(this._onPointerDown(f,(o.zIndex||1)+1,a.RANGE_TYPE.COLUMN,this._getActiveViewport(f),H.ScrollTimerType.X),f.button!==2&&m.stopPropagation())})),d.add(i==null?void 0:i.onPointerDown$.subscribeEvent((f,m)=>{if(this._reset(),!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,h=w.getAllSelection(S);this._addSelectionControlByModelData(h),this._selectionMoveStart$.next(this.getSelectionDataWithStyle());const g=c.onPointerUp$.subscribeEvent(()=>{g.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});f.button!==2&&m.stopPropagation()})),d}_addSelectionControlByModelData(n){var c;const s=this._skeleton,r=(c=n.style)!=null?c:w.genNormalSelectionStyle(this._themeService),o=this._scene;return n.style=r,this.newSelectionControl(o,s,n)}_initSelectionChangeListener(){this.disposeWithMe(this._refSelectionsService.selectionSet$.subscribe(n=>{this._reset(),this._skeleton&&this.resetSelectionsByModelData(n||[])}))}_initUserActionSyncListener(){this.disposeWithMe(this.selectionMoveStart$.subscribe(n=>{this._updateSelections(n,$.SelectionMoveType.MOVE_START)})),this.disposeWithMe(this.selectionMoving$.subscribe(n=>{this._updateSelections(n,$.SelectionMoveType.MOVING)})),this.disposeWithMe(this.selectionMoveEnd$.subscribe(n=>{this._updateSelections(n,$.SelectionMoveType.MOVE_END)}))}_updateSelections(n,s){const o=this._context.unit.getActiveSheet().getSheetId();n.length!==0&&this._workbookSelections.setSelections(o,n.map(i=>$.convertSelectionDataToRange(i)),s)}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(n=>{if(!n)return;const{skeleton:s}=n,{scene:r}=this._context,o=r.getViewport(H.SHEET_VIEWPORT_KEY.VIEW_MAIN);this._skeleton&&this._skeleton.worksheet.getSheetId()!==s.worksheet.getSheetId()&&this._reset(),this._changeRuntime(s,r,o);const i=this._workbookSelections.getCurrentSelections();this.resetSelectionsByModelData(i)}))}_getActiveViewport(n){const s=this._getSheetObject();return s==null?void 0:s.scene.getActiveViewportByCoord(H.Vector2.FromArray([n.offsetX,n.offsetY]))}_getSheetObject(){return w.getSheetObject(this._context.unit,this._context)}_onPointerDown(n,s=0,r=a.RANGE_TYPE.NORMAL,o,i=H.ScrollTimerType.ALL){var j;this._rangeType=r;const c=this._skeleton,d=this._scene;if(!d||!c)return;o&&(this._activeViewport=o);const{offsetX:f,offsetY:m}=n,S=d.getViewport(H.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!S)return;const h=d.getCoordRelativeToViewport(H.Vector2.FromArray([f,m])),{x:g,y:u}=h;this._startViewportPosX=g,this._startViewportPosY=u;const _=d.getScrollXYInfoByViewport(h),{scaleX:v,scaleY:C}=d.getAncestorScale(),R=this._skeleton.getCellByOffset(g,u,v,C,_);if(!R)return;switch(r){case a.RANGE_TYPE.NORMAL:break;case a.RANGE_TYPE.ROW:R.startColumn=0,R.endColumn=this._skeleton.getColumnCount()-1;break;case a.RANGE_TYPE.COLUMN:R.startRow=0,R.endRow=this._skeleton.getRowCount()-1;break;case a.RANGE_TYPE.ALL:R.startRow=0,R.startColumn=0,R.endRow=this._skeleton.getRowCount()-1,R.endColumn=this._skeleton.getColumnCount()-1}const I={range:R,primary:R,style:null};I.range.rangeType=r;const E=w.attachSelectionWithCoord(I,this._skeleton);this._startRangeWhenPointerDown={...E.rangeWithCoord};const b={...E.rangeWithCoord,rangeType:r};let M=this.getActiveSelectionControl();const F=this.getSelectionControls();for(const D of F){if(n.button===2&&a.Rectangle.contains(D.model,b)){M=D;return}if(D.model.isEqual(b)){M=D;break}}this._checkClearPreviousControls(n);const L=M==null?void 0:M.model.currentCell,P=n.shiftKey&&L,A=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;P&&L?this._makeSelectionByTwoCells(L,b,c,r,M):A&&M?M.updateRangeBySelectionWithCoord(E):M=this.newSelectionControl(d,c,I);for(let D=0;D<this.getSelectionControls().length-1;D++)this.getSelectionControls()[D].clearHighlight();this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),d.disableObjectsEvent(),this._clearUpdatingListeners(),this._addEndingListeners(),(j=d.getTransformer())==null||j.clearSelectedObjects(),this._setupPointerMoveListener(S,M,r,i,g,u),this._escapeShortcutDisposable=this._shortcutService.forceEscape(),this._scenePointerUpSub=d.onPointerUp$.subscribeEvent(()=>{var D;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(D=this._escapeShortcutDisposable)==null||D.dispose(),this._escapeShortcutDisposable=null})}newSelectionControl(n,s,r){const o=this.getSelectionControls().length,{rowHeaderWidth:i,columnHeaderHeight:c}=s,d=new w.SelectionControl(n,o,this._themeService,{highlightHeader:this._highlightHeader,enableAutoFill:!1,rowHeaderWidth:i,columnHeaderHeight:c}),f=w.attachSelectionWithCoord(r,s);return d.updateRangeBySelectionWithCoord(f),this._selectionControls.push(d),d.setControlExtension({skeleton:s,scene:n,themeService:this._themeService,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),d}};exports.RefSelectionsRenderService=Mn([Ne(1,a.Inject(a.Injector)),Ne(2,a.Inject(a.ThemeService)),Ne(3,l.IShortcutService),Ne(4,a.Inject(w.SheetSkeletonManagerService)),Ne(5,a.IContextService),Ne(6,$.IRefSelectionsService)],exports.RefSelectionsRenderService);function On(e){const t=w.genNormalSelectionStyle(e);return t.widgets={tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},t}function Nn(e){var r,o;const n=e.get(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 Se=(e=>(e[e.NOT_SELECT=0]="NOT_SELECT",e[e.NEED_ADD=1]="NEED_ADD",e[e.CAN_EDIT=2]="CAN_EDIT",e[e.EDIT_OTHER_SHEET_REFERENCE=3]="EDIT_OTHER_SHEET_REFERENCE",e))(Se||{});function Dn(e){var F;const{editorId:t,isFocus:n,disableOnClick:s,unitId:r,subUnitId:o}=e,i=l.useDependency(H.IRenderManagerService),c=l.useDependency(a.IUniverInstanceService),d=i.getRenderById(r),f=i.getRenderById(t),m=f==null?void 0:f.with(J.DocSelectionRenderService),S=l.useDependency(Rt.DocSelectionManagerService),h=l.useDependency(a.Injector),[g,u]=p.useState(0),_=l.useDependency(T.LexerTreeBuilder),v=p.useRef(!0),C=d==null?void 0:d.with(exports.RefSelectionsRenderService),R=Te(g),I=c.getUnit(r,a.UniverInstanceType.UNIVER_SHEET),E=I==null?void 0:I.getSheetBySheetId(o),b=l.useEvent(L=>{C&&C.setSkipLastEnabled(L===1||L===3),R.current=L,u(L)}),M=l.useEvent(()=>{var B,ne;if(!I)return;const L=I.getActiveSheet(),P=m==null?void 0:m.getActiveTextRange(),A=P!=null&&P.collapsed?P.startOffset:-1,j=Nn(h);if(!j)return;const D=(B=j==null?void 0:j.dataStream)==null?void 0:B.slice(0,-2),O=((ne=_.sequenceNodesBuilder(D))!=null?ne:[]).map(Y=>typeof Y=="object"?Y.nodeType===T.sequenceNodeType.REFERENCE?{...Y,range:T.deserializeRangeWithSheetWithCache(Y.token)}:{...Y,range:void 0}:Y),x=D[A-1],N=D[A],k=O.find(Y=>typeof Y=="object"&&Y.nodeType===T.sequenceNodeType.REFERENCE&&A===Y.endIndex+2),U=x&&T.matchRefDrawToken(x)&&(!N||T.isFormulaLexerToken(N)&&N!==T.matchToken.OPEN_BRACKET),V=!!k;if((D==null?void 0:D.substring(0,1))==="="&&(U||V))if(V){if(v.current)return;!k.range.sheetName&&L.getSheetId()===(E==null?void 0:E.getSheetId())||k.range.sheetName===L.getName()?b(2):b(3)}else v.current=!1,b(1);else b(0)});return p.useEffect(()=>{const L=S.textSelection$.pipe(K.filter(P=>P.unitId===t)).subscribe(()=>{M()});return()=>L.unsubscribe()},[M,S.textSelection$,t]),p.useEffect(()=>{n||(b(0),v.current=!0)},[n,b]),p.useEffect(()=>{var P;if(!s)return;const L=(P=f==null?void 0:f.mainComponent)==null?void 0:P.onPointerDown$.subscribeEvent(()=>{b(0),v.current=!0});return()=>L==null?void 0:L.unsubscribe()},[s,(F=f==null?void 0:f.mainComponent)==null?void 0:F.onPointerDown$,b]),p.useEffect(()=>{if(!n)return;const L=I==null?void 0:I.activeSheet$.subscribe(()=>{M()});return()=>L==null?void 0:L.unsubscribe()},[M,n,I==null?void 0:I.activeSheet$]),{isSelecting:g,isSelectingRef:R}}const An=()=>{const e=l.useDependency(T.LexerTreeBuilder);return p.useCallback(n=>e.sequenceNodesBuilder(n)||[],[e])};function wn(e,t,n){const s=new a.ColorKit(t).setAlpha(.05).toRgbString();return{id:n,strokeWidth:1,stroke:e.getColorFromTheme(t),fill:s,widgets:{tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},widgetSize:6,widgetStrokeWidth:1,widgetStroke:e.getColorFromTheme("white")}}function Pt(e){var I,E,b;const{unitId:t,subUnitId:n,currentWorkbook:s,refSelections:r,editor:o,refSelectionsService:i,refSelectionsRenderService:c,sheetSkeletonManagerService:d,themeService:f,univerInstanceService:m}=e,S=s.getUnitId(),h=m.getUnit(t,a.UniverInstanceType.UNIVER_SHEET),g=h==null?void 0:h.getActiveSheet(),u=[];if(!h||!g){i.setSelections(u);return}const _=g.getSheetId(),v=M=>{var F;return(F=h==null?void 0:h.getSheetBySheetName(M))==null?void 0:F.getSheetId()};if(!((I=d==null?void 0:d.getWorksheetSkeleton(_))==null?void 0:I.skeleton))return;const R=[];for(let M=0,F=r.length;M<F;M++){const L=r[M],{themeColor:P,token:A,refIndex:j,endIndex:D}=L,O=T.deserializeRangeWithSheet(A),{unitId:x,sheetName:N,range:k}=O,U=v(N);if(S!==t&&x!==S||x&&x!==S||U&&U!==_||!U&&_!==n)continue;const V=$.setEndForRange(k,g.getRowCount(),g.getColumnCount());V.unitId=t,V.sheetId=_,u.push({range:V,primary:null,style:wn(f,P,j.toString())}),R.push(D)}if(o){const M=(b=(E=o.getSelectionRanges())==null?void 0:E[0])==null?void 0:b.startOffset,F=R.findIndex(L=>L+2===M);F!==-1?c==null||c.setActiveSelectionIndex(F):c==null||c.resetActiveSelectionIndex()}return u}function Fn(e,t){const n=l.useDependency(a.IUniverInstanceService),s=l.useDependency(a.ThemeService),r=l.useDependency($.IRefSelectionsService),i=l.useDependency(H.IRenderManagerService).getRenderById(e),c=i==null?void 0:i.with(exports.RefSelectionsRenderService),d=i==null?void 0:i.with(w.SheetSkeletonManagerService),f=l.useEvent((m,S)=>{const h=n.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET);if(!h||c!=null&&c.selectionMoving)return;const g=Pt({unitId:e,subUnitId:t,currentWorkbook:h,refSelections:m,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 p.useEffect(()=>()=>{c==null||c.resetActiveSelectionIndex()},[c]),f}function jt(e=""){const t=l.useDependency(ye.IDescriptionService),n=kn(),s=l.useDependency(a.ICommandService),r=p.useMemo(()=>e.length,[e]);return l.useEvent((i,c,d=!0,f)=>{const m=i.getDocumentData(),S=i.getEditorId();if(!m)return[];const h=m.body;if(!h)return[];const g=h.dataStream.slice(0,h.dataStream.length-2),u={dataStream:"",...m.body};if(!g.startsWith(e))return[];if(c==null||c.length===0)return u.textRuns=[],s.syncExecuteCommand(J.ReplaceTextRunsCommand.id,{unitId:S,body:a.getBodySlice(u,0,u.dataStream.length-2)}),[];{const{textRuns:_,refSelections:v}=Ln(t,n,c);r&&_.forEach(I=>{I.ed=I.ed+r,I.st=I.st+r}),u.textRuns=[{st:0,ed:1,ts:{fs:11}},..._];const C=c.reduce((I,E)=>typeof E=="string"?`${I}${E}`:`${I}${E.token}`,"");u.dataStream=`${e}${C}\r
|
|
3
|
-
`;let R;if(d){R=i.getSelectionRanges();const I=u.dataStream.length-2+r;R.forEach(E=>{E.startOffset=Math.max(0,Math.min(E.startOffset,I)),E.endOffset=Math.max(0,Math.min(E.endOffset,I))})}return s.syncExecuteCommand(
|
|
4
|
-
`).slice(0,-2),c=(h=n.sequenceNodesBuilder(i.slice(1)))!=null?h:[],d=ot(c,o,!1),f=xt(c,d);return{nodeIndex:d,updatingRefIndex:f,sequenceNodes:c,offset:o}},Wn=()=>{},Bn=(e,t,n,s,r,o,i,c,d,f=Wn)=>{var j;const m=l.useDependency(H.IRenderManagerService),S=l.useDependency(a.IUniverInstanceService),h=l.useDependency(a.ICommandService),g=l.useDependency(Rt.DocSelectionManagerService),u=l.useDependency(a.ThemeService),_=l.useDependency(T.LexerTreeBuilder),v=S.getUnit(s),C=l.useEvent(D=>{var O,x;return(x=(O=v==null?void 0:v.getSheetBySheetId(D))==null?void 0:O.getName())!=null?x:""}),R=p.useMemo(()=>C(r),[C,r]),I=l.useObservable(v==null?void 0:v.activeSheet$),E=Te({activeSheet:I,sheetName:R}),b=l.useObservable(p.useMemo(()=>S.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[S])),M=m.getRenderById((j=b==null?void 0:b.getUnitId())!=null?j:""),F=M==null?void 0:M.with(exports.RefSelectionsRenderService),L=M==null?void 0:M.with(w.SheetSkeletonManagerService),P=l.useDependency($.IRefSelectionsService),A=l.useEvent((D,O)=>{var B,ne,Y,le,xe,ee;const x=Vn({editor:d,lexerTreeBuilder:_});if(!x)return;const{nodeIndex:N,updatingRefIndex:k,sequenceNodes:U,offset:V}=x;if(n.current===Se.NEED_ADD)if(V!==0){if(N===-1&&U.length)return;const Z=D[D.length-1],X=U.splice(N+1),ie=(B=Z.sheetId)!=null?B:r,Q={range:Z,unitId:(ne=Z.unitId)!=null?ne:b.getUnitId(),sheetName:C(ie)},ce=ie!==r,re=(b==null?void 0:b.getUnitId())!==s,Me=je([Q],i&&(ce||re),R,re);U.push({token:Me[0],nodeType:T.sequenceNodeType.REFERENCE});const ve=[...U,...X],oe=tt(ve);f(oe,$n(U),O)}else{const Z=D[D.length-1],X=(Y=Z.sheetId)!=null?Y:r,ie={range:Z,unitId:(le=Z.unitId)!=null?le:s,sheetName:C(X)},ce=je([ie],i&&X!==r);U.unshift({token:ce[0],nodeType:T.sequenceNodeType.REFERENCE});const re=tt(U);f(re,ce[0].length,O)}else if(n.current===Se.EDIT_OTHER_SHEET_REFERENCE){const Z=D.pop();if(!Z)return;const X=U[N];if(typeof X=="object"&&X.nodeType===T.sequenceNodeType.REFERENCE){const ie=X.token;X.token=R===(I==null?void 0:I.getName())?T.serializeRange(Z):T.serializeRangeWithSheet(I.getName(),Z);const Q=V+(X.token.length-ie.length);f(T.generateStringWithSequence(U),Q,O)}}else{const Z=[...D];if(k!==-1){const G=Z.pop();G&&Z.splice(k,0,G)}let X=0;const ie=U.map(G=>{var ae,ue,fe;if(typeof G=="string")return G;if(G.nodeType===T.sequenceNodeType.REFERENCE){const pe=T.deserializeRangeWithSheet(G.token);if(pe.sheetName||(pe.sheetName=R),i&&((ae=E.current.activeSheet)==null?void 0:ae.getName())!==pe.sheetName)return G.token;const de=Z[X];if(X++,!de)return"";const Ze=(ue=de.sheetId)!=null?ue:r,Xe={range:de,unitId:(fe=de.unitId)!=null?fe:s,sheetName:C(Ze)};return je([Xe],i,R)[0]}return G.token});let Q="",ce;ie.forEach((G,ae)=>{Q+=G,ae===N&&(ce=Q.length)});const re=[];for(let G=X;G<=D.length-1;G++){const ae=D[G],ue=(xe=ae.sheetId)!=null?xe:r,fe={range:ae,unitId:(ee=ae.unitId)!=null?ee:s,sheetName:C(ue)},de=je([fe],i&&ue!==r,R);re.push(de[0])}const Me=U[U.length-1],ve=Me&&(typeof Me=="string"?!1:Me.nodeType===T.sequenceNodeType.REFERENCE),oe=`${Q}${re.length&&ve?",":""}${re.join(",")}`;f(oe,!re.length&&ce?ce:oe.length,O)}});p.useEffect(()=>{if(F&&e){let D=!0;const O=(N,k)=>{if(D){D=!1;return}A(N.map(U=>U.rangeWithCoord),k)},x=new a.DisposableCollection;return x.add(F.selectionMoving$.subscribe(N=>{O(N,!1)})),x.add(F.selectionMoveEnd$.subscribe(N=>{O(N,!0)})),()=>{x.dispose()}}},[e,A,F]),p.useEffect(()=>{if(t&&F&&d){const D=new a.DisposableCollection,O=()=>{D.dispose(),F.getSelectionControls().forEach((k,U)=>{D.add(k.selectionScaling$.subscribe(V=>{const B=F.getSelectionDataWithStyle().map(Y=>Y.rangeWithCoord),ne=B[U];V.sheetId=ne.sheetId,V.unitId=ne.unitId,B[U]=V,A(B,!1)})),D.add(k.selectionMoving$.subscribe(V=>{const B=F.getSelectionDataWithStyle().map(Y=>Y.rangeWithCoord),ne=B[U];V.sheetId=ne.sheetId,V.unitId=ne.unitId,B[U]=V,A(B,!0)}))})},x=K.merge(d.input$,P.selectionSet$,F.selectionMoveEnd$).pipe(Qt.debounceTime(50)).subscribe(()=>{O()});return()=>{x.unsubscribe(),D.dispose()}}},[d,t,A,F,P.selectionSet$]),F==null||F.getSelectionDataWithStyle(),p.useEffect(()=>{if(c){const D=h.onCommandExecuted(O=>{var N;if(O.id!==$.SetSelectionsOperation.id)return;const x=O.params;if(x.extra==="formula-editor"&&x.selections.length){const k=x.selections[x.selections.length-1];if(k){const U=n.current===Se.NEED_ADD,V=((N=F==null?void 0:F.getSelectionDataWithStyle())!=null?N:[]).map(B=>B.rangeWithCoord);U?V.push(k.range):V[V.length-1]=k.range,A(V,!0)}}});return()=>{D.dispose()}}},[h,d,n,_,c,A,F]),p.useEffect(()=>{if(!d)return;const D=g.textSelection$.subscribe(O=>{O.unitId===d.getEditorId()&&Pt({unitId:s,subUnitId:r,refSelections:o.current,editor:d,refSelectionsService:P,refSelectionsRenderService:F,sheetSkeletonManagerService:L,themeService:u,univerInstanceService:S,currentWorkbook:b})});return()=>D.unsubscribe()},[g.textSelection$,d,o,F,P,L,r,u,s,S])},Hn=(e,t,n,s,r,o)=>{const i=l.useDependency(a.ICommandService),c=l.useDependency(J.IEditorService),f=l.useDependency(H.IRenderManagerService).getRenderById(t),m=l.useDependency(a.IUniverInstanceService),S=f==null?void 0:f.with(exports.RefSelectionsRenderService);p.useEffect(()=>{if(e&&S)if(n){const h=()=>{const _=S.getSelectionControls().length;for(let v=1;v<=_;v++)S.clearLastSelection();return setTimeout(()=>{o()},30)},g=i.onCommandExecuted(_=>{_.id===$.SetWorksheetActiveOperation.id&&h()}),u=m.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(_=>{h()});return()=>{g.dispose(),u.unsubscribe()}}else{const h=i.beforeCommandExecuted(g=>{if(g.id===$.SetWorksheetActiveOperation.id){s(!1),r(),o();const u=c.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);u==null||u.focus()}});return()=>{h.dispose()}}},[e,S])},Kn=(e,t,n)=>{const s=l.useDependency(T.LexerTreeBuilder),r=p.useRef(!0);p.useEffect(()=>{if(e){const o=setTimeout(()=>{r.current=!1},500);return()=>{clearTimeout(o)}}},[e]),p.useEffect(()=>{if(!r.current&&t){const o=s.checkIfAddBracket(n);t(o===0&&n.startsWith(T.operatorToken.EQUALS),`${n}`)}},[n,t])},qn=(e,t=[],n)=>{const s=l.useDependency(ye.IDescriptionService),[r,o]=p.useState([]),[i,c]=p.useState(""),d=p.useRef(-1),f=Te({nodes:t}),m=()=>{o([]),c(""),d.current=-1};return p.useEffect(()=>{if(n&&e){const h=n.input$.pipe(K.debounceTime(300)).subscribe(()=>{const g=n.getSelectionRanges();if(g.length===1){const u=f.current.nodes,_=g[0];if(_.collapsed){const v=ot(u,_.startOffset-1,!1);d.current=v;const C=u[v];if(C&&typeof C!="string"&&C.nodeType===T.sequenceNodeType.FUNCTION){d.current=v;const R=C.token,I=s.getSearchListByNameFirstLetter(R);o(I),c(R);return}}}d.current=-1,c(""),o(u=>u!=null&&u.length?[]:u)});return()=>{h.unsubscribe()}}},[n,e]),p.useEffect(()=>{e||m()},[e]),{searchList:r,searchText:i,handlerFormulaReplace:h=>{const g=[...f.current.nodes];if(d.current!==-1){const u=g.splice(d.current+1),_=g.pop()||"";let v=(typeof _=="string"?_.length:_.token.length)-h.length;return g.push(h),u[0]!==T.matchToken.OPEN_BRACKET&&(g.push(T.matchToken.OPEN_BRACKET),v--),{text:tt([...g,...u]),offset:v}}},reset:m}},Yn=()=>{},zn=p.forwardRef(Gn);function Gn(e,t){const{isFocus:n,sequenceNodes:s,onSelect:r,editor:o,onClose:i=Yn}=e,c=o.getEditorId(),d=l.useDependency(l.IShortcutService),f=l.useDependency(a.ICommandService),{searchList:m,searchText:S,handlerFormulaReplace:h,reset:g}=qn(n,s,o),u=p.useMemo(()=>!!m.length,[m]),_=p.useRef(void 0),[v,C]=p.useState(0),R=p.useRef(!1),[I]=Lt(c,u,[S,m]),E=Te({searchList:m,active:v}),b=A=>{const j=h(A);j&&(g(),r(j))};function M(A){R.current&&C(A)}function F(){R.current&&C(-1)}p.useEffect(()=>{if(!m.length)return;const A=`sheet.formula-embedding-editor.search_function.${c}`,j=new a.DisposableCollection,D=O=>{const{searchList:x,active:N}=E.current;switch(O){case l.KeyCode.ARROW_UP:{C(k=>{const U=Math.max(0,k-1);return L(U),U});break}case l.KeyCode.ARROW_DOWN:{C(k=>{const U=Math.min(x.length-1,k+1);return L(U),U});break}case l.KeyCode.TAB:case l.KeyCode.ENTER:{const k=x[N];b(k.name);break}case l.KeyCode.ESC:{g(),i();break}}};return j.add(f.registerCommand({id:A,type:a.CommandType.OPERATION,handler(O,x){const{keyCode:N}=x;D(N)}})),[l.KeyCode.ARROW_UP,l.KeyCode.ARROW_DOWN,l.KeyCode.ENTER,l.KeyCode.ESC,l.KeyCode.TAB].map(O=>({id:A,binding:O,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keyCode:O}})).forEach(O=>{j.add(d.registerShortcut(O))}),()=>{j.dispose()}},[m]);function L(A){const j=_.current;if(!j)return;const D=j.children[A];if(!D)return;const x=j.getBoundingClientRect().top,N=j.offsetHeight,k=D.getBoundingClientRect(),U=k.top,V=k.height;if(U>=0&&U>x&&U-x+V<=N)return;const B=D.offsetTop-(N-V)/2;j.scrollTo({top:B,behavior:"smooth"})}const P=p.useMemo(()=>{let A="";return()=>{clearTimeout(A),R.current=!0,A=setTimeout(()=>{R.current=!1},300)}},[]);return m.length>0&&u&&y.jsx(l.RectPopup,{portal:!0,anchorRect$:I,direction:"vertical",children:y.jsx("ul",{ref:A=>{_.current=A,t&&(t.current=A)},className:W.clsx("univer-m-0 univer-box-border univer-max-h-[400px] univer-w-[250px] univer-list-none univer-overflow-y-auto univer-rounded-lg univer-bg-white univer-p-2 univer-leading-5 univer-shadow-md univer-outline-none",W.borderClassName,W.scrollbarClassName),children:m.map((A,j)=>y.jsxs("li",{className:W.clsx("univer-box-border univer-cursor-pointer univer-rounded univer-px-2 univer-py-1 univer-text-gray-900 univer-transition-colors dark:univer-text-white",{"univer-bg-gray-200 dark:univer-bg-gray-600":v===j}),onMouseEnter:()=>M(j),onMouseLeave:F,onMouseMove:P,onClick:()=>{b(A.name),o&&o.focus()},children:[y.jsxs("span",{className:"univer-text-xs",children:[y.jsx("span",{className:"univer-text-red-500",children:A.name.substring(0,S.length)}),y.jsx("span",{children:A.name.slice(S.length)})]}),y.jsx("span",{className:"univer-block univer-text-xs univer-text-gray-400",children:A.desc})]},A.name))})})}const Zn=e=>e.startsWith(T.operatorToken.EQUALS)?e.slice(1):"",St=()=>{},Ut=p.forwardRef((e,t)=>{var lt,ut;const{errorText:n,initValue:s,unitId:r,subUnitId:o,isFocus:i=!0,isSupportAcrossSheet:c=!1,onFocus:d=St,onBlur:f=St,onChange:m,onVerify:S,className:h,editorId:g,moveCursor:u=!0,onFormulaSelectingChange:_,keyboardEventConfig:v,onMoveInEditor:C,resetSelectionOnBlur:R=!0,autoScrollbar:I=!0,isSingle:E=!0,disableSelectionOnClick:b=!1,autofocus:M=!0,disableContextMenu:F,style:L}=e,P=l.useDependency(J.IEditorService),A=p.useRef(null),j=l.useEvent(m);p.useImperativeHandle(t,()=>({isClickOutSide:z=>A.current?!A.current.contains(z.target):!1}));const D=l.useEvent(_),O=p.useRef(null),x=p.useRef(void 0),N=x.current,[k,U]=p.useState(i),V=p.useRef(null),B=p.useMemo(()=>g!=null?g:a.createInternalEditorID(`${w.EMBEDDING_FORMULA_EDITOR}-${a.generateRandomId(4)}`),[]),ne=p.useMemo(()=>n!==void 0,[n]),Y=l.useDependency(a.IUniverInstanceService),le=Y.getUnit(B);l.useObservable(le==null?void 0:le.change$);const xe=An(),ee=a.BuildTextUtils.transform.getPlainText((ut=(lt=le==null?void 0:le.getBody())==null?void 0:lt.dataStream)!=null?ut:""),Z=Te(ee),X=p.useMemo(()=>Zn(ee),[ee]),ie=p.useMemo(()=>xe(X),[X,xe]),{isSelecting:Q,isSelectingRef:ce}=Dn({unitId:r,subUnitId:o,editorId:B,isFocus:k,disableOnClick:b}),re=p.useRef(""),ve=l.useDependency(H.IRenderManagerService).getRenderById(B),oe=ve==null?void 0:ve.with(J.DocSelectionRenderService),G=oe==null?void 0:oe.isFocusing,ae=p.useMemo(()=>Y.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC),[Y]),ue=l.useObservable(ae),fe=(ue==null?void 0:ue.getUnitId())===B,pe=p.useRef([]),de=Q;l.useUpdateEffect(()=>{j(ee)},[ee,j]);const Ze=jt("="),Xe=Fn(r,o),Ce=l.useEvent((z,te=!0,ge,he)=>{if(!x.current)return;re.current=z;const ke=z[0]==="="?z.slice(1):"",me=xe(ke),zt=me.reduce((_e,Pe)=>typeof Pe=="object"?`${_e}${Pe.token}`:`${_e}${Pe}`,""),Le=Ze(x.current,zt===ke?me:[],te,he);if(pe.current=Le,ge){const _e=he!=null?he:N==null?void 0:N.getSelectionRanges();if((_e==null?void 0:_e.length)!==1)return;const Gt=_e[0].startOffset-1,Zt=ot(me,Gt,!1),dt=xt(me,Zt);if(dt>=0){const ht=Le.splice(dt,1)[0];ht&&Le.push(ht)}Xe(k?Le:[],x.current)}});p.useEffect(()=>{k&&Ce(ee,!1,!0)},[k]),p.useEffect(()=>{if(k){if(re.current===ee)return;Ce(ee,!1,!0)}},[ee]),Kn(k,S,ee);const Oe=Tn(N),at=Un(k,r,o);p.useEffect(()=>{var z;D(Q,(z=oe==null?void 0:oe.isFocusing)!=null?z:!0)},[D,Q]),J.useKeyboardEvent(k,v,N),p.useLayoutEffect(()=>{let z;if(V.current){z=P.register({autofocus:M,editorUnitId:B,initialSnapshot:{id:B,body:{dataStream:`${s}\r
|
|
5
|
-
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},
|
|
1
|
+
"use strict";var Xt=Object.defineProperty;var Qt=(e,t,n)=>t in e?Xt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var q=(e,t,n)=>Qt(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),A=require("@univerjs/sheets-ui"),T=require("@univerjs/engine-formula"),K=require("rxjs"),Q=require("@univerjs/docs-ui"),H=require("@univerjs/engine-render"),k=require("@univerjs/sheets"),ve=require("@univerjs/sheets-formula"),a=require("@univerjs/ui"),y=require("react/jsx-runtime"),V=require("@univerjs/design"),v=require("react"),Rt=require("@univerjs/docs"),Jt=require("rxjs/operators"),Ye={id:"sheet.command.paste-formula",type:l.CommandType.COMMAND,handler:async e=>e.get(l.ICommandService).executeCommand(A.SheetPasteCommand.id,{value:A.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA})},be={id:"formula-ui.operation.select-editor-formula",type:l.CommandType.OPERATION,handler:(e,t)=>!0};var en=Object.getOwnPropertyDescriptor,tn=(e,t,n,s)=>{for(var r=s>1?void 0:s?en(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},nn=(e,t)=>(n,s)=>t(n,s,e);const Et="FORMULA_PROMPT_ACTIVATED",nt=l.createIdentifier("formula-ui.prompt-service");let Je=class{constructor(e){q(this,"_search$",new K.Subject);q(this,"_help$",new K.Subject);q(this,"_navigate$",new K.Subject);q(this,"_accept$",new K.Subject);q(this,"_acceptFormulaName$",new K.Subject);q(this,"search$",this._search$.asObservable());q(this,"help$",this._help$.asObservable());q(this,"navigate$",this._navigate$.asObservable());q(this,"accept$",this._accept$.asObservable());q(this,"acceptFormulaName$",this._acceptFormulaName$.asObservable());q(this,"_searching",!1);q(this,"_helping",!1);q(this,"_sequenceNodes",[]);q(this,"_isLockedOnSelectionChangeRefString",!1);q(this,"_isLockedOnSelectionInsertRefString",!1);this._contextService=e}dispose(){this._search$.complete(),this._help$.complete(),this._navigate$.complete(),this._accept$.complete(),this._acceptFormulaName$.complete(),this._sequenceNodes=[]}search(e){this._contextService.setContextValue(Et,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=tn([nn(0,l.IContextService)],Je);const yt={id:"formula-ui.operation.help-function",type:l.CommandType.OPERATION,handler:async(e,t)=>(e.get(nt).help(t),!0)},oe={id:"formula-ui.operation.insert-function",type:l.CommandType.OPERATION,handler:async(e,t)=>{var R,I;const n=e.get(k.SheetsSelectionsService),s=e.get(Q.IEditorService),r=n.getCurrentSelections();if(!r||!r.length)return!1;const o=k.getSheetCommandTarget(e.get(l.IUniverInstanceService));if(!o)return!1;const{worksheet:i,unitId:c,subUnitId:d}=o,f=i.getCellMatrix(),{value:m}=t,S=e.get(l.ICommandService);e.get(A.IEditorBridgeService);const h=[],g=[];let u=null,_=0,p=0,C="";if(r.length===1&&(on(r[0].range)||cn(r[0].range)&>(f,r[0].range))){const{range:E,primary:b}=r[0],M=(R=b==null?void 0:b.actualRow)!=null?R:E.startRow,F=(I=b==null?void 0:b.actualColumn)!=null?I:E.startColumn;u=E,_=M,p=F;const L=ft(f,M,F);L&&(C=T.serializeRange(L))}else r.some(E=>{var F,L;const{range:b,primary:M}=E;if(gt(f,b)){const U=(F=M==null?void 0:M.actualRow)!=null?F:b.startRow,w=(L=M==null?void 0:M.actualColumn)!=null?L:b.startColumn,$=ft(f,U,w);if(!$)return u=b,_=U,p=w,!0;const D=T.serializeRange($),O=`=${m}(${D})`;h.push({range:b,primary:{row:U,column:w},formula:O})}else{const{startRow:U,startColumn:w,endRow:$,endColumn:D}=b;if(U===$){const O=an(f,U,D,i.getColumnCount()-1),x=O===D?D-1:D,N=T.serializeRange({startRow:U,endRow:$,startColumn:w,endColumn:x}),P=`=${m}(${N})`;g.push({range:b,primary:{row:U,column:O},formula:P})}else{let O=-1;for(let N=w;N<=D;N++){const P=ln(f,N,$,i.getRowCount()-1);O=Math.max(O,P)}const x=O===$?$-1:$;for(let N=w;N<=D;N++){const P=T.serializeRange({startRow:U,endRow:x,startColumn:N,endColumn:N}),j=`=${m}(${P})`;g.push({range:b,primary:{row:O,column:N},formula:j})}}}return!1});if(u){const E=k.getCellAtRowCol(_,p,i),b={range:l.Rectangle.clone(u),primary:{startRow:E.startRow,startColumn:E.startColumn,endRow:E.endRow,endColumn:E.endColumn,actualRow:_,actualColumn:p,isMerged:E.isMerged,isMergedMainCell:E.startRow===_&&E.startColumn===p}},M={unitId:c,subUnitId:d,selections:[b]};await S.executeCommand(k.SetSelectionsOperation.id,M);const F=s.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),L=s.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);S.syncExecuteCommand(A.SetCellEditVisibleOperation.id,{visible:!0,unitId:c,eventType:H.DeviceInputEventType.Dblclick});const U=`=${m}(${C}`;F==null||F.replaceText(U),L==null||L.replaceText(U,!1)}return h.length===0&&g.length===0?!1:S.executeCommand(ve.InsertFunctionCommand.id,{list:h,listOfRangeHasNumber:g})}};function ft(e,t,n){const s=rn(e,t,n);if(s!==t)return{startRow:s,endRow:t-1,startColumn:n,endColumn:n};const r=sn(e,t,n);return r!==n?{startRow:t,endRow:t,startColumn:r,endColumn:n-1}:null}function rn(e,t,n){let s=!1;if(t===0)return t;for(let r=t-1;r>=0;r--){const o=e.getValue(r,n);if(Fe(o)&&!s){if(r===0)return 0;s=!0}else{if(s&&!Fe(o))return r+1;if(s&&r===0)return 0}}return t}function sn(e,t,n){let s=!1;if(n===0)return n;for(let r=n-1;r>=0;r--){const o=e.getValue(t,r);if(Fe(o)&&!s){if(r===0)return 0;s=!0}else{if(s&&!Fe(o))return r+1;if(s&&r===0)return 0}}return n}function Fe(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return!1;const n=t.dataStream,r=n.substring(n.length-2,n.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n;return l.isRealNum(r)}return e&&(e.t===l.CellValueType.NUMBER||l.getCellValueType(e)===l.CellValueType.NUMBER)}function on(e){return e.startRow===e.endRow&&e.startColumn===e.endColumn}function cn(e){return e.startRow!==e.endRow&&e.startColumn!==e.endColumn}function gt(e,t){for(let n=t.startRow;n<=t.endRow;n++)for(let s=t.startColumn;s<=t.endColumn;s++)if(Fe(e.getValue(n,s)))return!1;return!0}function an(e,t,n,s){for(let r=n;r<=s;r++)if(!e.getValue(t,r))return r;return s}function ln(e,t,n,s){for(let r=n;r<=s;r++)if(!e.getValue(r,t))return r;return s}const It="SHEET_FORMULA_UI_PLUGIN",bt=`${It}_MORE_FUNCTIONS_COMPONENT`,rt={id:"formula-ui.operation.more-functions",type:l.CommandType.OPERATION,handler:async e=>(e.get(a.ISidebarService).open({header:{title:"formula.insert.tooltip"},children:{label:bt}}),!0)},st={id:"formula-ui.operation.change-ref-to-absolute",type:l.CommandType.OPERATION,handler:async e=>!0},Tt={id:"formula-ui.operation.search-function",type:l.CommandType.OPERATION,handler:async(e,t)=>(e.get(nt).search(t),!0)},ot=(e,t,n=!0)=>{let s=-1;return e.reduce((r,o,i)=>{if(r.isFinish)return r;const c=r.currentIndex;if(typeof o!="string")r.currentIndex+=o.token.length;else{const d=o.length;r.currentIndex+=d}return(n?r.currentIndex===t:t>c&&t<=r.currentIndex)&&(s=i,r.isFinish=!0),r},{currentIndex:0,isFinish:!1}),s},xt=(e,t)=>{const n=e[t];let s=-1;if(!n||typeof n=="string"||n.nodeType!==T.sequenceNodeType.REFERENCE)return-1;for(let r=0;r<=t;r++){const o=e[r];typeof o!="string"&&o.nodeType===T.sequenceNodeType.REFERENCE&&s++}return s};var se=function(){return se=Object.assign||function(e){for(var t,n=1,s=arguments.length;n<s;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},se.apply(this,arguments)},un=function(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,s=Object.getOwnPropertySymbols(e);r<s.length;r++)t.indexOf(s[r])<0&&Object.prototype.propertyIsEnumerable.call(e,s[r])&&(n[s[r]]=e[s[r]]);return n},Te=v.forwardRef(function(e,t){var n=e.icon,s=e.id,r=e.className,o=e.extend,i=un(e,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(s," ").concat(r||"").trim(),d=v.useRef("_".concat(fn()));return Mt(n,"".concat(s),{defIds:n.defIds,idSuffix:d.current},se({ref:t,className:c},i),o)});function Mt(e,t,n,s,r){return v.createElement(e.tag,se(se({key:t},dn(e,n,r)),s),(hn(e,n).children||[]).map(function(o,i){return Mt(o,"".concat(t,"-").concat(e.tag,"-").concat(i),n,void 0,r)}))}function dn(e,t,n){var s=se({},e.attrs);n!=null&&n.colorChannel1&&s.fill==="colorChannel1"&&(s.fill=n.colorChannel1),e.tag==="mask"&&s.id&&(s.id=s.id+t.idSuffix),Object.entries(s).forEach(function(o){var i=o[0],c=o[1];i==="mask"&&typeof c=="string"&&(s[i]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var r=t.defIds;return!r||r.length===0||(e.tag==="use"&&s["xlink:href"]&&(s["xlink:href"]=s["xlink:href"]+t.idSuffix),Object.entries(s).forEach(function(o){var i=o[0],c=o[1];typeof c=="string"&&(s[i]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),s}function hn(e,t){var n,s=t.defIds;return!s||s.length===0?e:e.tag==="defs"&&(!((n=e.children)===null||n===void 0)&&n.length)?se(se({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&s&&s.indexOf(r.attrs.id)>-1?se(se({},r),{attrs:se(se({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):e}function fn(){return Math.random().toString(36).substring(2,8)}Te.displayName="UniverIcon";var gn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ot=v.forwardRef(function(e,t){return v.createElement(Te,Object.assign({},e,{id:"check-mark-single",ref:t,icon:gn}))});Ot.displayName="CheckMarkSingle";var mn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},Nt=v.forwardRef(function(e,t){return v.createElement(Te,Object.assign({},e,{id:"close-single",ref:t,icon:mn}))});Nt.displayName="CloseSingle";var Sn={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"}}]},Dt=v.forwardRef(function(e,t){return v.createElement(Te,Object.assign({},e,{id:"delete-single",ref:t,icon:Sn}))});Dt.displayName="DeleteSingle";var pn={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"}}]},At=v.forwardRef(function(e,t){return v.createElement(Te,Object.assign({},e,{id:"increase-single",ref:t,icon:pn}))});At.displayName="IncreaseSingle";var vn={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"}}]},wt=v.forwardRef(function(e,t){return v.createElement(Te,Object.assign({},e,{id:"more-single",ref:t,icon:vn}))});wt.displayName="MoreSingle";var Cn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6185 12.4423C12.5907 12.2749 12.7773 12.15 12.9343 12.2308L15.4242 13.5126C15.6102 13.6084 15.5544 13.8745 15.3439 13.8955L14.2456 14.184L13.4521 15.1286C13.3495 15.2939 13.085 15.2463 13.0534 15.0568L12.6185 12.4423Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1 3.6C1 2.16406 2.16406 1 3.6 1H12.3C13.7359 1 14.9 2.16406 14.9 3.6V5.81156C14.9003 5.81881 14.9004 5.82609 14.9004 5.8334C14.9004 5.84071 14.9003 5.84799 14.9 5.85524V10.045C14.9003 10.0522 14.9004 10.0595 14.9004 10.0668C14.9004 10.3982 14.6318 10.6668 14.3004 10.6668H11.1668C10.8907 10.6668 10.6668 10.8907 10.6668 11.1668V14.3C10.6668 14.6314 10.3982 14.9 10.0668 14.9L10.05 14.8998L3.6 14.9C2.16406 14.9 1 13.7359 1 12.3V3.6ZM13.2 5.2334C13.4761 5.2334 13.7 5.00954 13.7 4.7334V3.6C13.7 2.8268 13.0732 2.2 12.3 2.2H11.1668C10.8907 2.2 10.6668 2.42386 10.6668 2.7V4.7334C10.6668 5.00954 10.8907 5.2334 11.1668 5.2334H13.2ZM10.6668 6.9334C10.6668 6.65726 10.8907 6.4334 11.1668 6.4334H13.2C13.4761 6.4334 13.7 6.65726 13.7 6.9334V8.9668C13.7 9.24294 13.4761 9.4668 13.2 9.4668H11.1668C10.8907 9.4668 10.6668 9.24294 10.6668 8.9668V6.9334ZM8.9668 5.2334C9.24294 5.2334 9.4668 5.00954 9.4668 4.7334V2.7C9.4668 2.42386 9.24294 2.2 8.9668 2.2H6.9334C6.65726 2.2 6.4334 2.42386 6.4334 2.7V4.7334C6.4334 5.00954 6.65726 5.2334 6.9334 5.2334L8.9668 5.2334ZM6.4334 6.9334C6.4334 6.65726 6.65726 6.4334 6.9334 6.4334L8.9668 6.4334C9.24294 6.4334 9.4668 6.65726 9.4668 6.9334V8.9668C9.4668 9.24294 9.24294 9.4668 8.9668 9.4668L6.9334 9.4668C6.65726 9.4668 6.4334 9.24294 6.4334 8.9668V6.9334ZM4.7334 5.2334C5.00954 5.2334 5.2334 5.00954 5.2334 4.7334V2.7C5.2334 2.42386 5.00954 2.2 4.7334 2.2H3.6C2.8268 2.2 2.2 2.8268 2.2 3.6V4.7334C2.2 5.00954 2.42386 5.2334 2.7 5.2334H4.7334ZM2.2 6.9334C2.2 6.65726 2.42386 6.4334 2.7 6.4334H4.7334C5.00954 6.4334 5.2334 6.65725 5.2334 6.9334V8.9668C5.2334 9.24294 5.00954 9.4668 4.7334 9.4668H2.7C2.42386 9.4668 2.2 9.24294 2.2 8.9668V6.9334ZM5.2334 11.1668C5.2334 10.8907 5.00954 10.6668 4.7334 10.6668H2.7C2.42386 10.6668 2.2 10.8907 2.2 11.1668V12.3C2.2 13.0732 2.8268 13.7 3.6 13.7H4.7334C5.00954 13.7 5.2334 13.4761 5.2334 13.2V11.1668ZM9.4668 11.1668C9.4668 10.8907 9.24294 10.6668 8.9668 10.6668H6.9334C6.65726 10.6668 6.4334 10.8907 6.4334 11.1668V13.2C6.4334 13.4761 6.65726 13.7 6.9334 13.7H8.9668C9.24294 13.7 9.4668 13.4761 9.4668 13.2V11.1668Z",fillRule:"evenodd",clipRule:"evenodd"}}]},kt=v.forwardRef(function(e,t){return v.createElement(Te,Object.assign({},e,{id:"select-range-single",ref:t,icon:Cn}))});kt.displayName="SelectRangeSingle";function _n(e,t){return Object.keys(e).filter(n=>isNaN(Number(n))&&n!=="DefinedName").map(n=>({label:t.t(`formula.functionType.${n.toLocaleLowerCase()}`),value:`${e[n]}`}))}function Ft(e){if(!e.require&&!e.repeat)return`[${e.name}]`;if(e.require&&!e.repeat)return e.name;if(!e.require&&e.repeat)return`[${e.name},...]`;if(e.require&&e.repeat)return`${e.name},...`}const Rn=(e,t=100)=>{v.useEffect(()=>{let n=null;const s=()=>{n===null&&(n=window.setTimeout(()=>{e(),n=null},t))};return window.addEventListener("scroll",s),window.addEventListener("resize",s),()=>{n!==null&&clearTimeout(n),window.removeEventListener("scroll",s),window.removeEventListener("resize",s)}},[e,t])};function Pt(e,t,n){const s=a.useDependency(Q.IEditorService),r=v.useMemo(()=>new K.BehaviorSubject({left:-999,top:-999,right:-999,bottom:-999}),[]),o=a.useDependency(a.ISidebarService),i=a.useDependency(l.IUniverInstanceService),c=a.useEvent(()=>{var I;const d=s.getEditor(e);if(!d)return;const f=d.getBoundingClientRect(),{marginTop:m=0,marginBottom:S=0}=d.getDocumentData().documentStyle,h=d.getSkeleton();if(!h)return;const g=(I=h.getSkeletonData())==null?void 0:I.pages[0].height;let{left:u,top:_,right:p,bottom:C}=f;_=_+m,C=g?_+g:C-S;const R=r.getValue();if(!(R.left===u&&R.top===_&&R.right===p&&R.bottom===C))return r.next({left:u-1,right:p+1,top:_-1,bottom:C+1}),f});return v.useEffect(()=>{t&&c()},[e,s,i.unitAdded$,c,t,...n!=null?n:[]]),Rn(c),v.useEffect(()=>{const d=o.scrollEvent$.pipe(K.throttleTime(100)).subscribe(c);return()=>{d.unsubscribe()}},[]),[r,c]}const xe=e=>{const t=v.useRef(e);return t.current=e,t},En=(e,t,n)=>{const s=a.useDependency(ve.IDescriptionService),r=a.useDependency(T.LexerTreeBuilder),[o,i]=v.useState(),[c,d]=v.useState(-1),[f,m]=v.useState(!0),S=xe(f),h=v.useRef(t);h.current=t;const g=()=>{i(void 0),d(-1),m(!1)};return v.useEffect(()=>{if(n&&e){const u=n.selectionChange$.pipe(K.debounceTime(50)).subscribe(p=>{if(p.textRanges.length===1){const[C]=p.textRanges;if(C.collapsed&&S.current){const R=r.getFunctionAndParameter(`${h.current}A`,C.startOffset-1);if(R){const{functionName:I,paramIndex:E}=R,b=s.getFunctionInfo(I);i(b),d(E);return}}}i(void 0),d(-1)}),_=n.selectionChange$.pipe(K.filter(p=>p.isEditing),K.filter(p=>p.textRanges.length===1),K.map(p=>p.textRanges[0].startOffset),K.distinctUntilChanged()).subscribe(()=>{m(!0)});return()=>{u.unsubscribe(),_.unsubscribe()}}},[n,e]),v.useEffect(()=>{e||g()},[e]),{functionInfo:o,paramIndex:c,reset:g}},yn=({onClick:e})=>y.jsx("div",{className:"univer-z-[15] univer-box-border univer-h-[18px] univer-cursor-pointer univer-overflow-visible univer-whitespace-nowrap univer-rounded-l univer-border univer-border-r-0 univer-border-gray-600 univer-bg-primary-600 univer-p-0.5 univer-text-xs univer-font-bold univer-leading-[13px] univer-text-white",onClick:e,children:"?"}),Xe=({className:e,title:t,value:n})=>y.jsxs("div",{className:"univer-my-2",children:[y.jsx("div",{className:V.clsx("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",e),children:t}),y.jsx("div",{className:"univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",children:n})]}),In=e=>{const{prefix:t,value:n,active:s,onClick:r}=e;return y.jsxs("div",{children:[y.jsxs("span",{children:[t,"("]}),n&&n.map((o,i)=>y.jsxs("span",{children:[y.jsx("span",{className:s===i?"univer-text-primary-500":"",onClick:()=>r(i),children:Ft(o)}),i===n.length-1?"":","]},o.name)),")"]})},mt=()=>{};function bn(e){const{onParamsSwitch:t=mt,onClose:n=mt,isFocus:s,editor:r,formulaText:o}=e,{functionInfo:i,paramIndex:c,reset:d}=En(s,o,r),f=v.useMemo(()=>!!i&&c>=0,[i,c]),m=a.useDependency(A.IEditorBridgeService),S=!a.useObservable(m.helpFunctionVisible$),[h,g]=v.useState(!0),u=a.useDependency(l.LocaleService),_=u.t("formula.prompt.required"),p=u.t("formula.prompt.optional"),C=r.getEditorId(),[R]=Pt(C,f,[i,c]);function I(M){t&&t(M)}const E=a.useEvent(M=>{m.helpFunctionVisible$.next(!M)}),b=()=>{E(!0),n()};return f&&i?S?y.jsx(a.RectPopup,{portal:!0,anchorRect$:R,direction:"left-center",children:y.jsx(yn,{onClick:()=>E(!1)})},"hidden"):y.jsx(a.RectPopup,{portal:!0,onClickOutside:()=>d(),anchorRect$:R,direction:"vertical",children:y.jsxs("div",{className:V.clsx("univer-m-0 univer-box-border univer-w-[250px] univer-select-none univer-list-none univer-rounded-lg univer-bg-white univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",V.borderClassName),children:[y.jsxs("div",{className:V.clsx("univer-box-border univer-flex univer-items-center univer-justify-between univer-px-4 univer-py-3 univer-text-xs univer-font-medium univer-text-gray-900 univer-wrap-anywhere dark:!univer-text-white",V.borderTopClassName),children:[y.jsx(In,{prefix:i.functionName,value:i.functionParameter,active:c,onClick:I}),y.jsxs("div",{className:"univer-flex",children:[y.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-500 univer-outline-none univer-transition-colors hover:univer-bg-gray-200",style:{transform:h?"rotateZ(-90deg)":"rotateZ(90deg)"},onClick:()=>g(!h),children:y.jsx(wt,{})}),y.jsx("div",{className:"univer-ml-2 univer-flex univer-h-6 univer-w-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-600 univer-outline-none univer-transition-colors dark:!univer-text-gray-200 hover:univer-bg-gray-300",onClick:b,children:y.jsx(Nt,{})})]})]}),y.jsx("div",{className:"univer-box-border univer-max-h-[350px] univer-overflow-y-auto univer-px-4 univer-pb-3 univer-pt-0",style:{height:h?"unset":0,padding:h?"revert-layer":0},children:y.jsxs("div",{className:"univer-mt-3",children:[y.jsx(Xe,{title:u.t("formula.prompt.helpExample"),value:`${i.functionName}(${i.functionParameter.map(M=>M.example).join(",")})`}),y.jsx(Xe,{title:u.t("formula.prompt.helpAbstract"),value:i.description}),i&&i.functionParameter&&i.functionParameter.map((M,F)=>y.jsx(Xe,{className:c===F?"univer-text-primary-500":"",title:M.name,value:`${M.require?_:p} ${M.detail}`},F))]})})]})},"show"):null}const Tn=e=>{const t=a.useDependency(Q.IEditorService);return a.useEvent(s=>{var r,o;if(e){t.focus(e.getEditorId());const i=[...e.getSelectionRanges()];if(l.Tools.isDefine(s))e.setSelectionRanges([{startOffset:s,endOffset:s}]);else if(!i.length&&!e.docSelectionRenderService.isOnPointerEvent){const c=(o=(r=e.getDocumentData().body)==null?void 0:r.dataStream)!=null?o:`\r
|
|
2
|
+
`,d=Math.max(c.length-2,0);e.setSelectionRanges([{startOffset:d,endOffset:d}])}else e.setSelectionRanges(i)}})};var xn=Object.getOwnPropertyDescriptor,Mn=(e,t,n,s)=>{for(var r=s>1?void 0:s?xn(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},De=(e,t)=>(n,s)=>t(n,s,e);exports.RefSelectionsRenderService=class extends 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(On(this._themeService)),this._remainLastEnabled=!0,this._highlightHeader=!1}getLocation(){return this._skeleton.getLocation()}setRemainLastEnabled(n){this._remainLastEnabled=n}setSkipLastEnabled(n){this._skipLastEnabled=n}clearLastSelection(){const n=this._selectionControls[this._selectionControls.length-1];n&&(n.dispose(),this._selectionControls.pop())}enableSelectionChanging(){return this._disableSelectionChanging(),this._eventDisposables=this._initCanvasEventListeners(),l.toDisposable(()=>this._disableSelectionChanging())}_disableSelectionChanging(){var n;(n=this._eventDisposables)==null||n.dispose(),this._eventDisposables=null}disableSelectionChanging(){this._disableSelectionChanging()}_initCanvasEventListeners(){const n=this._getSheetObject(),{spreadsheetRowHeader:s,spreadsheetColumnHeader:r,spreadsheet:o,spreadsheetLeftTopPlaceholder:i}=n,{scene:c}=this._context,d=new l.DisposableCollection;return d.add(o==null?void 0:o.onPointerDown$.subscribeEvent((f,m)=>{this.inRefSelectionMode()&&(this._onPointerDown(f,o.zIndex+1,l.RANGE_TYPE.NORMAL,this._getActiveViewport(f)),f.button!==2&&m.stopPropagation())})),d.add(s==null?void 0:s.onPointerDown$.subscribeEvent((f,m)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{row:h}=A.getCoordByOffset(f.offsetX,f.offsetY,c,S);A.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,l.RANGE_TYPE.ROW)||(this._onPointerDown(f,(o.zIndex||1)+1,l.RANGE_TYPE.ROW,this._getActiveViewport(f),H.ScrollTimerType.Y),f.button!==2&&m.stopPropagation())})),d.add(r==null?void 0:r.onPointerDown$.subscribeEvent((f,m)=>{if(!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,{column:h}=A.getCoordByOffset(f.offsetX,f.offsetY,c,S);A.checkInHeaderRanges(this._workbookSelections.getCurrentSelections(),h,l.RANGE_TYPE.COLUMN)||(this._onPointerDown(f,(o.zIndex||1)+1,l.RANGE_TYPE.COLUMN,this._getActiveViewport(f),H.ScrollTimerType.X),f.button!==2&&m.stopPropagation())})),d.add(i==null?void 0:i.onPointerDown$.subscribeEvent((f,m)=>{if(this._reset(),!this.inRefSelectionMode())return;const S=this._sheetSkeletonManagerService.getCurrent().skeleton,h=A.getAllSelection(S);this._addSelectionControlByModelData(h),this._selectionMoveStart$.next(this.getSelectionDataWithStyle());const g=c.onPointerUp$.subscribeEvent(()=>{g.unsubscribe(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())});f.button!==2&&m.stopPropagation()})),d}_addSelectionControlByModelData(n){var c;const s=this._skeleton,r=(c=n.style)!=null?c: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,k.SelectionMoveType.MOVE_START)})),this.disposeWithMe(this.selectionMoving$.subscribe(n=>{this._updateSelections(n,k.SelectionMoveType.MOVING)})),this.disposeWithMe(this.selectionMoveEnd$.subscribe(n=>{this._updateSelections(n,k.SelectionMoveType.MOVE_END)}))}_updateSelections(n,s){const o=this._context.unit.getActiveSheet().getSheetId();n.length!==0&&this._workbookSelections.setSelections(o,n.map(i=>k.convertSelectionDataToRange(i)),s)}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(n=>{if(!n)return;const{skeleton:s}=n,{scene:r}=this._context,o=r.getViewport(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=l.RANGE_TYPE.NORMAL,o,i=H.ScrollTimerType.ALL){var $;this._rangeType=r;const c=this._skeleton,d=this._scene;if(!d||!c)return;o&&(this._activeViewport=o);const{offsetX:f,offsetY:m}=n,S=d.getViewport(H.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!S)return;const h=d.getCoordRelativeToViewport(H.Vector2.FromArray([f,m])),{x:g,y:u}=h;this._startViewportPosX=g,this._startViewportPosY=u;const _=d.getScrollXYInfoByViewport(h),{scaleX:p,scaleY:C}=d.getAncestorScale(),R=this._skeleton.getCellByOffset(g,u,p,C,_);if(!R)return;switch(r){case l.RANGE_TYPE.NORMAL:break;case l.RANGE_TYPE.ROW:R.startColumn=0,R.endColumn=this._skeleton.getColumnCount()-1;break;case l.RANGE_TYPE.COLUMN:R.startRow=0,R.endRow=this._skeleton.getRowCount()-1;break;case l.RANGE_TYPE.ALL:R.startRow=0,R.startColumn=0,R.endRow=this._skeleton.getRowCount()-1,R.endColumn=this._skeleton.getColumnCount()-1}const I={range:R,primary:R,style:null};I.range.rangeType=r;const E=A.attachSelectionWithCoord(I,this._skeleton);this._startRangeWhenPointerDown={...E.rangeWithCoord};const b={...E.rangeWithCoord,rangeType:r};let M=this.getActiveSelectionControl();const F=this.getSelectionControls();for(const D of F){if(n.button===2&&l.Rectangle.contains(D.model,b)){M=D;return}if(D.model.isEqual(b)){M=D;break}}this._checkClearPreviousControls(n);const L=M==null?void 0:M.model.currentCell,U=n.shiftKey&&L,w=this._remainLastEnabled&&!n.ctrlKey&&!n.shiftKey&&!this._skipLastEnabled&&!this._singleSelectionEnabled;U&&L?this._makeSelectionByTwoCells(L,b,c,r,M):w&&M?M.updateRangeBySelectionWithCoord(E):M=this.newSelectionControl(d,c,I);for(let D=0;D<this.getSelectionControls().length-1;D++)this.getSelectionControls()[D].clearHighlight();this._selectionMoveStart$.next(this.getSelectionDataWithStyle()),d.disableObjectsEvent(),this._clearUpdatingListeners(),this._addEndingListeners(),($=d.getTransformer())==null||$.clearSelectedObjects(),this._setupPointerMoveListener(S,M,r,i,g,u),this._escapeShortcutDisposable=this._shortcutService.forceEscape(),this._scenePointerUpSub=d.onPointerUp$.subscribeEvent(()=>{var D;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(D=this._escapeShortcutDisposable)==null||D.dispose(),this._escapeShortcutDisposable=null})}newSelectionControl(n,s,r){const o=this.getSelectionControls().length,{rowHeaderWidth:i,columnHeaderHeight:c}=s,d=new A.SelectionControl(n,o,this._themeService,{highlightHeader:this._highlightHeader,enableAutoFill:!1,rowHeaderWidth:i,columnHeaderHeight:c}),f=A.attachSelectionWithCoord(r,s);return d.updateRangeBySelectionWithCoord(f),this._selectionControls.push(d),d.setControlExtension({skeleton:s,scene:n,themeService:this._themeService,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),d}};exports.RefSelectionsRenderService=Mn([De(1,l.Inject(l.Injector)),De(2,l.Inject(l.ThemeService)),De(3,a.IShortcutService),De(4,l.Inject(A.SheetSkeletonManagerService)),De(5,l.IContextService),De(6,k.IRefSelectionsService)],exports.RefSelectionsRenderService);function On(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 Nn(e){var r,o;const n=e.get(l.IUniverInstanceService).getCurrentUniverDocInstance();return n!=null&&n.getBody()?{dataStream:(o=(r=n.getBody())==null?void 0:r.dataStream)!=null?o:"",offset:0}:void 0}var pe=(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))(pe||{});function Dn(e){var F;const{editorId:t,isFocus:n,disableOnClick:s,unitId:r,subUnitId:o}=e,i=a.useDependency(H.IRenderManagerService),c=a.useDependency(l.IUniverInstanceService),d=i.getRenderById(r),f=i.getRenderById(t),m=f==null?void 0:f.with(Q.DocSelectionRenderService),S=a.useDependency(Rt.DocSelectionManagerService),h=a.useDependency(l.Injector),[g,u]=v.useState(0),_=a.useDependency(T.LexerTreeBuilder),p=v.useRef(!0),C=d==null?void 0:d.with(exports.RefSelectionsRenderService),R=xe(g),I=c.getUnit(r,l.UniverInstanceType.UNIVER_SHEET),E=I==null?void 0:I.getSheetBySheetId(o),b=a.useEvent(L=>{C&&C.setSkipLastEnabled(L===1||L===3),R.current=L,u(L)}),M=a.useEvent(()=>{var B,ne;if(!I)return;const L=I.getActiveSheet(),U=m==null?void 0:m.getActiveTextRange(),w=U!=null&&U.collapsed?U.startOffset:-1,$=Nn(h);if(!$)return;const D=(B=$==null?void 0:$.dataStream)==null?void 0:B.slice(0,-2),O=((ne=_.sequenceNodesBuilder(D))!=null?ne:[]).map(Y=>typeof Y=="object"?Y.nodeType===T.sequenceNodeType.REFERENCE?{...Y,range:T.deserializeRangeWithSheetWithCache(Y.token)}:{...Y,range:void 0}:Y),x=D[w-1],N=D[w],P=O.find(Y=>typeof Y=="object"&&Y.nodeType===T.sequenceNodeType.REFERENCE&&w===Y.endIndex+2),j=x&&T.matchRefDrawToken(x)&&(!N||T.isFormulaLexerToken(N)&&N!==T.matchToken.OPEN_BRACKET),W=!!P;if((D==null?void 0:D.substring(0,1))==="="&&(j||W))if(W){if(p.current)return;!P.range.sheetName&&L.getSheetId()===(E==null?void 0:E.getSheetId())||P.range.sheetName===L.getName()?b(2):b(3)}else p.current=!1,b(1);else b(0)});return v.useEffect(()=>{const L=S.textSelection$.pipe(K.filter(U=>U.unitId===t)).subscribe(()=>{M()});return()=>L.unsubscribe()},[M,S.textSelection$,t]),v.useEffect(()=>{n||(b(0),p.current=!0)},[n,b]),v.useEffect(()=>{var U;if(!s)return;const L=(U=f==null?void 0:f.mainComponent)==null?void 0:U.onPointerDown$.subscribeEvent(()=>{b(0),p.current=!0});return()=>L==null?void 0:L.unsubscribe()},[s,(F=f==null?void 0:f.mainComponent)==null?void 0:F.onPointerDown$,b]),v.useEffect(()=>{if(!n)return;const L=I==null?void 0:I.activeSheet$.subscribe(()=>{M()});return()=>L==null?void 0:L.unsubscribe()},[M,n,I==null?void 0:I.activeSheet$]),{isSelecting:g,isSelectingRef:R}}const An=()=>{const e=a.useDependency(T.LexerTreeBuilder);return v.useCallback(n=>e.sequenceNodesBuilder(n)||[],[e])};function wn(e,t,n){const s=new l.ColorKit(t).setAlpha(.05).toRgbString();return{id:n,strokeWidth:1,stroke:e.getColorFromTheme(t),fill:s,widgets:{tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},widgetSize:6,widgetStrokeWidth:1,widgetStroke:e.getColorFromTheme("white")}}function Lt(e){var I,E,b;const{unitId:t,subUnitId:n,currentWorkbook:s,refSelections:r,editor:o,refSelectionsService:i,refSelectionsRenderService:c,sheetSkeletonManagerService:d,themeService:f,univerInstanceService:m}=e,S=s.getUnitId(),h=m.getUnit(t,l.UniverInstanceType.UNIVER_SHEET),g=h==null?void 0:h.getActiveSheet(),u=[];if(!h||!g){i.setSelections(u);return}const _=g.getSheetId(),p=M=>{var F;return(F=h==null?void 0:h.getSheetBySheetName(M))==null?void 0:F.getSheetId()};if(!((I=d==null?void 0:d.getWorksheetSkeleton(_))==null?void 0:I.skeleton))return;const R=[];for(let M=0,F=r.length;M<F;M++){const L=r[M],{themeColor:U,token:w,refIndex:$,endIndex:D}=L,O=T.deserializeRangeWithSheet(w),{unitId:x,sheetName:N,range:P}=O,j=p(N);if(S!==t&&x!==S||x&&x!==S||j&&j!==_||!j&&_!==n)continue;const W=k.setEndForRange(P,g.getRowCount(),g.getColumnCount());W.unitId=t,W.sheetId=_,u.push({range:W,primary:null,style:wn(f,U,$.toString())}),R.push(D)}if(o){const M=(b=(E=o.getSelectionRanges())==null?void 0:E[0])==null?void 0:b.startOffset,F=R.findIndex(L=>L+2===M);F!==-1?c==null||c.setActiveSelectionIndex(F):c==null||c.resetActiveSelectionIndex()}return u}function kn(e,t){const n=a.useDependency(l.IUniverInstanceService),s=a.useDependency(l.ThemeService),r=a.useDependency(k.IRefSelectionsService),i=a.useDependency(H.IRenderManagerService).getRenderById(e),c=i==null?void 0:i.with(exports.RefSelectionsRenderService),d=i==null?void 0:i.with(A.SheetSkeletonManagerService),f=a.useEvent((m,S)=>{const h=n.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_SHEET);if(!h||c!=null&&c.selectionMoving)return;const g=Lt({unitId:e,subUnitId:t,currentWorkbook:h,refSelections:m,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 v.useEffect(()=>()=>{c==null||c.resetActiveSelectionIndex()},[c]),f}function Ut(e=""){const t=a.useDependency(ve.IDescriptionService),n=Fn(),s=a.useDependency(l.ICommandService),r=v.useMemo(()=>e.length,[e]);return a.useEvent((i,c,d=!0,f)=>{const m=i.getDocumentData(),S=i.getEditorId();if(!m)return[];const h=m.body;if(!h)return[];const g=h.dataStream.slice(0,h.dataStream.length-2),u={dataStream:"",...m.body};if(!g.startsWith(e))return[];if(c==null||c.length===0)return u.textRuns=[],s.syncExecuteCommand(Q.ReplaceTextRunsCommand.id,{unitId:S,body:l.getBodySlice(u,0,u.dataStream.length-2)}),[];{const{textRuns:_,refSelections:p}=Pn(t,n,c);r&&_.forEach(I=>{I.ed=I.ed+r,I.st=I.st+r}),u.textRuns=[{st:0,ed:1,ts:{fs:11}},..._];const C=c.reduce((I,E)=>typeof E=="string"?`${I}${E}`:`${I}${E.token}`,"");u.dataStream=`${e}${C}\r
|
|
3
|
+
`;let R;if(d){R=i.getSelectionRanges();const I=u.dataStream.length-2+r;R.forEach(E=>{E.startOffset=Math.max(0,Math.min(E.startOffset,I)),E.endOffset=Math.max(0,Math.min(E.endOffset,I))})}return s.syncExecuteCommand(Q.ReplaceTextRunsCommand.id,{unitId:S,body:l.getBodySlice(u,0,u.dataStream.length-2),textRanges:f!=null?f:R}),p}})}function Fn(){const e=a.useDependency(l.ThemeService),t=e.getCurrentTheme();return v.useMemo(()=>{const s=[e.getColorFromTheme("loop-color.1"),e.getColorFromTheme("loop-color.2"),e.getColorFromTheme("loop-color.3"),e.getColorFromTheme("loop-color.4"),e.getColorFromTheme("loop-color.5"),e.getColorFromTheme("loop-color.6"),e.getColorFromTheme("loop-color.7"),e.getColorFromTheme("loop-color.8"),e.getColorFromTheme("loop-color.9"),e.getColorFromTheme("loop-color.10"),e.getColorFromTheme("loop-color.11"),e.getColorFromTheme("loop-color.12")],r=e.getColorFromTheme("blue.700"),o=e.getColorFromTheme("jiqing.800"),i=e.getColorFromTheme("black");return{formulaRefColors:s,numberColor:r,stringColor:o,plainTextColor:i}},[t])}function Pn(e,t,n){const{formulaRefColors:s,numberColor:r,stringColor:o,plainTextColor:i}=t,c=[],d=[],f=new Map;let m=0;for(let S=0,h=n.length;S<h;S++){const g=n[S];if(typeof g=="string"){const I=c[c.length-1],E=I?I.ed:0,b=E+g.length;c.push({st:E,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 R="";if(p===T.sequenceNodeType.REFERENCE){if(f.has(C))R=f.get(C);else{const I=m%s.length;R=s[I],f.set(C,R),m++}d.push({refIndex:S,themeColor:R,token:C,startIndex:g.startIndex,endIndex:g.endIndex,index:d.length})}else p===T.sequenceNodeType.NUMBER?R=r:(p===T.sequenceNodeType.STRING||p===T.sequenceNodeType.ARRAY)&&(R=o);R&&R.length>0?c.push({st:u,ed:_+1,ts:{cl:{rgb:R},fs:11}}):c.push({st:u,ed:_+1,ts:{cl:{rgb:i},fs:11}})}return{textRuns:c,refSelections:d}}const Ln=(e,t,n,s)=>{const r=a.useDependency(l.ICommandService),o=a.useDependency(a.IShortcutService),i=v.useRef(t);i.current=t;const c=v.useRef(s);c.current=s,v.useEffect(()=>{if(!n||!e)return;const f=`sheet.formula-embedding-editor.${n.getEditorId()}`,m=new l.DisposableCollection,S=(u,_)=>{if(c.current){c.current(u,_);return}let p=l.Direction.LEFT;u===a.KeyCode.ARROW_DOWN?p=l.Direction.DOWN:u===a.KeyCode.ARROW_UP?p=l.Direction.UP:u===a.KeyCode.ARROW_RIGHT&&(p=l.Direction.RIGHT),_===a.MetaKeys.SHIFT?r.executeCommand(Q.MoveSelectionOperation.id,{direction:p}):r.executeCommand(Q.MoveCursorOperation.id,{direction:p})},h=(u,_)=>{let p=l.Direction.DOWN;u===a.KeyCode.ARROW_DOWN?p=l.Direction.DOWN:u===a.KeyCode.ARROW_UP?p=l.Direction.UP:u===a.KeyCode.ARROW_LEFT?p=l.Direction.LEFT:u===a.KeyCode.ARROW_RIGHT&&(p=l.Direction.RIGHT),i.current?_===a.MetaKeys.CTRL_COMMAND?r.executeCommand(A.MoveSelectionCommand.id,{direction:p,jumpOver:A.JumpOver.moveGap,extra:"formula-editor",fromCurrentSelection:i.current===pe.NEED_ADD||i.current===pe.EDIT_OTHER_SHEET_REFERENCE}):_===a.MetaKeys.SHIFT?r.executeCommand(A.ExpandSelectionCommand.id,{direction:p,extra:"formula-editor"}):_===(a.MetaKeys.CTRL_COMMAND|a.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===pe.NEED_ADD||i.current===pe.EDIT_OTHER_SHEET_REFERENCE}):S(u,_)};return m.add(r.registerCommand({id:f,type:l.CommandType.OPERATION,handler(u,_){const{keyCode:p,metaKey:C}=_;h(p,C)}})),[{keyCode:a.KeyCode.ARROW_DOWN},{keyCode:a.KeyCode.ARROW_LEFT},{keyCode:a.KeyCode.ARROW_RIGHT},{keyCode:a.KeyCode.ARROW_UP},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT}].map(({keyCode:u,metaKey:_})=>({id:f,binding:_?u|_:u,preconditions:()=>!0,priority:900,staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keyCode:u,metaKey:_}})).forEach(u=>{m.add(o.registerShortcut(u))}),()=>{m.dispose()}},[r,n,e,o])},Un=(e,t,n,s=!0)=>{var h;const r=a.useDependency(H.IRenderManagerService),o=a.useDependency(l.IContextService),i=a.useDependency(a.IContextMenuService),c=a.useDependency(k.IRefSelectionsService),d=a.useDependency(l.IUniverInstanceService),f=a.useObservable(v.useMemo(()=>d.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),[d])),m=r.getRenderById((h=f==null?void 0:f.getUnitId())!=null?h:""),S=m==null?void 0:m.with(exports.RefSelectionsRenderService);v.useLayoutEffect(()=>{if(e)return o.setContextValue(l.EDITOR_ACTIVATED,!0),()=>{o.setContextValue(l.EDITOR_ACTIVATED,!1),c.clear()}},[o,e,c]),v.useLayoutEffect(()=>{if(e&&t){const g=S==null?void 0:S.enableSelectionChanging();return o.setContextValue(k.REF_SELECTIONS_ENABLED,!0),()=>{o.setContextValue(k.REF_SELECTIONS_ENABLED,!1),g==null||g.dispose()}}},[o,e,S,t]),v.useEffect(()=>{if(e)return o.setContextValue(l.EDITOR_ACTIVATED,!0),s&&i.disable(),()=>{o.setContextValue(l.EDITOR_ACTIVATED,!1),s&&i.enable()}},[i,o,e,s]),v.useEffect(()=>{e&&(S==null||S.setSkipLastEnabled(!1))},[e,S])},$n=(e,t,n)=>{const s=a.useDependency(l.IUniverInstanceService),r=a.useDependency(k.SheetsSelectionsService);return v.useCallback(()=>{if(e){const i=[...r.getWorkbookSelections(t).getSelectionsOfWorksheet(n)],c=s.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),d=c==null?void 0:c.getActiveSheet();(c==null?void 0:c.getUnitId())!==t&&s.setCurrentUnitForType(t),d&&d.getSheetId()===n&&r.setSelections(i)}},[e,r,n,t,s])},jn=e=>e.reduce((t,n)=>typeof n=="string"?t+n.length:t+n.token.length,0),et=e=>e.map(t=>typeof t=="string"?t:t.token).join(""),$e=(e,t=!1,n="",s=!1)=>!t&&!s?e.map(r=>T.serializeRange(r.range)):e.map(r=>s?T.serializeRangeToRefString(r):r.sheetName!==""&&r.sheetName!==n?T.serializeRangeWithSheet(r.sheetName,r.range):T.serializeRange(r.range)),Wn=e=>{var m,S,h;const{editor:t,lexerTreeBuilder:n}=e,s=t==null?void 0:t.getSelectionRanges();if((s==null?void 0:s.length)!==1)return;const o=s[0].startOffset-1,i=((S=(m=t==null?void 0:t.getDocumentData().body)==null?void 0:m.dataStream)!=null?S:`\r
|
|
4
|
+
`).slice(0,-2),c=(h=n.sequenceNodesBuilder(i.slice(1)))!=null?h:[],d=ot(c,o,!1),f=xt(c,d);return{nodeIndex:d,updatingRefIndex:f,sequenceNodes:c,offset:o}},Vn=()=>{},Bn=(e,t,n,s,r,o,i,c,d,f=Vn)=>{var $;const m=a.useDependency(H.IRenderManagerService),S=a.useDependency(l.IUniverInstanceService),h=a.useDependency(l.ICommandService),g=a.useDependency(Rt.DocSelectionManagerService),u=a.useDependency(l.ThemeService),_=a.useDependency(T.LexerTreeBuilder),p=S.getUnit(s),C=a.useEvent(D=>{var O,x;return(x=(O=p==null?void 0:p.getSheetBySheetId(D))==null?void 0:O.getName())!=null?x:""}),R=v.useMemo(()=>C(r),[C,r]),I=a.useObservable(p==null?void 0:p.activeSheet$),E=xe({activeSheet:I,sheetName:R}),b=a.useObservable(v.useMemo(()=>S.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),[S])),M=m.getRenderById(($=b==null?void 0:b.getUnitId())!=null?$:""),F=M==null?void 0:M.with(exports.RefSelectionsRenderService),L=M==null?void 0:M.with(A.SheetSkeletonManagerService),U=a.useDependency(k.IRefSelectionsService),w=a.useEvent((D,O)=>{var B,ne,Y,ue,Me,ee;const x=Wn({editor:d,lexerTreeBuilder:_});if(!x)return;const{nodeIndex:N,updatingRefIndex:P,sequenceNodes:j,offset:W}=x;if(n.current===pe.NEED_ADD)if(W!==0){if(N===-1&&j.length)return;const Z=D[D.length-1],X=j.splice(N+1),ce=(B=Z.sheetId)!=null?B:r,J={range:Z,unitId:(ne=Z.unitId)!=null?ne:b.getUnitId(),sheetName:C(ce)},ae=ce!==r,re=(b==null?void 0:b.getUnitId())!==s,Oe=$e([J],i&&(ae||re),R,re);j.push({token:Oe[0],nodeType:T.sequenceNodeType.REFERENCE});const Ce=[...j,...X],ie=et(Ce);f(ie,jn(j),O)}else{const Z=D[D.length-1],X=(Y=Z.sheetId)!=null?Y:r,ce={range:Z,unitId:(ue=Z.unitId)!=null?ue:s,sheetName:C(X)},ae=$e([ce],i&&X!==r);j.unshift({token:ae[0],nodeType:T.sequenceNodeType.REFERENCE});const re=et(j);f(re,ae[0].length,O)}else if(n.current===pe.EDIT_OTHER_SHEET_REFERENCE){const Z=D.pop();if(!Z)return;const X=j[N];if(typeof X=="object"&&X.nodeType===T.sequenceNodeType.REFERENCE){const ce=X.token;X.token=R===(I==null?void 0:I.getName())?T.serializeRange(Z):T.serializeRangeWithSheet(I.getName(),Z);const J=W+(X.token.length-ce.length);f(T.generateStringWithSequence(j),J,O)}}else{const Z=[...D];if(P!==-1){const G=Z.pop();G&&Z.splice(P,0,G)}let X=0;const ce=j.map(G=>{var le,de,ge;if(typeof G=="string")return G;if(G.nodeType===T.sequenceNodeType.REFERENCE){const _e=T.deserializeRangeWithSheet(G.token);if(_e.sheetName||(_e.sheetName=R),i&&((le=E.current.activeSheet)==null?void 0:le.getName())!==_e.sheetName)return G.token;const he=Z[X];if(X++,!he)return"";const Ge=(de=he.sheetId)!=null?de:r,Ze={range:he,unitId:(ge=he.unitId)!=null?ge:s,sheetName:C(Ge)};return $e([Ze],i,R)[0]}return G.token});let J="",ae;ce.forEach((G,le)=>{J+=G,le===N&&(ae=J.length)});const re=[];for(let G=X;G<=D.length-1;G++){const le=D[G],de=(Me=le.sheetId)!=null?Me:r,ge={range:le,unitId:(ee=le.unitId)!=null?ee:s,sheetName:C(de)},he=$e([ge],i&&de!==r,R);re.push(he[0])}const Oe=j[j.length-1],Ce=Oe&&(typeof Oe=="string"?!1:Oe.nodeType===T.sequenceNodeType.REFERENCE),ie=`${J}${re.length&&Ce?",":""}${re.join(",")}`;f(ie,!re.length&&ae?ae:ie.length,O)}});v.useEffect(()=>{if(F&&e){let D=!0;const O=(N,P)=>{if(D){D=!1;return}w(N.map(j=>j.rangeWithCoord),P)},x=new l.DisposableCollection;return x.add(F.selectionMoving$.subscribe(N=>{O(N,!1)})),x.add(F.selectionMoveEnd$.subscribe(N=>{O(N,!0)})),()=>{x.dispose()}}},[e,w,F]),v.useEffect(()=>{if(t&&F&&d){const D=new l.DisposableCollection,O=()=>{D.dispose(),F.getSelectionControls().forEach((P,j)=>{D.add(P.selectionScaling$.subscribe(W=>{const B=F.getSelectionDataWithStyle().map(Y=>Y.rangeWithCoord),ne=B[j];W.sheetId=ne.sheetId,W.unitId=ne.unitId,B[j]=W,w(B,!1)})),D.add(P.selectionMoving$.subscribe(W=>{const B=F.getSelectionDataWithStyle().map(Y=>Y.rangeWithCoord),ne=B[j];W.sheetId=ne.sheetId,W.unitId=ne.unitId,B[j]=W,w(B,!0)}))})},x=K.merge(d.input$,U.selectionSet$,F.selectionMoveEnd$).pipe(Jt.debounceTime(50)).subscribe(()=>{O()});return()=>{x.unsubscribe(),D.dispose()}}},[d,t,w,F,U.selectionSet$]),F==null||F.getSelectionDataWithStyle(),v.useEffect(()=>{if(c){const D=h.onCommandExecuted(O=>{var N;if(O.id!==k.SetSelectionsOperation.id)return;const x=O.params;if(x.extra==="formula-editor"&&x.selections.length){const P=x.selections[x.selections.length-1];if(P){const j=n.current===pe.NEED_ADD,W=((N=F==null?void 0:F.getSelectionDataWithStyle())!=null?N:[]).map(B=>B.rangeWithCoord);j?W.push(P.range):W[W.length-1]=P.range,w(W,!0)}}});return()=>{D.dispose()}}},[h,d,n,_,c,w,F]),v.useEffect(()=>{if(!d)return;const D=g.textSelection$.subscribe(O=>{O.unitId===d.getEditorId()&&Lt({unitId:s,subUnitId:r,refSelections:o.current,editor:d,refSelectionsService:U,refSelectionsRenderService:F,sheetSkeletonManagerService:L,themeService:u,univerInstanceService:S,currentWorkbook:b})});return()=>D.unsubscribe()},[g.textSelection$,d,o,F,U,L,r,u,s,S])},Hn=(e,t,n,s,r,o)=>{const i=a.useDependency(l.ICommandService),c=a.useDependency(Q.IEditorService),f=a.useDependency(H.IRenderManagerService).getRenderById(t),m=a.useDependency(l.IUniverInstanceService),S=f==null?void 0:f.with(exports.RefSelectionsRenderService);v.useEffect(()=>{if(e&&S)if(n){const h=()=>{const _=S.getSelectionControls().length;for(let p=1;p<=_;p++)S.clearLastSelection();return setTimeout(()=>{o()},30)},g=i.onCommandExecuted(_=>{_.id===k.SetWorksheetActiveOperation.id&&h()}),u=m.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).subscribe(_=>{h()});return()=>{g.dispose(),u.unsubscribe()}}else{const h=i.beforeCommandExecuted(g=>{if(g.id===k.SetWorksheetActiveOperation.id){s(!1),r(),o();const u=c.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);u==null||u.focus()}});return()=>{h.dispose()}}},[e,S])},Kn=(e,t,n)=>{const s=a.useDependency(T.LexerTreeBuilder),r=v.useRef(!0);v.useEffect(()=>{if(e){const o=setTimeout(()=>{r.current=!1},500);return()=>{clearTimeout(o)}}},[e]),v.useEffect(()=>{if(!r.current&&t){const o=s.checkIfAddBracket(n);t(o===0&&n.startsWith(T.operatorToken.EQUALS),`${n}`)}},[n,t])},qn=(e,t=[],n)=>{const s=a.useDependency(ve.IDescriptionService),[r,o]=v.useState([]),[i,c]=v.useState(""),d=v.useRef(-1),f=xe({nodes:t}),m=()=>{o([]),c(""),d.current=-1};return v.useEffect(()=>{if(n&&e){const h=n.input$.pipe(K.debounceTime(300)).subscribe(()=>{const g=n.getSelectionRanges();if(g.length===1){const u=f.current.nodes,_=g[0];if(_.collapsed){const p=ot(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 R=C.token,I=s.getSearchListByNameFirstLetter(R);o(I),c(R);return}}}d.current=-1,c(""),o(u=>u!=null&&u.length?[]:u)});return()=>{h.unsubscribe()}}},[n,e]),v.useEffect(()=>{e||m()},[e]),{searchList:r,searchText:i,handlerFormulaReplace:h=>{const g=[...f.current.nodes];if(d.current!==-1){const u=g.splice(d.current+1),_=g.pop()||"";let p=(typeof _=="string"?_.length:_.token.length)-h.length;return g.push(h),u[0]!==T.matchToken.OPEN_BRACKET&&(g.push(T.matchToken.OPEN_BRACKET),p--),{text:et([...g,...u]),offset:p}}},reset:m}},Yn=()=>{},zn=v.forwardRef(Gn);function Gn(e,t){const{isFocus:n,sequenceNodes:s,onSelect:r,editor:o,onClose:i=Yn}=e,c=o.getEditorId(),d=a.useDependency(a.IShortcutService),f=a.useDependency(l.ICommandService),{searchList:m,searchText:S,handlerFormulaReplace:h,reset:g}=qn(n,s,o),u=v.useMemo(()=>!!m.length,[m]),_=v.useRef(void 0),[p,C]=v.useState(0),R=v.useRef(!1),[I]=Pt(c,u,[S,m]),E=xe({searchList:m,active:p}),b=w=>{const $=h(w);$&&(g(),r($))};function M(w){R.current&&C(w)}function F(){R.current&&C(-1)}v.useEffect(()=>{if(!m.length)return;const w=`sheet.formula-embedding-editor.search_function.${c}`,$=new l.DisposableCollection,D=O=>{const{searchList:x,active:N}=E.current;switch(O){case a.KeyCode.ARROW_UP:{C(P=>{const j=Math.max(0,P-1);return L(j),j});break}case a.KeyCode.ARROW_DOWN:{C(P=>{const j=Math.min(x.length-1,P+1);return L(j),j});break}case a.KeyCode.TAB:case a.KeyCode.ENTER:{const P=x[N];b(P.name);break}case a.KeyCode.ESC:{g(),i();break}}};return $.add(f.registerCommand({id:w,type:l.CommandType.OPERATION,handler(O,x){const{keyCode:N}=x;D(N)}})),[a.KeyCode.ARROW_UP,a.KeyCode.ARROW_DOWN,a.KeyCode.ENTER,a.KeyCode.ESC,a.KeyCode.TAB].map(O=>({id:w,binding:O,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keyCode:O}})).forEach(O=>{$.add(d.registerShortcut(O))}),()=>{$.dispose()}},[m]);function L(w){const $=_.current;if(!$)return;const D=$.children[w];if(!D)return;const x=$.getBoundingClientRect().top,N=$.offsetHeight,P=D.getBoundingClientRect(),j=P.top,W=P.height;if(j>=0&&j>x&&j-x+W<=N)return;const B=D.offsetTop-(N-W)/2;$.scrollTo({top:B,behavior:"smooth"})}const U=v.useMemo(()=>{let w="";return()=>{clearTimeout(w),R.current=!0,w=setTimeout(()=>{R.current=!1},300)}},[]);return m.length>0&&u&&y.jsx(a.RectPopup,{portal:!0,anchorRect$:I,direction:"vertical",children:y.jsx("ul",{ref:w=>{_.current=w,t&&(t.current=w)},"data-u-comp":"sheets-formula-editor",className:V.clsx("univer-m-0 univer-box-border univer-max-h-[400px] univer-w-[250px] univer-list-none univer-overflow-y-auto univer-rounded-lg univer-bg-white univer-p-2 univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",V.borderClassName,V.scrollbarClassName),children:m.map((w,$)=>y.jsxs("li",{className:V.clsx("univer-box-border univer-cursor-pointer univer-rounded univer-px-2 univer-py-1 univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200 dark:!univer-bg-gray-600":p===$}),onMouseEnter:()=>M($),onMouseLeave:F,onMouseMove:U,onClick:()=>{b(w.name),o&&o.focus()},children:[y.jsxs("span",{className:"univer-text-xs",children:[y.jsx("span",{className:"univer-text-red-500",children:w.name.substring(0,S.length)}),y.jsx("span",{children:w.name.slice(S.length)})]}),y.jsx("span",{className:"univer-block univer-text-xs univer-text-gray-400",children:w.desc})]},w.name))})})}const Zn=e=>e.startsWith(T.operatorToken.EQUALS)?e.slice(1):"",St=()=>{},$t=v.forwardRef((e,t)=>{var lt,ut;const{errorText:n,initValue:s,unitId:r,subUnitId:o,isFocus:i=!0,isSupportAcrossSheet:c=!1,onFocus:d=St,onBlur:f=St,onChange:m,onVerify:S,className:h,editorId:g,moveCursor:u=!0,onFormulaSelectingChange:_,keyboardEventConfig:p,onMoveInEditor:C,resetSelectionOnBlur:R=!0,autoScrollbar:I=!0,isSingle:E=!0,disableSelectionOnClick:b=!1,autofocus:M=!0,disableContextMenu:F,style:L}=e,U=a.useDependency(Q.IEditorService),w=v.useRef(null),$=a.useEvent(m);v.useImperativeHandle(t,()=>({isClickOutSide:z=>w.current?!w.current.contains(z.target):!1}));const D=a.useEvent(_),O=v.useRef(null),x=v.useRef(void 0),N=x.current,[P,j]=v.useState(i),W=v.useRef(null),B=v.useMemo(()=>g!=null?g:l.createInternalEditorID(`${A.EMBEDDING_FORMULA_EDITOR}-${l.generateRandomId(4)}`),[]),ne=v.useMemo(()=>n!==void 0,[n]),Y=a.useDependency(l.IUniverInstanceService),ue=Y.getUnit(B);a.useObservable(ue==null?void 0:ue.change$);const Me=An(),ee=l.BuildTextUtils.transform.getPlainText((ut=(lt=ue==null?void 0:ue.getBody())==null?void 0:lt.dataStream)!=null?ut:""),Z=xe(ee),X=v.useMemo(()=>Zn(ee),[ee]),ce=v.useMemo(()=>Me(X),[X,Me]),{isSelecting:J,isSelectingRef:ae}=Dn({unitId:r,subUnitId:o,editorId:B,isFocus:P,disableOnClick:b}),re=v.useRef(""),Ce=a.useDependency(H.IRenderManagerService).getRenderById(B),ie=Ce==null?void 0:Ce.with(Q.DocSelectionRenderService),G=ie==null?void 0:ie.isFocusing,le=v.useMemo(()=>Y.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_DOC),[Y]),de=a.useObservable(le),ge=(de==null?void 0:de.getUnitId())===B,_e=v.useRef([]),he=J;a.useUpdateEffect(()=>{$(ee)},[ee,$]);const Ge=Ut("="),Ze=kn(r,o),Re=a.useEvent((z,te=!0,me,fe)=>{if(!x.current)return;re.current=z;const Pe=z[0]==="="?z.slice(1):"",Se=Me(Pe),zt=Se.reduce((Ee,Ue)=>typeof Ue=="object"?`${Ee}${Ue.token}`:`${Ee}${Ue}`,""),Le=Ge(x.current,zt===Pe?Se:[],te,fe);if(_e.current=Le,me){const Ee=fe!=null?fe:N==null?void 0:N.getSelectionRanges();if((Ee==null?void 0:Ee.length)!==1)return;const Gt=Ee[0].startOffset-1,Zt=ot(Se,Gt,!1),dt=xt(Se,Zt);if(dt>=0){const ht=Le.splice(dt,1)[0];ht&&Le.push(ht)}Ze(P?Le:[],x.current)}});v.useEffect(()=>{P&&Re(ee,!1,!0)},[P]),v.useEffect(()=>{if(P){if(re.current===ee)return;Re(ee,!1,!0)}},[ee]),Kn(P,S,ee);const Ne=Tn(N),at=$n(P,r,o);v.useEffect(()=>{var z;D(J,(z=ie==null?void 0:ie.isFocusing)!=null?z:!0)},[D,J]),Q.useKeyboardEvent(P,p,N),v.useLayoutEffect(()=>{let z;if(W.current){z=U.register({autofocus:M,editorUnitId:B,initialSnapshot:{id:B,body:{dataStream:`${s}\r
|
|
5
|
+
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},W.current);const te=U.getEditor(B);x.current=te,Re(s,!1,!0)}return()=>{z==null||z.dispose()}},[]),v.useLayoutEffect(()=>{i?(j(i),Ne()):(R&&(N==null||N.blur(),at()),j(i))},[i,N,Ne,at,R]);const{checkScrollBar:Ht}=Q.useResize(N,E,I);Un(P,!!(J&&ge),r,F),Ln(!!(P&&G&&u),he,N,C);const Kt=a.useEvent((z,te,me)=>{if(!G)return;const fe=te!==-1?[{startOffset:te+1,endOffset:te+1,collapsed:!0}]:void 0;Re(`=${z}`,!0,me,fe),me&&(Ne(),te!==-1&&setTimeout(()=>{const Pe={startOffset:te+1,endOffset:te+1},Se=N==null?void 0:N.render.with(Q.DocBackScrollRenderController);Se==null||Se.scrollToRange({...Pe,collapsed:!0})},50),Ht())});Bn(P&&!!(J&&ge),P,ae,r,o,_e,c,!!he,N,Kt),Hn(P&&!!(J&&ge),r,c,j,f,()=>{Re(Z.current,!1,!0)});const qt=z=>{if(z){const te=N==null?void 0:N.getSelectionRanges();if(te&&te.length===1){const me=te[0];if(me.collapsed){const fe=z.offset;setTimeout(()=>{N==null||N.setSelectionRanges([{startOffset:me.startOffset-fe,endOffset:me.endOffset-fe}])},30)}}Ne(),Re(`=${z.text}`)}},Yt=()=>{j(!0),d(),Ne()};return y.jsxs("div",{className:h,children:[y.jsx("div",{className:V.clsx(`
|
|
6
6
|
univer-relative univer-box-border univer-flex univer-h-full univer-w-full univer-items-center
|
|
7
7
|
univer-justify-around univer-gap-2 univer-rounded-none univer-p-0 univer-ring-1
|
|
8
|
-
`,{"univer-ring-primary-500":k,"univer-ring-red-500":ne}),ref:A,children:y.jsx("div",{ref:V,className:"univer-relative univer-h-full univer-w-full",onMouseUp:Yt})}),n!==void 0?y.jsx("div",{className:"univer-my-1 univer-text-xs univer-text-red-500",children:n}):null,N?y.jsx(bn,{editor:N,isFocus:k,formulaText:ee,onClose:()=>Oe()}):null,N?y.jsx(zn,{isFocus:k,sequenceNodes:ie,onSelect:qt,ref:O,editor:N}):null]})});function Xn(e,t,n,s){const r=l.useDependency(T.LexerTreeBuilder),o=jt(""),i=l.useObservable(e==null?void 0:e.getDocumentDataModel().change$),[c,d]=p.useState([]),f=l.useDependency(w.IMarkSelectionService),m=p.useRef(""),S=l.useDependency(a.IUniverInstanceService);return p.useEffect(()=>{if(!e)return;const h=e.getDocumentDataModel().getPlainText();if(m.current===h)return;m.current=h;const g=r.sequenceNodesBuilder(h);d(g!=null?g:[])},[i,e,r]),p.useEffect(()=>{var u,_;if(!e)return;if(!t){const v=e.getDocumentData();e.setDocumentData({...v,body:{...v.body,dataStream:(_=(u=v.body)==null?void 0:u.dataStream)!=null?_:"",textRuns:[]}});return}const h=o(e,c,!1),g=new a.DisposableCollection;return h.forEach(v=>{const C=T.deserializeRangeWithSheet(v.token),R=S.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),I=R==null?void 0:R.getActiveSheet();if(!C.sheetName&&s!==(I==null?void 0:I.getSheetId())||C.sheetName&&(I==null?void 0:I.getName())!==C.sheetName)return;const E=new a.ColorKit(v.themeColor).toRgb(),b=f.addShape({range:C.range,style:{stroke:v.themeColor,fill:`rgba(${E.r}, ${E.g}, ${E.b}, 0.1)`,strokeDash:12},primary:null});b&&g.add(()=>f.removeShape(b))}),()=>{g.dispose()}},[e,t,o,f,c]),{sequenceNodes:c}}function Jn(e){const t=l.useDependency($.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),f=l.useEvent((m,S)=>{const h=c==null?void 0:c.getActiveSheet();if(!h||!n&&h.getSheetId()!==r||!(m!=null&&m.length))return;const g=m.map(u=>({range:u.range,unitId:s,sheetName:h.getSheetId()===r?"":h.getName()}));d(g,S)});p.useEffect(()=>{const m=new a.DisposableCollection;return m.add(t.selectionMoveStart$.subscribe(S=>{f(S,!0)})),m.add(t.selectionMoving$.subscribe(S=>{f(S,!1)})),m.add(t.selectionMoveEnd$.subscribe(S=>{f(S,!1)})),()=>{m.dispose()}},[f,t.selectionMoveEnd$,t.selectionMoveStart$,t.selectionMoving$])}const vt=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}),Qn=e=>{if(e.endColumn<e.startColumn){const t=e.endColumn;e.endColumn=e.startColumn,e.startColumn=t}if(e.endRow<e.startRow){const t=e.endRow;e.endRow=e.startRow,e.startRow=t}return e};function er(e){const{visible:t,initialValue:n,unitId:s,subUnitId:r,maxRangeCount:o=1/0,supportAcrossSheet:i,onConfirm:c,onClose:d,onShowBySelection:f}=e,m=l.useDependency(a.LocaleService),S=l.useDependency(T.LexerTreeBuilder),[h,g]=p.useState([]),[u,_]=p.useState(0),v=p.useRef(null);p.useEffect(()=>{if(t&&n.length){const E=n.map(b=>b.sheetName?T.serializeRangeWithSheet(b.sheetName,b.range):T.serializeRange(b.range));g(E),_(E.length-1)}else g([""]),_(0)},[t]);const C=(E,b)=>{const M=[...h];M[E]=b,g(M)},R=()=>{g([...h,""]),_(h.length)},I=E=>{h.splice(E,1),g([...h])};return Jn({unitId:s,subUnitId:r,supportAcrossSheet:i,onChange:(E,b)=>{if(!t&&f!=null&&f(E))return;const M=new Set(h),F=E.map(A=>A.sheetName?T.serializeRangeWithSheet(A.sheetName,A.range):T.serializeRange(A.range)),L=F.filter(A=>!M.has(A));if(!L.length)return;const P=[...h];if(F.length>1){b||P.splice(u,1),P.push(...L);const A=P.slice(0,o);g(A),_(A.length-1),requestAnimationFrame(()=>{var j;(j=v.current)==null||j.scrollTo({top:v.current.scrollHeight})})}else{P.splice(u,1,...L);const A=P.slice(0,o);g(A),_(u+L.length-1)}}}),y.jsx(W.Dialog,{width:"328px",open:t,title:m.t("rangeSelector.title"),draggable:!0,mask:!1,maskClosable:!1,footer:y.jsxs("footer",{children:[y.jsx(W.Button,{onClick:d,children:m.t("rangeSelector.cancel")}),y.jsx(W.Button,{style:{marginLeft:10},variant:"primary",onClick:()=>{c(h.filter(E=>{const b=S.sequenceNodesBuilder(E);return b&&b.length===1&&typeof b[0]!="string"&&b[0].nodeType===T.sequenceNodeType.REFERENCE}).map(E=>T.deserializeRangeWithSheet(E)).map(E=>({...E,range:Qn(E.range)})))},children:m.t("rangeSelector.confirm")})]}),onClose:d,children:y.jsxs("div",{ref:v,className:W.clsx("-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6",W.scrollbarClassName),children:[h.map((E,b)=>y.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-gap-4",children:[y.jsx(W.Input,{className:"univer-w-full",placeholder:m.t("rangeSelector.placeHolder"),onFocus:()=>_(b),value:E,onChange:M=>C(b,M),style:{borderColor:u===b?"rgb(var(--primary-color))":void 0}}),h.length>1&&y.jsx(Dt,{className:"univer-cursor-pointer",onClick:()=>I(b)})]},b)),h.length<o&&y.jsx("div",{children:y.jsxs(W.Button,{variant:"link",onClick:R,children:[y.jsx(At,{}),y.jsx("span",{children:m.t("rangeSelector.addAnotherRange")})]})})]})})}function tr(e){return e.split(T.matchToken.COMMA).filter(t=>!!t).map(t=>T.deserializeRangeWithSheet(t))}function nr(e){return e.map(t=>t.sheetName?T.serializeRangeWithSheet(t.sheetName,t.range):T.serializeRange(t.range)).join(T.matchToken.COMMA)}function it(e){const[t,n]=p.useState(null),{onVerify:s,selectorRef:r,unitId:o,subUnitId:i,maxRangeCount:c,supportAcrossSheet:d,autoFocus:f,onChange:m,onRangeSelectorDialogVisibleChange:S,onClickOutside:h,onFocusChange:g,forceShowDialogWhenSelectionChanged:u,hideEditor:_,resetRange:v}=e,[C,R]=p.useState(f!=null?f:!1),[I,E]=p.useState(!1),[b,M]=p.useState([]),F=l.useDependency(a.LocaleService),L=l.useDependency(J.IEditorService),{sequenceNodes:P}=Xn(t,C,o,i),A=Te(P),j=l.useDependency(a.ICommandService),D=l.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),L.blur()}),O=l.useEvent(()=>{var x;D(),M(tr((x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:"")),E(!0)});return p.useEffect(()=>{r&&(r.current={get editor(){return t},focus(){L.focus(t.getEditorId())},blur:D,verify:()=>vt(A.current),showDialog:x=>{D(),M(x),E(!0)},hideDialog:()=>{M([]),E(!1)},getValue:()=>{var x;return(x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:""}})},[D,t,L,r,A]),p.useEffect(()=>{var x;s==null||s(vt(P),(x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:"")},[P]),p.useEffect(()=>{S==null||S(I)},[I]),p.useEffect(()=>{if(I&&v)return()=>{const x={unitId:o,subUnitId:i,selections:v};j.executeCommand($.SetSelectionsOperation.id,x)}},[I]),y.jsxs(y.Fragment,{children:[_?null:y.jsx(J.RichTextEditor,{isSingle:!0,...e,onFocusChange:(x,N)=>{R(x),g==null||g(x,N)},editorRef:n,onClickOutside:()=>{R(!1),D(),h==null||h()},icon:y.jsx(W.Tooltip,{title:F.t("rangeSelector.buttonTooltip"),placement:"bottom",children:y.jsx(Ft,{className:"univer-cursor-pointer",onClick:O})})}),y.jsx(er,{initialValue:b,unitId:o,subUnitId:i,visible:I,maxRangeCount:c,onConfirm:x=>{const N=nr(x),k=a.RichTextBuilder.newEmptyData();k.body.dataStream=N,t==null||t.replaceText(N,!1),m==null||m(k,N),E(!1),M([]),requestAnimationFrame(()=>{D()})},onClose:()=>{E(!1),M([])},supportAcrossSheet:d,onShowBySelection:x=>C||u?(M(x),E(!0),!1):!0})]})}class ct{constructor(){q(this,"_currentSelector$",new K.BehaviorSubject(null));q(this,"currentSelector$",this._currentSelector$.asObservable())}showRangeSelectorDialog(t){const n=t.callback,s=new Promise(r=>{t.callback=o=>{r(o),n(o)}});return this._currentSelector$.next(t),s}}var rr=Object.getOwnPropertyDescriptor,sr=(e,t,n,s)=>{for(var r=s>1?void 0:s?rr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Ue=(e,t)=>(n,s)=>t(n,s,e);exports.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===$.ReorderRangeCommand.id?this._reorderFormula(t.params):{redos:[],undos:[]}}))}_reorderFormula(t){const n=[],s=[],{unitId:r,subUnitId:o,range:i,order:c}=t,d=this._univerInstanceService.getUniverSheetInstance(r),f=d==null?void 0:d.getSheetBySheetId(o);if(!f)return{redos:n,undos:s};const m=f.getCellMatrix(),S=new a.ObjectMatrix,h=new a.ObjectMatrix;let g=!1;return a.Range.foreach(i,(u,_)=>{let v=u;c.hasOwnProperty(u)&&(v=c[u]);const C=m.getValue(v,_);if(C!=null&&C.f||C!=null&&C.si){g=!0;const R=this._formulaDataModel.getFormulaStringByCell(v,_,o,r),I=this._lexerTreeBuilder.moveFormulaRefOffset(R,0,u-v),E=a.Tools.deepClone(C);E.f=I,E.si=null,S.setValue(u,_,E)}else S.setValue(u,_,C);h.setValue(u,_,m.getValue(u,_))}),g?(n.push({id:$.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:o,cellValue:S.getMatrix()}}),s.push({id:$.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:o,cellValue:h.getMatrix()}}),{redos:n,undos:s}):{redos:n,undos:s}}};exports.FormulaReorderController=sr([Ue(0,a.Inject($.SheetInterceptorService)),Ue(1,a.Inject(a.IUniverInstanceService)),Ue(2,a.Inject(T.FormulaDataModel)),Ue(3,a.Inject(T.LexerTreeBuilder))],exports.FormulaReorderController);const or="sheets-formula-ui.base.config",pt={};function ir(e){return e.getContextValue(a.FOCUSING_DOC)&&e.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function $t(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 cr=Object.getOwnPropertyDescriptor,ar=(e,t,n,s)=>{for(var r=s>1?void 0:s?cr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},De=(e,t)=>(n,s)=>t(n,s,e);const Qe="SHEET_FORMULA_ALERT",lr={[T.ErrorType.DIV_BY_ZERO]:"divByZero",[T.ErrorType.NAME]:"name",[T.ErrorType.VALUE]:"value",[T.ErrorType.NUM]:"num",[T.ErrorType.NA]:"na",[T.ErrorType.CYCLE]:"cycle",[T.ErrorType.REF]:"ref",[T.ErrorType.SPILL]:"spill",[T.ErrorType.CALC]:"calc",[T.ErrorType.ERROR]:"error",[T.ErrorType.CONNECT]:"connect",[T.ErrorType.NULL]:"null"};let nt=class extends 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(K.debounceTime(100)).subscribe(e=>{var t,n,s,r,o;if(e){const c=this._context.unit.getActiveSheet();if(!c)return;const d=c.getCell(e.location.row,e.location.col),f=(r=(s=(n=(t=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:t[e.location.unitId])==null?void 0:n[e.location.subUnitId])==null?void 0:s[e.location.row])==null?void 0:r[e.location.col];if(a.isICellData(d)){const m=$t(d,!!f);if(!m){this._hideAlert();return}const S=this._cellAlertManagerService.currentAlert.get(Qe),h=(o=S==null?void 0:S.alert)==null?void 0:o.location;if(h&&h.row===e.location.row&&h.col===e.location.col&&h.subUnitId===e.location.subUnitId&&h.unitId===e.location.unitId)return;this._cellAlertManagerService.showAlert({type:w.CellAlertType.ERROR,title:this._localeService.t("formula.error.title"),message:this._localeService.t(`formula.error.${lr[m]}`),location:e.location,width:200,height:74,key:Qe});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(Qe)}};nt=ar([De(1,a.Inject(w.HoverManagerService)),De(2,a.Inject(w.CellAlertManagerService)),De(3,a.Inject(a.LocaleService)),De(4,a.Inject(T.FormulaDataModel)),De(5,l.IZenZoneService)],nt);var ur=Object.getOwnPropertyDescriptor,dr=(e,t,n,s)=>{for(var r=s>1?void 0:s?ur(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Ct=(e,t)=>(n,s)=>t(n,s,e);let Ve=class extends a.Disposable{constructor(e,t){super(),this._autoFillService=e,this._lexerTreeBuilder=t,this._registerAutoFill()}_registerAutoFill(){const e={type:w.DATA_TYPE.FORMULA,priority:1001,match:t=>a.isFormulaString(t==null?void 0:t.f)||a.isFormulaId(t==null?void 0:t.si),isContinue:(t,n)=>t.type===w.DATA_TYPE.FORMULA,applyFunctions:{[w.APPLY_TYPE.COPY]:(t,n,s,r,o)=>{const{data:i,index:c}=t;return this._fillCopyFormula(i,n,s,c,r,o)}}};this._autoFillService.registerRule(e)}_fillCopyFormula(e,t,n,s,r,o){var f,m;const i=fr(r),c=[],d=new Map;for(let S=1;S<=t;S++){const h=(S-1)%e.length,g=s[h],u=a.Tools.deepClone(e[h]);if(u){const _=((f=e[h])==null?void 0:f.f)||"",v=((m=e[h])==null?void 0:m.si)||"",C=a.isFormulaString(_);if(a.isFormulaId(v))u.si=v,u.f=null,u.v=null,u.p=null,u.t=null,c.push(u);else if(C){let I=d.get(h);if(I)u.si=I,u.f=null,u.v=null,u.p=null,u.t=null;else{I=a.Tools.generateRandomId(6),d.set(h,I);const{offsetX:E,offsetY:b}=hr(i,t,n,o,g),M=this._lexerTreeBuilder.moveFormulaRefOffset(_,E,b);u.si=I,u.f=M,u.v=null,u.p=null,u.t=null}c.push(u)}}}return c}};Ve=dr([Ct(0,w.IAutoFillService),Ct(1,a.Inject(T.LexerTreeBuilder))],Ve);function hr(e,t,n,s,r){const{source:o,target:i}=s,{rows:c}=i,{rows:d}=o;let f=0,m=0;switch(n){case a.Direction.UP:m=c[r]-d[r];break;case a.Direction.RIGHT:f=e;break;case a.Direction.DOWN:m=c[r]-d[r];break;case a.Direction.LEFT:f=-e*t;break}return{offsetX:f,offsetY:m}}function fr(e){let t=0;for(const n in e)e[n].forEach(s=>{t+=s.data.length});return t}var gr=Object.getOwnPropertyDescriptor,mr=(e,t,n,s)=>{for(var r=s>1?void 0:s?gr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Ae=(e,t)=>(n,s)=>t(n,s,e);const Sr="default-paste-formula";let We=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:w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA,priority:10,specialPasteInfo:{label:"specialPaste.formula"},onPasteCells:(e,t,n,s)=>this._onPasteCells(e,t,n,s,!0)}}_pasteWithFormulaHook(){return{id:Sr,priority:10,onPasteCells:(e,t,n,s)=>this._onPasteCells(e,t,n,s,!1)}}_onPasteCells(e,t,n,s,r){var h;if([w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH].includes(s.pasteType))return{undos:[],redos:[]};const i=this._currentUniverSheet.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),c=t.unitId||i.getUnitId(),d=t.subUnitId||((h=i.getActiveSheet())==null?void 0:h.getSheetId());if(!c||!d)return{undos:[],redos:[]};const f=t.range,m=n,S={copyType:s.copyType||w.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:s.pasteType};return this._injector.invoke(g=>vr(c,d,f,m,g,S,this._lexerTreeBuilder,this._formulaDataModel,r,e))}};We=mr([Ae(0,a.IUniverInstanceService),Ae(1,a.Inject(T.LexerTreeBuilder)),Ae(2,w.ISheetClipboardService),Ae(3,a.Inject(a.Injector)),Ae(4,a.Inject(T.FormulaDataModel))],We);function vr(e,t,n,s,r,o,i,c,d=!1,f){const m=[],S=[],h=pr(e,t,n,s,o,i,c,f);if(!h.hasValue())return{undos:[],redos:[]};const g={unitId:e,subUnitId:t,cellValue:h.getData()};m.push({id:$.SetRangeValuesMutation.id,params:g});const u=$.SetRangeValuesUndoMutationFactory(r,g);return S.push({id:$.SetRangeValuesMutation.id,params:u}),{undos:S,redos:m}}function pr(e,t,n,s,r,o,i,c){return c?r.pasteType===w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE?_r(e,t,n,s,i,c):r.pasteType===w.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA?Rr(e,t,n,s,o,i,c):Er(e,t,n,s,r.copyType,o,i,c):Cr(e,t,n,s,i)}function Cr(e,t,n,s,r){const o=new a.ObjectMatrix,i=r.getSheetFormulaData(e,t);return s.forValue((c,d,f)=>{var g;const m=n.rows[c],S=n.cols[d],h={};a.isFormulaString(f.v)?(h.v=null,h.f=`${f.v}`,h.si=null,h.p=null,o.setValue(m,S,h)):(g=i==null?void 0:i[m])!=null&&g[S]&&(h.v=f.v,h.f=null,h.si=null,h.p=null,o.setValue(m,S,h))}),o}function _r(e,t,n,s,r,o){var f,m;const i=new a.ObjectMatrix,c=(m=(f=r.getArrayFormulaCellData())==null?void 0:f[o.unitId])==null?void 0:m[o.subUnitId],d=r.getSheetFormulaData(e,t);return s.forValue((S,h,g)=>{var I,E;const u=o.range.rows[S%o.range.rows.length],_=o.range.cols[h%o.range.cols.length],v=n.rows[S],C=n.cols[h],R={};if(a.isFormulaString(g.f)||a.isFormulaId(g.si))R.v=g.v,R.f=null,R.si=null,R.p=null,i.setValue(v,C,R);else if((I=c==null?void 0:c[u])!=null&&I[_]){const b=c[u][_];R.v=b.v,R.f=null,R.si=null,R.p=null,i.setValue(v,C,R)}else if((E=d==null?void 0:d[v])!=null&&E[C]){if(R.v=g.v,R.f=null,R.si=null,R.p=null,g.p){const b=Vt(g);b&&(R.v=b)}i.setValue(v,C,R)}}),i}function Rr(e,t,n,s,r,o,i){const c=new a.ObjectMatrix,d=new Map;return s.forValue((f,m,S)=>{const h=n.rows[f],g=n.cols[m],u={};if(a.isFormulaId(S.si)){if(i.unitId!==e||i.subUnitId!==t){const _=o.getFormulaStringByCell(i.range.rows[f%i.range.rows.length],i.range.cols[m%i.range.cols.length],i.subUnitId,i.unitId),v=n.cols[m]-i.range.cols[m%i.range.cols.length],C=n.rows[f]-i.range.rows[f%i.range.rows.length],R=r.moveFormulaRefOffset(_||"",v,C);u.si=null,u.f=R}else u.si=S.si,u.f=null;u.v=null,u.p=null,c.setValue(h,g,u)}else if(a.isFormulaString(S.f)){const _=`${f%i.range.rows.length}_${m%i.range.cols.length}`;let v=d.get(_);if(v)u.si=v,u.f=null;else{v=a.Tools.generateRandomId(6),d.set(_,v);const C=n.cols[m]-i.range.cols[m%i.range.cols.length],R=n.rows[f]-i.range.rows[f%i.range.rows.length],I=r.moveFormulaRefOffset(S.f||"",C,R);u.si=v,u.f=I}u.v=null,u.p=null,c.setValue(h,g,u)}else{if(u.v=S.v,u.f=null,u.si=null,u.p=null,S.p){const _=Vt(S);_&&(u.v=_)}c.setValue(h,g,u)}}),c}function Er(e,t,n,s,r,o,i,c){const d=new a.ObjectMatrix,f=new Map,m=i.getSheetFormulaData(e,t),S=[];return r===w.COPY_TYPE.CUT?s.forValue((h,g,u)=>{const _=n.rows[h],v=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 R=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[g%c.range.cols.length],c.subUnitId,c.unitId);C.f=R,C.si=null}C.v=null,C.p=null,d.setValue(_,v,C)}else a.isFormulaString(u.f)&&(C.f=u.f,C.si=null,C.v=null,C.p=null,d.setValue(_,v,C))}):s.forValue((h,g,u)=>{var R;const _=n.rows[h],v=n.cols[g],C={};if(a.isFormulaId(u.si)){if(c.unitId!==e||c.subUnitId!==t){const I=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[g%c.range.cols.length],c.subUnitId,c.unitId),E=n.cols[g]-c.range.cols[g%c.range.cols.length],b=n.rows[h]-c.range.rows[h%c.range.rows.length],M=o.moveFormulaRefOffset(I||"",E,b);C.si=null,C.f=M}else C.si=u.si,C.f=null;C.v=null,C.p=null,d.setValue(_,v,C)}else if(a.isFormulaString(u.f)){const I=`${h%c.range.rows.length}_${g%c.range.cols.length}`;let E=f.get(I);if(E)C.si=E,C.f=null;else{E=a.Tools.generateRandomId(6),f.set(I,E);const b=n.cols[g]-c.range.cols[g%c.range.cols.length],M=n.rows[h]-c.range.rows[h%c.range.rows.length],F=o.moveFormulaRefOffset(u.f||"",b,M);C.si=E,C.f=F}C.v=null,C.p=null,d.setValue(_,v,C)}else(R=m==null?void 0:m[_])!=null&&R[v]&&(C.v=u.v,C.f=null,C.si=null,C.p=u.p,d.setValue(_,v,C))}),S.length>0&&new a.ObjectMatrix(m).forValue((h,g,u)=>{if(!(c.range.rows.includes(h)&&c.range.cols.includes(g))&&!(n.rows.includes(h)&&n.cols.includes(g))&&S.includes(u==null?void 0:u.si)){const _=i.getFormulaStringByCell(h,g,c.subUnitId,c.unitId);d.setValue(h,g,{f:_,si:null,v:null,p:null})}}),d}function Vt(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 yr=Object.getOwnPropertyDescriptor,Ir=(e,t,n,s)=>{for(var r=s>1?void 0:s?yr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Re=(e,t)=>(n,s)=>t(n,s,e);let Be=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($.BEFORE_CELL_EDIT,{handler:(t,n,s)=>{var u,_,v,C;const{row:r,col:o,unitId:i,subUnitId:c,worksheet:d}=n,f=this._formulaDataModel.getArrayFormulaRange(),m=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return s(t);let S=null;const h=this._formulaDataModel.getFormulaStringByCell(r,o,c,i);if(h!==null&&(S={f:h}),t.v!=null&&t.v!==""&&((v=(_=(u=m[i])==null?void 0:u[c])==null?void 0:_[r])==null?void 0:v[o])==null)return S?{...t,...S}:s(t);const g=(C=f==null?void 0:f[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=>{$.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((f,m,S)=>{var v;if(S==null)return!0;const{startRow:h,startColumn:g,endRow:u,endColumn:_}=S;if(f===n&&m===s)return this._createArrayFormulaRangeShape(S,r),!1;if(n>=h&&n<=u&&s>=g&&s<=_){const C=i.getCell(h,g);if((C==null?void 0:C.v)===T.ErrorType.SPILL)return;const R=(v=d==null?void 0:d[f])==null?void 0:v[m];return R==null||R.f==null?!0:(c==null&&(c={f:R.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={range:t,primary:null,style:{strokeWidth:1,stroke:this._themeService.getColorFromTheme("primary.600"),fill:new a.ColorKit(this._themeService.getColorFromTheme("white")).setAlpha(0).toString(),widgets:{}}},c=w.attachSelectionWithCoord(i,r),{rowHeaderWidth:d,columnHeaderHeight:f}=r,m=new w.SelectionControl(o,w.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:d,columnHeaderHeight:f});m.updateRangeBySelectionWithCoord(c),m.setEvent(!1),this._previousShape=m}_removeArrayFormulaRangeShape(){this._previousShape!=null&&(this._previousShape.dispose(),this._previousShape=null)}_refreshArrayFormulaRangeShape(t,n){if(this._previousShape){const{startRow:s,endRow:r,startColumn:o,endColumn:i}=this._previousShape.getRange(),c={startRow:s,endRow:r,startColumn:o,endColumn:i};this._removeArrayFormulaRangeShape(),this._createArrayFormulaRangeShape(c,t)}}_checkCurrentSheet(t,n){const s=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!s)return!1;const r=s.worksheet;return r?r.unitId===t&&r.getSheetId()===n:!1}_updateArrayFormulaRangeShape(t,n){this._checkCurrentSheet(t,n)&&this._previousShape&&this._refreshArrayFormulaRangeShape(t)}_refreshArrayFormulaRangeShapeByRow(t,n,s){if(!this._checkCurrentSheet(t,n)||!this._previousShape)return;const{startRow:r,endRow:o,startColumn:i,endColumn:c}=this._previousShape.getRange();for(let d=0;d<s.length;d++){const{row:f}=s[d];if(r>=f){const m={startRow:r,endRow:o,startColumn:i,endColumn:c};this._refreshArrayFormulaRangeShape(t,m);break}}}};Be=Ir([Re(1,a.Inject($.SheetInterceptorService)),Re(2,a.Inject(T.FormulaDataModel)),Re(3,a.Inject(a.ThemeService)),Re(4,H.IRenderManagerService),Re(5,a.Inject(w.SheetSkeletonManagerService)),Re(6,a.ICommandService),Re(7,a.ILogService)],Be);var br=Object.getOwnPropertyDescriptor,Tr=(e,t,n,s)=>{for(var r=s>1?void 0:s?br(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},_t=(e,t)=>(n,s)=>t(n,s,e);const xr={tl:{size:6,color:"#409f11"}};let He=class extends a.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept($.INTERCEPTOR_POINT.CELL_CONTENT,{effect:a.InterceptorEffectEnum.Style,handler:(n,s,r)=>{var c,d,f,m;const o=(m=(f=(d=(c=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:c[s.unitId])==null?void 0:d[s.subUnitId])==null?void 0:f[s.row])==null?void 0:m[s.col];return $t(n,!!o)?r({...n,markers:{...n==null?void 0:n.markers,...xr}}):r(n)},priority:10}))}};He=Tr([_t(0,a.Inject($.SheetInterceptorService)),_t(1,a.Inject(T.FormulaDataModel))],He);function Mr(){const e=l.useDependency(ye.TriggerCalculationController),t=l.useDependency(a.ICommandService),n=l.useObservable(e.progress$),s=p.useCallback(()=>{t.executeCommand(T.SetFormulaCalculationStopMutation.id)},[t]),r=p.useCallback(()=>{e.clearProgress()},[e]);return y.jsx(l.ProgressBar,{progress:n,onTerminate:s,onClearProgress:r})}function Wt(e){const{prefix:t,value:n}=e;return y.jsxs("div",{children:[y.jsxs("span",{children:[t,"("]}),n&&n.map((s,r)=>y.jsxs("span",{children:[y.jsx("span",{children:kt(s)}),r===n.length-1?"":","]},r)),")"]})}function we(e){const{className:t,value:n,title:s}=e;return y.jsxs("div",{className:"univer-mb-2 univer-text-xs",children:[y.jsx("div",{className:`
|
|
8
|
+
`,{"univer-ring-primary-500":P,"univer-ring-red-500":ne}),ref:w,children:y.jsx("div",{ref:W,className:"univer-relative univer-h-full univer-w-full",onMouseUp:Yt})}),n!==void 0?y.jsx("div",{className:"univer-my-1 univer-text-xs univer-text-red-500",children:n}):null,N?y.jsx(bn,{editor:N,isFocus:P,formulaText:ee,onClose:()=>Ne()}):null,N?y.jsx(zn,{isFocus:P,sequenceNodes:ce,onSelect:qt,ref:O,editor:N}):null]})});function Xn(e,t,n,s){const r=a.useDependency(T.LexerTreeBuilder),o=Ut(""),i=a.useObservable(e==null?void 0:e.getDocumentDataModel().change$),[c,d]=v.useState([]),f=a.useDependency(A.IMarkSelectionService),m=v.useRef(""),S=a.useDependency(l.IUniverInstanceService);return v.useEffect(()=>{if(!e)return;const h=e.getDocumentDataModel().getPlainText();if(m.current===h)return;m.current=h;const g=r.sequenceNodesBuilder(h);d(g!=null?g:[])},[i,e,r]),v.useEffect(()=>{var u,_;if(!e)return;if(!t){const p=e.getDocumentData();e.setDocumentData({...p,body:{...p.body,dataStream:(_=(u=p.body)==null?void 0:u.dataStream)!=null?_:"",textRuns:[]}});return}const h=o(e,c,!1),g=new l.DisposableCollection;return h.forEach(p=>{const C=T.deserializeRangeWithSheet(p.token),R=S.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),I=R==null?void 0:R.getActiveSheet();if(!C.sheetName&&s!==(I==null?void 0:I.getSheetId())||C.sheetName&&(I==null?void 0:I.getName())!==C.sheetName)return;const E=new l.ColorKit(p.themeColor).toRgb(),b=f.addShape({range:C.range,style:{stroke:p.themeColor,fill:`rgba(${E.r}, ${E.g}, ${E.b}, 0.1)`,strokeDash:12},primary:null});b&&g.add(()=>f.removeShape(b))}),()=>{g.dispose()}},[e,t,o,f,c]),{sequenceNodes:c}}function Qn(e){const t=a.useDependency(k.SheetsSelectionsService),{supportAcrossSheet:n=!1,unitId:s,subUnitId:r,onChange:o}=e,c=a.useDependency(l.IUniverInstanceService).getUnit(s,l.UniverInstanceType.UNIVER_SHEET),d=a.useEvent(o),f=a.useEvent((m,S)=>{const h=c==null?void 0:c.getActiveSheet();if(!h||!n&&h.getSheetId()!==r||!(m!=null&&m.length))return;const g=m.map(u=>({range:u.range,unitId:s,sheetName:h.getSheetId()===r?"":h.getName()}));d(g,S)});v.useEffect(()=>{const m=new l.DisposableCollection;return m.add(t.selectionMoveStart$.subscribe(S=>{f(S,!0)})),m.add(t.selectionMoving$.subscribe(S=>{f(S,!1)})),m.add(t.selectionMoveEnd$.subscribe(S=>{f(S,!1)})),()=>{m.dispose()}},[f,t.selectionMoveEnd$,t.selectionMoveStart$,t.selectionMoving$])}const pt=e=>!e.some(n=>{if(typeof n=="string"){if(n!==T.matchToken.COMMA)return!0}else if(n.nodeType!==T.sequenceNodeType.REFERENCE)return!0;return!1}),Jn=e=>{if(e.endColumn<e.startColumn){const t=e.endColumn;e.endColumn=e.startColumn,e.startColumn=t}if(e.endRow<e.startRow){const t=e.endRow;e.endRow=e.startRow,e.startRow=t}return e};function er(e){const{visible:t,initialValue:n,unitId:s,subUnitId:r,maxRangeCount:o=1/0,supportAcrossSheet:i,onConfirm:c,onClose:d,onShowBySelection:f}=e,m=a.useDependency(l.LocaleService),S=a.useDependency(T.LexerTreeBuilder),[h,g]=v.useState([]),[u,_]=v.useState(0),p=v.useRef(null);v.useEffect(()=>{if(t&&n.length){const E=n.map(b=>b.sheetName?T.serializeRangeWithSheet(b.sheetName,b.range):T.serializeRange(b.range));g(E),_(E.length-1)}else g([""]),_(0)},[t]);const C=(E,b)=>{const M=[...h];M[E]=b,g(M)},R=()=>{g([...h,""]),_(h.length)},I=E=>{h.splice(E,1),g([...h])};return Qn({unitId:s,subUnitId:r,supportAcrossSheet:i,onChange:(E,b)=>{if(!t&&f!=null&&f(E))return;const M=new Set(h),F=E.map(w=>w.sheetName?T.serializeRangeWithSheet(w.sheetName,w.range):T.serializeRange(w.range)),L=F.filter(w=>!M.has(w));if(!L.length)return;const U=[...h];if(F.length>1){b||U.splice(u,1),U.push(...L);const w=U.slice(0,o);g(w),_(w.length-1),requestAnimationFrame(()=>{var $;($=p.current)==null||$.scrollTo({top:p.current.scrollHeight})})}else{U.splice(u,1,...L);const w=U.slice(0,o);g(w),_(u+L.length-1)}}}),y.jsx(V.Dialog,{width:"328px",open:t,title:m.t("rangeSelector.title"),draggable:!0,mask:!1,maskClosable:!1,footer:y.jsxs("footer",{className:"univer-flex univer-gap-2",children:[y.jsx(V.Button,{onClick:d,children:m.t("rangeSelector.cancel")}),y.jsx(V.Button,{variant:"primary",onClick:()=>{c(h.filter(E=>{const b=S.sequenceNodesBuilder(E);return b&&b.length===1&&typeof b[0]!="string"&&b[0].nodeType===T.sequenceNodeType.REFERENCE}).map(E=>T.deserializeRangeWithSheet(E)).map(E=>({...E,range:Jn(E.range)})))},children:m.t("rangeSelector.confirm")})]}),onClose:d,children:y.jsxs("div",{ref:p,className:V.clsx("-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6",V.scrollbarClassName),children:[h.map((E,b)=>y.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-gap-4",children:[y.jsx(V.Input,{className:V.clsx("univer-w-full",{"univer-border-primary-600":u===b}),placeholder:m.t("rangeSelector.placeHolder"),onFocus:()=>_(b),value:E,onChange:M=>C(b,M)}),h.length>1&&y.jsx(Dt,{className:"univer-cursor-pointer",onClick:()=>I(b)})]},b)),h.length<o&&y.jsx("div",{children:y.jsxs(V.Button,{variant:"link",onClick:R,children:[y.jsx(At,{}),y.jsx("span",{children:m.t("rangeSelector.addAnotherRange")})]})})]})})}function tr(e){return e.split(T.matchToken.COMMA).filter(t=>!!t).map(t=>T.deserializeRangeWithSheet(t))}function nr(e){return e.map(t=>t.sheetName?T.serializeRangeWithSheet(t.sheetName,t.range):T.serializeRange(t.range)).join(T.matchToken.COMMA)}function it(e){const[t,n]=v.useState(null),{onVerify:s,selectorRef:r,unitId:o,subUnitId:i,maxRangeCount:c,supportAcrossSheet:d,autoFocus:f,onChange:m,onRangeSelectorDialogVisibleChange:S,onClickOutside:h,onFocusChange:g,forceShowDialogWhenSelectionChanged:u,hideEditor:_,resetRange:p}=e,[C,R]=v.useState(f!=null?f:!1),[I,E]=v.useState(!1),[b,M]=v.useState([]),F=a.useDependency(l.LocaleService),L=a.useDependency(Q.IEditorService),{sequenceNodes:U}=Xn(t,C,o,i),w=xe(U),$=a.useDependency(l.ICommandService),D=a.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),L.blur()}),O=a.useEvent(()=>{var x;D(),M(tr((x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:"")),E(!0)});return v.useEffect(()=>{r&&(r.current={get editor(){return t},focus(){L.focus(t.getEditorId())},blur:D,verify:()=>pt(w.current),showDialog:x=>{D(),M(x),E(!0)},hideDialog:()=>{M([]),E(!1)},getValue:()=>{var x;return(x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:""}})},[D,t,L,r,w]),v.useEffect(()=>{var x;s==null||s(pt(U),(x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:"")},[U]),v.useEffect(()=>{S==null||S(I)},[I]),v.useEffect(()=>{if(I&&p)return()=>{const x={unitId:o,subUnitId:i,selections:p};$.executeCommand(k.SetSelectionsOperation.id,x)}},[I]),y.jsxs(y.Fragment,{children:[_?null:y.jsx(Q.RichTextEditor,{isSingle:!0,...e,onFocusChange:(x,N)=>{R(x),g==null||g(x,N)},editorRef:n,onClickOutside:()=>{R(!1),D(),h==null||h()},icon:y.jsx(V.Tooltip,{title:F.t("rangeSelector.buttonTooltip"),placement:"bottom",children:y.jsx(kt,{className:"univer-cursor-pointer dark:!univer-text-gray-300",onClick:O})})}),y.jsx(er,{initialValue:b,unitId:o,subUnitId:i,visible:I,maxRangeCount:c,onConfirm:x=>{const N=nr(x),P=l.RichTextBuilder.newEmptyData();P.body.dataStream=N,t==null||t.replaceText(N,!1),m==null||m(P,N),E(!1),M([]),requestAnimationFrame(()=>{D()})},onClose:()=>{E(!1),M([])},supportAcrossSheet:d,onShowBySelection:x=>C||u?(M(x),E(!0),!1):!0})]})}class ct{constructor(){q(this,"_currentSelector$",new K.BehaviorSubject(null));q(this,"currentSelector$",this._currentSelector$.asObservable())}showRangeSelectorDialog(t){const n=t.callback,s=new Promise(r=>{t.callback=o=>{r(o),n(o)}});return this._currentSelector$.next(t),s}}var rr=Object.getOwnPropertyDescriptor,sr=(e,t,n,s)=>{for(var r=s>1?void 0:s?rr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},je=(e,t)=>(n,s)=>t(n,s,e);exports.FormulaReorderController=class extends l.Disposable{constructor(t,n,s,r){super(),this._sheetInterceptorService=t,this._univerInstanceService=n,this._formulaDataModel=s,this._lexerTreeBuilder=r,this._initialize()}_initialize(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>t.id===k.ReorderRangeCommand.id?this._reorderFormula(t.params):{redos:[],undos:[]}}))}_reorderFormula(t){const n=[],s=[],{unitId:r,subUnitId:o,range:i,order:c}=t,d=this._univerInstanceService.getUniverSheetInstance(r),f=d==null?void 0:d.getSheetBySheetId(o);if(!f)return{redos:n,undos:s};const m=f.getCellMatrix(),S=new l.ObjectMatrix,h=new l.ObjectMatrix;let g=!1;return l.Range.foreach(i,(u,_)=>{let p=u;c.hasOwnProperty(u)&&(p=c[u]);const C=m.getValue(p,_);if(C!=null&&C.f||C!=null&&C.si){g=!0;const R=this._formulaDataModel.getFormulaStringByCell(p,_,o,r),I=this._lexerTreeBuilder.moveFormulaRefOffset(R,0,u-p),E=l.Tools.deepClone(C);E.f=I,E.si=null,S.setValue(u,_,E)}else S.setValue(u,_,C);h.setValue(u,_,m.getValue(u,_))}),g?(n.push({id:k.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:o,cellValue:S.getMatrix()}}),s.push({id:k.SetRangeValuesMutation.id,params:{unitId:r,subUnitId:o,cellValue:h.getMatrix()}}),{redos:n,undos:s}):{redos:n,undos:s}}};exports.FormulaReorderController=sr([je(0,l.Inject(k.SheetInterceptorService)),je(1,l.Inject(l.IUniverInstanceService)),je(2,l.Inject(T.FormulaDataModel)),je(3,l.Inject(T.LexerTreeBuilder))],exports.FormulaReorderController);const or="sheets-formula-ui.base.config",vt={};function ir(e){return e.getContextValue(l.FOCUSING_DOC)&&e.getContextValue(l.FOCUSING_UNIVER_EDITOR)}function jt(e,t=!1){return!t&&!(l.isFormulaString(e==null?void 0:e.f)||l.isFormulaId(e==null?void 0:e.si))?null:typeof(e==null?void 0:e.v)=="string"&&T.ERROR_TYPE_SET.has(e.v)?e.v:null}var cr=Object.getOwnPropertyDescriptor,ar=(e,t,n,s)=>{for(var r=s>1?void 0:s?cr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Ae=(e,t)=>(n,s)=>t(n,s,e);const Qe="SHEET_FORMULA_ALERT",lr={[T.ErrorType.DIV_BY_ZERO]:"divByZero",[T.ErrorType.NAME]:"name",[T.ErrorType.VALUE]:"value",[T.ErrorType.NUM]:"num",[T.ErrorType.NA]:"na",[T.ErrorType.CYCLE]:"cycle",[T.ErrorType.REF]:"ref",[T.ErrorType.SPILL]:"spill",[T.ErrorType.CALC]:"calc",[T.ErrorType.ERROR]:"error",[T.ErrorType.CONNECT]:"connect",[T.ErrorType.NULL]:"null"};let tt=class extends l.Disposable{constructor(e,t,n,s,r,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=s,this._formulaDataModel=r,this._zenZoneService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(K.debounceTime(100)).subscribe(e=>{var t,n,s,r,o;if(e){const c=this._context.unit.getActiveSheet();if(!c)return;const d=c.getCell(e.location.row,e.location.col),f=(r=(s=(n=(t=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:t[e.location.unitId])==null?void 0:n[e.location.subUnitId])==null?void 0:s[e.location.row])==null?void 0:r[e.location.col];if(l.isICellData(d)){const m=jt(d,!!f);if(!m){this._hideAlert();return}const S=this._cellAlertManagerService.currentAlert.get(Qe),h=(o=S==null?void 0:S.alert)==null?void 0:o.location;if(h&&h.row===e.location.row&&h.col===e.location.col&&h.subUnitId===e.location.subUnitId&&h.unitId===e.location.unitId)return;this._cellAlertManagerService.showAlert({type:A.CellAlertType.ERROR,title:this._localeService.t("formula.error.title"),message:this._localeService.t(`formula.error.${lr[m]}`),location:e.location,width:200,height:74,key:Qe});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(Qe)}};tt=ar([Ae(1,l.Inject(A.HoverManagerService)),Ae(2,l.Inject(A.CellAlertManagerService)),Ae(3,l.Inject(l.LocaleService)),Ae(4,l.Inject(T.FormulaDataModel)),Ae(5,a.IZenZoneService)],tt);var ur=Object.getOwnPropertyDescriptor,dr=(e,t,n,s)=>{for(var r=s>1?void 0:s?ur(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Ct=(e,t)=>(n,s)=>t(n,s,e);let Ve=class extends l.Disposable{constructor(e,t){super(),this._autoFillService=e,this._lexerTreeBuilder=t,this._registerAutoFill()}_registerAutoFill(){const e={type:A.DATA_TYPE.FORMULA,priority:1001,match:t=>l.isFormulaString(t==null?void 0:t.f)||l.isFormulaId(t==null?void 0:t.si),isContinue:(t,n)=>t.type===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 f,m;const i=fr(r),c=[],d=new Map;for(let S=1;S<=t;S++){const h=(S-1)%e.length,g=s[h],u=l.Tools.deepClone(e[h]);if(u){const _=((f=e[h])==null?void 0:f.f)||"",p=((m=e[h])==null?void 0:m.si)||"",C=l.isFormulaString(_);if(l.isFormulaId(p))u.si=p,u.f=null,u.v=null,u.p=null,u.t=null,c.push(u);else if(C){let I=d.get(h);if(I)u.si=I,u.f=null,u.v=null,u.p=null,u.t=null;else{I=l.Tools.generateRandomId(6),d.set(h,I);const{offsetX:E,offsetY:b}=hr(i,t,n,o,g),M=this._lexerTreeBuilder.moveFormulaRefOffset(_,E,b);u.si=I,u.f=M,u.v=null,u.p=null,u.t=null}c.push(u)}}}return c}};Ve=dr([Ct(0,A.IAutoFillService),Ct(1,l.Inject(T.LexerTreeBuilder))],Ve);function hr(e,t,n,s,r){const{source:o,target:i}=s,{rows:c}=i,{rows:d}=o;let f=0,m=0;switch(n){case l.Direction.UP:m=c[r]-d[r];break;case l.Direction.RIGHT:f=e;break;case l.Direction.DOWN:m=c[r]-d[r];break;case l.Direction.LEFT:f=-e*t;break}return{offsetX:f,offsetY:m}}function fr(e){let t=0;for(const n in e)e[n].forEach(s=>{t+=s.data.length});return t}var gr=Object.getOwnPropertyDescriptor,mr=(e,t,n,s)=>{for(var r=s>1?void 0:s?gr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},we=(e,t)=>(n,s)=>t(n,s,e);const Sr="default-paste-formula";let Be=class extends l.Disposable{constructor(e,t,n,s,r){super(),this._currentUniverSheet=e,this._lexerTreeBuilder=t,this._sheetClipboardService=n,this._injector=s,this._formulaDataModel=r,this._initialize()}_initialize(){this._registerClipboardHook()}_registerClipboardHook(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteFormulaHook())),this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteWithFormulaHook()))}_pasteFormulaHook(){return{id: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:Sr,priority:10,onPasteCells:(e,t,n,s)=>this._onPasteCells(e,t,n,s,!1)}}_onPasteCells(e,t,n,s,r){var h;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(l.UniverInstanceType.UNIVER_SHEET),c=t.unitId||i.getUnitId(),d=t.subUnitId||((h=i.getActiveSheet())==null?void 0:h.getSheetId());if(!c||!d)return{undos:[],redos:[]};const f=t.range,m=n,S={copyType:s.copyType||A.COPY_TYPE.COPY,copyRange:e==null?void 0:e.range,pasteType:s.pasteType};return this._injector.invoke(g=>pr(c,d,f,m,g,S,this._lexerTreeBuilder,this._formulaDataModel,r,e))}};Be=mr([we(0,l.IUniverInstanceService),we(1,l.Inject(T.LexerTreeBuilder)),we(2,A.ISheetClipboardService),we(3,l.Inject(l.Injector)),we(4,l.Inject(T.FormulaDataModel))],Be);function pr(e,t,n,s,r,o,i,c,d=!1,f){const m=[],S=[],h=vr(e,t,n,s,o,i,c,f);if(!h.hasValue())return{undos:[],redos:[]};const g={unitId:e,subUnitId:t,cellValue:h.getData()};m.push({id:k.SetRangeValuesMutation.id,params:g});const u=k.SetRangeValuesUndoMutationFactory(r,g);return S.push({id:k.SetRangeValuesMutation.id,params:u}),{undos:S,redos:m}}function vr(e,t,n,s,r,o,i,c){return c?r.pasteType===A.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE?_r(e,t,n,s,i,c):r.pasteType===A.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA?Rr(e,t,n,s,o,i,c):Er(e,t,n,s,r.copyType,o,i,c):Cr(e,t,n,s,i)}function Cr(e,t,n,s,r){const o=new l.ObjectMatrix,i=r.getSheetFormulaData(e,t);return s.forValue((c,d,f)=>{var g;const m=n.rows[c],S=n.cols[d],h={};l.isFormulaString(f.v)?(h.v=null,h.f=`${f.v}`,h.si=null,h.p=null,o.setValue(m,S,h)):(g=i==null?void 0:i[m])!=null&&g[S]&&(h.v=f.v,h.f=null,h.si=null,h.p=null,o.setValue(m,S,h))}),o}function _r(e,t,n,s,r,o){var f,m;const i=new l.ObjectMatrix,c=(m=(f=r.getArrayFormulaCellData())==null?void 0:f[o.unitId])==null?void 0:m[o.subUnitId],d=r.getSheetFormulaData(e,t);return s.forValue((S,h,g)=>{var I,E;const u=o.range.rows[S%o.range.rows.length],_=o.range.cols[h%o.range.cols.length],p=n.rows[S],C=n.cols[h],R={};if(l.isFormulaString(g.f)||l.isFormulaId(g.si))R.v=g.v,R.f=null,R.si=null,R.p=null,i.setValue(p,C,R);else if((I=c==null?void 0:c[u])!=null&&I[_]){const b=c[u][_];R.v=b.v,R.f=null,R.si=null,R.p=null,i.setValue(p,C,R)}else if((E=d==null?void 0:d[p])!=null&&E[C]){if(R.v=g.v,R.f=null,R.si=null,R.p=null,g.p){const b=Wt(g);b&&(R.v=b)}i.setValue(p,C,R)}}),i}function Rr(e,t,n,s,r,o,i){const c=new l.ObjectMatrix,d=new Map;return s.forValue((f,m,S)=>{const h=n.rows[f],g=n.cols[m],u={};if(l.isFormulaId(S.si)){if(i.unitId!==e||i.subUnitId!==t){const _=o.getFormulaStringByCell(i.range.rows[f%i.range.rows.length],i.range.cols[m%i.range.cols.length],i.subUnitId,i.unitId),p=n.cols[m]-i.range.cols[m%i.range.cols.length],C=n.rows[f]-i.range.rows[f%i.range.rows.length],R=r.moveFormulaRefOffset(_||"",p,C);u.si=null,u.f=R}else u.si=S.si,u.f=null;u.v=null,u.p=null,c.setValue(h,g,u)}else if(l.isFormulaString(S.f)){const _=`${f%i.range.rows.length}_${m%i.range.cols.length}`;let p=d.get(_);if(p)u.si=p,u.f=null;else{p=l.Tools.generateRandomId(6),d.set(_,p);const C=n.cols[m]-i.range.cols[m%i.range.cols.length],R=n.rows[f]-i.range.rows[f%i.range.rows.length],I=r.moveFormulaRefOffset(S.f||"",C,R);u.si=p,u.f=I}u.v=null,u.p=null,c.setValue(h,g,u)}else{if(u.v=S.v,u.f=null,u.si=null,u.p=null,S.p){const _=Wt(S);_&&(u.v=_)}c.setValue(h,g,u)}}),c}function Er(e,t,n,s,r,o,i,c){const d=new l.ObjectMatrix,f=new Map,m=i.getSheetFormulaData(e,t),S=[];return r===A.COPY_TYPE.CUT?s.forValue((h,g,u)=>{const _=n.rows[h],p=n.cols[g],C={};if(l.isFormulaId(u.si)){if(l.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 R=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[g%c.range.cols.length],c.subUnitId,c.unitId);C.f=R,C.si=null}C.v=null,C.p=null,d.setValue(_,p,C)}else l.isFormulaString(u.f)&&(C.f=u.f,C.si=null,C.v=null,C.p=null,d.setValue(_,p,C))}):s.forValue((h,g,u)=>{var R;const _=n.rows[h],p=n.cols[g],C={};if(l.isFormulaId(u.si)){if(c.unitId!==e||c.subUnitId!==t){const I=i.getFormulaStringByCell(c.range.rows[h%c.range.rows.length],c.range.cols[g%c.range.cols.length],c.subUnitId,c.unitId),E=n.cols[g]-c.range.cols[g%c.range.cols.length],b=n.rows[h]-c.range.rows[h%c.range.rows.length],M=o.moveFormulaRefOffset(I||"",E,b);C.si=null,C.f=M}else C.si=u.si,C.f=null;C.v=null,C.p=null,d.setValue(_,p,C)}else if(l.isFormulaString(u.f)){const I=`${h%c.range.rows.length}_${g%c.range.cols.length}`;let E=f.get(I);if(E)C.si=E,C.f=null;else{E=l.Tools.generateRandomId(6),f.set(I,E);const b=n.cols[g]-c.range.cols[g%c.range.cols.length],M=n.rows[h]-c.range.rows[h%c.range.rows.length],F=o.moveFormulaRefOffset(u.f||"",b,M);C.si=E,C.f=F}C.v=null,C.p=null,d.setValue(_,p,C)}else(R=m==null?void 0:m[_])!=null&&R[p]&&(C.v=u.v,C.f=null,C.si=null,C.p=u.p,d.setValue(_,p,C))}),S.length>0&&new l.ObjectMatrix(m).forValue((h,g,u)=>{if(!(c.range.rows.includes(h)&&c.range.cols.includes(g))&&!(n.rows.includes(h)&&n.cols.includes(g))&&S.includes(u==null?void 0:u.si)){const _=i.getFormulaStringByCell(h,g,c.subUnitId,c.unitId);d.setValue(h,g,{f:_,si:null,v:null,p:null})}}),d}function Wt(e){if(e!=null&&e.p){const t=e==null?void 0:e.p.body;if(t==null)return;const n=t.dataStream;return n.substring(n.length-2,n.length)===l.DEFAULT_EMPTY_DOCUMENT_VALUE?n.substring(0,n.length-2):n}}var yr=Object.getOwnPropertyDescriptor,Ir=(e,t,n,s)=>{for(var r=s>1?void 0:s?yr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},ye=(e,t)=>(n,s)=>t(n,s,e);let He=class extends l.Disposable{constructor(t,n,s,r,o,i,c,d){super();q(this,"_previousShape");q(this,"_skeleton");this._context=t,this._sheetInterceptorService=n,this._formulaDataModel=s,this._themeService=r,this._renderManagerService=o,this._sheetSkeletonManagerService=i,this._commandService=c,this._logService=d,this._initSkeletonChangeListener(),this._initInterceptorEditorStart(),this._commandExecutedListener()}_initSkeletonChangeListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(t=>{var n,s;if(t==null)this._logService.debug("[FormulaEditorShowController]: should not receive currentSkeleton$ as null!");else{const{skeleton:r}=t,o=(s=(n=this._skeleton)==null?void 0:n.worksheet)==null?void 0:s.getSheetId();if(this._changeRuntime(r),o!==r.worksheet.getSheetId())this._removeArrayFormulaRangeShape();else{const{unitId:i,sheetId:c}=t;this._updateArrayFormulaRangeShape(i,c)}}}))}_changeRuntime(t){this._skeleton=t}_initInterceptorEditorStart(){this.disposeWithMe(l.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(k.BEFORE_CELL_EDIT,{handler:(t,n,s)=>{var u,_,p,C;const{row:r,col:o,unitId:i,subUnitId:c,worksheet:d}=n,f=this._formulaDataModel.getArrayFormulaRange(),m=this._formulaDataModel.getArrayFormulaCellData();if(this._removeArrayFormulaRangeShape(),t==null)return s(t);let S=null;const h=this._formulaDataModel.getFormulaStringByCell(r,o,c,i);if(h!==null&&(S={f:h}),t.v!=null&&t.v!==""&&((p=(_=(u=m[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=f==null?void 0:f[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=>{k.SetWorksheetRowAutoHeightMutation.id===t.id&&requestIdleCallback(()=>{const n=t.params,{unitId:s,subUnitId:r,rowsAutoHeightInfo:o}=n;this._refreshArrayFormulaRangeShapeByRow(s,r,o)})}))}_displayArrayFormulaRangeShape(t,n,s,r,o,i,c){const d=this._formulaDataModel.getSheetFormulaData(r,o);return new l.ObjectMatrix(t).forValue((f,m,S)=>{var p;if(S==null)return!0;const{startRow:h,startColumn:g,endRow:u,endColumn:_}=S;if(f===n&&m===s)return this._createArrayFormulaRangeShape(S,r),!1;if(n>=h&&n<=u&&s>=g&&s<=_){const C=i.getCell(h,g);if((C==null?void 0:C.v)===T.ErrorType.SPILL)return;const R=(p=d==null?void 0:d[f])==null?void 0:p[m];return R==null||R.f==null?!0:(c==null&&(c={f:R.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={range:t,primary:null,style:{strokeWidth:1,stroke:this._themeService.getColorFromTheme("primary.600"),fill:new l.ColorKit(this._themeService.getColorFromTheme("white")).setAlpha(0).toString(),widgets:{}}},c=A.attachSelectionWithCoord(i,r),{rowHeaderWidth:d,columnHeaderHeight:f}=r,m=new A.SelectionControl(o,A.SELECTION_SHAPE_DEPTH.FORMULA_EDITOR_SHOW,this._themeService,{highlightHeader:!1,rowHeaderWidth:d,columnHeaderHeight:f});m.updateRangeBySelectionWithCoord(c),m.setEvent(!1),this._previousShape=m}_removeArrayFormulaRangeShape(){this._previousShape!=null&&(this._previousShape.dispose(),this._previousShape=null)}_refreshArrayFormulaRangeShape(t,n){if(this._previousShape){const{startRow:s,endRow:r,startColumn:o,endColumn:i}=this._previousShape.getRange(),c={startRow:s,endRow:r,startColumn:o,endColumn:i};this._removeArrayFormulaRangeShape(),this._createArrayFormulaRangeShape(c,t)}}_checkCurrentSheet(t,n){const s=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!s)return!1;const r=s.worksheet;return r?r.unitId===t&&r.getSheetId()===n:!1}_updateArrayFormulaRangeShape(t,n){this._checkCurrentSheet(t,n)&&this._previousShape&&this._refreshArrayFormulaRangeShape(t)}_refreshArrayFormulaRangeShapeByRow(t,n,s){if(!this._checkCurrentSheet(t,n)||!this._previousShape)return;const{startRow:r,endRow:o,startColumn:i,endColumn:c}=this._previousShape.getRange();for(let d=0;d<s.length;d++){const{row:f}=s[d];if(r>=f){const m={startRow:r,endRow:o,startColumn:i,endColumn:c};this._refreshArrayFormulaRangeShape(t,m);break}}}};He=Ir([ye(1,l.Inject(k.SheetInterceptorService)),ye(2,l.Inject(T.FormulaDataModel)),ye(3,l.Inject(l.ThemeService)),ye(4,H.IRenderManagerService),ye(5,l.Inject(A.SheetSkeletonManagerService)),ye(6,l.ICommandService),ye(7,l.ILogService)],He);var br=Object.getOwnPropertyDescriptor,Tr=(e,t,n,s)=>{for(var r=s>1?void 0:s?br(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},_t=(e,t)=>(n,s)=>t(n,s,e);const xr={tl:{size:6,color:"#409f11"}};let Ke=class extends l.RxDisposable{constructor(e,t){super(),this._sheetInterceptorService=e,this._formulaDataModel=t,this.disposeWithMe(this._sheetInterceptorService.intercept(k.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,handler:(n,s,r)=>{var c,d,f,m;const o=(m=(f=(d=(c=this._formulaDataModel.getArrayFormulaCellData())==null?void 0:c[s.unitId])==null?void 0:d[s.subUnitId])==null?void 0:f[s.row])==null?void 0:m[s.col];return jt(n,!!o)?r({...n,markers:{...n==null?void 0:n.markers,...xr}}):r(n)},priority:10}))}};Ke=Tr([_t(0,l.Inject(k.SheetInterceptorService)),_t(1,l.Inject(T.FormulaDataModel))],Ke);function Mr(){const e=a.useDependency(ve.TriggerCalculationController),t=a.useDependency(l.ICommandService),n=a.useObservable(e.progress$),s=v.useCallback(()=>{t.executeCommand(T.SetFormulaCalculationStopMutation.id)},[t]),r=v.useCallback(()=>{e.clearProgress()},[e]);return y.jsx(a.ProgressBar,{progress:n,onTerminate:s,onClearProgress:r})}function Vt(e){const{prefix:t,value:n}=e;return y.jsxs("div",{children:[y.jsxs("span",{children:[t,"("]}),n&&n.map((s,r)=>y.jsxs("span",{children:[y.jsx("span",{children:Ft(s)}),r===n.length-1?"":","]},r)),")"]})}function ke(e){const{className:t,value:n,title:s}=e;return y.jsxs("div",{className:"univer-mb-2 univer-text-xs",children:[y.jsx("div",{className:`
|
|
9
9
|
univer-mb-2 univer-font-medium univer-text-gray-500
|
|
10
10
|
${t}
|
|
11
|
-
`,children:s}),y.jsx("div",{className:"univer-text-gray-900 dark:univer-text-white",children:n})]})}function Or(e){const{functionInfo:t,onChange:n}=e;if(!t)return null;const[s,r]=p.useState([]),[o,i]=p.useState(t.functionParameter),[c,d]=p.useState(-1);return y.jsxs("div",{children:[y.jsx("div",{className:"univer-h-[364px] univer-overflow-y-auto",children:o.map((f,m)=>y.jsxs("div",{children:[y.jsx("div",{className:"univer-text-sm",children:f.name}),y.jsx("div",{className:"univer-mb-2 univer-mt-1"})]},m))}),y.jsx("div",{className:W.clsx("univer-flex-1 univer-p-3",W.borderLeftClassName),children:y.jsx(we,{title:c===-1?y.jsx(Wt,{prefix:t.functionName,value:o}):o[c].name,value:c===-1?t.description:o[c].detail})})]})}function Nr(e){const{onChange:t}=e,n="-1",[s,r]=p.useState(""),[o,i]=p.useState([]),[c,d]=p.useState(0),[f,m]=p.useState(n),[S,h]=p.useState(0),[g,u]=p.useState(null),_=l.useDependency(ye.IDescriptionService),v=l.useDependency(a.LocaleService),C=l.useDependency(l.ISidebarService),R=l.useObservable(C.sidebarOptions$),I=_n(T.FunctionType,v);I.unshift({label:v.t("formula.moreFunctions.allFunctions"),value:n});const E=v.t("formula.prompt.required"),b=v.t("formula.prompt.optional");p.useEffect(()=>{L(n)},[]),p.useEffect(()=>{F(0)},[o]),p.useEffect(()=>{R!=null&&R.visible&&(r(""),i([]),d(0),m(n),h(0),u(null),L(n))},[R]);const M=O=>{if(s.trim()==="")return O;const x=new RegExp(`(${s.toLocaleUpperCase()})`);return O.split(x).filter(Boolean).map((k,U)=>k.match(x)?y.jsx("span",{className:"univer-text-red-500",children:k},U):k)},F=O=>{if(o.length===0){u(null);return}h(O);const x=_.getFunctionInfo(o[O].name);if(!x){u(null);return}u(x),t(x)};function L(O){m(O);const x=_.getSearchListByType(+O);i(x)}function P(O){r(O);const x=_.getSearchListByName(O);i(x)}function A(O){if(O.stopPropagation(),O.key==="ArrowDown"){const x=c+1;d(x===o.length?0:x)}else if(O.key==="ArrowUp"){const x=c-1;d(x===-1?o.length-1:x)}else O.key==="Enter"&&F(c)}const j=O=>{d(O)},D=()=>{d(-1)};return y.jsxs("div",{children:[y.jsxs("div",{className:"univer-flex univer-items-center univer-justify-between univer-gap-[10%]",children:[y.jsx(W.Select,{value:f,options:I,onChange:L}),y.jsx(W.Input,{placeholder:v.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:A,value:s,onChange:P,size:"small",allowClear:!0})]}),y.jsx("ul",{className:W.clsx("univer-mx-0 univer-mb-0 univer-mt-2 univer-box-border univer-max-h-[364px] univer-w-full univer-select-none univer-list-none univer-overflow-y-auto univer-rounded univer-p-3 univer-outline-none",W.borderClassName),onKeyDown:A,tabIndex:-1,children:o.map(({name:O},x)=>y.jsxs("li",{className:W.clsx("univer-relative univer-box-border univer-cursor-pointer univer-rounded univer-px-7 univer-py-1 univer-text-sm univer-text-gray-900 univer-transition-colors dark:univer-text-white",{"univer-bg-gray-200":c===x}),onMouseEnter:()=>j(x),onMouseLeave:D,onClick:()=>F(x),children:[S===x&&y.jsx(Ot,{className:"univer-absolute univer-left-1.5 univer-top-1/2 univer-inline-flex -univer-translate-y-1/2 univer-text-base univer-text-primary-600"}),y.jsx("span",{className:"univer-block",children:M(O)})]},x))}),g&&y.jsxs("div",{className:"univer-mx-0 univer-my-2 univer-max-h-[307px] univer-overflow-y-auto",children:[y.jsx(we,{title:g.functionName,value:g.description}),y.jsx(we,{title:v.t("formula.moreFunctions.syntax"),value:y.jsx(Wt,{prefix:g.functionName,value:g.functionParameter})}),y.jsx(we,{title:v.t("formula.prompt.helpExample"),value:`${g.functionName}(${g.functionParameter.map(O=>O.example).join(",")})`}),g.functionParameter&&g.functionParameter.map(O=>y.jsx(we,{title:O.name,value:`${O.require?E:b} ${O.detail}`},O.name))]})]})}function Dr(){const e=w.useActiveWorkbook(),[t,n]=p.useState(!0),[s,r]=p.useState(!1),[o,i]=p.useState(null);l.useDependency(w.IEditorBridgeService);const c=l.useDependency(a.LocaleService),d=l.useDependency(J.IEditorService),f=l.useDependency(a.IUniverInstanceService),m=l.useDependency(a.ICommandService);function S(){n(!t),r(!s)}function h(){const g=$.getSheetCommandTarget(f);if(!g)return;m.executeCommand(w.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),v=`=${o==null?void 0:o.functionName}(`;u==null||u.replaceText(v),_==null||_.replaceText(v,!1)}return y.jsxs("div",{className:"univer-flex univer-h-full univer-flex-col univer-justify-between univer-leading-5",children:[t&&y.jsx(Nr,{onChange:i}),s&&y.jsx(Or,{functionInfo:o,onChange:()=>{}}),y.jsxs("div",{className:"univer-flex univer-justify-end",children:[s&&y.jsx(W.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&&y.jsx(W.Button,{onClick:S,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.prev")}),t&&!!e&&y.jsx(W.Button,{variant:"primary",onClick:h,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.confirm")})]})]})}function Ar(e){return{id:Ye.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$:w.getCurrentRangeDisable$(e,{workbookTypes:[$.WorkbookEditablePermission],worksheetTypes:[$.WorksheetEditPermission,$.WorksheetSetCellValuePermission],rangeTypes:[$.RangeProtectionPermissionEditPoint]})}}function wr(e){return{id:ze.id,title:"formula.insert.more",type:l.MenuItemType.BUTTON}}function Fr(e){return e.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(K.switchMap(s=>s&&e.get(l.IClipboardInterfaceService)?new K.Observable(o=>o.next(!e.get(l.IClipboardInterfaceService).supportClipboard)):K.of(!0)))}function kr(e){return{id:qe.id,type:l.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:Fr(e).pipe(K.combineLatestWith(w.getCurrentRangeDisable$(e,{workbookTypes:[$.WorkbookEditablePermission],rangeTypes:[$.RangeProtectionPermissionEditPoint],worksheetTypes:[$.WorksheetSetCellValuePermission,$.WorksheetEditPermission]})),K.map(([t,n])=>t||n))}}const Lr={[l.RibbonStartGroup.FORMULAS_INSERT]:{[Ye.id]:{order:1,menuItemFactory:Ar,[ze.id]:{order:1,menuItemFactory:wr}}},[w.PASTE_SPECIAL_MENU_ID]:{[qe.id]:{order:4,menuItemFactory:kr}}},Pr="meta_key_ctrl_And_Shift",Ge=[l.KeyCode.ARROW_DOWN,l.KeyCode.ARROW_UP,l.KeyCode.ARROW_LEFT,l.KeyCode.ARROW_RIGHT],jr=[...Ge,l.KeyCode.ENTER,l.KeyCode.TAB,l.KeyCode.ESC];function Ur(){const e=[];for(const t of jr)e.push({id:Ie.id,binding:t,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t}});return e}function $r(){const e=[];for(const t of Ge)e.push({id:Ie.id,binding:t|l.MetaKeys.SHIFT,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,metaKey:l.MetaKeys.SHIFT}});return e}function Vr(){const e=[];for(const t of Ge)e.push({id:Ie.id,binding:t|l.MetaKeys.CTRL_COMMAND,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,metaKey:l.MetaKeys.CTRL_COMMAND}});return e}function Wr(){const e=[];for(const t of Ge)e.push({id:Ie.id,binding:t|l.MetaKeys.SHIFT|l.MetaKeys.CTRL_COMMAND,preconditions:n=>w.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,metaKey:Pr}});return e}const Br={id:st.id,binding:l.KeyCode.F4,preconditions:e=>w.whenFormulaEditorActivated(e)};function Hr(){const e=[];for(const t of[l.KeyCode.ENTER,l.KeyCode.TAB,l.KeyCode.ARROW_DOWN,l.KeyCode.ARROW_UP])e.push({id:Ie.id,binding:t,preconditions:n=>ir(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}var Kr=Object.getOwnPropertyDescriptor,qr=(e,t,n,s)=>{for(var r=s>1?void 0:s?Kr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Ee=(e,t)=>(n,s)=>t(n,s,e);let Ke=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(Lr)}_registerCommands(){[qe,Ye,ze,Tt,yt,Ie,st].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...Ur(),...$r(),...Vr(),...Wr(),...Hr(),Br].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(w.SheetsUIPart.FORMULA_AUX,()=>l.connectInjector(Mr,this._injector))),this._componentManager.register(bt,Dr)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,[Be]))}};Ke=qr([Ee(0,a.Inject(a.Injector)),Ee(1,l.IMenuManagerService),Ee(2,a.ICommandService),Ee(3,l.IShortcutService),Ee(4,l.IUIPartsService),Ee(5,H.IRenderManagerService),Ee(6,a.Inject(l.ComponentManager))],Ke);const Yr=()=>{var s,r;const e=l.useDependency(ct),t=l.useObservable(e.currentSelector$),n=p.useRef(null);return p.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]),y.jsx(it,{unitId:(s=t==null?void 0:t.unitId)!=null?s:"",subUnitId:(r=t==null?void 0:t.subUnitId)!=null?r:"",hideEditor:!0,selectorRef:n,onChange:(o,i)=>{var c;t==null||t.callback((c=i==null?void 0:i.split(",").map(d=>T.deserializeRangeWithSheet(d)))!=null?c:[])}})};var zr=Object.defineProperty,Gr=Object.getOwnPropertyDescriptor,Zr=(e,t,n)=>t in e?zr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Xr=(e,t,n,s)=>{for(var r=s>1?void 0:s?Gr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},$e=(e,t)=>(n,s)=>t(n,s,e),Bt=(e,t,n)=>Zr(e,typeof t!="symbol"?t+"":t,n);exports.UniverSheetsFormulaUIPlugin=class extends a.Plugin{constructor(t=pt,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(pt,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(or,c,{merge:!0})}onStarting(){a.registerDependencies(this._injector,[[rt,{useClass:et}],[ct],[Ke],[Ve],[We],[Be],[He],[exports.FormulaReorderController]]),this._initUIPart()}onReady(){[[exports.RefSelectionsRenderService]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,t))})}onRendered(){[[nt]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,t))}),a.touchDependencies(this._injector,[[Ke],[We],[He]])}onSteady(){this._injector.get(Ve),this._injector.get(exports.FormulaReorderController)}_initUIPart(){const t=this._injector.get(l.ComponentManager);this.disposeWithMe(t.register(w.RANGE_SELECTOR_COMPONENT_KEY,it)),this.disposeWithMe(t.register(w.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,Ut)),this.disposeWithMe(this._uiPartsService.registerComponent(l.BuiltInUIPart.GLOBAL,()=>l.connectInjector(Yr,this._injector)))}};Bt(exports.UniverSheetsFormulaUIPlugin,"pluginName",It);Bt(exports.UniverSheetsFormulaUIPlugin,"type",a.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFormulaUIPlugin=Xr([a.DependentOn(T.UniverFormulaEnginePlugin,ye.UniverSheetsFormulaPlugin),$e(1,a.Inject(a.Injector)),$e(2,H.IRenderManagerService),$e(3,a.IConfigService),$e(4,l.IUIPartsService)],exports.UniverSheetsFormulaUIPlugin);exports.FORMULA_PROMPT_ACTIVATED=Et;exports.FormulaEditor=Ut;exports.GlobalRangeSelectorService=ct;exports.HelpFunctionOperation=yt;exports.InsertFunctionOperation=Ye;exports.MoreFunctionsOperation=ze;exports.RangeSelector=it;exports.ReferenceAbsoluteOperation=st;exports.SearchFunctionOperation=Tt;exports.SelectEditorFormulaOperation=Ie;exports.SheetOnlyPasteFormulaCommand=qe;
|
|
11
|
+
`,children:s}),y.jsx("div",{className:"univer-text-gray-900 dark:!univer-text-white",children:n})]})}function Or(e){const{functionInfo:t,onChange:n}=e;if(!t)return null;const[s,r]=v.useState([]),[o,i]=v.useState(t.functionParameter),[c,d]=v.useState(-1);return y.jsxs("div",{children:[y.jsx("div",{className:"univer-h-[364px] univer-overflow-y-auto",children:o.map((f,m)=>y.jsxs("div",{children:[y.jsx("div",{className:"univer-text-sm",children:f.name}),y.jsx("div",{className:"univer-mb-2 univer-mt-1"})]},m))}),y.jsx("div",{className:V.clsx("univer-flex-1 univer-p-3",V.borderLeftClassName),children:y.jsx(ke,{title:c===-1?y.jsx(Vt,{prefix:t.functionName,value:o}):o[c].name,value:c===-1?t.description:o[c].detail})})]})}function Nr(e){const{onChange:t}=e,n="-1",[s,r]=v.useState(""),[o,i]=v.useState([]),[c,d]=v.useState(0),[f,m]=v.useState(n),[S,h]=v.useState(0),[g,u]=v.useState(null),_=a.useDependency(ve.IDescriptionService),p=a.useDependency(l.LocaleService),C=a.useDependency(a.ISidebarService),R=a.useObservable(C.sidebarOptions$),I=_n(T.FunctionType,p);I.unshift({label:p.t("formula.moreFunctions.allFunctions"),value:n});const E=p.t("formula.prompt.required"),b=p.t("formula.prompt.optional");v.useEffect(()=>{L(n)},[]),v.useEffect(()=>{F(0)},[o]),v.useEffect(()=>{R!=null&&R.visible&&(r(""),i([]),d(0),m(n),h(0),u(null),L(n))},[R]);const M=O=>{if(s.trim()==="")return O;const x=new RegExp(`(${s.toLocaleUpperCase()})`);return O.split(x).filter(Boolean).map((P,j)=>P.match(x)?y.jsx("span",{className:"univer-text-red-500",children:P},j):P)},F=O=>{if(o.length===0){u(null);return}h(O);const x=_.getFunctionInfo(o[O].name);if(!x){u(null);return}u(x),t(x)};function L(O){m(O);const x=_.getSearchListByType(+O);i(x)}function U(O){r(O);const x=_.getSearchListByName(O);i(x)}function w(O){if(O.stopPropagation(),O.key==="ArrowDown"){const x=c+1;d(x===o.length?0:x)}else if(O.key==="ArrowUp"){const x=c-1;d(x===-1?o.length-1:x)}else O.key==="Enter"&&F(c)}const $=O=>{d(O)},D=()=>{d(-1)};return y.jsxs("div",{children:[y.jsxs("div",{className:"univer-flex univer-items-center univer-justify-between univer-gap-[10%]",children:[y.jsx(V.Select,{value:f,options:I,onChange:L}),y.jsx(V.Input,{placeholder:p.t("formula.moreFunctions.searchFunctionPlaceholder"),onKeyDown:w,value:s,onChange:U,size:"small",allowClear:!0})]}),y.jsx("ul",{className:V.clsx("univer-mx-0 univer-mb-0 univer-mt-2 univer-box-border univer-max-h-[364px] univer-w-full univer-select-none univer-list-none univer-overflow-y-auto univer-rounded univer-p-3 univer-outline-none",V.borderClassName),onKeyDown:w,tabIndex:-1,children:o.map(({name:O},x)=>y.jsxs("li",{className:V.clsx("univer-relative univer-box-border univer-cursor-pointer univer-rounded univer-px-7 univer-py-1 univer-text-sm univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200":c===x}),onMouseEnter:()=>$(x),onMouseLeave:D,onClick:()=>F(x),children:[S===x&&y.jsx(Ot,{className:"univer-absolute univer-left-1.5 univer-top-1/2 univer-inline-flex -univer-translate-y-1/2 univer-text-base univer-text-primary-600"}),y.jsx("span",{className:"univer-block",children:M(O)})]},x))}),g&&y.jsxs("div",{className:"univer-mx-0 univer-my-2 univer-max-h-[307px] univer-overflow-y-auto",children:[y.jsx(ke,{title:g.functionName,value:g.description}),y.jsx(ke,{title:p.t("formula.moreFunctions.syntax"),value:y.jsx(Vt,{prefix:g.functionName,value:g.functionParameter})}),y.jsx(ke,{title:p.t("formula.prompt.helpExample"),value:`${g.functionName}(${g.functionParameter.map(O=>O.example).join(",")})`}),g.functionParameter&&g.functionParameter.map(O=>y.jsx(ke,{title:O.name,value:`${O.require?E:b} ${O.detail}`},O.name))]})]})}function Dr(){const e=A.useActiveWorkbook(),[t,n]=v.useState(!0),[s,r]=v.useState(!1),[o,i]=v.useState(null);a.useDependency(A.IEditorBridgeService);const c=a.useDependency(l.LocaleService),d=a.useDependency(Q.IEditorService),f=a.useDependency(l.IUniverInstanceService),m=a.useDependency(l.ICommandService);function S(){n(!t),r(!s)}function h(){const g=k.getSheetCommandTarget(f);if(!g)return;m.executeCommand(A.SetCellEditVisibleOperation.id,{visible:!0,unitId:g.unitId,eventType:H.DeviceInputEventType.Dblclick});const u=d.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),_=d.getEditor(l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY),p=`=${o==null?void 0:o.functionName}(`;u==null||u.replaceText(p),_==null||_.replaceText(p,!1)}return y.jsxs("div",{className:"univer-flex univer-h-full univer-flex-col univer-justify-between univer-leading-5",children:[t&&y.jsx(Nr,{onChange:i}),s&&y.jsx(Or,{functionInfo:o,onChange:()=>{}}),y.jsxs("div",{className:"univer-flex univer-justify-end",children:[s&&y.jsx(V.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&&y.jsx(V.Button,{onClick:S,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.prev")}),t&&!!e&&y.jsx(V.Button,{variant:"primary",onClick:h,className:"univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0",children:c.t("formula.moreFunctions.confirm")})]})]})}function Ar(e){return{id:oe.id,title:"SUM",icon:"SumSingle",type:a.MenuItemType.BUTTON,params:{value:"SUM"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:A.getCurrentRangeDisable$(e,{workbookTypes:[k.WorkbookEditablePermission],worksheetTypes:[k.WorksheetEditPermission,k.WorksheetSetCellValuePermission],rangeTypes:[k.RangeProtectionPermissionEditPoint]})}}function wr(e){return{id:oe.id,title:"COUNT",icon:"CntSingle",type:a.MenuItemType.BUTTON,params:{value:"COUNT"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:A.getCurrentRangeDisable$(e,{workbookTypes:[k.WorkbookEditablePermission],worksheetTypes:[k.WorksheetEditPermission,k.WorksheetSetCellValuePermission],rangeTypes:[k.RangeProtectionPermissionEditPoint]})}}function kr(e){return{id:oe.id,title:"AVERAGE",icon:"AvgSingle",type:a.MenuItemType.BUTTON,params:{value:"AVERAGE"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:A.getCurrentRangeDisable$(e,{workbookTypes:[k.WorkbookEditablePermission],worksheetTypes:[k.WorksheetEditPermission,k.WorksheetSetCellValuePermission],rangeTypes:[k.RangeProtectionPermissionEditPoint]})}}function Fr(e){return{id:oe.id,title:"MAX",icon:"MaxSingle",type:a.MenuItemType.BUTTON,params:{value:"MAX"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:A.getCurrentRangeDisable$(e,{workbookTypes:[k.WorkbookEditablePermission],worksheetTypes:[k.WorksheetEditPermission,k.WorksheetSetCellValuePermission],rangeTypes:[k.RangeProtectionPermissionEditPoint]})}}function Pr(e){return{id:oe.id,title:"MIN",icon:"MinSingle",type:a.MenuItemType.BUTTON,params:{value:"MIN"},hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:A.getCurrentRangeDisable$(e,{workbookTypes:[k.WorkbookEditablePermission],worksheetTypes:[k.WorksheetEditPermission,k.WorksheetSetCellValuePermission],rangeTypes:[k.RangeProtectionPermissionEditPoint]})}}function Lr(e){return{id:rt.id,title:"formula.insert.more",type:a.MenuItemType.BUTTON,hidden$:a.getMenuHiddenObservable(e,l.UniverInstanceType.UNIVER_SHEET),disabled$:A.getCurrentRangeDisable$(e,{workbookTypes:[k.WorkbookEditablePermission],worksheetTypes:[k.WorksheetEditPermission,k.WorksheetSetCellValuePermission],rangeTypes:[k.RangeProtectionPermissionEditPoint]})}}function Ur(e){return e.get(l.IUniverInstanceService).getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(K.switchMap(s=>s&&e.get(a.IClipboardInterfaceService)?new K.Observable(o=>o.next(!e.get(a.IClipboardInterfaceService).supportClipboard)):K.of(!0)))}function $r(e){return{id:Ye.id,type:a.MenuItemType.BUTTON,title:"formula.operation.pasteFormula",disabled$:Ur(e).pipe(K.combineLatestWith(A.getCurrentRangeDisable$(e,{workbookTypes:[k.WorkbookEditablePermission],rangeTypes:[k.RangeProtectionPermissionEditPoint],worksheetTypes:[k.WorksheetSetCellValuePermission,k.WorksheetEditPermission]})),K.map(([t,n])=>t||n))}}const jr={[a.RibbonFormulasGroup.BASIC]:{[`${oe.id}.sum`]:{order:0,menuItemFactory:Ar},[`${oe.id}.count`]:{order:0,menuItemFactory:wr},[`${oe.id}.average`]:{order:0,menuItemFactory:kr},[`${oe.id}.max`]:{order:0,menuItemFactory:Fr},[`${oe.id}.min`]:{order:0,menuItemFactory:Pr}},[a.RibbonFormulasGroup.OTHERS]:{order:0,menuItemFactory:Lr},[A.PASTE_SPECIAL_MENU_ID]:{[Ye.id]:{order:4,menuItemFactory:$r}}},Wr="meta_key_ctrl_And_Shift",ze=[a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP,a.KeyCode.ARROW_LEFT,a.KeyCode.ARROW_RIGHT],Vr=[...ze,a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ESC];function Br(){const e=[];for(const t of Vr)e.push({id:be.id,binding:t,preconditions:n=>A.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t}});return e}function Hr(){const e=[];for(const t of ze)e.push({id:be.id,binding:t|a.MetaKeys.SHIFT,preconditions:n=>A.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.SHIFT}});return e}function Kr(){const e=[];for(const t of ze)e.push({id:be.id,binding:t|a.MetaKeys.CTRL_COMMAND,preconditions:n=>A.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,metaKey:a.MetaKeys.CTRL_COMMAND}});return e}function qr(){const e=[];for(const t of ze)e.push({id:be.id,binding:t|a.MetaKeys.SHIFT|a.MetaKeys.CTRL_COMMAND,preconditions:n=>A.whenFormulaEditorActivated(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,metaKey:Wr}});return e}const Yr={id:st.id,binding:a.KeyCode.F4,preconditions:e=>A.whenFormulaEditorActivated(e)};function zr(){const e=[];for(const t of[a.KeyCode.ENTER,a.KeyCode.TAB,a.KeyCode.ARROW_DOWN,a.KeyCode.ARROW_UP])e.push({id:be.id,binding:t,preconditions:n=>ir(n),staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keycode:t,isSingleEditor:!0}});return e}const Gr={id:ve.QuickSumCommand.id,binding:a.MetaKeys.ALT|a.KeyCode.EQUAL,preconditions:A.whenSheetEditorFocused,mac:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.ALT|a.KeyCode.EQUAL,description:"shortcut.sheets-formula-ui.quick-sum",group:"4_sheet-edit"};var Zr=Object.getOwnPropertyDescriptor,Xr=(e,t,n,s)=>{for(var r=s>1?void 0:s?Zr(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},Ie=(e,t)=>(n,s)=>t(n,s,e);let qe=class extends l.Disposable{constructor(e,t,n,s,r,o,i){super(),this._injector=e,this._menuManagerService=t,this._commandService=n,this._shortcutService=s,this._uiPartsService=r,this._renderManagerService=o,this._componentManager=i,this._initialize()}_initialize(){this._registerCommands(),this._registerMenus(),this._registerShortcuts(),this._registerComponents(),this._registerRenderModules()}_registerMenus(){this._menuManagerService.mergeMenu(jr)}_registerCommands(){[Ye,oe,rt,Tt,yt,be,st].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerShortcuts(){[...Br(),...Hr(),...Kr(),...qr(),...zr(),Gr,Yr].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_registerComponents(){this.disposeWithMe(this._uiPartsService.registerComponent(A.SheetsUIPart.FORMULA_AUX,()=>a.connectInjector(Mr,this._injector))),this._componentManager.register(bt,Dr)}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,[He]))}};qe=Xr([Ie(0,l.Inject(l.Injector)),Ie(1,a.IMenuManagerService),Ie(2,l.ICommandService),Ie(3,a.IShortcutService),Ie(4,a.IUIPartsService),Ie(5,H.IRenderManagerService),Ie(6,l.Inject(a.ComponentManager))],qe);const Qr=()=>{var s,r;const e=a.useDependency(ct),t=a.useObservable(e.currentSelector$),n=v.useRef(null);return v.useEffect(()=>{var o,i;if(t)return(i=n.current)==null||i.showDialog((o=t.initialValue)!=null?o:[]),()=>{var c;(c=n.current)==null||c.hideDialog()}},[t]),y.jsx(it,{unitId:(s=t==null?void 0:t.unitId)!=null?s:"",subUnitId:(r=t==null?void 0:t.subUnitId)!=null?r:"",hideEditor:!0,selectorRef:n,onChange:(o,i)=>{var c;t==null||t.callback((c=i==null?void 0:i.split(",").map(d=>T.deserializeRangeWithSheet(d)))!=null?c:[])}})};var Jr=Object.defineProperty,es=Object.getOwnPropertyDescriptor,ts=(e,t,n)=>t in e?Jr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ns=(e,t,n,s)=>{for(var r=s>1?void 0:s?es(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(r=i(r)||r);return r},We=(e,t)=>(n,s)=>t(n,s,e),Bt=(e,t,n)=>ts(e,typeof t!="symbol"?t+"":t,n);exports.UniverSheetsFormulaUIPlugin=class extends l.Plugin{constructor(t=vt,n,s,r,o){super(),this._config=t,this._injector=n,this._renderManagerService=s,this._configService=r,this._uiPartsService=o;const{menu:i,...c}=l.merge(vt,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(or,c,{merge:!0})}onStarting(){l.registerDependencies(this._injector,[[nt,{useClass:Je}],[ct],[qe],[Ve],[Be],[He],[Ke],[exports.FormulaReorderController]]),this._initUIPart()}onReady(){[[exports.RefSelectionsRenderService]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))})}onRendered(){[[tt]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))}),l.touchDependencies(this._injector,[[qe],[Be],[Ke]])}onSteady(){this._injector.get(Ve),this._injector.get(exports.FormulaReorderController)}_initUIPart(){const t=this._injector.get(a.ComponentManager);this.disposeWithMe(t.register(A.RANGE_SELECTOR_COMPONENT_KEY,it)),this.disposeWithMe(t.register(A.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,$t)),this.disposeWithMe(this._uiPartsService.registerComponent(a.BuiltInUIPart.GLOBAL,()=>a.connectInjector(Qr,this._injector)))}};Bt(exports.UniverSheetsFormulaUIPlugin,"pluginName",It);Bt(exports.UniverSheetsFormulaUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFormulaUIPlugin=ns([l.DependentOn(T.UniverFormulaEnginePlugin,ve.UniverSheetsFormulaPlugin),We(1,l.Inject(l.Injector)),We(2,H.IRenderManagerService),We(3,l.IConfigService),We(4,a.IUIPartsService)],exports.UniverSheetsFormulaUIPlugin);exports.FORMULA_PROMPT_ACTIVATED=Et;exports.FormulaEditor=$t;exports.GlobalRangeSelectorService=ct;exports.HelpFunctionOperation=yt;exports.InsertFunctionOperation=oe;exports.MoreFunctionsOperation=rt;exports.RangeSelector=it;exports.ReferenceAbsoluteOperation=st;exports.SearchFunctionOperation=Tt;exports.SelectEditorFormulaOperation=be;exports.SheetOnlyPasteFormulaCommand=Ye;
|
package/lib/cjs/locale/en-US.js
CHANGED
|
@@ -43,4 +43,4 @@ COUNTIF uses only a single criteria. Use COUNTIFS if you want to use multiple cr
|
|
|
43
43
|
2. Chinese uppercase
|
|
44
44
|
3. Reading and Writing Chinese Characters`}}},NUMBERVALUE:{description:"Converts text to number in a locale-independent manner",abstract:"Converts text to number in a locale-independent manner",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/numbervalue-function-1b05c8cf-2bfa-4437-af70-596c7ea7d879"}],functionParameter:{text:{name:"text",detail:"The text to convert to a number."},decimalSeparator:{name:"decimal_separator",detail:"The character used to separate the integer and fractional part of the result."},groupSeparator:{name:"group_separator",detail:"The character used to separate groupings of numbers."}}},PHONETIC:{description:"Extracts the phonetic (furigana) characters from a text string",abstract:"Extracts the phonetic (furigana) characters from a text string",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/phonetic-function-9a329dac-0c0f-42f8-9a55-639086988554"}],functionParameter:{number1:{name:"number1",detail:"first"},number2:{name:"number2",detail:"second"}}},PROPER:{description:"Capitalizes the first letter in each word of a text value",abstract:"Capitalizes the first letter in each word of a text value",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/proper-function-52a5a283-e8b2-49be-8506-b2887b889f94"}],functionParameter:{text:{name:"text",detail:"Text enclosed in quotation marks, a formula that returns text, or a reference to a cell containing the text you want to partially capitalize."}}},REGEXEXTRACT:{description:"Extracts the first matching substrings according to a regular expression.",abstract:"Extracts the first matching substrings according to a regular expression.",links:[{title:"Instruction",url:"https://support.google.com/docs/answer/3098244?sjid=5628197291201472796-AP&hl=en"}],functionParameter:{text:{name:"text",detail:"The input text."},regularExpression:{name:"regular_expression",detail:"The first part of text that matches this expression will be returned."}}},REGEXMATCH:{description:"Whether a piece of text matches a regular expression.",abstract:"Whether a piece of text matches a regular expression.",links:[{title:"Instruction",url:"https://support.google.com/docs/answer/3098292?sjid=5628197291201472796-AP&hl=en"}],functionParameter:{text:{name:"text",detail:"The text to be tested against the regular expression."},regularExpression:{name:"regular_expression",detail:"The regular expression to test the text against."}}},REGEXREPLACE:{description:"Replaces part of a text string with a different text string using regular expressions.",abstract:"Replaces part of a text string with a different text string using regular expressions.",links:[{title:"Instruction",url:"https://support.google.com/docs/answer/3098245?sjid=5628197291201472796-AP&hl=en"}],functionParameter:{text:{name:"text",detail:"The text, a part of which will be replaced."},regularExpression:{name:"regular_expression",detail:"The regular expression. All matching instances in text will be replaced."},replacement:{name:"replacement",detail:"The text which will be inserted into the original text."}}},REPLACE:{description:"Replaces characters within text",abstract:"Replaces characters within text",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/replace-replaceb-functions-8d799074-2425-4a8a-84bc-82472868878a"}],functionParameter:{oldText:{name:"old_text",detail:"Text in which you want to replace some characters."},startNum:{name:"start_num",detail:"The position of the character in old_text that you want to replace with new_text."},numChars:{name:"num_chars",detail:"The number of characters in old_text that you want REPLACE to replace with new_text."},newText:{name:"new_text",detail:"The text that will replace characters in old_text."}}},REPLACEB:{description:"Replaces characters within text",abstract:"Replaces characters within text",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/replace-replaceb-functions-8d799074-2425-4a8a-84bc-82472868878a"}],functionParameter:{oldText:{name:"old_text",detail:"Text in which you want to replace some characters."},startNum:{name:"start_num",detail:"The position of the character in old_text that you want to replace with new_text."},numBytes:{name:"num_bytes",detail:"The number of bytes in old_text that you want REPLACEB to replace with new_text."},newText:{name:"new_text",detail:"The text that will replace characters in old_text."}}},REPT:{description:"Repeats text a given number of times",abstract:"Repeats text a given number of times",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/rept-function-04c4d778-e712-43b4-9c15-d656582bb061"}],functionParameter:{text:{name:"text",detail:"The text you want to repeat."},numberTimes:{name:"number_times",detail:"A positive number specifying the number of times to repeat text."}}},RIGHT:{description:"Returns the rightmost characters from a text value",abstract:"Returns the rightmost characters from a text value",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/right-rightb-functions-240267ee-9afa-4639-a02b-f19e1786cf2f"}],functionParameter:{text:{name:"text",detail:"The text string containing the characters you want to extract."},numChars:{name:"num_chars",detail:"Specifies the number of characters you want RIGHT to extract."}}},RIGHTB:{description:"Returns the rightmost characters from a text value",abstract:"Returns the rightmost characters from a text value",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/right-rightb-functions-240267ee-9afa-4639-a02b-f19e1786cf2f"}],functionParameter:{text:{name:"text",detail:"The text string containing the characters you want to extract."},numBytes:{name:"num_bytes",detail:"Specifies the number of characters you want RIGHTB to extract, based on bytes."}}},SEARCH:{description:"Finds one text value within another (not case-sensitive)",abstract:"Finds one text value within another (not case-sensitive)",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/search-searchb-functions-9ab04538-0e55-4719-a72e-b6f54513b495"}],functionParameter:{findText:{name:"find_text",detail:"The text you want to find."},withinText:{name:"within_text",detail:"The text containing the text you want to find."},startNum:{name:"start_num",detail:"Specifies the character at which to start the search. If you omit start_num, it is assumed to be 1."}}},SEARCHB:{description:"Finds one text value within another (not case-sensitive)",abstract:"Finds one text value within another (not case-sensitive)",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/search-searchb-functions-9ab04538-0e55-4719-a72e-b6f54513b495"}],functionParameter:{findText:{name:"find_text",detail:"The text you want to find."},withinText:{name:"within_text",detail:"The text containing the text you want to find."},startNum:{name:"start_num",detail:"Specifies the character at which to start the search. If you omit start_num, it is assumed to be 1."}}},SUBSTITUTE:{description:"Substitutes new text for old text in a text string",abstract:"Substitutes new text for old text in a text string",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/substitute-function-6434944e-a904-4336-a9b0-1e58df3bc332"}],functionParameter:{text:{name:"text",detail:"The text or the reference to a cell containing text for which you want to substitute characters."},oldText:{name:"old_text",detail:"The text you want to replace."},newText:{name:"new_text",detail:"The text you want to replace old_text with."},instanceNum:{name:"instance_num",detail:"Specifies which occurrence of old_text you want to replace with new_text. If you specify instance_num, only that instance of old_text is replaced. Otherwise, every occurrence of old_text in text is changed to new_text."}}},T:{description:"Converts its arguments to text",abstract:"Converts its arguments to text",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/t-function-fb83aeec-45e7-4924-af95-53e073541228"}],functionParameter:{value:{name:"value",detail:"The value you want to test."}}},TEXT:{description:"Formats a number and converts it to text",abstract:"Formats a number and converts it to text",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/text-function-20d5ac4d-7b94-49fd-bb38-93d29371225c"}],functionParameter:{value:{name:"value",detail:"A numeric value that you want to be converted into text."},formatText:{name:"format_text",detail:"A text string that defines the formatting that you want to be applied to the supplied value."}}},TEXTAFTER:{description:"Returns text that occurs after given character or string",abstract:"Returns text that occurs after given character or string",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/textafter-function-c8db2546-5b51-416a-9690-c7e6722e90b4"}],functionParameter:{text:{name:"text",detail:"The text you are searching within. Wildcard characters not allowed."},delimiter:{name:"delimiter",detail:"The text that marks the point after which you want to extract."},instanceNum:{name:"instance_num",detail:"The instance of the delimiter after which you want to extract the text."},matchMode:{name:"match_mode",detail:"Determines whether the text search is case-sensitive. The default is case-sensitive."},matchEnd:{name:"match_end",detail:"Treats the end of text as a delimiter. By default, the text is an exact match."},ifNotFound:{name:"if_not_found",detail:"Value returned if no match is found. By default, #N/A is returned."}}},TEXTBEFORE:{description:"Returns text that occurs before a given character or string",abstract:"Returns text that occurs before a given character or string",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/textbefore-function-d099c28a-dba8-448e-ac6c-f086d0fa1b29"}],functionParameter:{text:{name:"text",detail:"The text you are searching within. Wildcard characters not allowed."},delimiter:{name:"delimiter",detail:"The text that marks the point after which you want to extract."},instanceNum:{name:"instance_num",detail:"The instance of the delimiter after which you want to extract the text."},matchMode:{name:"match_mode",detail:"Determines whether the text search is case-sensitive. The default is case-sensitive."},matchEnd:{name:"match_end",detail:"Treats the end of text as a delimiter. By default, the text is an exact match."},ifNotFound:{name:"if_not_found",detail:"Value returned if no match is found. By default, #N/A is returned."}}},TEXTJOIN:{description:"Text: Combines the text from multiple ranges and/or strings",abstract:"Text: Combines the text from multiple ranges and/or strings",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/textjoin-function-357b449a-ec91-49d0-80c3-0e8fc845691c"}],functionParameter:{delimiter:{name:"delimiter",detail:"A text string, either empty, or one or more characters enclosed by double quotes, or a reference to a valid text string."},ignoreEmpty:{name:"ignore_empty",detail:"If TRUE, ignores empty cells."},text1:{name:"text1",detail:"Text item to be joined. A text string, or array of strings, such as a range of cells."},text2:{name:"text2",detail:"Additional text items to be joined. There can be a maximum of 252 text arguments for the text items, including text1. Each can be a text string, or array of strings, such as a range of cells."}}},TEXTSPLIT:{description:"Splits text strings by using column and row delimiters",abstract:"Splits text strings by using column and row delimiters",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/textsplit-function-b1ca414e-4c21-4ca0-b1b7-bdecace8a6e7"}],functionParameter:{text:{name:"text",detail:"The text to split."},colDelimiter:{name:"col_delimiter",detail:"The character or string by which to split the column."},rowDelimiter:{name:"row_delimiter",detail:"The character or string on which to split the line."},ignoreEmpty:{name:"ignore_empty",detail:"Whether to ignore empty cells. The default is FALSE."},matchMode:{name:"match_mode",detail:"Searches for a delimiter match in the text. By default, a case-sensitive match is done."},padWith:{name:"pad_with",detail:"The value to use for padding. By default, #N/A is used."}}},TRIM:{description:"Removes all spaces from text except for single spaces between words.",abstract:"Removes spaces from text",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/trim-function-410388fa-c5df-49c6-b16c-9e5630b479f9"}],functionParameter:{text:{name:"text",detail:"The text from which you want spaces removed."}}},UNICHAR:{description:"Returns the Unicode character that is references by the given numeric value",abstract:"Returns the Unicode character that is references by the given numeric value",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/unichar-function-ffeb64f5-f131-44c6-b332-5cd72f0659b8"}],functionParameter:{number:{name:"number",detail:"Number is the Unicode number that represents the character."}}},UNICODE:{description:"Returns the number (code point) that corresponds to the first character of the text",abstract:"Returns the number (code point) that corresponds to the first character of the text",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/unicode-function-adb74aaa-a2a5-4dde-aff6-966e4e81f16f"}],functionParameter:{text:{name:"text",detail:"Text is the character for which you want the Unicode value."}}},UPPER:{description:"Converts text to uppercase",abstract:"Converts text to uppercase",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/upper-function-c11f29b3-d1a3-4537-8df6-04d0049963d6"}],functionParameter:{text:{name:"text",detail:"The text you want converted to uppercase."}}},VALUE:{description:"Converts a text argument to a number",abstract:"Converts a text argument to a number",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/value-function-257d0108-07dc-437d-ae1c-bc2d3953d8c2"}],functionParameter:{text:{name:"text",detail:"The text enclosed in quotation marks or a reference to a cell containing the text you want to convert."}}},VALUETOTEXT:{description:"Returns text from any specified value",abstract:"Returns text from any specified value",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/valuetotext-function-5fff61a2-301a-4ab2-9ffa-0a5242a08fea"}],functionParameter:{value:{name:"value",detail:"The value to return as text."},format:{name:"format",detail:`The format of the returned data. It can be one of two values:
|
|
45
45
|
0 Default. Concise format that is easy to read.
|
|
46
|
-
1 Strict format that includes escape characters and row delimiters. Generates a string that can be parsed when entered into the formula bar. Encapsulates returned strings in quotes except for Booleans, Numbers and Errors.`}}},CALL:{description:"Calls a procedure in a dynamic link library or code resource",abstract:"Calls a procedure in a dynamic link library or code resource",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/call-function-32d58445-e646-4ffd-8d5e-b45077a5e995"}],functionParameter:{number1:{name:"number1",detail:"first"},number2:{name:"number2",detail:"second"}}},EUROCONVERT:{description:"Converts a number to euros, converts a number from euros to a euro member currency, or converts a number from one euro member currency to another by using the euro as an intermediary (triangulation)",abstract:"Converts a number to euros, converts a number from euros to a euro member currency, or converts a number from one euro member currency to another by using the euro as an intermediary (triangulation)",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/euroconvert-function-79c8fd67-c665-450c-bb6c-15fc92f8345c"}],functionParameter:{number1:{name:"number1",detail:"first"},number2:{name:"number2",detail:"second"}}},REGISTER_ID:{description:"Returns the register ID of the specified dynamic link library (DLL) or code resource that has been previously registered",abstract:"Returns the register ID of the specified dynamic link library (DLL) or code resource that has been previously registered",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/register-id-function-f8f0af0f-fd66-4704-a0f2-87b27b175b50"}],functionParameter:{number1:{name:"number1",detail:"first"},number2:{name:"number2",detail:"second"}}}},d={},h={ENCODEURL:{description:"Returns a URL-encoded string",abstract:"Returns a URL-encoded string",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/encodeurl-function-07c7fb90-7c60-4bff-8687-fac50fe33d0e"}],functionParameter:{text:{name:"text",detail:"A string to be URL encoded"}}},FILTERXML:{description:"Returns specific data from the XML content by using the specified XPath",abstract:"Returns specific data from the XML content by using the specified XPath",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/filterxml-function-4df72efc-11ec-4951-86f5-c1374812f5b7"}],functionParameter:{number1:{name:"number1",detail:"first"},number2:{name:"number2",detail:"second"}}},WEBSERVICE:{description:"Returns data from a web service",abstract:"Returns data from a web service",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/webservice-function-0546a35a-ecc6-4739-aed7-c0b7ce1562c4"}],functionParameter:{number1:{name:"number1",detail:"first"},number2:{name:"number2",detail:"second"}}}},p={formula:{insert:{tooltip:"Functions",sum:"SUM",average:"AVERAGE",count:"COUNT",max:"MAX",min:"MIN",more:"More Functions..."},functionList:{...o,...r,...l,...m,...c,...n,...f,...u,...s,...i,...a,...t,...h,...e,...d},prompt:{helpExample:"EXAMPLE",helpAbstract:"ABOUT",required:"Required.",optional:"Optional."},error:{title:"Error",divByZero:"Divide by zero error",name:"Invalid name error",value:"Error in value",num:"Number error",na:"Value not available error",cycle:"Circular reference error",ref:"Invalid cell reference error",spill:"Spill range isn't blank",calc:"Calculation error",error:"Error",connect:"Getting data",null:"Null Error"},functionType:{financial:"Financial",date:"Date & Time",math:"Math & Trig",statistical:"Statistical",lookup:"Lookup & Reference",database:"Database",text:"Text",logical:"Logical",information:"Information",engineering:"Engineering",cube:"Cube",compatibility:"Compatibility",web:"Web",array:"Array",univer:"Univer",user:"User Defined",definedname:"Defined Name"},moreFunctions:{confirm:"Confirm",prev:"Previous",next:"Next",searchFunctionPlaceholder:"Search function",allFunctions:"All Functions",syntax:"SYNTAX"},operation:{pasteFormula:"Paste Formula"}}};module.exports=p;
|
|
46
|
+
1 Strict format that includes escape characters and row delimiters. Generates a string that can be parsed when entered into the formula bar. Encapsulates returned strings in quotes except for Booleans, Numbers and Errors.`}}},CALL:{description:"Calls a procedure in a dynamic link library or code resource",abstract:"Calls a procedure in a dynamic link library or code resource",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/call-function-32d58445-e646-4ffd-8d5e-b45077a5e995"}],functionParameter:{number1:{name:"number1",detail:"first"},number2:{name:"number2",detail:"second"}}},EUROCONVERT:{description:"Converts a number to euros, converts a number from euros to a euro member currency, or converts a number from one euro member currency to another by using the euro as an intermediary (triangulation)",abstract:"Converts a number to euros, converts a number from euros to a euro member currency, or converts a number from one euro member currency to another by using the euro as an intermediary (triangulation)",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/euroconvert-function-79c8fd67-c665-450c-bb6c-15fc92f8345c"}],functionParameter:{number1:{name:"number1",detail:"first"},number2:{name:"number2",detail:"second"}}},REGISTER_ID:{description:"Returns the register ID of the specified dynamic link library (DLL) or code resource that has been previously registered",abstract:"Returns the register ID of the specified dynamic link library (DLL) or code resource that has been previously registered",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/register-id-function-f8f0af0f-fd66-4704-a0f2-87b27b175b50"}],functionParameter:{number1:{name:"number1",detail:"first"},number2:{name:"number2",detail:"second"}}}},d={},h={ENCODEURL:{description:"Returns a URL-encoded string",abstract:"Returns a URL-encoded string",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/encodeurl-function-07c7fb90-7c60-4bff-8687-fac50fe33d0e"}],functionParameter:{text:{name:"text",detail:"A string to be URL encoded"}}},FILTERXML:{description:"Returns specific data from the XML content by using the specified XPath",abstract:"Returns specific data from the XML content by using the specified XPath",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/filterxml-function-4df72efc-11ec-4951-86f5-c1374812f5b7"}],functionParameter:{number1:{name:"number1",detail:"first"},number2:{name:"number2",detail:"second"}}},WEBSERVICE:{description:"Returns data from a web service",abstract:"Returns data from a web service",links:[{title:"Instruction",url:"https://support.microsoft.com/en-us/office/webservice-function-0546a35a-ecc6-4739-aed7-c0b7ce1562c4"}],functionParameter:{number1:{name:"number1",detail:"first"},number2:{name:"number2",detail:"second"}}}},p={shortcut:{"sheets-formula-ui":{"quick-sum":"Quick Sum"}},formula:{insert:{tooltip:"Functions",sum:"SUM",average:"AVERAGE",count:"COUNT",max:"MAX",min:"MIN",more:"More Functions..."},functionList:{...o,...r,...l,...m,...c,...n,...f,...u,...s,...i,...a,...t,...h,...e,...d},prompt:{helpExample:"EXAMPLE",helpAbstract:"ABOUT",required:"Required.",optional:"Optional."},error:{title:"Error",divByZero:"Divide by zero error",name:"Invalid name error",value:"Error in value",num:"Number error",na:"Value not available error",cycle:"Circular reference error",ref:"Invalid cell reference error",spill:"Spill range isn't blank",calc:"Calculation error",error:"Error",connect:"Getting data",null:"Null Error"},functionType:{financial:"Financial",date:"Date & Time",math:"Math & Trig",statistical:"Statistical",lookup:"Lookup & Reference",database:"Database",text:"Text",logical:"Logical",information:"Information",engineering:"Engineering",cube:"Cube",compatibility:"Compatibility",web:"Web",array:"Array",univer:"Univer",user:"User Defined",definedname:"Defined Name"},moreFunctions:{confirm:"Confirm",prev:"Previous",next:"Next",searchFunctionPlaceholder:"Search function",allFunctions:"All Functions",syntax:"SYNTAX"},operation:{pasteFormula:"Paste Formula"}}};module.exports=p;
|