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