chunk-U3EPM6JO.js 138 KB

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