index.js 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711
  1. var ro = Object.defineProperty;
  2. var oo = (e, t, n) => t in e ? ro(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
  3. var Q = (e, t, n) => oo(e, typeof t != "symbol" ? t + "" : t, n);
  4. import { CommandType as $e, ICommandService as ye, createIdentifier as so, IContextService as hn, IUniverInstanceService as pe, Rectangle as io, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as dn, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as tr, DEFAULT_EMPTY_DOCUMENT_VALUE as nr, isRealNum as co, CellValueType as Fn, getCellValueType as ao, toDisposable as rr, DisposableCollection as st, RANGE_TYPE as Te, Inject as ee, Injector as _t, ThemeService as Rt, useDependency as y, Tools as vt, ColorKit as or, getBodySlice as yn, UniverInstanceType as Me, Direction as he, EDITOR_ACTIVATED as Ft, LocaleService as Xe, createInternalEditorID as sr, generateRandomId as ir, useObservable as it, BuildTextUtils as cr, isFormulaString as Ge, isFormulaId as ct, FOCUSING_DOC as lo, FOCUSING_UNIVER_EDITOR as uo, Disposable as It, isICellData as fo, ObjectMatrix as Et, ILogService as ho, RxDisposable as mo, InterceptorEffectEnum as go, useInjector as po, connectInjector as Tn, Plugin as So, merge as vo, touchDependencies as Co, DependentOn as _o, IConfigService as Ro } from "@univerjs/core";
  5. import { SheetPasteCommand as Io, PREDEFINED_HOOK_NAME as rt, IEditorBridgeService as ar, BaseSelectionRenderService as Eo, getCoordByOffset as On, checkInHeaderRanges as Mn, getAllSelection as bo, genNormalSelectionStyle as lr, getSheetObject as xo, attachSelectionWithCoord as on, SelectionControl as ur, SheetSkeletonManagerService as kt, MoveSelectionCommand as Pn, JumpOver as An, ExpandSelectionCommand as Ln, RANGE_SELECTOR_SYMBOLS as No, SetCellEditVisibleOperation as Fo, EMBEDDING_FORMULA_EDITOR as yo, CellAlertType as To, HoverManagerService as Oo, CellAlertManagerService as Mo, DATA_TYPE as wn, APPLY_TYPE as Po, IAutoFillService as Ao, COPY_TYPE as Lo, ISheetClipboardService as wo, SELECTION_SHAPE_DEPTH as $o, useActiveWorkbook as Do, getCurrentRangeDisable$ as fr, PASTE_SPECIAL_MENU_ID as ko, whenFormulaEditorActivated as bt, SheetsUIPart as jo, RANGE_SELECTOR_COMPONENT_KEY as Ho, EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY as Wo } from "@univerjs/sheets-ui";
  6. import { sequenceNodeType as G, serializeRange as Ve, matchToken as ge, LexerTreeBuilder as Be, deserializeRangeWithSheet as we, matchRefDrawToken as Uo, isFormulaLexerToken as Vo, serializeRangeWithSheet as Tt, operatorToken as hr, ERROR_TYPE_SET as Bo, ErrorType as Se, FormulaDataModel as jt, SetFormulaCalculationResultMutation as qo, SetArrayFormulaDataMutation as Ko, SetFormulaCalculationStopMutation as Yo, FunctionType as zo, UniverFormulaEnginePlugin as Zo } from "@univerjs/engine-formula";
  7. import { Subject as ft, filter as sn, map as Ht, merge as cn, distinctUntilChanged as dr, throttleTime as mn, noop as $n, BehaviorSubject as Go, debounceTime as gn, combineLatestWith as Xo, switchMap as Jo, of as Dn, Observable as Qo } from "rxjs";
  8. import { IEditorService as qe, ReplaceTextRunsCommand as kn, DocSelectionRenderService as mr, MoveSelectionOperation as es, MoveCursorOperation as ts, useResize as gr, DocBackScrollRenderController as pr, useKeyboardEvent as ns } from "@univerjs/docs-ui";
  9. import { DeviceInputEventType as De, ScrollTimerType as Zt, SHEET_VIEWPORT_KEY as jn, Vector2 as Hn, IRenderManagerService as ve } from "@univerjs/engine-render";
  10. import { SheetsSelectionsService as Sr, getSheetCommandTarget as vr, getCellAtRowCol as rs, SetSelectionsOperation as Cr, SelectionMoveType as Gt, convertSelectionDataToRange as os, IRefSelectionsService as Wt, setEndForRange as ss, REF_SELECTIONS_ENABLED as Wn, SetWorksheetActiveOperation as Un, SetRangeValuesMutation as Vn, SetRangeValuesUndoMutationFactory as is, SheetInterceptorService as _r, BEFORE_CELL_EDIT as cs, SetWorksheetRowAutoHeightMutation as as, INTERCEPTOR_POINT as ls, WorkbookEditablePermission as Rr, WorksheetEditPermission as Ir, WorksheetSetCellValuePermission as Er, RangeProtectionPermissionEditPoint as br } from "@univerjs/sheets";
  11. import { InsertFunctionCommand as us, IDescriptionService as xt, TriggerCalculationController as fs, UniverSheetsFormulaPlugin as hs } from "@univerjs/sheets-formula";
  12. import { ISidebarService as Ut, IShortcutService as Vt, useEvent as Ee, KeyCode as $, MetaKeys as Y, IContextMenuService as ds, RectPopup as xr, useUpdateEffect as ms, IZenZoneService as gs, ProgressBar as ps, ILayoutService as Ss, MenuItemType as pn, getMenuHiddenObservable as vs, IClipboardInterfaceService as Bn, RibbonStartGroup as Cs, BuiltInUIPart as _s, ComponentManager as Nr, IMenuManagerService as Rs, IUIPartsService as Is } from "@univerjs/ui";
  13. import Es, { forwardRef as ke, useRef as q, createElement as Ke, useEffect as D, useCallback as at, useMemo as Z, useState as H, useLayoutEffect as lt } from "react";
  14. import { Tooltip as bs, Dialog as xs, Button as ot, Input as Fr, Popup as yr, Select as Ns } from "@univerjs/design";
  15. import { DocSelectionManagerService as Tr, RichTextEditingMutation as Fs } from "@univerjs/docs";
  16. import { throttleTime as ys, debounceTime as qn, map as Ts, distinctUntilChanged as Os } from "rxjs/operators";
  17. const Sn = {
  18. id: "sheet.command.paste-formula",
  19. type: $e.COMMAND,
  20. handler: async (e) => e.get(ye).executeCommand(Io.id, {
  21. value: rt.SPECIAL_PASTE_FORMULA
  22. })
  23. }, ut = {
  24. id: "formula-ui.operation.select-editor-formula",
  25. type: $e.OPERATION,
  26. handler: (e, t) => !0
  27. };
  28. var Ms = Object.defineProperty, Ps = Object.getOwnPropertyDescriptor, As = (e, t, n, o) => {
  29. for (var r = o > 1 ? void 0 : o ? Ps(t, n) : t, i = e.length - 1, s; i >= 0; i--)
  30. (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
  31. return o && r && Ms(t, n, r), r;
  32. }, Ls = (e, t) => (n, o) => t(n, o, e);
  33. const ws = "FORMULA_PROMPT_ACTIVATED", Nt = so("formula-ui.prompt-service");
  34. let an = class {
  35. constructor(e) {
  36. Q(this, "_search$", new ft());
  37. Q(this, "_help$", new ft());
  38. Q(this, "_navigate$", new ft());
  39. Q(this, "_accept$", new ft());
  40. Q(this, "_acceptFormulaName$", new ft());
  41. Q(this, "search$", this._search$.asObservable());
  42. Q(this, "help$", this._help$.asObservable());
  43. Q(this, "navigate$", this._navigate$.asObservable());
  44. Q(this, "accept$", this._accept$.asObservable());
  45. Q(this, "acceptFormulaName$", this._acceptFormulaName$.asObservable());
  46. Q(this, "_searching", !1);
  47. Q(this, "_helping", !1);
  48. Q(this, "_sequenceNodes", []);
  49. Q(this, "_isLockedOnSelectionChangeRefString", !1);
  50. Q(this, "_isLockedOnSelectionInsertRefString", !1);
  51. this._contextService = e;
  52. }
  53. dispose() {
  54. this._search$.complete(), this._help$.complete(), this._navigate$.complete(), this._accept$.complete(), this._acceptFormulaName$.complete(), this._sequenceNodes = [];
  55. }
  56. search(e) {
  57. this._contextService.setContextValue(ws, e.visible), this._searching = e.visible, this._search$.next(e);
  58. }
  59. isSearching() {
  60. return this._searching;
  61. }
  62. help(e) {
  63. this._helping = e.visible, this._help$.next(e);
  64. }
  65. isHelping() {
  66. return this._helping;
  67. }
  68. navigate(e) {
  69. this._navigate$.next(e);
  70. }
  71. accept(e) {
  72. this._accept$.next(e);
  73. }
  74. acceptFormulaName(e) {
  75. this._acceptFormulaName$.next(e);
  76. }
  77. getSequenceNodes() {
  78. return [...this._sequenceNodes];
  79. }
  80. setSequenceNodes(e) {
  81. this._sequenceNodes = e;
  82. }
  83. clearSequenceNodes() {
  84. this._sequenceNodes = [];
  85. }
  86. getCurrentSequenceNode(e) {
  87. return this._sequenceNodes[this.getCurrentSequenceNodeIndex(e)];
  88. }
  89. getCurrentSequenceNodeByIndex(e) {
  90. return this._sequenceNodes[e];
  91. }
  92. /**
  93. * Query the text coordinates in the sequenceNodes and determine the actual insertion index.
  94. * @param strIndex
  95. */
  96. getCurrentSequenceNodeIndex(e) {
  97. let t = 0;
  98. const n = this._sequenceNodes[0];
  99. for (let o = 0, r = this._sequenceNodes.length; o < r; o++) {
  100. const i = this._sequenceNodes[o];
  101. if (typeof i == "string")
  102. t++;
  103. else {
  104. const { endIndex: s } = i;
  105. t = s;
  106. }
  107. if (e <= t)
  108. return typeof n == "string" && e !== 0 ? o + 1 : o;
  109. }
  110. return this._sequenceNodes.length;
  111. }
  112. /**
  113. * Synchronize the reference text based on the changes of the selection.
  114. * @param nodeIndex
  115. * @param refString
  116. */
  117. updateSequenceRef(e, t) {
  118. const n = this._sequenceNodes[e];
  119. if (typeof n == "string" || n.nodeType !== G.REFERENCE)
  120. return;
  121. const o = t.length - n.token.length, r = { ...n };
  122. r.token = t, r.endIndex += o, this._sequenceNodes[e] = r;
  123. for (let i = e + 1, s = this._sequenceNodes.length; i < s; i++) {
  124. const c = this._sequenceNodes[i];
  125. if (typeof c == "string")
  126. continue;
  127. const a = { ...c };
  128. a.startIndex += o, a.endIndex += o, this._sequenceNodes[i] = a;
  129. }
  130. }
  131. /**
  132. * When the cursor is on the right side of a formula token,
  133. * you can add reference text to the formula by drawing a selection.
  134. * @param index
  135. * @param refString
  136. */
  137. insertSequenceRef(e, t) {
  138. const n = t.length, o = this.getCurrentSequenceNodeIndex(e);
  139. this._sequenceNodes.splice(o, 0, {
  140. token: t,
  141. startIndex: e,
  142. endIndex: e + n - 1,
  143. nodeType: G.REFERENCE
  144. });
  145. for (let r = o + 1, i = this._sequenceNodes.length; r < i; r++) {
  146. const s = this._sequenceNodes[r];
  147. if (typeof s == "string")
  148. continue;
  149. const c = { ...s };
  150. c.startIndex += n, c.endIndex += n, this._sequenceNodes[r] = c;
  151. }
  152. }
  153. /**
  154. * Insert a string at the cursor position in the text corresponding to the sequenceNodes.
  155. * @param index
  156. * @param content
  157. */
  158. insertSequenceString(e, t) {
  159. const n = this.getCurrentSequenceNodeIndex(e), o = t.split("");
  160. this._sequenceNodes.splice(n, 0, ...o);
  161. const r = o.length;
  162. for (let i = n + r, s = this._sequenceNodes.length; i < s; i++) {
  163. const c = this._sequenceNodes[i];
  164. if (typeof c == "string")
  165. continue;
  166. const a = { ...c };
  167. a.startIndex += r, a.endIndex += r, this._sequenceNodes[i] = a;
  168. }
  169. }
  170. enableLockedSelectionChange() {
  171. this._isLockedOnSelectionChangeRefString = !0;
  172. }
  173. disableLockedSelectionChange() {
  174. this._isLockedOnSelectionChangeRefString = !1;
  175. }
  176. isLockedSelectionChange() {
  177. return this._isLockedOnSelectionChangeRefString;
  178. }
  179. enableLockedSelectionInsert() {
  180. this._isLockedOnSelectionInsertRefString = !0;
  181. }
  182. disableLockedSelectionInsert() {
  183. this._isLockedOnSelectionInsertRefString = !1;
  184. }
  185. isLockedSelectionInsert() {
  186. return this._isLockedOnSelectionInsertRefString;
  187. }
  188. };
  189. an = As([
  190. Ls(0, hn)
  191. ], an);
  192. const $s = {
  193. id: "formula-ui.operation.help-function",
  194. type: $e.OPERATION,
  195. handler: async (e, t) => (e.get(Nt).help(t), !0)
  196. }, vn = {
  197. id: "formula-ui.operation.insert-function",
  198. type: $e.OPERATION,
  199. // eslint-disable-next-line max-lines-per-function
  200. handler: async (e, t) => {
  201. var C, _;
  202. const n = e.get(Sr), o = e.get(qe), r = n.getCurrentSelections();
  203. if (!r || !r.length)
  204. return !1;
  205. const i = vr(e.get(pe));
  206. if (!i) return !1;
  207. const { worksheet: s, unitId: c, subUnitId: a } = i, d = s.getCellMatrix(), { value: u } = t, h = e.get(ye), f = e.get(ar), g = [];
  208. let l = null, m = 0, S = 0, R = "";
  209. if (r.length === 1 && (js(r[0].range) || Hs(r[0].range))) {
  210. const { range: E, primary: x } = r[0], M = (C = x == null ? void 0 : x.actualRow) != null ? C : E.startRow, T = (_ = x == null ? void 0 : x.actualColumn) != null ? _ : E.startColumn;
  211. l = E, m = M, S = T;
  212. const P = Kn(d, M, T);
  213. P && (R = Ve(P));
  214. } else
  215. r.some((E) => {
  216. var w, I;
  217. const { range: x, primary: M } = E, T = (w = M == null ? void 0 : M.actualRow) != null ? w : x.startRow, P = (I = M == null ? void 0 : M.actualColumn) != null ? I : x.startColumn, A = Kn(d, T, P);
  218. if (!A)
  219. return l = x, m = T, S = P, !0;
  220. const N = Ve(A), b = `=${u}(${N})`;
  221. return g.push({
  222. range: x,
  223. primary: {
  224. row: T,
  225. column: P
  226. },
  227. formula: b
  228. }), !1;
  229. });
  230. if (l) {
  231. const E = rs(m, S, s), x = {
  232. range: io.clone(l),
  233. primary: {
  234. startRow: E.startRow,
  235. startColumn: E.startColumn,
  236. endRow: E.endRow,
  237. endColumn: E.endColumn,
  238. actualRow: m,
  239. actualColumn: S,
  240. isMerged: E.isMerged,
  241. isMergedMainCell: E.startRow === m && E.startColumn === S
  242. }
  243. }, M = {
  244. unitId: c,
  245. subUnitId: a,
  246. selections: [x]
  247. };
  248. await h.executeCommand(Cr.id, M);
  249. const T = o.getEditor(dn), P = o.getEditor(tr);
  250. f.changeVisible({
  251. visible: !0,
  252. unitId: c,
  253. eventType: De.Dblclick
  254. });
  255. const A = `=${u}(${R}`;
  256. T == null || T.replaceText(A), P == null || P.replaceText(A, !1);
  257. }
  258. return g.length === 0 ? !1 : h.executeCommand(us.id, {
  259. list: g
  260. });
  261. }
  262. };
  263. function Kn(e, t, n) {
  264. const o = Ds(e, t, n);
  265. if (o !== t)
  266. return {
  267. startRow: o,
  268. endRow: t - 1,
  269. startColumn: n,
  270. endColumn: n
  271. };
  272. const r = ks(e, t, n);
  273. return r !== n ? {
  274. startRow: t,
  275. endRow: t,
  276. startColumn: r,
  277. endColumn: n - 1
  278. } : null;
  279. }
  280. function Ds(e, t, n) {
  281. let o = !1;
  282. if (t === 0) return t;
  283. for (let r = t - 1; r >= 0; r--) {
  284. const i = e.getValue(r, n);
  285. if (Ot(i) && !o) {
  286. if (r === 0) return 0;
  287. o = !0;
  288. } else {
  289. if (o && !Ot(i))
  290. return r + 1;
  291. if (o && r === 0)
  292. return 0;
  293. }
  294. }
  295. return t;
  296. }
  297. function ks(e, t, n) {
  298. let o = !1;
  299. if (n === 0) return n;
  300. for (let r = n - 1; r >= 0; r--) {
  301. const i = e.getValue(t, r);
  302. if (Ot(i) && !o) {
  303. if (r === 0) return 0;
  304. o = !0;
  305. } else {
  306. if (o && !Ot(i))
  307. return r + 1;
  308. if (o && r === 0)
  309. return 0;
  310. }
  311. }
  312. return n;
  313. }
  314. function Ot(e) {
  315. if (e != null && e.p) {
  316. const t = e == null ? void 0 : e.p.body;
  317. if (t == null)
  318. return !1;
  319. const n = t.dataStream, r = n.substring(n.length - 2, n.length) === nr ? n.substring(0, n.length - 2) : n;
  320. return co(r);
  321. }
  322. return e && (e.t === Fn.NUMBER || ao(e) === Fn.NUMBER);
  323. }
  324. function js(e) {
  325. return e.startRow === e.endRow && e.startColumn === e.endColumn;
  326. }
  327. function Hs(e) {
  328. return e.startRow !== e.endRow && e.startColumn !== e.endColumn;
  329. }
  330. const Or = "SHEET_FORMULA_UI_PLUGIN", Mr = `${Or}_MORE_FUNCTIONS_COMPONENT`, Cn = {
  331. id: "formula-ui.operation.more-functions",
  332. type: $e.OPERATION,
  333. handler: async (e) => (e.get(Ut).open({
  334. header: { title: "formula.insert.tooltip" },
  335. children: { label: Mr }
  336. }), !0)
  337. }, Pr = {
  338. id: "formula-ui.operation.change-ref-to-absolute",
  339. type: $e.OPERATION,
  340. handler: async (e) => !0
  341. }, Ws = {
  342. id: "formula-ui.operation.search-function",
  343. type: $e.OPERATION,
  344. handler: async (e, t) => (e.get(Nt).search(t), !0)
  345. };
  346. var Xt = { exports: {} }, ht = {};
  347. /**
  348. * @license React
  349. * react-jsx-runtime.production.min.js
  350. *
  351. * Copyright (c) Facebook, Inc. and its affiliates.
  352. *
  353. * This source code is licensed under the MIT license found in the
  354. * LICENSE file in the root directory of this source tree.
  355. */
  356. var Yn;
  357. function Us() {
  358. if (Yn) return ht;
  359. Yn = 1;
  360. var e = Es, t = Symbol.for("react.element"), n = Symbol.for("react.fragment"), o = Object.prototype.hasOwnProperty, r = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, i = { key: !0, ref: !0, __self: !0, __source: !0 };
  361. function s(c, a, d) {
  362. var u, h = {}, f = null, g = null;
  363. d !== void 0 && (f = "" + d), a.key !== void 0 && (f = "" + a.key), a.ref !== void 0 && (g = a.ref);
  364. for (u in a) o.call(a, u) && !i.hasOwnProperty(u) && (h[u] = a[u]);
  365. if (c && c.defaultProps) for (u in a = c.defaultProps, a) h[u] === void 0 && (h[u] = a[u]);
  366. return { $$typeof: t, type: c, key: f, ref: g, props: h, _owner: r.current };
  367. }
  368. return ht.Fragment = n, ht.jsx = s, ht.jsxs = s, ht;
  369. }
  370. var zn;
  371. function Vs() {
  372. return zn || (zn = 1, Xt.exports = Us()), Xt.exports;
  373. }
  374. var p = Vs(), Ie = function() {
  375. return Ie = Object.assign || function(e) {
  376. for (var t, n = 1, o = arguments.length; n < o; n++) {
  377. t = arguments[n];
  378. for (var r in t) Object.prototype.hasOwnProperty.call(t, r) && (e[r] = t[r]);
  379. }
  380. return e;
  381. }, Ie.apply(this, arguments);
  382. }, Bs = function(e, t) {
  383. var n = {};
  384. for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && t.indexOf(o) < 0 && (n[o] = e[o]);
  385. if (e != null && typeof Object.getOwnPropertySymbols == "function")
  386. for (var r = 0, o = Object.getOwnPropertySymbols(e); r < o.length; r++)
  387. t.indexOf(o[r]) < 0 && Object.prototype.propertyIsEnumerable.call(e, o[r]) && (n[o[r]] = e[o[r]]);
  388. return n;
  389. }, Ye = ke(function(e, t) {
  390. var n = e.icon, o = e.id, r = e.className, i = e.extend, s = Bs(e, ["icon", "id", "className", "extend"]), c = "univerjs-icon univerjs-icon-".concat(o, " ").concat(r || "").trim(), a = q("_".concat(Ys()));
  391. return Ar(n, "".concat(o), { defIds: n.defIds, idSuffix: a.current }, Ie({ ref: t, className: c }, s), i);
  392. });
  393. function Ar(e, t, n, o, r) {
  394. return Ke(e.tag, Ie(Ie({ key: t }, qs(e, n, r)), o), (Ks(e, n).children || []).map(function(i, s) {
  395. return Ar(i, "".concat(t, "-").concat(e.tag, "-").concat(s), n, void 0, r);
  396. }));
  397. }
  398. function qs(e, t, n) {
  399. var o = Ie({}, e.attrs);
  400. n != null && n.colorChannel1 && o.fill === "colorChannel1" && (o.fill = n.colorChannel1);
  401. var r = t.defIds;
  402. return !r || r.length === 0 || (e.tag === "use" && o["xlink:href"] && (o["xlink:href"] = o["xlink:href"] + t.idSuffix), Object.entries(o).forEach(function(i) {
  403. var s = i[0], c = i[1];
  404. typeof c == "string" && (o[s] = c.replace(/url\(#(.*)\)/, "url(#$1".concat(t.idSuffix, ")")));
  405. })), o;
  406. }
  407. function Ks(e, t) {
  408. var n, o = t.defIds;
  409. return !o || o.length === 0 ? e : e.tag === "defs" && (!((n = e.children) === null || n === void 0) && n.length) ? Ie(Ie({}, e), { children: e.children.map(function(r) {
  410. return typeof r.attrs.id == "string" && o && o.indexOf(r.attrs.id) > -1 ? Ie(Ie({}, r), { attrs: Ie(Ie({}, r.attrs), { id: r.attrs.id + t.idSuffix }) }) : r;
  411. }) }) : e;
  412. }
  413. function Ys() {
  414. return Math.random().toString(36).substring(2, 8);
  415. }
  416. Ye.displayName = "UniverIcon";
  417. var zs = { 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" } }] }, Lr = ke(function(e, t) {
  418. return Ke(Ye, Object.assign({}, e, {
  419. id: "check-mark-single",
  420. ref: t,
  421. icon: zs
  422. }));
  423. });
  424. Lr.displayName = "CheckMarkSingle";
  425. var Zs = { 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" } }] }, Bt = ke(function(e, t) {
  426. return Ke(Ye, Object.assign({}, e, {
  427. id: "close-single",
  428. ref: t,
  429. icon: Zs
  430. }));
  431. });
  432. Bt.displayName = "CloseSingle";
  433. var Gs = { 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" } }] }, wr = ke(function(e, t) {
  434. return Ke(Ye, Object.assign({}, e, {
  435. id: "delete-single",
  436. ref: t,
  437. icon: Gs
  438. }));
  439. });
  440. wr.displayName = "DeleteSingle";
  441. var Xs = { 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" } }] }, $r = ke(function(e, t) {
  442. return Ke(Ye, Object.assign({}, e, {
  443. id: "details-single",
  444. ref: t,
  445. icon: Xs
  446. }));
  447. });
  448. $r.displayName = "DetailsSingle";
  449. var Js = { 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" } }] }, Dr = ke(function(e, t) {
  450. return Ke(Ye, Object.assign({}, e, {
  451. id: "increase-single",
  452. ref: t,
  453. icon: Js
  454. }));
  455. });
  456. Dr.displayName = "IncreaseSingle";
  457. var Qs = { 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" } }] }, _n = ke(function(e, t) {
  458. return Ke(Ye, Object.assign({}, e, {
  459. id: "more-single",
  460. ref: t,
  461. icon: Qs
  462. }));
  463. });
  464. _n.displayName = "MoreSingle";
  465. var ei = { 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" } }] }, kr = ke(function(e, t) {
  466. return Ke(Ye, Object.assign({}, e, {
  467. id: "select-range-single",
  468. ref: t,
  469. icon: ei
  470. }));
  471. });
  472. kr.displayName = "SelectRangeSingle";
  473. function jr(e) {
  474. var t, n, o = "";
  475. if (typeof e == "string" || typeof e == "number") o += e;
  476. else if (typeof e == "object") if (Array.isArray(e)) {
  477. var r = e.length;
  478. for (t = 0; t < r; t++) e[t] && (n = jr(e[t])) && (o && (o += " "), o += n);
  479. } else for (n in e) e[n] && (o && (o += " "), o += n);
  480. return o;
  481. }
  482. function ln() {
  483. for (var e, t, n = 0, o = "", r = arguments.length; n < r; n++) (e = arguments[n]) && (t = jr(e)) && (o && (o += " "), o += t);
  484. return o;
  485. }
  486. var ti = Object.defineProperty, ni = Object.getOwnPropertyDescriptor, ri = (e, t, n, o) => {
  487. for (var r = o > 1 ? void 0 : o ? ni(t, n) : t, i = e.length - 1, s; i >= 0; i--)
  488. (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
  489. return o && r && ti(t, n, r), r;
  490. }, tt = (e, t) => (n, o) => t(n, o, e);
  491. let Fe = class extends Eo {
  492. constructor(t, n, o, r, i, s, c) {
  493. super(
  494. n,
  495. o,
  496. r,
  497. i,
  498. s
  499. );
  500. Q(this, "_workbookSelections");
  501. Q(this, "_eventDisposables");
  502. this._context = t, this._contextService = s, this._refSelectionsService = c, this._workbookSelections = this._refSelectionsService.getWorkbookSelections(this._context.unitId), this._initSelectionChangeListener(), this._initSkeletonChangeListener(), this._initUserActionSyncListener(), this._setSelectionStyle(oi(this._themeService)), this._remainLastEnabled = !0, this._highlightHeader = !1;
  503. }
  504. getLocation() {
  505. return this._skeleton.getLocation();
  506. }
  507. setRemainLastEnabled(t) {
  508. this._remainLastEnabled = t;
  509. }
  510. /**
  511. * This is set to true when you need to add a new selection.
  512. * @param {boolean} enabled
  513. * @memberof RefSelectionsRenderService
  514. */
  515. setSkipLastEnabled(t) {
  516. this._skipLastEnabled = t;
  517. }
  518. clearLastSelection() {
  519. const t = this._selectionControls[this._selectionControls.length - 1];
  520. t && (t.dispose(), this._selectionControls.pop());
  521. }
  522. /**
  523. * Call this method and user will be able to select on the canvas to update selections.
  524. */
  525. enableSelectionChanging() {
  526. return this._disableSelectionChanging(), this._eventDisposables = this._initCanvasEventListeners(), rr(() => this._disableSelectionChanging());
  527. }
  528. _disableSelectionChanging() {
  529. var t;
  530. (t = this._eventDisposables) == null || t.dispose(), this._eventDisposables = null;
  531. }
  532. disableSelectionChanging() {
  533. this._disableSelectionChanging();
  534. }
  535. _initCanvasEventListeners() {
  536. const t = this._getSheetObject(), { spreadsheetRowHeader: n, spreadsheetColumnHeader: o, spreadsheet: r, spreadsheetLeftTopPlaceholder: i } = t, { scene: s } = this._context, c = new st();
  537. return c.add(r == null ? void 0 : r.onPointerDown$.subscribeEvent((a, d) => {
  538. this.inRefSelectionMode() && (this._onPointerDown(a, r.zIndex + 1, Te.NORMAL, this._getActiveViewport(a)), a.button !== 2 && d.stopPropagation());
  539. })), c.add(
  540. n == null ? void 0 : n.onPointerDown$.subscribeEvent((a, d) => {
  541. if (!this.inRefSelectionMode()) return;
  542. const u = this._sheetSkeletonManagerService.getCurrent().skeleton, { row: h } = On(a.offsetX, a.offsetY, s, u);
  543. Mn(this._workbookSelections.getCurrentSelections(), h, Te.ROW) || (this._onPointerDown(a, (r.zIndex || 1) + 1, Te.ROW, this._getActiveViewport(a), Zt.Y), a.button !== 2 && d.stopPropagation());
  544. })
  545. ), c.add(o == null ? void 0 : o.onPointerDown$.subscribeEvent((a, d) => {
  546. if (!this.inRefSelectionMode()) return;
  547. const u = this._sheetSkeletonManagerService.getCurrent().skeleton, { column: h } = On(a.offsetX, a.offsetY, s, u);
  548. Mn(this._workbookSelections.getCurrentSelections(), h, Te.COLUMN) || (this._onPointerDown(a, (r.zIndex || 1) + 1, Te.COLUMN, this._getActiveViewport(a), Zt.X), a.button !== 2 && d.stopPropagation());
  549. })), c.add(i == null ? void 0 : i.onPointerDown$.subscribeEvent((a, d) => {
  550. if (this._reset(), !this.inRefSelectionMode()) return;
  551. const u = this._sheetSkeletonManagerService.getCurrent().skeleton, h = bo(u);
  552. this._addSelectionControlByModelData(h), this._selectionMoveStart$.next(this.getSelectionDataWithStyle());
  553. const f = s.onPointerUp$.subscribeEvent(() => {
  554. f.unsubscribe(), this._selectionMoveEnd$.next(this.getSelectionDataWithStyle());
  555. });
  556. a.button !== 2 && d.stopPropagation();
  557. })), c;
  558. }
  559. /**
  560. * Add a selection in spreadsheet, create a new SelectionControl and then update this control by range derives from selection.
  561. * For ref selection, create selectionShapeExtension to handle user action.
  562. * @param {ISelectionWithCoord} selectionWithStyle
  563. */
  564. _addSelectionControlByModelData(t) {
  565. var s;
  566. const n = this._skeleton, o = (s = t.style) != null ? s : lr(this._themeService), r = this._scene;
  567. return t.style = o, this.newSelectionControl(r, n, t);
  568. }
  569. _initSelectionChangeListener() {
  570. this.disposeWithMe(this._refSelectionsService.selectionSet$.subscribe((t) => {
  571. this._reset(), this._skeleton && this.resetSelectionsByModelData(t || []);
  572. }));
  573. }
  574. /**
  575. * Update selectionModel in this._workbookSelections by user action in spreadsheet area.
  576. */
  577. _initUserActionSyncListener() {
  578. this.disposeWithMe(this.selectionMoveStart$.subscribe((t) => {
  579. this._updateSelections(t, Gt.MOVE_START);
  580. })), this.disposeWithMe(this.selectionMoving$.subscribe((t) => {
  581. this._updateSelections(t, Gt.MOVING);
  582. })), this.disposeWithMe(this.selectionMoveEnd$.subscribe((t) => {
  583. this._updateSelections(t, Gt.MOVE_END);
  584. }));
  585. }
  586. _updateSelections(t, n) {
  587. const r = this._context.unit.getActiveSheet().getSheetId();
  588. t.length !== 0 && this._workbookSelections.setSelections(
  589. r,
  590. t.map((i) => os(i)),
  591. n
  592. );
  593. }
  594. _initSkeletonChangeListener() {
  595. this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe((t) => {
  596. if (!t)
  597. return;
  598. const { skeleton: n } = t, { scene: o } = this._context, r = o.getViewport(jn.VIEW_MAIN);
  599. this._skeleton && this._skeleton.worksheet.getSheetId() !== n.worksheet.getSheetId() && this._reset(), this._changeRuntime(n, o, r);
  600. const i = this._workbookSelections.getCurrentSelections();
  601. this.resetSelectionsByModelData(i);
  602. }));
  603. }
  604. _getActiveViewport(t) {
  605. const n = this._getSheetObject();
  606. return n == null ? void 0 : n.scene.getActiveViewportByCoord(Hn.FromArray([t.offsetX, t.offsetY]));
  607. }
  608. _getSheetObject() {
  609. return xo(this._context.unit, this._context);
  610. }
  611. /**
  612. * Handle pointer down event, bind pointermove & pointerup handler.
  613. * then trigger selectionMoveStart$.
  614. *
  615. * @param evt
  616. * @param _zIndex
  617. * @param rangeType
  618. * @param viewport
  619. * @param scrollTimerType
  620. */
  621. // eslint-disable-next-line complexity, max-lines-per-function
  622. _onPointerDown(t, n = 0, o = Te.NORMAL, r, i = Zt.ALL) {
  623. var N;
  624. this._rangeType = o;
  625. const s = this._skeleton, c = this._scene;
  626. if (!c || !s)
  627. return;
  628. r && (this._activeViewport = r);
  629. const { offsetX: a, offsetY: d } = t, u = c.getViewport(jn.VIEW_MAIN);
  630. if (!u) return;
  631. const h = c.getCoordRelativeToViewport(Hn.FromArray([a, d])), { x: f, y: g } = h;
  632. this._startViewportPosX = f, this._startViewportPosY = g;
  633. const l = c.getScrollXYInfoByViewport(h), { scaleX: m, scaleY: S } = c.getAncestorScale(), R = this._skeleton.getCellByOffset(f, g, m, S, l);
  634. if (!R) return;
  635. switch (o) {
  636. case Te.NORMAL:
  637. break;
  638. case Te.ROW:
  639. R.startColumn = 0, R.endColumn = this._skeleton.getColumnCount() - 1;
  640. break;
  641. case Te.COLUMN:
  642. R.startRow = 0, R.endRow = this._skeleton.getRowCount() - 1;
  643. break;
  644. case Te.ALL:
  645. R.startRow = 0, R.startColumn = 0, R.endRow = this._skeleton.getRowCount() - 1, R.endColumn = this._skeleton.getColumnCount() - 1;
  646. }
  647. const C = { range: R, primary: R, style: null };
  648. C.range.rangeType = o;
  649. const _ = on(C, this._skeleton);
  650. this._startRangeWhenPointerDown = { ..._.rangeWithCoord };
  651. const E = { ..._.rangeWithCoord, rangeType: o };
  652. let x = this.getActiveSelectionControl();
  653. const M = this.getSelectionControls();
  654. for (const b of M) {
  655. if (t.button === 2 && b.model.isInclude(E)) {
  656. x = b;
  657. return;
  658. }
  659. if (b.model.isEqual(E)) {
  660. x = b;
  661. break;
  662. }
  663. }
  664. this._checkClearPreviousControls(t);
  665. const T = x == null ? void 0 : x.model.currentCell, P = t.shiftKey && T, A = this._remainLastEnabled && !t.ctrlKey && !t.shiftKey && !this._skipLastEnabled && !this._singleSelectionEnabled;
  666. P && T ? this._makeSelectionByTwoCells(
  667. T,
  668. E,
  669. s,
  670. o,
  671. x
  672. // Get updated in this method
  673. ) : A && x ? x.updateRangeBySelectionWithCoord(_) : x = this.newSelectionControl(c, s, C);
  674. for (let b = 0; b < this.getSelectionControls().length - 1; b++)
  675. this.getSelectionControls()[b].clearHighlight();
  676. this._selectionMoveStart$.next(this.getSelectionDataWithStyle()), c.disableObjectsEvent(), this._clearUpdatingListeners(), this._addEndingListeners(), (N = c.getTransformer()) == null || N.clearSelectedObjects(), this._setupPointerMoveListener(u, x, o, i, f, g), this._escapeShortcutDisposable = this._shortcutService.forceEscape(), this._scenePointerUpSub = c.onPointerUp$.subscribeEvent(() => {
  677. var b;
  678. this._clearUpdatingListeners(), this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()), (b = this._escapeShortcutDisposable) == null || b.dispose(), this._escapeShortcutDisposable = null;
  679. });
  680. }
  681. /**
  682. * Diff between normal selection, no highlightHeader for ref selections.
  683. * @param scene
  684. * @param skeleton
  685. * @param selectionWithCoord
  686. * @returns {SelectionControl} selectionControl just created
  687. */
  688. newSelectionControl(t, n, o) {
  689. const r = this.getSelectionControls().length, { rowHeaderWidth: i, columnHeaderHeight: s } = n, c = new ur(t, r, this._themeService, {
  690. highlightHeader: this._highlightHeader,
  691. enableAutoFill: !1,
  692. rowHeaderWidth: i,
  693. columnHeaderHeight: s
  694. }), a = on(o, n);
  695. return c.updateRangeBySelectionWithCoord(a), this._selectionControls.push(c), c.setControlExtension({
  696. skeleton: n,
  697. scene: t,
  698. themeService: this._themeService,
  699. injector: this._injector,
  700. selectionHooks: {
  701. selectionMoveEnd: () => {
  702. this._selectionMoveEnd$.next(this.getSelectionDataWithStyle());
  703. }
  704. }
  705. }), c;
  706. }
  707. };
  708. Fe = ri([
  709. tt(1, ee(_t)),
  710. tt(2, ee(Rt)),
  711. tt(3, Vt),
  712. tt(4, ee(kt)),
  713. tt(5, hn),
  714. tt(6, Wt)
  715. ], Fe);
  716. function oi(e) {
  717. const t = lr(e);
  718. return t.widgets = { tl: !0, tc: !0, tr: !0, ml: !0, mr: !0, bl: !0, bc: !0, br: !0 }, t;
  719. }
  720. const si = (e, t, n) => {
  721. const r = y(ve).getRenderById(e), i = r == null ? void 0 : r.with(Fe);
  722. D(() => {
  723. if (n && i) {
  724. const s = n.input$.subscribe((c) => {
  725. c.content === ge.COMMA ? i.setSkipLastEnabled(!0) : i.setSkipLastEnabled(!1);
  726. });
  727. return () => {
  728. s.unsubscribe();
  729. };
  730. }
  731. }, [n, i]), D(() => {
  732. i && (t.endsWith(ge.COMMA) || i.setSkipLastEnabled(!1));
  733. }, [t, i]);
  734. }, qt = () => {
  735. const e = y(Be);
  736. return at((n) => e.sequenceNodesBuilder(n) || [], [e]);
  737. }, ii = (e, t, n, o, r, i) => {
  738. const s = qt(), c = q(!0);
  739. D(() => {
  740. var a, d;
  741. if (i) {
  742. if (c.current) {
  743. const u = s(e);
  744. if (u.length) {
  745. const h = o(i, u);
  746. n && r(h);
  747. } else {
  748. const h = i.getDocumentData(), g = { dataStream: (d = (a = h.body) == null ? void 0 : a.dataStream) != null ? d : `${t}\r
  749. `, ...h.body };
  750. i.setDocumentData({ ...h, body: g });
  751. }
  752. c.current = !1;
  753. } else if (n) {
  754. const u = s(e), h = o(i, u);
  755. r(h);
  756. }
  757. }
  758. }, [i, n]);
  759. }, Hr = (e) => Ee((n) => {
  760. var o, r;
  761. if (e) {
  762. e.focus();
  763. const i = [...e.getSelectionRanges()];
  764. if (vt.isDefine(n))
  765. e.setSelectionRanges([{ startOffset: n, endOffset: n }]);
  766. else if (!i.length && !e.docSelectionRenderService.isOnPointerEvent) {
  767. const s = (r = (o = e.getDocumentData().body) == null ? void 0 : o.dataStream) != null ? r : `\r
  768. `, c = Math.max(s.length - 2, 0);
  769. e.setSelectionRanges([{ startOffset: c, endOffset: c }]);
  770. }
  771. }
  772. });
  773. function ci(e, t, n) {
  774. const o = e.getCurrentTheme(), r = new or(t).setAlpha(0.05).toRgbString();
  775. return {
  776. id: n,
  777. strokeWidth: 1,
  778. stroke: t,
  779. fill: r,
  780. widgets: { tl: !0, tc: !0, tr: !0, ml: !0, mr: !0, bl: !0, bc: !0, br: !0 },
  781. widgetSize: 6,
  782. widgetStrokeWidth: 1,
  783. widgetStroke: o.colorWhite
  784. };
  785. }
  786. function Wr(e) {
  787. var R, C, _;
  788. const {
  789. unitId: t,
  790. subUnitId: n,
  791. refSelections: o,
  792. editor: r,
  793. refSelectionsService: i,
  794. refSelectionsRenderService: s,
  795. sheetSkeletonManagerService: c,
  796. themeService: a,
  797. univerInstanceService: d
  798. } = e, u = d.getUnit(t, Me.UNIVER_SHEET), h = u == null ? void 0 : u.getActiveSheet(), f = [];
  799. if (!u || !h) {
  800. i.setSelections(f);
  801. return;
  802. }
  803. const g = h.getSheetId(), l = (E) => {
  804. var x;
  805. return (x = u == null ? void 0 : u.getSheetBySheetName(E)) == null ? void 0 : x.getSheetId();
  806. };
  807. if (!((R = c == null ? void 0 : c.getWorksheetSkeleton(g)) == null ? void 0 : R.skeleton)) return;
  808. const S = [];
  809. for (let E = 0, x = o.length; E < x; E++) {
  810. const M = o[E], { themeColor: T, token: P, refIndex: A, endIndex: N } = M, b = we(P), { unitId: w, sheetName: I, range: v } = b;
  811. if (w && t !== w)
  812. continue;
  813. const F = l(I);
  814. if (F && F !== g || !F && g !== n)
  815. continue;
  816. const O = ss(v, h.getRowCount(), h.getColumnCount());
  817. f.push({
  818. range: O,
  819. primary: null,
  820. style: ci(a, T, A.toString())
  821. }), S.push(N);
  822. }
  823. if (r) {
  824. const E = (_ = (C = r.getSelectionRanges()) == null ? void 0 : C[0]) == null ? void 0 : _.startOffset, x = S.findIndex((M) => M + 2 === E);
  825. x !== -1 ? s == null || s.setActiveSelectionIndex(x) : s == null || s.resetActiveSelectionIndex();
  826. }
  827. return f;
  828. }
  829. function Rn(e, t) {
  830. const n = y(pe), o = y(Rt), r = y(Wt), s = y(ve).getRenderById(e), c = s == null ? void 0 : s.with(Fe), a = s == null ? void 0 : s.with(kt), d = at((u, h) => {
  831. const f = Wr({
  832. unitId: e,
  833. subUnitId: t,
  834. refSelections: u,
  835. editor: h,
  836. refSelectionsService: r,
  837. refSelectionsRenderService: c,
  838. sheetSkeletonManagerService: a,
  839. themeService: o,
  840. univerInstanceService: n
  841. });
  842. if (!f) return;
  843. ((c == null ? void 0 : c.getSelectionControls()) || []).length === f.length ? c == null || c.resetSelectionsByModelData(f) : r.setSelections(f);
  844. }, [c, r, a, o, e, t, n]);
  845. return D(() => () => {
  846. c == null || c.resetActiveSelectionIndex();
  847. }, [c]), d;
  848. }
  849. function Ur(e = "") {
  850. const t = y(xt), n = Vr(), o = y(ye), r = Z(() => e.length, [e]);
  851. return at((s, c, a = !0, d) => {
  852. const u = s.getDocumentData(), h = s.getEditorId();
  853. if (!u)
  854. return [];
  855. const f = u.body;
  856. if (!f)
  857. return [];
  858. const g = f.dataStream.slice(0, f.dataStream.length - 2), l = { dataStream: "", ...u.body };
  859. if (!g.startsWith(e)) return [];
  860. if (c == null || c.length === 0)
  861. return l.textRuns = [], o.syncExecuteCommand(kn.id, {
  862. unitId: h,
  863. body: yn(l, 0, l.dataStream.length - 2)
  864. }), [];
  865. {
  866. const { textRuns: m, refSelections: S } = Br(t, n, c);
  867. r && m.forEach((_) => {
  868. _.ed = _.ed + r, _.st = _.st + r;
  869. }), l.textRuns = [{ st: 0, ed: 1, ts: { fs: 11 } }, ...m];
  870. const R = c.reduce((_, E) => typeof E == "string" ? `${_}${E}` : `${_}${E.token}`, "");
  871. l.dataStream = `${e}${R}\r
  872. `;
  873. let C;
  874. if (a) {
  875. C = s.getSelectionRanges();
  876. const _ = l.dataStream.length - 2 + r;
  877. C.forEach((E) => {
  878. E.startOffset = Math.max(0, Math.min(E.startOffset, _)), E.endOffset = Math.max(0, Math.min(E.endOffset, _));
  879. });
  880. }
  881. return o.syncExecuteCommand(kn.id, {
  882. unitId: h,
  883. body: yn(l, 0, l.dataStream.length - 2),
  884. textRanges: d != null ? d : C
  885. }), S;
  886. }
  887. }, [o, t, n, r, e]);
  888. }
  889. function Vr() {
  890. const t = y(Rt).getCurrentTheme();
  891. return Z(() => {
  892. const o = [
  893. t.loopColor1,
  894. t.loopColor2,
  895. t.loopColor3,
  896. t.loopColor4,
  897. t.loopColor5,
  898. t.loopColor6,
  899. t.loopColor7,
  900. t.loopColor8,
  901. t.loopColor9,
  902. t.loopColor10,
  903. t.loopColor11,
  904. t.loopColor12
  905. ], r = t.hyacinth700, i = t.verdancy800, s = t.colorBlack;
  906. return { formulaRefColors: o, numberColor: r, stringColor: i, plainTextColor: s };
  907. }, [t]);
  908. }
  909. function Br(e, t, n) {
  910. const { formulaRefColors: o, numberColor: r, stringColor: i, plainTextColor: s } = t, c = [], a = [], d = /* @__PURE__ */ new Map();
  911. let u = 0;
  912. for (let h = 0, f = n.length; h < f; h++) {
  913. const g = n[h];
  914. if (typeof g == "string") {
  915. const _ = c[c.length - 1], E = _ ? _.ed : 0, x = E + g.length;
  916. c.push({
  917. st: E,
  918. ed: x,
  919. ts: {
  920. cl: {
  921. rgb: s
  922. },
  923. fs: 11
  924. }
  925. });
  926. continue;
  927. }
  928. if (e.hasDefinedNameDescription(g.token.trim())) {
  929. c.push({
  930. st: g.startIndex,
  931. ed: g.endIndex + 1,
  932. ts: {
  933. cl: {
  934. rgb: s
  935. },
  936. fs: 11
  937. }
  938. });
  939. continue;
  940. }
  941. const { startIndex: l, endIndex: m, nodeType: S, token: R } = g;
  942. let C = "";
  943. if (S === G.REFERENCE) {
  944. if (d.has(R))
  945. C = d.get(R);
  946. else {
  947. const _ = u % o.length;
  948. C = o[_], d.set(R, C), u++;
  949. }
  950. a.push({
  951. refIndex: h,
  952. themeColor: C,
  953. token: R,
  954. startIndex: g.startIndex,
  955. endIndex: g.endIndex,
  956. index: a.length
  957. });
  958. } else S === G.NUMBER ? C = r : (S === G.STRING || S === G.ARRAY) && (C = i);
  959. C && C.length > 0 ? c.push({
  960. st: l,
  961. ed: m + 1,
  962. ts: {
  963. cl: {
  964. rgb: C
  965. },
  966. fs: 11
  967. }
  968. }) : c.push({
  969. st: l,
  970. ed: m + 1,
  971. ts: {
  972. cl: {
  973. rgb: s
  974. },
  975. fs: 11
  976. }
  977. });
  978. }
  979. return { textRuns: c, refSelections: a };
  980. }
  981. function ai(e) {
  982. var r, i;
  983. const n = e.get(pe).getCurrentUniverDocInstance();
  984. return n != null && n.getBody() ? { dataStream: (i = (r = n.getBody()) == null ? void 0 : r.dataStream) != null ? i : "", offset: 0 } : void 0;
  985. }
  986. var Mt = /* @__PURE__ */ ((e) => (e[e.NOT_SELECT = 0] = "NOT_SELECT", e[e.NEED_ADD = 1] = "NEED_ADD", e[e.CAN_EDIT = 2] = "CAN_EDIT", e))(Mt || {});
  987. function li(e, t, n) {
  988. var g;
  989. const r = y(ve).getRenderById(e), i = r == null ? void 0 : r.with(mr), s = y(Tr), c = y(_t), [a, d] = H(
  990. 0
  991. /* NOT_SELECT */
  992. ), u = y(Be), h = q(!0), f = q(a);
  993. return f.current = a, D(() => {
  994. const l = s.textSelection$.pipe(
  995. sn((m) => m.unitId === e),
  996. Ht(() => {
  997. const m = i == null ? void 0 : i.getActiveTextRange();
  998. return m != null && m.collapsed ? m.startOffset : -1;
  999. })
  1000. ).subscribe((m) => {
  1001. var P, A;
  1002. const S = ai(c);
  1003. if (!S) return;
  1004. const R = (P = S == null ? void 0 : S.dataStream) == null ? void 0 : P.slice(0, -2), C = (A = u.sequenceNodesBuilder(R)) != null ? A : [], _ = R[m - 1], E = R[m], x = C.findIndex((N) => typeof N == "object" && N.nodeType === G.REFERENCE && m === N.endIndex + 2), M = _ && Uo(_) && (!E || Vo(E) && E !== ge.OPEN_BRACKET), T = x > -1;
  1005. if ((R == null ? void 0 : R.substring(0, 1)) === "=" && (M || T))
  1006. if (T) {
  1007. if (h.current)
  1008. return;
  1009. d(
  1010. 2
  1011. /* CAN_EDIT */
  1012. );
  1013. } else
  1014. h.current = !1, d(
  1015. 1
  1016. /* NEED_ADD */
  1017. );
  1018. else
  1019. d(
  1020. 0
  1021. /* NOT_SELECT */
  1022. );
  1023. });
  1024. return () => l.unsubscribe();
  1025. }, [s.textSelection$, i, e, c, u]), D(() => {
  1026. t || (d(
  1027. 0
  1028. /* NOT_SELECT */
  1029. ), h.current = !0);
  1030. }, [t]), D(() => {
  1031. var m;
  1032. if (!n) return;
  1033. const l = (m = r == null ? void 0 : r.mainComponent) == null ? void 0 : m.onPointerDown$.subscribeEvent(() => {
  1034. d(
  1035. 0
  1036. /* NOT_SELECT */
  1037. ), h.current = !0;
  1038. });
  1039. return () => l == null ? void 0 : l.unsubscribe();
  1040. }, [n, (g = r == null ? void 0 : r.mainComponent) == null ? void 0 : g.onPointerDown$]), { isSelecting: a };
  1041. }
  1042. const qr = (e, t, n, o) => {
  1043. const r = y(ye), i = y(Vt), s = q(t);
  1044. s.current = t;
  1045. const c = q(o);
  1046. c.current = o, D(() => {
  1047. if (!n || !e)
  1048. return;
  1049. const d = `sheet.formula-embedding-editor.${n.getEditorId()}`, u = new st(), h = (l, m) => {
  1050. if (c.current) {
  1051. c.current(l, m);
  1052. return;
  1053. }
  1054. let S = he.LEFT;
  1055. l === $.ARROW_DOWN ? S = he.DOWN : l === $.ARROW_UP ? S = he.UP : l === $.ARROW_RIGHT && (S = he.RIGHT), m === Y.SHIFT ? r.executeCommand(es.id, {
  1056. direction: S
  1057. }) : r.executeCommand(ts.id, {
  1058. direction: S
  1059. });
  1060. }, f = (l, m) => {
  1061. let S = he.DOWN;
  1062. l === $.ARROW_DOWN ? S = he.DOWN : l === $.ARROW_UP ? S = he.UP : l === $.ARROW_LEFT ? S = he.LEFT : l === $.ARROW_RIGHT && (S = he.RIGHT), s.current ? m === Y.CTRL_COMMAND ? r.executeCommand(Pn.id, {
  1063. direction: S,
  1064. jumpOver: An.moveGap,
  1065. extra: "formula-editor",
  1066. fromCurrentSelection: s.current === Mt.NEED_ADD
  1067. }) : m === Y.SHIFT ? r.executeCommand(Ln.id, {
  1068. direction: S,
  1069. extra: "formula-editor"
  1070. }) : m === (Y.CTRL_COMMAND | Y.SHIFT) ? r.executeCommand(Ln.id, {
  1071. direction: S,
  1072. jumpOver: An.moveGap,
  1073. extra: "formula-editor"
  1074. }) : r.executeCommand(Pn.id, {
  1075. direction: S,
  1076. extra: "formula-editor",
  1077. fromCurrentSelection: s.current === Mt.NEED_ADD
  1078. }) : h(l, m);
  1079. };
  1080. return u.add(r.registerCommand({
  1081. id: d,
  1082. type: $e.OPERATION,
  1083. handler(l, m) {
  1084. const { keyCode: S, metaKey: R } = m;
  1085. f(S, R);
  1086. }
  1087. })), [
  1088. { keyCode: $.ARROW_DOWN },
  1089. { keyCode: $.ARROW_LEFT },
  1090. { keyCode: $.ARROW_RIGHT },
  1091. { keyCode: $.ARROW_UP },
  1092. { keyCode: $.ARROW_DOWN, metaKey: Y.SHIFT },
  1093. { keyCode: $.ARROW_LEFT, metaKey: Y.SHIFT },
  1094. { keyCode: $.ARROW_RIGHT, metaKey: Y.SHIFT },
  1095. { keyCode: $.ARROW_UP, metaKey: Y.SHIFT },
  1096. { keyCode: $.ARROW_DOWN, metaKey: Y.CTRL_COMMAND },
  1097. { keyCode: $.ARROW_LEFT, metaKey: Y.CTRL_COMMAND },
  1098. { keyCode: $.ARROW_RIGHT, metaKey: Y.CTRL_COMMAND },
  1099. { keyCode: $.ARROW_UP, metaKey: Y.CTRL_COMMAND },
  1100. { keyCode: $.ARROW_DOWN, metaKey: Y.CTRL_COMMAND | Y.SHIFT },
  1101. { keyCode: $.ARROW_LEFT, metaKey: Y.CTRL_COMMAND | Y.SHIFT },
  1102. { keyCode: $.ARROW_RIGHT, metaKey: Y.CTRL_COMMAND | Y.SHIFT },
  1103. { keyCode: $.ARROW_UP, metaKey: Y.CTRL_COMMAND | Y.SHIFT }
  1104. ].map(({ keyCode: l, metaKey: m }) => ({
  1105. id: d,
  1106. binding: m ? l | m : l,
  1107. preconditions: () => !0,
  1108. priority: 900,
  1109. staticParameters: {
  1110. eventType: De.Keyboard,
  1111. keyCode: l,
  1112. metaKey: m
  1113. }
  1114. })).forEach((l) => {
  1115. u.add(i.registerShortcut(l));
  1116. }), () => {
  1117. u.dispose();
  1118. };
  1119. }, [r, n, e, i]);
  1120. }, Kr = (e, t) => {
  1121. const o = y(ve).getRenderById(e), r = o == null ? void 0 : o.with(Fe);
  1122. D(() => {
  1123. r && (t ? r == null || r.setRemainLastEnabled(!1) : r == null || r.setRemainLastEnabled(!0));
  1124. }, [t, r]);
  1125. }, In = (e, t, n, o = !0) => {
  1126. const r = y(ve), i = y(hn), s = y(ds), c = y(Wt), a = r.getRenderById(n), d = a == null ? void 0 : a.with(Fe);
  1127. lt(() => {
  1128. if (e)
  1129. return i.setContextValue(Ft, !0), () => {
  1130. i.setContextValue(Ft, !1), c.clear();
  1131. };
  1132. }, [i, e, c]), lt(() => {
  1133. if (e && t) {
  1134. const u = d == null ? void 0 : d.enableSelectionChanging();
  1135. return i.setContextValue(Wn, !0), () => {
  1136. i.setContextValue(Wn, !1), u == null || u.dispose();
  1137. };
  1138. }
  1139. }, [i, e, d, t]), D(() => {
  1140. if (e)
  1141. return i.setContextValue(Ft, !0), o && s.disable(), () => {
  1142. i.setContextValue(Ft, !1), o && s.enable();
  1143. };
  1144. }, [s, i, e, o]), D(() => {
  1145. e && (d == null || d.setSkipLastEnabled(!1));
  1146. }, [e, d]);
  1147. }, ui = () => {
  1148. D(() => () => {
  1149. }, []);
  1150. }, Yr = (e, t, n) => {
  1151. const o = y(pe), r = y(Sr);
  1152. return at(() => {
  1153. if (e) {
  1154. const s = [...r.getWorkbookSelections(t).getSelectionsOfWorksheet(n)], c = o.getCurrentUnitForType(Me.UNIVER_SHEET), a = c == null ? void 0 : c.getActiveSheet();
  1155. a && a.getSheetId() === n && r.setSelections(s);
  1156. }
  1157. }, [e, r, n, t, o]);
  1158. }, un = (e) => typeof e == "string" ? e === ge.COMMA : !1, fi = (e) => {
  1159. if (typeof e == "object")
  1160. return e.nodeType === G.REFERENCE;
  1161. }, hi = (e) => e.filter((t) => un(t) || fi(t)), En = (e) => {
  1162. if (e.endColumn < e.startColumn) {
  1163. const t = e.endColumn;
  1164. e.endColumn = e.startColumn, e.startColumn = t;
  1165. }
  1166. if (e.endRow < e.startRow) {
  1167. const t = e.endRow;
  1168. e.endRow = e.startRow, e.startRow = t;
  1169. }
  1170. return e;
  1171. }, Oe = (e) => e.map((t) => typeof t == "string" ? t : t.token).join("");
  1172. function Zn(e, t, n) {
  1173. var o, r;
  1174. return ((r = (o = e.getUnit(t)) == null ? void 0 : o.getSheetBySheetId(n)) == null ? void 0 : r.getName()) || "";
  1175. }
  1176. const Ne = (e, t = !1, n = "") => t ? e.map((o) => o.sheetName !== "" && o.sheetName !== n ? Tt(o.sheetName, o.range) : Ve(o.range)) : e.map((o) => Ve(o.range)), zr = (e, t, n, o, r, i, s) => {
  1177. const c = y(ve), a = y(pe), d = q(!1), u = c.getRenderById(t), h = u == null ? void 0 : u.with(Fe), f = q([]), g = Z(() => {
  1178. const m = hi(o), S = f.current;
  1179. return m.length === S.length ? (S.splice(0), S.push(...m), S) : m;
  1180. }, [o]);
  1181. f.current = g;
  1182. const l = q();
  1183. D(() => {
  1184. if (e && h) {
  1185. let m = !0;
  1186. const S = (_, E) => {
  1187. var I;
  1188. if (m || d.current) {
  1189. m = !1;
  1190. return;
  1191. }
  1192. const x = [..._], M = a.getUnit(t), T = ((I = M == null ? void 0 : M.getActiveSheet()) == null ? void 0 : I.getName()) || "", P = g.map((v, F) => {
  1193. if (typeof v == "string") {
  1194. if (!g[F - 1])
  1195. return null;
  1196. const L = g[F + 1];
  1197. return un(v) && (un(L) || F === g.length - 1) ? null : v;
  1198. } else if (v.nodeType === G.REFERENCE) {
  1199. const O = we(v.token);
  1200. O.unitId = O.unitId === "" ? t : O.unitId, O.sheetName = O.sheetName === "" ? T : O.sheetName;
  1201. const { unitId: L, sheetName: B } = O;
  1202. if (i && (L !== t || T !== B))
  1203. return null;
  1204. if (L === t && T === B) {
  1205. const K = x.shift();
  1206. if (K && Zn(a, t, K.rangeWithCoord.sheetId || "") === B) {
  1207. const V = { ...v };
  1208. return En(K.rangeWithCoord), r ? V.token = Tt(T, K.rangeWithCoord) : V.token = Ve(K.rangeWithCoord), V;
  1209. }
  1210. }
  1211. return v;
  1212. }
  1213. return null;
  1214. }).filter((v) => !!v), A = Ne(
  1215. x.map((v) => {
  1216. var F, O, L;
  1217. return {
  1218. range: v.rangeWithCoord,
  1219. unitId: (F = v.rangeWithCoord.unitId) != null ? F : "",
  1220. sheetName: Zn(a, (O = v.rangeWithCoord.unitId) != null ? O : "", (L = v.rangeWithCoord.sheetId) != null ? L : "")
  1221. };
  1222. }),
  1223. r
  1224. ).join(ge.COMMA), N = Oe(P), b = `${N}${N && A ? ge.COMMA : ""}${A}`, w = d.current;
  1225. s(b, w ? -1 : b.length, E);
  1226. }, R = h.selectionMoveEnd$.subscribe((_) => {
  1227. if (S(_, !0), d.current = !1, l.current) {
  1228. const { result: E, offset: x } = l.current;
  1229. s(E, x, !0), l.current = void 0;
  1230. }
  1231. }), C = h.selectionMoving$.pipe(ys(50)).subscribe((_) => {
  1232. S(_, !1);
  1233. });
  1234. return () => {
  1235. R.unsubscribe(), C.unsubscribe();
  1236. };
  1237. }
  1238. }, [e, g, h, r, i, s, a, t]), D(() => {
  1239. if (e && h) {
  1240. const m = new st(), S = (_, E) => {
  1241. var w;
  1242. let x = 0, M = 0, T = !1;
  1243. const P = a.getUnit(t), A = ((w = P == null ? void 0 : P.getActiveSheet()) == null ? void 0 : w.getName()) || "", N = g.map((I) => {
  1244. if (typeof I == "string")
  1245. return T || (M += I.length), I;
  1246. if (I.nodeType === G.REFERENCE) {
  1247. const v = we(_);
  1248. if (v.unitId = v.unitId === "" ? t : v.unitId, v.sheetName = v.sheetName === "" ? A : v.sheetName, x === E) {
  1249. T = !0;
  1250. const F = { ...I, token: _ };
  1251. return r ? F.token = Tt(v.sheetName, v.range) : F.token = Ve(v.range), x++, M += F.token.length, F;
  1252. }
  1253. return x++, T || (M += I.token.length), I;
  1254. }
  1255. return I;
  1256. }), b = Oe(N);
  1257. l.current = { result: b, offset: M }, s(b, -1, !1);
  1258. };
  1259. let R = 0;
  1260. const C = h.selectionMoveEnd$.subscribe(() => {
  1261. R = setTimeout(() => {
  1262. m.dispose(), h.getSelectionControls().forEach((E, x) => {
  1263. m.add(cn(E.selectionMoving$, E.selectionScaling$).pipe(
  1264. Ht((M) => Ve(M)),
  1265. dr()
  1266. ).subscribe((M) => {
  1267. d.current = !0, S(M, x);
  1268. }));
  1269. });
  1270. }, 30);
  1271. });
  1272. return () => {
  1273. C.unsubscribe(), m.dispose(), clearTimeout(R);
  1274. };
  1275. }
  1276. }, [e, h, g, s, a, t, r]);
  1277. }, bn = (e, t, n, o, r, i) => {
  1278. const s = y(ye), c = y(qe), d = y(ve).getRenderById(t), u = d == null ? void 0 : d.with(Fe);
  1279. D(() => {
  1280. if (e && u)
  1281. if (n) {
  1282. const h = s.onCommandExecuted((f) => {
  1283. if (f.id === Un.id) {
  1284. const g = u.getSelectionControls().length;
  1285. for (let l = 1; l <= g; l++)
  1286. u.clearLastSelection();
  1287. setTimeout(() => {
  1288. i();
  1289. }, 30);
  1290. }
  1291. });
  1292. return () => {
  1293. h.dispose();
  1294. };
  1295. } else {
  1296. const h = s.beforeCommandExecuted((f) => {
  1297. if (f.id === Un.id) {
  1298. o(!1), r(), i();
  1299. const g = c.getEditor(dn);
  1300. g == null || g.focus();
  1301. }
  1302. });
  1303. return () => {
  1304. h.dispose();
  1305. };
  1306. }
  1307. }, [e, u]);
  1308. }, Zr = (e) => !e.some((n) => {
  1309. if (typeof n == "string") {
  1310. if (n !== ge.COMMA)
  1311. return !0;
  1312. } else if (n.nodeType !== G.REFERENCE)
  1313. return !0;
  1314. return !1;
  1315. }), di = (e, t, n) => {
  1316. const o = q(!0);
  1317. D(() => {
  1318. if (e) {
  1319. const r = setTimeout(() => {
  1320. o.current = !1;
  1321. }, 500);
  1322. return () => {
  1323. clearTimeout(r);
  1324. };
  1325. }
  1326. }, [e]), D(() => {
  1327. if (!o.current && t) {
  1328. const r = Zr(n);
  1329. t(r, Oe(n));
  1330. }
  1331. }, [n, t]);
  1332. }, mi = "univer-sheet-range-selector-text-wrap", gi = "univer-sheet-range-selector-placeholder", pi = "univer-sheet-range-selector-error", Si = "univer-sheet-range-selector-error-wrap", vi = "univer-sheet-range-selector-text", Ci = "univer-sheet-range-selector-active", _i = "univer-sheet-range-selector-icon", Ri = "univer-sheet-range-selector-dialog-item", Ii = "univer-sheet-range-selector-dialog-item-delete", xe = {
  1333. sheetRangeSelectorTextWrap: mi,
  1334. sheetRangeSelectorPlaceholder: gi,
  1335. sheetRangeSelectorError: pi,
  1336. sheetRangeSelectorErrorWrap: Si,
  1337. sheetRangeSelectorText: vi,
  1338. sheetRangeSelectorActive: Ci,
  1339. sheetRangeSelectorIcon: _i,
  1340. sheetRangeSelectorDialogItem: Ri,
  1341. sheetRangeSelectorDialogItemDelete: Ii
  1342. }, dt = () => {
  1343. };
  1344. function Ei(e) {
  1345. const {
  1346. initValue: t,
  1347. unitId: n,
  1348. subUnitId: o,
  1349. errorText: r,
  1350. placeholder: i,
  1351. actions: s,
  1352. onChange: c = dt,
  1353. onVerify: a = dt,
  1354. onRangeSelectorDialogVisibleChange: d = dt,
  1355. onBlur: u = dt,
  1356. onFocus: h = dt,
  1357. isFocus: f = !0,
  1358. isOnlyOneRange: g = !1,
  1359. isSupportAcrossSheet: l = !1
  1360. } = e, m = Ee(c), S = y(qe), R = y(Xe), C = y(ye), _ = y(Be), E = q(null), [x, M] = H(!1), [T, P] = H(f), A = Z(() => sr(`${No}-${ir(4)}`), []), N = q(), b = N.current, w = q(null), I = y(pe), v = Z(() => !x && T, [x, T]), [F, O] = H(() => typeof t == "string" ? t : Ne(t, l).join(ge.COMMA)), L = Z(() => I.getCurrentTypeOfUnit$(Me.UNIVER_DOC), [I]), B = it(L), K = (B == null ? void 0 : B.getUnitId()) === A, V = q([]), U = Ee((j, k) => {
  1361. E.current && !x && !E.current.contains(j.target) && k();
  1362. });
  1363. s && (s.handleOutClick = U);
  1364. const ne = Z(() => F.split(ge.COMMA).filter((j) => !!j).map((j) => we(j)), [F]), ie = Z(() => r !== void 0, [r]), te = Yr(!x && T, n, o);
  1365. Z(() => (j) => {
  1366. const k = _.sequenceNodesBuilder(j);
  1367. if (k) {
  1368. if (Zr(k)) {
  1369. const X = k.map((oe) => {
  1370. if (typeof oe == "string")
  1371. return oe;
  1372. if (oe.nodeType === G.REFERENCE) {
  1373. const Je = { ...oe }, Pe = we(oe.token);
  1374. return Pe.range = En(Pe.range), l || (Pe.sheetName = "", Pe.unitId = ""), Je.token = Ne([Pe], l)[0], Je;
  1375. }
  1376. return oe;
  1377. }), J = Oe(X);
  1378. m(J);
  1379. }
  1380. } else
  1381. O("");
  1382. }, [l]);
  1383. const W = Hr(b), { checkScrollBar: Ce } = gr(b, !0, !0), de = qt(), fe = Z(() => de(F), [F]), re = Ur(), be = Rn(n, o), ce = Ee((j, k = !0, z = !0) => {
  1384. if (!N.current)
  1385. return;
  1386. const X = de(j), J = re(N.current, X, k);
  1387. V.current = J, z && be(J, N.current);
  1388. });
  1389. D(() => {
  1390. const j = C.onCommandExecuted((k) => {
  1391. var z, X;
  1392. if (k.id === Fs.id) {
  1393. const J = k.params, { unitId: oe } = J;
  1394. oe === A && m(cr.transform.getPlainText((X = (z = b == null ? void 0 : b.getDocumentData().body) == null ? void 0 : z.dataStream) != null ? X : ""));
  1395. }
  1396. });
  1397. return () => j.dispose();
  1398. }, [C, b, A, m]);
  1399. const _e = Ee((j, k, z) => {
  1400. ce(j), O(j), z && (W(), k !== -1 && setTimeout(() => {
  1401. const X = { startOffset: k, endOffset: k };
  1402. b == null || b.setSelectionRanges([X]);
  1403. const J = b == null ? void 0 : b.render.with(pr);
  1404. J == null || J.scrollToRange({ ...X, collapsed: !0 });
  1405. }, 50), Ce());
  1406. });
  1407. zr(v, n, o, fe, l, g, _e), In(v, v && K, n), Kr(n, g), si(n, F, b), di(v, a, fe), qr(v, 0, b), ui(), bn(v, n, l, P, u, () => {
  1408. v && ce(F);
  1409. }), D(() => {
  1410. if (b) {
  1411. const j = b.input$.pipe(mn(100)).subscribe((k) => {
  1412. var X, J;
  1413. const z = ((J = (X = k.data.body) == null ? void 0 : X.dataStream) != null ? J : "").replaceAll(/\n|\r/g, "").replaceAll(/,{2,}/g, ",").replaceAll(/(^,)/g, "");
  1414. ce(z, !1), O(z);
  1415. });
  1416. return () => {
  1417. j.unsubscribe();
  1418. };
  1419. }
  1420. }, [b]), D(() => {
  1421. const j = C.onCommandExecuted((k) => {
  1422. k.id === Fo.id && (M(!1), d(!1), P(!1), u());
  1423. });
  1424. return () => {
  1425. j.dispose();
  1426. };
  1427. }, [l]), lt(() => {
  1428. let j;
  1429. if (w.current) {
  1430. j = S.register({
  1431. autofocus: !0,
  1432. editorUnitId: A,
  1433. initialSnapshot: {
  1434. id: A,
  1435. body: { dataStream: `${F}\r
  1436. `, textRuns: [] },
  1437. documentStyle: {}
  1438. }
  1439. }, w.current);
  1440. const k = S.getEditor(A);
  1441. N.current = k, ce(F, !1, !1);
  1442. }
  1443. return () => {
  1444. j == null || j.dispose();
  1445. };
  1446. }, []), lt(() => {
  1447. f ? (P(f), W()) : (b == null || b.blur(), te(), P(f));
  1448. }, [f, W]), ii(F, "", T, re, be, b);
  1449. const me = () => {
  1450. h(), W(), P(!0);
  1451. }, Re = (j) => {
  1452. const k = Ne(j, l).join(ge.COMMA);
  1453. k || b == null || b.setDocumentData({ ...b.getDocumentData(), body: { dataStream: `\r
  1454. `, textRuns: [] } }), ce(k), O(k), M(!1), d(!1), setTimeout(() => {
  1455. P(!0), b == null || b.setSelectionRanges([{ startOffset: k.length, endOffset: k.length }]), W(), Ce();
  1456. }, 30);
  1457. }, je = () => {
  1458. M(!1), d(!1), setTimeout(() => {
  1459. P(!0), W();
  1460. }, 30);
  1461. }, He = () => {
  1462. ie || (W(), setTimeout(() => {
  1463. M(!0), d(!0), P(!1);
  1464. }, 30));
  1465. };
  1466. return /* @__PURE__ */ p.jsxs("div", { className: xe.sheetRangeSelector, ref: E, children: [
  1467. /* @__PURE__ */ p.jsxs(
  1468. "div",
  1469. {
  1470. className: ln(xe.sheetRangeSelectorTextWrap, {
  1471. [xe.sheetRangeSelectorActive]: T && !ie,
  1472. [xe.sheetRangeSelectorError]: ie
  1473. }),
  1474. children: [
  1475. /* @__PURE__ */ p.jsx("div", { className: xe.sheetRangeSelectorText, ref: w, onMouseUp: me }),
  1476. /* @__PURE__ */ p.jsx(bs, { title: R.t("rangeSelector.buttonTooltip"), placement: "bottom", children: /* @__PURE__ */ p.jsx(kr, { className: xe.sheetRangeSelectorIcon, onClick: He }) }),
  1477. r !== void 0 ? /* @__PURE__ */ p.jsx("div", { className: xe.sheetRangeSelectorErrorWrap, children: r }) : null,
  1478. i !== void 0 && !F ? /* @__PURE__ */ p.jsx("div", { className: xe.sheetRangeSelectorPlaceholder, children: i }) : null
  1479. ]
  1480. }
  1481. ),
  1482. x && /* @__PURE__ */ p.jsx(
  1483. bi,
  1484. {
  1485. editorId: A,
  1486. handleConfirm: Re,
  1487. handleClose: je,
  1488. unitId: n,
  1489. subUnitId: o,
  1490. initValue: ne,
  1491. visible: x,
  1492. isOnlyOneRange: g,
  1493. isSupportAcrossSheet: l
  1494. }
  1495. )
  1496. ] });
  1497. }
  1498. function bi(e) {
  1499. const { handleConfirm: t, handleClose: n, visible: o, initValue: r, unitId: i, subUnitId: s, isOnlyOneRange: c, isSupportAcrossSheet: a } = e, d = y(Xe), u = y(xt), h = y(Be), g = y(ve).getRenderById(i), l = g == null ? void 0 : g.with(Fe), [m, S] = H(() => {
  1500. if (c) {
  1501. const v = r[0];
  1502. return v ? Ne([v], a) : [""];
  1503. }
  1504. return Ne(r, a);
  1505. }), [R, C] = H(() => m.length - 1), _ = Vr(), E = Z(() => m.join(ge.COMMA), [m]), x = qt(), M = Z(() => x(E), [E]), T = Z(() => Br(u, _, M).refSelections, [M]), P = () => {
  1506. S([]), setTimeout(() => {
  1507. n();
  1508. }, 30);
  1509. }, A = (v, F) => {
  1510. F ? l == null || l.setSkipLastEnabled(!1) : l == null || l.setSkipLastEnabled(!0), S((O) => {
  1511. const L = [...O];
  1512. return L[v] = F, L;
  1513. });
  1514. }, N = (v) => {
  1515. l == null || l.setSkipLastEnabled(!1), S((F) => {
  1516. if (F.length === 1)
  1517. return F;
  1518. const O = [];
  1519. return F.forEach((L, B) => {
  1520. v !== B && O.push(L);
  1521. }), O;
  1522. });
  1523. }, b = () => {
  1524. l == null || l.setSkipLastEnabled(!0), S((v) => (v.push(""), C(v.length - 1), [...v]));
  1525. }, w = Ee((v) => {
  1526. var O;
  1527. l == null || l.setSkipLastEnabled(!1);
  1528. const F = v.split(ge.COMMA).filter((L) => !!L);
  1529. S(c ? [(O = F[0]) != null ? O : ""] : F);
  1530. }), I = Rn(i, s);
  1531. return zr(R >= 0, i, s, M, a, c, w), In(R >= 0, R >= 0, i), Kr(i, c), bn(R >= 0, i, a, $n, $n, () => I(T)), D(() => {
  1532. I(T);
  1533. }, [T]), D(() => {
  1534. (m.length === 0 || m.length === 1 && !m[0]) && (l == null || l.setSkipLastEnabled(!0));
  1535. }, [m]), /* @__PURE__ */ p.jsx(
  1536. xs,
  1537. {
  1538. width: "328px",
  1539. visible: o,
  1540. title: d.t("rangeSelector.title"),
  1541. draggable: !0,
  1542. closeIcon: /* @__PURE__ */ p.jsx(Bt, {}),
  1543. footer: /* @__PURE__ */ p.jsxs("footer", { children: [
  1544. /* @__PURE__ */ p.jsx(ot, { onClick: P, children: d.t("rangeSelector.cancel") }),
  1545. /* @__PURE__ */ p.jsx(
  1546. ot,
  1547. {
  1548. style: { marginLeft: 10 },
  1549. onClick: () => t(m.filter((v) => {
  1550. const F = h.sequenceNodesBuilder(v);
  1551. return F && F.length === 1 && typeof F[0] != "string" && F[0].nodeType === G.REFERENCE;
  1552. }).map((v) => we(v)).map((v) => ({ ...v, range: En(v.range) }))),
  1553. type: "primary",
  1554. children: d.t("rangeSelector.confirm")
  1555. }
  1556. )
  1557. ] }),
  1558. onClose: P,
  1559. children: /* @__PURE__ */ p.jsxs("div", { className: xe.sheetRangeSelectorDialog, children: [
  1560. m.map((v, F) => /* @__PURE__ */ p.jsxs("div", { className: xe.sheetRangeSelectorDialogItem, children: [
  1561. /* @__PURE__ */ p.jsx(
  1562. Fr,
  1563. {
  1564. affixWrapperStyle: { width: "100%" },
  1565. placeholder: d.t("rangeSelector.placeHolder"),
  1566. onFocus: () => C(F),
  1567. value: v,
  1568. onChange: (O) => A(F, O)
  1569. },
  1570. `input_${F}`
  1571. ),
  1572. m.length > 1 && !c && /* @__PURE__ */ p.jsx(wr, { className: xe.sheetRangeSelectorDialogItemDelete, onClick: () => N(F) })
  1573. ] }, `${v}_${F}`)),
  1574. !c && /* @__PURE__ */ p.jsx("div", { children: /* @__PURE__ */ p.jsxs(ot, { type: "link", size: "small", onClick: b, children: [
  1575. /* @__PURE__ */ p.jsx(Dr, {}),
  1576. /* @__PURE__ */ p.jsx("span", { children: d.t("rangeSelector.addAnotherRange") })
  1577. ] }) })
  1578. ] })
  1579. }
  1580. );
  1581. }
  1582. function xi(e, t) {
  1583. return Object.keys(e).filter((n) => isNaN(Number(n)) && n !== "DefinedName").map((n) => ({
  1584. label: t.t(`formula.functionType.${n.toLocaleLowerCase()}`),
  1585. value: `${e[n]}`
  1586. }));
  1587. }
  1588. function xn(e) {
  1589. if (!e.require && !e.repeat)
  1590. return `[${e.name}]`;
  1591. if (e.require && !e.repeat)
  1592. return e.name;
  1593. if (!e.require && e.repeat)
  1594. return `[${e.name},...]`;
  1595. if (e.require && e.repeat)
  1596. return `${e.name},...`;
  1597. }
  1598. const Ni = (e, t = 100) => {
  1599. D(() => {
  1600. let n = null;
  1601. const o = () => {
  1602. n === null && (n = window.setTimeout(() => {
  1603. e(), n = null;
  1604. }, t));
  1605. };
  1606. return window.addEventListener("scroll", o), window.addEventListener("resize", o), () => {
  1607. n !== null && clearTimeout(n), window.removeEventListener("scroll", o), window.removeEventListener("resize", o);
  1608. };
  1609. }, [e, t]);
  1610. };
  1611. function Gr(e, t, n) {
  1612. const o = y(qe), r = Z(() => new Go({ left: -999, top: -999, right: -999, bottom: -999 }), []), i = y(Ut), s = y(pe), c = Ee(() => {
  1613. const a = o.getEditor(e);
  1614. if (!a)
  1615. return;
  1616. const d = a.getBoundingClientRect(), { left: u, top: h, right: f, bottom: g } = d, l = r.getValue();
  1617. if (!(l.left === u && l.top === h && l.right === f && l.bottom === g))
  1618. return r.next({ left: u - 1, right: f + 1, top: h - 1, bottom: g + 1 }), d;
  1619. });
  1620. return D(() => {
  1621. t && c();
  1622. }, [e, o, s.unitAdded$, c, t, ...n != null ? n : []]), Ni(c), D(() => {
  1623. const a = i.scrollEvent$.pipe(mn(100)).subscribe(c);
  1624. return () => {
  1625. a.unsubscribe();
  1626. };
  1627. }, []), [r, c];
  1628. }
  1629. const Ct = (e) => {
  1630. const t = q(e);
  1631. return t.current = e, t;
  1632. }, Fi = (e, t, n) => {
  1633. const o = y(xt), r = y(Be), [i, s] = H(), [c, a] = H(-1), [d, u] = H(!0), h = Ct(d), f = q(t);
  1634. f.current = t;
  1635. const g = () => {
  1636. s(void 0), a(-1), u(!1);
  1637. };
  1638. return D(() => {
  1639. if (n && e) {
  1640. const l = n.selectionChange$.pipe(gn(50)).subscribe((S) => {
  1641. if (S.textRanges.length === 1) {
  1642. const [R] = S.textRanges;
  1643. if (R.collapsed && h.current) {
  1644. const C = r.getFunctionAndParameter(`${f.current}A`, R.startOffset - 1);
  1645. if (C) {
  1646. const { functionName: _, paramIndex: E } = C, x = o.getFunctionInfo(_);
  1647. s(x), a(E);
  1648. return;
  1649. }
  1650. }
  1651. }
  1652. s(void 0), a(-1);
  1653. }), m = n.selectionChange$.pipe(
  1654. sn((S) => S.isEditing),
  1655. sn((S) => S.textRanges.length === 1),
  1656. Ht((S) => S.textRanges[0].startOffset),
  1657. dr()
  1658. ).subscribe(() => {
  1659. u(!0);
  1660. });
  1661. return () => {
  1662. l.unsubscribe(), m.unsubscribe();
  1663. };
  1664. }
  1665. }, [n, e]), D(() => {
  1666. e || g();
  1667. }, [e]), {
  1668. functionInfo: i,
  1669. paramIndex: c,
  1670. reset: g
  1671. };
  1672. }, yi = "univer-formula-help-function", Ti = "univer-formula-help-function-title", Oi = "univer-formula-help-function-title-icons", Mi = "univer-formula-help-function-title-icon", Pi = "univer-formula-help-function-content", Ai = "univer-formula-help-function-content-inner", Li = "univer-formula-help-function-content-params", wi = "univer-formula-help-function-content-params-title", $i = "univer-formula-help-function-content-params-detail", Di = "univer-formula-help-function-active", ki = "univer-formula-help-decorator", ji = "univer-formula-help-param", Hi = "univer-formula-help-param-prefix", Wi = "univer-formula-help-param-item", Ui = "univer-formula-help-param-active", ue = {
  1673. formulaHelpFunction: yi,
  1674. formulaHelpFunctionTitle: Ti,
  1675. formulaHelpFunctionTitleIcons: Oi,
  1676. formulaHelpFunctionTitleIcon: Mi,
  1677. formulaHelpFunctionContent: Pi,
  1678. formulaHelpFunctionContentInner: Ai,
  1679. formulaHelpFunctionContentParams: Li,
  1680. formulaHelpFunctionContentParamsTitle: wi,
  1681. formulaHelpFunctionContentParamsDetail: $i,
  1682. formulaHelpFunctionActive: Di,
  1683. formulaHelpDecorator: ki,
  1684. formulaHelpParam: ji,
  1685. formulaHelpParamPrefix: Hi,
  1686. formulaHelpParamItem: Wi,
  1687. formulaHelpParamActive: Ui
  1688. }, Jt = ({ className: e, title: t, value: n }) => /* @__PURE__ */ p.jsxs("div", { className: ue.formulaHelpFunctionContentParams, children: [
  1689. /* @__PURE__ */ p.jsx(
  1690. "div",
  1691. {
  1692. className: `
  1693. ${ue.formulaHelpFunctionContentParamsTitle}
  1694. ${e}
  1695. `,
  1696. children: t
  1697. }
  1698. ),
  1699. /* @__PURE__ */ p.jsx("div", { className: ue.formulaHelpFunctionContentParamsDetail, children: n })
  1700. ] }), Vi = (e) => {
  1701. const { prefix: t, value: n, active: o, onClick: r } = e;
  1702. return /* @__PURE__ */ p.jsxs("div", { className: ue.formulaHelpParam, children: [
  1703. /* @__PURE__ */ p.jsxs("span", { className: ue.formulaHelpParamPrefix, children: [
  1704. t,
  1705. "("
  1706. ] }),
  1707. n && n.map((i, s) => /* @__PURE__ */ p.jsxs("span", { className: ue.formulaHelpParamItem, children: [
  1708. /* @__PURE__ */ p.jsx(
  1709. "span",
  1710. {
  1711. className: o === s ? ue.formulaHelpFunctionActive : ue.formulaHelpParamActive,
  1712. onClick: () => r(s),
  1713. children: xn(i)
  1714. }
  1715. ),
  1716. s === n.length - 1 ? "" : ","
  1717. ] }, i.name)),
  1718. ")"
  1719. ] });
  1720. }, Gn = () => {
  1721. };
  1722. function Bi(e) {
  1723. const { onParamsSwitch: t = Gn, onClose: n = Gn, isFocus: o, editor: r, formulaText: i } = e, { functionInfo: s, paramIndex: c, reset: a } = Fi(o, i, r), d = Z(() => !!s && c >= 0, [s, c]), [u, h] = H(!0), f = y(Xe), g = f.t("formula.prompt.required"), l = f.t("formula.prompt.optional"), m = r.getEditorId(), [S] = Gr(m, d, [s, c]);
  1724. function R(_) {
  1725. t && t(_);
  1726. }
  1727. const C = () => {
  1728. a(), n();
  1729. };
  1730. return d && s ? /* @__PURE__ */ p.jsx(xr, { portal: !0, onClickOutside: () => a(), anchorRect$: S, direction: "vertical", children: /* @__PURE__ */ p.jsxs("div", { className: ue.formulaHelpFunction, children: [
  1731. /* @__PURE__ */ p.jsxs("div", { className: ue.formulaHelpFunctionTitle, children: [
  1732. /* @__PURE__ */ p.jsx(
  1733. Vi,
  1734. {
  1735. prefix: s.functionName,
  1736. value: s.functionParameter,
  1737. active: c,
  1738. onClick: R
  1739. }
  1740. ),
  1741. /* @__PURE__ */ p.jsxs("div", { className: ue.formulaHelpFunctionTitleIcons, children: [
  1742. /* @__PURE__ */ p.jsx(
  1743. "div",
  1744. {
  1745. className: ue.formulaHelpFunctionTitleIcon,
  1746. style: { transform: u ? "rotateZ(-90deg)" : "rotateZ(90deg)" },
  1747. onClick: () => h(!u),
  1748. children: /* @__PURE__ */ p.jsx(_n, {})
  1749. }
  1750. ),
  1751. /* @__PURE__ */ p.jsx(
  1752. "div",
  1753. {
  1754. className: ue.formulaHelpFunctionTitleIcon,
  1755. onClick: C,
  1756. children: /* @__PURE__ */ p.jsx(Bt, {})
  1757. }
  1758. )
  1759. ] })
  1760. ] }),
  1761. /* @__PURE__ */ p.jsx(
  1762. "div",
  1763. {
  1764. className: ue.formulaHelpFunctionContent,
  1765. style: {
  1766. height: u ? "unset" : 0,
  1767. padding: u ? "revert-layer" : 0
  1768. },
  1769. children: /* @__PURE__ */ p.jsxs("div", { className: ue.formulaHelpFunctionContentInner, children: [
  1770. /* @__PURE__ */ p.jsx(
  1771. Jt,
  1772. {
  1773. title: f.t("formula.prompt.helpExample"),
  1774. value: `${s.functionName}(${s.functionParameter.map((_) => _.example).join(",")})`
  1775. }
  1776. ),
  1777. /* @__PURE__ */ p.jsx(
  1778. Jt,
  1779. {
  1780. title: f.t("formula.prompt.helpAbstract"),
  1781. value: s.description
  1782. }
  1783. ),
  1784. s && s.functionParameter && s.functionParameter.map((_, E) => /* @__PURE__ */ p.jsx(
  1785. Jt,
  1786. {
  1787. className: c === E ? ue.formulaHelpFunctionActive : "",
  1788. title: _.name,
  1789. value: `${_.require ? g : l} ${_.detail}`
  1790. },
  1791. E
  1792. ))
  1793. ] })
  1794. }
  1795. )
  1796. ] }) }) : null;
  1797. }
  1798. const Xr = (e, t, n = !0) => {
  1799. let o = -1;
  1800. return e.reduce((r, i, s) => {
  1801. if (r.isFinish)
  1802. return r;
  1803. const c = r.currentIndex;
  1804. if (typeof i != "string")
  1805. r.currentIndex += i.token.length;
  1806. else {
  1807. const a = i.length;
  1808. r.currentIndex += a;
  1809. }
  1810. return (n ? r.currentIndex === t : t > c && t <= r.currentIndex) && (o = s, r.isFinish = !0), r;
  1811. }, { currentIndex: 0, isFinish: !1 }), o;
  1812. }, yt = (e) => e.reduce((t, n) => typeof n == "string" ? t + n.length : t + n.token.length, 0), qi = () => {
  1813. }, Ki = (e, t, n, o, r, i, s, c, a, d, u = qi) => {
  1814. const h = y(ve), f = y(pe), g = y(ye), l = Ct(i), m = y(Tr), S = y(Rt), R = f.getUnit(o), C = Ee((I) => {
  1815. var v, F;
  1816. return (F = (v = R == null ? void 0 : R.getSheetBySheetId(I)) == null ? void 0 : v.getName()) != null ? F : "";
  1817. }), _ = Z(() => C(r), [C, r]), E = it(R == null ? void 0 : R.activeSheet$), x = Ct({ activeSheet: E, sheetName: _ }), M = h.getRenderById(o), T = M == null ? void 0 : M.with(Fe), P = M == null ? void 0 : M.with(kt), A = y(Wt), N = q(!1), b = q(n);
  1818. b.current = n;
  1819. const w = q();
  1820. D(() => {
  1821. if (T && e) {
  1822. let I = !0;
  1823. const v = (O, L) => {
  1824. var ie, te, W, Ce, de, fe;
  1825. if (I) {
  1826. I = !1;
  1827. return;
  1828. }
  1829. const B = d == null ? void 0 : d.getSelectionRanges();
  1830. if ((B == null ? void 0 : B.length) !== 1)
  1831. return;
  1832. const V = B[0].startOffset - 1, U = [...l.current], ne = Xr(U, V, !1);
  1833. if (b.current === Mt.NEED_ADD)
  1834. if (V !== 0) {
  1835. if (ne === -1 && U.length)
  1836. return;
  1837. const re = O[O.length - 1], be = U.splice(ne + 1), ce = (ie = re.rangeWithCoord.sheetId) != null ? ie : r, _e = {
  1838. range: re.rangeWithCoord,
  1839. unitId: (te = re.rangeWithCoord.unitId) != null ? te : o,
  1840. sheetName: C(ce)
  1841. }, Re = Ne([_e], c && ce !== r, _);
  1842. U.push({ token: Re[0], nodeType: G.REFERENCE });
  1843. const je = [...U, ...be], He = Oe(je);
  1844. u(He, yt(U), L);
  1845. } else {
  1846. const re = O[O.length - 1], be = (W = re.rangeWithCoord.sheetId) != null ? W : r, ce = {
  1847. range: re.rangeWithCoord,
  1848. unitId: (Ce = re.rangeWithCoord.unitId) != null ? Ce : o,
  1849. sheetName: C(be)
  1850. }, me = Ne([ce], c && be !== r);
  1851. U.unshift({ token: me[0], nodeType: G.REFERENCE });
  1852. const Re = Oe(U);
  1853. u(Re, me[0].length, L);
  1854. }
  1855. else {
  1856. let re = 0;
  1857. const be = U.map((j) => {
  1858. var k, z, X;
  1859. if (typeof j == "string")
  1860. return j;
  1861. if (j.nodeType === G.REFERENCE) {
  1862. const J = we(j.token);
  1863. if (J.sheetName || (J.sheetName = _), c && ((k = x.current.activeSheet) == null ? void 0 : k.getName()) !== J.sheetName)
  1864. return j.token;
  1865. const oe = O[re];
  1866. if (re++, !oe)
  1867. return "";
  1868. const Je = (z = oe.rangeWithCoord.sheetId) != null ? z : r, Pe = {
  1869. range: oe.rangeWithCoord,
  1870. unitId: (X = oe.rangeWithCoord.unitId) != null ? X : o,
  1871. sheetName: C(Je)
  1872. };
  1873. return Ne([Pe], c, _)[0];
  1874. }
  1875. return j.token;
  1876. });
  1877. let ce = "", _e;
  1878. be.forEach((j, k) => {
  1879. ce += j, k === ne && (_e = ce.length);
  1880. });
  1881. const me = [];
  1882. for (let j = re; j <= O.length - 1; j++) {
  1883. const k = O[j], z = (de = k.rangeWithCoord.sheetId) != null ? de : r, X = {
  1884. range: k.rangeWithCoord,
  1885. unitId: (fe = k.rangeWithCoord.unitId) != null ? fe : o,
  1886. sheetName: C(z)
  1887. }, oe = Ne([X], c && z !== r, _);
  1888. me.push(oe[0]);
  1889. }
  1890. const Re = U[U.length - 1], je = Re && (typeof Re == "string" ? !1 : Re.nodeType === G.REFERENCE), He = `${ce}${me.length && je ? "," : ""}${me.join(",")}`;
  1891. u(He, !me.length && _e ? _e : He.length, L);
  1892. }
  1893. }, F = new st();
  1894. return F.add(T.selectionMoving$.subscribe((O) => {
  1895. N.current || v(O, !1);
  1896. })), F.add(T.selectionMoveEnd$.subscribe((O) => {
  1897. N.current || v(O, !0);
  1898. })), () => {
  1899. F.dispose();
  1900. };
  1901. }
  1902. }, [T, d, c, e, l, r, o, C, _, u, x]), D(() => {
  1903. if (t && T && d) {
  1904. const I = new st(), v = (L, B) => {
  1905. let K = 0, V = 0, U = !1;
  1906. const { sheetName: ne } = x.current, ie = l.current.map((W) => {
  1907. var Ce;
  1908. if (typeof W == "string")
  1909. return U || (V += W.length), W;
  1910. if (W.nodeType === G.REFERENCE) {
  1911. const de = we(W.token);
  1912. if (de.unitId || (de.unitId = o), de.sheetName || (de.sheetName = ne), c && ((Ce = x.current.activeSheet) == null ? void 0 : Ce.getName()) !== de.sheetName)
  1913. return U || (V += W.token.length), W;
  1914. if (K === B) {
  1915. U = !0;
  1916. const fe = { ...W, token: L };
  1917. return c && de.sheetName !== ne ? fe.token = Tt(de.sheetName, we(L).range) : fe.token = L, V += fe.token.length, K++, fe;
  1918. }
  1919. return U || (V += W.token.length), K++, W;
  1920. }
  1921. return U || (V += W.token.length), W;
  1922. }), te = Oe(ie);
  1923. u(te, -1, !0), w.current = { result: te, offset: V };
  1924. }, F = () => {
  1925. I.dispose(), T.getSelectionControls().forEach((B, K) => {
  1926. I.add(cn(B.selectionMoving$, B.selectionScaling$).pipe(
  1927. Ts((V) => Ve(V)),
  1928. Os(),
  1929. qn(100)
  1930. ).subscribe((V) => {
  1931. N.current = !0, v(V, K);
  1932. }));
  1933. }), I.add(T.selectionMoveEnd$.subscribe((B) => {
  1934. if (N.current = !1, w.current) {
  1935. const { result: K, offset: V } = w.current;
  1936. u(K, V || -1, !0), w.current = void 0;
  1937. }
  1938. }));
  1939. }, O = cn(
  1940. d.input$,
  1941. A.selectionSet$,
  1942. T.selectionMoveEnd$
  1943. ).pipe(
  1944. qn(50)
  1945. ).subscribe(() => {
  1946. F();
  1947. });
  1948. return () => {
  1949. O.unsubscribe(), I.dispose();
  1950. };
  1951. }
  1952. }, [t, T, d, A.selectionSet$, x, l, u, c, o]), D(() => {
  1953. if (a) {
  1954. const I = g.onCommandExecuted((v) => {
  1955. if (v.id !== Cr.id)
  1956. return;
  1957. const F = v.params;
  1958. if (F.extra !== "formula-editor")
  1959. return;
  1960. const { selections: O } = F;
  1961. if (O.length) {
  1962. const L = O[O.length - 1];
  1963. if (L) {
  1964. const B = L.range, K = r, V = {
  1965. range: B,
  1966. unitId: F.unitId === o ? "" : F.unitId,
  1967. sheetName: F.subUnitId === K ? "" : C(K)
  1968. }, U = [...l.current], ie = Ne([V], c, _)[0];
  1969. let te = U[U.length - 1];
  1970. if (typeof te == "object" && te.nodeType === G.REFERENCE) {
  1971. te = { ...te }, te.token = ie, te.endIndex = te.startIndex + ie.length, U[U.length - 1] = te;
  1972. const W = Oe(U);
  1973. u(W, yt(U), !0);
  1974. } else {
  1975. const W = yt(U);
  1976. U.push({
  1977. nodeType: G.REFERENCE,
  1978. token: ie,
  1979. startIndex: W,
  1980. endIndex: W + ie.length
  1981. });
  1982. const Ce = Oe(U);
  1983. u(Ce, yt(U), !0);
  1984. }
  1985. }
  1986. }
  1987. });
  1988. return () => {
  1989. I.dispose();
  1990. };
  1991. }
  1992. }, [g, C, u, c, a, l, _, r, o]), D(() => {
  1993. if (!d)
  1994. return;
  1995. const I = m.textSelection$.subscribe((v) => {
  1996. v.unitId === d.getEditorId() && Wr({
  1997. unitId: o,
  1998. subUnitId: r,
  1999. refSelections: s.current,
  2000. editor: d,
  2001. refSelectionsService: A,
  2002. refSelectionsRenderService: T,
  2003. sheetSkeletonManagerService: P,
  2004. themeService: S,
  2005. univerInstanceService: f
  2006. });
  2007. });
  2008. return () => I.unsubscribe();
  2009. }, [m.textSelection$, d, s, T, A, l, P, r, S, o, f]);
  2010. }, Yi = (e, t, n) => {
  2011. const o = y(Be), r = q(!0);
  2012. D(() => {
  2013. if (e) {
  2014. const i = setTimeout(() => {
  2015. r.current = !1;
  2016. }, 500);
  2017. return () => {
  2018. clearTimeout(i);
  2019. };
  2020. }
  2021. }, [e]), D(() => {
  2022. if (!r.current && t) {
  2023. const i = o.checkIfAddBracket(n);
  2024. t(i === 0 && n.startsWith(hr.EQUALS), `${n}`);
  2025. }
  2026. }, [n, t]);
  2027. }, zi = "univer-sheet-embedding-formula-editor-active", Zi = "univer-sheet-embedding-formula-editor-wrap", Gi = "univer-sheet-embedding-formula-editor-text", Xi = "univer-sheet-embedding-formula-editor-error", Ji = "univer-sheet-embedding-formula-editor", Qi = "univer-sheet-embedding-formula-editor-error-wrap", nt = {
  2028. sheetEmbeddingFormulaEditorActive: zi,
  2029. sheetEmbeddingFormulaEditorWrap: Zi,
  2030. sheetEmbeddingFormulaEditorText: Gi,
  2031. sheetEmbeddingFormulaEditorError: Xi,
  2032. sheetEmbeddingFormulaEditor: Ji,
  2033. sheetEmbeddingFormulaEditorErrorWrap: Qi
  2034. }, ec = (e, t = [], n) => {
  2035. const o = y(xt), [r, i] = H([]), [s, c] = H(""), a = q(-1), d = Ct({ nodes: t }), u = () => {
  2036. i([]), c(""), a.current = -1;
  2037. };
  2038. return D(() => {
  2039. if (n && e) {
  2040. const f = n.input$.pipe(gn(300)).subscribe(() => {
  2041. const g = n.getSelectionRanges();
  2042. if (g.length === 1) {
  2043. const l = d.current.nodes, m = g[0];
  2044. if (m.collapsed) {
  2045. const S = Xr(l, m.startOffset - 1, !1);
  2046. a.current = S;
  2047. const R = l[S];
  2048. if (R && typeof R != "string" && R.nodeType === G.FUNCTION) {
  2049. a.current = S;
  2050. const C = R.token, _ = o.getSearchListByNameFirstLetter(C);
  2051. i(_), c(C);
  2052. return;
  2053. }
  2054. }
  2055. }
  2056. a.current = -1, c(""), i((l) => l != null && l.length ? [] : l);
  2057. });
  2058. return () => {
  2059. f.unsubscribe();
  2060. };
  2061. }
  2062. }, [n, e]), D(() => {
  2063. e || u();
  2064. }, [e]), {
  2065. searchList: r,
  2066. searchText: s,
  2067. handlerFormulaReplace: (f) => {
  2068. const g = [...d.current.nodes];
  2069. if (a.current !== -1) {
  2070. const l = g.splice(a.current + 1), m = g.pop() || "";
  2071. let S = (typeof m == "string" ? m.length : m.token.length) - f.length;
  2072. return g.push(f), l[0] !== ge.OPEN_BRACKET && (g.push(ge.OPEN_BRACKET), S--), { text: Oe([...g, ...l]), offset: S };
  2073. }
  2074. },
  2075. reset: u
  2076. };
  2077. }, tc = "univer-formula-search-function", nc = "univer-formula-search-function-item", rc = "univer-formula-search-function-item-name", oc = "univer-formula-search-function-item-name-light", sc = "univer-formula-search-function-item-desc", ic = "univer-formula-search-function-item-active", We = {
  2078. formulaSearchFunction: tc,
  2079. formulaSearchFunctionItem: nc,
  2080. formulaSearchFunctionItemName: rc,
  2081. formulaSearchFunctionItemNameLight: oc,
  2082. formulaSearchFunctionItemDesc: sc,
  2083. formulaSearchFunctionItemActive: ic
  2084. }, cc = () => {
  2085. }, ac = ke(lc);
  2086. function lc(e, t) {
  2087. const { isFocus: n, sequenceNodes: o, onSelect: r, editor: i, onClose: s = cc } = e, c = i.getEditorId(), a = y(Vt), d = y(ye), { searchList: u, searchText: h, handlerFormulaReplace: f, reset: g } = ec(n, o, i), l = Z(() => !!u.length, [u]), m = q(), [S, R] = H(0), C = q(!1), [_] = Gr(c, l, [h, u]), E = Ct({ searchList: u, active: S }), x = (N) => {
  2088. const b = f(N);
  2089. b && (g(), r(b));
  2090. };
  2091. function M(N) {
  2092. C.current && R(N);
  2093. }
  2094. function T() {
  2095. C.current && R(-1);
  2096. }
  2097. D(() => {
  2098. if (!u.length)
  2099. return;
  2100. const N = `sheet.formula-embedding-editor.search_function.${c}`, b = new st(), w = (I) => {
  2101. const { searchList: v, active: F } = E.current;
  2102. switch (I) {
  2103. case $.ARROW_UP: {
  2104. R((O) => {
  2105. const L = Math.max(0, O - 1);
  2106. return P(L), L;
  2107. });
  2108. break;
  2109. }
  2110. case $.ARROW_DOWN: {
  2111. R((O) => {
  2112. const L = Math.min(v.length - 1, O + 1);
  2113. return P(L), L;
  2114. });
  2115. break;
  2116. }
  2117. case $.TAB:
  2118. case $.ENTER: {
  2119. const O = v[F];
  2120. x(O.name);
  2121. break;
  2122. }
  2123. case $.ESC: {
  2124. g(), s();
  2125. break;
  2126. }
  2127. }
  2128. };
  2129. return b.add(d.registerCommand({
  2130. id: N,
  2131. type: $e.OPERATION,
  2132. handler(I, v) {
  2133. const { keyCode: F } = v;
  2134. w(F);
  2135. }
  2136. })), [$.ARROW_UP, $.ARROW_DOWN, $.ENTER, $.ESC, $.TAB].map((I) => ({
  2137. id: N,
  2138. binding: I,
  2139. preconditions: () => !0,
  2140. priority: 1e3,
  2141. staticParameters: {
  2142. eventType: De.Keyboard,
  2143. keyCode: I
  2144. }
  2145. })).forEach((I) => {
  2146. b.add(a.registerShortcut(I));
  2147. }), () => {
  2148. b.dispose();
  2149. };
  2150. }, [u]);
  2151. function P(N) {
  2152. var V;
  2153. const b = (V = m.current) == null ? void 0 : V.querySelectorAll(`.${We.formulaSearchFunctionItem}`)[N];
  2154. if (!b) return;
  2155. const w = b.parentNode;
  2156. if (!w) return;
  2157. const v = w.getBoundingClientRect().top, F = w.offsetHeight, O = b.getBoundingClientRect(), L = O.top, B = O.height;
  2158. if (L >= 0 && L > v && L - v + B <= F)
  2159. return;
  2160. const K = b.offsetTop - (F - B) / 2;
  2161. w.scrollTo({
  2162. top: K,
  2163. behavior: "smooth"
  2164. });
  2165. }
  2166. const A = Z(() => {
  2167. let N = "";
  2168. return () => {
  2169. clearTimeout(N), C.current = !0, N = setTimeout(() => {
  2170. C.current = !1;
  2171. }, 300);
  2172. };
  2173. }, []);
  2174. return u.length > 0 && l && /* @__PURE__ */ p.jsx(xr, { portal: !0, anchorRect$: _, direction: "vertical", children: /* @__PURE__ */ p.jsx(
  2175. "ul",
  2176. {
  2177. className: We.formulaSearchFunction,
  2178. ref: (N) => {
  2179. m.current = N, t && (t.current = N);
  2180. },
  2181. children: u.map((N, b) => /* @__PURE__ */ p.jsxs(
  2182. "li",
  2183. {
  2184. className: S === b ? `
  2185. ${We.formulaSearchFunctionItem}
  2186. ${We.formulaSearchFunctionItemActive}
  2187. ` : We.formulaSearchFunctionItem,
  2188. onMouseEnter: () => M(b),
  2189. onMouseLeave: T,
  2190. onMouseMove: A,
  2191. onClick: () => {
  2192. x(N.name), i && i.focus();
  2193. },
  2194. children: [
  2195. /* @__PURE__ */ p.jsxs("span", { className: We.formulaSearchFunctionItemName, children: [
  2196. /* @__PURE__ */ p.jsx("span", { className: We.formulaSearchFunctionItemNameLight, children: N.name.substring(0, h.length) }),
  2197. /* @__PURE__ */ p.jsx("span", { children: N.name.slice(h.length) })
  2198. ] }),
  2199. /* @__PURE__ */ p.jsx("span", { className: We.formulaSearchFunctionItemDesc, children: N.desc })
  2200. ]
  2201. },
  2202. N.name
  2203. ))
  2204. }
  2205. ) });
  2206. }
  2207. const uc = (e) => e.startsWith(hr.EQUALS) ? e.slice(1) : "", Qt = () => {
  2208. };
  2209. function fc(e) {
  2210. var Yt, Nn;
  2211. const {
  2212. errorText: t,
  2213. initValue: n,
  2214. unitId: o,
  2215. subUnitId: r,
  2216. isFocus: i = !0,
  2217. isSupportAcrossSheet: s = !1,
  2218. onFocus: c = Qt,
  2219. onBlur: a = Qt,
  2220. onChange: d,
  2221. onVerify: u,
  2222. actions: h,
  2223. className: f,
  2224. editorId: g,
  2225. moveCursor: l = !0,
  2226. onFormulaSelectingChange: m,
  2227. keyboradEventConfig: S,
  2228. onMoveInEditor: R,
  2229. resetSelectionOnBlur: C = !0,
  2230. autoScrollbar: _ = !0,
  2231. isSingle: E = !0,
  2232. disableSelectionOnClick: x = !1,
  2233. disableContextMenu: M
  2234. } = e, T = y(qe), P = q(null), A = Ee(d);
  2235. h && (h.handleOutClick = (ae, le) => {
  2236. P.current && !P.current.contains(ae.target) && le();
  2237. });
  2238. const N = Ee(m), b = q(null), w = q(), I = w.current, [v, F] = H(i), O = q(null), L = Z(() => g != null ? g : sr(`${yo}-${ir(4)}`), []), B = Z(() => t !== void 0, [t]), K = y(pe), V = K.getUnit(L);
  2239. it(V == null ? void 0 : V.change$);
  2240. const U = qt(), ne = cr.transform.getPlainText((Nn = (Yt = V == null ? void 0 : V.getBody()) == null ? void 0 : Yt.dataStream) != null ? Nn : ""), ie = Z(() => uc(ne), [ne]), te = Z(() => U(ie), [ie, U]), { isSelecting: W } = li(L, v, x), Ce = q(""), fe = y(ve).getRenderById(L), re = fe == null ? void 0 : fe.with(mr), be = re == null ? void 0 : re.isFocusing, ce = Z(() => K.getCurrentTypeOfUnit$(Me.UNIVER_DOC), [K]), _e = it(ce), me = (_e == null ? void 0 : _e.getUnitId()) === L, Re = q([]), je = W;
  2241. ms(() => {
  2242. A(ne);
  2243. }, [ne, A]);
  2244. const He = Ur("="), j = Rn(o, r), k = Ee((ae, le = !0, Ae, Qe) => {
  2245. if (!w.current)
  2246. return;
  2247. Ce.current = ae;
  2248. const zt = U(ae[0] === "=" ? ae.slice(1) : ""), et = He(
  2249. w.current,
  2250. zt,
  2251. le,
  2252. Qe
  2253. );
  2254. Re.current = et, Ae && j(v ? et : [], w.current);
  2255. });
  2256. D(() => {
  2257. v && k(ne, !1, !0);
  2258. }, [ne, v, k]), Yi(v, u, ne);
  2259. const z = Hr(I), X = Yr(v, o, r);
  2260. D(() => {
  2261. N(W);
  2262. }, [N, W]), ns(v, S, I), lt(() => {
  2263. let ae;
  2264. if (O.current) {
  2265. ae = T.register({
  2266. autofocus: !0,
  2267. editorUnitId: L,
  2268. initialSnapshot: {
  2269. id: L,
  2270. body: {
  2271. dataStream: `${n}\r
  2272. `,
  2273. textRuns: [],
  2274. customBlocks: [],
  2275. customDecorations: [],
  2276. customRanges: []
  2277. },
  2278. documentStyle: {}
  2279. }
  2280. }, O.current);
  2281. const le = T.getEditor(L);
  2282. w.current = le, k(n, !1, !0);
  2283. }
  2284. return () => {
  2285. ae == null || ae.dispose();
  2286. };
  2287. }, []), lt(() => {
  2288. i ? (F(i), z()) : (C && (I == null || I.blur(), X()), F(i));
  2289. }, [i, I, z, X, C]);
  2290. const { checkScrollBar: J } = gr(I, E, _);
  2291. In(v, !!(W && me), o, M), qr(v && l, je, I, R);
  2292. const oe = Ee((ae, le, Ae) => {
  2293. if (!be)
  2294. return;
  2295. const Qe = le !== -1 ? [{ startOffset: le + 1, endOffset: le + 1, collapsed: !0 }] : void 0;
  2296. k(`=${ae}`, !0, Ae, Qe), Ae && (z(), le !== -1 && setTimeout(() => {
  2297. const zt = { startOffset: le + 1, endOffset: le + 1 }, et = I == null ? void 0 : I.render.with(pr);
  2298. et == null || et.scrollToRange({ ...zt, collapsed: !0 });
  2299. }, 50), J());
  2300. });
  2301. Ki(
  2302. v && !!(W && me),
  2303. v,
  2304. W,
  2305. o,
  2306. r,
  2307. te,
  2308. Re,
  2309. s,
  2310. !!je,
  2311. I,
  2312. oe
  2313. ), bn(v && !!(W && me), o, s, F, a, Qt);
  2314. const Je = (ae) => {
  2315. if (ae) {
  2316. const le = I == null ? void 0 : I.getSelectionRanges();
  2317. if (le && le.length === 1) {
  2318. const Ae = le[0];
  2319. if (Ae.collapsed) {
  2320. const Qe = ae.offset;
  2321. setTimeout(() => {
  2322. I == null || I.setSelectionRanges([{ startOffset: Ae.startOffset - Qe, endOffset: Ae.endOffset - Qe }]);
  2323. }, 30);
  2324. }
  2325. }
  2326. z(), k(`=${ae.text}`);
  2327. }
  2328. }, Pe = () => {
  2329. F(!0), c(), z();
  2330. };
  2331. return /* @__PURE__ */ p.jsxs("div", { className: ln(nt.sheetEmbeddingFormulaEditor, f), children: [
  2332. /* @__PURE__ */ p.jsx(
  2333. "div",
  2334. {
  2335. className: ln(nt.sheetEmbeddingFormulaEditorWrap, {
  2336. [nt.sheetEmbeddingFormulaEditorActive]: v,
  2337. [nt.sheetEmbeddingFormulaEditorError]: B
  2338. }),
  2339. ref: P,
  2340. children: /* @__PURE__ */ p.jsx(
  2341. "div",
  2342. {
  2343. className: nt.sheetEmbeddingFormulaEditorText,
  2344. ref: O,
  2345. onMouseUp: Pe
  2346. }
  2347. )
  2348. }
  2349. ),
  2350. t !== void 0 ? /* @__PURE__ */ p.jsx("div", { className: nt.sheetEmbeddingFormulaEditorErrorWrap, children: t }) : null,
  2351. I ? /* @__PURE__ */ p.jsx(
  2352. Bi,
  2353. {
  2354. editor: I,
  2355. isFocus: v,
  2356. formulaText: ne,
  2357. onClose: () => z()
  2358. }
  2359. ) : null,
  2360. I ? /* @__PURE__ */ p.jsx(
  2361. ac,
  2362. {
  2363. isFocus: v,
  2364. sequenceNodes: te,
  2365. onSelect: Je,
  2366. ref: b,
  2367. editor: I
  2368. }
  2369. ) : null
  2370. ] });
  2371. }
  2372. const hc = "sheets-formula-ui.base.config", Xn = {};
  2373. function dc(e) {
  2374. return e.getContextValue(lo) && e.getContextValue(uo);
  2375. }
  2376. function Jr(e, t = !1) {
  2377. return !t && !(Ge(e == null ? void 0 : e.f) || ct(e == null ? void 0 : e.si)) ? null : typeof (e == null ? void 0 : e.v) == "string" && Bo.has(e.v) ? e.v : null;
  2378. }
  2379. var mc = Object.defineProperty, gc = Object.getOwnPropertyDescriptor, pc = (e, t, n, o) => {
  2380. for (var r = o > 1 ? void 0 : o ? gc(t, n) : t, i = e.length - 1, s; i >= 0; i--)
  2381. (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
  2382. return o && r && mc(t, n, r), r;
  2383. }, mt = (e, t) => (n, o) => t(n, o, e);
  2384. const en = "SHEET_FORMULA_ALERT", Sc = {
  2385. [Se.DIV_BY_ZERO]: "divByZero",
  2386. [Se.NAME]: "name",
  2387. [Se.VALUE]: "value",
  2388. [Se.NUM]: "num",
  2389. [Se.NA]: "na",
  2390. [Se.CYCLE]: "cycle",
  2391. [Se.REF]: "ref",
  2392. [Se.SPILL]: "spill",
  2393. [Se.CALC]: "calc",
  2394. [Se.ERROR]: "error",
  2395. [Se.CONNECT]: "connect",
  2396. [Se.NULL]: "null"
  2397. };
  2398. let fn = class extends It {
  2399. constructor(e, t, n, o, r, i) {
  2400. super(), this._context = e, this._hoverManagerService = t, this._cellAlertManagerService = n, this._localeService = o, this._formulaDataModel = r, this._zenZoneService = i, this._init();
  2401. }
  2402. _init() {
  2403. this._initCellAlertPopup(), this._initZenService();
  2404. }
  2405. _initCellAlertPopup() {
  2406. this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(gn(100)).subscribe((e) => {
  2407. var t, n, o, r, i;
  2408. if (e) {
  2409. const c = this._context.unit.getActiveSheet();
  2410. if (!c) return;
  2411. const a = c.getCell(e.location.row, e.location.col), d = (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];
  2412. if (fo(a)) {
  2413. const u = Jr(a, !!d);
  2414. if (!u) {
  2415. this._hideAlert();
  2416. return;
  2417. }
  2418. const h = this._cellAlertManagerService.currentAlert.get(en), f = (i = h == null ? void 0 : h.alert) == null ? void 0 : i.location;
  2419. if (f && f.row === e.location.row && f.col === e.location.col && f.subUnitId === e.location.subUnitId && f.unitId === e.location.unitId)
  2420. return;
  2421. this._cellAlertManagerService.showAlert({
  2422. type: To.ERROR,
  2423. title: this._localeService.t("formula.error.title"),
  2424. message: this._localeService.t(`formula.error.${Sc[u]}`),
  2425. location: e.location,
  2426. width: 200,
  2427. height: 74,
  2428. key: en
  2429. });
  2430. return;
  2431. }
  2432. }
  2433. this._hideAlert();
  2434. }));
  2435. }
  2436. _initZenService() {
  2437. this.disposeWithMe(this._zenZoneService.visible$.subscribe((e) => {
  2438. e && this._hideAlert();
  2439. }));
  2440. }
  2441. _hideAlert() {
  2442. this._cellAlertManagerService.removeAlert(en);
  2443. }
  2444. };
  2445. fn = pc([
  2446. mt(1, ee(Oo)),
  2447. mt(2, ee(Mo)),
  2448. mt(3, ee(Xe)),
  2449. mt(4, ee(jt)),
  2450. mt(5, gs)
  2451. ], fn);
  2452. var vc = Object.defineProperty, Cc = Object.getOwnPropertyDescriptor, _c = (e, t, n, o) => {
  2453. for (var r = o > 1 ? void 0 : o ? Cc(t, n) : t, i = e.length - 1, s; i >= 0; i--)
  2454. (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
  2455. return o && r && vc(t, n, r), r;
  2456. }, Jn = (e, t) => (n, o) => t(n, o, e);
  2457. let Pt = class extends It {
  2458. constructor(e, t) {
  2459. super(), this._autoFillService = e, this._lexerTreeBuilder = t, this._registerAutoFill();
  2460. }
  2461. _registerAutoFill() {
  2462. const e = {
  2463. type: wn.FORMULA,
  2464. priority: 1001,
  2465. match: (t) => Ge(t == null ? void 0 : t.f) || ct(t == null ? void 0 : t.si),
  2466. isContinue: (t, n) => t.type === wn.FORMULA,
  2467. applyFunctions: {
  2468. [Po.COPY]: (t, n, o, r) => {
  2469. const { data: i, index: s } = t;
  2470. return this._fillCopyFormula(i, n, o, s, r);
  2471. }
  2472. }
  2473. };
  2474. this._autoFillService.registerRule(e);
  2475. }
  2476. _fillCopyFormula(e, t, n, o, r) {
  2477. var a, d;
  2478. const i = Ic(r), s = [], c = /* @__PURE__ */ new Map();
  2479. for (let u = 1; u <= t; u++) {
  2480. const h = (u - 1) % e.length, f = vt.deepClone(e[h]);
  2481. if (f) {
  2482. const g = ((a = e[h]) == null ? void 0 : a.f) || "", l = ((d = e[h]) == null ? void 0 : d.si) || "", m = Ge(g);
  2483. if (ct(l))
  2484. f.si = l, f.f = null, f.v = null, f.p = null, f.t = null, s.push(f);
  2485. else if (m) {
  2486. let R = c.get(h);
  2487. if (R)
  2488. f.si = R, f.f = null, f.v = null, f.p = null, f.t = null;
  2489. else {
  2490. R = vt.generateRandomId(6), c.set(h, R);
  2491. const { offsetX: C, offsetY: _ } = Rc(i, t, n), E = this._lexerTreeBuilder.moveFormulaRefOffset(
  2492. g,
  2493. C,
  2494. _
  2495. );
  2496. f.si = R, f.f = E, f.v = null, f.p = null, f.t = null;
  2497. }
  2498. s.push(f);
  2499. }
  2500. }
  2501. }
  2502. return s;
  2503. }
  2504. };
  2505. Pt = _c([
  2506. Jn(0, Ao),
  2507. Jn(1, ee(Be))
  2508. ], Pt);
  2509. function Rc(e, t, n) {
  2510. let o = 0, r = 0;
  2511. switch (n) {
  2512. case he.UP:
  2513. r = -e * t;
  2514. break;
  2515. case he.RIGHT:
  2516. o = e;
  2517. break;
  2518. case he.DOWN:
  2519. r = e;
  2520. break;
  2521. case he.LEFT:
  2522. o = -e * t;
  2523. break;
  2524. }
  2525. return { offsetX: o, offsetY: r };
  2526. }
  2527. function Ic(e) {
  2528. let t = 0;
  2529. for (const n in e)
  2530. e[n].forEach((o) => {
  2531. t += o.data.length;
  2532. });
  2533. return t;
  2534. }
  2535. var Ec = Object.defineProperty, bc = Object.getOwnPropertyDescriptor, xc = (e, t, n, o) => {
  2536. for (var r = o > 1 ? void 0 : o ? bc(t, n) : t, i = e.length - 1, s; i >= 0; i--)
  2537. (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
  2538. return o && r && Ec(t, n, r), r;
  2539. }, gt = (e, t) => (n, o) => t(n, o, e);
  2540. const Nc = "default-paste-formula";
  2541. let At = class extends It {
  2542. constructor(e, t, n, o, r) {
  2543. super(), this._currentUniverSheet = e, this._lexerTreeBuilder = t, this._sheetClipboardService = n, this._injector = o, this._formulaDataModel = r, this._initialize();
  2544. }
  2545. _initialize() {
  2546. this._registerClipboardHook();
  2547. }
  2548. _registerClipboardHook() {
  2549. this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteFormulaHook())), this.disposeWithMe(this._sheetClipboardService.addClipboardHook(this._pasteWithFormulaHook()));
  2550. }
  2551. _pasteFormulaHook() {
  2552. return {
  2553. id: rt.SPECIAL_PASTE_FORMULA,
  2554. priority: 10,
  2555. specialPasteInfo: { label: "specialPaste.formula" },
  2556. onPasteCells: (e, t, n, o) => this._onPasteCells(e, t, n, o, !0)
  2557. };
  2558. }
  2559. _pasteWithFormulaHook() {
  2560. return {
  2561. id: Nc,
  2562. priority: 10,
  2563. onPasteCells: (e, t, n, o) => this._onPasteCells(e, t, n, o, !1)
  2564. };
  2565. }
  2566. _onPasteCells(e, t, n, o, r) {
  2567. var f;
  2568. if ([
  2569. rt.SPECIAL_PASTE_FORMAT,
  2570. rt.SPECIAL_PASTE_COL_WIDTH
  2571. ].includes(o.pasteType))
  2572. return {
  2573. undos: [],
  2574. redos: []
  2575. };
  2576. const s = this._currentUniverSheet.getCurrentUnitForType(Me.UNIVER_SHEET), c = t.unitId || s.getUnitId(), a = t.subUnitId || ((f = s.getActiveSheet()) == null ? void 0 : f.getSheetId());
  2577. if (!c || !a)
  2578. return {
  2579. undos: [],
  2580. redos: []
  2581. };
  2582. const d = t.range, u = n, h = {
  2583. copyType: o.copyType || Lo.COPY,
  2584. copyRange: e == null ? void 0 : e.range,
  2585. pasteType: o.pasteType
  2586. };
  2587. return this._injector.invoke((g) => Fc(
  2588. c,
  2589. a,
  2590. d,
  2591. u,
  2592. g,
  2593. h,
  2594. this._lexerTreeBuilder,
  2595. this._formulaDataModel,
  2596. r,
  2597. e
  2598. ));
  2599. }
  2600. };
  2601. At = xc([
  2602. gt(0, pe),
  2603. gt(1, ee(Be)),
  2604. gt(2, wo),
  2605. gt(3, ee(_t)),
  2606. gt(4, ee(jt))
  2607. ], At);
  2608. function Fc(e, t, n, o, r, i, s, c, a = !1, d) {
  2609. const u = [], h = [], f = yc(e, t, n, o, i, s, c, d), g = {
  2610. unitId: e,
  2611. subUnitId: t,
  2612. cellValue: f.getData()
  2613. };
  2614. u.push({
  2615. id: Vn.id,
  2616. params: g
  2617. });
  2618. const l = is(
  2619. r,
  2620. g
  2621. );
  2622. return h.push({
  2623. id: Vn.id,
  2624. params: l
  2625. }), {
  2626. undos: h,
  2627. redos: u
  2628. };
  2629. }
  2630. function yc(e, t, n, o, r, i, s, c) {
  2631. return c ? r.pasteType === rt.SPECIAL_PASTE_VALUE ? Oc(e, t, n, o, s, c) : r.pasteType === rt.SPECIAL_PASTE_FORMULA ? Mc(e, t, n, o, i, s, c) : Pc(e, t, n, o, i, s, c) : Tc(e, t, n, o, s);
  2632. }
  2633. function Tc(e, t, n, o, r) {
  2634. const i = new Et(), s = r.getSheetFormulaData(e, t);
  2635. return o.forValue((c, a, d) => {
  2636. var g;
  2637. const u = n.rows[c], h = n.cols[a], f = {};
  2638. Ge(d.v) ? (f.v = null, f.f = `${d.v}`, f.si = null, f.p = null, i.setValue(u, h, f)) : (g = s == null ? void 0 : s[u]) != null && g[h] && (f.v = d.v, f.f = null, f.si = null, f.p = null, i.setValue(u, h, f));
  2639. }), i;
  2640. }
  2641. function Oc(e, t, n, o, r, i) {
  2642. var d, u;
  2643. const s = new Et(), c = (u = (d = r.getArrayFormulaCellData()) == null ? void 0 : d[i.unitId]) == null ? void 0 : u[i.subUnitId], a = r.getSheetFormulaData(e, t);
  2644. return o.forValue((h, f, g) => {
  2645. var _, E;
  2646. const l = i.range.rows[h % i.range.rows.length], m = i.range.cols[f % i.range.cols.length], S = n.rows[h], R = n.cols[f], C = {};
  2647. if (Ge(g.f) || ct(g.si))
  2648. C.v = g.v, C.f = null, C.si = null, C.p = null, s.setValue(S, R, C);
  2649. else if ((_ = c == null ? void 0 : c[l]) != null && _[m]) {
  2650. const x = c[l][m];
  2651. C.v = x.v, C.f = null, C.si = null, C.p = null, s.setValue(S, R, C);
  2652. } else if ((E = a == null ? void 0 : a[S]) != null && E[R]) {
  2653. if (C.v = g.v, C.f = null, C.si = null, C.p = null, g.p) {
  2654. const x = Qr(g);
  2655. x && (C.v = x);
  2656. }
  2657. s.setValue(S, R, C);
  2658. }
  2659. }), s;
  2660. }
  2661. function Mc(e, t, n, o, r, i, s) {
  2662. const c = new Et(), a = /* @__PURE__ */ new Map();
  2663. return o.forValue((d, u, h) => {
  2664. const f = n.rows[d], g = n.cols[u], l = {};
  2665. if (ct(h.si)) {
  2666. if (s.unitId !== e || s.subUnitId !== t) {
  2667. const m = i.getFormulaStringByCell(
  2668. s.range.rows[d % s.range.rows.length],
  2669. s.range.cols[u % s.range.cols.length],
  2670. s.subUnitId,
  2671. s.unitId
  2672. ), S = n.cols[u] - s.range.cols[u % s.range.cols.length], R = n.rows[d] - s.range.rows[d % s.range.rows.length], C = r.moveFormulaRefOffset(m || "", S, R);
  2673. l.si = null, l.f = C;
  2674. } else
  2675. l.si = h.si, l.f = null;
  2676. l.v = null, l.p = null, c.setValue(f, g, l);
  2677. } else if (Ge(h.f)) {
  2678. const m = `${d % s.range.rows.length}_${u % s.range.cols.length}`;
  2679. let S = a.get(m);
  2680. if (S)
  2681. l.si = S, l.f = null;
  2682. else {
  2683. S = vt.generateRandomId(6), a.set(m, S);
  2684. const R = n.cols[u] - s.range.cols[u % s.range.cols.length], C = n.rows[d] - s.range.rows[d % s.range.rows.length], _ = r.moveFormulaRefOffset(h.f || "", R, C);
  2685. l.si = S, l.f = _;
  2686. }
  2687. l.v = null, l.p = null, c.setValue(f, g, l);
  2688. } else {
  2689. if (l.v = h.v, l.f = null, l.si = null, l.p = null, h.p) {
  2690. const m = Qr(h);
  2691. m && (l.v = m);
  2692. }
  2693. c.setValue(f, g, l);
  2694. }
  2695. }), c;
  2696. }
  2697. function Pc(e, t, n, o, r, i, s) {
  2698. const c = new Et(), a = /* @__PURE__ */ new Map(), d = i.getSheetFormulaData(e, t);
  2699. return o.forValue((u, h, f) => {
  2700. var S;
  2701. const g = n.rows[u], l = n.cols[h], m = {};
  2702. if (ct(f.si)) {
  2703. if (s.unitId !== e || s.subUnitId !== t) {
  2704. const R = i.getFormulaStringByCell(
  2705. s.range.rows[u % s.range.rows.length],
  2706. s.range.cols[h % s.range.cols.length],
  2707. s.subUnitId,
  2708. s.unitId
  2709. ), C = n.cols[h] - s.range.cols[h % s.range.cols.length], _ = n.rows[u] - s.range.rows[u % s.range.rows.length], E = r.moveFormulaRefOffset(R || "", C, _);
  2710. m.si = null, m.f = E;
  2711. } else
  2712. m.si = f.si, m.f = null;
  2713. m.v = null, m.p = null, c.setValue(g, l, m);
  2714. } else if (Ge(f.f)) {
  2715. const R = `${u % s.range.rows.length}_${h % s.range.cols.length}`;
  2716. let C = a.get(R);
  2717. if (C)
  2718. m.si = C, m.f = null;
  2719. else {
  2720. C = vt.generateRandomId(6), a.set(R, C);
  2721. const _ = n.cols[h] - s.range.cols[h % s.range.cols.length], E = n.rows[u] - s.range.rows[u % s.range.rows.length], x = r.moveFormulaRefOffset(f.f || "", _, E);
  2722. m.si = C, m.f = x;
  2723. }
  2724. m.v = null, m.p = null, c.setValue(g, l, m);
  2725. } else (S = d == null ? void 0 : d[g]) != null && S[l] && (m.v = f.v, m.f = null, m.si = null, m.p = f.p, c.setValue(g, l, m));
  2726. }), c;
  2727. }
  2728. function Qr(e) {
  2729. if (e != null && e.p) {
  2730. const t = e == null ? void 0 : e.p.body;
  2731. if (t == null)
  2732. return;
  2733. const n = t.dataStream;
  2734. return n.substring(n.length - 2, n.length) === nr ? n.substring(0, n.length - 2) : n;
  2735. }
  2736. }
  2737. var Ac = Object.defineProperty, Lc = Object.getOwnPropertyDescriptor, wc = (e, t, n, o) => {
  2738. for (var r = o > 1 ? void 0 : o ? Lc(t, n) : t, i = e.length - 1, s; i >= 0; i--)
  2739. (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
  2740. return o && r && Ac(t, n, r), r;
  2741. }, ze = (e, t) => (n, o) => t(n, o, e);
  2742. let Lt = class extends It {
  2743. constructor(t, n, o, r, i, s, c, a) {
  2744. super();
  2745. Q(this, "_previousShape");
  2746. Q(this, "_skeleton");
  2747. this._context = t, this._sheetInterceptorService = n, this._formulaDataModel = o, this._themeService = r, this._renderManagerService = i, this._sheetSkeletonManagerService = s, this._commandService = c, this._logService = a, this._initSkeletonChangeListener(), this._initInterceptorEditorStart(), this._commandExecutedListener();
  2748. }
  2749. _initSkeletonChangeListener() {
  2750. this.disposeWithMe(
  2751. this._sheetSkeletonManagerService.currentSkeleton$.subscribe((t) => {
  2752. var n, o;
  2753. if (t == null)
  2754. this._logService.debug("[FormulaEditorShowController]: should not receive currentSkeleton$ as null!");
  2755. else {
  2756. const { skeleton: r } = t, i = (o = (n = this._skeleton) == null ? void 0 : n.worksheet) == null ? void 0 : o.getSheetId();
  2757. if (this._changeRuntime(r), i !== r.worksheet.getSheetId())
  2758. this._removeArrayFormulaRangeShape();
  2759. else {
  2760. const { unitId: s, sheetId: c } = t;
  2761. this._updateArrayFormulaRangeShape(s, c);
  2762. }
  2763. }
  2764. })
  2765. );
  2766. }
  2767. _changeRuntime(t) {
  2768. this._skeleton = t;
  2769. }
  2770. _initInterceptorEditorStart() {
  2771. this.disposeWithMe(
  2772. rr(
  2773. this._sheetInterceptorService.writeCellInterceptor.intercept(
  2774. cs,
  2775. {
  2776. handler: (t, n, o) => {
  2777. var l, m, S, R;
  2778. const { row: r, col: i, unitId: s, subUnitId: c, worksheet: a } = n, d = this._formulaDataModel.getArrayFormulaRange(), u = this._formulaDataModel.getArrayFormulaCellData();
  2779. if (this._removeArrayFormulaRangeShape(), t == null)
  2780. return o(t);
  2781. let h = null;
  2782. const f = this._formulaDataModel.getFormulaStringByCell(r, i, c, s);
  2783. if (f !== null && (h = { f }), t.v != null && t.v !== "" && ((S = (m = (l = u[s]) == null ? void 0 : l[c]) == null ? void 0 : m[r]) == null ? void 0 : S[i]) == null)
  2784. return h ? { ...t, ...h } : o(t);
  2785. const g = (R = d == null ? void 0 : d[s]) == null ? void 0 : R[c];
  2786. return g != null && (h = this._displayArrayFormulaRangeShape(g, r, i, s, c, a, h)), h ? { ...t, ...h } : o(t);
  2787. }
  2788. }
  2789. )
  2790. )
  2791. );
  2792. }
  2793. _commandExecutedListener() {
  2794. this.disposeWithMe(this._commandService.onCommandExecuted((t, n) => {
  2795. (t.id === qo.id || t.id === Ko.id && n && n.remove) && this._removeArrayFormulaRangeShape();
  2796. })), this.disposeWithMe(
  2797. this._commandService.beforeCommandExecuted((t) => {
  2798. as.id === t.id && requestIdleCallback(() => {
  2799. const n = t.params, { unitId: o, subUnitId: r, rowsAutoHeightInfo: i } = n;
  2800. this._refreshArrayFormulaRangeShapeByRow(o, r, i);
  2801. });
  2802. })
  2803. );
  2804. }
  2805. _displayArrayFormulaRangeShape(t, n, o, r, i, s, c) {
  2806. const a = this._formulaDataModel.getSheetFormulaData(r, i);
  2807. return new Et(t).forValue((d, u, h) => {
  2808. var S;
  2809. if (h == null)
  2810. return !0;
  2811. const { startRow: f, startColumn: g, endRow: l, endColumn: m } = h;
  2812. if (d === n && u === o)
  2813. return this._createArrayFormulaRangeShape(h, r), !1;
  2814. if (n >= f && n <= l && o >= g && o <= m) {
  2815. const R = s.getCell(f, g);
  2816. if ((R == null ? void 0 : R.v) === Se.SPILL)
  2817. return;
  2818. const C = (S = a == null ? void 0 : a[d]) == null ? void 0 : S[u];
  2819. return C == null || C.f == null ? !0 : (c == null && (c = {
  2820. f: C.f,
  2821. isInArrayFormulaRange: !0
  2822. }), this._createArrayFormulaRangeShape(h, r), !1);
  2823. }
  2824. }), c;
  2825. }
  2826. _createArrayFormulaRangeShape(t, n) {
  2827. const o = this._renderManagerService.getRenderById(n), r = this._sheetSkeletonManagerService.getCurrentSkeleton();
  2828. if (!o || !r) return;
  2829. const { scene: i } = o;
  2830. if (!i) return;
  2831. const s = this._themeService.getCurrentTheme(), c = {
  2832. range: t,
  2833. primary: null,
  2834. style: {
  2835. strokeWidth: 1,
  2836. stroke: s.hyacinth700,
  2837. fill: new or(s.colorWhite).setAlpha(0).toString(),
  2838. widgets: {}
  2839. }
  2840. }, a = on(c, r), { rowHeaderWidth: d, columnHeaderHeight: u } = r, h = new ur(i, $o.FORMULA_EDITOR_SHOW, this._themeService, {
  2841. highlightHeader: !1,
  2842. rowHeaderWidth: d,
  2843. columnHeaderHeight: u
  2844. });
  2845. h.updateRangeBySelectionWithCoord(a), h.setEvent(!1), this._previousShape = h;
  2846. }
  2847. _removeArrayFormulaRangeShape() {
  2848. this._previousShape != null && (this._previousShape.dispose(), this._previousShape = null);
  2849. }
  2850. _refreshArrayFormulaRangeShape(t, n) {
  2851. if (this._previousShape) {
  2852. const { startRow: o, endRow: r, startColumn: i, endColumn: s } = this._previousShape.getRange(), c = { startRow: o, endRow: r, startColumn: i, endColumn: s };
  2853. this._removeArrayFormulaRangeShape(), this._createArrayFormulaRangeShape(c, t);
  2854. }
  2855. }
  2856. _checkCurrentSheet(t, n) {
  2857. const o = this._sheetSkeletonManagerService.getCurrentSkeleton();
  2858. if (!o) return !1;
  2859. const r = o.worksheet;
  2860. return r ? r.unitId === t && r.getSheetId() === n : !1;
  2861. }
  2862. _updateArrayFormulaRangeShape(t, n) {
  2863. this._checkCurrentSheet(t, n) && this._previousShape && this._refreshArrayFormulaRangeShape(t);
  2864. }
  2865. _refreshArrayFormulaRangeShapeByRow(t, n, o) {
  2866. if (!this._checkCurrentSheet(t, n) || !this._previousShape) return;
  2867. const { startRow: r, endRow: i, startColumn: s, endColumn: c } = this._previousShape.getRange();
  2868. for (let a = 0; a < o.length; a++) {
  2869. const { row: d } = o[a];
  2870. if (r >= d) {
  2871. const u = {
  2872. startRow: r,
  2873. endRow: i,
  2874. startColumn: s,
  2875. endColumn: c
  2876. };
  2877. this._refreshArrayFormulaRangeShape(t, u);
  2878. break;
  2879. }
  2880. }
  2881. }
  2882. };
  2883. Lt = wc([
  2884. ze(1, ee(_r)),
  2885. ze(2, ee(jt)),
  2886. ze(3, ee(Rt)),
  2887. ze(4, ve),
  2888. ze(5, ee(kt)),
  2889. ze(6, ye),
  2890. ze(7, ho)
  2891. ], Lt);
  2892. var $c = Object.defineProperty, Dc = Object.getOwnPropertyDescriptor, kc = (e, t, n, o) => {
  2893. for (var r = o > 1 ? void 0 : o ? Dc(t, n) : t, i = e.length - 1, s; i >= 0; i--)
  2894. (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
  2895. return o && r && $c(t, n, r), r;
  2896. }, Qn = (e, t) => (n, o) => t(n, o, e);
  2897. const jc = {
  2898. tl: {
  2899. size: 6,
  2900. color: "#409f11"
  2901. }
  2902. };
  2903. let wt = class extends mo {
  2904. constructor(e, t) {
  2905. super(), this._sheetInterceptorService = e, this._formulaDataModel = t, this.disposeWithMe(this._sheetInterceptorService.intercept(
  2906. ls.CELL_CONTENT,
  2907. {
  2908. effect: go.Style,
  2909. handler: (n, o, r) => {
  2910. var c, a, d, u;
  2911. const i = (u = (d = (a = (c = this._formulaDataModel.getArrayFormulaCellData()) == null ? void 0 : c[o.unitId]) == null ? void 0 : a[o.subUnitId]) == null ? void 0 : d[o.row]) == null ? void 0 : u[o.col];
  2912. return Jr(n, !!i) ? r({
  2913. ...n,
  2914. markers: {
  2915. ...n == null ? void 0 : n.markers,
  2916. ...jc
  2917. }
  2918. }) : r(n);
  2919. },
  2920. priority: 10
  2921. }
  2922. ));
  2923. }
  2924. };
  2925. wt = kc([
  2926. Qn(0, ee(_r)),
  2927. Qn(1, ee(jt))
  2928. ], wt);
  2929. function Hc() {
  2930. const e = y(fs), t = y(ye), n = it(e.progress$), o = at(() => {
  2931. t.executeCommand(Yo.id);
  2932. }, [t]), r = at(() => {
  2933. e.clearProgress();
  2934. }, [e]);
  2935. return /* @__PURE__ */ p.jsx(ps, { progress: n, onTerminate: o, onClearProgress: r });
  2936. }
  2937. const Wc = (e, t = 100) => {
  2938. D(() => {
  2939. let n = null;
  2940. const o = () => {
  2941. n === null && (n = window.setTimeout(() => {
  2942. e(), n = null;
  2943. }, t));
  2944. };
  2945. return window.addEventListener("scroll", o), window.addEventListener("resize", o), () => {
  2946. n !== null && clearTimeout(n), window.removeEventListener("scroll", o), window.removeEventListener("resize", o);
  2947. };
  2948. }, [e, t]);
  2949. }, Uc = "univer-formula-help-function", Vc = "univer-formula-help-function-title", Bc = "univer-formula-help-function-title-icons", qc = "univer-formula-help-function-title-icon", Kc = "univer-formula-help-function-content", Yc = "univer-formula-help-function-content-inner", zc = "univer-formula-help-function-content-params", Zc = "univer-formula-help-function-content-params-title", Gc = "univer-formula-help-function-content-params-detail", Xc = "univer-formula-help-function-active", Jc = "univer-formula-help-decorator", Qc = "univer-formula-help-param", ea = "univer-formula-help-param-prefix", ta = "univer-formula-help-param-item", na = "univer-formula-help-param-active", se = {
  2950. formulaHelpFunction: Uc,
  2951. formulaHelpFunctionTitle: Vc,
  2952. formulaHelpFunctionTitleIcons: Bc,
  2953. formulaHelpFunctionTitleIcon: qc,
  2954. formulaHelpFunctionContent: Kc,
  2955. formulaHelpFunctionContentInner: Yc,
  2956. formulaHelpFunctionContentParams: zc,
  2957. formulaHelpFunctionContentParamsTitle: Zc,
  2958. formulaHelpFunctionContentParamsDetail: Gc,
  2959. formulaHelpFunctionActive: Xc,
  2960. formulaHelpDecorator: Jc,
  2961. formulaHelpParam: Qc,
  2962. formulaHelpParamPrefix: ea,
  2963. formulaHelpParamItem: ta,
  2964. formulaHelpParamActive: na
  2965. };
  2966. function ra() {
  2967. const [e, t] = H(!1), [n, o] = H(!0), [r, i] = H(!0), [s, c] = H(0), [a, d] = H([0, 0]), [u, h] = H({ left: 0, top: 0 }), [f, g] = H(null), l = y(Nt), m = y(Xe), S = m.t("formula.prompt.required"), R = m.t("formula.prompt.optional"), C = y(pe), _ = y(qe), E = y(Ut), x = po();
  2968. Wc(M), D(() => {
  2969. const N = l.help$.subscribe((w) => {
  2970. const { visible: I, paramIndex: v, functionInfo: F } = w;
  2971. if (!I) {
  2972. t(I);
  2973. return;
  2974. }
  2975. const O = T();
  2976. if (O == null)
  2977. return;
  2978. const { left: L, top: B, height: K } = O;
  2979. F.description === "" && F.functionParameter.length === 0 || (d([L, B + K]), c(v), g(F), h({ left: L, top: B }), t(I));
  2980. }), b = E.scrollEvent$.pipe(mn(100)).subscribe(M);
  2981. return () => {
  2982. N == null || N.unsubscribe(), b.unsubscribe();
  2983. };
  2984. }, []);
  2985. function M() {
  2986. if (!r)
  2987. return;
  2988. const N = T();
  2989. if (N == null)
  2990. return;
  2991. const { left: b, top: w, height: I } = N;
  2992. d([b, w + I]);
  2993. }
  2994. function T() {
  2995. const N = C.getCurrentUniverDocInstance();
  2996. if (!N)
  2997. return;
  2998. const b = N.getUnitId();
  2999. if (!_.isEditor(b))
  3000. return;
  3001. const w = _.getEditor(b);
  3002. return w == null ? void 0 : w.getBoundingClientRect();
  3003. }
  3004. function P(N) {
  3005. c(N);
  3006. }
  3007. function A() {
  3008. i(!r), x.get(Ss).focus();
  3009. }
  3010. return /* @__PURE__ */ p.jsx(p.Fragment, { children: r ? /* @__PURE__ */ p.jsx(yr, { visible: e, offset: a, children: f ? /* @__PURE__ */ p.jsxs("div", { className: se.formulaHelpFunction, children: [
  3011. /* @__PURE__ */ p.jsxs("div", { className: se.formulaHelpFunctionTitle, children: [
  3012. /* @__PURE__ */ p.jsx(
  3013. oa,
  3014. {
  3015. prefix: f.functionName,
  3016. value: f.functionParameter,
  3017. active: s,
  3018. onClick: P
  3019. }
  3020. ),
  3021. /* @__PURE__ */ p.jsxs("div", { className: se.formulaHelpFunctionTitleIcons, children: [
  3022. /* @__PURE__ */ p.jsx(
  3023. "div",
  3024. {
  3025. className: se.formulaHelpFunctionTitleIcon,
  3026. style: { transform: n ? "rotateZ(-90deg)" : "rotateZ(90deg)" },
  3027. onClick: () => o(!n),
  3028. children: /* @__PURE__ */ p.jsx(_n, {})
  3029. }
  3030. ),
  3031. /* @__PURE__ */ p.jsx(
  3032. "div",
  3033. {
  3034. className: se.formulaHelpFunctionTitleIcon,
  3035. onClick: A,
  3036. children: /* @__PURE__ */ p.jsx(Bt, {})
  3037. }
  3038. )
  3039. ] })
  3040. ] }),
  3041. /* @__PURE__ */ p.jsx(
  3042. "div",
  3043. {
  3044. className: se.formulaHelpFunctionContent,
  3045. style: {
  3046. height: n ? "unset" : 0,
  3047. padding: n ? "revert-layer" : 0
  3048. },
  3049. children: /* @__PURE__ */ p.jsxs("div", { className: se.formulaHelpFunctionContentInner, children: [
  3050. /* @__PURE__ */ p.jsx(
  3051. tn,
  3052. {
  3053. title: m.t("formula.prompt.helpExample"),
  3054. value: `${f.functionName}(${f.functionParameter.map((N) => N.example).join(",")})`
  3055. }
  3056. ),
  3057. /* @__PURE__ */ p.jsx(
  3058. tn,
  3059. {
  3060. title: m.t("formula.prompt.helpAbstract"),
  3061. value: f.description
  3062. }
  3063. ),
  3064. f && f.functionParameter && f.functionParameter.map((N, b) => /* @__PURE__ */ p.jsx(
  3065. tn,
  3066. {
  3067. className: s === b ? se.formulaHelpFunctionActive : "",
  3068. title: N.name,
  3069. value: `${N.require ? S : R} ${N.detail}`
  3070. },
  3071. b
  3072. ))
  3073. ] })
  3074. }
  3075. )
  3076. ] }) : /* @__PURE__ */ p.jsx(p.Fragment, {}) }) : e ? /* @__PURE__ */ p.jsx(
  3077. "div",
  3078. {
  3079. className: se.formulaHelpDecorator,
  3080. onClick: () => i(!r),
  3081. style: { left: u.left - 24, top: u.top },
  3082. children: /* @__PURE__ */ p.jsx($r, {})
  3083. }
  3084. ) : /* @__PURE__ */ p.jsx(p.Fragment, {}) });
  3085. }
  3086. const tn = (e) => /* @__PURE__ */ p.jsxs("div", { className: se.formulaHelpFunctionContentParams, children: [
  3087. /* @__PURE__ */ p.jsx(
  3088. "div",
  3089. {
  3090. className: `
  3091. ${se.formulaHelpFunctionContentParamsTitle}
  3092. ${e.className}
  3093. `,
  3094. children: e.title
  3095. }
  3096. ),
  3097. /* @__PURE__ */ p.jsx("div", { className: se.formulaHelpFunctionContentParamsDetail, children: e.value })
  3098. ] }), oa = (e) => {
  3099. const { prefix: t, value: n, active: o, onClick: r } = e;
  3100. return /* @__PURE__ */ p.jsxs("div", { className: se.formulaHelpParam, children: [
  3101. /* @__PURE__ */ p.jsxs("span", { className: se.formulaHelpParamPrefix, children: [
  3102. t,
  3103. "("
  3104. ] }),
  3105. n && n.map((i, s) => (
  3106. // TODO@Dushusir: more params needs to be active
  3107. /* @__PURE__ */ p.jsxs("span", { className: se.formulaHelpParamItem, children: [
  3108. /* @__PURE__ */ p.jsx(
  3109. "span",
  3110. {
  3111. className: o === s ? se.formulaHelpFunctionActive : se.formulaHelpParamActive,
  3112. onClick: () => r(s),
  3113. children: xn(i)
  3114. }
  3115. ),
  3116. s === n.length - 1 ? "" : ","
  3117. ] }, s)
  3118. )),
  3119. ")"
  3120. ] });
  3121. }, sa = "univer-formula-search-function", ia = "univer-formula-search-function-item", ca = "univer-formula-search-function-item-name", aa = "univer-formula-search-function-item-name-light", la = "univer-formula-search-function-item-desc", ua = "univer-formula-search-function-item-active", Ue = {
  3122. formulaSearchFunction: sa,
  3123. formulaSearchFunctionItem: ia,
  3124. formulaSearchFunctionItemName: ca,
  3125. formulaSearchFunctionItemNameLight: aa,
  3126. formulaSearchFunctionItemDesc: la,
  3127. formulaSearchFunctionItemActive: ua
  3128. };
  3129. function fa() {
  3130. const [e, t] = H(!1), [n, o] = H(0), [r, i] = H([0, 0]), [s, c] = H([]), [a, d] = H(""), u = q(null), h = y(Nt), f = y(pe), g = y(qe);
  3131. D(() => {
  3132. let C = [], _ = 0;
  3133. const E = h.search$.subscribe((T) => {
  3134. const { visible: P, searchText: A, searchList: N } = T;
  3135. if (!P) {
  3136. t(P);
  3137. return;
  3138. }
  3139. const b = l();
  3140. if (b == null)
  3141. return;
  3142. const { left: w, top: I, height: v } = b;
  3143. d(A), c(N), C = N, i([w, I + v]), t(P), o(0), _ = 0;
  3144. }), x = h.navigate$.subscribe((T) => {
  3145. const { direction: P } = T;
  3146. if (P === he.UP) {
  3147. let A = _ - 1;
  3148. A = A < 0 ? C.length - 1 : A, o(A), _ = A;
  3149. } else if (P === he.DOWN) {
  3150. let A = _ + 1;
  3151. A = A >= C.length ? 0 : A, o(A), _ = A;
  3152. }
  3153. R(_);
  3154. }), M = h.accept$.subscribe((T) => {
  3155. const P = C[_].name;
  3156. h.acceptFormulaName(P);
  3157. });
  3158. return () => {
  3159. E == null || E.unsubscribe(), x == null || x.unsubscribe(), M == null || M.unsubscribe();
  3160. };
  3161. }, []);
  3162. function l() {
  3163. const _ = f.getCurrentUniverDocInstance().getUnitId();
  3164. if (!g.isEditor(_))
  3165. return;
  3166. const E = g.getEditor(_);
  3167. return E == null ? void 0 : E.getBoundingClientRect();
  3168. }
  3169. function m(C) {
  3170. o(C);
  3171. }
  3172. function S() {
  3173. o(-1);
  3174. }
  3175. function R(C) {
  3176. var w;
  3177. const _ = (w = u.current) == null ? void 0 : w.querySelectorAll(`.${Ue.formulaSearchFunctionItem}`)[C];
  3178. if (!_) return;
  3179. const E = _.parentNode;
  3180. if (!E) return;
  3181. const M = E.getBoundingClientRect().top, T = E.offsetHeight, P = _.getBoundingClientRect(), A = P.top, N = P.height;
  3182. if (A >= 0 && A > M && A - M + N <= T)
  3183. return;
  3184. const b = _.offsetTop - (T - N) / 2;
  3185. E.scrollTo({
  3186. top: b,
  3187. behavior: "smooth"
  3188. });
  3189. }
  3190. return s.length > 0 && /* @__PURE__ */ p.jsx(yr, { visible: e, offset: r, children: /* @__PURE__ */ p.jsx("ul", { className: Ue.formulaSearchFunction, ref: u, children: s.map((C, _) => /* @__PURE__ */ p.jsxs(
  3191. "li",
  3192. {
  3193. className: n === _ ? `
  3194. ${Ue.formulaSearchFunctionItem}
  3195. ${Ue.formulaSearchFunctionItemActive}
  3196. ` : Ue.formulaSearchFunctionItem,
  3197. onMouseEnter: () => m(_),
  3198. onMouseLeave: S,
  3199. onClick: () => h.acceptFormulaName(C.name),
  3200. children: [
  3201. /* @__PURE__ */ p.jsxs("span", { className: Ue.formulaSearchFunctionItemName, children: [
  3202. /* @__PURE__ */ p.jsx("span", { className: Ue.formulaSearchFunctionItemNameLight, children: C.name.substring(0, a.length) }),
  3203. /* @__PURE__ */ p.jsx("span", { children: C.name.slice(a.length) })
  3204. ] }),
  3205. /* @__PURE__ */ p.jsx("span", { className: Ue.formulaSearchFunctionItemDesc, children: C.desc })
  3206. ]
  3207. },
  3208. _
  3209. )) }) });
  3210. }
  3211. function ha() {
  3212. return /* @__PURE__ */ p.jsxs(p.Fragment, { children: [
  3213. /* @__PURE__ */ p.jsx(fa, {}),
  3214. /* @__PURE__ */ p.jsx(ra, {})
  3215. ] });
  3216. }
  3217. const da = "univer-formula-more-functions", ma = "univer-formula-more-functions-operation", er = {
  3218. formulaMoreFunctions: da,
  3219. formulaMoreFunctionsOperation: ma
  3220. };
  3221. function eo(e) {
  3222. const { prefix: t, value: n } = e;
  3223. return /* @__PURE__ */ p.jsxs("div", { children: [
  3224. /* @__PURE__ */ p.jsxs("span", { children: [
  3225. t,
  3226. "("
  3227. ] }),
  3228. n && n.map((o, r) => /* @__PURE__ */ p.jsxs("span", { children: [
  3229. /* @__PURE__ */ p.jsx("span", { children: xn(o) }),
  3230. r === n.length - 1 ? "" : ","
  3231. ] }, r)),
  3232. ")"
  3233. ] });
  3234. }
  3235. const ga = "univer-formula-function-params", pa = "univer-formula-function-params-title", Sa = "univer-formula-function-params-detail", nn = {
  3236. formulaFunctionParams: ga,
  3237. formulaFunctionParamsTitle: pa,
  3238. formulaFunctionParamsDetail: Sa
  3239. };
  3240. function St(e) {
  3241. const { className: t, value: n, title: o } = e;
  3242. return /* @__PURE__ */ p.jsxs("div", { className: nn.formulaFunctionParams, children: [
  3243. /* @__PURE__ */ p.jsx(
  3244. "div",
  3245. {
  3246. className: `
  3247. ${nn.formulaFunctionParamsTitle}
  3248. ${t}
  3249. `,
  3250. children: o
  3251. }
  3252. ),
  3253. /* @__PURE__ */ p.jsx("div", { className: nn.formulaFunctionParamsDetail, children: n })
  3254. ] });
  3255. }
  3256. const va = "univer-formula-input-params-list", Ca = "univer-formula-input-params-list-item-name", _a = "univer-formula-input-params-list-item-selector", pt = {
  3257. formulaInputParamsList: va,
  3258. formulaInputParamsListItemName: Ca,
  3259. formulaInputParamsListItemSelector: _a
  3260. };
  3261. function Ra(e) {
  3262. const { functionInfo: t, onChange: n } = e;
  3263. if (!t) return null;
  3264. H([]);
  3265. const [o, r] = H(t.functionParameter), [i, s] = H(-1);
  3266. return /* @__PURE__ */ p.jsxs("div", { className: pt.formulaInputParams, children: [
  3267. /* @__PURE__ */ p.jsx("div", { className: pt.formulaInputParamsList, children: o.map((c, a) => /* @__PURE__ */ p.jsxs("div", { children: [
  3268. /* @__PURE__ */ p.jsx("div", { className: pt.formulaInputParamsListItemName, children: c.name }),
  3269. /* @__PURE__ */ p.jsx("div", { className: pt.formulaInputParamsListItemSelector })
  3270. ] }, a)) }),
  3271. /* @__PURE__ */ p.jsx("div", { className: pt.formulaInputParamsInfo, children: /* @__PURE__ */ p.jsx(
  3272. St,
  3273. {
  3274. title: i === -1 ? /* @__PURE__ */ p.jsx(eo, { prefix: t.functionName, value: o }) : o[i].name,
  3275. value: i === -1 ? t.description : o[i].detail
  3276. }
  3277. ) })
  3278. ] });
  3279. }
  3280. const Ia = "univer-formula-select-function-select", Ea = "univer-formula-select-function-result", ba = "univer-formula-select-function-result-item", xa = "univer-formula-select-function-result-item-name-light", Na = "univer-formula-select-function-result-item-selected", Fa = "univer-formula-select-function-result-item-active", ya = "univer-formula-select-function-content", Le = {
  3281. formulaSelectFunctionSelect: Ia,
  3282. formulaSelectFunctionResult: Ea,
  3283. formulaSelectFunctionResultItem: ba,
  3284. formulaSelectFunctionResultItemNameLight: xa,
  3285. formulaSelectFunctionResultItemSelected: Na,
  3286. formulaSelectFunctionResultItemActive: Fa,
  3287. formulaSelectFunctionContent: ya
  3288. };
  3289. function Ta(e) {
  3290. const { onChange: t } = e, n = "-1", [o, r] = H(""), [i, s] = H([]), [c, a] = H(0), [d, u] = H(n), [h, f] = H(0), [g, l] = H(null), m = y(xt), S = y(Xe), R = y(Ut), C = it(R.sidebarOptions$), _ = xi(zo, S);
  3291. _.unshift({
  3292. label: S.t("formula.moreFunctions.allFunctions"),
  3293. value: n
  3294. });
  3295. const E = S.t("formula.prompt.required"), x = S.t("formula.prompt.optional");
  3296. D(() => {
  3297. P(n);
  3298. }, []), D(() => {
  3299. T(0);
  3300. }, [i]), D(() => {
  3301. C != null && C.visible && (r(""), s([]), a(0), u(n), f(0), l(null), P(n));
  3302. }, [C]);
  3303. const M = (I) => {
  3304. if (o.trim() === "") return I;
  3305. const v = new RegExp(`(${o.toLocaleUpperCase()})`);
  3306. return I.split(v).filter(Boolean).map((O, L) => O.match(v) ? /* @__PURE__ */ p.jsx("span", { className: Le.formulaSelectFunctionResultItemNameLight, children: O }, L) : O);
  3307. }, T = (I) => {
  3308. if (i.length === 0) {
  3309. l(null);
  3310. return;
  3311. }
  3312. f(I);
  3313. const v = m.getFunctionInfo(i[I].name);
  3314. if (!v) {
  3315. l(null);
  3316. return;
  3317. }
  3318. l(v), t(v);
  3319. };
  3320. function P(I) {
  3321. u(I);
  3322. const v = m.getSearchListByType(+I);
  3323. s(v);
  3324. }
  3325. function A(I) {
  3326. r(I);
  3327. const v = m.getSearchListByName(I);
  3328. s(v);
  3329. }
  3330. function N(I) {
  3331. if (I.stopPropagation(), I.key === "ArrowDown") {
  3332. const v = c + 1;
  3333. a(v === i.length ? 0 : v);
  3334. } else if (I.key === "ArrowUp") {
  3335. const v = c - 1;
  3336. a(v === -1 ? i.length - 1 : v);
  3337. } else I.key === "Enter" && T(c);
  3338. }
  3339. const b = (I) => {
  3340. a(I);
  3341. }, w = () => {
  3342. a(-1);
  3343. };
  3344. return /* @__PURE__ */ p.jsxs("div", { children: [
  3345. /* @__PURE__ */ p.jsxs("div", { className: Le.formulaSelectFunctionSelect, children: [
  3346. /* @__PURE__ */ p.jsx(Ns, { value: d, options: _, onChange: P }),
  3347. /* @__PURE__ */ p.jsx(
  3348. Fr,
  3349. {
  3350. placeholder: S.t("formula.moreFunctions.searchFunctionPlaceholder"),
  3351. onKeyDown: N,
  3352. value: o,
  3353. onChange: A,
  3354. size: "large",
  3355. allowClear: !0
  3356. }
  3357. )
  3358. ] }),
  3359. /* @__PURE__ */ p.jsx("ul", { className: Le.formulaSelectFunctionResult, onKeyDown: N, tabIndex: -1, children: i.map(({ name: I }, v) => /* @__PURE__ */ p.jsxs(
  3360. "li",
  3361. {
  3362. className: c === v ? `
  3363. ${Le.formulaSelectFunctionResultItem}
  3364. ${Le.formulaSelectFunctionResultItemActive}
  3365. ` : Le.formulaSelectFunctionResultItem,
  3366. onMouseEnter: () => b(v),
  3367. onMouseLeave: w,
  3368. onClick: () => T(v),
  3369. children: [
  3370. h === v && /* @__PURE__ */ p.jsx(Lr, { className: Le.formulaSelectFunctionResultItemSelected }),
  3371. /* @__PURE__ */ p.jsx("span", { className: Le.formulaSelectFunctionResultItemName, children: M(I) })
  3372. ]
  3373. },
  3374. v
  3375. )) }),
  3376. g && /* @__PURE__ */ p.jsxs("div", { className: Le.formulaSelectFunctionContent, children: [
  3377. /* @__PURE__ */ p.jsx(St, { title: g.functionName, value: g.description }),
  3378. /* @__PURE__ */ p.jsx(
  3379. St,
  3380. {
  3381. title: S.t("formula.moreFunctions.syntax"),
  3382. value: /* @__PURE__ */ p.jsx(eo, { prefix: g.functionName, value: g.functionParameter })
  3383. }
  3384. ),
  3385. /* @__PURE__ */ p.jsx(
  3386. St,
  3387. {
  3388. title: S.t("formula.prompt.helpExample"),
  3389. value: `${g.functionName}(${g.functionParameter.map((I) => I.example).join(",")})`
  3390. }
  3391. ),
  3392. g.functionParameter && g.functionParameter.map((I, v) => /* @__PURE__ */ p.jsx(
  3393. St,
  3394. {
  3395. title: I.name,
  3396. value: `${I.require ? E : x} ${I.detail}`
  3397. },
  3398. v
  3399. ))
  3400. ] })
  3401. ] });
  3402. }
  3403. function Oa() {
  3404. const e = Do(), [t, n] = H(!0), [o, r] = H(!1), [i, s] = H(null), c = y(ar), a = y(Xe), d = y(qe), u = y(pe);
  3405. function h() {
  3406. n(!t), r(!o);
  3407. }
  3408. function f() {
  3409. const g = vr(u);
  3410. if (!g) return;
  3411. c.changeVisible({
  3412. visible: !0,
  3413. unitId: g.unitId,
  3414. eventType: De.Dblclick
  3415. });
  3416. const l = d.getEditor(dn), m = d.getEditor(tr), S = `=${i == null ? void 0 : i.functionName}(`;
  3417. l == null || l.replaceText(S), m == null || m.replaceText(S, !1);
  3418. }
  3419. return /* @__PURE__ */ p.jsxs("div", { className: er.formulaMoreFunctions, children: [
  3420. t && /* @__PURE__ */ p.jsx(Ta, { onChange: s }),
  3421. o && /* @__PURE__ */ p.jsx(Ra, { functionInfo: i, onChange: () => {
  3422. } }),
  3423. /* @__PURE__ */ p.jsxs("div", { className: er.formulaMoreFunctionsOperation, children: [
  3424. o && /* @__PURE__ */ p.jsx(ot, { type: "primary", size: "small", onClick: h, children: a.t("formula.moreFunctions.next") }),
  3425. o && /* @__PURE__ */ p.jsx(ot, { size: "small", onClick: h, children: a.t("formula.moreFunctions.prev") }),
  3426. t && !!e && /* @__PURE__ */ p.jsx(ot, { type: "primary", size: "small", onClick: f, children: a.t("formula.moreFunctions.confirm") })
  3427. ] })
  3428. ] });
  3429. }
  3430. function Ma(e) {
  3431. return {
  3432. id: vn.id,
  3433. icon: "FunctionSingle",
  3434. tooltip: "formula.insert.tooltip",
  3435. type: pn.SELECTOR,
  3436. selections: [
  3437. {
  3438. label: "SUM",
  3439. value: "SUM",
  3440. icon: "SumSingle"
  3441. },
  3442. {
  3443. label: "AVERAGE",
  3444. value: "AVERAGE",
  3445. icon: "AvgSingle"
  3446. },
  3447. {
  3448. label: "COUNT",
  3449. value: "COUNT",
  3450. icon: "CntSingle"
  3451. },
  3452. {
  3453. label: "MAX",
  3454. value: "MAX",
  3455. icon: "MaxSingle"
  3456. },
  3457. {
  3458. label: "MIN",
  3459. value: "MIN",
  3460. icon: "MinSingle"
  3461. }
  3462. ],
  3463. hidden$: vs(e, Me.UNIVER_SHEET),
  3464. disabled$: fr(e, { workbookTypes: [Rr], worksheetTypes: [Ir, Er], rangeTypes: [br] })
  3465. };
  3466. }
  3467. function Pa(e) {
  3468. return {
  3469. id: Cn.id,
  3470. title: "formula.insert.more",
  3471. type: pn.BUTTON
  3472. };
  3473. }
  3474. function Aa(e) {
  3475. return e.get(pe).getCurrentTypeOfUnit$(Me.UNIVER_SHEET).pipe(
  3476. Jo((o) => o ? e.get(Bn) ? new Qo((i) => i.next(!e.get(Bn).supportClipboard)) : Dn(!0) : Dn(!0))
  3477. );
  3478. }
  3479. function La(e) {
  3480. return {
  3481. id: Sn.id,
  3482. type: pn.BUTTON,
  3483. title: "formula.operation.pasteFormula",
  3484. disabled$: Aa(e).pipe(
  3485. Xo(fr(e, { workbookTypes: [Rr], rangeTypes: [br], worksheetTypes: [Er, Ir] })),
  3486. Ht(([t, n]) => t || n)
  3487. )
  3488. };
  3489. }
  3490. const wa = {
  3491. [Cs.FORMULAS_INSERT]: {
  3492. [vn.id]: {
  3493. order: 1,
  3494. menuItemFactory: Ma,
  3495. [Cn.id]: {
  3496. order: 1,
  3497. menuItemFactory: Pa
  3498. }
  3499. }
  3500. },
  3501. [ko]: {
  3502. [Sn.id]: {
  3503. order: 4,
  3504. menuItemFactory: La
  3505. }
  3506. }
  3507. }, $a = "meta_key_ctrl_And_Shift", Kt = [
  3508. $.ARROW_DOWN,
  3509. $.ARROW_UP,
  3510. $.ARROW_LEFT,
  3511. $.ARROW_RIGHT
  3512. ], Da = [...Kt, $.ENTER, $.TAB, $.ESC];
  3513. function ka() {
  3514. const e = [];
  3515. for (const t of Da)
  3516. e.push({
  3517. id: ut.id,
  3518. binding: t,
  3519. preconditions: (n) => bt(n),
  3520. staticParameters: {
  3521. eventType: De.Keyboard,
  3522. keycode: t
  3523. }
  3524. });
  3525. return e;
  3526. }
  3527. function ja() {
  3528. const e = [];
  3529. for (const t of Kt)
  3530. e.push({
  3531. id: ut.id,
  3532. binding: t | Y.SHIFT,
  3533. preconditions: (n) => bt(n),
  3534. staticParameters: {
  3535. eventType: De.Keyboard,
  3536. keycode: t,
  3537. metaKey: Y.SHIFT
  3538. }
  3539. });
  3540. return e;
  3541. }
  3542. function Ha() {
  3543. const e = [];
  3544. for (const t of Kt)
  3545. e.push({
  3546. id: ut.id,
  3547. binding: t | Y.CTRL_COMMAND,
  3548. preconditions: (n) => bt(n),
  3549. staticParameters: {
  3550. eventType: De.Keyboard,
  3551. keycode: t,
  3552. metaKey: Y.CTRL_COMMAND
  3553. }
  3554. });
  3555. return e;
  3556. }
  3557. function Wa() {
  3558. const e = [];
  3559. for (const t of Kt)
  3560. e.push({
  3561. id: ut.id,
  3562. binding: t | Y.SHIFT | Y.CTRL_COMMAND,
  3563. preconditions: (n) => bt(n),
  3564. staticParameters: {
  3565. eventType: De.Keyboard,
  3566. keycode: t,
  3567. metaKey: $a
  3568. }
  3569. });
  3570. return e;
  3571. }
  3572. const Ua = {
  3573. id: Pr.id,
  3574. binding: $.F4,
  3575. preconditions: (e) => bt(e)
  3576. };
  3577. function Va() {
  3578. const e = [];
  3579. for (const t of [$.ENTER, $.TAB, $.ARROW_DOWN, $.ARROW_UP])
  3580. e.push({
  3581. id: ut.id,
  3582. binding: t,
  3583. preconditions: (n) => dc(n),
  3584. staticParameters: {
  3585. eventType: De.Keyboard,
  3586. keycode: t,
  3587. isSingleEditor: !0
  3588. }
  3589. });
  3590. return e;
  3591. }
  3592. var Ba = Object.defineProperty, qa = Object.getOwnPropertyDescriptor, Ka = (e, t, n, o) => {
  3593. for (var r = o > 1 ? void 0 : o ? qa(t, n) : t, i = e.length - 1, s; i >= 0; i--)
  3594. (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
  3595. return o && r && Ba(t, n, r), r;
  3596. }, Ze = (e, t) => (n, o) => t(n, o, e);
  3597. let $t = class extends It {
  3598. constructor(e, t, n, o, r, i, s) {
  3599. super(), this._injector = e, this._menuManagerService = t, this._commandService = n, this._shortcutService = o, this._uiPartsService = r, this._renderManagerService = i, this._componentManager = s, this._initialize();
  3600. }
  3601. _initialize() {
  3602. this._registerCommands(), this._registerMenus(), this._registerShortcuts(), this._registerComponents(), this._registerRenderModules();
  3603. }
  3604. _registerMenus() {
  3605. this._menuManagerService.mergeMenu(wa);
  3606. }
  3607. _registerCommands() {
  3608. [
  3609. Sn,
  3610. vn,
  3611. Cn,
  3612. Ws,
  3613. $s,
  3614. ut,
  3615. Pr
  3616. ].forEach((e) => this.disposeWithMe(this._commandService.registerCommand(e)));
  3617. }
  3618. _registerShortcuts() {
  3619. [
  3620. ...ka(),
  3621. ...ja(),
  3622. ...Ha(),
  3623. ...Wa(),
  3624. ...Va(),
  3625. Ua
  3626. ].forEach((e) => {
  3627. this.disposeWithMe(this._shortcutService.registerShortcut(e));
  3628. });
  3629. }
  3630. _registerComponents() {
  3631. this.disposeWithMe(this._uiPartsService.registerComponent(_s.CONTENT, () => Tn(ha, this._injector))), this.disposeWithMe(this._uiPartsService.registerComponent(jo.FORMULA_AUX, () => Tn(Hc, this._injector))), this._componentManager.register(Mr, Oa);
  3632. }
  3633. _registerRenderModules() {
  3634. this.disposeWithMe(this._renderManagerService.registerRenderModule(Me.UNIVER_SHEET, [Lt]));
  3635. }
  3636. };
  3637. $t = Ka([
  3638. Ze(0, ee(_t)),
  3639. Ze(1, Rs),
  3640. Ze(2, ye),
  3641. Ze(3, Vt),
  3642. Ze(4, Is),
  3643. Ze(5, ve),
  3644. Ze(6, ee(Nr))
  3645. ], $t);
  3646. var to = Object.defineProperty, Ya = Object.getOwnPropertyDescriptor, za = (e, t, n) => t in e ? to(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, Za = (e, t, n, o) => {
  3647. for (var r = o > 1 ? void 0 : o ? Ya(t, n) : t, i = e.length - 1, s; i >= 0; i--)
  3648. (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
  3649. return o && r && to(t, n, r), r;
  3650. }, rn = (e, t) => (n, o) => t(n, o, e), no = (e, t, n) => za(e, typeof t != "symbol" ? t + "" : t, n);
  3651. let Dt = class extends So {
  3652. constructor(e = Xn, t, n, o) {
  3653. super(), this._config = e, this._injector = t, this._renderManagerService = n, this._configService = o;
  3654. const { menu: r, ...i } = vo(
  3655. Xn,
  3656. this._config
  3657. );
  3658. r && this._configService.setConfig("menu", r, { merge: !0 }), this._configService.setConfig(hc, i);
  3659. }
  3660. onStarting() {
  3661. const e = this._injector;
  3662. [
  3663. [Nt, { useClass: an }],
  3664. [$t],
  3665. [Pt],
  3666. [At],
  3667. [Lt],
  3668. [wt]
  3669. ].forEach((o) => e.add(o));
  3670. const n = this._injector.get(Nr);
  3671. n.register(Ho, Ei), n.register(Wo, fc);
  3672. }
  3673. onRendered() {
  3674. [
  3675. [Fe],
  3676. [fn]
  3677. ].forEach((e) => {
  3678. this.disposeWithMe(this._renderManagerService.registerRenderModule(Me.UNIVER_SHEET, e));
  3679. }), Co(this._injector, [
  3680. [$t],
  3681. // FormulaProgressBar relies on TriggerCalculationController, but it is necessary to ensure that the formula calculation is done after rendered.
  3682. [At],
  3683. [wt]
  3684. ]);
  3685. }
  3686. onSteady() {
  3687. this._injector.get(Pt);
  3688. }
  3689. };
  3690. no(Dt, "pluginName", Or);
  3691. no(Dt, "type", Me.UNIVER_SHEET);
  3692. Dt = Za([
  3693. _o(Zo, hs),
  3694. rn(1, ee(_t)),
  3695. rn(2, ve),
  3696. rn(3, Ro)
  3697. ], Dt);
  3698. export {
  3699. ws as FORMULA_PROMPT_ACTIVATED,
  3700. fc as FormulaEditor,
  3701. $s as HelpFunctionOperation,
  3702. vn as InsertFunctionOperation,
  3703. Cn as MoreFunctionsOperation,
  3704. Ei as RangeSelector,
  3705. Fe as RefSelectionsRenderService,
  3706. Pr as ReferenceAbsoluteOperation,
  3707. Ws as SearchFunctionOperation,
  3708. ut as SelectEditorFormulaOperation,
  3709. Sn as SheetOnlyPasteFormulaCommand,
  3710. Dt as UniverSheetsFormulaUIPlugin
  3711. };